function prune() { if (!JRequest::checkToken()) { $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error'); $this->setRedirect(KunenaRoute::_($this->baseurl, false)); return; } $categories = KunenaForumCategoryHelper::getCategories(JRequest::getVar('prune_forum', array(0)), false, 'admin'); if (!$categories) { $this->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); $where = array(); $where[] = " AND tt.last_post_time < {$prune_date}"; $controloptions = JRequest::getString('controloptions', 0); if ($controloptions == 'answered') { $where[] = 'AND tt.posts>1'; } elseif ($controloptions == 'unanswered') { $where[] = 'AND tt.posts=1'; } elseif ($controloptions == 'locked') { $where[] = 'AND tt.locked>0'; } elseif ($controloptions == 'deleted') { $where[] = 'AND tt.hold IN (2,3)'; } elseif ($controloptions == 'unapproved') { $where[] = 'AND tt.hold=1'; } elseif ($controloptions == 'shadow') { $where[] = 'AND tt.moved_id>0'; } elseif ($controloptions == 'normal') { $where[] = 'AND tt.locked=0'; } elseif ($controloptions == 'all') { // No filtering } else { $where[] = 'AND 0'; } // Keep sticky topics? if (JRequest::getInt('keepsticky', 1)) { $where[] = ' AND tt.ordering=0'; } $where = implode(' ', $where); $params = array('where' => $where); $count = 0; foreach ($categories as $category) { if ($trashdelete) { $count += $category->purge($prune_date, $params); } else { $count += $category->trash($prune_date, $params); } } if ($trashdelete) { $this->app->enqueueMessage("" . JText::_('COM_KUNENA_FORUMPRUNEDFOR') . " " . $prune_days . " " . JText::_('COM_KUNENA_PRUNEDAYS') . "; " . JText::_('COM_KUNENA_PRUNEDELETED') . " {$count} " . JText::_('COM_KUNENA_PRUNETHREADS')); } else { $this->app->enqueueMessage("" . JText::_('COM_KUNENA_FORUMPRUNEDFOR') . " " . $prune_days . " " . JText::_('COM_KUNENA_PRUNEDAYS') . "; " . JText::_('COM_KUNENA_PRUNETRASHED') . " {$count} " . JText::_('COM_KUNENA_PRUNETHREADS')); } $this->setRedirect(KunenaRoute::_($this->baseurl, false)); }
/** * 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; }
/** * 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); } }
static public function getSubscriptions($user = null) { $user = KunenaUserHelper::get($user); $db = JFactory::getDBO (); $query = "SELECT category_id FROM #__kunena_user_categories WHERE user_id={$db->Quote($user->userid)} AND subscribed=1"; $db->setQuery ( $query ); $subscribed = (array) $db->loadResultArray (); if (KunenaError::checkDatabaseError()) return; return KunenaForumCategoryHelper::getCategories($subscribed); }
/** * 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 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 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'); }
/** * @param mixed $categories * @param int $limitstart * @param int $limit * @param array $params * * @return array|KunenaForumTopic[] */ public static function getLatestTopics($categories = false, $limitstart = 0, $limit = 0, $params = array()) { KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; $db = JFactory::getDBO(); $config = KunenaFactory::getConfig(); if ($limit < 1 && empty($params['nolimit'])) { $limit = $config->threads_per_page; } $reverse = isset($params['reverse']) ? (int) $params['reverse'] : 0; $orderby = isset($params['orderby']) ? (string) $params['orderby'] : 'tt.last_post_time DESC'; $starttime = isset($params['starttime']) ? (int) $params['starttime'] : 0; $user = isset($params['user']) ? KunenaUserHelper::get($params['user']) : KunenaUserHelper::getMyself(); $hold = isset($params['hold']) ? (string) $params['hold'] : 0; $moved = isset($params['moved']) ? (string) $params['moved'] : 0; $where = isset($params['where']) ? (string) $params['where'] : ''; if (strstr('ut.last_', $orderby)) { $post_time_field = 'ut.last_post_time'; } elseif (strstr('tt.first_', $orderby)) { $post_time_field = 'tt.first_post_time'; } else { $post_time_field = 'tt.last_post_time'; } $categories = KunenaForumCategoryHelper::getCategories($categories, $reverse); $catlist = array(); foreach ($categories as $category) { $catlist += $category->getChannels(); } if (empty($catlist)) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return array(0, array()); } $catlist = implode(',', array_keys($catlist)); $whereuser = array(); if (!empty($params['started'])) { $whereuser[] = 'ut.owner=1'; } if (!empty($params['replied'])) { $whereuser[] = '(ut.owner=0 AND ut.posts>0)'; } if (!empty($params['posted'])) { $whereuser[] = 'ut.posts>0'; } if (!empty($params['favorited'])) { $whereuser[] = 'ut.favorite=1'; } if (!empty($params['subscribed'])) { $whereuser[] = 'ut.subscribed=1'; } if ($config->keywords || $config->userkeywords) { $kwids = array(); if (!empty($params['keywords'])) { $keywords = KunenaKeywordHelper::getByKeywords($params['keywords']); foreach ($keywords as $keyword) { $kwids[] = $keyword->id; } $kwids = implode(',', $kwids); } //TODO: add support for keywords (example:) /* SELECT tt.*, COUNT(*) AS score FROM #__kunena_keywords_map AS km INNER JOIN #__kunena_topics` AS tt ON km.topic_id=tt.id WHERE km.keyword_id IN (1,2) AND km.user_id IN (0,62) GROUP BY topic_id ORDER BY score DESC, tt.last_post_time DESC */ } $wheretime = $starttime ? " AND {$post_time_field}>{$db->Quote($starttime)}" : ''; $whereuser = $whereuser ? " AND ut.user_id={$db->Quote($user->userid)} AND (" . implode(' OR ', $whereuser) . ')' : ''; $where = "tt.hold IN ({$hold}) AND tt.category_id IN ({$catlist}) {$whereuser} {$wheretime} {$where}"; if (!$moved) { $where .= " AND tt.moved_id='0'"; } // Get total count if ($whereuser) { $query = "SELECT COUNT(*) FROM #__kunena_user_topics AS ut INNER JOIN #__kunena_topics AS tt ON tt.id=ut.topic_id WHERE {$where}"; } else { $query = "SELECT COUNT(*) FROM #__kunena_topics AS tt WHERE {$where}"; } $db->setQuery($query); $total = (int) $db->loadResult(); if (KunenaError::checkDatabaseError() || !$total) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return array(0, array()); } // If out of range, use last page if ($limit && $total < $limitstart) { $limitstart = intval($total / $limit) * $limit; } // Get items if ($whereuser) { $query = "SELECT tt.*, ut.posts AS myposts, ut.last_post_id AS my_last_post_id, ut.favorite, tt.last_post_id AS lastread, 0 AS unread\r\n\t\t\t\tFROM #__kunena_user_topics AS ut\r\n\t\t\t\tINNER JOIN #__kunena_topics AS tt ON tt.id=ut.topic_id\r\n\t\t\t\tWHERE {$where} ORDER BY {$orderby}"; } else { $query = "SELECT tt.*, ut.posts AS myposts, ut.last_post_id AS my_last_post_id, ut.favorite, tt.last_post_id AS lastread, 0 AS unread\r\n\t\t\t\tFROM #__kunena_topics AS tt\r\n\t\t\t\tLEFT JOIN #__kunena_user_topics AS ut ON tt.id=ut.topic_id AND ut.user_id={$db->Quote($user->userid)}\r\n\t\t\t\tWHERE {$where} ORDER BY {$orderby}"; } $db->setQuery($query, $limitstart, $limit); $results = (array) $db->loadAssocList('id'); if (KunenaError::checkDatabaseError()) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return array(0, array()); } $topics = array(); foreach ($results as $id => $result) { $instance = new KunenaForumTopic($result); $instance->exists(true); self::$_instances[$id] = $instance; $topics[$id] = $instance; } unset($results); KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return array($total, $topics); }
/** * @param bool|array|int $categories * @param int $limitstart * @param int $limit * @param array $params * * @return array */ public static function getLatestMessages($categories = false, $limitstart = 0, $limit = 0, $params = array()) { $reverse = isset($params['reverse']) ? (int) $params['reverse'] : 0; $orderby = isset($params['orderby']) ? (string) $params['orderby'] : 'm.time DESC'; $starttime = isset($params['starttime']) ? (int) $params['starttime'] : 0; $mode = isset($params['mode']) ? $params['mode'] : 'recent'; $user = isset($params['user']) ? $params['user'] : false; $where = isset($params['where']) ? (string) $params['where'] : ''; $childforums = isset($params['childforums']) ? (bool) $params['childforums'] : false; $db = JFactory::getDBO(); // FIXME: use right config setting if ($limit < 1 && empty($params['nolimit'])) { $limit = KunenaFactory::getConfig()->threads_per_page; } $query = $db->getQuery(true); $query->select('m.*, t.message')->from('#__kunena_messages AS m')->innerJoin('#__kunena_messages_text AS t ON m.id = t.mesid')->where('m.moved=0')->order($orderby); $authorise = 'read'; $hold = 'm.hold=0'; $userfield = 'm.userid'; switch ($mode) { case 'unapproved': $authorise = 'approve'; $hold = "m.hold=1"; break; case 'deleted': $authorise = 'undelete'; $hold = "m.hold>=2"; break; case 'mythanks': $userfield = 'th.userid'; $query->innerJoin('#__kunena_thankyou AS th ON m.id = th.postid'); break; case 'thankyou': $userfield = 'th.targetuserid'; $query->innerJoin('#__kunena_thankyou AS th ON m.id = th.postid'); break; case 'recent': default: } if (is_array($categories) && in_array(0, $categories)) { $categories = false; } $categories = KunenaForumCategoryHelper::getCategories($categories, $reverse, 'topic.' . $authorise); if ($childforums) { $categories += KunenaForumCategoryHelper::getChildren($categories, -1, array('action' => 'topic.' . $authorise)); } $catlist = array(); foreach ($categories as $category) { $catlist += $category->getChannels(); } if (empty($catlist)) { return array(0, array()); } $allowed = implode(',', array_keys($catlist)); $query->where("m.catid IN ({$allowed})"); $query->where($hold); if ($user) { $query->where("{$userfield}={$db->Quote($user)}"); } // Negative time means no time if ($starttime == 0) { $starttime = KunenaFactory::getSession()->lasttime; } elseif ($starttime > 0) { $starttime = JFactory::getDate()->toUnix() - $starttime * 3600; } if ($starttime > 0) { $query->where("m.time>{$db->Quote($starttime)}"); } if ($where) { $query->where($where); } $cquery = clone $query; $cquery->clear('select')->clear('order')->select('COUNT(*)'); $db->setQuery($cquery); $total = (int) $db->loadResult(); if (KunenaError::checkDatabaseError() || !$total) { return array(0, array()); } // If out of range, use last page if ($limit && $total < $limitstart) { $limitstart = intval($total / $limit) * $limit; } $db->setQuery($query, $limitstart, $limit); $results = $db->loadAssocList(); if (KunenaError::checkDatabaseError()) { return array(0, array()); } $messages = array(); foreach ($results as $result) { $instance = new KunenaForumMessage($result); $instance->exists(true); self::$_instances[$instance->id] = $instance; $messages[$instance->id] = $instance; } unset($results); return array($total, $messages); }
protected function DisplayCreate($tpl = null) { $this->setLayout('edit'); // Get captcha $captcha = KunenaSpamRecaptcha::getInstance(); if ($captcha->enabled()) { $this->captchaHtml = $captcha->getHtml(); if (!$this->captchaHtml) { $this->app->enqueueMessage($captcha->getError(), 'error'); $this->redirectBack(); return; } } // Get saved message $saved = $this->app->getUserState('com_kunena.postfields'); // Get topic icons if allowed if ($this->config->topicicons) { $this->topicIcons = $this->ktemplate->getTopicIcons(false, $saved ? $saved['icon_id'] : 0); } $categories = KunenaForumCategoryHelper::getCategories(); $arrayanynomousbox = array(); $arraypollcatid = array(); foreach ($categories as $category) { if (!$category->isSection() && $category->allow_anonymous) { $arrayanynomousbox[] = '"' . $category->id . '":' . $category->post_anonymous; } if (!$category->isSection() && $category->allow_polls) { $arraypollcatid[] = '"' . $category->id . '":1'; } } $arrayanynomousbox = implode(',', $arrayanynomousbox); $arraypollcatid = implode(',', $arraypollcatid); $this->document->addScriptDeclaration('var arrayanynomousbox={' . $arrayanynomousbox . '}'); $this->document->addScriptDeclaration('var pollcategoriesid = {' . $arraypollcatid . '};'); $cat_params = array('ordering' => 'ordering', 'toplevel' => 0, 'sections' => 0, 'direction' => 1, 'hide_lonely' => 1, 'action' => 'topic.create'); $this->catid = $this->state->get('item.catid'); $this->category = KunenaForumCategoryHelper::get($this->catid); list($this->topic, $this->message) = $this->category->newTopic($saved); if (!$this->topic->category_id) { $msg = JText::sprintf('COM_KUNENA_POST_NEW_TOPIC_NO_PERMISSIONS', $this->topic->getError()); $this->app->enqueueMessage($msg, 'notice'); return false; } $options = array(); $selected = $this->topic->category_id; if ($this->config->pickup_category) { $options[] = JHtml::_('select.option', '', JText::_('COM_KUNENA_SELECT_CATEGORY'), 'value', 'text'); $selected = 0; } if ($saved) { $selected = $saved['catid']; } $this->selectcatlist = JHtml::_('kunenaforum.categorylist', 'catid', $this->catid, $options, $cat_params, 'class="inputbox required"', 'value', 'text', $selected, 'postcatid'); $this->_prepareDocument('create'); $this->action = 'post'; $this->allowedExtensions = KunenaAttachmentHelper::getExtensions($this->category); if ($arraypollcatid) { $this->poll = $this->topic->getPoll(); } $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->render('Topic/Edit', $tpl); }
/** * Get messages where a user received (or said) Thank You * @param int $userid * @param bool $target * @param int $limitstart * @param int $limit * @return Objectlist List of the wanted messages */ static public function getUserMessages($userid, $target=true, $limitstart=0, $limit=10) { $db = JFactory::getDBO(); $field = 'targetuserid'; if (!$target) $field = 'userid'; $categories = KunenaForumCategoryHelper::getCategories(); $catlist = implode(',', array_keys($categories)); $query = "SELECT m.catid, m.thread, m.id FROM #__kunena_thankyou AS t INNER JOIN #__kunena_messages AS m ON m.id=t.postid INNER JOIN #__kunena_topics AS tt ON m.thread=tt.id WHERE m.catid IN ({$catlist}) AND m.hold=0 AND tt.hold=0 AND t.{$field}={$db->quote(intval($userid))}"; $db->setQuery ( $query, (int) $limitstart, (int) $limit ); $results = $db->loadObjectList (); KunenaError::checkDatabaseError(); return $results; }
function loadCategories() { KUNENA_PROFILER ? KunenaProfiler::instance()->start('function '.__CLASS__.'::'.__FUNCTION__.'()') : null; $categories = KunenaForumCategoryHelper::getCategories(); self::$catidcache = array(); foreach ($categories as $id=>$category) { self::$catidcache[$id] = self::stringURLSafe ( $category->name ); } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.__CLASS__.'::'.__FUNCTION__.'()') : null; }
/** * Prepare category index display. * * @return void */ protected function before() { parent::before(); $this->me = KunenaUserHelper::getMyself(); // Get sections to display. $catid = $this->input->getInt('catid', 0); if ($catid) { $sections = KunenaForumCategoryHelper::getCategories($catid); } else { $sections = KunenaForumCategoryHelper::getChildren(); } $sectionIds = array(); $this->more[$catid] = 0; foreach ($sections as $key => $category) { $this->categories[$category->id] = array(); $this->more[$category->id] = 0; // Display only categories which are supposed to show up. if ($catid || $category->params->get('display.index.parent', 3) > 0) { if ($catid || $category->params->get('display.index.children', 3) > 1) { $sectionIds[] = $category->id; } else { $this->more[$category->id]++; } } else { $this->more[$category->parent_id]++; unset($sections[$key]); continue; } } // Get categories and subcategories. if (empty($sections)) { return; } $this->sections = $sections; $categories = KunenaForumCategoryHelper::getChildren($sectionIds); if (empty($categories)) { return; } $categoryIds = array(); $topicIds = array(); $userIds = array(); $postIds = array(); foreach ($categories as $key => $category) { $this->more[$category->id] = 0; // Display only categories which are supposed to show up. if ($catid || $category->params->get('display.index.parent', 3) > 1) { if ($catid || $category->getParent()->params->get('display.index.children', 3) > 2 && $category->params->get('display.index.children', 3) > 2) { $categoryIds[] = $category->id; } else { $this->more[$category->id]++; } } else { $this->more[$category->parent_id]++; unset($categories[$key]); continue; } // Get list of topics. $last = $category->getLastCategory(); if ($last->last_topic_id) { $topicIds[$last->last_topic_id] = $last->last_topic_id; } $this->categories[$category->parent_id][] = $category; $rssURL = $category->getRSSUrl(); if (!empty($rssURL)) { $category->rssURL = $category->getRSSUrl(); } } $subcategories = KunenaForumCategoryHelper::getChildren($categoryIds); foreach ($subcategories as $category) { // Display only categories which are supposed to show up. if ($catid || $category->params->get('display.index.parent', 3) > 2) { $this->categories[$category->parent_id][] = $category; } else { $this->more[$category->parent_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. $this->pending = array(); if ($this->me->exists() && !$this->me->isBanned()) { // Load new topic counts. KunenaForumCategoryHelper::getNewTopics(array_keys($categories + $subcategories)); // Get categories which are moderated by current user. $access = KunenaAccess::getInstance(); $moderate = $access->getAdminStatus($this->me) + $access->getModeratorStatus($this->me); if (!empty($moderate[0])) { // Global moderators. $moderate = $categories; } else { // Category moderators. $moderate = array_intersect_key($categories, $moderate); } if (!empty($moderate)) { // Get pending messages. $catlist = implode(',', array_keys($moderate)); $db = JFactory::getDbo(); $db->setQuery("SELECT catid, COUNT(*) AS count\n\t\t\t\t\tFROM #__kunena_messages\n\t\t\t\t\tWHERE catid IN ({$catlist}) AND hold=1\n\t\t\t\t\tGROUP BY catid"); $pending = $db->loadAssocList(); KunenaError::checkDatabaseError(); foreach ($pending as $item) { if ($item['count']) { $this->pending[$item['catid']] = $item['count']; } } if ($this->me->ordering != 0) { $topic_ordering = $this->me->ordering == 1 ? true : false; } else { $topic_ordering = $this->config->default_sort == 'asc' ? false : true; } // Fix last post position when user can see unapproved or deleted posts. if (!$topic_ordering) { KunenaForumMessageHelper::loadLocation($postIds); } } } }
/** * Prepare topic creation form. * * @return bool * * @throws RuntimeException */ protected function before() { parent::before(); $catid = $this->input->getInt('catid', 0); $saved = $this->app->getUserState('com_kunena.postfields'); $this->me = KunenaUserHelper::getMyself(); $this->template = KunenaFactory::getTemplate(); $categories = KunenaForumCategoryHelper::getCategories(); $arrayanynomousbox = array(); $arraypollcatid = array(); foreach ($categories as $category) { if (!$category->isSection() && $category->allow_anonymous) { $arrayanynomousbox[] = '"' . $category->id . '":' . $category->post_anonymous; } if (!$category->isSection() && $category->allow_polls) { $arraypollcatid[] = '"' . $category->id . '":1'; } } $arrayanynomousbox = implode(',', $arrayanynomousbox); $arraypollcatid = implode(',', $arraypollcatid); // FIXME: We need to proxy this... $this->document = JFactory::getDocument(); $this->document->addScriptDeclaration('var arrayanynomousbox={' . $arrayanynomousbox . '}'); $this->document->addScriptDeclaration('var pollcategoriesid = {' . $arraypollcatid . '};'); $this->category = KunenaForumCategoryHelper::get($catid); list($this->topic, $this->message) = $this->category->newTopic($saved); $this->template->setCategoryIconset($this->topic->getCategory()->iconset); // Get topic icons if they are enabled. if ($this->config->topicicons) { $this->topicIcons = $this->template->getTopicIcons(false, $saved ? $saved['icon_id'] : 0, $this->topic->getCategory()->iconset); } if ($this->topic->isAuthorised('create') && $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; } if (!$this->topic->category_id) { throw new KunenaExceptionAuthorise(JText::sprintf('COM_KUNENA_POST_NEW_TOPIC_NO_PERMISSIONS', $this->topic->getError()), $this->me->exists() ? 403 : 401); } $options = array(); $selected = $this->topic->category_id; if ($this->config->pickup_category) { $options[] = JHtml::_('select.option', '', JText::_('COM_KUNENA_SELECT_CATEGORY'), 'value', 'text'); $selected = 0; } if ($saved) { $selected = $saved['catid']; } $cat_params = array('ordering' => 'ordering', 'toplevel' => 0, 'sections' => 0, 'direction' => 1, 'hide_lonely' => 1, 'action' => 'topic.create'); $this->selectcatlist = JHtml::_('kunenaforum.categorylist', 'catid', $catid, $options, $cat_params, 'class="form-control inputbox required"', 'value', 'text', $selected, 'postcatid'); $this->action = 'post'; $this->allowedExtensions = KunenaAttachmentHelper::getExtensions($this->category); if ($arraypollcatid) { $this->poll = $this->topic->getPoll(); } $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_NEW_TOPIC'); return true; }
public function getChannels($action='read') { KUNENA_PROFILER ? KunenaProfiler::instance()->start('function '.__CLASS__.'::'.__FUNCTION__.'()') : null; if ($this->_channels === false) { $this->_channels['none'] = array(); if (!$this->published || $this->parent_id == 0 || (!$this->numTopics && $this->locked)) { // Unpublished categories and sections do not have channels } elseif (empty($this->channels) || $this->channels == $this->id) { // No channels defined $this->_channels['none'][$this->id] = $this; } else { // Fetch all channels $ids = array_flip(explode(',', $this->channels)); if (isset($ids[0]) || isset($ids['THIS'])) { // Handle current category $this->_channels['none'][$this->id] = $this; } if (!empty($ids)) { // More category channels $this->_channels['none'] += KunenaForumCategoryHelper::getCategories(array_keys($ids), null, 'none'); } if (isset($ids['CHILDREN'])) { // Children category channels $this->_channels['none'] += KunenaForumCategoryHelper::getChildren($this->id, 1, array($action=>'none')); } } } if (!isset($this->_channels[$action])) { $this->_channels[$action] = array(); foreach ($this->_channels['none'] as $channel) { if (($channel->id == $this->id && $action == 'read') || $channel->authorise($action, null, false)) $this->_channels[$action][$channel->id] = $channel; } } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.__CLASS__.'::'.__FUNCTION__.'()') : null; return $this->_channels[$action]; }
/** * 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); }
public function loadTopTopics($limit=0) { $limit = $limit ? $limit : $this->_config->popsubjectcount; if (count($this->topTopics) < $limit) { $categories = implode(',', array_keys(KunenaForumCategoryHelper::getCategories())); $query = "SELECT id, category_id AS catid, subject, posts AS count FROM #__kunena_topics WHERE moved_id=0 AND hold=0 AND category_id IN ({$categories}) ORDER BY count DESC"; $this->_db->setQuery ( $query, 0, $limit ); $this->topTopics = (array) $this->_db->loadObjectList (); KunenaError::checkDatabaseError(); $top = reset($this->topTopics); if (empty($top->count)) { $this->topTopics = array(); return; } foreach ($this->topTopics as $item) { $item->link = CKunenaLink::GetThreadLink( 'view', $item->catid, $item->id, KunenaHtmlParser::parseText ($item->subject), '' ); $item->percent = round(100 * $item->count / $top->count); } $top->title = JText::_('COM_KUNENA_STAT_TOP') .' '. $limit .' '. JText::_('COM_KUNENA_STAT_POPULAR') .' '. JText::_('COM_KUNENA_STAT_POPULAR_USER_KGSG'); $top->titleName = JText::_('COM_KUNENA_GEN_SUBJECT'); $top->titleCount = JText::_('COM_KUNENA_USRL_HITS'); } return array_slice($this->topTopics, 0, $limit); }
/** * Prepare user's topic list. * * @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=user&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)); } $user = KunenaUserHelper::get($this->state->get('user')); // Get categories for the filter. $categoryIds = $this->state->get('list.categories'); $reverse = !$this->state->get('list.categories.in'); $authorise = 'read'; $order = 'last_post_time'; $finder = new KunenaForumTopicFinder; $finder ->filterByMoved(false) ->filterByHold(array(0)) ->filterByTime($time); switch ($this->state->get('list.mode')) { case 'posted' : $finder ->filterByUser($user, 'posted') ->order('last_post_id', -1, 'ut'); break; case 'started' : $finder->filterByUser($user, 'owner'); break; case 'favorites' : $finder->filterByUser($user, 'favorited'); break; case 'subscriptions' : $finder->filterByUser($user, 'subscribed'); break; default : $finder ->filterByUser($user, 'involved') ->order('favorite', -1, 'ut'); 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->topics = $finder ->order($order, -1) ->start($this->pagination->limitstart) ->limit($this->pagination->limit) ->find(); if ($this->topics) { $this->prepareTopics(); } $actions = array('delete', 'approve', 'undelete', 'move', 'permdelete'); switch ($this->state->get('list.mode')) { case 'posted' : $this->headerText = JText::_('COM_KUNENA_VIEW_TOPICS_USERS_MODE_POSTED'); break; case 'started' : $this->headerText = JText::_('COM_KUNENA_VIEW_TOPICS_USERS_MODE_STARTED'); break; case 'favorites' : $this->headerText = JText::_('COM_KUNENA_VIEW_TOPICS_USERS_MODE_FAVORITES'); $actions = array('unfavorite'); break; case 'subscriptions' : $this->headerText = JText::_('COM_KUNENA_VIEW_TOPICS_USERS_MODE_SUBSCRIPTIONS'); $actions = array('unsubscribe'); break; case 'plugin' : $this->headerText = JText::_('COM_KUNENA_VIEW_TOPICS_USERS_MODE_PLUGIN_' . strtoupper($this->state->get('list.modetype'))); break; default : $this->headerText = JText::_('COM_KUNENA_VIEW_TOPICS_USERS_MODE_DEFAULT'); } $this->actions = $this->getTopicActions($this->topics, $actions); }
public function batch_moderators() { if (!JSession::checkToken('post')) { $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error'); $this->app->redirect(KunenaRoute::_($this->baseurl, false)); } $cid = JRequest::getVar('cid', array(), 'post', 'array'); // Array of integers JArrayHelper::toInteger($cid); $catids = JRequest::getVar('catid', array(), 'post', 'array'); // Array of integers JArrayHelper::toInteger($catids); if (empty($cid)) { $this->app->enqueueMessage(JText::_('COM_KUNENA_USERS_BATCH_NO_USERS_SELECTED'), 'error'); $this->app->redirect(KunenaRoute::_($this->baseurl, false)); } if (empty($catids)) { $this->app->enqueueMessage(JText::_('COM_KUNENA_USERS_BATCH_NO_CATEGORIES_SELECTED'), 'error'); $this->app->redirect(KunenaRoute::_($this->baseurl, false)); } // Update moderator rights $categories = KunenaForumCategoryHelper::getCategories(false, false, 'admin'); $users = KunenaUserHelper::loadUsers($cid); foreach ($users as $user) { foreach ($categories as $category) { if (in_array($category->id, $catids)) { $category->setModerator($user, true); } } // Global moderator is a special case if ($this->me->isAdmin() && in_array(0, $catids)) { KunenaAccess::getInstance()->setModerator(0, $user, true); } } $this->app->enqueueMessage(JText::_('COM_KUNENA_USERS_SET_MODERATORS_DONE')); $this->app->redirect(KunenaRoute::_($this->baseurl, false)); }
public function getCategories() { if ($this->items === false) { $this->items = array(); $catid = $this->getState('item.id'); $layout = $this->getState('layout'); $flat = false; if ($layout == 'user') { $categories[0] = KunenaForumCategoryHelper::getSubscriptions(); $flat = true; } elseif ($catid) { $categories[0] = KunenaForumCategoryHelper::getCategories($catid); if (empty($categories[0])) { return array(); } } else { $categories[0] = KunenaForumCategoryHelper::getChildren(); } if ($flat) { $allsubcats = $categories[0]; } else { $allsubcats = KunenaForumCategoryHelper::getChildren(array_keys($categories[0]), 1); } if (empty($allsubcats)) { return array(); } KunenaForumCategoryHelper::getNewTopics(array_keys($allsubcats)); $modcats = array(); $lastpostlist = array(); $userlist = array(); $topiclist = array(); foreach ($allsubcats as $subcat) { if ($flat || isset($categories[0][$subcat->parent_id])) { $last = $subcat->getLastCategory(); if ($last->last_topic_id) { // Get list of topics $topiclist[$last->last_topic_id] = $last->last_topic_id; } if ($this->config->listcat_show_moderators) { // Get list of moderators $subcat->moderators = $subcat->getModerators(false, false); $userlist += $subcat->moderators; } if ($this->me->isModerator($subcat)) { $modcats[] = $subcat->id; } } $categories[$subcat->parent_id][] = $subcat; } // Prefetch topics $topics = KunenaForumTopicHelper::getTopics($topiclist); foreach ($topics as $topic) { // Prefetch users $userlist[$topic->last_post_userid] = $topic->last_post_userid; $lastpostlist[$topic->id] = $topic->last_post_id; } if ($this->me->ordering != 0) { $topic_ordering = $this->me->ordering == 1 ? true : false; } else { $topic_ordering = $this->config->default_sort == 'asc' ? false : true; } $this->pending = array(); if ($this->me->userid && count($modcats)) { $catlist = implode(',', $modcats); $db = JFactory::getDBO(); $db->setQuery("SELECT catid, COUNT(*) AS count\n\t\t\t\tFROM #__kunena_messages\n\t\t\t\tWHERE catid IN ({$catlist}) AND hold=1\n\t\t\t\tGROUP BY catid"); $pending = $db->loadAssocList(); KunenaError::checkDatabaseError(); foreach ($pending as $item) { if ($item['count']) { $this->pending[$item['catid']] = $item['count']; } } } // Fix last post position when user can see unapproved or deleted posts if ($lastpostlist && !$topic_ordering && ($this->me->isAdmin() || KunenaAccess::getInstance()->getModeratorStatus())) { KunenaForumMessageHelper::getMessages($lastpostlist); KunenaForumMessageHelper::loadLocation($lastpostlist); } // Prefetch all users/avatars to avoid user by user queries during template iterations KunenaUserHelper::loadUsers($userlist); if ($flat) { $this->items = $allsubcats; } else { $this->items = $categories; } } return $this->items; }
protected function getRecentTopics() { $catid = $this->getState ( 'item.id' ); $limitstart = $this->getState ( 'list.start' ); $limit = $this->getState ( 'list.limit' ); $time = $this->getState ( 'list.time' ); if ($time < 0) { $time = 0; } elseif ($time == 0) { $time = KunenaFactory::getSession ()->lasttime; } else { $time = JFactory::getDate ()->toUnix () - ($time * 3600); } $latestcategory = $this->getState ( 'list.categories' ); $latestcategory_in = $this->getState ( 'list.categories.in' ); $hold = 0; $where = ''; $lastpost = true; switch ($this->getState ( 'list.mode' )) { case 'topics' : $lastpost = false; break; case 'sticky' : $where = 'AND tt.ordering>0'; break; case 'locked' : $where = 'AND tt.locked>0'; break; case 'noreplies' : $where = 'AND tt.posts=1'; break; case 'unapproved' : $allowed = KunenaForumCategoryHelper::getCategories(false, false, 'topic.approve'); if (empty($allowed)) { return array(0, array()); } $allowed = implode(',', array_keys($allowed)); $hold = '1'; $where = "AND tt.category_id IN ({$allowed})"; break; case 'deleted' : $allowed = KunenaForumCategoryHelper::getCategories(false, false, 'topic.undelete'); if (empty($allowed)) { return array(0, array()); } $allowed = implode(',', array_keys($allowed)); $hold = '2'; $where = "AND tt.category_id IN ({$allowed})"; break; case 'replies' : default : break; } $params = array ( 'reverse' => ! $latestcategory_in, 'orderby' => $lastpost ? 'tt.last_post_time DESC' : 'tt.first_post_time DESC', 'starttime' => $time, 'hold' => $hold, 'where' => $where ); list ( $this->total, $this->topics ) = KunenaForumTopicHelper::getLatestTopics ( $latestcategory, $limitstart, $limit, $params ); $this->_common (); }
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 get all deleted topics. * * @return Array * @since 1.6 */ public function getTopicsItems() { /*$db = JFactory::getDBO (); $where = ''; if ($this->getState ( 'list.search')) { $where = ' AND LOWER( subject ) LIKE '.$db->Quote( '%'.$db->getEscaped( $this->getState ( 'list.search'), true ).'%', false ).' OR LOWER( username )LIKE '.$db->Quote( '%'.$db->getEscaped( $this->getState ( 'list.search'), true ).'%', false ).' OR id LIKE '.$db->Quote( '%'.$db->getEscaped( $this->getState ( 'list.search'), true ).'%', false ); }*/ $cats = KunenaForumCategoryHelper::getCategories(); $cats_array =array(); foreach ($cats as $cat) { if ( $cat->id ) $cats_array[] = $cat->id; } list($total,$topics) = KunenaForumTopicHelper::getLatestTopics ( $cats_array, $this->getState('list.start'), $this->getState('list.limit'), array ('hold' => '2,3') ); $this->setState ( 'list.total', $total ); return $topics; }
/** * @param mixed $user * * @return mixed */ public function getAllowedCategories($user = null) { static $read = array(); KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; $user = KunenaFactory::getUser($user); $id = $user->userid; if (!isset($read[$id])) { $app = JFactory::getApplication(); // TODO: handle guests/bots with no userstate $read[$id] = $app->getUserState("com_kunena.user{$id}_read"); if ($read[$id] === null) { $read[$id] = array(); $categories = KunenaForumCategoryHelper::getCategories(false, false, 'none'); foreach ($categories as $category) { // Remove unpublished categories if (!$category->published) { unset($categories[$category->id]); } // Moderators have always access if (self::isModerator($id, $category->id)) { $read[$id][$category->id] = $category->id; unset($categories[$category->id]); } } // Get external authorization if (!empty($categories)) { /** @var KunenaAccess $access */ foreach ($this->accesstypes['all'] as $access) { if (method_exists($access, 'authoriseCategories')) { $read[$id] += $access->authoriseCategories($id, $categories); } } } $app->setUserState("com_kunena.user{$id}_read", $read[$id]); } } $allowed = $read[$id]; KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return $allowed; }
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); }
public function getAllowedCategories($user = null, $rule = 'read') { static $read = array(); KUNENA_PROFILER ? KunenaProfiler::instance()->start('function '.__CLASS__.'::'.__FUNCTION__.'()') : null; $user = KunenaFactory::getUser($user); $id = $user->userid; $allowed = array(); switch ($rule) { case 'read': case 'post': case 'reply': case 'edit': if (!isset($read[$id])) { $app = JFactory::getApplication(); // TODO: handle guests/bots with no userstate $read[$id] = $app->getUserState("com_kunena.user{$id}_read"); if ($read[$id] === null) { $read[$id] = array(); $categories = KunenaForumCategoryHelper::getCategories(false, false, 'none'); foreach ( $categories as $category ) { if (!$category->published) { unset($categories[$category->id]); } if ($id && self::isModerator($id, $category->id)) { $read[$id][$category->id] = $category->id; unset($categories[$category->id]); } } $read[$id] += self::$instance->loadAllowedCategories($id, $categories); $app->setUserState("com_kunena.user{$id}_read", $read[$id]); } } $allowed = $read[$id]; break; case 'moderate': if (isset(self::$moderatorsByUserid[$id])) $allowed += self::$moderatorsByUserid[$id]; // Continue: Administrators have also moderation permissions case 'admin': if (isset(self::$adminsByUserid[$id])) $allowed += self::$adminsByUserid[$id]; } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.__CLASS__.'::'.__FUNCTION__.'()') : null; return $allowed; }
protected function setVariable($cid, $variable, $value) { KunenaFactory::loadLanguage('com_kunena', 'admin'); if (!JSession::checkToken('post')) { $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error'); return; } if (empty ($cid)) { $this->app->enqueueMessage(JText::_('COM_KUNENA_A_NO_CATEGORIES_SELECTED'), 'notice'); return; } $count = 0; $name = null; $categories = KunenaForumCategoryHelper::getCategories($cid); foreach ($categories as $category) { if ($category->get($variable) == $value) { continue; } if (!$category->authorise('admin')) { $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_CATEGORY_NO_ADMIN', $this->escape($category->name)), 'notice'); } elseif (!$category->isCheckedOut($this->me->userid)) { $category->set($variable, $value); if ($category->save()) { $count++; $name = $category->name; } else { $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_CATEGORY_SAVE_FAILED', $category->id, $this->escape($category->getError())), 'notice'); } } else { $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_CATEGORY_X_CHECKED_OUT', $this->escape($category->name)), 'notice'); } } if ($count == 1 && $name) { $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_CATEGORY_SAVED', $this->escape($name))); } if ($count > 1) { $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_CATEGORIES_SAVED', $count)); } }
function unsubscribe() { if (! JSession::checkToken ('request') ) { $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' ); $this->redirectBack (); } $catid = JRequest::getInt('catid', 0); $catids = $catid ? array($catid) : array_keys(JRequest::getVar('categories', array(), 'post', 'array')); // Array or integer keys JArrayHelper::toInteger($catids); $categories = KunenaForumCategoryHelper::getCategories($catids); foreach($categories as $category) { if (!$category->authorise('read')) { $this->app->enqueueMessage ( $category->getError(), 'error' ); continue; } if ($this->me->exists()) { $success = $category->subscribe(0); if ($success) { $this->app->enqueueMessage ( JText::sprintf('COM_KUNENA_GEN_CATEGORY_NAME_UNSUBCRIBED', $category->name) ); } } } $this->redirectBack (); }
function displayManage($tpl) { $admin = KunenaForumCategoryHelper::getCategories(false, false, 'admin'); if (empty($admin)) { $this->setError(JText::_('COM_KUNENA_NO_ACCESS')); $this->displayNoAccess($this->getErrors()); return; } KunenaFactory::loadLanguage('com_kunena', 'admin'); $this->categories = $this->get('AdminCategories'); $this->navigation = $this->get('AdminNavigation'); $header = JText::_('COM_KUNENA_ADMIN'); $this->header = $header; $this->setTitle($header); $this->display($tpl); }
/** * @param mixed $user * * @return mixed */ public function getAllowedCategories($user = null) { static $read = array(); KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; if (!$user instanceof KunenaUser) { $user = KunenaFactory::getUser($user); } if (!isset($read[$user->userid])) { $id = $user->userid; $app = JFactory::getApplication(); // TODO: handle guests/bots with no userstate $read[$id] = $app->getUserState("com_kunena.user{$id}_read"); if ($read[$id] === null) { $list = array(); $categories = KunenaForumCategoryHelper::getCategories(false, false, 'none'); foreach ($categories as $category) { // Remove unpublished categories if ($category->published != 1) { unset($categories[$category->id]); } // Moderators have always access if (self::isModerator($user, $category->id)) { $list[$category->id] = $category->id; unset($categories[$category->id]); } } // Get external authorization if (!empty($categories)) { // @var KunenaAccess $access foreach ($this->accesstypes['all'] as $access) { if (method_exists($access, 'authoriseCategories')) { $list += $access->authoriseCategories($id, $categories); } } } // Clean up and filter the resulting list by using only array keys. $list = array_keys($list); Joomla\Utilities\ArrayHelper::toInteger($list); $read[$id] = array_combine($list, $list); unset($read[$id][0]); $app->setUserState("com_kunena.user{$id}_read", $read[$id]); } } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return $read[$user->userid]; }