Пример #1
0
 /**
  * Notify the winner
  * @since Version 3.9.1
  * @return \Railpage\Gallery\Competition
  * @param \Railpage\Images\Competition
  * @todo Check recipient preferences for email notifications
  */
 public static function notifyWinner(Competition $compObject)
 {
     if (isset($compObject->meta['winnernotified']) && $compObject->meta['winnernotified'] === true) {
         return $this;
     }
     if ($Photo = $compObject->getWinningPhoto()) {
         /**
          * Create a news article
          */
         CompetitionUtility::createNewsArticle_Winner($compObject);
         /**
          * Create a site message
          */
         CompetitionUtility::createSiteNotificationForWinner($compObject);
         /**
          * Create an email
          */
         $Notification = new Notification();
         $Notification->AddRecipient($Photo->Author->id, $Photo->Author->username, $Photo->Author->contact_email);
         $Notification->subject = sprintf("Photo competition: %s", $compObject->title);
         /**
          * Set our email body
          */
         $body = sprintf("Hi %s,\n\nCongratulations! You won the <a href='%s'>%s</a> photo competition!\n\nAs the winner of this competition, you get to <a href='%s'>select a theme</a> for the next competition. You have seven days to do so, before we automatically select one.\n\nThanks\nThe Railpage team.", $Photo->Author->username, $compObject->url->canonical, $compObject->title, "https://www.railpage.com.au" . $compObject->url->suggestsubject);
         if (function_exists("wpautop") && function_exists("format_post")) {
             $body = wpautop(format_post($body));
         }
         /**
          * Assemble some template vars for our email
          */
         foreach ($Photo->Image->sizes as $size) {
             $hero = $size['source'];
             if ($size['width'] >= 600) {
                 break;
             }
         }
         $Smarty = AppCore::getSmarty();
         $Smarty->Assign("email", array("subject" => $Notification->subject, "hero" => array("image" => $hero, "title" => sprintf("Winning photo: Yours! <em>%s</em>", $Photo->Image->title), "link" => $compObject->url->url, "author" => $Photo->Author->username), "body" => $body));
         $Notification->body = $Smarty->Fetch($Smarty->ResolveTemplate("template.generic"));
         $Notification->commit();
         /**
          * Update the winnernotified flag
          */
         $compObject->meta['winnernotified'] = true;
         $compObject->commit();
     }
     return $compObject;
 }
