public static function update(post_model $post, $category_id, $tags) { $post->save(); if ($category_id != $post->category_id) { category_model::dec_by_id(array('post_count' => 1), $category_id); category_model::inc_by_id(array('post_count' => 1), $post->category_id); } self::delete_tags_for_post($post); self::create_tags_for_post($post, $tags); }
public static function new_action() { // 拦截 self::method('post'); $post_id = g_int('post_id'); $post = post_model::get_by_id($post_id); self::forward_404_if($post === null, '文章不存在,无法评论'); try { // 校验 $checker = new lazy_checker(p()); $checker->check('captcha', array('should_be' => array(setting_model::get_by_id(setting_model::id_captcha_answer)->value, '验证码不正确'))); $checker->del('captcha'); $checker->check_model_rules('comment'); $comment = $checker->get_all(); if (!visitor::has_role('member') && member_model::get_one(array('name' => $comment['author'])) !== null) { $checker->failed('author', '您不能使用管理员的昵称'); } // 执行 $comment['post_id'] = $post_id; $comment['pub_time'] = clock::get_stamp(); comment_model::add($comment); post_model::inc_by_id(array('comment_count' => 1), $post_id); setting_model::inc_by_id(array('value' => 1), setting_model::id_comment_count); // 成功 self::json_result(true, '评论成功', 0, url('post/show?id=' . $post_id)); } catch (check_failed $e) { // 失败 self::json_result(false, $e->get_reasons()); } }
public static function delete($comment_id) { $comment = comment_model::get_by_id($comment_id); if ($comment !== null) { comment_model::del_by_id($comment_id); post_model::dec_by_id(array('comment_count' => 1), $comment->post_id); } }
public static function delete($category_id) { $category = category_model::get_by_id($category_id); if ($category !== null) { if (!$category->can_be_deleted()) { return false; } category_model::del_by_id($category_id); if ($category->has_posts()) { post_model::set(array('category_id' => category_model::default_id), array('category_id' => $category_id)); category_model::inc_by_id(array('post_count' => $category->post_count), category_model::default_id); } } return true; }
public static function delete_action() { // 拦截 self::method('delete'); self::role('member'); self::csrf('member'); // 校验 // 执行 $id = g_int('id'); $post = post_model::get_by_id($id); if ($post !== null) { comment_model::del(array('post_id' => $id)); category_model::dec_by_id(array('post_count' => 1), $post->category_id); post_model::del_by_id($id); publish_service::delete_tags_for_post($post); } // 成功 self::send_json(true); }
//エラー保持用配列 $errors = array(); // メッセージ配列 $msg = array(); // 各変数宣言 $login_id = $_SESSION['login_id']; $color_id = ''; $post_body = ''; $login_user_info = array(); $user_list = array(); $my_follow_list = array(); $good_list = array(); $all_time_line = array(); // modelオブジェクト作成 $main = new main_model(); $post = new post_model(); $follow = new follow_model(); $good = new good_model(); // DBコネクトオブジェクト取得 try { $db = get_db_connect(); } catch (PDOException $e) { $errors[] = entity_str($e->getMessage()); } // ユーザ情報を取得する $login_user_info = $main->getMyProfile($db, $login_id); // フォロー一覧を取得 $my_follows = $follow->myFollowUser($db, $login_id); if (is_array($my_follows)) { foreach ($my_follows as $my_follow) { $my_follow_list[] = $my_follow['follower_user_id'];