Example #1
0
 /**
  * Constructor
  * @since Version 3.0.1
  * @version 3.0.1
  * @param object $db
  * @param int $id
  */
 public function __construct($id = false)
 {
     parent::__construct();
     if (filter_var($id, FILTER_VALIDATE_INT)) {
         $this->load($id);
     }
 }
Example #2
0
 /**
  * Constructor
  * @since Version 3.2
  * @version 3.2
  * @param object $db
  * @param array $forum_list
  */
 public function __construct()
 {
     parent::__construct();
     foreach (func_get_args() as $arg) {
         if (filter_var($arg, FILTER_VALIDATE_INT) || is_array($arg)) {
             if (is_array($arg)) {
                 $forum_list = array_keys($arg);
                 if ($key = array_search(37, $forum_list)) {
                     unset($forum_list[$key]);
                 }
                 $this->forum_list = $forum_list;
             }
         }
     }
 }
Example #3
0
 /**
  * Constructor
  * @since Version 3.0.1
  * @version 3.0.1
  * @param object $db
  * @param int $id
  */
 public function __construct($id = false)
 {
     parent::__construct();
     $this->id = $id;
     $exec_sql = true;
     if ($this->db instanceof \sql_db) {
         if ($this->id) {
             $query = "SELECT * FROM nuke_bbcategories WHERE cat_id = " . $this->db->real_escape_string($this->id);
             if ($rs = $this->db->query($query)) {
                 $row = $rs->fetch_assoc();
                 $this->title = $row['cat_title'];
                 $this->order = $row['cat_order'];
                 $rs->close();
                 $query = "SELECT forum_id AS id, forum_name AS title FROM nuke_bbforums WHERE cat_id = " . $this->db->real_escape_string($this->id) . " ORDER BY forum_order";
                 if ($rs = $this->db->query($query)) {
                     while ($row = $rs->fetch_assoc()) {
                         $result[] = $row;
                     }
                     foreach ($result as $row) {
                         $this->forums[$row['id']] = $row['title'];
                     }
                 }
             } else {
                 throw new Exception(sprintf("Category ID %d does not exist", $this->id));
             }
         }
     } else {
         $query = "SELECT * FROM nuke_bbcategories WHERE cat_id = ?";
         $row = $this->db->fetchRow($query, $this->id);
         $this->title = $row['cat_title'];
         $this->order = $row['cat_order'];
         $query = "SELECT forum_id AS id, forum_name AS title FROM nuke_bbforums WHERE cat_id = ? ORDER BY forum_order";
         foreach ($this->db->fetchAll($query, $this->id) as $row) {
             $this->forums[$row['id']] = $row['title'];
         }
     }
 }
Example #4
0
 /**
  * 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";
     }
 }
Example #5
0
 /**
  * Constructor
  * @since Version 3.0.1
  * @version 3.0.1
  * @param int $forumid
  * @param object $database
  */
 public function __construct($forumid = false, $getParent = true)
 {
     parent::__construct();
     $timer = Debug::GetTimer();
     $this->Module = new Module("forums");
     if (filter_var($forumid, FILTER_VALIDATE_INT)) {
         $this->load($forumid, $getParent);
     } elseif ($shortname = filter_var($forumid, FILTER_SANITIZE_STRING)) {
         if (!is_null($shortname)) {
             $this->load($shortname, $getParent);
         }
     }
     Debug::LogEvent(__METHOD__, $timer);
 }
