/** * Latest forum posts * @since Version 3.2 * @version 3.2 * @param array $auth_ary * @param int $since * @return array */ public function latestPosts($is_auth_ary, $since, $limit = 10) { if (empty($is_auth_ary) || !is_array($is_auth_ary)) { return false; } // To start off, get the list of forums $Index = new Index($this->db); $forum_list = $Index->forums(); $exclude_forums = array(); for ($i = 0, $c = count($forum_list); $i < $c; $i++) { if ($is_auth_ary[$forum_list[$i]['forum_id']]['auth_view']) { if (!in_array($forum_list[$i]['forum_id'], array("37"))) { $exclude_forums[] = $forum_list[$i]['forum_id']; } } } if ($this->db instanceof \sql_db) { if (!empty($since) && is_int($since) && $since > 0) { $since = " AND p.post_time >= " . $this->db->real_escape_string(intval($since)); } $query = "SELECT p.post_id, pt.bbcode_uid, p.post_time, pt.post_text, p.enable_bbcode, p.enable_html, p.enable_smilies, p.enable_sig, p.post_edit_time, p.poster_id AS user_id, u.username, t.topic_title, t.topic_id, f.forum_name, f.forum_id\n FROM nuke_bbposts p\n LEFT JOIN nuke_bbposts_text AS pt ON p.post_id = pt.post_id\n LEFT JOIN nuke_users AS u ON p.poster_id = u.user_id\n LEFT JOIN nuke_bbtopics AS t ON p.topic_id = t.topic_id\n LEFT JOIN nuke_bbforums AS f ON p.forum_id = f.forum_id\n WHERE p.forum_id IN (" . implode(",", $exclude_forums) . ") " . $since . "\n ORDER BY p.post_time DESC\n LIMIT 0, " . $this->db->real_escape_string($limit) . ""; if ($rs = $this->db->query($query)) { $return = array(); while ($row = $rs->fetch_assoc()) { $row['post_text'] = stripslashes($row['post_text']); $return[] = $row; } return $return; } else { trigger_error("Could not fetch new posts"); trigger_error($this->db->error); return false; } } else { $params = array(); if (!empty($since) && is_int($since) && $since > 0) { $since = " AND p.post_time >= ?"; $params[] = intval($since); } $query = "SELECT p.post_id, pt.bbcode_uid, p.post_time, pt.post_text, p.enable_bbcode, p.enable_html, p.enable_smilies, p.enable_sig, p.post_edit_time, p.poster_id AS user_id, u.username, t.topic_title, t.topic_id, f.forum_name, f.forum_id\n FROM nuke_bbposts p\n LEFT JOIN nuke_bbposts_text AS pt ON p.post_id = pt.post_id\n LEFT JOIN nuke_users AS u ON p.poster_id = u.user_id\n LEFT JOIN nuke_bbtopics AS t ON p.topic_id = t.topic_id\n LEFT JOIN nuke_bbforums AS f ON p.forum_id = f.forum_id\n WHERE p.forum_id IN (" . implode(",", $exclude_forums) . ") " . $since . "\n ORDER BY p.post_time DESC\n LIMIT 0, ?"; $params[] = $limit; $return = array(); foreach ($this->db->fetchAll($query, $params) as $row) { $row['post_text'] = stripslashes($row['post_text']); $return[] = $row; } return $return; } }
/** * Get forums within this category * @since Version 3.8.7 * @yield new Forum */ public function getForums() { if (!$this->User instanceof User) { throw new Exception("Cannot get the list of forums within this category because no valid user has been specified"); } $userdata = $this->User->generateUserData(); $Index = new Index(); if (!isset($prefix)) { $prefix = "nuke"; } if (!isset($user_prefix)) { $user_prefix = "nuke"; } require_once "includes" . DS . "auth.php"; require_once "includes" . DS . "constants.php"; $is_auth_ary = auth(AUTH_VIEW, AUTH_LIST_ALL, $userdata, $Index->forums()); $forums = array(); foreach ($is_auth_ary as $forum_id => $perms) { if (intval($perms['auth_view']) === 1) { $forums[] = $forum_id; } #printArray($perms);die; } $query = "SELECT forum_id FROM nuke_bbforums WHERE cat_id = ? AND forum_id IN ('" . implode("', '", $forums) . "') ORDER BY forum_order"; foreach ($this->db->fetchAll($query, $this->id) as $row) { (yield new Forum($row['forum_id'])); } }
/** * Get an SQL query used to exclude forums from timeline lookup * @since Version 3.9.1 * @param \Railpage\Users\User $User * @return string */ private function getFilteredForums() { $timer = Debug::GetTimer(); if (!isset($this->User->Guest) || !$this->User->Guest instanceof User) { return ""; } $mckey = sprintf("forum.post.filter.user:%d", $this->User->Guest->id); if ($forum_post_filter = $this->Redis->fetch($mckey)) { return $forum_post_filter; } $Forums = new Forums(); $Index = new Index(); $acl = $Forums->setUser($this->User->Guest)->getACL(); $allowed_forums = array(); foreach ($Index->forums() as $row) { $Forum = new Forum($row['forum_id']); if ($Forum->setUser($this->User->Guest)->isAllowed(Forums::AUTH_READ)) { $allowed_forums[] = $Forum->id; } } $forum_filter = "AND p.forum_id IN (" . implode(",", $allowed_forums) . ")"; if (count($allowed_forums) === 0) { $this->Redis->save($mckey, "", strtotime("+1 week")); return ""; } $forum_post_filter = "AND id NOT IN (SELECT l.id AS log_id\r\n FROM log_general AS l \r\n LEFT JOIN nuke_bbposts AS p ON p.post_id = l.value\r\n WHERE l.key = 'post_id' \r\n " . $forum_filter . ")"; $this->Redis->save($mckey, $forum_post_filter, strtotime("+1 week")); Debug::LogEvent(__METHOD__, $timer); return $forum_post_filter; }