Example #1
0
	/**
	 * @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;
	}
 /**
  * @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);
 }
Example #3
0
 /**
  * @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);
 }
Example #4
0
	function isCategoryConflict($menuitem, $catid, $catname) {
		KUNENA_PROFILER ? KunenaProfiler::instance()->start('function '.__CLASS__.'::'.__FUNCTION__.'()') : null;
		if (isset ( self::$views[$catname] ) || isset ( self::$layouts[$catname] ) || isset ( self::$functions[$catname] ) ) {
			KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.__CLASS__.'::'.__FUNCTION__.'()') : null;
			return true;
		}
		if (self::$catidcache === null) {
			self::loadCategories ();
		}
		$keys = array_keys(self::$catidcache, $catname);
		if (count($keys) == 1) return false;
		if (!empty($menuitem->query['catid'])) {
			$keys = array_flip($keys);
			unset($keys[$catid]);
			$categories = array_intersect_key($keys, KunenaForumCategoryHelper::getChildren($menuitem->query['catid']));
			KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.__CLASS__.'::'.__FUNCTION__.'()') : null;
			return !empty($categories);
		}
		KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.__CLASS__.'::'.__FUNCTION__.'()') : null;
		return true;
	}
Example #5
0
	protected static function checkCategory($item, JUri $uri)
	{
		static $cache = array();
		$catid = (int) $uri->getVar('catid');
		$check = self::check($item, $uri);

		if (!$check || !$catid)
		{
			return $check;
		}

		if (!isset($cache[$item->id]))
		{
			$cache[$item->id] = array();

			if (!empty($item->query['catid']))
			{
				$cache[$item->id] = KunenaForumCategoryHelper::getChildren($item->query['catid']);
				$cache[$item->id][$item->query['catid']] = KunenaForumCategoryHelper::get($item->query['catid']);
			}
		}

		return intval(isset($cache[$item->id][$catid])) * 8;
	}
Example #6
0
 static function getCategoryTree($xmap, $parent, &$params, $parentCat)
 {
     $db = JFactory::getDBO();
     // Load categories
     if (self::getKunenaMajorVersion() >= '2.0') {
         // Kunena 2.0+
         $catlink = 'index.php?option=com_kunena&view=category&catid=%s&Itemid=' . $parent->id;
         $toplink = 'index.php?option=com_kunena&view=topic&catid=%s&id=%s&Itemid=' . $parent->id;
         // kimport('kunena.forum.category.helper');
         $categories = KunenaForumCategoryHelper::getChildren($parentCat);
     } else {
         $catlink = 'index.php?option=com_kunena&func=showcat&catid=%s&Itemid=' . $parent->id;
         $toplink = 'index.php?option=com_kunena&func=view&catid=%s&id=%s&Itemid=' . $parent->id;
         if (self::getKunenaMajorVersion() >= '1.6') {
             // Kunena 1.6+
             kimport('session');
             $session = KunenaFactory::getSession();
             $session->updateAllowedForums();
             $allowed = $session->allowed;
             $query = "SELECT id, name FROM `#__kunena_categories` WHERE parent={$parentCat} AND id IN ({$allowed}) ORDER BY ordering";
         } else {
             // Kunena 1.0+
             $query = "SELECT id, name FROM `{$params['table_prefix']}_categories` WHERE parent={$parentCat} AND published=1 AND pub_access=0 ORDER BY ordering";
         }
         $db->setQuery($query);
         $categories = $db->loadObjectList();
     }
     /* get list of categories */
     $xmap->changeLevel(1);
     foreach ($categories as $cat) {
         $node = new stdclass();
         $node->id = $parent->id;
         $node->browserNav = $parent->browserNav;
         $node->uid = 'com_kunenac' . $cat->id;
         $node->name = $cat->name;
         $node->priority = $params['cat_priority'];
         $node->changefreq = $params['cat_changefreq'];
         $node->link = sprintf($catlink, $cat->id);
         $node->expandible = true;
         $node->secure = $parent->secure;
         if ($xmap->printNode($node) !== FALSE) {
             xmap_com_kunena::getCategoryTree($xmap, $parent, $params, $cat->id);
         }
     }
     if ($params['include_topics']) {
         if (self::getKunenaMajorVersion() >= '2.0') {
             // Kunena 2.0+
             // kimport('kunena.forum.topic.helper');
             // TODO: orderby parameter is missing:
             $topics = KunenaForumTopicHelper::getLatestTopics($parentCat, 0, $params['limit'], array('starttime', $params['days']));
             if (count($topics) == 2 && is_numeric($topics[0])) {
                 $topics = $topics[1];
             }
         } else {
             $access = KunenaFactory::getAccessControl();
             $hold = $access->getAllowedHold(self::$profile, $parentCat);
             // Kunena 1.0+
             $query = "SELECT t.id, t.catid, t.subject, max(m.time) as time, count(m.id) as msgcount\n                    FROM {$params['table_prefix']}_messages t\n                    INNER JOIN {$params['table_prefix']}_messages AS m ON t.id = m.thread\n                    WHERE t.catid={$parentCat} AND t.parent=0\n                    AND t.hold in ({$hold})\n                    GROUP BY m.`thread`\n                    ORDER BY {$params['topics_order']} DESC";
             if ($params['days']) {
                 $query = "SELECT * FROM ({$query}) as topics WHERE time >= {$params['days']}";
             }
             #echo str_replace('#__','mgbj2_',$query);
             $db->setQuery($query, 0, $params['limit']);
             $topics = $db->loadObjectList();
         }
         //get list of topics
         foreach ($topics as $topic) {
             $node = new stdclass();
             $node->id = $parent->id;
             $node->browserNav = $parent->browserNav;
             $node->uid = 'com_kunenat' . $topic->id;
             $node->name = $topic->subject;
             $node->priority = $params['topic_priority'];
             $node->changefreq = $params['topic_changefreq'];
             $node->modified = intval(@$topic->last_post_time ? $topic->last_post_time : $topic->time);
             $node->link = sprintf($toplink, @$topic->category_id ? $topic->category_id : $topic->catid, $topic->id);
             $node->expandible = false;
             $node->secure = $parent->secure;
             if ($xmap->printNode($node) !== FALSE) {
                 // Pagination will not work with K2.0, revisit this when that version is out and stable
                 if ($params['include_pagination'] && isset($topic->msgcount) && $topic->msgcount > self::$config->messages_per_page) {
                     $msgPerPage = self::$config->messages_per_page;
                     $threadPages = ceil($topic->msgcount / $msgPerPage);
                     for ($i = 2; $i <= $threadPages; $i++) {
                         $subnode = new stdclass();
                         $subnode->id = $node->id;
                         $subnode->uid = $node->uid . 'p' . $i;
                         $subnode->name = "[{$i}]";
                         $subnode->seq = $i;
                         $subnode->link = $node->link . '&limit=' . $msgPerPage . '&limitstart=' . ($i - 1) * $msgPerPage;
                         $subnode->browserNav = $node->browserNav;
                         $subnode->priority = $node->priority;
                         $subnode->changefreq = $node->changefreq;
                         $subnode->modified = $node->modified;
                         $subnode->secure = $node->secure;
                         $xmap->printNode($subnode);
                     }
                 }
             }
         }
     }
     $xmap->changeLevel(-1);
 }
