/** * Get stories from topic * @version 3.0 * @since Version 3.0 * @return mixed * @param int $page * @param int $limit * @param boolean $total */ public function stories($page = 0, $limit = 25, $total = true) { $return = false; $mckey = "railpage:topic_id=" . $this->id . ".stories.page=" . $page . ".limit=" . $limit . ".total=" . (int) $total; $mcexp = strtotime("+1 hour"); if (!($return = getMemcacheObject($mckey))) { // Get it from Sphinx $Sphinx = $this->getSphinx(); $query = $Sphinx->select("*")->from("idx_news_article")->orderBy("story_time_unix", "DESC")->limit($page * $limit, $limit)->where("topic_id", "=", $this->id); $matches = $query->execute(); $meta = $Sphinx->query("SHOW META"); $meta = $meta->execute(); if (is_array($matches) && count($matches)) { $return = array("total" => $meta[1]['Value'], "children" => array(), "page" => $page, "perpage" => $limit, "topic_id" => $this->id); foreach ($matches as $id => $row) { $row['time_relative'] = time2str($row['story_time_unix']); $row['time'] = $row['story_time']; $row['title'] = format_topictitle($row['story_title']); // Match the first sentence $line = explode("\n", $row['story_blurb']); $row['firstline'] = preg_replace('/([^?!.]*.).*/', '\\1', strip_tags($line[0])); if (empty($row['story_slug'])) { $row['slug'] = $this->createSlug($row['story_id']); } $row['url'] = $this->makePermaLink($row['story_slug']); $row['hometext'] = $row['story_blurb']; $row['bodytext'] = $row['story_body']; $row['featured_image'] = $row['story_image']; $row['informant'] = $row['username']; $return['children'][$id] = $row; } } } if (!isset($return) || $return === false || !is_array($return)) { $query = "SELECT SQL_CALC_FOUND_ROWS s.*, t.topicname, t.topicimage, t.topictext, u.user_id AS informant_id FROM nuke_stories AS s LEFT JOIN nuke_topics AS t ON s.topic = t.topicid LEFT JOIN nuke_users AS u ON s.informant = u.username WHERE s.topic = ? AND s.approved = ? ORDER BY s.time DESC LIMIT ?, ?"; $return = array(); $return['total'] = 0; $return['children'] = array(); $return['page'] = $page; $return['perpage'] = $limit; $return['topic_id'] = $this->id; if ($result = $this->db_readonly->fetchAll($query, array($this->id, "1", $page * $limit, $limit))) { $return['total'] = $this->db_readonly->fetchOne("SELECT FOUND_ROWS() AS total"); foreach ($result as $row) { if (function_exists("relative_date")) { $row['time_relative'] = relative_date(strtotime($row['time'])); } else { $row['time_relative'] = $row['time']; } $row['title'] = format_topictitle($row['title']); // Match the first sentence $line = explode("\n", $row['hometext']); $row['firstline'] = preg_replace('/([^?!.]*.).*/', '\\1', strip_tags($line[0])); if (empty($row['slug'])) { $row['slug'] = $this->createSlug($row['sid']); } $row['url'] = $this->makePermaLink($row['slug']); $return['children'][] = $row; } } setMemcacheObject($mckey, $return, $mcexp); } return $return; }
/** * Auto generate a competition for the next calendar month * @since Version 3.9.1 * @return \Railpage\Images\Competition */ public function autoPopulateNextComp() { $month = new DateTime("first day of next month"); $title = $month->format("F Y"); $Competition = new Competition($title); while (filter_var($Competition->id, FILTER_VALIDATE_INT)) { $month->add(new DateInterval("P1M")); $title = $month->format("F Y"); $Competition = new Competition($title); } /** * If the comp ID isn't a valid int assume we need to create a new comp */ if (!filter_var($Competition->id, FILTER_VALIDATE_INT)) { $Competition->title = $title; $Competition->SubmissionsDateOpen = clone $month; $Competition->SubmissionsDateClose = clone $month; $Competition->SubmissionsDateClose->add(new DateInterval("P14D")); $Competition->VotingDateOpen = clone $month; $Competition->VotingDateOpen->add(new DateInterval("P15D")); $Competition->VotingDateClose = clone $month; $Competition->VotingDateClose->add(new DateInterval("P1M"))->sub(new DateInterval("P1D")); $Competition->meta = array("maxvotes" => self::MAX_VOTES_PER_USER); /** * Get a suggested theme */ $themes = $this->getSuggestedThemes(); $themes = array_reverse($themes, true); foreach ($themes as $theme) { if (!isset($theme['used']) || $theme['used'] == false) { if (function_exists("format_topictitle")) { $theme['theme'] = format_topictitle($theme['theme']); } $Competition->theme = $theme['theme']; #sprintf("%s (suggested by %s)", $theme['theme'], $theme['user']['username']); if ($theme['winner'] == true) { break; } } } } return $Competition; }
/** * Constructor * @since Version 3.8.7 * @param int $id */ public function __construct($id = NULL) { parent::__construct(); $this->Module = new Module("images"); if (filter_var($id, FILTER_VALIDATE_INT)) { /** * Record this in the debug log */ debug_recordInstance(__CLASS__); $this->mckey = sprintf("railpage:image=%d", $id); if (!($row = getMemcacheObject($this->mckey))) { $query = "SELECT i.id, i.provider, i.photo_id, i.modified, i.meta, i.lat, i.lon FROM image AS i WHERE i.id = ?"; $row = $this->db->fetchRow($query, $id); $row['meta'] = json_decode($row['meta'], true); setMemcacheObject($this->mckey, $row, strtotime("+24 hours")); } $this->id = $id; $this->provider = $row['provider']; $this->photo_id = $row['photo_id']; $this->Date = new DateTime($row['modified']); $this->title = !empty($row['meta']['title']) ? format_topictitle($row['meta']['title']) : "Untitled"; $this->description = $row['meta']['description']; $this->sizes = $row['meta']['sizes']; $this->links = $row['meta']['links']; $this->meta = $row['meta']['data']; $this->url = new Url("/image?id=" . $this->id); if ($this->provider == "rpoldgallery") { $GalleryImage = new \Railpage\Gallery\Image($this->photo_id); $this->url->source = $GalleryImage->url->url; if (empty($this->meta['source'])) { $this->meta['source'] = $this->url->source; } } /** * Normalize some sizes */ if (count($this->sizes)) { if (!isset($this->sizes['thumb'])) { foreach ($this->sizes as $size) { if ($size['width'] >= 280 && $size['height'] >= 150) { $this->sizes['thumb'] = $size; break; } } } if (!isset($this->sizes['small'])) { foreach ($this->sizes as $size) { if ($size['width'] >= 500 && $size['height'] >= 281) { $this->sizes['small'] = $size; break; } } } $width = 0; foreach ($this->sizes as $size) { if ($size['width'] > $width) { $this->sizes['largest'] = $size; $width = $size['width']; } } foreach ($this->sizes as $size) { if ($size['width'] >= 1920) { $this->sizes['fullscreen'] = $size; break; } } foreach ($this->sizes as $size) { if ($size['width'] > 1024 && $size['width'] <= 1920) { $this->sizes['larger'] = $size; break; } } foreach ($this->sizes as $size) { if ($size['width'] == 1024) { $this->sizes['large'] = $size; break; } } foreach ($this->sizes as $size) { if ($size['width'] == 800) { $this->sizes['medium'] = $size; break; } } } if (isset($row['meta']['author'])) { $this->author = json_decode(json_encode($row['meta']['author'])); if (isset($this->author->railpage_id)) { $this->author->User = new User($this->author->railpage_id); } } else { $this->populate(true); } if (round($row['lat'], 3) != "0.000" && round($row['lon'], 3) != "0.000") { try { $this->Place = new Place($row['lat'], $row['lon']); } catch (Exception $e) { // Throw it away. Don't care. } } /** * Set the source URL */ if (isset($this->meta['source'])) { $this->source = $this->meta['source']; } else { switch ($this->provider) { case "flickr": $this->source = "https://flic.kr/p/" . base58_encode($this->photo_id); } } $this->getJSON(); } }
/** * Constructor * @since Version 3.0.1 * @version 3.0.1 * @param int $threadid * @param object $database */ function __construct($threadid = false) { if (RP_DEBUG) { global $site_debug; $debug_timer_start = microtime(true); } $this->starttime = time(); $this->Module = new Module("forums"); parent::__construct(); if (filter_var($threadid, FILTER_VALIDATE_INT)) { $query = "SELECT *, (SELECT COUNT(post_id) FROM nuke_bbposts WHERE topic_id = ?) AS num_posts FROM nuke_bbtopics WHERE topic_id = ? LIMIT 1"; // MGH 9/09/2014 - COUNT(post_id) added to properly calculate number of posts/replies $row = $this->db->fetchRow($query, array($threadid, $threadid)); } elseif (is_string($threadid)) { $query = "SELECT * FROM nuke_bbtopics WHERE url_slug = ? LIMIT 1"; $row = $this->db->fetchRow($query, $threadid); $row['num_posts'] = $this->db->fetchOne("SELECT COUNT(post_id) FROM nuke_bbposts WHERE topic_id = ?", $row['topic_id']); // MGH 9/09/2014 - COUNT(post_id) added to properly calculate number of posts/replies } if (isset($row) && is_array($row)) { $this->id = $row['topic_id']; $this->title = function_exists("format_topictitle") ? format_topictitle($row['topic_title']) : $row['topic_title']; $this->forum = new Forum($row['forum_id']); $this->url = new Url(sprintf("/f-t%d.htm", $this->id)); $this->Forum =& $this->forum; $this->starteruid = $row['topic_poster']; $this->starttime = $row['topic_time']; $this->views = $row['topic_views']; $this->replies = $row['num_posts'] - 1; $this->posts = $row['num_posts']; $this->status = $row['topic_status']; $this->firstpost = $row['topic_first_post_id']; $this->lastpost = $row['topic_last_post_id']; $this->type = $row['topic_type']; $this->url_slug = $row['url_slug']; $this->meta = isset($row['topic_meta']) ? json_decode($row['topic_meta'], true) : array(); if (empty($this->url_slug)) { $this->createSlug(); $this->commit(); } $this->DateStarted = new DateTime(sprintf("@%s", $row['topic_time'])); $this->DateStarted->setTimezone(new DateTimeZone("Australia/Melbourne")); if ($this->forum->id == 71) { $this->url->developers = sprintf("/%s/d/%s", "developers", $this->url_slug); } } if (RP_DEBUG) { $site_debug[] = __CLASS__ . "::" . __METHOD__ . " completed in " . round(microtime(true) - $debug_timer_start, 5) . "s"; } }
/** * Get the latest news items * @version 3.7.5 * @since Version 3.0 * @return mixed * @param int $number * @param int $offset */ public function latest($number = 5, $offset = 0) { $return = false; $mckey = "railpage:news.latest.count=" . $number . ".offset=" . $offset; $mcexp = strtotime("+5 minutes"); // Store for five minutes #removeMemcacheObject($mckey); $Sphinx = $this->getSphinx(); $query = $Sphinx->select("*")->from("idx_news_article")->orderBy("story_time_unix", "DESC")->where("story_active", "=", 1)->limit($offset, $number); $matches = $query->execute(); if (is_array($matches) && count($matches)) { foreach ($matches as $id => $row) { $row['time_relative'] = time2str($row['story_time_unix']); $row['time'] = time2str($row['story_time']); // Match the first sentence $line = explode("\n", str_replace("\r\n", "\n", $row['story_blurb'])); $row['firstline'] = strip_tags($line[0]); $row['hometext'] = wpautop(process_bbcode($row['story_blurb'])); $row['bodytext'] = wpautop(process_bbcode($row['story_body'])); $row['title'] = format_topictitle($row['story_title']); $row['featured_image'] = $row['story_image']; if (empty($row['slug'])) { $row['slug'] = $this->createSlug($row['story_id']); } $row['url'] = $this->makePermaLink($row['story_slug']); $matches[$id] = $row; } return $matches; } else { if (RP_DEBUG) { global $site_debug; $debug_timer_start = microtime(true); } if ($data = $this->getCache($mckey)) { // Do nothing, it's already been formatted and stored return $data; } else { if ($this->db instanceof \sql_db) { $query = "SELECT s.*, t.topicname, t.topicimage, t.topictext, u.user_id AS informant_id, u.user_id, u.username, u.user_avatar FROM nuke_stories s, nuke_topics t, nuke_users u WHERE u.user_id = s.user_id AND s.topic = t.topicid AND s.approved = 1 ORDER BY s.time DESC LIMIT " . $this->db->real_escape_string($offset) . ", " . $this->db->real_escape_string($number); if ($rs = $this->db->query($query)) { $return = array(); require_once "includes/functions.php"; while ($row = $rs->fetch_assoc()) { if (function_exists("relative_date")) { $row['time_relative'] = relative_date(strtotime($row['time'])); } else { $row['time_relative'] = $row['time']; } // Match the first sentence $line = explode("\n", str_replace("\r\n", "\n", $row['hometext'])); #$row['firstline'] = preg_replace('/([^?!.]*.).*/', '\\1', strip_tags($line[0])); $row['firstline'] = strip_tags($line[0]); $row['hometext'] = format_post($row['hometext']); $row['hometext'] = wpautop($row['hometext']); $return[] = $row; } $this->setCache($mckey, $return, $mcexp); return $return; } else { throw new \Exception($this->db->error . "\n\n" . $query); return false; } } else { $query = "SELECT s.*, t.topicname, t.topicimage, t.topictext, u.user_id AS informant_id, u.user_id, u.username, u.user_avatar \r\n\t\t\t\t\t\t\t\tFROM nuke_stories AS s\r\n\t\t\t\t\t\t\t\tLEFT JOIN nuke_topics AS t ON s.topic = t.topicid\r\n\t\t\t\t\t\t\t\tLEFT JOIN nuke_users AS u ON s.informant = u.username\r\n\t\t\t\t\t\t\t\tWHERE s.title != \"\"\r\n\t\t\t\t\t\t\t\tAND s.approved = ?\r\n\t\t\t\t\t\t\t\tORDER BY s.time DESC\r\n\t\t\t\t\t\t\t\tLIMIT ?, ?"; if ($result = $this->db_readonly->fetchAll($query, array("1", $offset, $number))) { $return = array(); foreach ($result as $row) { if (function_exists("relative_date")) { $row['time_relative'] = relative_date(strtotime($row['time'])); } else { $row['time_relative'] = $row['time']; } // Match the first sentence $line = explode("\n", str_replace("\r\n", "\n", $row['hometext'])); $row['firstline'] = strip_tags($line[0]); $row['hometext'] = format_post($row['hometext']); $row['hometext'] = wpautop($row['hometext']); if (empty($row['slug'])) { $row['slug'] = $this->createSlug($row['sid']); } $row['url'] = $this->makePermaLink($row['slug']); $return[] = $row; } $this->setCache($mckey, $return, $mcexp); if (RP_DEBUG) { $site_debug[] = "Zend_DB: SUCCESS select latest news articles in " . round(microtime(true) - $debug_timer_start, 5) . "s"; } return $return; } } } } }
/** * Render the page * @since Version 3.10.0 * @return string */ public function render() { if (!$this->userObject instanceof User) { throw new InvalidArgumentException("No valid user object has been provided"); } #$this->smarty->clearCache($this->template, $this->unique); if ($this->smarty->isCached($this->template, $this->unique)) { Debug::LogCLI("!! Template file " . $this->template . " is already cached for unique ID " . $this->unique); return $this->smarty->fetch($this->template, $this->unique); } Debug::LogCLI("Template file " . $this->template . " is NOT cached for unique ID \"" . $this->unique . "\""); /** * Get user alerts */ if (!$this->userObject->guest) { global $acl; $alerts = $this->userObject->getAlerts($acl); $this->smarty->Assign("alerts", $alerts, true); } /** * Get the latest jobs */ $newjobs = array(); foreach ((new Jobs())->yieldNewJobs(5) as $Job) { $newjobs[] = $Job->getArray(); } $this->smarty->Assign("jobs", $newjobs, true); /** * Upcoming events */ $Memcached = AppCore::GetMemcached(); $cachekey = "railpage.home.upcomingevents"; $upcoming = []; if (!($upcoming = $Memcached->fetch($cachekey))) { $Events = new Events(); $upcoming = []; foreach ($Events->getUpcomingEvents(5) as $row) { //$Event = EventsFactory::CreateEvent($row['event_id']); $EventDate = new EventDate($row['id']); $data = $EventDate->getArray(); $upcoming[] = $data; } $Memcached->save("railpage.home.upcomingevents", $upcoming, strtotime("+5 minutes")); } $this->smarty->Assign("upcomingevents", $upcoming); /** * New photos */ $this->smarty->Assign("newphotos", RecentImages::getNewest(5)); /** * Chronicle */ $Chronicle = new Chronicle(); $this->smarty->Assign("chronicle", $Chronicle->getEntriesForToday(10)); /** * Get the latest railcam photo */ $Camera = new Camera(1); $Photo = $Camera->getLatest(false); $railcam = $Photo->getArray(); $railcam['sizes']['small']['source'] = ImageCache::cache($railcam['sizes']['small']['source']); $this->smarty->Assign("railcam", $railcam); $this->smarty->Assign("railcam_updated", ContentUtility::relativeTime($railcam['dates']['taken'])); /** * First check if this user has a personalised news feed */ if (filter_var($this->userObject->id, FILTER_VALIDATE_INT) && $this->userObject->id > 0) { $Feed = new Feed(); $Feed->setUser($this->userObject)->getFilters(); if (count($Feed->filter_words) || count($Feed->filter_topics)) { $latest = $Feed->findArticles(0, 20); foreach ($latest as $id => $article) { $article['sid'] = $article['story_id']; $article['catid'] = $article['topic_id']; $article['hometext'] = preg_replace("@(\\[b\\]|\\[\\/b\\])@", "", $article['story_blurb']); $article['informant'] = $article['username']; $article['informant_id'] = $article['user_id']; $article['ForumThreadId'] = $article['forum_topic_id']; $article['topictext'] = $article['topic_title']; $article['topic'] = $article['topic_id']; $article['featured_image'] = $article['story_image']; $article['title'] = $article['story_title']; $article['time_relative'] = time2str($article['story_time_unix']); $latest[$id] = $article; } } } $this->smarty->Assign("personalfeed", isset($latest)); /** * No personal news feed - go ahead as normal */ if (!isset($latest)) { /** * Instantiate the base News module */ $News = new Base(); /** * Get the latest 15 news articles */ $latest = $News->latest(20); } /** * Format titles and tags for the latest news articles */ foreach ($latest as $id => $data) { /** * Load the JSON for this article */ if (!isset($data['sid'])) { $data['sid'] = $data['story_id']; } $json = json_decode(News::getArticleJSON($data['sid']), true); $latest[$id]['hometext'] = isset($json['article']['blub']) ? wpautop(process_bbcode($json['article']['blub'])) : wpautop(process_bbcode($json['article']['blurb'])); $latest[$id]['hometext'] = strip_tags($latest[$id]['hometext'], "<a><p><img><br><br /><strong><em>"); $latest[$id]['title'] = format_topictitle($data['title']); $latest[$id]['topic'] = $json['article']['topic']; $latest[$id]['topic_highlight'] = ColourUtility::String2Hex($latest[$id]['topic_title']); $latest[$id]['url'] = $json['article']['url']; $latest[$id]['author'] = $json['article']['author']; $latest[$id]['staff'] = $json['article']['staff']; if (!empty($latest[$id]['featured_image'])) { $latest[$id]['featured_image'] = ImageCache::cache($latest[$id]['featured_image']); } // Get the first paragraph from the home text preg_match("/<p>(.*)<\\/p>/", $latest[$id]['hometext'], $matches); $latest[$id]['hometext'] = strip_tags($matches[1]); if (empty($json['article']['body']) && !empty($json['article']['source'])) { $latest[$id]['url'] = $json['article']['source']; } /** * Pre-rendering */ $this->smarty->addHeadTag(sprintf("<link rel='prerender' href='%s'>", $json['article']['url']['url'])); } /** * Slice the first news article off */ $newsLatest = array_shift($latest); /** * Send them to Smarty */ $this->smarty->assign("newsLatest", $newsLatest); $this->smarty->assign("news", $latest); $this->smarty->assign("pagecontrols", '<p style="background: #333; background: rgba(0, 0, 0, 0.6);margin: -20px;padding: 10px;margin-top: 20px; text-align: center;">Wasting time and bandwidth since 1992</p>'); if ($this->params['handheld']) { $this->smarty->assign("pagecontrols", '<p style="background: #333; background: rgba(0, 0, 0, 0.6);margin: 0px -20px;padding: 0px;margin-top: 40px; text-align: center;font-size:1em;">Wasting time and bandwidth since 1992</p>'); } return $this->smarty->fetch($this->template, $this->unique); }
/** * Constructor * @since Version 3.0.1 * @version 3.0.1 * @param int $threadid * @param object $database */ function __construct($threadid = false) { if (RP_DEBUG) { global $site_debug; $debug_timer_start = microtime(true); } $this->starttime = time(); $this->Module = new Module("forums"); parent::__construct(); if (filter_var($threadid, FILTER_VALIDATE_INT)) { $query = "SELECT *, (SELECT COUNT(post_id) FROM nuke_bbposts WHERE topic_id = ?) AS num_posts FROM nuke_bbtopics WHERE topic_id = ? LIMIT 1"; // MGH 9/09/2014 - COUNT(post_id) added to properly calculate number of posts/replies $row = $this->db->fetchRow($query, array($threadid, $threadid)); } elseif (is_string($threadid)) { $query = "SELECT * FROM nuke_bbtopics WHERE url_slug = ? LIMIT 1"; $row = $this->db->fetchRow($query, $threadid); $row['num_posts'] = $this->db->fetchOne("SELECT COUNT(post_id) FROM nuke_bbposts WHERE topic_id = ?", $row['topic_id']); // MGH 9/09/2014 - COUNT(post_id) added to properly calculate number of posts/replies } if (isset($row) && is_array($row)) { $this->id = $row['topic_id']; $this->title = format_topictitle(str_replace("Re: ", "", $row["topic_title"])); $this->forum = new Forum($row['forum_id']); $this->url = new Url(sprintf("/f-t%d.htm", $this->id)); $this->Forum =& $this->forum; $this->starteruid = $row['topic_poster']; $this->starttime = $row['topic_time']; $this->views = $row['topic_views']; $this->replies = $row['num_posts'] - 1; $this->posts = $row['num_posts']; $this->status = $row['topic_status']; $this->firstpost = $row['topic_first_post_id']; $this->lastpost = $row['topic_last_post_id']; $this->type = $row['topic_type']; $this->url_slug = $row['url_slug']; if (empty($this->url_slug)) { $this->createSlug(); $this->commit(); } $this->DateStarted = new DateTime(sprintf("@%s", $row['topic_time'])); $this->DateStarted->setTimezone(new DateTimeZone("Australia/Melbourne")); if ($this->forum->id == 71) { $this->url->developers = sprintf("/%s/d/%s", "developers", $this->url_slug); } /** * Get highlighted posts within this thread */ /* if (!$highlights = getMemcacheObject(sprintf("railpage.highlighted.thread=%d", $this->id))) { $query = "SELECT post_id FROM nuke_bbposts WHERE topic_id = ? AND post_rating > 0"; $highlights = $this->db->fetchAll($query, $this->id); if (!is_array($highlights)) { $highlights = array(); } @setMemcacheObject(sprintf("railpage.highlighted.thread=%d", $this->id), $highlights); } foreach ($highlights as $row) { $this->highlights[] = $row['post_id']; } if (count($this->highlights)) { $this->highlighted = true; } */ /** * Get poll data from this thread * So totally deprecated. Let's just comment out this code and see what breaks... 6/09/2014 MGH */ /** if ($this->db instanceof \sql_db) { // Poll data $query = "SELECT v.vote_id, v.vote_text, v.vote_start, v.vote_length, vr.vote_option_id, vr.vote_option_text, vr.vote_result, vt.vote_user_id FROM nuke_bbvote_desc AS v LEFT JOIN nuke_bbvote_results AS vr ON vr.vote_id = v.vote_id LEFT JOIN nuke_bbvote_voters AS vt ON vt.vote_id = v.vote_id WHERE v.topic_id = ".$this->id; if ($rs = $this->db->query($query)) { if ($rs->num_rows > 0) { // We have a poll! $polldata = array(); while ($row = $rs->fetch_assoc()) { $polldata['id'] = $row['vote_id']; $polldata['question'] = $row['vote_text']; $polldata['start'] = $row['vote_start']; $polldata['finish'] = $row['vote_start'] + $row['vote_length']; if (is_array($polldata['voters'])) { if (!in_array($row['vote_user_id'], $polldata['voters'])) { $polldata['voters'][] = $row['vote_user_id']; } } $polldata['options'][$row['vote_option_id']]['option'] = $row['vote_option_text']; $polldata['options'][$row['vote_option_id']]['votes'] = $row['vote_result']; } $this->polldata = $polldata; } } else { throw new Exception($this->db->error); } } else { // Complete this later } */ } if (RP_DEBUG) { $site_debug[] = __CLASS__ . "::" . __METHOD__ . " completed in " . round(microtime(true) - $debug_timer_start, 5) . "s"; } }
/** * Most read articles this week * @version 3.0 * @since Version 3.2 * @return mixed * @param int $limit */ public function mostReadThisWeek($limit = 5) { $return = false; $params = array(); if (isset($this->id) && filter_var($this->id, FILTER_VALIDATE_INT)) { $topic_sql = "AND s.topic = ?"; $params[] = $this->id; } else { $topic_sql = NULL; } $query = "SELECT s.*, t.topictext, t.topicname FROM nuke_stories s, nuke_topics t WHERE s.topic = t.topicid " . $topic_sql . " AND s.weeklycounter > 0 ORDER BY s.weeklycounter DESC LIMIT 0, ?"; $params[] = $limit; if ($result = $this->db_readonly->fetchAll($query, $params)) { $return = array(); foreach ($result as $row) { if (function_exists("relative_date")) { $row['time_relative'] = relative_date(strtotime($row['time'])); } else { $row['time_relative'] = $row['time']; } // Match the first sentence $line = explode("\n", str_replace("\r\n", "\n", !empty($row['lead']) ? $row['lead'] : $row['hometext'])); $row['firstline'] = trim(strip_tags($line[0])); $row['story_lead'] = !empty($row['lead']) ? $row['lead'] : $row['hometext']; $row['story_body'] = !empty($row['paragraphs']) ? $row['paragraphs'] : $row['bodytext']; $row['hometext'] = wpautop(process_bbcode(!empty($row['lead']) ? $row['lead'] : $row['hometext'])); $row['bodytext'] = wpautop(process_bbcode(!empty($row['paragraphs']) ? $row['paragraphs'] : $row['bodytext'])); $row['title'] = format_topictitle($row['title']); if (empty($row['slug'])) { $row['slug'] = $this->createSlug($row['sid']); } $row['url'] = $this->makePermaLink($row['slug']); $return[] = $row; } } return $return; }