/administrator/components/com_xmap/extensions/com_agora.php

https://bitbucket.org/dreamriks/gift · PHP · 201 lines · 157 code · 24 blank · 20 comment · 56 complexity · 05fccb027144f1a490f9b68cbe5bbf57 MD5 · raw file

  1. <?php
  2. /**
  3. * @author Guillermo Vargas, http://joomla.vargas.co.cr
  4. * @email guille@vargas.co.cr
  5. * @version $Id: com_agora.php 153 2011-02-26 21:10:11Z guilleva $
  6. * @package Xmap
  7. * @license GNU/GPL
  8. * @description Xmap plugin for Agora Forumn Component.
  9. */
  10. /** Handles Agora forum structure */
  11. class xmap_com_agora {
  12. /*
  13. * This function is called before a menu item is printed. We use it to set the
  14. * proper uniqueid for the item
  15. */
  16. function prepareMenuItem(&$node,&$params) {
  17. $link_query = parse_url( $node->link );
  18. parse_str( html_entity_decode($link_query['query']), $link_vars);
  19. $id = intval(JArrayHelper::getValue($link_vars,'id',0));
  20. $task = JArrayHelper::getValue( $link_vars, 'task', '', '' );
  21. if ( $task == '' && $id ) {
  22. $node->uid = 'com_agorac'.$catid;
  23. $node->expandible = true;
  24. } elseif ($task == 'forum' && $id) {
  25. $node->uid = 'com_agoraf'.$id;
  26. $node->expandible = true;
  27. } elseif ($task == 'topic' && $id) {
  28. $node->uid = 'com_agorat'.$id;
  29. $node->expandible = false;
  30. }
  31. }
  32. function getTree ( &$xmap, &$parent, &$params ) {
  33. if (strpos($parent->link, 'task=topic') ) {
  34. return true; // Do not expand links to posts
  35. }
  36. $link_query = parse_url( $parent->link );
  37. parse_str( html_entity_decode($link_query['query']), $link_vars);
  38. $task = $xmap->getParam($link_vars,'task','');
  39. $id = $xmap->getParam($link_vars,'id',0);
  40. $forumid = $catid = 0;
  41. if ($task == 'forum') {
  42. $forumid = $id;
  43. } else {
  44. $catid = $id;
  45. }
  46. $include_forums = $xmap->getParam($params,'include_forums',1);
  47. $include_forums = ( $include_forums == 1
  48. || ( $include_forums == 2 && $xmap->view == 'xml')
  49. || ( $include_forums == 3 && $xmap->view == 'html')
  50. || $xmap->view == 'navigator');
  51. $params['include_forums'] = $include_forums;
  52. $include_topics = $xmap->getParam($params,'include_topics',1);
  53. $include_topics = ( $include_topics == 1
  54. || ( $include_topics == 2 && $xmap->view == 'xml')
  55. || ( $include_topics == 3 && $xmap->view == 'html')
  56. || $xmap->view == 'navigator');
  57. $params['include_topics'] = $include_topics;
  58. $priority = $xmap->getParam($params,'cat_priority',$parent->priority);
  59. $changefreq = $xmap->getParam($params,'cat_changefreq',$parent->changefreq);
  60. if ($priority == '-1')
  61. $priority = $parent->priority;
  62. if ($changefreq == '-1')
  63. $changefreq = $parent->changefreq;
  64. $params['cat_priority'] = $priority;
  65. $params['cat_changefreq'] = $changefreq;
  66. // Forums Properties
  67. $priority = $xmap->getParam($params,'forum_priority',$parent->priority);
  68. $changefreq = $xmap->getParam($params,'forum_changefreq',$parent->changefreq);
  69. if ($priority == '-1')
  70. $priority = $parent->priority;
  71. if ($changefreq == '-1')
  72. $changefreq = $parent->changefreq;
  73. $params['forum_priority'] = $priority;
  74. $params['forum_changefreq'] = $changefreq;
  75. // Topics Properties
  76. $priority = $xmap->getParam($params,'topic_priority',$parent->priority);
  77. $changefreq = $xmap->getParam($params,'topic_changefreq',$parent->changefreq);
  78. if ($priority == '-1')
  79. $priority = $parent->priority;
  80. if ($changefreq == '-1')
  81. $changefreq = $parent->changefreq;
  82. $params['topic_priority'] = $priority;
  83. $params['topic_changefreq'] = $changefreq;
  84. if ( $include_topics ) {
  85. $ordering = $xmap->getParam($params,'topics_order','ordering');
  86. if ( !in_array($ordering,array('last_post','subject','num_views')) )
  87. $ordering = 'last_post desc';
  88. $params['topics_order'] = $ordering;
  89. $params['limit'] = '';
  90. $params['days'] = '';
  91. $limit = $xmap->getParam($params,'max_topics','');
  92. if ( intval($limit) )
  93. $params['limit'] = ' LIMIT '.$limit;
  94. $days = $xmap->getParam($params,'max_age','');
  95. if ( intval($days) )
  96. $params['days'] = ' AND last_post >='.($xmap->now - ($days*86400)) ." ";
  97. }
  98. xmap_com_agora::getCategoryTree($xmap, $parent, $params, $catid, $forumid);
  99. }
  100. /* Return category/forum tree */
  101. function getCategoryTree( &$xmap, &$parent, &$params, $parentCat, $parentForum=0 )
  102. {
  103. $database =& JFactory::getDBO();
  104. /*get list of categories*/
  105. $xmap->changeLevel(1);
  106. if ( !$parentCat && !$parentForum ) {
  107. $query = "SELECT id, cat_name FROM #__agora_categories WHERE enable=1 ORDER BY disp_position";
  108. $database->setQuery($query);
  109. # echo $database->getQuery();
  110. $cats = $database->loadObjectList();
  111. foreach ( $cats as $cat ) {
  112. $node = new stdclass;
  113. $node->id = $parent->id;
  114. $node->browserNav = $parent->browserNav;
  115. $node->uid = $parent->uid.'c'.$cat->id;
  116. $node->name = $cat->cat_name;
  117. $node->priority = $params['cat_priority'];
  118. $node->changefreq = $params['cat_changefreq'];
  119. $node->link = 'index.php?option=com_agora&amp;id='.$cat->id;
  120. $node->expandible = true;
  121. if ( $xmap->printNode($node) !== FALSE ) {
  122. xmap_com_agora::getCategoryTree($xmap,$parent,$params,$cat->id,0);
  123. }
  124. }
  125. } else {
  126. if ( $params['include_forums'] ) {
  127. $query = "SELECT f.id,f.forum_name,f.last_post as modified ".
  128. "FROM #__agora_forums AS f ".
  129. "WHERE cat_id=$parentCat ".
  130. "AND parent_forum_id=$parentForum AND enable=1";
  131. $database->setQuery($query);
  132. $forums = $database->loadObjectList();
  133. //get list of forums
  134. foreach($forums as $forum) {
  135. $node = new stdclass;
  136. $node->id = $parent->id;
  137. $node->browserNav = $parent->browserNav;
  138. $node->uid = $parent->uid.'f'.$forum->id;
  139. $node->name = $forum->forum_name;
  140. $node->priority = $params['forum_priority'];
  141. $node->changefreq = $params['forum_changefreq'];
  142. $node->modified = intval($forum->modified);
  143. $node->link = 'index.php?option=com_agora&amp;task=forum&amp;id='.$forum->id;
  144. $node->expandible = true;
  145. if ( $xmap->printNode($node) !== FALSE ) {
  146. xmap_com_agora::getCategoryTree($xmap,$parent,$params,$parentCat,$forum->id);
  147. }
  148. }
  149. if ( $params['include_topics'] ) {
  150. $query = "SELECT id, subject, last_post as modified ".
  151. "FROM #__agora_topics ".
  152. "WHERE forum_id=$parentForum ".
  153. $params['days'] .
  154. "ORDER BY ". $params['topics_order'] .
  155. $params['limit'];
  156. $database->setQuery($query);
  157. $topics = $database->loadObjectList();
  158. //get list of topics
  159. foreach($topics as $topic) {
  160. $node = new stdclass;
  161. $node->id = $parent->id;
  162. $node->browserNav = $parent->browserNav;
  163. $node->uid = $parent->uid.'t'.$topic->id;
  164. $node->name = $topic->subject;
  165. $node->priority = $params['topic_priority'];
  166. $node->changefreq = $params['topic_changefreq'];
  167. $node->modified = intval($topic->modified);
  168. $node->link = 'index.php?option=com_agora&amp;task=topic&amp;id='.$topic->id;
  169. $node->expandible = false;
  170. $xmap->printNode($node);
  171. }
  172. }
  173. }
  174. }
  175. $xmap->changeLevel(-1);
  176. }
  177. }