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_sobipro.php
282 lines (245 loc) · 10.4 KB
/
com_sobipro.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
281
282
<?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_sobipro
{
public static $sectionConfig = array();
public static function prepareMenuItem($node, &$params)
{
// TODO new JUri
$link_query = parse_url($node->link);
parse_str(html_entity_decode($link_query['query']), $link_vars);
$sid = JArrayHelper::getValue($link_vars, 'sid', 0);
$db = JFactory::getDbo();
$db->setQuery('SELECT * FROM `#__sobipro_object` where id=' . (int)$sid);
$row = $db->loadObject();
$node->uid = 'com_sobiproo' . $sid;
if ($row->oType == 'section' || $row->oType == 'category')
{
$node->expandible = true;
} else
{
$node->expandible = false;
}
}
/** Get the content tree for this kind of content */
public static function getTree($xmap, $parent, &$params)
{
if ($xmap->isNews) // This component does not provide news content. don't waste time/resources
return false;
if (!self::loadSobi())
{
return;
}
// TODO new JUri
$link_query = parse_url($parent->link);
parse_str(html_entity_decode($link_query['query']), $link_vars);
$sid = JArrayHelper::getValue($link_vars, 'sid', 1);
$task = JArrayHelper::getValue($link_vars, 'task', null);
if (in_array($task, array('search', 'entry.add')))
{
return;
}
$db = JFactory::getDbo();
$db->setQuery('SELECT * FROM `#__sobipro_object` where id=' . (int)$sid);
$object = $db->loadObject();
if ($object->oType == 'entry')
{
return;
} elseif ($object->oType == 'category')
{
$sectionId = self::findCategorySection($object->parent);
} else
{
$sectionId = $sid;
}
self::$sectionConfig = self::getSectionConfig($sectionId);
$include_entries = JArrayHelper::getValue($params, 'include_entries', 1);
$include_entries = ($include_entries == 1
|| ($include_entries == 2 && $xmap->view == 'xml')
|| ($include_entries == 3 && $xmap->view == 'html')
|| $xmap->view == 'navigator');
$params['include_entries'] = $include_entries;
$priority = JArrayHelper::getValue($params, 'cat_priority', $parent->priority);
$changefreq = JArrayHelper::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;
$priority = JArrayHelper::getValue($params, 'entry_priority', $parent->priority);
$changefreq = JArrayHelper::getValue($params, 'entry_changefreq', $parent->changefreq);
if ($priority == '-1')
$priority = $parent->priority;
if ($changefreq == '-1')
$changefreq = $parent->changefreq;
$params['entry_priority'] = $priority;
$params['entry_changefreq'] = $changefreq;
$date = JFactory::getDate();
$params['now'] = $date->toSql();
if ($include_entries)
{
$ordering = JArrayHelper::getValue($params, 'entries_order', 'b.position');
$orderdir = JArrayHelper::getValue($params, 'entries_orderdir', 'ASC');
if (!in_array($ordering, array('b.position', 'a.counter', 'b.validSince', 'a.updatedTime')))
{
$ordering = 'b.position';
}
if (!in_array($orderdir, array('ASC', 'DESC')))
{
$orderdir = 'ASC';
}
$params['ordering'] = $ordering . ' ' . $orderdir;
$params['limit'] = '';
$params['days'] = '';
$limit = JArrayHelper::getValue($params, 'max_entries', '');
if (intval($limit))
$params['limit'] = ' LIMIT ' . $limit;
$days = JArrayHelper::getValue($params, 'max_age', '');
if (intval($days))
$params['days'] = ' AND a.publish_up >=\'' . strftime("%Y-%m-%d %H:%M:%S", $xmap->now - ($days * 86400)) . "' ";
}
self::getCategoryTree($xmap, $parent, $sid, $params);
}
/** SobiPro support */
public static function getCategoryTree($xmap, $parent, $sid, &$params)
{
$database =& JFactory::getDBO();
$query =
"SELECT a.id,a.nid, a.name, b.pid as pid "
. "\n FROM #__sobipro_object AS a, #__sobipro_relations AS b "
. "\n WHERE a.parent=$sid"
. " AND a.oType='category'"
. " AND b.oType=a.oType"
. " AND a.state=1 "
. " AND a.approved=1 "
. "\n AND a.id=b.id "
. "\n ORDER BY b.position ASC";
$database->setQuery($query);
$rows = $database->loadObjectList();
$modified = time();
$xmap->changeLevel(1);
foreach ($rows as $row)
{
$node = new stdclass;
$node->id = $parent->id;
$node->uid = 'com_sobiproc' . $row->id; // Unique ID
$node->browserNav = $parent->browserNav;
$node->name = html_entity_decode($row->name);
$node->modified = $modified;
#$node->link = 'index.php?option=com_sobipro&sid='.$row->id.':'.trim( SPLang::urlSafe( $row->name ) ).'&Itemid='.$parent->id;
$node->link = SPJoomlaMainFrame::url(array('sid' => $row->id, 'title' => $row->name), false, false);
$node->priority = $params['cat_priority'];
$node->changefreq = $params['cat_changefreq'];
$node->expandible = true;
$node->secure = $parent->secure;
if ($xmap->printNode($node) !== false)
{
self::getCategoryTree($xmap, $parent, $row->id, $params);
}
}
if ($params['include_entries'])
{
$query =
"SELECT a.id, c.baseData as name,a.updatedTime as modified,b.validSince as publish_up, b.pid as catid "
. "\n FROM #__sobipro_object AS a, #__sobipro_relations AS b, #__sobipro_field_data c"
. "\n WHERE a.state=1 "
. "\n AND a.id=b.id "
. "\n AND b.oType = 'entry'"
. "\n AND b.pid = $sid"
. "\n AND a.approved=1 "
. "\n AND (a.validUntil>='{$params['now']}' or a.validUntil='0000-00-00 00:00:00' ) "
. "\n AND (a.validSince<='{$params['now']}' or a.validSince='0000-00-00 00:00:00' ) "
. "\n AND a.id=c.sid AND c.fid=" . self::$sectionConfig['name_field']->sValue
. "\n AND c.section=" . self::$sectionConfig['name_field']->section
. $params['days']
. "\n ORDER BY " . $params['ordering']
. $params['limit'];
$database->setQuery($query);
$rows = $database->loadObjectList();
foreach ($rows as $row)
{
$node = new stdclass;
$node->id = $parent->id;
$node->uid = 'com_sobiproe' . $row->id; // Unique ID
$node->browserNav = $parent->browserNav;
$node->name = html_entity_decode($row->name);
$node->modified = $row->modified ? $row->modified : $row->publish_up;
$node->priority = $params['entry_priority'];
$node->changefreq = $params['entry_changefreq'];
$node->expandible = false;
$node->secure = $parent->secure;
# $node->link = 'index.php?option=com_sobipro&pid='.$row->catid . '&sid=' . $row->id.':'.trim( SPLang::urlSafe( $row->name )).'&Itemid='.$parent->id;
$node->link = SPJoomlaMainFrame::url(array('sid' => $row->id, 'pid' => $row->catid, 'title' => $row->name), false, false);
$xmap->printNode($node);
}
}
$xmap->changeLevel(-1);
}
protected static function getSectionConfig($sectionId)
{
$db = JFactory::getDbo();
$db->setQuery('SELECT * FROM `#__sobipro_config` where section=' . (int)$sectionId);
return $db->loadObjectList('sKey');
}
protected static function loadSobi()
{
if (defined('SOBI_TESTS'))
{
return true;
}
define('SOBI_TESTS', false);
$ver = new JVersion();
$ver = str_replace('.', null, $ver->RELEASE);
// added by Pierre Burri-Wittke globeall.de
if ($ver > '15')
{
$ver = '16';
}
define('SOBI_CMS', 'joomla' . $ver);
define('SOBIPRO', true);
define('SOBI_TASK', 'task');
define('SOBI_DEFLANG', JFactory::getLanguage()->getDefault());
define('SOBI_ACL', 'front');
define('SOBI_ROOT', JPATH_ROOT);
define('SOBI_MEDIA', implode('/', array(JPATH_ROOT, 'media', 'sobipro')));
define('SOBI_MEDIA_LIVE', JURI::root() . '/media/sobipro');
define('SOBI_PATH', SOBI_ROOT . '/components/com_sobipro');
if (!file_exists(SOBI_PATH . '/lib/base/fs/loader.php'))
{
return false;
}
require_once SOBI_PATH . '/lib/base/fs/loader.php';
SPLoader::loadClass('sobi');
SPLoader::loadClass('base.request');
SPLoader::loadClass('base.object');
SPLoader::loadClass('base.factory');
SPLoader::loadClass('base.mainframe');
// added by Pierre Burri-Wittke globeall.de
SPLoader::loadClass('base.const');
SPLoader::loadClass('cms.base.mainframe');
SPLoader::loadClass('cms.base.lang');
return true;
}
protected static function findCategorySection($sid)
{
$db = JFactory::getDbo();
$db->setQuery('SELECT id,parent,oType FROM `#__sobipro_object` where id=' . (int)$sid);
$row = $db->loadObject();
if ($row->oType == 'section')
{
return $row->id;
} else
{
return self::findCategorySection($row->parent);
}
}
}