/administrator/components/com_xmap/extensions/com_lknanswers.php

https://bitbucket.org/dreamriks/gift · PHP · 147 lines · 121 code · 14 blank · 12 comment · 32 complexity · 98dcab373c74c5f64146180f4cad95ab 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_lknanswers.php 120 2010-06-26 11:51:39Z guilleva $
  6. * @package Xmap
  7. * @license GNU/GPL
  8. * @description Xmap plugin for lknanswers component
  9. */
  10. defined( '_JEXEC' ) or die( 'Restricted access.' );
  11. class xmap_com_lknanswers {
  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 == 'detail_category' && $id ) {
  22. $node->uid = 'com_lknanswersc'.$cid;
  23. $node->expandible = true;
  24. } elseif ($task == 'question' && $id) {
  25. $node->uid = 'com_lknanswersq'.$id;
  26. $node->expandible = false;
  27. }
  28. }
  29. function getTree( &$xmap, &$parent, &$params)
  30. {
  31. $link_query = parse_url( $parent->link );
  32. parse_str( html_entity_decode($link_query['query']), $link_vars );
  33. $task = JArrayHelper::getValue($link_vars,'task','');
  34. if ($task && $task != 'detail_category') {
  35. return $list;
  36. } elseif ($task == 'detail_category') {
  37. $catid = intval(JArrayHelper::getValue($link_vars,'id',0));
  38. } else {
  39. $catid=0;
  40. }
  41. $include_questions = JArrayHelper::getValue( $params, 'include_questions',1,'' );
  42. $include_questions = ( $include_questions == 1
  43. || ( $include_questions == 2 && $xmap->view == 'xml')
  44. || ( $include_questions == 3 && $xmap->view == 'html')
  45. || $xmap->view == 'navigator');
  46. $params['include_questions'] = $include_questions;
  47. $priority = JArrayHelper::getValue($params,'cat_priority',$parent->priority,'');
  48. $changefreq = JArrayHelper::getValue($params,'cat_changefreq',$parent->changefreq,'');
  49. if ($priority == '-1')
  50. $priority = $parent->priority;
  51. if ($changefreq == '-1')
  52. $changefreq = $parent->changefreq;
  53. $params['cat_priority'] = $priority;
  54. $params['cat_changefreq'] = $changefreq;
  55. $priority = JArrayHelper::getValue($params,'question_priority',$parent->priority,'');
  56. $changefreq = JArrayHelper::getValue($params,'question_changefreq',$parent->changefreq,'');
  57. if ($priority == '-1')
  58. $priority = $parent->priority;
  59. if ($changefreq == '-1')
  60. $changefreq = $parent->changefreq;
  61. $params['question_priority'] = $priority;
  62. $params['question_changefreq'] = $changefreq;
  63. if ( $include_questions ) {
  64. $params['limit'] = '';
  65. $params['days'] = '';
  66. $limit = JArrayHelper::getValue($params,'max_questions','','');
  67. if ( intval($limit) )
  68. $params['limit'] = ' LIMIT '.$limit;
  69. $days = JArrayHelper::getValue($params,'max_age','','');
  70. if ( intval($days) )
  71. $params['days'] = ' AND a.created >= \''.date('Y-m-d H:m:s', ($xmap->now - ($days*86400)) ) ."' ";
  72. }
  73. xmap_com_lknanswers::getCategoriesTree( $xmap, $parent, $params, $catid );
  74. }
  75. function getCategoriesTree ( &$xmap, &$parent, &$params, &$catid )
  76. {
  77. $db = JFactory::getDBO();
  78. $db->setQuery(
  79. "SELECT a.id, a.title, a.parent_id, ".
  80. "CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(':', a.id, a.alias) ELSE a.id END as slug ".
  81. "FROM `#__lknanswers_categories` AS a, ".
  82. " `#__lknanswers_acl` AS b " .
  83. "WHERE a.published=1 AND a.id = b.cat_id AND b.group_id={$xmap->gid} AND a.parent_id=$catid ".
  84. "ORDER BY Title"
  85. );
  86. $cats = $db->loadObjectList();
  87. $xmap->changeLevel(1);
  88. foreach($cats as $cat) {
  89. $node = new stdclass;
  90. $node->id = $parent->id;
  91. $node->uid = $parent->uid.'c'.$cat->id; // Uniq ID for the category
  92. $node->pid = $cat->parent_id;
  93. $node->name = $cat->title;
  94. $node->priority = $params['cat_priority'];
  95. $node->changefreq = $params['cat_changefreq'];
  96. $node->link = 'index.php?option=com_lknanswers&task=detail_category&id='.$cat->slug;
  97. $node->expandible = true;
  98. if ($xmap->printNode($node) !== FALSE ) {
  99. xmap_com_lknanswers::getCategoriesTree($xmap, $parent, $params, $cat->id);
  100. }
  101. }
  102. if ( $params['include_questions'] ) {
  103. $db->setQuery (
  104. "SELECT a.id, a.title, a.cat_id,UNIX_TIMESTAMP(a.created) AS created, UNIX_TIMESTAMP(MAX(b.created)) AS last_answered, ".
  105. " CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(':', a.id, a.alias) ELSE a.id END as slug ".
  106. "FROM `#__lknanswers_questions` AS a LEFT JOIN `#__lknanswers_question_answers` as b ON a.id = b.question_id and b.published=1 ".
  107. "WHERE a.cat_id=$catid and a.published=1 ".
  108. $params['days'] . " " .
  109. "GROUP by a.id ORDER BY a.created desc" .
  110. $params['limit']
  111. );
  112. $questions = $db->loadObjectList();
  113. foreach($questions as $question) {
  114. $node = new stdclass;
  115. $node->id = $parent->id; // Itemid
  116. $node->uid = $parent->uid .'q'.$question->id; // Uniq ID for the download
  117. $node->name = $question->title;
  118. $node->modified = $question->last_answered? $question->last_answered : $question->created;
  119. $node->link = 'index.php?option=com_lknanswers&task=question&id='.$question->slug;
  120. $node->priority = $params['question_priority'];
  121. $node->changefreq = $params['question_changefreq'];
  122. $node->expandible = false;
  123. $xmap->printNode($node);
  124. }
  125. }
  126. $xmap->changeLevel(-1);
  127. }
  128. }