Example #7
0
 protected function buildInfo()
 {
     if ($this->_topics !== false) {
         return;
     }
     $this->_topics = 0;
     $this->_posts = 0;
     $this->_lastcat = $this;
     /** @var array|KunenaForumCategory[] $categories */
     $categories[$this->id] = $this;
     // TODO: support channels
     //$categories += $this->getChannels();
     $categories += KunenaForumCategoryHelper::getChildren($this->id);
     foreach ($categories as $category) {
         $category->buildInfo();
         $lastCategory = $category->getLastCategory();
         $this->_topics += $category->_topics ? $category->_topics : max($category->numTopics, 0);
         $this->_posts += $category->_posts ? $category->_posts : max($category->numPosts, 0);
         if ($lastCategory->last_post_time && $this->_lastcat->last_post_time < $lastCategory->last_post_time) {
             $this->_lastcat = $lastCategory;
         }
     }
 }
Example #8
0
 /**
  * @return array
  */
 public static function getBoards()
 {
     if (!class_exists('KunenaForumCategoryHelper')) {
         return array();
     }
     $rows = KunenaForumCategoryHelper::getChildren(0, 10);
     $categories = array();
     if ($rows) {
         foreach ($rows as $row) {
             $categories[] = moscomprofilerHTML::makeOption($row->id, str_repeat('- ', $row->level + 1) . ' ' . $row->name);
         }
     }
     return $categories;
 }
