Example #1
0
 public static function about_action()
 {
     // 拦截
     self::role('member');
     $setting = setting_model::get_by_id(setting_model::id_about);
     if (visitor::is_post()) {
         // 拦截
         self::csrf('member');
         try {
             // 校验
             $checker = new lazy_checker(p());
             $checker->check('content', array('change_to' => 'string', 'cannot_be' => array('', '关于不能为空')));
             // 执行
             $setting->value = $checker->content;
             $setting->save();
             // 成功
             self::json_result(true, '关于信息编辑成功。', 0, url('site/about'));
         } catch (check_failed $e) {
             // 失败
             self::json_result(false, $e->get_reasons());
         }
     } else {
         // 呈现
         self::set('content', $setting->value);
         self::show_page();
     }
 }
Example #2
0
 public static function create_tags_for_post(post_model $post, $tags)
 {
     if ($tags === '') {
         return;
     }
     $post_tags = [];
     $tag_names = array_map('trim', explode(',', $tags));
     $old_tags = tag_model::get_in('name', $tag_names);
     if ($old_tags === []) {
         foreach ($tag_names as $tag_name) {
             $tag_id = tag_model::add(array('name' => $tag_name, 'refer_count' => 1));
             $post_tags[] = array('post_id' => $post->id, 'tag_id' => $tag_id);
         }
         setting_model::inc_by_id(array('value' => count($tag_names)), setting_model::id_tag_count);
     } else {
         tag_model::inc_by_ids(array('refer_count' => 1), array_keys($old_tags));
         $old_tag_names = [];
         foreach ($old_tags as $old_tag) {
             $post_tags[] = array('post_id' => $post->id, 'tag_id' => $old_tag->id);
             $old_tag_names[] = $old_tag->name;
         }
         $new_tag_names = array_diff($tag_names, $old_tag_names);
         if ($new_tag_names !== []) {
             foreach ($new_tag_names as $new_tag_name) {
                 $tag_id = tag_model::add(array('name' => $new_tag_name, 'refer_count' => 1));
                 $post_tags[] = array('post_id' => $post->id, 'tag_id' => $tag_id);
             }
             setting_model::inc_by_id(array('value' => count($new_tag_names)), setting_model::id_tag_count);
         }
     }
     if ($post_tags !== []) {
         post_tag_model::add_many($post_tags);
     }
 }
Example #3
0
 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());
     }
 }
Example #4
0
 public static function get_settings()
 {
     static $settings = null;
     if ($settings === null) {
         $settings = setting_model::get_all();
     }
     return $settings;
 }
Example #5
0
 public static function about_action()
 {
     // 呈现
     self::set('about', setting_model::get_about());
     list($pager, $messages) = message_model::pager_all(array(array('id' => 'DESC'), g_int('page', 1), 10));
     $pager['target'] = 'site/about';
     self::set('pager', $pager);
     self::set('messages', $messages);
     self::set('logined', visitor::has_role('member'));
     self::set('captcha_question', setting_model::get_by_id(setting_model::id_captcha_question)->value);
     self::show_page('', 'three');
 }
Example #6
0
 public static function show_action()
 {
     // 呈现
     $post_id = g_int('id');
     $post = post_model::get_by_id($post_id);
     self::forward_404_if($post === null, '文章不存在');
     binder::bind($post, 'belongs_to', 'member');
     binder::bind($post, 'belongs_to', 'category');
     binder::bind($post, 'many_many', 'tag', array('post_tag', 0));
     self::set('post', $post);
     $order_limit = array(array('id' => 'DESC'), g_int('page', 1), 10);
     list($pager, $comments) = comment_model::pager_with_count($post->comment_count, array('post_id' => $post_id), $order_limit);
     $pager['target'] = 'post/show?id=' . $post_id;
     self::set('pager', $pager);
     self::set('comments', $comments);
     self::set('logined', visitor::has_role('member'));
     self::set('captcha_question', setting_model::get_by_id(setting_model::id_captcha_question)->value);
     self::show_page('', 'four');
 }
Example #7
0
 public static function new_action()
 {
     // 拦截
     self::method('post');
     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('message');
         // 执行
         $message = $checker->get_all();
         $message['pub_time'] = clock::get_stamp();
         message_model::add($message);
         // 成功
         self::json_result(true, '留言成功。', 0, url('site/about'));
     } catch (check_failed $e) {
         // 失败
         self::json_result(false, $e->get_reasons());
     }
 }