public function getCatsubcriptions() { $db = JFactory::getDBO(); $userid = $this->getState($this->getName() . '.id'); $subscatslist = KunenaForumCategoryHelper::getSubscriptions($userid); return $subscatslist; }
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 category display. * * @return void * * @throws KunenaExceptionAuthorise */ protected function before() { parent::before(); require_once KPATH_SITE . '/models/category.php'; $this->model = new KunenaModelCategory(); $this->me = KunenaUserHelper::getMyself(); $catid = $this->input->getInt('catid'); $limitstart = $this->input->getInt('limitstart', 0); $limit = $this->input->getInt('limit', 0); if ($limit < 1 || $limit > 100) { $limit = $this->config->threads_per_page; } // TODO: $direction = 'DESC'; $this->category = KunenaForumCategoryHelper::get($catid); $this->category->tryAuthorise(); $this->headerText = JText::_('COM_KUNENA_THREADS_IN_FORUM') . ': ' . $this->category->name; $topic_ordering = $this->category->topic_ordering; $access = KunenaAccess::getInstance(); $hold = $access->getAllowedHold($this->me, $catid); $moved = 1; $params = array('hold' => $hold, 'moved' => $moved); switch ($topic_ordering) { case 'alpha': $params['orderby'] = 'tt.ordering DESC, tt.subject ASC '; break; case 'creation': $params['orderby'] = 'tt.ordering DESC, tt.first_post_time ' . $direction; break; case 'lastpost': default: $params['orderby'] = 'tt.ordering DESC, tt.last_post_time ' . $direction; } list($this->total, $this->topics) = KunenaForumTopicHelper::getLatestTopics($catid, $limitstart, $limit, $params); if ($this->total > 0) { // 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. if ($lastreadlist || $this->me->isAdmin() || KunenaAccess::getInstance()->getModeratorStatus()) { KunenaForumMessageHelper::loadLocation($lastpostlist + $lastreadlist); } } $this->topicActions = $this->model->getTopicActions(); $this->actionMove = $this->model->getActionMove(); $this->pagination = new KunenaPagination($this->total, $limitstart, $limit); $this->pagination->setDisplayedPages(5); }
/** * Get categories for a specific user. * * @param bool|array|int $ids The category ids to load. * @param mixed $user The user id to load. * * @return KunenaForumCategoryUser[] */ static public function getCategories($ids = false, $user = null) { $user = KunenaUserHelper::get($user); if ($ids === false) { // Get categories which are seen by current user $ids = KunenaForumCategoryHelper::getCategories(); } elseif (!is_array ($ids) ) { $ids = array($ids); } // Convert category objects into ids foreach ($ids as $i => $id) { if ($id instanceof KunenaForumCategory) $ids[$i] = $id->id; } $ids = array_unique($ids); self::loadCategories($ids, $user); $list = array (); foreach ( $ids as $id ) { if (!empty(self::$_instances [$user->userid][$id])) { $list [$id] = self::$_instances [$user->userid][$id]; } } return $list; }
/** * Prepare category display. * * @return void * * @throws KunenaExceptionAuthorise */ protected function before() { parent::before(); require_once KPATH_SITE . '/models/category.php'; $catid = $this->input->getInt('catid'); $this->category = KunenaForumCategoryHelper::get($catid); $this->category->tryAuthorise(); }
/** * Test getCategories() */ public function testGetCategories() { $categories = KunenaForumCategoryHelper::getCategories(); $categoryusers = KunenaForumCategoryUserHelper::getCategories(); foreach ($categories as $category) { $this->assertTrue(isset($categoryusers[$category->id])); $this->assertEquals($category->id, $categoryusers[$category->id]->category_id); } }
/** * Test getCategories() */ public function testGetAllCategories() { $categories = KunenaForumCategoryHelper::getCategories(); $this->assertInternalType('array', $categories); foreach ($categories as $id=>$category) { $this->assertEquals($id, $category->id); $this->assertTrue($category->exists()); $this->assertSame($category, KunenaForumCategoryHelper::get($id)); } }
function check() { $user = KunenaUserHelper::get($this->user_id); if (!$user->exists()) { $this->setError ( JText::sprintf ( 'COM_KUNENA_LIB_TABLE_USERCATEGORIES_ERROR_USER_INVALID', (int) $user->userid ) ); } if ($this->category_id && !KunenaForumCategoryHelper::get($this->category_id)->exists()) { $this->setError ( JText::sprintf ( 'COM_KUNENA_LIB_TABLE_USERCATEGORIES_ERROR_CATEGORY_INVALID', (int) $category->id ) ); } return ($this->getError () == ''); }
/** * @return array */ public function getCategories() { $rows = \KunenaForumCategoryHelper::getChildren( 0, 10, array( 'action' => 'admin', 'unpublished' => true ) ); $options = array(); foreach ( $rows as $row ) { $options[] = \moscomprofilerHTML::makeOption( (string) $row->id, str_repeat( '- ', $row->level + 1 ) . ' ' . $row->name ); } return $options; }
/** * Send list of topic icons in JSON for the category set selected * * @return string */ public function displayTopicIcons() { jimport('joomla.filesystem.folder'); $catid = $this->app->input->getInt('catid', 0); $category = KunenaForumCategoryHelper::get($catid); $category_iconset = $category->iconset; if (empty($category_iconset)) { $response = array(); // Set the MIME type and header for JSON output. $this->document->setMimeEncoding('application/json'); JResponse::setHeader('Content-Disposition', 'attachment; filename="' . $this->getName() . '.' . $this->getLayout() . '.json"'); echo json_encode($response); } $topicIcons = array(); $template = KunenaFactory::getTemplate(); $xmlfile = JPATH_ROOT . '/media/kunena/topic_icons/' . $category_iconset . '/topicicons.xml'; if (is_file($xmlfile)) { $xml = simplexml_load_file($xmlfile); foreach ($xml->icons as $icons) { $type = (string) $icons->attributes()->type; $width = (int) $icons->attributes()->width; $height = (int) $icons->attributes()->height; foreach ($icons->icon as $icon) { $attributes = $icon->attributes(); $icon = new stdClass(); $icon->id = (int) $attributes->id; $icon->type = (string) $attributes->type ? (string) $attributes->type : $type; $icon->name = (string) $attributes->name; if ($icon->type != 'user') { $icon->id = $icon->type . '_' . $icon->name; } $icon->iconset = $category_iconset; $icon->published = (int) $attributes->published; $icon->title = (string) $attributes->title; $icon->b2 = (string) $attributes->b2; $icon->b3 = (string) $attributes->b3; $icon->fa = (string) $attributes->fa; $icon->filename = (string) $attributes->src; $icon->width = (int) $attributes->width ? (int) $attributes->width : $width; $icon->height = (int) $attributes->height ? (int) $attributes->height : $height; $icon->path = JURI::root() . 'media/kunena/topic_icons/' . $category_iconset . '/' . $icon->filename; $icon->relpath = $template->getTopicIconPath("{$icon->filename}", false, $category_iconset); $topicIcons[] = $icon; } } } // Set the MIME type and header for JSON output. $this->document->setMimeEncoding('application/json'); JResponse::setHeader('Content-Disposition', 'attachment; filename="' . $this->getName() . '.' . $this->getLayout() . '.json"'); echo json_encode($topicIcons); }
public function check() { $category = KunenaForumCategoryHelper::get($this->category_id); if (!$category->exists()) { $this->setError(JText::sprintf('COM_KUNENA_LIB_TABLE_TOPICS_ERROR_CATEGORY_INVALID', $category->id)); } else { $this->category_id = $category->id; } $this->subject = trim($this->subject); if (!$this->subject) { $this->setError(JText::sprintf('COM_KUNENA_LIB_TABLE_TOPICS_ERROR_NO_SUBJECT')); } return $this->getError() == ''; }
/** * 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)); }
function save() { $db = JFactory::getDBO (); $app = JFactory::getApplication (); if (! JRequest::checkToken ()) { $app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' ); $app->redirect ( KunenaRoute::_($this->baseurl, false) ); } $newview = JRequest::getVar ( 'newview' ); $newrank = JRequest::getVar ( 'newrank' ); $signature = JRequest::getVar ( 'message' ); $deleteSig = JRequest::getVar ( 'deleteSig' ); $moderator = JRequest::getInt ( 'moderator' ); $uid = JRequest::getInt ( 'uid' ); $avatar = JRequest::getVar ( 'avatar' ); $deleteAvatar = JRequest::getVar ( 'deleteAvatar' ); $neworder = JRequest::getInt ( 'neworder' ); $modCatids = $moderator ? JRequest::getVar ( 'catid', array () ) : array(); if ($deleteSig == 1) { $signature = ""; } $avatar = ''; if ($deleteAvatar == 1) { $avatar = ",avatar=''"; } $db->setQuery ( "UPDATE #__kunena_users SET signature={$db->quote($signature)}, view='$newview', ordering='$neworder', rank='$newrank' $avatar WHERE userid='$uid'" ); $db->query (); if (KunenaError::checkDatabaseError()) return; $app->enqueueMessage ( JText::_ ( 'COM_KUNENA_USER_PROFILE_SAVED_SUCCESSFULLY' ) ); // Update moderator rights $me = KunenaUserHelper::getMyself(); $categories = KunenaForumCategoryHelper::getCategories(false, false, 'admin'); $user = KunenaFactory::getUser($uid); foreach ($categories as $category) { $category->setModerator($user, in_array($category->id, $modCatids)); } // Global moderator is a special case if ($me->isAdmin()) { KunenaFactory::getAccessControl()->setModerator(0, $user, in_array(0, $modCatids)); } $app->redirect ( KunenaRoute::_($this->baseurl, false) ); }
/** * 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'); }
/** * @param XmapDisplayerInterface $xmap * @param stdClass $parent * @param array $params * @param int $catid */ private static function getCategoryTree($xmap, stdClass $parent, array &$params, $catid) { /** @var KunenaForumCategory[] $categories */ $categories = KunenaForumCategoryHelper::getChildren($catid); $xmap->changeLevel(1); foreach ($categories as $cat) { $node = new stdClass(); $node->id = $parent->id; $node->browserNav = $parent->browserNav; $node->uid = $parent->uid . '_c_' . $cat->id; $node->name = $cat->name; $node->priority = $params['cat_priority']; $node->changefreq = $params['cat_changefreq']; $node->link = 'index.php?option=com_kunena&view=category&catid=' . $cat->id . '&Itemid=' . $parent->id; $node->secure = $parent->secure; if ($xmap->printNode($node)) { self::getTopics($xmap, $parent, $params, $cat->id); } } $xmap->changeLevel(-1); }
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)); }
/** * Prepare topic list for moderators. * * @return void */ protected function before() { parent::before(); $this->me = KunenaUserHelper::getMyself(); $access = KunenaAccess::getInstance(); $this->moreUri = null; $params = $this->app->getParams('com_kunena'); $start = $this->input->getInt('limitstart', 0); $limit = $this->input->getInt('limit', 0); if ($limit < 1 || $limit > 100) { $limit = $this->config->threads_per_page; } // Get configuration from menu item. $categoryIds = $params->get('topics_categories', array()); $reverse = !$params->get('topics_catselection', 1); // Make sure that category list is an array. if (!is_array($categoryIds)) { $categoryIds = explode(',', $categoryIds); } if (!$reverse && empty($categoryIds) || in_array(0, $categoryIds)) { $categoryIds = false; } $categories = KunenaForumCategoryHelper::getCategories($categoryIds, $reverse); $finder = new KunenaForumTopicFinder(); $finder->filterByCategories($categories)->filterAnsweredBy(array_keys($access->getModerators() + $access->getAdmins()), true)->filterByMoved(false)->where('locked', '=', 0); $this->pagination = new KunenaPagination($finder->count(), $start, $limit); if ($this->moreUri) { $this->pagination->setUri($this->moreUri); } $this->topics = $finder->order('last_post_time', -1)->start($this->pagination->limitstart)->limit($this->pagination->limit)->find(); if ($this->topics) { $this->prepareTopics(); } $actions = array('delete', 'approve', 'undelete', 'move', 'permdelete'); $this->actions = $this->getTopicActions($this->topics, $actions); // TODO <- $this->headerText = JText::_('Topics Needing Attention'); }
function displayFooter($tpl = null) { require_once KPATH_SITE . '/lib/kunena.link.class.php'; $catid = 0; if (KunenaFactory::getConfig ()->enablerss) { if ($catid > 0) { kimport ( 'kunena.forum.category.helper' ); $category = KunenaForumCategoryHelper::get ( $catid ); if ($category->pub_access == 0 && $category->parent) $rss_params = '&catid=' . ( int ) $catid; } else { $rss_params = ''; } if (isset ( $rss_params )) { $document = JFactory::getDocument (); $document->addCustomTag ( '<link rel="alternate" type="application/rss+xml" title="' . JText::_ ( 'COM_KUNENA_LISTCAT_RSS' ) . '" href="' . CKunenaLink::GetRSSURL ( $rss_params ) . '" />' ); $this->assign ( 'rss', CKunenaLink::GetRSSLink ( $this->getIcon ( 'krss', JText::_('COM_KUNENA_LISTCAT_RSS') ), 'follow', $rss_params )); } } $template = KunenaFactory::getTemplate (); $credits = CKunenaLink::GetTeamCreditsLink ( $catid, JText::_('COM_KUNENA_POWEREDBY') ) . ' ' . CKunenaLink::GetCreditsLink (); if ($template->params->get('templatebyText') !='') { $credits .= ' :: <a href ="'. $template->params->get('templatebyLink').'" rel="follow">' . $template->params->get('templatebyText') .' '. $template->params->get('templatebyName') .'</a>'; } $this->assign ( 'credits', $credits ); $result = $this->loadTemplate($tpl); if (JError::isError($result)) { return $result; } echo $result; }
public function loadCategoryCount() { if ($this->sectionCount === null) { $this->sectionCount = $this->categoryCount = 0; $categories = KunenaForumCategoryHelper::getCategories(false, false, 'none'); foreach ($categories as $category) { if (!$category->published) { continue; } if ($category->isSection()) { $this->sectionCount++; } else { $this->categoryCount++; $this->topicCount += $category->numTopics; $this->messageCount += $category->numPosts; } } } }
/** * Method to change the title & alias. * * @param integer $category_id The id of the category. * @param string $alias The alias. * @param string $name The name. * * @return array Contains the modified title and alias. * * @since 2.0.0-BETA2 */ protected function _generateNewTitle($category_id, $alias, $name) { while (KunenaForumCategoryHelper::getAlias($category_id, $alias)) { $name = JString::increment($name); $alias = JString::increment($alias, 'dash'); } return array($name, $alias); }
<?php /** * Kunena Component * @package Kunena.Template.Crypsis * @subpackage Pages.Topic * * @copyright (C) 2008 - 2016 Kunena Team. All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL * @link https://www.kunena.org **/ defined('_JEXEC') or die; $content = $this->execute('Topic/Form/Reply'); // Display breadcrumb path to the current category / topic / message / moderate. $parents = KunenaForumCategoryHelper::getParents($content->category->id); $parents[] = $content->category; /** @var KunenaForumCategory $parent */ foreach ($parents as $parent) { $this->addBreadcrumb( $parent->displayField('name'), $parent->getUri() ); } $this->addBreadcrumb( $content->topic->subject, $content->topic->getUri() );
/** * 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); }
protected function buildInfo() { if ($this->_topics !== false) return; $this->_topics = 0; $this->_posts = 0; $this->_lastid = 0; $categories = $this->getChannels(); $categories += KunenaForumCategoryHelper::getChildren($this->id); foreach ($categories as $category) { $category->buildInfo(); $this->_topics += $category->numTopics; $this->_posts += $category->numPosts; if (KunenaForumCategoryHelper::get($this->_lastid)->last_post_time < $category->last_post_time) $this->_lastid = $category->id; } }
public static function categorylist($name, $parent, $options = array(), $params = array(), $attribs = null, $key = 'value', $text = 'text', $selected = array(), $idtag = false, $translate = false) { $unpublished = isset($params['unpublished']) ? (bool) $params['unpublished'] : 0; $sections = isset($params['sections']) ? (bool) $params['sections'] : 0; $ordering = isset($params['ordering']) ? (string) $params['ordering'] : 'ordering'; $direction = isset($params['direction']) && $params['direction'] == 'desc' ? -1 : 1; $action = isset($params['action']) ? (string) $params['action'] : 'read'; $levels = isset($params['levels']) ? (int) $params['levels'] : 10; $topleveltxt = isset($params['toplevel']) ? $params['toplevel'] : false; $catid = isset($params['catid']) ? (int) $params['catid'] : 0; $hide_lonely = isset($params['hide_lonely']) ? (bool) $params['hide_lonely'] : 0; $params = array(); $params['ordering'] = $ordering; $params['direction'] = $direction; $params['unpublished'] = $unpublished; $params['action'] = $action; $params['selected'] = $catid; if ($catid) { $category = KunenaForumCategoryHelper::get($catid); if (!$category->getParent()->authorise($action) && !KunenaUserHelper::getMyself()->isAdmin()) { $categories = KunenaForumCategoryHelper::getParents($catid, $levels, $params); } } $channels = array(); if (!isset($categories)) { $category = KunenaForumCategoryHelper::get($parent); $children = KunenaForumCategoryHelper::getChildren($parent, $levels, $params); if ($params['action'] == 'topic.create') { $channels = $category->getChannels(); if (empty($children) && !isset($channels[$category->id])) { $category = KunenaForumCategoryHelper::get(); } foreach ($channels as $id => $channel) { if (!$id || $category->id == $id || isset($children[$id]) || !$channel->authorise($action)) { unset($channels[$id]); } } } $categories = $category->id > 0 ? array($category->id => $category) + $children : $children; if ($hide_lonely && count($categories) + count($channels) <= 1) { return; } } if (!is_array($options)) { $options = array(); } if ($selected === false || $selected === null) { $selected = array(); } elseif (!is_array($selected)) { $selected = array((string) $selected); } if ($topleveltxt) { $me = KunenaUserHelper::getMyself(); $disabled = $action == 'admin' && !$me->isAdmin(); $options[] = JHtml::_('select.option', '0', JText::_($topleveltxt), 'value', 'text', $disabled); if (empty($selected) && !$disabled) { $selected[] = 0; } $toplevel = 1; } else { $toplevel = -KunenaForumCategoryHelper::get($parent)->level; } foreach ($categories as $category) { $disabled = !$category->authorise($action) || !$sections && $category->isSection(); if (empty($selected) && !$disabled) { $selected[] = $category->id; } $options[] = JHtml::_('select.option', $category->id, str_repeat('- ', $category->level + $toplevel) . ' ' . $category->name, 'value', 'text', $disabled); } $disabled = false; foreach ($channels as $category) { if (empty($selected)) { $selected[] = $category->id; } $options[] = JHtml::_('select.option', $category->id, '+ ' . $category->getParent()->name . ' / ' . $category->name, 'value', 'text', $disabled); } reset($options); if (is_array($attribs)) { $attribs = JArrayHelper::toString($attribs); } $id = $name; if ($idtag) { $id = $idtag; } $id = str_replace('[', '', $id); $id = str_replace(']', '', $id); $html = ''; if (!empty($options)) { $html .= '<select name="' . $name . '" id="' . $id . '" ' . $attribs . '>'; $html .= JHtml::_('select.options', $options, $key, $text, $selected, $translate); $html .= '</select>'; } return $html; }
/** * @return KunenaForumCategory */ public function getCategory() { return KunenaForumCategoryHelper::get($this->category_id); }
function check() { $category = KunenaForumCategoryHelper::get($this->catid); if (!$category->exists()) { // TODO: maybe we should have own error message? or not? $this->setError ( JText::sprintf ( 'COM_KUNENA_LIB_TABLE_TOPICS_ERROR_CATEGORY_INVALID', $this->catid ) ); } else { $this->catid = $category->id; } $this->subject = trim($this->subject); if (!$this->subject) { $this->setError ( JText::_ ( 'COM_KUNENA_LIB_TABLE_MESSAGES_ERROR_NO_SUBJECT' ) ); } $this->message = trim($this->message); if (!$this->message) { $this->setError ( JText::_ ( 'COM_KUNENA_LIB_TABLE_MESSAGES_ERROR_NO_MESSAGE' ) ); } if (!$this->time) { $this->time = JFactory::getDate()->toUnix(); } $this->modified_reason = trim($this->modified_reason); return ($this->getError () == ''); }
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); }
/** * @param int $catid * @param bool $type * * @return stdClass|string */ public function getRank($catid = 0, $type = false) { // Default rank $rank = new stdClass(); $rank->rank_id = false; $rank->rank_title = null; $rank->rank_min = 0; $rank->rank_special = 0; $rank->rank_image = null; $config = KunenaFactory::getConfig(); $category = KunenaForumCategoryHelper::get($catid); if (!$config->showranking) { return; } if (self::$_ranks === null) { $this->_db->setQuery("SELECT * FROM #__kunena_ranks"); self::$_ranks = $this->_db->loadObjectList('rank_id'); KunenaError::checkDatabaseError(); } $rank->rank_title = JText::_('COM_KUNENA_RANK_USER'); $rank->rank_image = 'rank0.gif'; if ($this->userid == 0) { $rank->rank_id = 0; $rank->rank_title = JText::_('COM_KUNENA_RANK_VISITOR'); $rank->rank_special = 1; } else { if ($this->isBanned()) { $rank->rank_id = 0; $rank->rank_title = JText::_('COM_KUNENA_RANK_BANNED'); $rank->rank_special = 1; $rank->rank_image = 'rankbanned.gif'; foreach (self::$_ranks as $cur) { if ($cur->rank_special == 1 && JFile::stripExt($cur->rank_image) == 'rankbanned') { $rank = $cur; break; } } } else { if ($this->rank != 0 && isset(self::$_ranks[$this->rank])) { $rank = self::$_ranks[$this->rank]; } else { if ($this->rank == 0 && $this->isAdmin($category)) { $rank->rank_id = 0; $rank->rank_title = JText::_('COM_KUNENA_RANK_ADMINISTRATOR'); $rank->rank_special = 1; $rank->rank_image = 'rankadmin.gif'; foreach (self::$_ranks as $cur) { if ($cur->rank_special == 1 && JFile::stripExt($cur->rank_image) == 'rankadmin') { $rank = $cur; break; } } } else { if ($this->rank == 0 && $this->isModerator($category)) { $rank->rank_id = 0; $rank->rank_title = JText::_('COM_KUNENA_RANK_MODERATOR'); $rank->rank_special = 1; $rank->rank_image = 'rankmod.gif'; foreach (self::$_ranks as $cur) { if ($cur->rank_special == 1 && JFile::stripExt($cur->rank_image) == 'rankmod') { $rank = $cur; break; } } } } } } } if ($rank->rank_id === false) { //post count rank $rank->rank_id = 0; foreach (self::$_ranks as $cur) { if ($cur->rank_special == 0 && $cur->rank_min <= $this->posts && $cur->rank_min >= $rank->rank_min) { $rank = $cur; } } } if ($type == 'title') { return $rank->rank_title; } if ($type == 'image') { $template = KunenaTemplate::getInstance(); if (!$config->rankimages) { return; } $iconurl = $template->getRankPath($rank->rank_image, true); return '<img src="' . $iconurl . '" alt="" />'; } if (!$config->rankimages) { $rank->rank_image = null; } return $rank; }
function kunena_200_2011_12_14_aliases($parent) { $config = KunenaFactory::getConfig(); // Create views foreach (KunenaRoute::$views as $view => $dummy) { kCreateAlias('view', $view, $view, 1); } // Create layouts foreach (KunenaRoute::$layouts as $layout => $dummy) { kCreateAlias('layout', "category.{$layout}", "category/{$layout}", 1); kCreateAlias('layout', "category.{$layout}", $layout, 0); } // Create legacy functions foreach (KunenaRouteLegacy::$functions as $func => $dummy) { kCreateAlias('legacy', $func, $func, 1); } $categories = KunenaForumCategoryHelper::getCategories(false, false, 'none'); $aliasLit = $aliasUtf = array(); // Create SEF: id foreach ($categories as $category) { kCreateCategoryAlias($category, $category->id); // Create SEF names $aliasUtf[$category->id] = kStringURLSafe($category->name); $aliasLit[$category->id] = JFilterOutput::stringURLSafe($category->name); } // Sort aliases by category id (oldest ID accepts also sefcat format.. ksort($categories); // Create SEF: id-name and id-Name (UTF8) foreach ($categories as $id => $category) { $created = false; if ($config->get('sefutf8')) { $name = $aliasUtf[$category->id]; if (!empty($name)) { $created = kCreateCategoryAlias($category, "{$id}-{$name}", 1); } } $name = $aliasLit[$category->id]; if (!empty($name)) { kCreateCategoryAlias($category, "{$id}-{$name}", !$created); } } // Create SEF: name and Name (UTF8) if ($config->get('sefcats')) { foreach ($categories as $category) { $created = false; if ($config->get('sefutf8')) { $name = $aliasUtf[$category->id]; $keys = array_keys($aliasUtf, $name); if (!empty($name)) { $created = kCreateCategoryAlias($category, $name, count($keys) == 1); } } $name = $aliasLit[$category->id]; $keys = array_keys($aliasLit, $name); if (!empty($name)) { kCreateCategoryAlias($category, $name, !$created && count($keys) == 1); } } } return array('action' => '', 'name' => JText::_('COM_KUNENA_INSTALL_200_ALIASES'), 'success' => true); }