Example #9
0
 public function getTopics()
 {
     if ($this->topics === false) {
         $catid = $this->getState('item.id');
         $limitstart = $this->getState('list.start');
         $limit = $this->getState('list.limit');
         $format = $this->getState('format');
         $topic_ordering = $this->getCategory()->topic_ordering;
         $access = KunenaAccess::getInstance();
         $hold = $format == 'feed' ? 0 : $access->getAllowedHold($this->me, $catid);
         $moved = $format == 'feed' ? 0 : 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 ' . strtoupper($this->getState('list.direction'));
                 break;
             case 'lastpost':
             default:
                 $params['orderby'] = 'tt.ordering DESC, tt.last_post_time ' . strtoupper($this->getState('list.direction'));
         }
         if ($format == 'feed') {
             $catid = array_keys(KunenaForumCategoryHelper::getChildren($catid, 100) + array($catid => 1));
         }
         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 (($lastpostlist || $lastreadlist) && ($this->me->isAdmin() || KunenaAccess::getInstance()->getModeratorStatus())) {
                 KunenaForumMessageHelper::loadLocation($lastpostlist + $lastreadlist);
             }
         }
     }
     return $this->topics;
 }
Example #10
0
 /**
  * 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);
             }
         }
     }
 }
Example #11
0
	public function getAdminCategories() {
		if ( $this->_admincategories === false ) {
			$me = KunenaUserHelper::getMyself();
			$params = array (
				'ordering'=>$this->getState ( 'list.ordering' ),
				'direction'=>$this->getState ( 'list.direction' ) == 'asc' ? 1 : -1,
				'search'=>$this->getState ( 'list.search' ),
				'unpublished'=>1,
				'action'=>'admin');
			$catid = $this->getState ( 'item.id', 0 );
			$categories = array();
			if ($catid) {
				$categories = KunenaForumCategoryHelper::getParents($catid, $this->getState ( 'list.levels' ), array('unpublished'=>1, 'action'=>'none'));
				$categories[] = KunenaForumCategoryHelper::get($catid);
			}
			$categories = array_merge($categories, KunenaForumCategoryHelper::getChildren($catid, $this->getState ( 'list.levels' ), $params));
			$categories = KunenaForumCategoryHelper::getIndentation($categories);
			$this->setState ( 'list.total', count($categories) );
			$this->_admincategories = array_slice ( $categories, $this->getState ( 'list.start' ), $this->getState ( 'list.limit' ) );
			$admin = 0;
			$acl = KunenaFactory::getAccessControl();
			foreach ($this->_admincategories as $category) {
				$siblings = array_keys(KunenaForumCategoryHelper::getCategoryTree($category->parent_id));
				if (empty($siblings)) {
					// FIXME: deal with orphaned categories
					$orphans = true;
					$category->parent_id = 0;
					$category->name = JText::_ ( 'COM_KUNENA_CATEGORY_ORPHAN' ) . ' : ' . $category->name;
				}
				$category->up = $me->isAdmin($category->parent_id) && reset($siblings) != $category->id;
				$category->down = $me->isAdmin($category->parent_id) && end($siblings) != $category->id;
				$category->reorder = $me->isAdmin($category->parent_id);
				if ($category->accesstype == 'joomla.level') {
					$groupname = $acl->getGroupName($category->accesstype, $category->access);
					if (version_compare(JVERSION, '1.6','>')) {
						// Joomla 1.6+
						$category->accessname = JText::_('COM_KUNENA_INTEGRATION_JOOMLA_LEVEL').': '.($groupname ? $groupname : JText::_('COM_KUNENA_NOBODY'));
					} else {
						// Joomla 1.5
						$category->accessname = JText::_('COM_KUNENA_INTEGRATION_JOOMLA_LEVEL').': '.($groupname ? JText::_($groupname) : JText::_('COM_KUNENA_NOBODY'));
					}
				} elseif ($category->accesstype != 'none') {
					$category->accessname = JText::_('COM_KUNENA_INTEGRATION_'.strtoupper(preg_replace('/[^\w\d]+/', '_', $category->accesstype))).': '.$category->access;
				} elseif (version_compare(JVERSION, '1.6','>')) {
					// Joomla 1.6+
					$groupname = $acl->getGroupName($category->accesstype, $category->pub_access);
					$category->accessname = JText::sprintf( $category->pub_recurse ? 'COM_KUNENA_A_GROUP_X_PLUS' : 'COM_KUNENA_A_GROUP_X_ONLY', $groupname ? JText::_( $groupname ) : JText::_('COM_KUNENA_NOBODY') );
					$groupname = $acl->getGroupName($category->accesstype, $category->admin_access);
					if ($groupname && $category->pub_access != $category->admin_access) {
						$category->accessname .= ' / '.JText::sprintf( $category->admin_recurse ? 'COM_KUNENA_A_GROUP_X_PLUS' : 'COM_KUNENA_A_GROUP_X_ONLY', JText::_( $groupname ));
					}
				} else {
					// Joomla 1.5
					$groupname = $acl->getGroupName($category->accesstype, $category->pub_access);
					if ($category->pub_access == 0) {
						$category->accessname = JText::_('COM_KUNENA_PUBLIC');
					} else if ($category->pub_access == - 1) {
						$category->accessname = JText::_('COM_KUNENA_ALLREGISTERED');
					} else if ($category->pub_access == 1 || !$groupname) {
						$category->accessname = JText::_('COM_KUNENA_NOBODY');
					} else {
						$category->accessname = JText::sprintf( $category->pub_recurse ? 'COM_KUNENA_A_GROUP_X_PLUS' : 'COM_KUNENA_A_GROUP_X_ONLY', JText::_( $groupname ));
					}
					$groupname = $acl->getGroupName($category->accesstype, $category->admin_access);
					if ($category->pub_access > 0 && $groupname && $category->pub_access != $category->admin_access) {
						$category->accessname .= ' / '.JText::sprintf( $category->admin_recurse ? 'COM_KUNENA_A_GROUP_X_PLUS' : 'COM_KUNENA_A_GROUP_X_ONLY', JText::_( $groupname ));
					}
				}
				if ($category->accesstype != 'none') {
					$category->admin_group = '';
				} else {
					$category->admin_group = JText::_ ( $acl->getGroupName($category->accesstype, $category->admin_access ));
				}
				if ($me->isAdmin($category->id) && $category->isCheckedOut(0)) {
					$category->editor = KunenaFactory::getUser($category->checked_out)->getName();
				} else {
					$category->checked_out = 0;
					$category->editor = '';
				}
				$admin += $me->isAdmin($category->id);
			}
			$this->setState ( 'list.count.admin', $admin );
		}
		if (isset($orphans)) {
			$app = JFactory::getApplication ();
			$app->enqueueMessage ( JText::_ ( 'COM_KUNENA_CATEGORY_ORPHAN_DESC' ), 'notice' );
		}
		return $this->_admincategories;
	}
Example #12
0
	public function getAdminCategories() {
		if ( $this->_admincategories === false ) {
			$me = KunenaFactory::getUser();
			$jversion = new JVersion ();
			$params = array (
				'ordering'=>$this->getState ( 'list.ordering' ),
				'direction'=>$this->getState ( 'list.direction' ) == 'asc' ? 1 : -1,
				'search'=>$this->getState ( 'list.search' ),
				'unpublished'=>1,
				'action'=>'admin');
			$catid = $this->getState ( 'item.id', 0 );
			$categories = array();
			if ($catid) {
				$categories = KunenaForumCategoryHelper::getParents($catid, $this->getState ( 'list.levels' ), array('unpublished'=>1, 'action'=>'none'));
				$categories[] = KunenaForumCategoryHelper::get($catid);
			}
			$categories = array_merge($categories, KunenaForumCategoryHelper::getChildren($catid, $this->getState ( 'list.levels' ), $params));
			$categories = KunenaForumCategoryHelper::getIndentation($categories);
			$this->setState ( 'list.total', count($categories) );
			$this->_admincategories = array_slice ( $categories, $this->getState ( 'list.start' ), $this->getState ( 'list.limit' ) );
			$admin = 0;
			$acl = KunenaFactory::getAccessControl();
			foreach ($this->_admincategories as $category) {
				$siblings = array_keys(KunenaForumCategoryHelper::getCategoryTree($category->parent_id));
				if (empty($siblings)) {
					// FIXME: deal with orphaned categories
					$orphans = true;
					$category->parent_id = 0;
					$category->name = JText::_ ( 'COM_KUNENA_CATEGORY_ORPHAN' ) . ' : ' . $category->name;
				}
				$category->up = $me->isAdmin($category->parent_id) && reset($siblings) != $category->id;
				$category->down = $me->isAdmin($category->parent_id) && end($siblings) != $category->id;
				$category->reorder = $me->isAdmin($category->parent_id);
				if ($category->accesstype != 'none') {
					$category->pub_group = JText::_('COM_KUNENA_INTEGRATION_'.strtoupper($category->accesstype));
				} elseif ($jversion->RELEASE == '1.5') {
					if ($category->pub_access == 0) {
						$category->pub_group = JText::_('COM_KUNENA_EVERYBODY');
					} else if ($category->pub_access == - 1) {
						$category->pub_group = JText::_('COM_KUNENA_ALLREGISTERED');
					} else if ($category->pub_access == 1) {
						$category->pub_group = JText::_('COM_KUNENA_NOBODY');
					} else {
						$category->pub_group = JText::_( $acl->getGroupName($category->pub_access) );
					}
				} else {
					$category->pub_group = $category->pub_access ? JText::_( $acl->getGroupName($category->pub_access) ) : JText::_('COM_KUNENA_NOBODY');
				}
				if ($category->accesstype != 'none') {
					$category->admin_group = '';
				} else {
					$category->admin_group = JText::_ ( $acl->getGroupName($category->admin_access ));
				}
				if ($me->isAdmin($category->id) && $category->isCheckedOut(0)) {
					$category->editor = KunenaFactory::getUser($category->checked_out)->getName();
				} else {
					$category->checked_out = 0;
					$category->editor = '';
				}
				$admin += $me->isAdmin($category->id);
			}
			$this->setState ( 'list.count.admin', $admin );
		}
		if (isset($orphans)) {
			$app = JFactory::getApplication ();
			$app->enqueueMessage ( JText::_ ( 'COM_KUNENA_CATEGORY_ORPHAN_DESC' ), 'notice' );
		}
		return $this->_admincategories;
	}
Example #13
0
	/**
	 * @return array
	 */
	public function categories()
	{
		$options			=	array();

		if ( $this->installed() ) {
			$rows			=	KunenaForumCategoryHelper::getChildren( 0, 10 );

			if ( $rows ) foreach ( $rows as $row ) {
				$options[]	=	moscomprofilerHTML::makeOption( (string) $row->id, str_repeat( '- ', $row->level + 1  ) . ' ' . $row->name );
			}
		}

		return $options;
	}
