Example #1
0
 /**
  * Is this thread stale?
  * @since Version 3.9.1
  * @return boolean
  */
 public function isThreadStale()
 {
     if (!filter_var($this->lastpost, FILTER_VALIDATE_INT)) {
         return false;
     }
     $stale = new DateTime("6 months ago");
     $Post = ForumsFactory::CreatePost($this->lastpost);
     return $Post->Date < $stale;
 }
Example #2
0
 /**
  * Load the forum
  * @since Version 3.9.1
  * @return \Railpage\Forums\Forum
  * @param int|string $id
  * @param boolean $getParent
  */
 public function load($id = false, $getParent = false)
 {
     if ($id === false) {
         throw new InvalidArgumentException("No valid forum ID or shortname was provided");
     }
     $this->url = new Url(sprintf("/f-f%d.htm", $id));
     if (filter_var($id, FILTER_VALIDATE_INT)) {
         #$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";
         $query = "SELECT f.*, p.post_time, p.poster_id, p.post_username, pt.post_subject, pt.post_text, pt.bbcode_uid,\r\n                            t.topic_id, t.topic_title, t.topic_time,\r\n                            f.forum_name, f.forum_desc\r\n                        FROM nuke_bbforums AS f\r\n                            LEFT JOIN nuke_bbposts AS p ON f.forum_last_post_id = p.post_id\r\n                            LEFT JOIN nuke_bbtopics AS t ON p.topic_id = t.topic_id\r\n                            LEFT JOIN nuke_bbposts_text AS pt ON pt.post_id = p.post_id\r\n                        WHERE f.forum_id = ?";
         $row = $this->db->fetchRow($query, $id);
     }
     if (isset($row) && is_array($row)) {
         $this->id = $row['forum_id'];
         $this->catid = $row["cat_id"];
         $this->name = function_exists("html_entity_decode_utf8") ? html_entity_decode_utf8($row["forum_name"]) : $row['forum_name'];
         $this->description = function_exists("html_entity_decode_utf8") ? html_entity_decode_utf8($row["forum_desc"]) : $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 = ForumsFactory::CreateCategory($this->catid);
         }
         if (filter_var($row['forum_parent'], FILTER_VALIDATE_INT) && $row['forum_parent'] > 0) {
             $this->Parent = new Forum($row['forum_parent']);
         }
     }
 }
Example #3
0
 /**
  * @depends testAddForum
  * @depends testCreateUser
  */
 public function testAddThread($forum_id, $User)
 {
     $Forum = ForumsFactory::CreateForum($forum_id);
     $Thread = new Thread();
     $Thread->setAuthor($User)->setForum($Forum);
     $Thread->title = "Test thread";
     $Thread->commit();
     $Post = new Post();
     $Post->setAuthor($User)->setThread($Thread);
     $Post->text = "asdfasffasasfa87s9fsas989sfa9ffds";
     $Post->commit();
     $NewThread = ForumsFactory::CreateThread($Thread->id);
     $NewPost = ForumsFactory::CreatePost($Post->id);
     $Index = ForumsFactory::CreateIndex();
     ForumsUtility::updateUserThreadView($Thread, $User);
     ForumsUtility::updateUserThreadView($Thread);
     ForumsUtility::getForumNotifications($User);
 }
Example #4
0
 /**
  * Get forums within this category
  * @since Version 3.8.7
  * @yield new Forum
  */
 public function getForums()
 {
     if (!$this->User instanceof User) {
         throw new Exception("Cannot get the list of forums within this category because no valid user has been specified");
     }
     $userdata = $this->User->generateUserData();
     $Index = ForumsFactory::CreateIndex();
     #new Index;
     if (!isset($prefix)) {
         $prefix = "nuke";
     }
     if (!isset($user_prefix)) {
         $user_prefix = "nuke";
     }
     require_once "includes" . DS . "auth.php";
     require_once "includes" . DS . "constants.php";
     $is_auth_ary = auth(AUTH_VIEW, AUTH_LIST_ALL, $userdata, $Index->forums());
     $forums = array();
     foreach ($is_auth_ary as $forum_id => $perms) {
         if (intval($perms['auth_view']) === 1) {
             $forums[] = $forum_id;
         }
         #printArray($perms);die;
     }
     $query = "SELECT forum_id FROM nuke_bbforums WHERE cat_id = ? AND forum_id IN ('" . implode("', '", $forums) . "') ORDER BY forum_order";
     foreach ($this->db->fetchAll($query, $this->id) as $row) {
         (yield new Forum($row['forum_id']));
     }
 }
Example #5
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);
 }