Scroll To Top
Yofiel menu
Welcome, Guest

TOPIC: Xmap ~ Kunena Plugin revision

Xmap ~ Kunena Plugin revision 2 years 3 months ago #1

This is for the Xmap developers, it is code for the xmap 3.0 plugin so that it includes forum posts in both the HTML and XML sitemaps. But I do not have nested categories, so I did not put that in.
Hide LIne Numbers
  1. <?php
  2. class xmap_com_kunena{
  3.     static $profile;
  4.     static $config;
  5.     // called before a menu item is printed. We use it to set the proper uniqueid for the item 
  6.     function prepareMenuItem($node, &$params){$link_query = parse_url($node->link);
  7.         parse_str(html_entity_decode($link_query['query']), $link_vars);
  8.         $catid = intval(JArrayHelper::getValue($link_vars, 'catid', 0));
  9.         $id = intval(JArrayHelper::getValue($link_vars, 'id', 0));
  10.         $func = JArrayHelper::getValue($link_vars, 'func', '', '');
  11.         if($func = 'showcat' && $catid){
  12.                 $node->uid = 'com_kunenac'.$catid;
  13.                 $node->expandible = false;
  14.         }
  15.         elseif($func = 'view' && $id){
  16.                 $node->uid = 'com_kunenaf'.$id;
  17.                 $node->expandible = false;
  18.         }
  19.     }
  20.     function getTree($xmap, $parent, &$params){
  21.         if($xmap->isNews)return false;
  22.         if(!xmap_com_kunena::loadKunenaApi())return false;
  23.         if(!self::$profile){
  24.             self::$config = KunenaFactory::getConfig();
  25.             self::$profile = KunenaFactory::getUser();
  26.         }
  27.         $user = JFactory::getUser();
  28.         $catid = 0;
  29.         $link_query = parse_url($parent->link);
  30.         if(!isset($link_query['query']))return;
  31.         parse_str(html_entity_decode($link_query['query']), $link_vars);
  32.         $view = JArrayHelper::getValue($link_vars, 'view', '');
  33.         $layout = JArrayHelper::getValue($link_vars, 'layout', '');
  34.         $catid_link = JArrayHelper::getValue($link_vars, 'catid', 0);
  35.         if($view == 'category' AND (!$layout OR 'list' == $layout)){
  36.             if(!empty($catid_link)){
  37.                 $link_query = parse_url($parent->link);
  38.                 parse_str(html_entity_decode($link_query['query']), $link_vars);
  39.                 $catid = JArrayHelper::getValue($link_vars, 'catid', 0);
  40.             }else{
  41.                 $catid = 0;
  42.             }
  43.             // Get ItemID of the main menu entry of the component
  44.             $component = JComponentHelper::getComponent('com_kunena');
  45.             $menus = JApplication::getMenu('site', array());
  46.             $items = $menus->getItems('component_id', $component->id);
  47.             foreach($items as $item){
  48.                 if(@$item->query['view'] == 'home'){
  49.                     $parent->id = $item->id;
  50.                     break;
  51.                 }
  52.             }
  53.         }else{
  54.             return true;
  55.         }
  56.         $priority = JArrayHelper::getValue($params, 'cat_priority', $parent->priority);
  57.         $changefreq = JArrayHelper::getValue($params, 'cat_changefreq', $parent->changefreq);
  58.         if($priority == '-1')$priority = $parent->priority;
  59.         if($changefreq == '-1')    $changefreq = $parent->changefreq;
  60.         $params['cat_priority'] = $priority;
  61.         $params['cat_changefreq'] = $changefreq;
  62.         $jVersion = new JVersion();
  63.         if($jVersion->isCompatible('3.1'))
  64.             $params['groups'] = implode(',', $user->getAuthorisedViewLevels());
  65.         else{
  66.             $params['groups'] = implode(',', $user->authorisedLevels());
  67.         }
  68.         $priority = JArrayHelper::getValue($params, 'topic_priority', $parent->priority);
  69.         $changefreq = JArrayHelper::getValue($params, 'topic_changefreq', $parent->changefreq);
  70.         if($priority == '-1')$priority = $parent->priority;
  71.         if($changefreq == '-1')$changefreq = $parent->changefreq;
  72.         $params['topic_priority'] = $priority;
  73.         $params['topic_changefreq'] = $changefreq;
  74.         $ordering = JArrayHelper::getValue($params, 'topics_order', 'ordering');
  75.         if(!in_array($ordering, array('id', 'ordering', 'time', 'subject', 'hits')))
  76.             $ordering = 'ordering';
  77.         $params['topics_order'] = 't.`'.$ordering.'`';
  78.         $params['include_pagination'] = ($xmap->view == 'xml');
  79.         $params['limit'] = '';
  80.         $params['days'] = '';
  81.         $limit = JArrayHelper::getValue($params, 'max_topics', '');
  82.         if(is_numeric($limit))$params['limit'] = $limit;
  83.         $days = JArrayHelper::getValue($params, 'max_age', '');
  84.         $params['days'] = false;
  85.         if(is_numeric($days))$params['days'] = ($xmap->now - (intval($days) * 86400));
  86.         $params['table_prefix'] = xmap_com_kunena::getTablePrefix();
  87.         xmap_com_kunena::getCategoryTree($xmap, $parent, $params, $catid);
  88.     }
  89.    function getCategoryTree($xmap, $parent, &$params, $parentCat){
  90.         $db = JFactory::getDBO();
  91.         $catlink = 'index.php?option=com_kunena&view=category&catid=%s&Itemid='
  92.             .$parent->id;
  93.         $toplink = 'index.php?option=com_kunena&view=topic&catid=%s&id=%s&Itemid='
  94.             .$parent->id;
  95.         $categories = KunenaForumCategoryHelper::getChildren($parentCat);
  96.         $xmap->changeLevel(1);
  97.         $topics = KunenaForumTopicHelper::getLatestTopics($parentCat, 0, 
  98.                 ($params['limit'] ? (int)$params['limit'] : PHP_INT_MAX), 
  99.                 array('starttime', $params['days']));
  100.         foreach($topics[1] as $topic){
  101.             $node = new stdclass;
  102.             $node->id = $parent->id;
  103.             $node->browserNav = $parent->browserNav;
  104.             $node->uid = 'com_kunenat'.$topic->id;
  105.             $node->name = $topic->subject;
  106.             $node->priority = $params['topic_priority'];
  107.             $node->changefreq = $params['topic_changefreq'];
  108.             $node->modified = intval($topic->last_post_time);
  109.             $node->link = sprintf($toplink, $topic->category_id, $topic->id);
  110.             $node->expandible = false;
  111.             $node->secure = $parent->secure;
  112.             $xmap->printNode($node);
  113.         }
  114.         $xmap->changeLevel(-1);
  115.     }
  116.     private static function loadKunenaApi(){
  117.         if(!defined('KUNENA_LOADED')){
  118.             jimport('joomla.application.component.helper');
  119.             if(!JComponentHelper::isEnabled('com_kunena', true))return false;
  120.             $kunena_api = JPATH_ADMINISTRATOR.'/components/com_kunena/api.php';
  121.             if(!is_file($kunena_api))return false;
  122.             require_once ($kunena_api);
  123.         }
  124.         return true;
  125.     }
  126.     function getKunenaMajorVersion(){
  127.         static $version;
  128.         if(!$version){
  129.             if(class_exists('KunenaForum'))$version = KunenaForum::versionMajor();
  130.             elseif(class_exists('Kunena'))$version = substr(Kunena::version(), 0, 3);
  131.         }
  132.         return $version;
  133.     }
  134.     function getTablePrefix(){
  135.         return '#__kunena';
  136.     }
  137. }
Ernest
The administrator has disabled public write access.