Пример #2
0
 /**
  * Get the formatted lead text for this article
  * @since Version 3.10.0
  * @param \Railpage\News\Article $Article
  * @param string $section The section of the article (lead or paragraphs) to format
  * @return string
  */
 public static function FormatArticleText($Article, $section = "lead")
 {
     $Memcached = AppCore::GetMemcached();
     $cachekey = $section == "lead" ? Article::CACHE_KEY_FORMAT_LEAD : Article::CACHE_KEY_FORMAT_PARAGRAPHS;
     $cachekey = sprintf($cachekey, $Article->id);
     $whitespace_find = array("<p> </p>", "<p></p>", "<p>&nbsp;</p>");
     $whitespace_replace = array("", "", "");
     #$Memcached->delete($cachekey);
     if (!($text = $Memcached->Fetch($cachekey))) {
         $text = $section == "lead" ? $Article->getLead() : $Article->getParagraphs();
         if (function_exists("format_post")) {
             $text = str_replace($whitespace_find, $whitespace_replace, $text);
             $text = format_post($text);
             if (is_object($text)) {
                 $text = $text->__toString();
             }
             $Memcached->save($cachekey, $text, 0);
         }
     }
     return $text;
 }
         if ($row["icq"] == "") {
             $gastbook['icq'] = "";
         } else {
             $gastbook['icq'] = "<a href=\"http://wwp.icq.com/" . htmlspecialchars($row["icq"]) . "#pager\" target=\"_blank\"><font size=\"1\" face=\"Tahoma\">" . htmlspecialchars($row["icq"]) . "</font></a>";
         }
         if ($row["aim"] == "") {
             $gastbook['aim'] = "";
         } else {
             $gastbook['aim'] = "<a href=\"aim:goim?screenname=" . htmlspecialchars($row["aim"]) . "&message=Hi+" . htmlspecialchars($row["aim"]) . ".+Are+you+there?\" target=\"_blank\"><font size=\"1\" face=\"Arial\">" . htmlspecialchars($row["aim"]) . "</font></a>";
         }
         if ($row["yahoo"] == "") {
             $gastbook['yahoo'] = "";
         } else {
             $gastbook['yahoo'] = "<a href=\"http://edit.yahoo.com/config/send_webmesg?.target=" . htmlspecialchars($row["yahoo"]) . "&.src=pg\" target=\"_blank\"><font size=\"1\" face=\"Tahoma\">" . htmlspecialchars($row["yahoo"]) . "</font></a>";
         }
         $gastbook['massege'] = format_post($gastbook['massege'], 0, 1);
         $gastbook['name'] = $row['name'];
         $gastbook['tag'] = wochentag(strtotime($row['datum']));
         $gastbook['jahr'] = date('d.m.Y', strtotime($row['datum']));
         $gastbook['uhr'] = date('H:i:s', strtotime($row['datum']));
         $gastbook['id'] = $row['id'];
         $guestbookentrie[$i] = $gastbook;
         $smarty->assign("guestbookentrie", $guestbookentrie);
         $i++;
         $iRow = $iRow + 1;
     }
     $smarty->assign("gastbooklinkleiste", $gastbook['linkleiste']);
     $smarty->assign("neuer_eintrag", $_GET['neu']);
     $smarty->display("community_gaestebuch.tpl.php");
     break;
 case "chat":
