Пример #1
0
 /**
  * Добавление комментария:
  */
 public static function CreateComment($params, $safeMode = true)
 {
     if (Blog_BlogPostsModel::PostExists($params['post_id'])) {
         $session = Session::getInstance();
         $post = Blog_BlogPostsModel::GetPost($params['post_id']);
         // Запрет комментирования закрытых тредов:
         if ($post['closed'] == true) {
             return false;
         }
         $cache = KVS::getInstance();
         $id = $cache->incr('Blog_BlogPostsModel', null, 'nextPostId');
         $text_original = $params['text'];
         // Обработка:
         $params['text'] = TexyHelper::markup($params['text'], !$session->isAdminSession());
         $record = array('id' => $id, 'post_id' => $params['post_id'], 'ip' => $_SERVER['REMOTE_ADDR'], 'created_at' => time(), 'text' => $params['text']);
         if (HomeBoardHelper::existsBoard($params['homeboard'])) {
             $record['author'] = $params['homeboard'];
         }
         if (!$safeMode) {
             $record = array_merge($record, array('special_comment' => @$params['special_comment']));
         }
         $dbh = PDOQuery::getInstance();
         $dbh->insert('1chan_comment', $record);
         if ($post['bumpable'] && time() - $post['created_at'] < 60 * 60 * 24 * 30) {
             $dbh->update_insecure('1chan_post', array('updated_at' => time(), 'comments' => '`comments`+1'), 'id = ' . $dbh->q($params['post_id']), 1, true);
         } else {
             $dbh->update_insecure('1chan_post', array('comments' => '`comments`+1'), 'id = ' . $dbh->q($params['post_id']), 1, true);
         }
         $record['text_original'] = $text_original;
         EventModel::getInstance()->Broadcast('add_comment', $record);
         /**
          * Сохраняем в кеше последние комментарии:
          */
         $record['post_title'] = $post['title'];
         $cache->listAdd(__CLASS__, null, 'lastComments', $id);
         $cache->listTrim(__CLASS__, null, 'lastComments', 0, 31);
         return $id;
     }
     return false;
 }
Пример #2
0
 /**
  * Действие удаление комментария:
  */
 public function removePostCommentAjaxAction(Application $application)
 {
     if (!Session::getInstance()->isAdminSession()) {
         return false;
     }
     $comment = Blog_BlogCommentsModel::GetComment($_GET['id']);
     $post = Blog_BlogPostsModel::GetPost(@$comment['post_id']);
     if ($comment && $post && ControlModel::checkModrights($post['category'])) {
         Blog_BlogCommentsModel::RemoveComment($_GET['id']);
         ControlModel::logModEvent(date("d-m-Y H:i:s") . ' ' . $_SESSION['auth']['name'] . '<br /> удалил комментарий ' . $comment['id'] . ' в посте <a href="http://' . TemplateHelper::getSiteUrl() . '/news/res/' . $post['id'] . '/" class="js-cross-link">&gt;&gt;' . $post['id'] . '</a>' . '<br /><em>' . strip_tags($comment['text'], 'a') . '</em>');
         JabberBot::send('-=$ /me (модлог) ' . $_SESSION['auth']['name'] . ' удалил комментарий ' . $comment['id'] . ' в посте http://' . TemplateHelper::getSiteUrl() . '/news/res/' . $post['id'] . '/');
         return true;
     }
     return false;
 }
Пример #3
0
 /**
  * Получение коммента:
  */
 public function getPostCommentAjaxAction()
 {
     $cache = KVS::getInstance();
     $comment = Blog_BlogCommentsModel::GetComment($_GET['id']);
     $session = Session::getInstance();
     $session->activeSet('last_visit_post_' . $comment['post_id'], time());
     if ($comment) {
         if ($_GET['title']) {
             $post = Blog_BlogPostsModel::GetPost($comment['post_id']);
             $comment['post_title'] = $post['title'];
         }
         $comment['created_at'] = TemplateHelper::date('d M Y @ H:i', $comment['created_at']);
         $comment['author'] = array($comment['author'], HomeBoardHelper::getBoard($comment['author']));
         unset($comment['ip']);
         return $comment;
     }
     return false;
 }
Пример #4
0
 /**
  * Оценка поста:
  */
 public static function RatePost($id, $increment = true)
 {
     $dbh = PDOQuery::getInstance();
     $ip = $_SERVER['REMOTE_ADDR'];
     $cache = KVS::getInstance();
     $post = Blog_BlogPostsModel::GetPost($id);
     if ($post && !$post['rateable']) {
         return false;
     }
     $raters = unserialize($cache->get(__CLASS__, $id, 'raters'));
     if (!$raters) {
         return false;
     }
     if (in_array($ip, $raters)) {
         return false;
     } else {
         $raters[] = $ip;
         $cache->set(__CLASS__, $id, 'raters', serialize($raters));
     }
     $dbh->update_insecure('1chan_post', array('rate' => '`rate`' . ($increment ? '+1' : '-1')), 'id = ' . $dbh->q($id), 1, true);
     $post = Blog_BlogPostsModel::GetPost($id);
     EventModel::getInstance()->Broadcast('rate_post', array($id, $post['rate']));
     /**
     		if ($post['rate'] >= ControlModel::getRatedCount() && !$post['rated'])
     			self::RatedPost($id, true);
     		**/
     return true;
 }
Пример #5
0
 /**
  * Поиск постов:
  */
 public function postSearchAction(Application $application, Template $template)
 {
     $template->setParameter('menu', 'posts');
     $template->setParameter('submenu', 'post_search');
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         if (!empty($_POST['id'])) {
             $post = Blog_BlogPostsModel::GetPost($_POST['id']);
             if ($post) {
                 $this['posts'] = array($post);
             }
         } else {
             $search = new SphinxClient();
             $search->SetServer('localhost', 3312);
             $search->SetSortMode(SPH_SORT_EXTENDED, '@relevance DESC, created_at DESC, @id DESC');
             $search->SetLimits(0, 60);
             $search->SetWeights(array('title' => 40, 'text' => 20, 'text_full' => 10));
             if (isset($_POST['category'])) {
                 $search->SetFilter('category', $_POST['category']);
             }
             $result = $search->Query($_POST['query'], '*');
             if (is_array($result['matches'])) {
                 $ids = array_keys($result['matches']);
                 $this['posts'] = Blog_BlogPostsModel::GetPostsByIds($ids);
             }
         }
     }
     return true;
 }