示例#1
0
 $row =& $rowset[$post_list[$i]];
 $poster_id = $row['user_id'];
 // End signature parsing, only if needed
 if ($user_cache[$poster_id]['sig'] && $row['enable_sig'] && empty($user_cache[$poster_id]['sig_parsed'])) {
     $user_cache[$poster_id]['sig'] = censor_text($user_cache[$poster_id]['sig']);
     if ($user_cache[$poster_id]['sig_bbcode_bitfield']) {
         $bbcode->bbcode_second_pass($user_cache[$poster_id]['sig'], $user_cache[$poster_id]['sig_bbcode_uid'], $user_cache[$poster_id]['sig_bbcode_bitfield']);
     }
     $user_cache[$poster_id]['sig'] = bbcode_nl2br($user_cache[$poster_id]['sig']);
     $user_cache[$poster_id]['sig'] = smiley_text($user_cache[$poster_id]['sig']);
     $user_cache[$poster_id]['sig_parsed'] = true;
 }
 // Parse the message and subject
 $message = censor_text($row['post_text']);
 // tapatalk add for bbcode pretreatment
 $message = process_bbcode($message, $row['bbcode_uid']);
 // Second parse bbcode here
 if ($row['bbcode_bitfield']) {
     $bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
 }
 $message = bbcode_nl2br($message);
 $message = smiley_text($message);
 if (!empty($attachments[$row['post_id']])) {
     $config['img_link_width'] = $config['img_link_height'] = 100000;
     // tapatalk add
     parse_attachments($forum_id, $message, $attachments[$row['post_id']], $update_count);
 }
 // Replace naughty words such as farty pants
 $row['post_subject'] = censor_text($row['post_subject']);
 // Highlight active words (primarily for search)
 if ($highlight_match) {
示例#2
0
 /**
  * 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;
                 }
             }
         }
     }
 }
示例#3
0
 /**
  * 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);
 }
示例#4
0
 /**
  * Get and personalise the content for this newsletter
  * @since Version 3.10.0
  * @return \Railpage\Newsletters\Weekly
  */
 private function personaliseContent()
 {
     $replacements = array();
     Debug::LogCLI("Looping through " . count($this->recipients) . " users and preparing email decoration");
     $this->user_ids = array();
     $counter = 0;
     /**
      * Loop through our list of users and start to curate the contents
      */
     foreach ($this->recipients as $row) {
         // Flag this user ID so that we can update the "last sent" timestamp later
         $user_ids[] = $row['user_id'];
         // Sanity check : validate the email address first
         if (!filter_var($row['user_email'], FILTER_VALIDATE_EMAIL)) {
             Debug::LogCLI("Skipping user ID " . $row['user_id'] . " - \"" . $row['user_email'] . "\" is not a valid email address");
             continue;
         }
         // Add the recipient
         $this->Notification->addRecipient($row['user_id'], $row['username'], $row['user_email']);
         // Assign some decoration
         $replacements[$row['user_email']] = array("##username##" => $row['username'], "##email##" => $row['user_email'], "##email_encoded##" => urlencode($row['user_email']), "##unsubscribe##" => sprintf("http://railpage.com.au/unsubscribe?email=%s&newsletter=weekly", urlencode($row['user_email'])));
         /**
          * Get the custom news feed articles
          */
         Debug::LogCLI("Preparing personalised news for user ID " . $row['user_id']);
         // Try and create the user object. If it bombs out, we need to know about it but let the newsletter continue
         try {
             $User = UserFactory::CreateUser($row['user_id']);
         } catch (Exception $e) {
             Debug::LogCLI("Skipped user due to exception: " . $e->getMessage());
             continue;
         }
         // Create the custom news feed object
         $Feed = new Feed();
         $Feed->setUser($User);
         $articles = $Feed->addFilter(Feed::FILTER_UNREAD)->addFilter(Feed::FILTER_LAST_30_DAYS)->findArticles(0, 10, "story_hits");
         // If the number of personalised articles is less than ten, drop the filter and simply find ten recent and unread articles
         if (count($articles) < 10) {
             Debug::LogCLI("Found " . count($articles) . " articles for user ID " . $User->id . " - dropping keyword and topic filter from feed");
             $Feed->filter_words = null;
             $Feed->filter_topics = null;
             $articles = $Feed->findArticles(0, 10, "story_hits");
         }
         // If we have less than six articles skip this user altogether.
         if (count($articles) < 6) {
             Debug::LogCLI("Found " . count($articles) . " articles for user ID " . $User->id . " - skipping");
             continue;
         }
         Debug::LogCLI("Proceeding with newsletter for user ID " . $User->id);
         // Loop through each article and normalise the content
         foreach ($articles 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'] = ContentUtility::FormatTitle($article['topic_title']);
             $article['topic'] = $article['topic_id'];
             $article['featured_image'] = ImageCache::cache($article['story_image']);
             $article['title'] = $article['story_title'];
             $article['url'] = NewsletterUtility::CreateUTMParametersForLink($this->Newsletter, $article['url']);
             $articles[$id] = $article;
         }
         $articles = array_values($articles);
         if (!isset($start)) {
             $start = 0;
         }
         // Loop through the prepended content and assign it to the blocks
         foreach ($this->prependedContent as $i => $block) {
             $tmp = ["##block" . $i . ".subtitle##" => $block['title'], "##block" . $i . ".featuredimage##" => $block['featuredimage'], "##block" . $i . ".text##" => strip_tags(wpautop(process_bbcode($block['text'])), "<br><br /><p>"), "##block" . $i . ".link##" => strpos($block['url'], "http") === false ? "http://www.railpage.com.au" . $block['url'] : $block['url'], "##block" . $i . ".alt_title##" => $block['subtitle'], "##block" . $i . ".link_text##" => isset($block['link_text']) && !empty($block['link_text']) ? $block['link_text'] : "Continue reading"];
             $replacements[$row['user_email']] = array_merge($replacements[$row['user_email']], $tmp);
         }
         // Loop through our content and assign to content blocks
         for ($i = count($this->prependedContent) + $start; $i < $start + $this->num_items; $i++) {
             $Date = new DateTime($articles[$i]['story_time']);
             $tmp = ["##block" . $i . ".subtitle##" => $articles[$i]['story_title'], "##block" . $i . ".featuredimage##" => $articles[$i]['story_image'], "##block" . $i . ".text##" => strip_tags(wpautop(process_bbcode($articles[$i]['story_lead'])), "<br><br /><p>"), "##block" . $i . ".link##" => strpos($articles[$i]['url'], "http") === false ? "http://www.railpage.com.au" . $articles[$i]['url'] : $articles[$i]['url'], "##block" . $i . ".alt_title##" => sprintf("Published %s", $Date->format("F j, Y, g:i a")), "##block" . $i . ".link_text##" => "Continue reading"];
             $replacements[$row['user_email']] = array_merge($replacements[$row['user_email']], $tmp);
         }
         Debug::LogCLI("Completed personalisation of newsletter for user ID " . $User->id);
         // Increment our personalised newsletter counter
         $counter++;
         /**
          * Break after 150 recipients. Don't want to be flagged as a spammer, or overload the MTA
          */
         if ($counter == 150) {
             break;
         }
     }
     $this->replacements = $replacements;
     return $this;
 }
示例#5
0
 /**
  * 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;
 }