Пример #4
0
 /**
  * Return news article text
  * @since Version 3.0.1
  * @version 3.4
  * @param int $id
  * @return mixed
  */
 public function fetch($id = false)
 {
     if ($id) {
         $this->id = $id;
     }
     if (!$this->id) {
         throw new Exception("Cannot fetch news article - no ID given");
         return false;
     }
     $return = false;
     $mckey = __METHOD__ . "-" . $this->id;
     $mcexp = strtotime("+1 hour");
     /*
     if ($this->pending === false && $this->memcache && $return = $this->memcache->get($mckey)) {
     	// Do nothing
     	printArray($return);die;
     } else {
     */
     if ($this->db instanceof \sql_db) {
         if ($this->pending == true) {
             // Get story from pending table
             $query = "SELECT u.username, 0 AS sent_to_fb, p.geo_lat, p.geo_lon, p.qid as sid, p.uname as informant, p.subject as title, p.story as hometext, p.storyext as bodytext, p.topic, p.source, t.topicname, t.topicimage, t.topictext, p.timestamp as time FROM nuke_users u, nuke_queue p, nuke_topics t WHERE p.topic = t.topicid AND p.uid = u.user_id AND p.qid = '" . $this->db->real_escape_string($this->id) . "'";
             $table = "pending";
         } else {
             $query = "SELECT s.*, t.topicname, t.topicimage, t.topictext, t.topicid FROM nuke_stories s, nuke_topics t WHERE s.topic = t.topicid AND s.sid = '" . $this->db->real_escape_string($this->id) . "'";
             $table = "published";
         }
         if ($rs = $this->db->query($query)) {
             if ($rs->num_rows == 0) {
                 throw new Exception("Cannot fetch " . $table . " article ID " . $this->id . " - no story found");
                 return false;
             }
             $return = $rs->fetch_assoc();
             if ($this->pending === false && $this->memcache) {
                 $this->memcache->set($mckey, $return, $mcexp);
             }
         }
     } else {
         if ($this->pending == true) {
             $query = "SELECT q.qid AS sid, q.uid AS user_id, u.username, q.subject AS title, q.story AS hometext, q.storyext AS bodytext, q.timestamp AS time, q.source, t.topicname, t.topictext, q.topic, 'oldqueue' AS queue\r\n\t\t\t\t\t\t\t\tFROM nuke_queue AS q\r\n\t\t\t\t\t\t\t\tLEFT JOIN nuke_topics AS t ON q.topic = t.topicid\r\n\t\t\t\t\t\t\t\tLEFT JOIN nuke_users AS u ON q.uid = u.user_id\r\n\t\t\t\t\t\t\t\tWHERE q.qid = ?";
         } else {
             $query = "SELECT s.*, t.topicname, t.topicimage, t.topictext, t.topicid \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\tWHERE s.sid = ?";
         }
         $return = $this->db_readonly->fetchRow($query, $this->id);
     }
     /*
     }
     */
     if (isset($return) && is_array($return) && !empty($return)) {
         $this->title = $return['title'];
         $this->blurb = $return['hometext'];
         $this->body = $return['bodytext'];
         $this->date = new DateTime($return['time']);
         $this->hits = isset($return['weeklycounter']) ? intval($return['weeklycounter']) : 0;
         $this->Topic = new Topic($return['topic']);
         $this->user_id = isset($return['user_id']) ? intval($return['user_id']) : 0;
         $this->staff_user_id = isset($return['staff_id']) ? intval($return['staff_id']) : 0;
         $this->topic_id = isset($return['ForumThreadID']) ? intval($return['ForumThreadID']) : 0;
         $this->source = $return['source'];
         $this->approved = isset($return['approved']) ? (bool) $return['approved'] : false;
         $this->sent_to_fb = isset($return['sent_to_fb']) ? (bool) $return['sent_to_fb'] : false;
         $this->featured_image = isset($return['featured_image']) ? $return['featured_image'] : false;
         if (isset($return['geo_lat']) && !empty($return['geo_lat']) && isset($return['geo_lon']) && !empty($return['geo_lon'])) {
             $this->lat = $return['geo_lat'];
             $this->lon = $return['geo_lon'];
         }
         if (empty($return['slug'])) {
             $return['slug'] = $this->createSlug();
         }
         $this->slug = $return['slug'];
         $this->url = new Url($this->makePermaLink($this->slug));
         $this->blurb_clean = format_post($this->blurb, false, false, true, true, true);
         $this->body_clean = format_post($this->body, false, false, true, true, true);
         $this->setAuthor(new User($this->user_id));
         $this->username = $this->Author->username;
         $this->setStaff(new User($this->staff_user_id));
         $this->staff_username = $this->Staff->username;
         // Rest of this shit is for backwards compatibility
         $whitespace_find = array("<p> </p>", "<p></p>", "<p>&nbsp;</p>");
         $whitespace_replace = array("", "", "");
         #$return['hometext'] = format_post(str_replace($whitespace_find, $whitespace_replace, $return['hometext']));
         #$return['bodytext'] = format_post(str_replace($whitespace_find, $whitespace_replace, $return['bodytext']));
         #$return['hometext'] = convert_to_utf8($return['hometext']);
         #$return['bodytext'] = convert_to_utf8($return['bodytext']);
         #$return['hometext'] = wpautop($return['hometext']);
         #$return['bodytext'] = process_multimedia(wpautop($return['bodytext']));
         try {
             $this->fwlink = new \Railpage\fwlink($this->url);
             if (empty($this->fwlink->url)) {
                 $this->fwlink->url = $this->url;
                 $this->fwlink->title = $this->title;
                 $this->fwlink->commit();
             }
         } catch (Exception $e) {
             global $Error;
             $Error->save($e);
         }
     } else {
         #throw new Exception($this->db->error."\n\n".$query);
         throw new Exception(sprintf("Cannot find news article #%d", $this->id));
         return false;
     }
     return $return;
 }
