This repository has been archived by the owner on May 5, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcom_kunena.php
190 lines (157 loc) · 6.82 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
<?php
/**
* @author Guillermo Vargas <guille@vargas.co.cr>
* @author Branko Wilhelm <branko.wilhelm@gmail.com>
* @link http://www.z-index.net
* @copyright (c) 2005 - 2009 Joomla! Vargas. All rights reserved.
* @copyright (c) 2015 Branko Wilhelm. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
class xmap_com_kunena
{
/**
* @var array
*/
private static $views = array('home', 'category');
/**
* @var bool
*/
private static $enabled = false;
public function __construct()
{
self::$enabled = JPluginHelper::isEnabled('system', 'kunena') && JComponentHelper::isEnabled('com_kunena');
}
/**
* @param XmapDisplayerInterface $xmap
* @param stdClass $parent
* @param array $params
*/
public static function getTree($xmap, stdClass $parent, array &$params)
{
$uri = new JUri($parent->link);
if ($xmap->isNews || !self::$enabled || !in_array($uri->getVar('view'), self::$views))
{
return;
}
$params['include_topics'] = JArrayHelper::getValue($params, 'include_topics', 1);
$params['include_topics'] = ($params['include_topics'] == 1 || ($params['include_topics'] == 2 && $xmap->view == 'xml') || ($params['include_topics'] == 3 && $xmap->view == 'html'));
$params['include_pagination'] = JArrayHelper::getValue($params, 'include_pagination', 0);
$params['include_pagination'] = ($params['include_pagination'] == 1 || ($params['include_pagination'] == 2 && $xmap->view == 'xml') || ($params['include_pagination'] == 3 && $xmap->view == 'html'));
$params['cat_priority'] = JArrayHelper::getValue($params, 'cat_priority', $parent->priority);
$params['cat_priority'] = ($params['cat_priority'] == -1) ? $parent->priority : $params['cat_priority'];
$params['cat_changefreq'] = JArrayHelper::getValue($params, 'cat_changefreq', $parent->changefreq);
$params['cat_changefreq'] = ($params['cat_changefreq'] == -1) ? $parent->changefreq : $params['cat_changefreq'];
$params['topic_priority'] = JArrayHelper::getValue($params, 'topic_priority', $parent->changefreq);
$params['topic_priority'] = ($params['topic_priority'] == -1) ? $parent->priority : $params['topic_priority'];
$params['topic_changefreq'] = JArrayHelper::getValue($params, 'topic_changefreq', $parent->changefreq);
$params['topic_changefreq'] = ($params['topic_changefreq'] == -1) ? $parent->changefreq : $params['topic_changefreq'];
if ($params['include_topics'])
{
if ((int)$limit = JArrayHelper::getValue($params, 'max_topics', 0))
{
$params['limit'] = $limit;
} else
{
$params['limit'] = 0;
}
if ((int)$days = JArrayHelper::getValue($params, 'max_age', 0))
{
$params['days'] = (JFactory::getDate()->toUnix() - (intval($days) * 86400));
} else
{
$params['days'] = '';
}
}
self::getCategoryTree($xmap, $parent, $params, $uri->getVar('catid', 0));
}
/**
* @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);
}
/**
* @param XmapDisplayerInterface $xmap
* @param stdClass $parent
* @param array $params
* @param int $catid
*/
private static function getTopics($xmap, stdClass $parent, array &$params, $catid)
{
self::getCategoryTree($xmap, $parent, $params, $catid);
if (!$params['include_topics'])
{
return;
}
/** @var KunenaForumTopic[] $topics */
$topics = KunenaForumTopicHelper::getLatestTopics($catid, 0, $params['limit'], array('nolimit' => true, 'starttime' => $params['days']));
$topics = $topics[1];
if (empty($topics))
{
return;
}
$xmap->changeLevel(1);
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 = $topic->last_post_time;
$node->link = 'index.php?option=com_kunena&view=topic&catid=' . $topic->category_id . '&id=' . $topic->id;
$node->secure = $parent->secure;
if ($xmap->printNode($node) && $params['include_pagination'])
{
$msgPerPage = KunenaFactory::getConfig()->get('messages_per_page');
$threadPages = ceil($topic->getTotal() / $msgPerPage);
if ($threadPages > 1)
{
$xmap->changeLevel(1);
for ($i = 2; $i <= $threadPages; $i++)
{
$subnode = new stdClass;
$subnode->id = $node->id;
$subnode->uid = $node->uid . '_p_' . $i;
$subnode->name = '[' . $i . ']';
$subnode->link = $node->link . '&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);
}
}
}
$xmap->changeLevel(-1);
}
}