Example #6
0
 /**
  * Constructor
  * @since Version 3.0.1
  * @version 3.0.1
  * @param int $forumid
  * @param object $database
  */
 function __construct($forumid, $getParent = true)
 {
     parent::__construct();
     if (RP_DEBUG) {
         global $site_debug;
         $debug_timer_start = microtime(true);
     }
     $this->Module = new Module("forums");
     $this->url = new Url(sprintf("/f-f%d.htm", $forumid));
     if ($this->db instanceof \sql_db) {
         $query = "SELECT * FROM nuke_bbforums f LEFT JOIN (nuke_bbtopics t, nuke_bbposts p, nuke_bbposts_text pt) ON (f.forum_last_post_id = p.post_id AND p.topic_id = t.topic_id AND pt.post_id = p.post_id) WHERE f.forum_id = '" . $this->db->real_escape_string($forumid) . "' LIMIT 1";
         $result = $this->db->query($query);
         if ($result->num_rows == 1) {
             $row = $result->fetch_assoc();
             foreach ($row as $key => $val) {
                 //$row[$key] = iconv('windows-1256', 'UTF-8', $val);
             }
         }
         $result->close();
     } else {
         $query = "SELECT * FROM nuke_bbforums f LEFT JOIN (nuke_bbtopics t, nuke_bbposts p, nuke_bbposts_text pt) ON (f.forum_last_post_id = p.post_id AND p.topic_id = t.topic_id AND pt.post_id = p.post_id) WHERE f.forum_id = ? LIMIT 1";
         $row = $this->db->fetchRow($query, $forumid);
     }
     if (isset($row) && is_array($row)) {
         $this->id = $forumid;
         $this->catid = $row["cat_id"];
         $this->name = html_entity_decode_utf8($row["forum_name"]);
         $this->description = html_entity_decode_utf8($row["forum_desc"]);
         $this->status = $row["forum_status"];
         $this->order = $row["forum_order"];
         $this->posts = $row["forum_posts"];
         $this->topics = $row["forum_topics"];
         $this->last_post = $row["forum_last_post_id"];
         $this->last_post_id = $this->last_post;
         $this->last_post_time = $row['post_time'];
         $this->last_post_user_id = $row['poster_id'];
         $this->last_post_username = $row['post_username'];
         $this->last_post_subject = $row['post_subject'];
         $this->last_post_text = $row['post_text'];
         $this->last_post_bbcodeuid = $row['bbcode_uid'];
         $this->last_post_topic_id = $row['topic_id'];
         $this->last_post_topic_title = $row['topic_title'];
         $this->last_post_topic_time = $row['topic_time'];
         $this->acl_resource = sprintf("railpage.forums.forum:%d", $this->id);
         if ($getParent) {
             $this->category = new Category($this->catid);
         }
     }
     if (RP_DEBUG) {
         $site_debug[] = __CLASS__ . "::" . __METHOD__ . " completed in " . round(microtime(true) - $debug_timer_start, 5) . "s";
     }
 }
Example #7
0
 /**
  * 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;
 }
Example #8
0
 /**
  * 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";
     }
 }
Example #9
0
 /**
  * Constructor
  * @since Version 3.0.1
  * @version 3.0.1
  * @param object $database
  * @param int $postid
  */
 function __construct($postid = false)
 {
     parent::__construct();
     $this->Module = new Module("forums");
     $this->timestamp = time();
     if (filter_var($postid, FILTER_VALIDATE_INT)) {
         if (RP_DEBUG) {
             global $site_debug;
             $debug_timer_start = microtime(true);
         }
         if ($this->db instanceof \sql_db) {
             $query = "SELECT p.*, t.*, u.username, u.user_avatar FROM nuke_bbposts p, nuke_bbposts_text t, nuke_users AS u WHERE u.user_id = p.poster_id AND p.post_id = '" . $this->db->real_escape_string($postid) . "' AND t.post_id = p.post_id LIMIT 1";
             $result = $this->db->query($query);
             if ($result && $result->num_rows == 1) {
                 $row = $result->fetch_assoc();
             }
         } else {
             $query = "SELECT p.*, t.*, u.username, u.user_avatar FROM nuke_bbposts p, nuke_bbposts_text t, nuke_users AS u WHERE u.user_id = p.poster_id AND p.post_id = ? AND t.post_id = p.post_id LIMIT 1";
             $row = $this->db->fetchRow($query, $postid);
             if (RP_DEBUG) {
                 if ($row === false) {
                     $site_debug[] = "Zend_DB: FAILED select post ID " . $this->id . " in " . round(microtime(true) - $debug_timer_start, 5) . "s";
                 } else {
                     $site_debug[] = "Zend_DB: SUCCESS select post ID " . $this->id . " in " . round(microtime(true) - $debug_timer_start, 5) . "s";
                 }
             }
         }
     } elseif (is_string($postid)) {
         $query = "SELECT p.*, t.*, u.username, u.user_avatar FROM nuke_bbposts p, nuke_bbposts_text t, nuke_users AS u WHERE u.user_id = p.poster_id AND t.url_slug = ? AND t.post_id = p.post_id LIMIT 1";
         $row = $this->db->fetchRow($query, $postid);
     }
     if (isset($row) && is_array($row)) {
         $this->id = $row['post_id'];
         $this->thread = new Thread($row['topic_id']);
         $this->uid = $row['poster_id'];
         $this->username = $row['username'];
         $this->user_avatar = $row['user_avatar'];
         $this->timestamp = $row['post_time'];
         $this->ip = $row['poster_ip'];
         $this->flag_bbCode = $row['enable_bbcode'];
         $this->flag_html = $row['enable_html'];
         $this->flag_smilies = $row['enable_smilies'];
         $this->flag_signature = $row['enable_sig'];
         $this->edit_timestamp = $row['post_edit_time'];
         $this->edit_count = $row['post_edit_count'];
         $this->reported = $row['post_reported'];
         $this->herring_count = $row['post_edit_count'];
         $this->bbcodeuid = $row['bbcode_uid'];
         $this->subject = $row['post_subject'];
         $this->text = stripslashes($row['post_text']);
         $this->old_text = stripslashes($row['post_text']);
         $this->rating = $row['post_rating'];
         $this->bbcode_uid = $row['bbcode_uid'];
         $this->editor_version = $row['editor_version'];
         $this->url_slug = $row['url_slug'];
         if (empty($this->url_slug)) {
             $this->createSlug();
             $this->commit();
         }
         $this->lat = $row['lat'];
         $this->lon = $row['lon'];
         $this->Date = new DateTime();
         $this->Date->setTimestamp($row['post_time']);
         $this->Author = new User($row['poster_id']);
         $this->makeLinks();
     }
 }