Пример #5
0
function get_post($id, $format = true)
{
    // we have no id
    if (!$id || !filter_var($id, FILTER_VALIDATE_INT)) {
        return array();
    }
    global $db;
    try {
        $query = $db->prepare("\n            SELECT p.id, p.user_id, p.title, p.text, p.created_at, p.has_image,\n                   u.email AS user_email,\n                   u.name AS user_name,\n                   array_to_string(array_agg(t.tag), '|') AS tags\n            FROM posts p\n            LEFT JOIN posts_tags pt ON (p.id = pt.post_id)\n            LEFT JOIN tags t ON (t.id = pt.tag_id)\n            LEFT JOIN users u ON (u.id = p.user_id)\n            WHERE p.id = :id\n            GROUP BY p.id, p.user_id, p.title, p.text, p.created_at, p.has_image, u.email, u.name\n            ORDER BY p.created_at DESC\n        ");
        $query->execute(array('id' => $id));
    } catch (PDOException $e) {
        return array();
    }
    if ($query->rowCount() === 1) {
        $post = $query->fetch(PDO::FETCH_ASSOC);
        if ($format) {
            $post = format_post($post);
        }
        return $post;
    }
    return array();
}
Пример #6
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;
                 }
             }
         }
     }
 }
Пример #7
0
 /**
  * Send an email notification for this competition
  * @since Version 3.9.1
  * @param \Railpage\Images\Competition $photoComp
  * @param array $notificationOptions
  * @return void
  * @todo Finish push notifications
  */
 public static function sendNotification(Competition $photoComp, $notificationOptions)
 {
     if (count((new Competitions())->getPreviousContestants()) == 0) {
         return false;
     }
     $flag = $notificationOptions['flag'];
     if (!is_array($notificationOptions)) {
         $notificationOptions = [];
     }
     // If we want to exclude contestants in this competition from this email, set this to true
     // This is to remind contestants from previous comps to submit a photo
     if (!isset($notificationOptions['excludeCurrentContestants'])) {
         $notificationOptions['excludeCurrentContestants'] = false;
     }
     /**
      * Check if the notification sent flag has been set
      */
     if (!isset($photoComp->meta[$flag]) || !filter_var($photoComp->meta[$flag]) || $photoComp->meta[$flag] === false) {
         /**
          * Create the notification
          */
         $Notification = new Notification();
         $Notification->subject = $notificationOptions['subject'];
         $Push = new Notification();
         $Push->subject = $Notification->subject;
         $Push->transport = Notifications::TRANSPORT_PUSH;
         /**
          * Add recipients and decoration
          */
         $Notification = self::notificationDoRecipients($Notification, $photoComp, $notificationOptions);
         $Push = self::notificationDoRecipients($Push, $photoComp, $notificationOptions);
         /**
          * Set our email body
          */
         if (function_exists("wpautop") && function_exists("format_post")) {
             $notificationOptions['body'] = wpautop(format_post($notificationOptions['body']));
         }
         /**
          * Assemble some template vars for our email
          */
         $Smarty = AppCore::getSmarty();
         $Smarty->Assign("email", array("subject" => $notificationOptions['subject'], "body" => $notificationOptions['body']));
         /**
          * Set the body, submit the notification to the dispatch queue
          */
         $Notification->body = $Smarty->Fetch($Smarty->ResolveTemplate("template.generic"));
         $Notification->commit();
         /**
          * Set the notification flag
          */
         $photoComp->meta[$flag] = true;
         $photoComp->commit();
     }
 }
