public function get_recent_posts($uid) { $posts = array(); $id = (int) $uid; $access_conditions = ''; if ($id != \CODOF\User\CurrentUser\CurrentUser::id()) { $topic = new \CODOF\Forum\Topic(false); $access_conditions = "AND " . $topic->getViewTopicPermissionConditions(); } $qry = 'SELECT c.cat_alias,c.cat_img,p.omessage AS message, t.title, t.topic_id,' . ' u.id, u.name, u.avatar, t.topic_created,t.no_posts,t.no_views, p.post_created,p.post_id ' . ' FROM ' . PREFIX . 'codo_posts AS p ' . ' LEFT JOIN ' . PREFIX . 'codo_categories AS c ON p.cat_id=c.cat_id ' . ' LEFT JOIN ' . PREFIX . 'codo_topics AS t ON t.topic_id=p.topic_id ' . ' LEFT JOIN ' . PREFIX . 'codo_users AS u ON t.uid=u.id ' . ' WHERE p.uid = ' . $id . ' AND p.post_status<>0 ' . $access_conditions . ' ORDER BY p.post_created DESC ' . ' LIMIT 20 OFFSET 0'; $obj = $this->db->query($qry); if ($obj) { $posts = $this->gen_posts_arr($obj->fetchAll()); } $category = new \CODOF\Forum\Category(); return array("topics" => $posts, "RURI" => RURI, "DURI" => DURI, "CAT_IMGS" => CAT_IMGS, "CURR_THEME" => CURR_THEME, "reply_txt" => _t("replies"), "views_txt" => _t("views"), "posted" => _t("posted"), "created" => _t("created"), "no_topics" => _t("You have no recent posts"), "new_topic" => _t("Create new topic"), "can_create" => $category->canCreateTopicInAtleastOne()); }
private function base_query() { if ($this->count_rows && $this->isMySQL) { $count = 'SQL_CALC_FOUND_ROWS'; } else { $count = ''; } $qry = 'SELECT ' . $count . ' #SELECTORS# ' . 'FROM codo_posts AS p ' . 'LEFT JOIN codo_topics AS t ON t.topic_id=p.topic_id ' . 'LEFT JOIN codo_users AS u ON u.id=p.uid ' . 'LEFT JOIN codo_categories AS c ON c.cat_id=t.cat_id ' . 'LEFT JOIN codo_user_roles AS r ON r.uid=u.id AND r.is_primary=1 ' . 'WHERE t.topic_status<>0 ' . ' AND p.post_status=1' . ' #CONDITIONS# '; if ($this->cats != null) { $qry .= ' AND p.cat_id IN (?) '; } if ($this->tid != null) { if (strpos($this->tid, '=') === FALSE) { $this->tid = ' = ' . $this->tid; } $qry .= ' AND p.topic_id ' . $this->tid; } if ($this->pid != null) { $qry .= ' AND p.post_id ' . $this->pid; } if ($this->time_within != 'anytime') { $time = new \CODOF\Time(); $error = false; if ($this->time_within == 'hour') { $this->time_within = $time->unix_get_time_hour(); } else { if ($this->time_within == 'day') { $this->time_within = $time->unix_get_time_day(); } else { if ($this->time_within == 'week') { $this->time_within = $time->unix_get_time_day(7); } else { if ($this->time_within == 'month') { $this->time_within = $time->unix_get_time_day(31); } else { if ($this->time_within == 'year') { $this->time_within = $time->unix_get_time_day(365); } else { $error = true; } } } } } if (!$error) { $qry .= ' AND p.post_created > ' . $this->time_within; } } $topic = new \CODOF\Forum\Topic(false); $qry .= ' AND ' . $topic->getViewTopicPermissionConditions(); $qry .= ' ORDER BY #SORT# #ORDER# LIMIT ' . $this->num_results . ' OFFSET ' . $this->from; return $qry; }