Example #10
0
 /**
  * Constructor
  * @since Version 3.0.1
  * @version 3.0.1
  * @param object $database
  * @param int $postid
  */
 public function __construct($postid = false)
 {
     $post_timer_start = Debug::GetTimer();
     parent::__construct();
     $this->Module = new Module("forums");
     $this->timestamp = time();
     $this->mckey = sprintf("railpage:forums;post=%d", $postid);
     $this->Memcached = AppCore::getMemcached();
     if (!($row = $this->Memcached->fetch($this->mckey))) {
         Debug::LogEvent("Could not find forum post in Redis using cache key " . $this->mckey);
         if (filter_var($postid, FILTER_VALIDATE_INT)) {
             $timer = Debug::GetTimer();
             $query = "SELECT p.*, t.*, u.username, u.user_avatar FROM nuke_bbposts p, nuke_bbposts_text t, nuke_users AS u WHERE u.user_id = p.poster_id AND p.post_id = ? AND t.post_id = p.post_id LIMIT 1";
             $row = $this->db->fetchRow($query, $postid);
             $rs = $this->Memcached->save($this->mckey, $row, 43200);
             Debug::LogEvent("Fetch forum post from database", $timer);
             if (!$rs) {
                 Debug::LogEvent("!! Failed to store forum post in cache provider");
             }
         } elseif (is_string($postid)) {
             $query = "SELECT p.*, t.*, u.username, u.user_avatar FROM nuke_bbposts p, nuke_bbposts_text t, nuke_users AS u WHERE u.user_id = p.poster_id AND t.url_slug = ? AND t.post_id = p.post_id LIMIT 1";
             $row = $this->db->fetchRow($query, $postid);
             $rs = $this->Memcached->save($this->mckey, $row, 43200);
         }
     }
     if (isset($row) && is_array($row)) {
         $this->id = $row['post_id'];
         $this->thread = ForumsFactory::CreateThread($row['topic_id']);
         $this->uid = $row['poster_id'];
         $this->username = $row['username'];
         $this->user_avatar = $row['user_avatar'];
         $this->timestamp = $row['post_time'];
         $this->ip = $row['poster_ip'];
         $this->flag_bbCode = $row['enable_bbcode'];
         $this->flag_html = $row['enable_html'];
         $this->flag_smilies = $row['enable_smilies'];
         $this->flag_signature = $row['enable_sig'];
         $this->edit_timestamp = $row['post_edit_time'];
         $this->edit_count = $row['post_edit_count'];
         $this->reported = $row['post_reported'];
         $this->herring_count = $row['post_edit_count'];
         $this->bbcodeuid = $row['bbcode_uid'];
         $this->subject = $row['post_subject'];
         $this->text = stripslashes($row['post_text']);
         $this->old_text = stripslashes($row['post_text']);
         $this->rating = $row['post_rating'];
         $this->bbcode_uid = $row['bbcode_uid'];
         $this->editor_version = $row['editor_version'];
         $this->url_slug = $row['url_slug'];
         $this->pinned = isset($row['pinned']) ? (bool) $row['pinned'] : false;
         if (empty($this->url_slug)) {
             $this->createSlug();
             $this->commit();
         }
         $this->lat = $row['lat'];
         $this->lon = $row['lon'];
         $this->Date = new DateTime();
         $this->Date->setTimestamp($row['post_time']);
         $this->Author = UserFactory::CreateUser($row['poster_id']);
         $this->makeLinks();
     }
     Debug::LogEvent(__METHOD__, $post_timer_start);
 }