Пример #8
0
 /**
  * Filter jobs
  * @since Version 3.8
  * @param array $args
  * @return array
  */
 public function filter($args = false)
 {
     if ($args === false) {
         $args = array();
     }
     if (!is_array($args)) {
         throw new Exception("Cannot filter jobs - incorrect filter given");
         return false;
     }
     if ($this->db instanceof \sql_db) {
         $query = "SELECT j.*, jc.jn_classification_name AS job_classification_name, o.organisation_name , jl.jn_location_name AS job_location_name\r\n\t\t\t\t\tFROM jn_jobs AS j \r\n\t\t\t\t\t\tINNER JOIN jn_classifications AS jc ON j.job_classification_id = jc.jn_classification_id\r\n\t\t\t\t\t\tINNER JOIN organisation AS o ON j.organisation_id = o.organisation_id\r\n\t\t\t\t\t\tINNER JOIN jn_locations AS jl ON j.job_location_id = jl.jn_location_id ";
         $where = array();
         $salary_min = isset($args['job_salary_min']) ? $args['job_salary_min'] : false;
         $salary_max = isset($args['job_salary_max']) ? $args['job_salary_max'] : false;
         foreach ($args as $column => $value) {
             if (!empty($value) && $column != "job_salary_min" && $column != "job_salary_max") {
                 $where[] = "j." . $column . " = '" . $this->db->real_escape_string($value) . "'";
             }
         }
         if ($salary_min) {
             $where[] = "j.job_salary >= " . $this->db->real_escape_string($salary_min);
         }
         if ($salary_max) {
             $where[] = "j.job_salary <= " . $this->db->real_escape_string($salary_max);
         }
         if (count($where)) {
             $query .= " WHERE " . implode(" AND ", $where);
         }
         $query .= " ORDER BY j.job_expiry ASC";
         if ($rs = $this->db->query($query)) {
             $return = array();
             $return['args'] = $args;
             $return['count'] = $rs->num_rows;
             while ($row = $rs->fetch_assoc()) {
                 $row['job_description'] = format_post($row['job_description']);
                 $return['jobs'][$row['job_id']] = $row;
             }
             return $return;
         } else {
             throw new Exception($this->db->error);
             return false;
         }
     } else {
         // Assume Zend_Db
         $query = "SELECT j.*, jc.jn_classification_name AS job_classification_name, o.organisation_name , jl.jn_location_name AS job_location_name\r\n\t\t\t\t\tFROM jn_jobs AS j \r\n\t\t\t\t\t\tINNER JOIN jn_classifications AS jc ON j.job_classification_id = jc.jn_classification_id\r\n\t\t\t\t\t\tINNER JOIN organisation AS o ON j.organisation_id = o.organisation_id\r\n\t\t\t\t\t\tINNER JOIN jn_locations AS jl ON j.job_location_id = jl.jn_location_id ";
         $where = array();
         $params = array();
         $salary_min = isset($args['job_salary_min']) ? $args['job_salary_min'] : false;
         $salary_max = isset($args['job_salary_max']) ? $args['job_salary_max'] : false;
         foreach ($args as $column => $value) {
             if (!empty($value) && $column != "job_salary_min" && $column != "job_salary_max") {
                 $where[] = "j." . $column . " = ?";
                 $params[] = $value;
             }
         }
         if ($salary_min) {
             $where[] = "j.job_salary >= ?";
             $params[] = $salary_min;
         }
         if ($salary_max) {
             $where[] = "j.job_salary <= ?";
             $params[] = $salary_max;
         }
         $where[] = "j.job_expiry > ?";
         $params[] = date("Y-m-d H:i:s");
         #printArray($where);printArray($params);die;
         if (count($where)) {
             $query .= " WHERE " . implode(" AND ", $where);
         }
         $query .= " ORDER BY j.job_expiry ASC";
         #printArray($query);die;
         if ($result = $this->db->fetchAll($query, $params)) {
             $return = array();
             $return = array();
             $return['args'] = $args;
             $return['count'] = count($result);
             foreach ($result as $row) {
                 $row['job_description'] = format_post($row['job_description']);
                 $return['jobs'][$row['job_id']] = $row;
             }
             return $return;
         }
     }
 }
Пример #9
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
     $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();
     /**
      * Attempt to fetch from Sphinx first
      */
     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", !empty($row['story_lead']) ? $row['story_lead'] : $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;
     }
     /**
      * Fall back to database query
      */
     if (!($data = $this->Memcached->fetch($mckey))) {
         $timer = Debug::GetTimer();
         $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                        FROM nuke_stories AS s\r\n                        LEFT JOIN nuke_topics AS t ON s.topic = t.topicid\r\n                        LEFT JOIN nuke_users AS u ON s.informant = u.username\r\n                        WHERE s.title != \"\"\r\n                        AND s.approved = ?\r\n                        ORDER BY s.time DESC\r\n                        LIMIT ?, ?";
         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->Memcached->save($mckey, $return, $mcexp);
             Debug::LogEvent(__METHOD__, $timer);
         }
         return $return;
     }
 }
