Ejemplo n.º 1
0
 public function getPosts()
 {
     $inUser = cmsUser::getInstance();
     $sql = "SELECT p.id, p.thread_id, p.user_id, p.pubdate, p.editdate, p.edittimes, p.rating, p.attach_count, p.content_html, p.pinned,\r\n                       u.nickname, u.login, u.is_deleted, u.logdate, u.status,\r\n                       up.imageurl, up.signature_html, up.city, up.karma, g.access as group_access, g.is_admin {$this->inDB->select}\r\n                FROM cms_forum_posts p\r\n                {$this->inDB->join}\r\n                LEFT JOIN cms_users u ON u.id = p.user_id\r\n                LEFT JOIN cms_user_profiles up ON up.user_id = u.id\r\n                LEFT JOIN cms_user_groups g ON u.group_id = g.id\r\n                WHERE 1=1\r\n                {$this->inDB->where}\r\n                {$this->inDB->group_by}\r\n                {$this->inDB->order_by} \n";
     if ($this->inDB->limit) {
         $sql .= "LIMIT {$this->inDB->limit}";
     }
     $result = $this->inDB->query($sql);
     $this->inDB->resetConditions();
     if (!$this->inDB->num_rows($result)) {
         return array();
     }
     while ($post = $this->inDB->fetch_assoc($result)) {
         $post['fpubdate'] = cmsCore::dateFormat($post['pubdate']);
         $post['wday'] = cmsCore::dateToWday($post['pubdate']);
         $post['peditdate'] = cmsCore::dateFormat($post['editdate'], true, true);
         $post['post_count'] = $this->getUserPostsCount($post['user_id']);
         $post['avatar_url'] = cmsUser::getUserAvatarUrl($post['user_id'], 'small', $post['imageurl'], $post['is_deleted']);
         $post['flogdate'] = cmsUser::getOnlineStatus($post['user_id'], $post['logdate']);
         $post['userrank'] = $this->getForumUserRank($post);
         $post['user_awards'] = cmsUser::getAwardsList($post['user_id']);
         $post['attached_files'] = $this->config['fa_on'] && $post['attach_count'] ? $this->getPostAttachments($post['id']) : array();
         $end_min = $this->checkEditTime($post['pubdate']);
         $post['is_author'] = $post['user_id'] == cmsUser::getInstance()->id;
         $post['is_author_can_edit'] = (is_bool($end_min) ? $end_min : $end_min > 0) && $post['is_author'];
         if ($inUser->id) {
             $post['is_voted'] = $post['is_author'] ? true : cmsUser::isRateUser('forum_post', $inUser->id, $post['id']);
         } else {
             $post['is_voted'] = true;
         }
         $posts[] = $post;
     }
     $this->resetAbstractArray();
     return cmsCore::callEvent('GET_FORUM_POSTS', $posts);
 }
Ejemplo n.º 2
0
 /**
  * Получаем комментарии по заданным параметрам
  * @return array
  */
 public function getComments($only_published = true, $is_tree = false, $from_module = false)
 {
     $inUser = cmsUser::getInstance();
     $comments = array();
     global $_LANG;
     $published = $only_published ? 'c.published = 1' : '1=1';
     $sql = "SELECT c.*,\r\n\t\t\t\t\t   IFNULL(u.nickname, 0) as nickname,\r\n\t\t\t\t\t   IFNULL(u.login, 0) as login,\r\n\t\t\t\t\t   IFNULL(u.is_deleted, 0) as is_deleted,\r\n\t\t\t\t\t   IFNULL(p.imageurl, 0) as imageurl,\r\n\t\t\t\t\t   IFNULL(p.gender, 0) as gender\r\n                FROM cms_comments c\r\n\t\t\t\tLEFT JOIN cms_users u ON u.id = c.user_id\r\n\t\t\t\tLEFT JOIN cms_user_profiles p ON p.user_id = u.id\r\n                WHERE {$published}\r\n\t\t\t\t\t{$this->inDB->where}\r\n\r\n                {$this->inDB->group_by}\r\n\r\n                {$this->inDB->order_by}\n";
     if ($this->inDB->limit) {
         $sql .= "LIMIT {$this->inDB->limit}";
     }
     $result = $this->inDB->query($sql);
     $this->inDB->resetConditions();
     if (!$this->inDB->num_rows($result)) {
         return array();
     }
     while ($comment = $this->inDB->fetch_assoc($result)) {
         $comment['level'] = 0;
         $comment['is_editable'] = $this->isEditable($comment['pubdate']);
         $comment['fpubdate'] = cmsCore::dateFormat($comment['pubdate'], true, true);
         if ($comment['guestname']) {
             $comment['author'] = $comment['guestname'];
             $comment['is_profile'] = false;
             $comment['ip'] = in_array($this->config['cmm_ip'], array(1, 2)) ? $comment['ip'] : '';
         } else {
             $comment['author']['nickname'] = $comment['nickname'];
             $comment['author']['login'] = $comment['login'];
             $comment['is_profile'] = true;
             $comment['user_image'] = cmsUser::getUserAvatarUrl($comment['user_id'], 'small', $comment['imageurl'], $comment['is_deleted']);
             $comment['ip'] = $this->config['cmm_ip'] == 2 && $comment['ip'] ? $comment['ip'] : '';
         }
         switch ($comment['gender']) {
             case 'm':
                 $comment['gender'] = $_LANG['COMMENTS_MALE'];
                 break;
             case 'f':
                 $comment['gender'] = $_LANG['COMMENTS_FEMALE'];
                 break;
             default:
                 $comment['gender'] = $_LANG['COMMENTS_GENDER'];
         }
         $comment['show'] = !$this->config['min_karma'] || $comment['rating'] >= $this->config['min_karma_show'] || cmsUser::userIsAdmin($comment['user_id']);
         $comment['is_my'] = $inUser->id == $comment['user_id'];
         if ($inUser->id) {
             $comment['is_voted'] = $comment['is_my'] ? true : cmsUser::isRateUser('comment', $inUser->id, $comment['id']);
         } else {
             $comment['is_voted'] = true;
         }
         $comments[] = $comment;
     }
     if ($is_tree) {
         $comments = $this->buildTree(0, 0, $comments);
     }
     return $from_module ? cmsCore::callEvent('GET_COMMENTS_MODULE', $comments) : cmsCore::callEvent('GET_COMMENTS', $comments);
 }