/** * Prepare user attachments list. * * @return void */ protected function before() { parent::before(); $userid = $this->input->getInt('userid'); $params = array('file' => '1', 'image' => '1', 'orderby' => 'desc', 'limit' => '30'); $this->template = KunenaFactory::getTemplate(); $this->me = KunenaUserHelper::getMyself(); $this->profile = KunenaUserHelper::get($userid); $this->attachments = KunenaAttachmentHelper::getByUserid($this->profile, $params); // Pre-load messages. $messageIds = array(); foreach ($this->attachments as $attachment) { $messageIds[] = (int) $attachment->mesid; } $messages = KunenaForumMessageHelper::getMessages($messageIds, 'none'); // Pre-load topics. $topicIds = array(); foreach ($messages as $message) { $topicIds[] = $message->thread; } KunenaForumTopicHelper::getTopics($topicIds, 'none'); $this->headerText = JText::_('COM_KUNENA_MANAGE_ATTACHMENTS'); }
function recount() { $app = JFactory::getApplication (); $state = $app->getUserState ( 'com_kunena.admin.recount', null ); if ($state === null) { // First run $query = "SELECT MAX(id) FROM #__kunena_messages"; $db = JFactory::getDBO(); $db->setQuery ( $query ); $state = new StdClass(); $state->step = 0; $state->maxId = (int) $db->loadResult (); $state->start = 0; } $this->checkTimeout(); while (1) { $count = mt_rand(95000, 105000); switch ($state->step) { case 0: // Update topic statistics kimport('kunena.forum.topic.helper'); KunenaForumTopicHelper::recount(false, $state->start, $state->start+$count); $state->start += $count; //$app->enqueueMessage ( JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_TOPICS', min($state->start, $state->maxId), $state->maxId) ); break; case 1: // Update usertopic statistics kimport('kunena.forum.topic.user.helper'); KunenaForumTopicUserHelper::recount(false, $state->start, $state->start+$count); $state->start += $count; //$app->enqueueMessage ( JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_USERTOPICS', min($state->start, $state->maxId), $state->maxId) ); break; case 2: // Update user statistics kimport('kunena.user.helper'); KunenaUserHelper::recount(); //$app->enqueueMessage ( JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_USER') ); break; case 3: // Update category statistics kimport('kunena.forum.category.helper'); KunenaForumCategoryHelper::recount(); //$app->enqueueMessage ( JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_CATEGORY') ); break; default: $app->setUserState ( 'com_kunena.admin.recount', null ); $app->enqueueMessage (JText::_('COM_KUNENA_RECOUNTFORUMS_DONE')); $this->setRedirect(KunenaRoute::_('index.php?option=com_kunena', false)); return; } if (!$state->start || $state->start > $state->maxId) { $state->step++; $state->start = 0; } if ($this->checkTimeout()) break; } $app->setUserState ( 'com_kunena.admin.recount', $state ); $this->setRedirect(KunenaRoute::_('index.php?option=com_kunena&view=recount&task=recount', false)); }
/** * Prepare reply history display. * * @return void */ protected function before() { parent::before(); $id = $this->input->getInt('id'); $this->topic = KunenaForumTopicHelper::get($id); $this->history = KunenaForumMessageHelper::getMessagesByTopic($this->topic, 0, (int) $this->config->historylimit, 'DESC'); $this->replycount = $this->topic->getReplies(); $this->historycount = count($this->history); KunenaAttachmentHelper::getByMessage($this->history); $userlist = array(); foreach ($this->history as $message) { $userlist[(int) $message->userid] = (int) $message->userid; } KunenaUserHelper::loadUsers($userlist); // Run events $params = new JRegistry(); $params->set('ksource', 'kunena'); $params->set('kunena_view', 'topic'); $params->set('kunena_layout', 'history'); $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('kunena'); $dispatcher->trigger('onKunenaPrepare', array('kunena.messages', &$this->history, &$params, 0)); // FIXME: need to improve BBCode class on this... $this->attachments = KunenaAttachmentHelper::getByMessage($this->history); $this->inline_attachments = array(); $this->headerText = JText::_('COM_KUNENA_POST_EDIT') . ' ' . $this->topic->subject; }
/** * Prepare report message form. * * @return void * * @throws KunenaExceptionAuthorise */ protected function before() { parent::before(); $id = $this->input->getInt('id'); $mesid = $this->input->getInt('mesid'); $me = KunenaUserHelper::getMyself(); if (!$this->config->reportmsg) { // Deny access if report feature has been disabled. throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), 404); } if (!$me->exists()) { // Deny access if user is guest. throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), 401); } if (!$mesid) { $this->topic = KunenaForumTopicHelper::get($id); $this->topic->tryAuthorise(); } else { $this->message = KunenaForumMessageHelper::get($mesid); $this->message->tryAuthorise(); $this->topic = $this->message->getTopic(); } $this->category = $this->topic->getCategory(); $this->uri = "index.php?option=com_kunena&view=topic&layout=report&catid={$this->category->id}" . "&id={$this->topic->id}" . ($this->message ? "&mesid={$this->message->id}" : ''); }
/** * Method to get the options of the topic * * @return array */ public function getTopicOptions() { $options = array(); // Start with default options. if (!$this->message) { $options[] = JHtml::_('select.option', 0, JText::_('COM_KUNENA_MODERATION_MOVE_TOPIC')); } else { $options[] = JHtml::_('select.option', 0, JText::_('COM_KUNENA_MODERATION_CREATE_TOPIC')); } $options[] = JHtml::_('select.option', -1, JText::_('COM_KUNENA_MODERATION_ENTER_TOPIC')); // Then list a few topics. $db = JFactory::getDbo(); $params = array( 'orderby' => 'tt.last_post_time DESC', 'where' => " AND tt.id != {$db->Quote($this->topic->id)} "); list ($total, $topics) = KunenaForumTopicHelper::getLatestTopics($this->category->id, 0, 30, $params); foreach ($topics as $topic) { $options[] = JHtml::_('select.option', $topic->id, $this->escape($topic->subject)); } return $options; }
/** * Prepare topics by pre-loading needed information. * * @param array $userIds List of additional user Ids to be loaded. * @param array $mesIds List of additional message Ids to be loaded. * * @return void */ protected function prepareTopics(array $userIds = array(), array $mesIds = array()) { // Collect user Ids for avatar prefetch when integrated. $lastIds = array(); foreach ($this->topics as $topic) { $userIds[(int) $topic->first_post_userid] = (int) $topic->first_post_userid; $userIds[(int) $topic->last_post_userid] = (int) $topic->last_post_userid; $lastIds[(int) $topic->last_post_id] = (int) $topic->last_post_id; } // Prefetch all users/avatars to avoid user by user queries during template iterations. if (!empty($userIds)) { KunenaUserHelper::loadUsers($userIds); } $topicIds = array_keys($this->topics); KunenaForumTopicHelper::getUserTopics($topicIds); /* KunenaForumTopicHelper::getKeywords($topicIds); */ $mesIds += KunenaForumTopicHelper::fetchNewStatus($this->topics); // Fetch also last post positions when user can see unapproved or deleted posts. // TODO: Optimize? Take account of configuration option... if ($this->me->isAdmin() || KunenaAccess::getInstance()->getModeratorStatus()) { $mesIds += $lastIds; } // Load position information for all selected messages. if ($mesIds) { KunenaForumMessageHelper::loadLocation($mesIds); } }
public function getSubscriptions() { $db = JFactory::getDBO(); $userid = $this->getState($this->getName() . '.id'); $db->setQuery("SELECT topic_id AS thread FROM #__kunena_user_topics WHERE user_id='$userid' AND subscribed=1"); $subslist = (array) $db->loadObjectList(); if (KunenaError::checkDatabaseError()) { return array(); } $topic_list = array(); if (!empty($subslist)) { foreach ($subslist as $sub) { $topic_list[] = $sub->thread; } $topic_list = KunenaForumTopicHelper::getTopics($topic_list); } return $topic_list; }
/** * Test getTopics() */ public function testGetTopics() { list($count, $topics) = KunenaForumTopicHelper::getLatestTopics(false, 0, 20); $topicusers = KunenaForumTopicUserHelper::getTopics($topics); foreach ($topics as $topic) { $this->assertTrue(isset($topicusers[$topic->id])); $this->assertEquals($topic->id, $topicusers[$topic->id]->topic_id); } }
/** * Prepare topic reply form. * * @return void * * @throws RuntimeException * @throws KunenaExceptionAuthorise */ protected function before() { parent::before(); $catid = $this->input->getInt('catid'); $id = $this->input->getInt('id'); $mesid = $this->input->getInt('mesid'); $quote = $this->input->getBool('quote', false); $saved = $this->app->getUserState('com_kunena.postfields'); $this->me = KunenaUserHelper::getMyself(); $this->template = KunenaFactory::getTemplate(); if (!$mesid) { $this->topic = KunenaForumTopicHelper::get($id); $parent = KunenaForumMessageHelper::get($this->topic->first_post_id); } else { $parent = KunenaForumMessageHelper::get($mesid); $this->topic = $parent->getTopic(); } $this->category = $this->topic->getCategory(); if ($parent->isAuthorised('reply') && $this->me->canDoCaptcha()) { if (JPluginHelper::isEnabled('captcha')) { $plugin = JPluginHelper::getPlugin('captcha'); $params = new JRegistry($plugin[0]->params); $captcha_pubkey = $params->get('public_key'); $catcha_privkey = $params->get('private_key'); if (!empty($captcha_pubkey) && !empty($catcha_privkey)) { JPluginHelper::importPlugin('captcha'); $dispatcher = JDispatcher::getInstance(); $result = $dispatcher->trigger('onInit', 'dynamic_recaptcha_1'); $this->captchaEnabled = $result[0]; } } else { $this->captchaEnabled = false; } } $parent->tryAuthorise('reply'); // Run event. $params = new JRegistry(); $params->set('ksource', 'kunena'); $params->set('kunena_view', 'topic'); $params->set('kunena_layout', 'reply'); $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('kunena'); $dispatcher->trigger('onKunenaPrepare', array('kunena.topic', &$this->topic, &$params, 0)); // Can user edit topic icons? if ($this->config->topicicons && $this->topic->isAuthorised('edit')) { $this->topicIcons = $this->template->getTopicIcons(false, $saved ? $saved['icon_id'] : $this->topic->icon_id); } list($this->topic, $this->message) = $parent->newReply($saved ? $saved : $quote); $this->action = 'post'; $this->allowedExtensions = KunenaAttachmentHelper::getExtensions($this->category); $this->post_anonymous = $saved ? $saved['anonymous'] : !empty($this->category->post_anonymous); $this->subscriptionschecked = $saved ? $saved['subscribe'] : $this->config->subscriptionschecked == 1; $this->app->setUserState('com_kunena.postfields', null); $this->canSubscribe = $this->canSubscribe(); $this->headerText = JText::_('COM_KUNENA_BUTTON_MESSAGE_REPLY') . ' ' . $this->topic->subject; }
/** * Test new KunenaForumTopicUser() */ public function testNew() { $admin = KunenaFactory::getUser('admin'); list($count, $topics) = KunenaForumTopicHelper::getLatestTopics(false, 0, 1); self::$topic = reset($topics); $topicuser = new KunenaForumTopicUser(self::$topic->id, $admin); $this->assertInstanceOf('KunenaForumTopicUser', $topicuser); $this->assertFalse($topicuser->exists()); $this->assertEquals(self::$topic->id, $topicuser->topic_id); $this->assertEquals($admin->userid, $topicuser->user_id); }
function displaySubscriptions() { $id = $this->app->input->get('id', 0, 'int'); $topic = KunenaForumTopicHelper::get($id); $acl = KunenaAccess::getInstance(); $cat_subscribers = $acl->loadSubscribers($topic, KunenaAccess::CATEGORY_SUBSCRIPTION); $this->cat_subscribers_users = KunenaUserHelper::loadUsers($cat_subscribers); $topic_subscribers = $acl->loadSubscribers($topic, KunenaAccess::TOPIC_SUBSCRIPTION); $this->topic_subscribers_users = KunenaUserHelper::loadUsers($topic_subscribers); $this->cat_topic_subscribers = $acl->getSubscribers($topic->getCategory()->id, $id, KunenaAccess::CATEGORY_SUBSCRIPTION | KunenaAccess::TOPIC_SUBSCRIPTION, 1, 1); $this->display(); }
public function check() { $user = KunenaUserHelper::get($this->user_id); $topic = KunenaForumTopicHelper::get($this->topic_id); if (!$user->exists()) { $this->setError(JText::sprintf('COM_KUNENA_LIB_TABLE_USERTOPICS_ERROR_USER_INVALID', (int) $user->userid)); } if (!$topic->exists()) { $this->setError(JText::sprintf('COM_KUNENA_LIB_TABLE_USERTOPICS_ERROR_TOPIC_INVALID', (int) $topic->id)); } $this->category_id = $topic->category_id; return $this->getError() == ''; }
/** * @param mixed $topic * @param mixed $user * * @internal */ public function __construct($topic = null, $user = null) { $topic = KunenaForumTopicHelper::get($topic); // Always fill empty data $this->_db = JFactory::getDBO(); // Create the table object $table = $this->getTable(); // Lets bind the data $this->setProperties($table->getProperties()); $this->_exists = false; $this->topic_id = $topic->exists() ? $topic->id : null; $this->category_id = $topic->exists() ? $topic->category_id : null; $this->user_id = KunenaUserHelper::get($user)->userid; }
/** * Redirect unread layout to the page that contains the first unread message. * * @return void * * @throws KunenaExceptionAuthorise */ protected function before() { $catid = $this->input->getInt('catid', 0); $id = $this->input->getInt('id', 0); $category = KunenaForumCategoryHelper::get($catid); $category->tryAuthorise(); $topic = KunenaForumTopicHelper::get($id); $topic->tryAuthorise(); KunenaForumTopicHelper::fetchNewStatus(array($topic->id => $topic)); $message = KunenaForumMessageHelper::get($topic->lastread ? $topic->lastread : $topic->last_post_id); $message->tryAuthorise(); while (@ob_end_clean()) { } $this->app->redirect($topic->getUrl($category, false, $message)); }
/** * Prepare topic moderate display. * * @return void * * @throws KunenaExceptionAuthorise */ protected function before() { parent::before(); $catid = $this->input->getInt('catid'); $id = $this->input->getInt('id'); $mesid = $this->input->getInt('mesid'); if (!$mesid) { $this->topic = KunenaForumTopicHelper::get($id); $this->topic->tryAuthorise('move'); } else { $this->message = KunenaForumMessageHelper::get($mesid); $this->message->tryAuthorise('move'); $this->topic = $this->message->getTopic(); } $this->category = $this->topic->getCategory(); $this->uri = "index.php?option=com_kunena&view=topic&layout=moderate" . "&catid={$this->category->id}&id={$this->topic->id}" . ($this->message ? "&mesid={$this->message->id}" : ''); $this->title = !$this->message ? JText::_('COM_KUNENA_TITLE_MODERATE_TOPIC') : JText::_('COM_KUNENA_TITLE_MODERATE_MESSAGE'); // Load topic icons if available. if ($this->config->topicicons) { $this->template = KunenaTemplate::getInstance(); $this->template->setCategoryIconset(); $this->topicIcons = $this->template->getTopicIcons(false); } // Have a link to moderate user as well. if (isset($this->message)) { $user = $this->message->getAuthor(); if ($user->exists()) { $username = $user->getName(); $this->userLink = $this->message->userid ? JHtml::_('kunenaforum.link', 'index.php?option=com_kunena&view=user&layout=moderate&userid=' . $this->message->userid, $username . ' (' . $this->message->userid . ')', $username . ' (' . $this->message->userid . ')') : null; } } if ($this->message) { $this->banHistory = KunenaUserBan::getUserHistory($this->message->userid); $this->me = KunenaFactory::getUser(); // Get thread and reply count from current message: $db = JFactory::getDbo(); $query = "SELECT COUNT(mm.id) AS replies FROM #__kunena_messages AS m\r\n\t\t\t\tINNER JOIN #__kunena_messages AS t ON m.thread=t.id\r\n\t\t\t\tLEFT JOIN #__kunena_messages AS mm ON mm.thread=m.thread AND mm.time > m.time\r\n\t\t\t\tWHERE m.id={$db->Quote($this->message->id)}"; $db->setQuery($query, 0, 1); $this->replies = $db->loadResult(); if (KunenaError::checkDatabaseError()) { return; } } $this->banInfo = KunenaUserBan::getInstanceByUserid(JFactory::getUser()->id, true); }
/** * Prepare category subscriptions display. * * @return void * * @throws KunenaExceptionAuthorise */ protected function before() { parent::before(); $me = KunenaUserHelper::getMyself(); if (!$me->exists()) { throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), 401); } $limit = $this->input->getInt('limit', 0); if ($limit < 1 || $limit > 100) { $limit = 20; } $limitstart = $this->input->getInt('limitstart', 0); if ($limitstart < 0) { $limitstart = 0; } list($total, $this->categories) = KunenaForumCategoryHelper::getLatestSubscriptions($me->userid); $topicIds = array(); $userIds = array(); $postIds = array(); foreach ($this->categories as $category) { // Get list of topics. if ($category->last_topic_id) { $topicIds[$category->last_topic_id] = $category->last_topic_id; } } // Pre-fetch topics (also display unauthorized topics as they are in allowed categories). $topics = KunenaForumTopicHelper::getTopics($topicIds, 'none'); // Pre-fetch users (and get last post ids for moderators). foreach ($topics as $topic) { $userIds[$topic->last_post_userid] = $topic->last_post_userid; $postIds[$topic->id] = $topic->last_post_id; } KunenaUserHelper::loadUsers($userIds); KunenaForumMessageHelper::getMessages($postIds); // Pre-fetch user related stuff. if ($me->exists() && !$me->isBanned()) { // Load new topic counts. KunenaForumCategoryHelper::getNewTopics(array_keys($this->categories)); } $this->actions = $this->getActions(); $this->pagination = new JPagination($total, $limitstart, $limit); $this->headerText = JText::_('COM_KUNENA_CATEGORY_SUBSCRIPTIONS'); }
/** * Prepare poll display. * * @return void * * @throws KunenaExceptionAuthorise */ protected function before() { parent::before(); $this->topic = KunenaForumTopicHelper::get($this->input->getInt('id')); $this->category = $this->topic->getCategory(); $this->config = KunenaFactory::getConfig(); $this->me = KunenaUserHelper::getMyself(); // Need to check if poll is allowed in this category. $this->topic->tryAuthorise('poll.read'); $this->poll = $this->topic->getPoll(); $this->usercount = $this->poll->getUserCount(); $this->usersvoted = $this->poll->getUsers(); $this->voted = $this->poll->getMyVotes(); if (!empty($this->alwaysVote)) { // Authorise forced vote. $this->topic->tryAuthorise('poll.vote'); $this->name = 'Topic/Poll/Vote'; } elseif (!$this->voted && $this->topic->isAuthorised('poll.vote')) { $this->name = 'Topic/Poll/Vote'; } else { $this->name = 'Topic/Poll/Results'; $this->show_title = true; $this->users_voted_list = array(); $this->users_voted_morelist = array(); if ($this->config->pollresultsuserslist && !empty($this->usersvoted)) { $userids_votes = array(); foreach ($this->usersvoted as $userid => $vote) { $userids_votes[] = $userid; } $loaded_users = KunenaUserHelper::loadUsers($userids_votes); $i = 0; foreach ($loaded_users as $userid => $user) { if ($i <= '4') { $this->users_voted_list[] = $loaded_users[$userid]->getLink(); } else { $this->users_voted_morelist[] = $loaded_users[$userid]->getLink(); } $i++; } } } $this->uri = "index.php?option=com_kunena&view=topic&layout=poll&catid={$this->category->id}&id={$this->topic->id}"; }
static public function getMessagesByTopic($topic, $start=0, $limit=0, $ordering='ASC', $hold=0, $orderbyid = false) { $topic = KunenaForumTopicHelper::get($topic); if (!$topic->exists()) return array(); $total = $topic->getTotal(); if ($start < 0) $start = 0; if ($limit < 1) $limit = KunenaFactory::getConfig()->messages_per_page; // If out of range, use last page if ($total < $start) $start = intval($total / $limit) * $limit; $ordering = strtoupper($ordering); if ($ordering != 'DESC') $ordering = 'ASC'; return self::loadMessagesByTopic($topic->id, $start, $limit, $ordering, $hold, $orderbyid); }
function doprune() { $app = JFactory::getApplication (); if (!JRequest::checkToken()) { $app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' ); $this->setRedirect(KunenaRoute::_($this->baseurl, false)); return; } $category = KunenaForumCategoryHelper::get(JRequest::getInt ( 'prune_forum', 0 )); if (!$category->authorise('admin')) { $app->enqueueMessage ( JText::_ ( 'COM_KUNENA_CHOOSEFORUMTOPRUNE' ), 'error' ); $this->setRedirect(KunenaRoute::_($this->baseurl, false)); return; } // Convert days to seconds for timestamp functions... $prune_days = JRequest::getInt ( 'prune_days', 36500 ); $prune_date = JFactory::getDate()->toUnix() - ($prune_days * 86400); $trashdelete = JRequest::getInt( 'trashdelete', 0); // Get up to 100 oldest topics to be deleted $params = array( 'orderby'=>'tt.last_post_time ASC', 'where'=>"AND tt.last_post_time<{$prune_date} AND ordering=0", ); list($count, $topics) = KunenaForumTopicHelper::getLatestTopics($category->id, 0, 100, $params); $deleted = 0; foreach ( $topics as $topic ) { $deleted++; if ( $trashdelete ) $topic->delete(false); else $topic->trash(); } KunenaUserHelper::recount(); KunenaForumCategoryHelper::recount(); KunenaForumMessageAttachmentHelper::cleanup(); if ( $trashdelete ) $app->enqueueMessage ( "" . JText::_('COM_KUNENA_FORUMPRUNEDFOR') . " " . $prune_days . " " . JText::_('COM_KUNENA_PRUNEDAYS') . "; " . JText::_('COM_KUNENA_PRUNEDELETED') . " {$deleted}/{$count} " . JText::_('COM_KUNENA_PRUNETHREADS') ); else $app->enqueueMessage ( "" . JText::_('COM_KUNENA_FORUMPRUNEDFOR') . " " . $prune_days . " " . JText::_('COM_KUNENA_PRUNEDAYS') . "; " . JText::_('COM_KUNENA_PRUNETRASHED') . " {$deleted}/{$count} " . JText::_('COM_KUNENA_PRUNETHREADS') ); $this->setRedirect(KunenaRoute::_($this->baseurl, false)); }
/** * @param int $limit * * @return array */ public function loadTopPolls($limit = 0) { $limit = $limit ? $limit : $this->_config->poppollscount; if (count($this->topPolls) < $limit) { $query = "SELECT poll.threadid AS id, SUM(opt.votes) AS count\n\t\t\t\t\tFROM #__kunena_polls_options AS opt\n\t\t\t\t\tINNER JOIN #__kunena_polls AS poll ON poll.id=opt.pollid\n\t\t\t\t\tGROUP BY pollid\n\t\t\t\t\tHAVING count > 0\n\t\t\t\t\tORDER BY count DESC"; $this->_db->setQuery($query, 0, $limit); $polls = (array) $this->_db->loadObjectList('id'); KunenaError::checkDatabaseError(); $this->topPolls = KunenaForumTopicHelper::getTopics(array_keys($polls)); $top = reset($this->topPolls); if (!$top) { return array(); } $top->title = JText::_('COM_KUNENA_LIB_STAT_TOP_POLLS'); $top->titleName = JText::_('COM_KUNENA_POLL_STATS_NAME'); $top->titleCount = JText::_('COM_KUNENA_USRL_VOTES'); $top->count = $polls[$top->id]->count; foreach ($this->topPolls as &$item) { $item = clone $item; $item->count = $polls[$item->id]->count; $item->link = JHtml::_('kunenaforum.link', $item->getUri(), KunenaHtmlParser::parseText($item->subject)); $item->percent = round(100 * $item->count / $top->count); } } return array_slice($this->topPolls, 0, $limit); }
/** * Perform recount on statistics in smaller chunks. * * @return void * @throws Exception */ public function dorecount() { $ajax = $this->input->getWord('format', 'html') == 'json'; if (!JSession::checkToken('request')) { $this->setResponse(array('success' => false, 'header' => JText::_('COM_KUNENA_AJAX_ERROR'), 'message' => JText::_('COM_KUNENA_AJAX_DETAILS_BELOW'), 'error' => JText::_('COM_KUNENA_ERROR_TOKEN')), $ajax); $this->setRedirect(KunenaRoute::_($this->baseurl, false)); return; } $state = $this->app->getUserState('com_kunena.admin.recount', null); try { $this->checkTimeout(); while (1) { // Topic count per run. // TODO: count isn't accurate as it can overflow total. $count = mt_rand(4500, 5500); switch ($state->step) { case 0: if ($state->topics) { // Update topic statistics KunenaForumTopicHelper::recount(false, $state->start, $state->start + $count); $state->start += $count; $msg = JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_TOPICS_X', round(min(100 * $state->start / $state->maxId + 1, 100)) . '%'); } break; case 1: if ($state->usertopics) { // Update user's topic statistics KunenaForumTopicUserHelper::recount(false, $state->start, $state->start + $count); $state->start += $count; $msg = JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_USERTOPICS_X', round(min(100 * $state->start / $state->maxId + 1, 100)) . '%'); } break; case 2: if ($state->categories) { // Update category statistics KunenaForumCategoryHelper::recount(); KunenaForumCategoryHelper::fixAliases(); $msg = JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_CATEGORIES_X', '100%'); } break; case 3: if ($state->users) { // Update user statistics KunenaUserHelper::recount(); $msg = JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_USERS_X', '100%'); } break; case 4: if ($state->polls) { // Update user statistics KunenaForumTopicPollHelper::recount(); $msg = JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_POLLS_X', '100%'); } break; default: $header = JText::_('COM_KUNENA_RECOUNTFORUMS_DONE'); $msg = JText::_('COM_KUNENA_AJAX_REQUESTED_RECOUNTED'); $this->app->setUserState('com_kunena.admin.recount', null); $this->setResponse(array('success' => true, 'status' => '100%', 'header' => $header, 'message' => $msg), $ajax); $this->setRedirect(KunenaRoute::_($this->baseurl, false), $header); return; } $state->current = min($state->current + $count, $state->total); if (!$state->start || $state->start > $state->maxId) { $state->step++; $state->start = 0; } if ($this->checkTimeout()) { break; } } $state->reload++; $this->app->setUserState('com_kunena.admin.recount', $state); } catch (Exception $e) { if (!$ajax) { throw $e; } $this->setResponse(array('success' => false, 'status' => sprintf("%2.1f%%", 99 * $state->current / ($state->total + 1)), 'header' => JText::_('COM_KUNENA_AJAX_ERROR'), 'message' => JText::_('COM_KUNENA_AJAX_DETAILS_BELOW'), 'error' => $e->getMessage()), $ajax); } $token = JSession::getFormToken() . '=1'; $redirect = KunenaRoute::_("{$this->baseurl}&task=dorecount&i={$state->reload}&{$token}", false); $this->setResponse(array('success' => true, 'status' => sprintf("%2.1f%%", 99 * $state->current / ($state->total + 1)), 'header' => JText::_('COM_KUNENA_AJAX_RECOUNT_WAIT'), 'message' => $msg, 'href' => $redirect), $ajax); }
/** * Retrieves a list of tasks created by a particular user. * * @since 1.0 * @access public * @param int $userId The user's / creator's id. * * @return Array A list of notes item. */ public function getPosts($userId, $total = 10) { $db = FD::db(); $sql = $db->sql(); $sql->select('#__kunena_messages', 'a'); $sql->column('a.thread'); $sql->where('a.parent', 0); $sql->where('a.userid', $userId); $sql->where('a.hold', '0', '='); $sql->order('a.time', 'DESC'); $sql->limit(0, $total); $db->setQuery($sql); $result = $db->loadColumn(); if (!$result) { return array(); } $posts = KunenaForumTopicHelper::getTopics($result); return $posts; }
/** * @param XmapDisplayerInterface $xmap * @param stdClass $parent * @param array $params * @param int $catid */ private static function getTopics($xmap, stdClass $parent, array &$params, $catid) { self::getCategoryTree($xmap, $parent, $params, $catid); if (!$params['include_topics']) { return; } /** @var KunenaForumTopic[] $topics */ $topics = KunenaForumTopicHelper::getLatestTopics($catid, 0, $params['limit'], array('nolimit' => true, 'starttime' => $params['days'])); $topics = $topics[1]; if (empty($topics)) { return; } $xmap->changeLevel(1); foreach ($topics as $topic) { $node = new stdClass(); $node->id = $parent->id; $node->browserNav = $parent->browserNav; $node->uid = $parent->uid . '_t_' . $topic->id; $node->name = $topic->subject; $node->priority = $params['topic_priority']; $node->changefreq = $params['topic_changefreq']; $node->modified = $topic->last_post_time; $node->link = 'index.php?option=com_kunena&view=topic&catid=' . $topic->category_id . '&id=' . $topic->id; $node->secure = $parent->secure; if ($xmap->printNode($node) && $params['include_pagination']) { $msgPerPage = KunenaFactory::getConfig()->get('messages_per_page'); $threadPages = ceil($topic->getTotal() / $msgPerPage); if ($threadPages > 1) { $xmap->changeLevel(1); for ($i = 2; $i <= $threadPages; $i++) { $subnode = new stdClass(); $subnode->id = $node->id; $subnode->uid = $node->uid . '_p_' . $i; $subnode->name = '[' . $i . ']'; $subnode->link = $node->link . '&limitstart=' . ($i - 1) * $msgPerPage; $subnode->browserNav = $node->browserNav; $subnode->priority = $node->priority; $subnode->changefreq = $node->changefreq; $subnode->modified = $node->modified; $subnode->secure = $node->secure; $xmap->printNode($subnode); } $xmap->changeLevel(-1); } } } $xmap->changeLevel(-1); }
/** * Method to get details on selected items. * * @return Array * @since 1.6 */ public function getPurgeItems() { kimport('kunena.error'); $app = JFactory::getApplication (); $ids = $app->getUserState ( 'com_kunena.purge' ); $topic = $app->getUserState('com_kunena.topic'); $message = $app->getUserState('com_kunena.message'); $ids = implode ( ',', $ids ); if ( $topic ) { $items = KunenaForumTopicHelper::getTopics($ids); } elseif ( $message ) { $items = KunenaForumMessageHelper::getMessages($ids); } else { } return $items; }
protected function _common() { if ($this->total > 0) { $config = KunenaFactory::getConfig (); // collect user ids for avatar prefetch when integrated $userlist = array(); $lastpostlist = array(); foreach ( $this->topics as $topic ) { $userlist[intval($topic->first_post_userid)] = intval($topic->first_post_userid); $userlist[intval($topic->last_post_userid)] = intval($topic->last_post_userid); $lastpostlist[intval($topic->last_post_id)] = intval($topic->last_post_id); } // Prefetch all users/avatars to avoid user by user queries during template iterations if ( !empty($userlist) ) KunenaUserHelper::loadUsers($userlist); KunenaForumTopicHelper::getUserTopics(array_keys($this->topics)); KunenaForumTopicHelper::getKeywords(array_keys($this->topics)); $lastreadlist = KunenaForumTopicHelper::fetchNewStatus($this->topics); // Fetch last / new post positions when user can see unapproved or deleted posts $me = KunenaUserHelper::get(); if (($lastpostlist || $lastreadlist) && $me->userid && $me->isModerator()) { KunenaForumMessageHelper::loadLocation($lastpostlist + $lastreadlist); } } }
/** * Free up memory by cleaning up all cached items. */ public static function cleanup() { self::$_instances = array(); }
/** * @param array $userlist * @param array $postlist */ protected function _common(array $userlist = array(), array $postlist = array()) { if ($this->total > 0) { // collect user ids for avatar prefetch when integrated $lastpostlist = array(); foreach ($this->topics as $topic) { $userlist[intval($topic->first_post_userid)] = intval($topic->first_post_userid); $userlist[intval($topic->last_post_userid)] = intval($topic->last_post_userid); $lastpostlist[intval($topic->last_post_id)] = intval($topic->last_post_id); } // Prefetch all users/avatars to avoid user by user queries during template iterations if (!empty($userlist)) { KunenaUserHelper::loadUsers($userlist); } KunenaForumTopicHelper::getUserTopics(array_keys($this->topics)); KunenaForumTopicHelper::getKeywords(array_keys($this->topics)); $lastreadlist = KunenaForumTopicHelper::fetchNewStatus($this->topics); // Fetch last / new post positions when user can see unapproved or deleted posts if ($postlist || $lastreadlist || $this->me->userid && ($this->me->isAdmin() || KunenaAccess::getInstance()->getModeratorStatus())) { KunenaForumMessageHelper::loadLocation($postlist + $lastpostlist + $lastreadlist); } } }
function displayBreadcrumb($tpl = null) { $catid = JRequest::getInt ( 'catid', 0 ); $id = JRequest::getInt ( 'id', 0 ); $view = JRequest::getWord ( 'view', 'default' ); $layout = JRequest::getWord ( 'layout', 'default' ); $app = JFactory::getApplication(); $pathway = $app->getPathway(); $active = JFactory::getApplication()->getMenu ()->getActive (); if (empty($this->pathway)) { if ($catid) { $parents = KunenaForumCategoryHelper::getParents($catid); $parents[$catid] = KunenaForumCategoryHelper::get($catid); // Remove categories from pathway if menu item contains/excludes them if (!empty($active->query['catid']) && isset($parents[$active->query['catid']])) { $curcatid = $active->query['catid']; while (($item = array_shift($parents)) !== null) { if ($item->id == $curcatid) break; } } foreach ( $parents as $parent ) { $pathway->addItem($this->escape( $parent->name ), KunenaRoute::normalize("index.php?option=com_kunena&view=category&catid={$parent->id}")); } } if ($id) { $topic = KunenaForumTopicHelper::get($id); $pathway->addItem($this->escape( $topic->subject ), KunenaRoute::normalize("index.php?option=com_kunena&view=category&catid={$catid}&id={$topic->id}")); } if ($view == 'topic') { $active_layout = (!empty($active->query['view']) && $active->query['view'] == 'topic' && !empty($active->query['layout'])) ? $active->query['layout'] : ''; switch ($layout) { case 'create': if ($active_layout != 'create') $pathway->addItem($this->escape( JText::_('COM_KUNENA_BUTTON_NEW_TOPIC'), KunenaRoute::normalize() )); break; case 'reply': if ($active_layout != 'reply') $pathway->addItem($this->escape( JText::_('COM_KUNENA_BUTTON_REPLY_TOPIC'), KunenaRoute::normalize() )); break; case 'edit': if ($active_layout != 'edit') $pathway->addItem($this->escape( JText::_('COM_KUNENA_BUTTON_EDIT'), KunenaRoute::normalize() )); break; } } } $this->pathway = array(); foreach ($pathway->getPathway() as $pitem) { $item = new StdClass(); $item->name = $this->escape($pitem->name); $item->link = KunenaRoute::_($pitem->link); if ($item->link) $this->pathway[] = $item; } $result = $this->loadTemplate($tpl); if (JError::isError($result)) { return $result; } echo $result; }
function recountCategories() { $app = JFactory::getApplication(); $state = $app->getUserState('com_kunena.install.recount', null); // Only perform this stage if database needs recounting (upgrade from older version) $version = $this->getVersion(); if (version_compare($version->version, '2.0.0-DEV', ">")) { return true; } if ($state === null) { // First run $query = "SELECT MAX(id) FROM #__kunena_messages"; $this->db->setQuery($query); $state = new StdClass(); $state->step = 0; $state->maxId = (int) $this->db->loadResult(); $state->start = 0; } while (1) { $count = mt_rand(95000, 105000); switch ($state->step) { case 0: // Update topic statistics KunenaForumTopicHelper::recount(false, $state->start, $state->start + $count); $state->start += $count; $this->addStatus(JText::sprintf('COM_KUNENA_MIGRATE_RECOUNT_TOPICS', min($state->start, $state->maxId), $state->maxId), true, '', 'recount'); break; case 1: // Update usertopic statistics KunenaForumTopicUserHelper::recount(false, $state->start, $state->start + $count); $state->start += $count; $this->addStatus(JText::sprintf('COM_KUNENA_MIGRATE_RECOUNT_USERTOPICS', min($state->start, $state->maxId), $state->maxId), true, '', 'recount'); break; case 2: // Update user statistics KunenaUserHelper::recount(); $this->addStatus(JText::sprintf('COM_KUNENA_MIGRATE_RECOUNT_USER'), true, '', 'recount'); break; case 3: // Update category statistics KunenaForumCategoryHelper::recount(); $this->addStatus(JText::sprintf('COM_KUNENA_MIGRATE_RECOUNT_CATEGORY'), true, '', 'recount'); break; default: $app->setUserState('com_kunena.install.recount', null); $this->addStatus(JText::_('COM_KUNENA_MIGRATE_RECOUNT_DONE'), true, '', 'recount'); return true; } if (!$state->start || $state->start > $state->maxId) { $state->step++; $state->start = 0; } if ($this->checkTimeout()) { break; } } $app->setUserState('com_kunena.install.recount', $state); return false; }
/** * Prepare category list display. * * @return void */ protected function before() { parent::before(); require_once KPATH_SITE . '/models/topics.php'; $this->model = new KunenaModelTopics(array(), $this->input); $this->model->initialize($this->getOptions(), $this->getOptions()->get('embedded', false)); $this->state = $this->model->getState(); $this->me = KunenaUserHelper::getMyself(); $this->moreUri = null; $this->embedded = $this->getOptions()->get('embedded', false); if ($this->embedded) { $this->moreUri = new JUri('index.php?option=com_kunena&view=topics&layout=posts&mode=' . $this->state->get('list.mode') . '&userid=' . $this->state->get('user') . '&sel=' . $this->state->get('list.time') . '&limit=' . $this->state->get('list.limit')); $this->moreUri->setVar('Itemid', KunenaRoute::getItemID($this->moreUri)); } $start = $this->state->get('list.start'); $limit = $this->state->get('list.limit'); // Handle &sel=x parameter. $time = $this->state->get('list.time'); if ($time < 0) { $time = null; } elseif ($time == 0) { $time = new JDate(KunenaFactory::getSession()->lasttime); } else { $time = new JDate(JFactory::getDate()->toUnix() - $time * 3600); } $userid = $this->state->get('user'); $user = is_numeric($userid) ? KunenaUserHelper::get($userid) : null; // Get categories for the filter. $categoryIds = $this->state->get('list.categories'); $reverse = !$this->state->get('list.categories.in'); $authorise = 'read'; $order = 'time'; $finder = new KunenaForumMessageFinder(); $finder->filterByTime($time); switch ($this->state->get('list.mode')) { case 'unapproved': $authorise = 'topic.post.approve'; $finder->filterByUser(null, 'author')->filterByHold(array(1)); break; case 'deleted': $authorise = 'topic.post.undelete'; $finder->filterByUser($user, 'author')->filterByHold(array(2, 3)); break; case 'mythanks': $finder->filterByUser($user, 'thanker')->filterByHold(array(0)); break; case 'thankyou': $finder->filterByUser($user, 'thankee')->filterByHold(array(0)); break; default: $finder->filterByUser($user, 'author')->filterByHold(array(0)); break; } $categories = KunenaForumCategoryHelper::getCategories($categoryIds, $reverse, $authorise); $finder->filterByCategories($categories); $this->pagination = new KunenaPagination($finder->count(), $start, $limit); if ($this->moreUri) { $this->pagination->setUri($this->moreUri); } $this->messages = $finder->order($order, -1)->start($this->pagination->limitstart)->limit($this->pagination->limit)->find(); // Load topics... $topicIds = array(); foreach ($this->messages as $message) { $topicIds[(int) $message->thread] = (int) $message->thread; } $this->topics = KunenaForumTopicHelper::getTopics($topicIds, 'none'); $userIds = $mesIds = array(); foreach ($this->messages as $message) { $userIds[(int) $message->userid] = (int) $message->userid; $mesIds[(int) $message->id] = (int) $message->id; } if ($this->topics) { $this->prepareTopics($userIds, $mesIds); } switch ($this->state->get('list.mode')) { case 'unapproved': $this->headerText = JText::_('COM_KUNENA_VIEW_TOPICS_POSTS_MODE_UNAPPROVED'); $actions = array('approve', 'delete', 'permdelete'); break; case 'deleted': $this->headerText = JText::_('COM_KUNENA_VIEW_TOPICS_POSTS_MODE_DELETED'); $actions = array('undelete', 'delete', 'permdelete'); break; case 'mythanks': $this->headerText = JText::_('COM_KUNENA_VIEW_TOPICS_POSTS_MODE_MYTHANKS'); $actions = array('approve', 'delete', 'permdelete'); break; case 'thankyou': $this->headerText = JText::_('COM_KUNENA_VIEW_TOPICS_POSTS_MODE_THANKYOU'); $actions = array('approve', 'delete', 'permdelete'); break; case 'recent': default: $this->headerText = JText::_('COM_KUNENA_VIEW_TOPICS_POSTS_MODE_DEFAULT'); $actions = array('delete', 'permdelete'); } $this->actions = $this->getMessageActions($this->messages, $actions); }