Пример #10
0
 /**
  * Return additional head tags in a concatenated string
  * @since Version 3.8 
  * @return string
  */
 public function getHeadTags()
 {
     $tags = array();
     if (count($this->rp_meta_tags)) {
         foreach ($this->rp_meta_tags as $property => $content) {
             $tag = '<meta property="' . $property . '" content="' . htmlentities(format_post($content, false, false, false, false, true)) . '">';
             if ($property == "og:image" || $property == "twitter:image") {
                 $tag = str_replace("&amp;", "&", $tag);
             }
             $tags[] = $tag;
         }
     }
     if (count($this->head_links)) {
         foreach ($this->head_links as $rel => $href) {
             $tag = '<link rel="' . $rel . '" href="' . htmlentities($href) . '">';
             $tags[] = $tag;
         }
     }
     if (count($this->preload['prefetch'])) {
         foreach ($this->preload['prefetch'] as $href) {
             $tag = '<link rel="prefetch" href="' . htmlentities($href) . '">';
             $tags[] = $tag;
         }
     }
     if (count($this->preload['prerender'])) {
         foreach ($this->preload['prerender'] as $href) {
             $tag = '<link rel="prerender" href="' . htmlentities($href) . '">';
             $tags[] = $tag;
         }
     }
     return implode("\n\t", array_merge($tags, $this->head_tags));
 }
Пример #11
0
 /**
  * Get a standardised array of this data
  * @since Version 3.9.1
  * @return array
  */
 public function getArray()
 {
     $idea = array("id" => $this->id, "title" => $this->title, "description" => function_exists("format_post") ? format_post($this->description) : $this->description, "status" => Ideas::getStatusDescription($this->status), "url" => $this->url->getURLs(), "votes" => array("num" => $this->getVotes(), "text" => $this->getVotes() == 1 ? "1 vote" : sprintf("%d votes", $this->getVotes())), "date" => array("absolute" => $this->User instanceof User ? $this->Date->format($this->User->date_format) : $this->Date->format("F j, Y, g:i a"), "relative" => time2str($this->Date->getTimestamp())), "author" => array("id" => $this->Author->id, "username" => $this->Author->username, "url" => $this->Author->url, "avatar" => array("small" => function_exists("format_avatar") ? format_avatar($this->Author->avatar, 40) : $this->Author->avatar, "large" => function_exists("format_avatar") ? format_avatar($this->Author->avatar, 120) : $this->Author->avatar)), "category" => array("id" => $this->Category->id, "name" => $this->Category->name, "url" => $this->Category->url), "voters" => array());
     return $idea;
 }
