-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
tag.php
337 lines (284 loc) · 8.4 KB
/
tag.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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<?php
/**
* @package Joomla.Site
* @subpackage com_tags
*
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* Tags Component Tag Model
*
* @since 3.1
*/
class TagsModelTag extends JModelList
{
/**
* The tags that apply.
*
* @var object
* @since 3.1
*/
protected $tag = null;
/**
* The list of items associated with the tags.
*
* @var array
* @since 3.1
*/
protected $items = null;
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
*
* @see JController
* @since 3.1
*/
public function __construct($config = array())
{
if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
'core_content_id', 'c.core_content_id',
'core_title', 'c.core_title',
'core_type_alias', 'c.core_type_alias',
'core_checked_out_user_id', 'c.core_checked_out_user_id',
'core_checked_out_time', 'c.core_checked_out_time',
'core_catid', 'c.core_catid',
'core_state', 'c.core_state',
'core_access', 'c.core_access',
'core_created_user_id', 'c.core_created_user_id',
'core_created_time', 'c.core_created_time',
'core_modified_time', 'c.core_modified_time',
'core_ordering', 'c.core_ordering',
'core_featured', 'c.core_featured',
'core_language', 'c.core_language',
'core_hits', 'c.core_hits',
'core_publish_up', 'c.core_publish_up',
'core_publish_down', 'c.core_publish_down',
'core_images', 'c.core_images',
'core_urls', 'c.core_urls',
'match_count',
);
}
parent::__construct($config);
}
/**
* Method to get a list of items for a list of tags.
*
* @return mixed An array of objects on success, false on failure.
*
* @since 3.1
*/
public function getItems()
{
// Invoke the parent getItems method to get the main list
$items = parent::getItems();
if (!empty($items))
{
foreach ($items as $item)
{
$explodedTypeAlias = explode('.', $item->type_alias);
$item->link = 'index.php?option=' . $explodedTypeAlias[0] . '&view=' . $explodedTypeAlias[1] . '&id='
. $item->content_item_id . ':' . $item->core_alias;
// Get display date
switch ($this->state->params->get('tag_list_show_date'))
{
case 'modified':
$item->displayDate = $item->core_modified_time;
break;
case 'created':
$item->displayDate = $item->core_created_time;
break;
default:
case 'published':
$item->displayDate = ($item->core_publish_up == 0) ? $item->core_created_time : $item->core_publish_up;
break;
}
}
return $items;
}
else
{
return false;
}
}
/**
* Method to build an SQL query to load the list data of all items with a given tag.
*
* @return string An SQL query
*
* @since 3.1
*/
protected function getListQuery()
{
$tagId = $this->getState('tag.id') ? : '';
$typesr = $this->getState('tag.typesr');
$orderByOption = $this->getState('list.ordering', 'c.core_title');
$includeChildren = $this->state->params->get('include_children', 0);
$orderDir = $this->getState('list.direction', 'ASC');
$matchAll = $this->getState('params')->get('return_any_or_all', 1);
$language = $this->getState('tag.language');
$stateFilter = $this->getState('tag.state');
// Optionally filter on language
if (empty($language))
{
$language = JComponentHelper::getParams('com_tags')->get('tag_list_language_filter', 'all');
}
$tagsHelper = new JHelperTags;
$query = $tagsHelper->getTagItemsQuery($tagId, $typesr, $includeChildren, $orderByOption, $orderDir, $matchAll, $language, $stateFilter);
if ($this->state->get('list.filter'))
{
$query->where($this->_db->quoteName('c.core_title') . ' LIKE ' . $this->_db->quote('%' . $this->state->get('list.filter') . '%'));
}
return $query;
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
*
* @since 3.1
*/
protected function populateState($ordering = 'c.core_title', $direction = 'ASC')
{
$app = JFactory::getApplication();
// Load the parameters.
$params = $app->isAdmin() ? JComponentHelper::getParams('com_tags') : $app->getParams();
$this->setState('params', $params);
// Load state from the request.
$ids = $app->input->get('id', array(), 'array');
JArrayHelper::toInteger($ids);
$pkString = implode(',', $ids);
$this->setState('tag.id', $pkString);
// Get the selected list of types from the request. If none are specified all are used.
$typesr = $app->input->get('types', array(), 'array');
if ($typesr)
{
// Implode is needed because the array can contain a string with a coma separated list of ids
$typesr = implode(',', $typesr);
// Sanitise
$typesr = explode(',', $typesr);
JArrayHelper::toInteger($typesr);
$this->setState('tag.typesr', $typesr);
}
$language = $app->input->getString('tag_list_language_filter');
$this->setState('tag.language', $language);
// List state information
$format = $app->input->getWord('format');
if ($format == 'feed')
{
$limit = $app->get('feed_limit');
}
else
{
if ($this->state->params->get('show_pagination_limit'))
{
$limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->get('list_limit'), 'uint');
}
else
{
$limit = $this->state->params->get('maximum', 20);
}
}
$this->setState('list.limit', $limit);
$offset = $app->input->get('limitstart', 0, 'uint');
$this->setState('list.start', $offset);
$itemid = $pkString . ':' . $app->input->get('Itemid', 0, 'int');
$orderCol = $app->getUserStateFromRequest('com_tags.tag.list.' . $itemid . '.filter_order', 'filter_order', '', 'string');
$orderCol = !$orderCol ? $this->state->params->get('tag_list_orderby', 'c.core_title') : $orderCol;
if (!in_array($orderCol, $this->filter_fields))
{
$orderCol = 'c.core_title';
}
$this->setState('list.ordering', $orderCol);
$listOrder = $app->getUserStateFromRequest('com_tags.tag.list.' . $itemid . '.filter_order_direction', 'filter_order_Dir', '', 'string');
$listOrder = !$listOrder ? $this->state->params->get('tag_list_orderby_direction', 'ASC') : $listOrder;
if (!in_array(strtoupper($listOrder), array('ASC', 'DESC', '')))
{
$listOrder = 'ASC';
}
$this->setState('list.direction', $listOrder);
$this->setState('tag.state', 1);
// Optional filter text
$filterSearch = $app->getUserStateFromRequest('com_tags.tag.list.' . $itemid . '.filter_search', 'filter-search', '', 'string');
$this->setState('list.filter', $filterSearch);
}
/**
* Method to get tag data for the current tag or tags
*
* @param integer $pk An optional ID
*
* @return object
*
* @since 3.1
*/
public function getItem($pk = null)
{
if (!isset($this->item) ||$this->item === null)
{
$this->item = false;
if (empty($id))
{
$id = $this->getState('tag.id');
}
// Get a level row instance.
$table = JTable::getInstance('Tag', 'TagsTable');
$idsArray = explode(',', $id);
// Attempt to load the rows into an array.
foreach ($idsArray as $id)
{
try
{
$table->load($id);
// Check published state.
if ($published = $this->getState('filter.published'))
{
if ($table->published != $published)
{
return $this->item;
}
}
// Convert the JTable to a clean JObject.
$properties = $table->getProperties(1);
$this->item[] = JArrayHelper::toObject($properties, 'JObject');
}
catch (RuntimeException $e)
{
$this->setError($e->getMessage());
return false;
}
}
}
return $this->item;
}
/**
* Increment the hit counter.
*
* @param integer $pk Optional primary key of the article to increment.
*
* @return boolean True if successful; false otherwise and internal error set.
*
* @since 3.2
*/
public function hit($pk = 0)
{
$input = JFactory::getApplication()->input;
$hitcount = $input->getInt('hitcount', 1);
if ($hitcount)
{
$pk = (!empty($pk)) ? $pk : (int) $this->getState('tag.id');
$table = JTable::getInstance('Tag', 'TagsTable');
$table->load($pk);
$table->hit($pk);
}
return true;
}
}