-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcom_kunena.php
280 lines (241 loc) · 9.73 KB
/
com_kunena.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<?php
/**
* @author Guillermo Vargas, http://joomla.vargas.co.cr
* @email guille@vargas.co.cr
* @version $Id$
* @package XMap
* @license GNU/GPL
* @description XMap plugin for Kunena Forum.
*
* Modified by Masterpro project (https://masterpro.ws).
*/
defined( '_JEXEC' ) or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\Utilities\ArrayHelper;
use Kunena\Forum\Libraries\Factory\KunenaFactory;
use Kunena\Forum\Libraries\Forum\Category\KunenaCategoryHelper;
use Kunena\Forum\Libraries\Forum\Topic\KunenaTopicHelper;
/** Handles Kunena forum structure */
class xmap_com_kunena
{
/*
* This function is called before a menu item is printed. We use it to set the
* proper uniqueid for the item.
*/
static $profile;
static $config;
function prepareMenuItem($node, &$params)
{
$link_query = parse_url($node->link);
parse_str(html_entity_decode($link_query['query']), $link_vars);
$catid = intval(ArrayHelper::getValue($link_vars, 'catid', 0));
$id = intval(ArrayHelper::getValue($link_vars, 'id', 0));
$func = ArrayHelper::getValue($link_vars, 'func', '', '');
if($func = 'showcat' && $catid)
{
$node->uid = 'com_kunenac'.$catid;
$node->expandible = false;
}
elseif($func = 'view' && $id)
{
$node->uid = 'com_kunenaf'.$id;
$node->expandible = false;
}
}
function getTree($xmap, $parent, &$params)
{
if($xmap->isNews) // This component does not provide news content. don't waste time/resources
return false;
// Make sure that we can load the kunena api
if(!xmap_com_kunena::loadKunenaApi())
{
return false;
}
if(!self::$profile)
{
self::$config = KunenaFactory::getConfig();
;
self::$profile = KunenaFactory::getUser();
}
$user = Factory::getUser();
$catid = 0;
$link_query = parse_url($parent->link);
if(!isset($link_query['query']))
{
return;
}
parse_str(html_entity_decode($link_query['query']), $link_vars);
$view = ArrayHelper::getValue($link_vars, 'view', '');
$layout = ArrayHelper::getValue($link_vars, 'layout', '');
$catid_link = ArrayHelper::getValue($link_vars, 'catid', 0);
if($view == 'category' AND (!$layout OR 'list' == $layout))
{
if(!empty($catid_link))
{
$link_query = parse_url($parent->link);
parse_str(html_entity_decode($link_query['query']), $link_vars);
$catid = ArrayHelper::getValue($link_vars, 'catid', 0);
}
else
{
$catid = 0;
}
// Get ItemID of the main menu entry of the component
$component = ComponentHelper::getComponent('com_kunena');
$menus = Factory::getApplication()->getMenu('site', array());
$items = $menus->getItems('component_id', $component->id);
foreach($items as $item)
{
if(@$item->query['view'] == 'home')
{
$parent->id = $item->id;
break;
}
}
}
else
{
return true;
}
$include_topics = ArrayHelper::getValue($params, 'include_topics', 1);
$include_topics = ( $include_topics == 1
|| ( $include_topics == 2 && $xmap->view == 'xml')
|| ( $include_topics == 3 && $xmap->view == 'html')
|| $xmap->view == 'navigator');
$params['include_topics'] = $include_topics;
$priority = ArrayHelper::getValue($params, 'cat_priority', $parent->priority);
$changefreq = ArrayHelper::getValue($params, 'cat_changefreq', $parent->changefreq);
if($priority == '-1')
$priority = $parent->priority;
if($changefreq == '-1')
$changefreq = $parent->changefreq;
$params['cat_priority'] = $priority;
$params['cat_changefreq'] = $changefreq;
$params['groups'] = implode(',', $user->getAuthorisedViewLevels());
$priority = ArrayHelper::getValue($params, 'topic_priority', $parent->priority);
$changefreq = ArrayHelper::getValue($params, 'topic_changefreq', $parent->changefreq);
if($priority == '-1')
$priority = $parent->priority;
if($changefreq == '-1')
$changefreq = $parent->changefreq;
$params['topic_priority'] = $priority;
$params['topic_changefreq'] = $changefreq;
if($include_topics)
{
$ordering = ArrayHelper::getValue($params, 'topics_order', 'ordering');
if(!in_array($ordering, array('id', 'ordering', 'time', 'subject', 'hits')))
$ordering = 'ordering';
$params['topics_order'] = 't.`'.$ordering.'`';
$params['include_pagination'] = ($xmap->view == 'xml');
$params['limit'] = '';
$params['days'] = '';
$limit = ArrayHelper::getValue($params, 'max_topics', '');
if(is_numeric($limit))
{
$params['limit'] = $limit;
}
$days = ArrayHelper::getValue($params, 'max_age', '');
$params['days'] = false;
if(is_numeric($days))
{
$params['days'] = ($xmap->now - (intval($days) * 86400));
}
}
$params['table_prefix'] = xmap_com_kunena::getTablePrefix();
xmap_com_kunena::getCategoryTree($xmap, $parent, $params, $catid);
}
// Builds the Kunena's tree
function getCategoryTree($xmap, $parent, &$params, $parentCat)
{
$db = Factory::getDBO();
// Load categories
$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;
$categories = KunenaCategoryHelper::getChildren($parentCat);
/* 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'])
{
$topics = KunenaTopicHelper::getLatestTopics($parentCat, 0, ($params['limit'] ? (int)$params['limit'] : PHP_INT_MAX), array('starttime', $params['days']));
foreach($topics[1] 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);
$node->link = sprintf($toplink, $topic->category_id, $topic->id);
$node->expandible = false;
$node->secure = $parent->secure;
if($xmap->printNode($node) !== FALSE)
{
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);
}
private static function loadKunenaApi()
{
if(!defined('KUNENA_LOADED'))
{
jimport('joomla.application.component.helper');
// Check if Kunena component is installed/enabled
if(!ComponentHelper::isEnabled('com_kunena', true))
{
return false;
}
// Check if Kunena API exists
$kunena_api = JPATH_ADMINISTRATOR.'/components/com_kunena/api.php';
if(!is_file($kunena_api))
return false;
// Load Kunena API
require_once ($kunena_api);
}
return true;
}
function getTablePrefix()
{
return '#__kunena';
}
}