Пример #12
0
 /**
  * Get the latest x events within y keys
  * @since Version 3.6
  * @param int $limit
  * @param mixed $keys
  * @return array
  */
 public function latest($limit = 25, $keys = false, $page = 1)
 {
     $tidy_options = array("show-body-only" => true);
     if (is_array($keys)) {
         $sql_keys = " WHERE `key` IN ('" . implode("','", $keys) . "')";
     } elseif (is_string($keys)) {
         $sql_keys = " WHERE `key` = '" . $this->db->real_escape_string($keys) . "'";
     } else {
         $sql_keys = NULL;
     }
     $query = "SELECT e.id, e.module, e.user_id, u.username, u.user_avatar, e.timestamp, e.title, e.args, e.key, e.value FROM log_general AS e INNER JOIN nuke_users AS u ON u.user_id = e.user_id " . $sql_keys . " ORDER BY id DESC LIMIT 0, ?";
     if ($stmt = $this->db->prepare($query)) {
         $stmt->bind_param("i", $limit);
         $stmt->execute();
         $return = array();
         $stmt->bind_result($id, $module_name, $user_id, $username, $user_avatar, $timestamp, $title, $args, $key, $value);
         while ($stmt->fetch()) {
             $row['id'] = $id;
             $row['module'] = $module_name;
             $row['user_id'] = $user_id;
             $row['username'] = $username;
             $row['user_avatar'] = $user_avatar;
             $row['timestamp'] = new \DateTime($timestamp);
             $row['title'] = $title;
             $row['args'] = json_decode($args, true);
             $row['key'] = $key;
             $row['value'] = $value;
             $return[$timestamp] = $row;
         }
         $stmt->close();
         /**
          * Get forum posts
          */
         $query = "SELECT p.post_id, FROM_UNIXTIME( p.post_time ) AS post_time\r\n\t\t\t\t\tFROM nuke_bbposts AS p\r\n\t\t\t\t\tINNER JOIN nuke_bbtopics_watch AS w ON p.topic_id = w.topic_id\r\n\t\t\t\t\tWHERE w.user_id = ?\r\n\t\t\t\t\tAND p.poster_id != ?\r\n\t\t\t\t\tORDER BY p.post_time DESC\r\n\t\t\t\t\tLIMIT 0, 30";
         if ($stmt = $this->db->prepare($query)) {
             $stmt->bind_param("ii", $this->user_id, $this->user_id);
             $stmt->execute();
             $stmt->bind_result($post_id, $post_time);
             while ($stmt->fetch()) {
                 $post_ids[$post_id] = $post_time;
             }
             $stmt->close();
             foreach (array_keys($post_ids) as $post_id) {
                 try {
                     $Post = new \Railpage\Forums\Post($this->db, $post_id);
                 } catch (\Exception $e) {
                     #printArray($e->getMessage());
                     //throw new \Exception($e->getMessage());
                 }
                 $row['post_id'] = $Post->id;
                 $row['module'] = "forums";
                 $row['user_id'] = $Post->uid;
                 $row['username'] = $Post->username;
                 $row['user_avatar'] = $Post->user_avatar;
                 $row['timestamp'] = new \DateTime($post_ids[$post_id]);
                 $row['title'] = "Posted in " . $Post->thread->title;
                 $row['args'] = array("Thread title" => $Post->thread->title, "Thread ID" => $Post->thread->id, "Forum name" => $Post->thread->forum->name, "Forum ID" => $Post->thread->forum->id, "Post excerpt" => $Post->text, "Object path" => "Forums &raquo; " . $Post->thread->forum->name);
                 if (strlen($row['args']['Post excerpt']) > 256) {
                     $row['args']['Post excerpt'] = format_post(tidy_parse_string(trim(substr($row['args']['Post excerpt'], 0, 256)))) . "...";
                 }
                 $row['event_title'] = "<a href='/f-p" . $Post->id . ".htm#" . $Post->id . "'>" . $Post->thread->title . "</a>";
                 $row['action'] = "posted in";
                 $row['key'] = "post_id";
                 $row['value'] = $Post->id;
                 $return[$post_ids[$post_id]] = $row;
             }
         }
         try {
             $NewsBase = new \Railpage\News\Base($this->db);
             $latest = $NewsBase->latest(10);
             foreach ($latest as $id => $data) {
                 $row = array();
                 $row['article_id'] = $data['sid'];
                 $row['user_id'] = $data['user_id'];
                 $row['username'] = $data['username'];
                 $row['user_avatar'] = $data['user_avatar'];
                 $row['article_title'] = $data['title'];
                 $row['timestamp'] = new \DateTime($data['time']);
                 $row['action'] = "published";
                 $row['event_title'] = $data['title'];
                 $row['title'] = "Published a news story";
                 $row['args']['First line'] = $data['firstline'];
                 $row['args']['Topic ID'] = $data['topic'];
                 $row['args']['Topic title'] = $data['topictext'];
                 $row['args']['Object path'] = "News &raquo; " . $data['topictext'];
                 $row['key'] = "article_id";
                 $row['value'] = $data['sid'];
                 $return[$data['time']] = $row;
             }
         } catch (Exception $e) {
         }
         krsort($return);
         return $return;
     } else {
         throw new \Exception($this->db->error . "\n\n" . $query);
         return false;
     }
 }
