Mithril as main method
This commit is contained in:
@@ -124,8 +124,7 @@ class Posts
|
||||
|
||||
View::render($url, [
|
||||
'posts' => $datas,
|
||||
'user' => $user,
|
||||
'token' => Token::generate()
|
||||
'user' => $user
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -263,8 +262,26 @@ class Posts
|
||||
}
|
||||
|
||||
/* Methods */
|
||||
public function post($args = [])
|
||||
public function post($args)
|
||||
{
|
||||
$post = [];
|
||||
|
||||
if ($args == [] || count($args) < 4) {
|
||||
$post['status'] = false;
|
||||
$post['message'] = 'Semua data harus diisi ya broo';
|
||||
$post['data'] = $args;
|
||||
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
|
||||
echo json_encode($post);
|
||||
die();
|
||||
}
|
||||
Session::flash('info', 'Semua data harus diisi');
|
||||
if (isset($table)) {
|
||||
Redirect::to("/posts/category");
|
||||
} else {
|
||||
Redirect::to('/posts/entry');
|
||||
}
|
||||
die();
|
||||
}
|
||||
if (isset($args['_addon'])) {
|
||||
$table = $args['_addon'];
|
||||
unset($args['_addon']);
|
||||
@@ -272,6 +289,12 @@ class Posts
|
||||
|
||||
foreach ($args as $value) {
|
||||
if ($value == '') {
|
||||
$post['status'] = false;
|
||||
$post['message'] = 'Semua data harus diisi';
|
||||
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
|
||||
echo json_encode($post);
|
||||
die();
|
||||
}
|
||||
Session::flash('info', 'Semua data harus diisi');
|
||||
if (isset($table)) {
|
||||
Redirect::to("/posts/category");
|
||||
@@ -282,6 +305,12 @@ class Posts
|
||||
}
|
||||
}
|
||||
|
||||
$query_string = $_SERVER['HTTP_X_QUERY'];
|
||||
$exploded = explode('&', $query_string);
|
||||
$args['creator'] = substr_replace($exploded[1], '', 0, 2);
|
||||
$args['created_at'] = date('Y-m-d H:i:s');
|
||||
$args['edited_at'] = $args['created_at'];
|
||||
|
||||
// Avoid XSS attack
|
||||
$args = XSS::avoid($args);
|
||||
|
||||
@@ -297,16 +326,27 @@ class Posts
|
||||
$length = strlen($args['content']);
|
||||
$args['delay'] = $length * 84;
|
||||
|
||||
if ($this->model->entry($args)) {
|
||||
Session::flash('info', 'Data berhasil diunggah');
|
||||
Redirect::to('/');
|
||||
try {
|
||||
$this->model->entry($args);
|
||||
} catch (Exception $e) {
|
||||
$post['message'] = $e->getMessage();
|
||||
}
|
||||
$post['status'] = true;
|
||||
$post['route_to'] = '';
|
||||
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
|
||||
echo json_encode($post);
|
||||
die();
|
||||
}
|
||||
Session::flash('info', 'Data berhasil diunggah');
|
||||
Redirect::to('/');
|
||||
}
|
||||
die();
|
||||
}
|
||||
|
||||
public function put($args)
|
||||
{
|
||||
$update = [];
|
||||
|
||||
if (isset($args['_addon'])) {
|
||||
$table = $args['_addon'];
|
||||
unset($args['_addon']);
|
||||
@@ -318,6 +358,11 @@ class Posts
|
||||
die();
|
||||
}
|
||||
|
||||
if (isset($args['categoryName'])) { unset($args['categoryName']); }
|
||||
if (isset($args['creatorName'])) { unset($args['creatorName']); }
|
||||
if (isset($args['background'])) { unset($args['background']); }
|
||||
if (isset($args['foreground'])) { unset($args['foreground']); }
|
||||
|
||||
// Avoid XSS attack
|
||||
$args = XSS::avoid($args);
|
||||
|
||||
@@ -361,6 +406,12 @@ class Posts
|
||||
$args['delay'] = $length * 84;
|
||||
|
||||
if ($this->model->update($args, $id)) {
|
||||
$update['status'] = true;
|
||||
$update['route_to'] = '';
|
||||
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
|
||||
echo json_encode($update);
|
||||
die();
|
||||
}
|
||||
Session::flash('info', 'Data berhasil diperbarui');
|
||||
Redirect::to('/');
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user