protected function _common() { $this->totalpages = ceil($this->total / $this->threads_per_page); if (!empty($this->threadids)) { $idstr = implode(",", $this->threadids); if (empty($this->loadids)) { $loadstr = ''; } else { $loadstr = 'OR a.id IN (' . implode(",", $this->loadids) . ')'; } $query = "SELECT a.*, j.id AS userid, t.message, l.myfavorite, l.favcount, l.threadhits, l.lasttime, l.threadattachments, COUNT(aa.id) AS attachments,\n\t\t\t\tl.msgcount, l.mycount, l.lastid, l.mylastid, l.lastid AS lastread, 0 AS unread, u.avatar, j.username, j.name AS uname, c.name AS catname, c.class_sfx\n\t\t\tFROM (\n\t\t\t\tSELECT m.thread, MAX(m.hits) AS threadhits, MAX(f.userid IS NOT null AND f.userid={$this->db->Quote($this->my->id)}) AS myfavorite, COUNT(DISTINCT f.userid) AS favcount,\n\t\t\t\t\tCOUNT(DISTINCT a.id) AS threadattachments, COUNT(DISTINCT m.id) AS msgcount, COUNT(DISTINCT IF(m.userid={$this->db->Quote($this->user->id)}, m.id, NULL)) AS mycount,\n\t\t\t\t\tMAX(m.id) AS lastid, MAX(IF(m.userid={$this->db->Quote($this->user->id)}, m.id, 0)) AS mylastid, MAX(m.time) AS lasttime\n\t\t\t\tFROM #__kunena_messages AS m"; if ($this->config->allowfavorites) { $query .= " LEFT JOIN #__kunena_favorites AS f ON f.thread = m.thread"; } else { $query .= " LEFT JOIN #__kunena_favorites AS f ON f.thread = 0"; } $query .= "\n\t\t\t\tLEFT JOIN #__kunena_attachments AS a ON a.mesid = m.id\n\t\t\t\tWHERE m.hold IN ({$this->hold}) AND m.moved='0' AND m.thread IN ({$idstr})\n\t\t\t\tGROUP BY thread\n\t\t\t) AS l\n\t\t\tINNER JOIN #__kunena_messages AS a ON a.thread = l.thread\n\t\t\tINNER JOIN #__kunena_messages_text AS t ON a.id = t.mesid\n\t\t\tLEFT JOIN #__users AS j ON j.id = a.userid\n\t\t\tLEFT JOIN #__kunena_users AS u ON u.userid = j.id\n\t\t\tLEFT JOIN #__kunena_categories AS c ON c.id = a.catid\n\t\t\tLEFT JOIN #__kunena_attachments AS aa ON aa.mesid = a.id\n\t\t\tWHERE (a.parent='0' OR a.id=l.lastid {$loadstr})\n\t\t\tGROUP BY a.id\n\t\t\tORDER BY {$this->order}"; $this->db->setQuery($query); $this->messages = $this->db->loadObjectList('id'); KunenaError::checkDatabaseError(); // collect user ids for avatar prefetch when integrated $userlist = array(); foreach ($this->messages as $message) { if ($message->parent == 0) { $this->threads[$message->thread] = $message; $routerlist[$message->id] = $message->subject; if ($this->func == 'mylatest' && $message->myfavorite) { $this->highlight++; } } if ($message->id == $message->lastid) { $this->lastreply[$message->thread] = $message; } if (isset($this->loadids) && in_array($message->id, $this->loadids)) { $this->customreply[$message->id] = $message; } $userlist[intval($message->userid)] = intval($message->userid); $userlist[intval($message->modified_by)] = intval($message->modified_by); } // Load threads to Kunena router to avoid extra SQL queries if (!empty($routerlist)) { include_once KUNENA_PATH . '/router.php'; KunenaRouter::loadMessages($routerlist); } // Prefetch all users/avatars to avoid user by user queries during template iterations KunenaUser::loadUsers($userlist); if ($this->config->shownew && $this->my->id) { $readlist = $this->session->readtopics; $this->db->setQuery("SELECT thread, MIN(id) AS lastread, SUM(1) AS unread FROM #__kunena_messages " . "WHERE hold IN ({$this->hold}) AND moved='0' AND thread NOT IN ({$readlist}) AND thread IN ({$idstr}) AND time>{$this->db->Quote($this->prevCheck)} GROUP BY thread"); // TODO: check input $msgidlist = $this->db->loadObjectList(); KunenaError::checkDatabaseError(); foreach ($msgidlist as $msgid) { $this->messages[$msgid->thread]->lastread = $msgid->lastread; $this->messages[$msgid->thread]->unread = $msgid->unread; } } } }
function getView() { // Is user allowed to read category from the URL? if ($this->catid && !$this->session->canRead($this->catid)) { return; } $this->allow = 1; $where[] = "a.hold IN ({$this->hold})"; $where = implode(' AND ', $where); $query = "SELECT a.*, b.*, p.id AS poll_id, modified.name AS modified_name, modified.username AS modified_username\n\t\t\tFROM #__kunena_messages AS a\n\t\t\tLEFT JOIN #__kunena_messages_text AS b ON a.id=b.mesid\n\t\t\tLEFT JOIN #__users AS modified ON a.modified_by = modified.id\n\t\t\tLEFT JOIN #__kunena_polls AS p ON a.id=p.threadid\n\t\t\tWHERE a.id={$this->db->Quote($this->id)} AND {$where}"; $this->db->setQuery($query); $this->first_message = $this->db->loadObject(); // Invalid message id (deleted, on hold?) if (KunenaError::checkDatabaseError() || !$this->first_message) { return; } // Is user allowed to see the forum specified in the message? if (!$this->session->canRead($this->first_message->catid)) { $this->allow = 0; return; } $this->thread = $this->first_message->thread; // Test if this is a valid URL. If not, redirect browser to the right location if ($this->first_message->moved || $this->thread != $this->id || $this->catid != $this->first_message->catid) { $this->catid = $this->first_message->catid; if ($this->first_message->moved) { $newurl = array(); parse_str($this->first_message->message, $newloc); $this->id = $newloc['id']; $query = "SELECT catid, thread FROM #__kunena_messages AS a WHERE a.id='{$this->id}'"; $this->db->setQuery($query); $newpos = $this->db->loadObject(); if (!$newpos) { $this->allow = 0; return; } if (KunenaError::checkDatabaseError()) { return; } $this->thread = $newpos->thread; $this->catid = $newpos->catid; } // This query to calculate the page this reply is sitting on within this thread $query = "SELECT COUNT(*) FROM #__kunena_messages AS a WHERE a.thread={$this->db->Quote($this->thread)} AND {$where} AND a.id<={$this->db->Quote($this->id)}"; $this->db->setQuery($query); $replyCount = $this->db->loadResult(); if (KunenaError::checkDatabaseError()) { return; } $replyPage = $replyCount > $this->config->messages_per_page ? ceil($replyCount / $this->config->messages_per_page) : 1; $this->redirect = CKunenaLink::GetThreadPageURL('view', $this->catid, $this->thread, $replyPage, $this->config->messages_per_page, $this->first_message->id, false); } //Get the category name for breadcrumb $this->db->setQuery("SELECT * FROM #__kunena_categories WHERE id={$this->db->Quote($this->catid)}"); $this->catinfo = $this->db->loadObject(); if (KunenaError::checkDatabaseError()) { return; } //Get Parent's cat.name for breadcrumb $this->db->setQuery("SELECT id, name FROM #__kunena_categories WHERE id={$this->db->Quote($this->catinfo->parent)}"); $objCatParentInfo = $this->db->loadObject(); if (KunenaError::checkDatabaseError()) { return; } // START $this->emoticons = smile::getEmoticons(0); $this->prevCheck = $this->session->lasttime; $this->read_topics = explode(',', $this->session->readtopics); $showedEdit = 0; $this->kunena_forum_locked = $this->catinfo->locked; //check if topic is locked $this->topicLocked = $this->first_message->locked; if (!$this->topicLocked) { //topic not locked; check if forum is locked $this->topicLocked = $this->catinfo->locked; } $this->topicSticky = $this->first_message->ordering; CKunenaTools::markTopicRead($this->thread, $this->my->id); //update the hits counter for this topic & exclude the owner if ($this->my->id == 0 || $this->first_message->userid != $this->my->id) { $this->db->setQuery("UPDATE #__kunena_messages SET hits=hits+1 WHERE id={$this->db->Quote($this->thread)} AND parent='0'"); $this->db->query(); KunenaError::checkDatabaseError(); } $query = "SELECT COUNT(*) FROM #__kunena_messages AS a WHERE a.thread={$this->db->Quote($this->thread)} AND {$where}"; $this->db->setQuery($query); $this->total_messages = $this->db->loadResult(); KunenaError::checkDatabaseError(); // If page does not exist, redirect to the last page if ($this->total_messages <= $this->limitstart) { $page = ceil($this->total_messages / $this->limit); $this->redirect = CKunenaLink::GetThreadPageURL('view', $this->catid, $this->id, $page, $this->limit, '', false); } $maxpages = 7 - 2; // odd number here (show - 2) $totalpages = ceil($this->total_messages / $this->limit); $page = floor($this->limitstart / $this->limit) + 1; $firstpage = 1; if ($this->ordering == 'desc') { $firstpage = $totalpages; } // Get replies of current thread $query = "SELECT a.*, b.*, modified.name AS modified_name, modified.username AS modified_username\n\t\t\t\t\tFROM #__kunena_messages AS a\n\t\t\t\t\tLEFT JOIN #__kunena_messages_text AS b ON a.id=b.mesid\n\t\t\t\t\tLEFT JOIN #__users AS modified ON a.modified_by = modified.id\n\t\t\t\t\tWHERE a.thread={$this->db->Quote($this->thread)} AND {$where}\n\t\t\t\t\tORDER BY id {$this->ordering}"; $this->db->setQuery($query, $this->limitstart, $this->limit); $this->messages = (array) $this->db->loadObjectList('id'); KunenaError::checkDatabaseError(); // First collect the message ids of the first message and all replies $messageids = array(); $this->threaded = array(); $userlist = array(); foreach ($this->messages as $message) { $messageids[] = $message->id; // Threaded ordering if (isset($this->messages[$message->parent])) { $this->threaded[$message->parent][] = $message->id; } else { $this->threaded[0][] = $message->id; } $userlist[intval($message->userid)] = intval($message->userid); $userlist[intval($message->modified_by)] = intval($message->modified_by); } if (!isset($this->messages[$this->mesid])) { $this->mesid = reset($messageids); } if ($this->layout != 'view') { if (!isset($this->messages[$this->id])) { $this->messages = $this->getThreadedOrdering(0, array('edge')); } else { $this->messages = $this->getThreadedOrdering(); } } // create a list of ids we can use for our sql $idstr = @join(",", $messageids); // Load attachments require_once KUNENA_PATH_LIB . '/kunena.attachments.class.php'; $attachments = CKunenaAttachments::getInstance(); if (is_a($attachments, 'CKunenaAttachments')) { $message_attachments = $attachments->get($idstr); // Now that we have all relevant messages in messages, asign any matching attachments foreach ($this->messages as $message) { // Mark as new if ($this->my->id && $this->prevCheck < $message->time && !in_array($message->thread, $this->read_topics)) { $message->new = true; } else { $message->new = false; } // Assign attachments if (isset($message_attachments[$message->id])) { $message->attachments = $message_attachments[$message->id]; } } // Done with attachments } $this->pagination = $this->getPagination($this->catid, $this->thread, $page, $totalpages, $maxpages); //meta description and keywords $metaKeys = kunena_htmlspecialchars("{$this->first_message->subject}, {$objCatParentInfo->name}, {$this->config->board_title}, " . JText::_('COM_KUNENA_GEN_FORUM') . ', ' . $this->app->getCfg('sitename')); // Create Meta Description form the content of the first message // better for search results display but NOT for search ranking! $metaDesc = KunenaParser::stripBBCode($this->first_message->message); $metaDesc = strip_tags($metaDesc); // Now remove all tags $metaDesc = preg_replace('/\\s+/', ' ', $metaDesc); // remove newlines $metaDesc = preg_replace('/^[^\\w0-9]+/', '', $metaDesc); // remove characters at the beginning that are not letters or numbers $metaDesc = trim($metaDesc); // Remove trailing spaces and beginning // remove multiple spaces while (strpos($metaDesc, ' ') !== false) { $metaDesc = str_replace(' ', ' ', $metaDesc); } // limit to 185 characters - google will cut off at ~150 if (strlen($metaDesc) > 185) { $metaDesc = rtrim(JString::substr($metaDesc, 0, 182)) . '...'; } $metaDesc = htmlspecialchars($metaDesc); $document =& JFactory::getDocument(); $document->setMetadata('keywords', $metaKeys); $document->setDescription($metaDesc); $this->layout_buttons = array(); if ($this->config->enable_threaded_layouts) { if ($this->layout != 'view') { $this->layout_buttons[] = CKunenaLink::GetThreadLayoutLink('flat', $this->catid, $this->thread, $this->mesid, CKunenaTools::showButton('layout-flat', JText::_('COM_KUNENA_BUTTON_LAYOUT_FLAT')), $this->limitstart, $this->limit, JText::_('COM_KUNENA_BUTTON_LAYOUT_FLAT_LONG'), 'nofollow', 'kicon-button kbuttonuser btn-left'); } if ($this->layout != 'threaded') { $this->layout_buttons[] = CKunenaLink::GetThreadLayoutLink('threaded', $this->catid, $this->thread, $this->mesid, CKunenaTools::showButton('layout-threaded', JText::_('COM_KUNENA_BUTTON_LAYOUT_THREADED')), $this->limitstart, $this->limit, JText::_('COM_KUNENA_BUTTON_LAYOUT_THREADED_LONG'), 'nofollow', 'kicon-button kbuttonuser btn-left'); } if ($this->layout != 'indented') { $this->layout_buttons[] = CKunenaLink::GetThreadLayoutLink('indented', $this->catid, $this->thread, $this->mesid, CKunenaTools::showButton('layout-indented', JText::_('COM_KUNENA_BUTTON_LAYOUT_INDENTED')), $this->limitstart, $this->limit, JText::_('COM_KUNENA_BUTTON_LAYOUT_INDENTED_LONG'), 'nofollow', 'kicon-button kbuttonuser btn-left'); } } //Perform subscriptions check only once $this->cansubscribe = 0; if ($this->config->allowsubscriptions && $this->config->topic_subscriptions != 'disabled' && $this->my->id) { $this->db->setQuery("SELECT thread, future1 FROM #__kunena_subscriptions WHERE userid={$this->db->Quote($this->my->id)} AND thread={$this->db->Quote($this->thread)}"); $fb_subscribed = $this->db->loadObject(); KunenaError::checkDatabaseError(); if (!$fb_subscribed) { $this->cansubscribe = 1; } elseif ($fb_subscribed->future1 == 1) { $query_thread = "UPDATE #__kunena_subscriptions\n\t\t\t\t\tSET future1=0 WHERE thread={$this->db->Quote($this->thread)} AND userid={$this->db->Quote($this->my->id)}"; $this->db->setQuery($query_thread); $this->db->query(); } } //Perform favorites check only once $fb_canfavorite = 0; $this->db->setQuery("SELECT MAX(userid={$this->db->Quote($this->my->id)}) AS favorited, COUNT(*) AS totalfavorited FROM #__kunena_favorites WHERE thread={$this->db->Quote($this->thread)}"); list($this->favorited, $this->totalfavorited) = $this->db->loadRow(); KunenaError::checkDatabaseError(); if ($this->config->allowfavorites && $this->my->id) { if (!$this->favorited) { $fb_canfavorite = 1; } } //get the Moderator list for display $this->db->setQuery("SELECT m.*, u.* FROM #__kunena_moderation AS m INNER JOIN #__users AS u ON u.id=m.userid WHERE m.catid={$this->db->Quote($this->catid)} AND u.block=0"); $this->modslist = $this->db->loadObjectList(); KunenaError::checkDatabaseError(); $this->catModerators = array(); foreach ($this->modslist as $mod) { $this->catModerators[] = $mod->userid; $userlist[intval($mod->userid)] = intval($mod->userid); } // Prefetch all users/avatars to avoid user by user queries during template iterations KunenaUser::loadUsers($userlist); //data ready display now if (CKunenaTools::isModerator($this->my->id, $this->catid) || $this->topicLocked == 0) { //this user is allowed to reply to this topic $this->thread_reply = CKunenaLink::GetTopicPostReplyLink('reply', $this->catid, $this->thread, CKunenaTools::showButton('reply', JText::_('COM_KUNENA_BUTTON_REPLY_TOPIC')), 'nofollow', 'kicon-button kbuttoncomm btn-left', JText::_('COM_KUNENA_BUTTON_REPLY_TOPIC_LONG')); } // Thread Subscription if ($this->cansubscribe == 1) { // this user is allowed to subscribe - check performed further up to eliminate duplicate checks // for top and bottom navigation $this->thread_subscribe = CKunenaLink::GetTopicPostLink('subscribe', $this->catid, $this->id, CKunenaTools::showButton('subscribe', JText::_('COM_KUNENA_BUTTON_SUBSCRIBE_TOPIC')), 'nofollow', 'kicon-button kbuttonuser btn-left', JText::_('COM_KUNENA_BUTTON_SUBSCRIBE_TOPIC_LONG')); } if ($this->my->id != 0 && $this->config->allowsubscriptions && $this->config->topic_subscriptions != 'disabled' && $this->cansubscribe == 0) { // this user is allowed to unsubscribe $this->thread_subscribe = CKunenaLink::GetTopicPostLink('unsubscribe', $this->catid, $this->id, CKunenaTools::showButton('subscribe', JText::_('COM_KUNENA_BUTTON_UNSUBSCRIBE_TOPIC')), 'nofollow', 'kicon-button kbuttonuser btn-left', JText::_('COM_KUNENA_BUTTON_UNSUBSCRIBE_TOPIC_LONG')); } //START: FAVORITES if ($fb_canfavorite == 1) { // this user is allowed to add a favorite - check performed further up to eliminate duplicate checks // for top and bottom navigation $this->thread_favorite = CKunenaLink::GetTopicPostLink('favorite', $this->catid, $this->id, CKunenaTools::showButton('favorite', JText::_('COM_KUNENA_BUTTON_FAVORITE_TOPIC')), 'nofollow', 'kicon-button kbuttonuser btn-left', JText::_('COM_KUNENA_BUTTON_FAVORITE_TOPIC_LONG')); } if ($this->my->id != 0 && $this->config->allowfavorites && $fb_canfavorite == 0) { // this user is allowed to unfavorite $this->thread_favorite = CKunenaLink::GetTopicPostLink('unfavorite', $this->catid, $this->id, CKunenaTools::showButton('favorite', JText::_('COM_KUNENA_BUTTON_UNFAVORITE_TOPIC')), 'nofollow', 'kicon-button kbuttonuser btn-left', JText::_('COM_KUNENA_BUTTON_UNFAVORITE_TOPIC_LONG')); } // FINISH: FAVORITES if (CKunenaTools::isModerator($this->my->id, $this->catid) || !$this->kunena_forum_locked) { //this user is allowed to post a new topic $this->thread_new = CKunenaLink::GetPostNewTopicLink($this->catid, CKunenaTools::showButton('newtopic', JText::_('COM_KUNENA_BUTTON_NEW_TOPIC')), 'nofollow', 'kicon-button kbuttoncomm btn-left', JText::_('COM_KUNENA_BUTTON_NEW_TOPIC_LONG')); } if (CKunenaTools::isModerator($this->my->id, $this->catid)) { // offer the moderator always the move link to relocate a topic to another forum // and the (un)sticky bit links // and the (un)lock links if ($this->topicSticky == 0) { $this->thread_sticky = CKunenaLink::GetTopicPostLink('sticky', $this->catid, $this->id, CKunenaTools::showButton('sticky', JText::_('COM_KUNENA_BUTTON_STICKY_TOPIC')), 'nofollow', 'kicon-button kbuttonmod btn-left', JText::_('COM_KUNENA_BUTTON_STICKY_TOPIC_LONG')); } else { $this->thread_sticky = CKunenaLink::GetTopicPostLink('unsticky', $this->catid, $this->id, CKunenaTools::showButton('sticky', JText::_('COM_KUNENA_BUTTON_UNSTICKY_TOPIC')), 'nofollow', 'kicon-button kbuttonmod btn-left', JText::_('COM_KUNENA_BUTTON_UNSTICKY_TOPIC_LONG')); } if ($this->topicLocked == 0) { $this->thread_lock = CKunenaLink::GetTopicPostLink('lock', $this->catid, $this->id, CKunenaTools::showButton('lock', JText::_('COM_KUNENA_BUTTON_LOCK_TOPIC')), 'nofollow', 'kicon-button kbuttonmod btn-left', JText::_('COM_KUNENA_BUTTON_LOCK_TOPIC_LONG')); } else { $this->thread_lock = CKunenaLink::GetTopicPostLink('unlock', $this->catid, $this->id, CKunenaTools::showButton('lock', JText::_('COM_KUNENA_BUTTON_UNLOCK_TOPIC')), 'nofollow', 'kicon-button kbuttonmod btn-left', JText::_('COM_KUNENA_BUTTON_UNLOCK_TOPIC_LONG')); } $this->thread_delete = CKunenaLink::GetTopicPostLink('deletethread', $this->catid, $this->id, CKunenaTools::showButton('delete', JText::_('COM_KUNENA_BUTTON_DELETE_TOPIC')), 'nofollow', 'kicon-button kbuttonmod btn-left', JText::_('COM_KUNENA_BUTTON_DELETE_TOPIC_LONG')); $this->thread_moderate = CKunenaLink::GetTopicPostReplyLink('moderatethread', $this->catid, $this->id, CKunenaTools::showButton('moderate', JText::_('COM_KUNENA_BUTTON_MODERATE_TOPIC')), 'nofollow', 'kicon-button kbuttonmod btn-left', JText::_('COM_KUNENA_BUTTON_MODERATE')); } $this->headerdesc = nl2br(smile::smileReplace($this->catinfo->headerdesc, 0, $this->config->disemoticons, $this->emoticons)); $tabclass = array("row1", "row2"); $this->mmm = 0; $this->replydir = $this->ordering == 'DESC' ? -1 : 1; if ($this->replydir < 0) { $this->replynum = $this->total_messages - $this->limitstart + 1; } else { $this->replynum = $this->limitstart; } $this->myname = $this->config->username ? $this->my->username : $this->my->name; $this->allow_anonymous = !empty($this->catinfo->allow_anonymous) && $this->my->id; $this->anonymous = $this->allow_anonymous && !empty($this->catinfo->post_anonymous); }
function __construct($catid, $page = 0) { kimport('html.parser'); $this->func = 'showcat'; $this->catid = $catid; $this->page = $page; $this->hasSubCats = ''; $template = KunenaFactory::getTemplate(); $this->params = $template->params; $this->db = JFactory::getDBO(); $this->my = JFactory::getUser(); $this->myprofile = KunenaFactory::getUser(); $this->session = KunenaFactory::getSession(); $this->config = KunenaFactory::getConfig(); if (!$this->catid) { return; } if (!$this->session->canRead($this->catid)) { return; } $this->allow = 1; $this->tabclass = array("row1", "row2"); $this->prevCheck = $this->session->lasttime; $this->app =& JFactory::getApplication(); //Get the category information $query = "SELECT c.*, s.catid AS subscribeid\n\t\t\t\tFROM #__kunena_categories AS c\n\t\t\t\tLEFT JOIN #__kunena_subscriptions_categories AS s ON c.id = s.catid\n\t\t\t\tAND s.userid = '{$this->my->id}'\n\t\t\t\tWHERE c.id={$this->db->Quote($this->catid)}"; $this->db->setQuery($query); $this->objCatInfo = $this->db->loadObject(); if (KunenaError::checkDatabaseError()) { return; } //Get the Category's parent category name for breadcrumb $this->db->setQuery("SELECT name, id FROM #__kunena_categories WHERE id={$this->db->Quote($this->objCatInfo->parent)}"); $objCatParentInfo = $this->db->loadObject(); if (KunenaError::checkDatabaseError()) { return; } //check if this forum is locked $this->kunena_forum_locked = $this->objCatInfo->locked; //check if this forum is subject to review $this->kunena_forum_reviewed = $this->objCatInfo->review; $threads_per_page = $this->config->threads_per_page; $access = KunenaFactory::getAccessControl(); $hold = $access->getAllowedHold($this->myprofile, $this->catid); /*//////////////// Start selecting messages, prepare them for threading, etc... /////////////////*/ $this->page = $this->page < 1 ? 1 : $this->page; $offset = ($this->page - 1) * $threads_per_page; $row_count = $this->page * $threads_per_page; $this->db->setQuery("SELECT COUNT(*) FROM #__kunena_messages WHERE parent='0' AND catid={$this->db->Quote($this->catid)} AND hold IN ({$hold})"); $this->total = (int) $this->db->loadResult(); KunenaError::checkDatabaseError(); $this->totalpages = ceil($this->total / $threads_per_page); $query = "SELECT t.id, MAX(m.id) AS lastid FROM #__kunena_messages AS t\n\tINNER JOIN #__kunena_messages AS m ON t.id = m.thread\n\tWHERE t.parent='0' AND t.hold IN ({$hold}) AND t.catid={$this->db->Quote($this->catid)} AND m.hold IN ({$hold}) AND m.catid={$this->db->Quote($this->catid)}\n\tGROUP BY m.thread ORDER BY t.ordering DESC, lastid DESC"; $this->db->setQuery($query, $offset, $threads_per_page); $threadids = $this->db->loadResultArray(); KunenaError::checkDatabaseError(); $idstr = implode(",", $threadids); $this->messages = array(); $this->threads = array(); $this->highlight = 0; $routerlist = array(); if (count($threadids) > 0) { $query = "SELECT a.*, j.id AS userid, t.message AS message, l.myfavorite, l.favcount, l.attachments,\n\t\t\t\t\t\t\tl.msgcount, l.lastid, l.lastid AS lastread, 0 AS unread, j.username, j.name AS uname, u.avatar, c.id AS catid, c.name AS catname, c.class_sfx\n\tFROM (\n\t\tSELECT m.thread, MAX(f.userid='{$this->my->id}') AS myfavorite, COUNT(DISTINCT f.userid) AS favcount, COUNT(a.mesid) AS attachments,\n\t\t\tCOUNT(DISTINCT m.id) AS msgcount, MAX(m.id) AS lastid, MAX(m.time) AS lasttime\n\t\tFROM #__kunena_messages AS m"; if ($this->config->allowfavorites) { $query .= " LEFT JOIN #__kunena_favorites AS f ON f.thread = m.thread"; } else { $query .= " LEFT JOIN #__kunena_favorites AS f ON f.thread = 0"; } $query .= "\n\t\tLEFT JOIN #__kunena_attachments AS a ON a.mesid = m.thread\n\t\tWHERE m.hold IN ({$hold}) AND m.thread IN ({$idstr})\n\t\tGROUP BY thread\n\t) AS l\n\tINNER JOIN #__kunena_messages AS a ON a.thread = l.thread\n\tINNER JOIN #__kunena_messages_text AS t ON a.thread = t.mesid\n\tLEFT JOIN #__users AS j ON j.id = a.userid\n\tLEFT JOIN #__kunena_users AS u ON u.userid = j.id\n\tLEFT JOIN #__kunena_categories AS c ON c.id = a.catid\n\tWHERE (a.parent='0' OR a.id=l.lastid)\n\tORDER BY ordering DESC, lastid DESC"; $this->db->setQuery($query); $this->messages = $this->db->loadObjectList('id'); KunenaError::checkDatabaseError(); // collect user ids for avatar prefetch when integrated $userlist = array(); foreach ($this->messages as $message) { if ($message->parent == 0) { $this->threads[$message->thread] = $message; $routerlist[$message->id] = $message->subject; if ($message->ordering) { $this->highlight++; } } if ($message->id == $message->lastid) { $this->lastreply[$message->thread] = $message; } $userlist[intval($message->userid)] = intval($message->userid); $userlist[intval($message->modified_by)] = intval($message->modified_by); } require_once KUNENA_PATH . '/router.php'; KunenaRouter::loadMessages($routerlist); if ($this->config->shownew && $this->my->id) { $readlist = $this->session->readtopics; $this->db->setQuery("SELECT thread, MIN(id) AS lastread, SUM(1) AS unread FROM #__kunena_messages " . "WHERE hold IN ({$hold}) AND moved='0' AND thread NOT IN ({$readlist}) AND thread IN ({$idstr}) AND time>{$this->db->Quote($this->prevCheck)} GROUP BY thread"); $msgidlist = $this->db->loadObjectList(); KunenaError::checkDatabaseError(); foreach ($msgidlist as $msgid) { $this->messages[$msgid->thread]->lastread = $msgid->lastread; $this->messages[$msgid->thread]->unread = $msgid->unread; } } } //Perform subscriptions check $kunena_cansubscribecat = 0; if ($this->config->allowsubscriptions && $this->config->category_subscriptions != 'disabled' && ("" != $this->my->id || 0 != $this->my->id)) { if ($this->objCatInfo->subscribeid == '') { $kunena_cansubscribecat = 1; } } //meta description and keywords $metaKeys = kunena_htmlspecialchars(JText::_('COM_KUNENA_CATEGORIES') . ", {$objCatParentInfo->name}, {$this->objCatInfo->name}, {$this->config->board_title}, " . $this->app->getCfg('sitename')); $metaDesc = kunena_htmlspecialchars("{$this->objCatInfo->description} ({$this->page}/{$this->totalpages})"); $document =& JFactory::getDocument(); $cur = $document->get('description'); $metaDesc = $cur . '. ' . $metaDesc; $document =& JFactory::getDocument(); $document->setMetadata('keywords', $metaKeys); $document->setDescription($metaDesc); $this->headerdesc = $this->objCatInfo->headerdesc; if (CKunenaTools::isModerator($this->my->id, $this->catid) || !$this->kunena_forum_locked) { //this user is allowed to post a new topic: $this->forum_new = CKunenaLink::GetPostNewTopicLink($this->catid, CKunenaTools::showButton('newtopic', JText::_('COM_KUNENA_BUTTON_NEW_TOPIC')), 'nofollow', 'kicon-button kbuttoncomm btn-left', JText::_('COM_KUNENA_BUTTON_NEW_TOPIC_LONG')); } if ($this->my->id != 0 && $this->total) { $this->forum_markread = CKunenaLink::GetCategoryActionLink('markthisread', $this->catid, CKunenaTools::showButton('markread', JText::_('COM_KUNENA_BUTTON_MARKFORUMREAD')), 'nofollow', 'kicon-button kbuttonuser btn-left', JText::_('COM_KUNENA_BUTTON_MARKFORUMREAD_LONG')); } // Thread Subscription if ($kunena_cansubscribecat == 1) { // this user is allowed to subscribe - check performed further up to eliminate duplicate checks // for top and bottom navigation $this->thread_subscribecat = CKunenaLink::GetCategoryActionLink('subscribecat', $this->catid, CKunenaTools::showButton('subscribe', JText::_('COM_KUNENA_BUTTON_SUBSCRIBE_CATEGORY')), 'nofollow', 'kicon-button kbuttonuser btn-left', JText::_('COM_KUNENA_BUTTON_SUBSCRIBE_CATEGORY_LONG')); } if ($this->my->id != 0 && $this->config->allowsubscriptions && $this->config->category_subscriptions != 'disabled' && $kunena_cansubscribecat == 0) { // this user is allowed to unsubscribe $this->thread_subscribecat = CKunenaLink::GetCategoryActionLink('unsubscribecat', $this->catid, CKunenaTools::showButton('subscribe', JText::_('COM_KUNENA_BUTTON_UNSUBSCRIBE_CATEGORY')), 'nofollow', 'kicon-button kbuttonuser btn-left', JText::_('COM_KUNENA_BUTTON_UNSUBSCRIBE_CATEGORY_LONG')); } //get the Moderator list for display $this->db->setQuery("SELECT * FROM #__kunena_moderation AS m INNER JOIN #__users AS u ON u.id=m.userid WHERE m.catid={$this->db->Quote($this->catid)} AND u.block=0"); $this->modslist = $this->db->loadObjectList(); KunenaError::checkDatabaseError(); foreach ($this->modslist as $mod) { $userlist[intval($mod->userid)] = intval($mod->userid); } // Prefetch all users/avatars to avoid user by user queries during template iterations if (!empty($userlist)) { KunenaUser::loadUsers($userlist); } $this->columns = CKunenaTools::isModerator($this->my->id, $this->catid) ? 6 : 5; $this->showposts = 0; $this->actionDropdown[] = JHTML::_('select.option', '', JText::_('COM_KUNENA_BULK_CHOOSE_ACTION')); }
function loadCategories() { if ($this->_loaded) { return; } $this->_loaded = true; $catids = array(); foreach ($this->categories[0] as $cat) { $catids[] = $cat->id; } if (empty($catids)) { return; } $catlist = implode(',', $catids); $readlist = $this->session->readtopics; if ($this->config->shownew && $this->my->id) { $subquery = " (SELECT COUNT(DISTINCT thread) FROM #__kunena_messages AS mmm WHERE c.id=mmm.catid AND mmm.hold='0' AND mmm.time>{$this->db->Quote($this->prevCheck)} AND mmm.thread NOT IN ({$readlist})) AS new"; } else { $subquery = " 0 AS new"; } // TODO: optimize this query (just combined many queries into one) $query = "SELECT c.*, m.id AS mesid, m.thread, m.catid, t.subject AS topicsubject, m.subject, m.name AS mname, u.id AS userid, u.username, u.name AS uname,\n\t\t\t(SELECT COUNT(*) FROM #__kunena_messages AS mm WHERE m.thread=mm.thread) AS msgcount, {$subquery}\n\t\t\tFROM #__kunena_categories AS c\n\t\t\tLEFT JOIN #__kunena_messages AS m ON c.id_last_msg=m.id\n\t\t\tLEFT JOIN #__kunena_messages AS t ON m.thread=t.id\n\t\t\tLEFT JOIN #__users AS u ON u.id=m.userid\n\t\t\tWHERE c.parent IN ({$catlist}) AND c.published='1' AND c.id IN({$this->session->allowed}) ORDER BY ordering, name"; $this->db->setQuery($query); $allsubcats = $this->db->loadObjectList(); if (KunenaError::checkDatabaseError()) { return; } $this->tabclass = array("row1", "row2"); $subcats = array(); $routerlist = array(); $userlist = array(); $myprofile = KunenaFactory::getUser(); if ($myprofile->ordering != '0') { $topic_ordering = $myprofile->ordering == '1' ? true : false; } else { $topic_ordering = $this->config->default_sort == 'asc' ? false : true; } foreach ($allsubcats as $i => $subcat) { if ($subcat->mesid) { $routerlist[$subcat->thread] = $subcat->subject; } if ($topic_ordering) { $subcat->page = 1; } else { $subcat->page = ceil($subcat->msgcount / $this->config->messages_per_page); } if ($this->config->shownew && $this->my->id != 0) { if ($subcat->new) { // Check Unread Cat Images if (is_file(KUNENA_ABSCATIMAGESPATH . $subcat->id . "_on.gif")) { $allsubcats[$i]->htmlCategoryIcon = "<img src=\"" . KUNENA_URLCATIMAGES . $subcat->id . "_on.gif\" border=\"0\" class='kforum-cat-image' alt=\" \" />"; } else { $allsubcats[$i]->htmlCategoryIcon = CKunenaTools::showIcon('kunreadforum', JText::_('COM_KUNENA_GEN_FORUM_NEWPOST')); } } else { // Check Read Cat Images if (is_file(KUNENA_ABSCATIMAGESPATH . $subcat->id . "_off.gif")) { $allsubcats[$i]->htmlCategoryIcon = "<img src=\"" . KUNENA_URLCATIMAGES . $subcat->id . "_off.gif\" border=\"0\" class='kforum-cat-image' alt=\" \" />"; } else { $allsubcats[$i]->htmlCategoryIcon = CKunenaTools::showIcon('kreadforum', JText::_('COM_KUNENA_GEN_FORUM_NOTNEW')); } } } else { if (is_file(KUNENA_ABSCATIMAGESPATH . $subcat->id . "_notlogin.gif")) { $allsubcats[$i]->htmlCategoryIcon = "<img src=\"" . KUNENA_URLCATIMAGES . $subcat->id . "_notlogin.gif\" border=\"0\" class='kforum-cat-image' alt=\" \" />"; } else { $allsubcats[$i]->htmlCategoryIcon = CKunenaTools::showIcon('knotloginforum', JText::_('COM_KUNENA_GEN_FORUM_NOTNEW')); } } // collect user ids for avatar prefetch when integrated $userlist[intval($subcat->userid)] = intval($subcat->userid); } require_once KUNENA_PATH . '/router.php'; KunenaRouter::loadMessages($routerlist); $modcats = array(); foreach ($allsubcats as $subcat) { $this->categories[$subcat->parent][] = $subcat; $subcats[] = $subcat->id; if ($subcat->moderated) { $modcats[] = $subcat->id; } } // Get the childforums $this->childforums = array(); if (count($subcats)) { $subcatlist = implode(',', $subcats); if ($this->config->shownew && $this->my->id) { $subquery = " (SELECT COUNT(DISTINCT thread) FROM #__kunena_messages AS m WHERE c.id=m.catid AND m.hold='0' AND m.time>{$this->db->Quote($this->prevCheck)} AND m.thread NOT IN ({$readlist})) AS new"; } else { $subquery = "0 AS new"; } $query = "SELECT c.id, c.name, c.description, c.parent, c.numTopics, c.numPosts, {$subquery}\n\t\t\tFROM #__kunena_categories AS c\n\t\t\tWHERE c.parent IN ({$subcatlist}) AND c.published='1' AND c.id IN({$this->session->allowed}) ORDER BY c.ordering, c.name"; $this->db->setQuery($query); $childforums = $this->db->loadObjectList(); KunenaError::checkDatabaseError(); foreach ($childforums as $i => $childforum) { //Begin: parent read unread iconset if ($this->config->showchildcaticon) { if ($this->config->shownew && $this->my->id != 0) { if ($childforum->new) { // Check Unread Cat Images if (is_file(KUNENA_ABSCATIMAGESPATH . $childforum->id . "_on_childsmall.gif")) { $childforum->htmlCategoryIcon = "<img src=\"" . KUNENA_URLCATIMAGES . $childforum->id . "_on_childsmall.gif\" border=\"0\" class='kforum-cat-image' alt=\" \" />"; } else { $childforum->htmlCategoryIcon = CKunenaTools::showIcon('kunreadforum-sm', JText::_('COM_KUNENA_GEN_FORUM_NEWPOST')); } } else { // Check Read Cat Images if (is_file(KUNENA_ABSCATIMAGESPATH . $childforum->id . "_off_childsmall.gif")) { $childforum->htmlCategoryIcon = "<img src=\"" . KUNENA_URLCATIMAGES . $childforum->id . "_off_childsmall.gif\" border=\"0\" class='kforum-cat-image' alt=\" \" />"; } else { $childforum->htmlCategoryIcon = CKunenaTools::showIcon('kreadforum-sm', JText::_('COM_KUNENA_GEN_FORUM_NOTNEW')); } } } else { // Not Login Cat Images if (is_file(KUNENA_ABSCATIMAGESPATH . $childforum->id . "_notlogin_childsmall.gif")) { $childforum->htmlCategoryIcon = "<img src=\"" . KUNENA_URLCATIMAGES . $childforum->id . "_notlogin_childsmall.gif\" border=\"0\" class='kforum-cat-image' alt=\" \" />"; } else { $childforum->htmlCategoryIcon = CKunenaTools::showIcon('knotloginforum-sm', JText::_('COM_KUNENA_GEN_FORUM_NOTNEW')); } } } else { $childforum->htmlCategoryIcon = ''; } $this->childforums[$childforum->parent][] = $childforum; } } $this->modlist = array(); $this->pending = array(); if (count($modcats)) { if ($this->config->listcat_show_moderators) { $modcatlist = implode(',', $modcats); $this->db->setQuery("SELECT * FROM #__kunena_moderation AS m\n\t\t\t\t\tINNER JOIN #__users AS u ON u.id=m.userid\n\t\t\t\t\tWHERE m.catid IN ({$modcatlist}) AND u.block=0"); $modlist = $this->db->loadObjectList(); KunenaError::checkDatabaseError(); foreach ($modlist as $mod) { $this->modlist[$mod->catid][] = $mod; $userlist[intval($mod->userid)] = intval($mod->userid); } } if (CKunenaTools::isModerator($this->my->id)) { foreach ($modcats as $i => $catid) { if (!CKunenaTools::isModerator($this->my->id, $catid)) { unset($modcats[$i]); } } if (count($modcats)) { $modcatlist = implode(',', $modcats); $this->db->setQuery("SELECT catid, COUNT(*) AS count\n\t\t\t\t\tFROM #__kunena_messages\n\t\t\t\t\tWHERE catid IN ({$modcatlist}) AND hold='1'\n\t\t\t\t\tGROUP BY catid"); $pending = $this->db->loadAssocList(); KunenaError::checkDatabaseError(); foreach ($pending as $i) { if ($i['count']) { $this->pending[$i['catid']] = $i['count']; } } } } } // Prefetch all users/avatars to avoid user by user queries during template iterations kimport('user'); KunenaUser::loadUsers($userlist); }
function __construct() { $this->app = JFactory::getApplication(); $this->config = KunenaFactory::getConfig(); $this->db = JFactory::getDBO(); $this->my = JFactory::getUser(); $this->me = KunenaFactory::getUser(); $this->search = JRequest::getVar('search', ''); $this->limitstart = JRequest::getInt('limitstart', 0); $this->limit = $querylimit = JRequest::getInt('limit', (int) $this->config->userlist_rows); jimport('joomla.html.pagination'); if (!$this->isAllowed()) { return false; } $filter_order = $this->app->getUserStateFromRequest('kunena.userlist.filter_order', 'filter_order', 'registerDate', 'cmd'); $filter_order_dir = $this->app->getUserStateFromRequest('kunena.userlist.filter_order_dir', 'filter_order_Dir', 'asc', 'word'); $direction = $filter_order_dir == 'asc' ? 'ASC' : 'DESC'; $orderby = " ORDER BY {$this->db->nameQuote($filter_order)} {$direction}"; if (empty($this->search)) { if ($this->config->userlist_count_users == '0') { $where = '1'; } elseif ($this->config->userlist_count_users == '1') { $where = '(block=0 OR activation="")'; } elseif ($this->config->userlist_count_users == '2') { $where = '(block=0 AND activation="")'; } elseif ($this->config->userlist_count_users == '3') { $where = 'block=0'; } } else { $where = '1'; } // Total $this->db->setQuery("SELECT COUNT(*) FROM #__users WHERE {$where}"); $this->total = $this->db->loadResult(); KunenaError::checkDatabaseError(); // Search total $query = "SELECT COUNT(*) FROM #__users AS u INNER JOIN #__kunena_users AS fu ON u.id=fu.userid WHERE {$where}"; if ($this->search != "") { if (!JRequest::checkToken()) { $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error'); while (@ob_end_clean()) { } $this->app->redirect(CKunenaLink::GetUserlistURL()); return false; } $query .= " AND (u.name LIKE '%{$this->db->getEscaped($this->search)}%' OR u.username LIKE '%{$this->db->getEscaped($this->search)}%')"; } $this->db->setQuery($query); $total = $this->db->loadResult(); KunenaError::checkDatabaseError(); if ($this->limit > $total) { $this->limitstart = 0; } // this is need to show something when the user choose all, but we need to limit even the 'all' with a number if ($this->limit == 0) { $querylimit = '150'; } $useridAdmin = KUNENA_JOOMLA_COMPAT == '1.5' ? '62' : '42'; // Select query $moderator = intval($this->me->isModerator()); $query = "SELECT u.id, u.name, u.username, u.usertype, IF(fu.hideEmail=0 OR {$moderator},u.email,'') AS email, u.registerDate, u.lastvisitDate, fu.userid, fu.showOnline, fu.group_id, fu.posts, fu.karma, fu.uhits " . " FROM #__users AS u INNER JOIN #__kunena_users AS fu ON fu.userid = u.id WHERE {$where}"; $this->searchuri = ""; if ($this->search != "") { $query .= " AND (name LIKE '%{$this->db->getEscaped($this->search)}%' OR username LIKE '%{$this->db->getEscaped($this->search)}%') AND u.id NOT IN ({$useridAdmin})"; $this->searchuri .= "&search=" . $this->search; } else { $query .= " AND u.id NOT IN ({$useridAdmin})"; } $query .= $orderby; $query .= " LIMIT {$this->limitstart}, {$querylimit}"; $this->db->setQuery($query); $this->users = $this->db->loadObjectList(); KunenaError::checkDatabaseError(); $userlist = array(); foreach ($this->users as $user) { $userlist[intval($user->userid)] = intval($user->userid); } // Prefetch all users/avatars to avoid user by user queries during template iterations KunenaUser::loadUsers($userlist); // table ordering $this->order_dir = $filter_order_dir; $this->order = $filter_order; if ($this->search == "") { $this->search = JText::_('COM_KUNENA_USRL_SEARCH'); } $this->pageNav = new JPagination($total, $this->limitstart, $this->limit); $this->allow = true; $template = KunenaFactory::getTemplate(); $this->params = $template->params; }