Пример #13
0
 /**
  * Send this reminder
  * @since Version 3.8.7
  * @return \Railpage\Reminders\Reminder
  * @param boolean $markAsSent Flag to indicate if this is a test notification or not
  */
 public function send($markAsSent = false)
 {
     $this->validate();
     $Smarty = AppCore::getSmarty();
     /**
      * Set some vars
      */
     $email = array("subject" => $this->title, "body" => wpautop(format_post($this->text)));
     /**
      * Try and load the object to get some fancy stuff from it
      */
     try {
         $classname = sprintf("\\%s", $this->object);
         $Object = new $classname($this->object_id);
         $email['subtitle'] = "Railpage \\ " . $Object->Module->name;
         if (isset($Object->meta['coverphoto']) && !empty($Object->meta['coverphoto'])) {
             if ($CoverPhoto = (new Images())->getImageFromUrl($Object->meta['coverphoto'])) {
                 $email['hero'] = array("title" => isset($Object->name) ? $Object->name : $Object->title, "link" => isset($Object->url->canonical) ? $Object->url->canonical : sprintf("http://www.railpage.com.au%s", (string) $Object->url), "author" => isset($CoverPhoto->author->realname) && !empty($CoverPhoto->author->realname) ? $CoverPhoto->author->realname : $CoverPhoto->author->username);
                 if (strpos($email['hero']['link'], "http://") === false) {
                     $email['hero']['link'] = "http://www.railpage.com.au" . $email['hero']['link'];
                 }
                 if (strpos($email['hero']['link'], "railpage.com.au") === false) {
                     $email['hero']['link'] = sprintf("http://www.railpage.com.au%s", (string) $Object->url);
                 }
                 $utm = ["utm_source=reminder", "utm_medium=email", sprintf("utm_campaign=%s", ContentUtility::generateUrlSlug($this->title))];
                 $joiner = strpos($email['hero']['link'], "?") === false ? "?" : "&";
                 $email['hero']['link'] .= $joiner . implode("&", $utm);
                 foreach ($CoverPhoto->sizes as $size) {
                     if ($size >= 620) {
                         $email['hero']['image'] = $size['source'];
                     }
                 }
             }
         }
     } catch (Exception $e) {
     }
     /**
      * Process and fetch the email template
      */
     $tpl = $Smarty->ResolveTemplate("template.reminder");
     $Smarty->Assign("email", $email);
     $body = $Smarty->Fetch($tpl);
     $Notification = new Notification();
     $Notification->subject = $this->title;
     $Notification->body = $body;
     $Notification->addRecipient($this->User->id, $this->User->username, $this->User->contact_email);
     $Notification->commit();
     if ($markAsSent) {
         $this->sent = true;
         $this->Dispatched = new DateTime();
         $this->commit();
     }
     /**
      * Start composing and sending the email
      */
     /*
     $message = Swift_Message::newInstance()
         ->setSubject($this->title)
         ->setFrom(array(
             $this->Config->SMTP->username => $this->Config->SiteName
         ))
         ->setTo(array(
             $this->User->contact_email => !empty($this->User->realname) ? $this->User->realname : $this->User->username
         ))
         ->setBody($body, 'text/html');
     
     $transport = Swift_SmtpTransport::newInstance($this->Config->SMTP->host, $this->Config->SMTP->port, $this->Config->SMTP->TLS = true ? "tls" : NULL)
         ->setUsername($this->Config->SMTP->username)
         ->setPassword($this->Config->SMTP->password);
     
     $mailer = Swift_Mailer::newInstance($transport);
     
     if ($result = $mailer->send($message)) {
         if ($markAsSent) {
             $this->sent = true;
             $this->Dispatched = new DateTime;
             $this->commit();
         }
     }
     */
     return $this;
 }