Example #14
0
	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->getLastPosted ();
				if ($last->last_topic_id) {
					$topiclist[$last->last_topic_id] = $last->last_topic_id;
					// collect user ids for avatar prefetch when integrated
					$userlist [(int)$last->last_post_userid] = (int)$last->last_post_userid;
					$lastpostlist [(int)$subcat->id] = (int)$last->last_post_id;
					$last->_last_post_location = $last->last_topic_posts;
				}

				if ($this->config->listcat_show_moderators) {
					$subcat->moderators = $subcat->getModerators ( false, false );
					$userlist += $subcat->moderators;
				}

				if ($this->me->isModerator ( $subcat->id ))
					$modcats [] = $subcat->id;
			}
			$categories [$subcat->parent_id] [] = $subcat;
		}
		KunenaForumTopicHelper::getTopics($topiclist);

		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
				FROM #__kunena_messages
				WHERE catid IN ({$catlist}) AND hold=1
				GROUP 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->userid && $this->me->isModerator()) {
			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;
	}
Example #15
0
 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;
 }
Example #16
0
 public function getAdminCategories()
 {
     if ($this->_admincategories === false) {
         $params = array('ordering' => $this->getState('list.ordering'), 'direction' => $this->getState('list.direction') == 'asc' ? 1 : -1, 'search' => $this->getState('filter.search'), 'unpublished' => 1, 'published' => $this->getState('filter.published'), 'filter_title' => $this->getState('filter.title'), 'filter_type' => $this->getState('filter.type'), 'filter_access' => $this->getState('filter.access'), 'filter_locked' => $this->getState('filter.locked'), 'filter_allow_polls' => $this->getState('filter.allow_polls'), 'filter_review' => $this->getState('filter.review'), 'filter_anonymous' => $this->getState('filter.anonymous'), 'action' => 'admin');
         $catid = $this->getState('item.id', 0);
         $categories = array();
         $orphans = array();
         if ($catid) {
             $categories = KunenaForumCategoryHelper::getParents($catid, $this->getState('filter.levels'), array('unpublished' => 1, 'action' => 'none'));
             $categories[] = KunenaForumCategoryHelper::get($catid);
         } else {
             $orphans = KunenaForumCategoryHelper::getOrphaned($this->getState('filter.levels'), $params);
         }
         $categories = array_merge($categories, KunenaForumCategoryHelper::getChildren($catid, $this->getState('filter.levels'), $params));
         $categories = array_merge($orphans, $categories);
         $categories = KunenaForumCategoryHelper::getIndentation($categories);
         $this->setState('list.total', count($categories));
         if ($this->getState('list.limit')) {
             $this->_admincategories = array_slice($categories, $this->getState('list.start'), $this->getState('list.limit'));
         } else {
             $this->_admincategories = $categories;
         }
         $admin = 0;
         $acl = KunenaAccess::getInstance();
         /** @var KunenaForumCategory $category */
         foreach ($this->_admincategories as $category) {
             // TODO: Following is needed for J!2.5 only:
             $parent = $category->getParent();
             $siblings = array_keys(KunenaForumCategoryHelper::getCategoryTree($category->parent_id));
             $category->up = $this->me->isAdmin($parent) && reset($siblings) != $category->id;
             $category->down = $this->me->isAdmin($parent) && end($siblings) != $category->id;
             $category->reorder = $this->me->isAdmin($parent);
             // Get ACL groups for the category.
             $access = $acl->getCategoryAccess($category);
             $category->accessname = array();
             foreach ($access as $item) {
                 $category->accessname[] = $item['title'];
             }
             $category->accessname = implode(' / ', $category->accessname);
             // Checkout?
             if ($this->me->isAdmin($category) && $category->isCheckedOut(0)) {
                 $category->editor = KunenaFactory::getUser($category->checked_out)->getName();
             } else {
                 $category->checked_out = 0;
                 $category->editor = '';
             }
             $admin += $this->me->isAdmin($category);
         }
         $this->setState('list.count.admin', $admin);
     }
     if (!empty($orphans)) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_CATEGORY_ORPHAN_DESC'), 'notice');
     }
     return $this->_admincategories;
 }
