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_garyscookbook.php
176 lines (134 loc) · 6.47 KB
/
com_garyscookbook.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
<?php
/**
* @author Branko Wilhelm <branko.wilhelm@gmail.com>
* @link http://wwr.z-index.net
* @copyright (c) 2013 - 2015 Branko Wilhelm
* @license GNU/GPLv3 http://wwr.gnu.org/licenses/gpl-3.0.html
*/
defined('_JEXEC') or die;
class xmap_com_garyscookbook
{
private static $views = array('category', 'categories');
private static $enabled = false;
public function __construct()
{
self::$enabled = JComponentHelper::isEnabled('com_garyscookbook');
JLoader::register('GaryscookbookHelperRoute', JPATH_SITE . '/components/com_garyscookbook/helpers/route.php');
}
public static function getTree(XmapDisplayer &$xmap, stdClass &$parent, array &$params)
{
$uri = new JUri($parent->link);
if (!self::$enabled || !in_array($uri->getVar('view'), self::$views)) {
return;
}
$params['groups'] = implode(',', JFactory::getUser()->getAuthorisedViewLevels());
$params['language_filter'] = JFactory::getApplication()->getLanguageFilter();
$params['include_recipes'] = JArrayHelper::getValue($params, 'include_recipes', 1);
$params['include_recipes'] = ($params['include_recipes'] == 1 || ($params['include_recipes'] == 2 && $xmap->view == 'xml') || ($params['include_recipes'] == 3 && $xmap->view == 'html'));
$params['show_unauth'] = JArrayHelper::getValue($params, 'show_unauth', 0);
$params['show_unauth'] = ($params['show_unauth'] == 1 || ($params['show_unauth'] == 2 && $xmap->view == 'xml') || ($params['show_unauth'] == 3 && $xmap->view == 'html'));
$params['category_priority'] = JArrayHelper::getValue($params, 'category_priority', $parent->priority);
$params['category_changefreq'] = JArrayHelper::getValue($params, 'category_changefreq', $parent->changefreq);
if ($params['category_priority'] == -1) {
$params['category_priority'] = $parent->priority;
}
if ($params['category_changefreq'] == -1) {
$params['category_changefreq'] = $parent->changefreq;
}
$params['recipe_priority'] = JArrayHelper::getValue($params, 'recipe_priority', $parent->priority);
$params['recipe_changefreq'] = JArrayHelper::getValue($params, 'recipe_changefreq', $parent->changefreq);
if ($params['recipe_priority'] == -1) {
$params['recipe_priority'] = $parent->priority;
}
if ($params['recipe_changefreq'] == -1) {
$params['recipe_changefreq'] = $parent->changefreq;
}
switch ($uri->getVar('view')) {
case 'categories':
self::getCategoryTree($xmap, $parent, $params, $uri->getVar('id'));
break;
case 'category':
self::getRecipes($xmap, $parent, $params, $uri->getVar('id'));
break;
}
}
private static function getCategoryTree(XmapDisplayer &$xmap, stdClass &$parent, array &$params, $parent_id)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select(array('c.id', 'c.alias', 'c.title', 'c.parent_id'))
->from('#__categories AS c')
->where('c.parent_id = ' . $db->quote($parent_id ? $parent_id : 1))
->where('c.extension = ' . $db->quote('com_garyscookbook'))
->where('c.published = 1')
->order('c.lft');
if (!$params['show_unauth']) {
$query->where('c.access IN(' . $params['groups'] . ')');
}
if ($params['language_filter']) {
$query->where('c.language IN(' . $db->quote(JFactory::getLanguage()->getTag()) . ', ' . $db->quote('*') . ')');
}
$db->setQuery($query);
$rows = $db->loadObjectList();
if (empty($rows)) {
return;
}
$xmap->changeLevel(1);
foreach ($rows as $row) {
$node = new stdclass;
$node->id = $parent->id;
$node->name = $row->title;
$node->uid = $parent->uid . '_cid_' . $row->id;
$node->browserNav = $parent->browserNav;
$node->priority = $params['category_priority'];
$node->changefreq = $params['category_changefreq'];
$node->pid = $row->parent_id;
$node->link = GaryscookbookHelperRoute::getCategoryRoute($row->id);
if ($xmap->printNode($node) !== false) {
self::getRecipes($xmap, $parent, $params, $row->id);
}
}
$xmap->changeLevel(-1);
}
private static function getRecipes(XmapDisplayer &$xmap, stdClass &$parent, array &$params, $catid)
{
self::getCategoryTree($xmap, $parent, $params, $catid);
if (!$params['include_recipes']) {
return;
}
$db = JFactory::getDbo();
$now = JFactory::getDate('now', 'UTC')->toSql();
$query = $db->getQuery(true)
->select(array('r.id', 'r.alias', 'r.imgtitle'))
->from('#__garyscookbook AS r')
->where('(r.catid = ' . $db->Quote($catid) . ' OR r.catid2 = ' . $db->Quote($catid) . ' OR r.catid3 = ' . $db->Quote($catid) . ' OR r.catid4 = ' . $db->Quote($catid) . ' OR r.catid5 = ' . $db->Quote($catid) . ')')
->where('r.published = 1')
->where('(r.publish_up = ' . $db->quote($db->getNullDate()) . ' OR r.publish_up <= ' . $db->quote($now) . ')')
->where('(r.publish_down = ' . $db->quote($db->getNullDate()) . ' OR r.publish_down >= ' . $db->quote($now) . ')')
->order('r.ordering');
if (!$params['show_unauth']) {
$query->where('r.access IN(' . $params['groups'] . ')');
}
if ($params['language_filter']) {
$query->where('r.language IN(' . $db->quote(JFactory::getLanguage()->getTag()) . ', ' . $db->quote('*') . ')');
}
$db->setQuery($query);
$rows = $db->loadObjectList();
if (empty($rows)) {
return;
}
$xmap->changeLevel(1);
foreach ($rows as $row) {
$node = new stdclass;
$node->id = $parent->id;
$node->name = $row->imgtitle;
$node->uid = $parent->uid . '_' . $row->id;
$node->browserNav = $parent->browserNav;
$node->priority = $params['recipe_priority'];
$node->changefreq = $params['recipe_changefreq'];
$node->link = GaryscookbookHelperRoute::getGaryscookbookRoute($row->id . ':' . $row->alias, $catid);
$xmap->printNode($node);
}
$xmap->changeLevel(-1);
}
}