$value) { $keys[] = '`' . $key . '`'; $values[] = '\'' . $value . '\''; } $sql = "insert into comments (" . implode(', ', $keys) . ") values (" . implode(', ', $values) . ")"; Db::query($sql, $args); Notifications::set('success', 'Your comment has been sent'); return true; } public static function update() { $post = Input::post(array('id', 'text', 'status')); $errors = array(); if(empty($post['text'])) { $errors[] = 'Please enter comment text'; } if(count($errors)) { $output = json_encode(array('result' => false, 'errors' => $errors)); Response::content($output); return false; } $id = $post['id']; unset($post['id']); $updates = array(); $args = array(); foreach($post as $key => $value) { $updates[] = '`' . $key . '` = ?'; $args[] = $value; } $sql = "update comments set " . implode(', ', $updates) . " where id = ?"; $args[] = $id; Db::query($sql, $args); $output = json_encode(array('result' => true)); Response::content($output); } public static function update_status() { $post = Input::post(array('id', 'status')); $errors = array(); if(in_array($post['status'], array('published', 'pending', 'spam')) === false) { $errors[] = 'Invalid comment status'; } if(count($errors)) { $output = json_encode(array('result' => false, 'errors' => $errors)); Response::content($output); return false; } $id = $post['id']; unset($post['id']); $updates = array(); $args = array(); foreach($post as $key => $value) { $updates[] = '`' . $key . '` = ?'; $args[] = $value; } $sql = "update comments set " . implode(', ', $updates) . " where id = ?"; $args[] = $id; Db::query($sql, $args); $output = json_encode(array('result' => true)); Response::content($output); } public static function remove() { $id = Input::post('id'); $sql = "delete from comments where id = ?"; $args = array($id); Db::query($sql, $args); $output = json_encode(array('result' => true)); Response::content($output); } }