Example #17
0
	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;
		}
	}
Example #18
0
 /**
  * Return category tree
  */
 function getCategoryTree(&$xmap, &$parent, &$params, $parentCat)
 {
     $database =& JFactory::getDBO();
     $list = array();
     // Load categories
     if (self::getKunenaMajorVersion() >= '2.0') {
         // Kunena 2.0+
         $catlink = 'index.php?option=com_kunena&amp;view=category&amp;catid=%s';
         $toplink = 'index.php?option=com_kunena&amp;view=topic&amp;catid=%s&amp;id=%s';
         kimport('kunena.forum.category.helper');
         $categories = KunenaForumCategoryHelper::getChildren($parentCat);
     } else {
         $catlink = 'index.php?option=com_kunena&amp;func=showcat&amp;catid=%s';
         $toplink = 'index.php?option=com_kunena&amp;func=view&amp;catid=%s&amp;id=%s';
         if (self::getKunenaMajorVersion() >= '1.6') {
             // Kunena 1.6+
             kimport('session');
             $session = KunenaFactory::getSession();
             $session->updateAllowedForums();
             $allowed = $session->allowed;
             $query = "SELECT id, name FROM #__kunena_categories WHERE parent={$parentCat} AND id IN ({$allowed}) ORDER BY ordering";
         } else {
             // Kunena 1.0+
             $query = "SELECT id, name FROM {$params['table_prefix']}_categories WHERE parent={$parentCat} AND published=1 AND pub_access=0 ORDER BY ordering";
         }
         $database->setQuery($query);
         $categories = $database->loadObjectList();
     }
     // Create list of categories
     $xmap->changeLevel(1);
     foreach ($categories as $category) {
         $node = new stdclass();
         $node->id = $parent->id;
         $node->browserNav = $parent->browserNav;
         $node->uid = $parent->uid . 'c' . $category->id;
         $node->name = $category->name;
         $node->priority = $params['cat_priority'];
         $node->changefreq = $params['cat_changefreq'];
         $node->link = sprintf($catlink, $category->id);
         $node->expandible = true;
         if ($xmap->printNode($node) !== FALSE) {
             xmap_com_kunena::getCategoryTree($xmap, $parent, $params, $category->id);
         }
     }
     // Load topics
     if ($params['include_topics'] && $parentCat) {
         if (self::getKunenaMajorVersion() >= '2.0') {
             // Kunena 2.0+
             kimport('kunena.forum.topic.helper');
             // TODO: orderby parameter is missing:
             $topics = KunenaForumtopicHelper::getLatestTopics($parentCat, 0, $params['limit'], array('starttime', $params['days']));
         } else {
             // Kunena 1.0+
             $days = $params['days'] ? "AND time >= {$params['days']}" : '';
             $query = "SELECT id, catid, subject, time \n\t\t\t\t\tFROM {$params['table_prefix']}_messages \n\t\t\t\t\tWHERE catid={$parentCat} AND parent=0 {$days} \n\t\t\t\t\tORDER BY `{$params['topics_order']}` DESC";
             $database->setQuery($query, 0, $params['limit']);
             $topics = $database->loadObjectList();
         }
         // Create list of topics
         foreach ($topics as $topic) {
             $node = new stdclass();
             $node->id = $parent->id;
             $node->browserNav = $parent->browserNav;
             $node->uid = $parent->uid . 't' . $topic->id;
             $node->name = $topic->subject;
             $node->priority = $params['topic_priority'];
             $node->changefreq = $params['topic_changefreq'];
             $node->modified = intval($topic->time);
             $node->link = sprintf($toplink, $topic->catid, $topic->id);
             $node->expandible = false;
             $xmap->printNode($node);
         }
     }
     $xmap->changeLevel(-1);
 }