-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
articles.php
204 lines (175 loc) · 6.2 KB
/
articles.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
<?php
/**
* @version $Id$
* @copyright Copyright (C) 2005 - 2009 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die;
jimport('joomla.application.component.modellist');
/**
* This models supports retrieving lists of articles.
*
* @package Joomla.Administrator
* @subpackage com_content
* @since 1.6
*/
class ContentModelArticles extends JModelList
{
/**
* Model context string.
*
* @var string
*/
public $_context = 'com_content.articles';
/**
* Method to auto-populate the model state.
*
* @since 1.6
*/
protected function _populateState()
{
$app = &JFactory::getApplication();
// List state information
//$limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'));
$limit = JRequest::getInt('limit', $app->getCfg('list_limit', 0));
$this->setState('list.limit', $limit);
//$limitstart = $app->getUserStateFromRequest($this->_context.'.limitstart', 'limitstart', 0);
$limitstart = JRequest::getInt('limitstart', 0);
$this->setState('list.limitstart', $limitstart);
//$orderCol = $app->getUserStateFromRequest($this->_context.'.ordercol', 'filter_order', 'a.lft');
$orderCol = JRequest::getCmd('filter_order', 'a.ordering');
$this->setState('list.ordering', $orderCol);
//$orderDirn = $app->getUserStateFromRequest($this->_context.'.orderdirn', 'filter_order_Dir', 'asc');
$orderDirn = JRequest::getWord('filter_order_Dir', 'asc');
$this->setState('list.direction', $orderDirn);
$params = $app->getParams();
$this->setState('params', $params);
$this->setState('filter.published', 1);
$this->setState('filter.access', true);
}
/**
* Method to get a store id based on model configuration state.
*
* This is necessary because the model is used by the component and
* different modules that might need different sets of data or different
* ordering requirements.
*
* @param string $id A prefix for the store id.
*
* @return string A store id.
*/
protected function _getStoreId($id = '')
{
// Compile the store id.
$id .= ':'.$this->getState('list.start');
$id .= ':'.$this->getState('list.limit');
$id .= ':'.$this->getState('list.ordering');
$id .= ':'.$this->getState('list.direction');
$id .= ':'.$this->getState('filter.published');
$id .= ':'.$this->getState('filter.access');
return md5($id);
}
/**
* @param boolean True to join selected foreign information
*
* @return string
*/
function _getListQuery()
{
// Create a new query object.
$query = new JQuery;
// Select the required fields from the table.
$query->select($this->getState(
'list.select',
'a.id, a.title, a.alias, a.title_alias, a.introtext, a.state, a.catid, a.created, a.created_by, a.created_by_alias,' .
' a.modified, a.modified_by,a.publish_up, a.publish_down, a.attribs, a.metadata, a.metakey, a.metadesc, a.access,' .
' LENGTH(a.fulltext) AS readmore'
));
$query->from('#__content AS a');
// Join over the categories.
$query->select('c.title AS category_title, c.path AS category_route, c.access AS category_access');
$query->join('LEFT', '#__categories AS c ON c.id = a.catid');
// Join over the users for the author.
$query->select('ua.name AS author_name');
$query->join('LEFT', '#__users AS ua ON ua.id = a.created_by');
// Filter by access level.
if ($access = $this->getState('filter.access'))
{
$user = &JFactory::getUser();
$groups = implode(',', $user->authorisedLevels());
$query->where('a.access IN ('.$groups.')');
}
// Filter by published state
$published = $this->getState('filter.published');
if (is_numeric($published)) {
$query->where('a.state = ' . (int) $published);
}
else if (is_array($published))
{
JArrayHelper::toInteger($published);
$published = implode(',', $published);
$query->where('a.state IN ('.$published.')');
}
// Filter by a single or group of categories.
$categoryId = $this->getState('filter.category_id');
if (is_numeric($categoryId)) {
$query->where('a.catid = ' . (int) $categoryId);
}
else if (is_array($categoryId))
{
JArrayHelper::toInteger($categoryId);
$categoryId = implode(',', $categoryId);
$query->where('a.catid IN ('.$categoryId.')');
}
// Filter by start and end dates.
$nullDate = $this->_db->Quote($this->_db->getNullDate());
$nowDate = $this->_db->Quote(JFactory::getDate()->toMySQL());
$query->where('(a.publish_up = '.$nullDate.' OR a.publish_up <= '.$nowDate.')');
$query->where('(a.publish_down = '.$nullDate.' OR a.publish_down >= '.$nowDate.')');
// Add the list ordering clause.
$query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.ordering')).' '.$this->_db->getEscaped($this->getState('list.direction', 'ASC')));
//echo nl2br(str_replace('#__','jos_',$query));
return $query;
}
/**
* Method to get a list of articles.
*
* Overriden to inject convert the attribs field into a JParameter object.
*
* @return mixed An array of objects on success, false on failure.
*/
public function &getItems()
{
$items = &parent::getItems();
$user = &JFactory::getUser();
$groups = $user->authorisedLevels();
// Contvert the parameter fields into objects.
foreach ($items as &$item)
{
$registry = new JRegistry;
$registry->loadJSON($item->attribs);
$item->params = clone $this->getState('params');
$item->params->merge($registry);
// TODO: Embed the access controls in here
$item->params->set('access-edit', false);
$access = $this->getState('filter.access');
if ($access = $this->getState('filter.access'))
{
// If the access filter has been set, we already have only the articles this user can view.
$item->params->set('access-view', true);
}
else
{
// If no access filter is set, the layout takes some responsibility for display of limited information.
if ($item->catid == 0 || $item->category_access === null) {
$item->params->set('access-view', in_array($item->access, $groups));
}
else {
$item->params->set('access-view', in_array($item->access, $groups) && in_array($item->category_access, $groups));
}
}
}
return $items;
}
}