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
/
com_zoo.php
213 lines (172 loc) · 7.12 KB
/
com_zoo.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
<?php
/**
* Updated for SEF by Matt Faulds (Trafalgar Design)
*
*/
/**
* @version 2.1.1TD
* @package Joomla
* @subpackage Xmap - Zoo Plugin
* @copyright (C) 2010-2011 WDEVP
* @license GNU/GPL
*/
defined('_JEXEC') or die;
class xmap_com_zoo {
protected static $_menu_items;
function prepareMenuItem(&$node) {
$link_query = parse_url( $node->link );
parse_str( html_entity_decode($link_query['query']), $link_vars);
$component = JArrayHelper::getValue($link_vars, 'option', '');
$view = JArrayHelper::getValue($link_vars,'view','');
if ($component == 'com_zoo' && $view == 'frontpage' ) {
$id = intval(JArrayHelper::getValue($link_vars,'id',0));
if ( $id != 0 ) {
$node->uid = 'zoo'.$id;
$node->expandible = false;
}
}
}
function getTree( &$xmap, &$parent, &$params) {
$link_query = parse_url( $parent->link );
parse_str( html_entity_decode($link_query['query']), $link_vars );
$view = JArrayHelper::getValue($link_vars,'view',0);
$include_categories = JArrayHelper::getValue( $params, 'include_categories',1,'' );
$include_categories = ( $include_categories == 1
|| ( $include_categories == 2 && $xmap->view == 'xml')
|| ( $include_categories == 3 && $xmap->view == 'html')
|| $xmap->view == 'navigator');
$params['include_categories'] = $include_categories;
$include_items = JArrayHelper::getValue( $params, 'include_items',1,'' );
$include_items = ( $include_items == 1
|| ( $include_items == 2 && $xmap->view == 'xml')
|| ( $include_items == 3 && $xmap->view == 'html')
|| $xmap->view == 'navigator');
$params['include_items'] = $include_items;
$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,'item_priority',$parent->priority,'');
$changefreq = JArrayHelper::getValue($params,'item_changefreq',$parent->changefreq,'');
if ($priority == '-1')
$priority = $parent->priority;
if ($changefreq == '-1')
$changefreq = $parent->changefreq;
$params['item_priority'] = $priority;
$params['item_changefreq'] = $changefreq;
self::getCategoryTree($xmap, $parent, $params);
}
function getCategoryTree ( &$xmap, &$parent, &$params) {
$db = &JFactory::getDBO();
// first we fetch what application we are talking about
$menu =& JSite::getMenu();
$menuparams = $menu->getParams($parent->id);
$appid = intval($menuparams->get('application', 0));
// if selected, we print title category
if ($params['include_categories']) {
// we print title if there is any
// commented out as non-functioning - Matt Faulds
// if ($params['categories_title'] != "" && $xmap->view == 'html') {
// echo "<".$params['categories_title_tag'].">".$params['categories_title']."</".$params['categories_title_tag'].">";
// }
// get categories info from database
$queryc = 'SELECT c.id, c.name '.
'FROM #__zoo_category c '.
' WHERE c.application_id = '.$appid.' AND c.published=1 '.
' ORDER by c.ordering';
$db->setQuery($queryc);
$cats = $db->loadObjectList();
// now we print categories
$xmap->changeLevel(1);
foreach($cats as $cat) {
// Added by Matt Faulds to allow SEF urls
if(!($Itemid = self::_find('frontpage',$appid)->id)) {
$Itemid = self::_find('category',$appid)->id;
}
$node = new stdclass;
$node->id = $parent->id;
$node->uid = $parent->uid .'c'.$cat->id;
$node->name = $cat->name;
$node->link = 'index.php?option=com_zoo&task=category&category_id='.$cat->id.'&Itemid='.$Itemid;
$node->priority = $params['cat_priority'];
$node->changefreq = $params['cat_changefreq'];
$node->expandible = true;
$xmap->printNode($node);
}
$xmap->changeLevel(-1);
}
if ($params['include_items'] ){
// commented out as non-functioning - Matt Faulds
// if ($params['items_title'] != "" && $xmap->view == 'html') {
// echo "<".$params['items_title_tag'].">".$params['items_title']."</".$params['items_title_tag'].">";
// }
// get items info from database
// basically it select those items that are published now (publish_up is less then now, meaning it's in past)
// and not unpublished yet (either not have publish_down date set, or that date is in future)
$queryi = 'SELECT i.id, i.name, i.publish_up ,i.application_id'.
' FROM #__zoo_item i'.
' WHERE i.application_id= '.$appid.
' AND DATEDIFF( i.publish_up, NOW( ) ) <=0'.
' AND IF( i.publish_down >0, DATEDIFF( i.publish_down, NOW( ) ) >0, true )'.
' ORDER BY i.publish_up';
$db->setQuery($queryi);
$items = $db->loadObjectList();
// now we print items
$xmap->changeLevel(1);
foreach($items as $item) {
// Added by Matt Faulds to allow SEF urls
if(!($Itemid = self::_find('frontpage',$appid)->id) AND !($Itemid = self::_find('category',$appid)->id)) {
$Itemid = self::_find('item',$appid)->id;
}
// if we are making news map, we should ignore items older then 3 days
if ($xmap->isNews && strtotime($item->publish_up) < ($xmap->now - (3 * 86400))) {
continue;
}
$node = new stdclass;
$node->id = $parent->id;
$node->uid = $parent->uid .'i'.$item->id;
$node->name = $item->name;
$node->link = 'index.php?option=com_zoo&task=item&item_id='.$item->id.'&Itemid='.$Itemid;
$node->priority = $params['item_priority'];
$node->changefreq = $params['item_changefreq'];
$node->expandible = true;
$node->modified = strtotime($item->publish_up);
$node->newsItem = 1; // if we are making news map and it get this far, it's news
$xmap->printNode($node);
}
$xmap->changeLevel(-1);
}
}
// Adapted from ZOO 2.5.10
// Added by Matt Faulds to allow SEF urls
protected function _find($type, $id) {
// load config
require_once(JPATH_ADMINISTRATOR.'/components/com_zoo/config.php');
// get ZOO app
$app = App::getInstance('zoo');
if (self::$_menu_items == null) {
$component_id = $app->joomla->isVersion('1.5') ? 'componentid' : 'component_id';
$menu_items = $app->object->create('JSite')->getMenu()->getItems($component_id, JComponentHelper::getComponent('com_zoo')->id);
$menu_items = $menu_items ? $menu_items : array();
self::$_menu_items = array_fill_keys(array('category', 'frontpage', 'item'), array());
foreach($menu_items as $menu_item) {
switch (@$menu_item->query['view']) {
case 'frontpage':
self::$_menu_items['frontpage'][$app->parameter->create($menu_item->params)->get('application')] = $menu_item;
break;
case 'category':
self::$_menu_items['category'][$app->parameter->create($menu_item->params)->get('category')] = $menu_item;
break;
case 'item':
self::$_menu_items['item'][$app->parameter->create($menu_item->params)->get('item_id')] = $menu_item;
break;
}
}
}
return @self::$_menu_items[$type][$id];
}
}