|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* site_content controller |
|
5
|
|
|
* @see http://modx.im/blog/addons/374.html |
|
6
|
|
|
* |
|
7
|
|
|
* @category controller |
|
8
|
|
|
* @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html |
|
9
|
|
|
* @author Agel_Nash <[email protected]>, kabachello <[email protected]> |
|
10
|
|
|
*/ |
|
11
|
|
|
class site_contentDocLister extends DocLister |
|
|
|
|
|
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Экземпляр экстендера TV |
|
15
|
|
|
* |
|
16
|
|
|
* @var null|xNop|tv_DL_Extender |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $extTV = null; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Экземпляр экстендера cache |
|
22
|
|
|
* |
|
23
|
|
|
* @var null|xNop|cache_DL_Extender |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $extCache = null; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Экземпляр экстендера пагинации |
|
29
|
|
|
* @var null|paginate_DL_Extender |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $extPaginate = null; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* site_contentDocLister constructor. |
|
35
|
|
|
* @param DocumentParser $modx |
|
36
|
|
|
* @param array $cfg |
|
37
|
|
|
* @param null $startTime |
|
|
|
|
|
|
38
|
|
|
*/ |
|
39
|
29 |
|
public function __construct($modx, $cfg = array(), $startTime = null) |
|
40
|
|
|
{ |
|
41
|
29 |
|
parent::__construct($modx, $cfg, $startTime); |
|
42
|
29 |
|
$this->extTV = $this->getExtender('tv', true, true); |
|
43
|
29 |
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @abstract |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getDocs($tvlist = '') |
|
49
|
|
|
{ |
|
50
|
|
|
if ($tvlist == '') { |
|
51
|
|
|
$tvlist = $this->getCFGDef('tvList', ''); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$this->extTV->getAllTV_Name(); |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @var $multiCategories multicategories_DL_Extender |
|
58
|
|
|
*/ |
|
59
|
|
|
$multiCategories = $this->getCFGDef('multiCategories', 0) ? $this->getExtender('multicategories', true) : null; |
|
60
|
|
|
if ($multiCategories) { |
|
|
|
|
|
|
61
|
|
|
$multiCategories->init($this); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @var $extJotCount jotcount_DL_Extender |
|
66
|
|
|
*/ |
|
67
|
|
|
$extJotCount = $this->getCFGdef('jotcount', 0) ? $this->getExtender('jotcount', true) : null; |
|
68
|
|
|
|
|
69
|
|
|
if ($extJotCount) { |
|
|
|
|
|
|
70
|
|
|
$extJotCount->init($this); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @var $extCommentsCount commentscount_DL_Extender |
|
75
|
|
|
*/ |
|
76
|
|
|
$extCommentsCount = $this->getCFGdef('commentsCount', 0) ? $this->getExtender('commentscount', true) : null; |
|
77
|
|
|
|
|
78
|
|
|
if ($extCommentsCount) { |
|
|
|
|
|
|
79
|
|
|
$extCommentsCount->init($this); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
if ($this->extPaginate = $this->getExtender('paginate')) { |
|
|
|
|
|
|
83
|
|
|
$this->extPaginate->init($this); |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$type = $this->getCFGDef('idType', 'parents'); |
|
87
|
|
|
$this->_docs = ($type == 'parents') ? $this->getChildrenList() : $this->getDocList(); |
|
88
|
|
|
if ($tvlist != '' && count($this->_docs) > 0) { |
|
89
|
|
|
$tv = $this->extTV->getTVList(array_keys($this->_docs), $tvlist); |
|
|
|
|
|
|
90
|
|
|
if (!is_array($tv)) { |
|
|
|
|
|
|
91
|
|
|
$tv = array(); |
|
92
|
|
|
} |
|
93
|
|
|
foreach ($tv as $docID => $TVitem) { |
|
94
|
|
|
if (isset($this->_docs[$docID]) && is_array($this->_docs[$docID])) { |
|
95
|
|
|
$this->_docs[$docID] = array_merge($this->_docs[$docID], $TVitem); |
|
96
|
|
|
} else { |
|
97
|
|
|
unset($this->_docs[$docID]); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
/** |
|
102
|
|
|
* @var $extUser user_DL_Extender |
|
103
|
|
|
*/ |
|
104
|
|
|
if ($extUser = $this->getExtender('user')) { |
|
105
|
|
|
$extUser->init($this, array('fields' => $this->getCFGDef("userFields", ""))); |
|
106
|
|
|
foreach ($this->_docs as &$item) { |
|
107
|
|
|
$item = $extUser->setUserData($item); |
|
108
|
|
|
} |
|
109
|
|
|
//[+user.id.createdby+], [+user.fullname.publishedby+], [+dl.user.publishedby+].... |
|
110
|
|
|
} |
|
111
|
|
|
if (1 == $this->getCFGDef('tree', '0')) { |
|
112
|
|
|
$this->treeBuild('id', 'parent'); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
return $this->_docs; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @param string $tpl |
|
120
|
|
|
* @return string |
|
121
|
|
|
*/ |
|
122
|
|
|
public function _render($tpl = '') |
|
|
|
|
|
|
123
|
|
|
{ |
|
124
|
|
|
$out = ''; |
|
125
|
|
|
$separator = $this->getCFGDef('outputSeparator', ''); |
|
126
|
|
|
if ($tpl == '') { |
|
127
|
|
|
$tpl = $this->getCFGDef('tpl', '@CODE:<a href="[+url+]">[+pagetitle+]</a><br />'); |
|
128
|
|
|
} |
|
129
|
|
|
if ($tpl != '') { |
|
130
|
|
|
$this->toPlaceholders(count($this->_docs), 1, "display"); // [+display+] - сколько показано на странице. |
|
131
|
|
|
|
|
132
|
|
|
$i = 1; |
|
133
|
|
|
$sysPlh = $this->renameKeyArr($this->_plh, $this->getCFGDef("sysKey", "dl")); |
|
134
|
|
|
if (count($this->_docs) > 0) { |
|
135
|
|
|
/** |
|
136
|
|
|
* @var $extSummary summary_DL_Extender |
|
137
|
|
|
*/ |
|
138
|
|
|
$extSummary = $this->getExtender('summary'); |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @var $extPrepare prepare_DL_Extender |
|
142
|
|
|
*/ |
|
143
|
|
|
$extPrepare = $this->getExtender('prepare'); |
|
144
|
|
|
|
|
145
|
|
|
$this->skippedDocs = 0; |
|
146
|
|
|
foreach ($this->_docs as $item) { |
|
147
|
|
|
$this->renderTPL = $tpl; |
|
148
|
|
|
$item['summary'] = $extSummary ? $this->getSummary($item, $extSummary, 'introtext', 'content') : ''; |
|
149
|
|
|
|
|
150
|
|
|
$item = array_merge( |
|
151
|
|
|
$item, |
|
152
|
|
|
$sysPlh |
|
153
|
|
|
); //inside the chunks available all placeholders set via $modx->toPlaceholders with prefix id, and with prefix sysKey |
|
154
|
|
|
$item['iteration'] = $i; //[+iteration+] - Number element. Starting from zero |
|
155
|
|
|
|
|
156
|
|
|
if (isset($item['menutitle']) && $item['menutitle'] != '') { |
|
157
|
|
|
$item['title'] = $item['menutitle']; |
|
158
|
|
|
} elseif (isset($item['pagetitle'])) { |
|
159
|
|
|
$item['title'] = $item['pagetitle']; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
if ($this->getCFGDef('makeUrl', 1)) { |
|
163
|
|
|
if ($item['type'] == 'reference') { |
|
164
|
|
|
$item['url'] = is_numeric($item['content']) ? $this->modx->makeUrl( |
|
|
|
|
|
|
165
|
|
|
$item['content'], |
|
166
|
|
|
'', |
|
167
|
|
|
'', |
|
168
|
|
|
$this->getCFGDef('urlScheme', '') |
|
169
|
|
|
) : $item['content']; |
|
170
|
|
|
} else { |
|
171
|
|
|
$item['url'] = $this->modx->makeUrl($item['id'], '', '', $this->getCFGDef('urlScheme', '')); |
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
|
|
$date = $this->getCFGDef('dateSource', 'pub_date'); |
|
175
|
|
|
if (isset($item[$date])) { |
|
176
|
|
|
if (!$item[$date] && $date == 'pub_date' && isset($item['createdon'])) { |
|
|
|
|
|
|
177
|
|
|
$date = 'createdon'; |
|
178
|
|
|
} |
|
179
|
|
|
$_date = is_numeric($item[$date]) && $item[$date] == (int) $item[$date] ? $item[$date] : strtotime($item[$date]); |
|
180
|
|
|
if ($_date !== false) { |
|
181
|
|
|
$_date = $_date + $this->modx->config['server_offset_time']; |
|
182
|
|
|
$dateFormat = $this->getCFGDef('dateFormat', 'd.m.Y H:i'); |
|
183
|
|
|
if ($dateFormat) { |
|
184
|
|
|
$item['date'] = date($dateFormat, $_date); |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
$findTpl = $this->renderTPL; |
|
190
|
|
|
$tmp = $this->uniformPrepare($item, $i); |
|
191
|
|
|
extract($tmp, EXTR_SKIP); |
|
192
|
|
|
if ($this->renderTPL == '') { |
|
193
|
|
|
$this->renderTPL = $findTpl; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
if ($extPrepare) { |
|
197
|
|
|
$item = $extPrepare->init($this, array( |
|
198
|
|
|
'data' => $item, |
|
199
|
|
|
'nameParam' => 'prepare', |
|
200
|
|
|
)); |
|
201
|
|
|
if ($item === false) { |
|
202
|
|
|
$this->skippedDocs++; |
|
203
|
|
|
continue; |
|
204
|
|
|
} |
|
205
|
|
|
} |
|
206
|
|
|
$tmp = $this->parseChunk($this->renderTPL, $item); |
|
207
|
|
|
|
|
208
|
|
|
if ($this->getCFGDef('contentPlaceholder', 0) !== 0) { |
|
209
|
|
|
$this->toPlaceholders( |
|
210
|
|
|
$tmp, |
|
211
|
|
|
1, |
|
212
|
|
|
"item[" . $i . "]" |
|
213
|
|
|
); // [+item[x]+] – individual placeholder for each iteration documents on this page |
|
214
|
|
|
} |
|
215
|
|
|
$out .= $tmp; |
|
216
|
|
|
if (next($this->_docs) !== false) { |
|
217
|
|
|
$out .= $separator; |
|
218
|
|
|
} |
|
219
|
|
|
$i++; |
|
220
|
|
|
} |
|
221
|
|
|
} else { |
|
222
|
|
|
$noneTPL = $this->getCFGDef('noneTpl', $this->getCFGDef('noneTPL', '')); |
|
223
|
|
|
$out = ($noneTPL != '') ? $this->parseChunk($noneTPL, $sysPlh) : ''; |
|
224
|
|
|
} |
|
225
|
|
|
$out = $this->renderWrap($out); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
return $this->toPlaceholders($out); |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* @param array $data |
|
233
|
|
|
* @param mixed $fields |
|
234
|
|
|
* @param array $array |
|
235
|
|
|
* @return string |
|
236
|
|
|
*/ |
|
237
|
|
|
public function getJSON($data, $fields, $array = array()) |
|
|
|
|
|
|
238
|
|
|
{ |
|
239
|
|
|
$out = array(); |
|
240
|
|
|
$fields = is_array($fields) ? $fields : explode(",", $fields); |
|
241
|
|
|
$date = $this->getCFGDef('dateSource', 'pub_date'); |
|
242
|
|
|
/** |
|
243
|
|
|
* @var $extSummary summary_DL_Extender |
|
244
|
|
|
*/ |
|
245
|
|
|
$extSummary = $this->getExtender('summary'); |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* @var $extPrepare prepare_DL_Extender |
|
249
|
|
|
*/ |
|
250
|
|
|
$extPrepare = $this->getExtender('prepare'); |
|
251
|
|
|
|
|
252
|
|
|
/** |
|
253
|
|
|
* @var $extE e_DL_Extender |
|
254
|
|
|
*/ |
|
255
|
|
|
$extE = $this->getExtender('e', true, true); |
|
256
|
|
|
|
|
257
|
|
|
foreach ($data as $num => $row) { |
|
258
|
|
|
if ((array('1') == $fields || in_array('summary', $fields)) && $extSummary) { |
|
259
|
|
|
$row['summary'] = $this->getSummary($row, $extSummary, 'introtext', 'content'); |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
if (array('1') == $fields || in_array('date', $fields)) { |
|
263
|
|
|
if (isset($row[$date])) { |
|
264
|
|
|
if (!$row[$date] && $date == 'pub_date' && isset($row['createdon'])) { |
|
|
|
|
|
|
265
|
|
|
$date = 'createdon'; |
|
266
|
|
|
} |
|
267
|
|
|
$_date = is_numeric($row[$date]) && $row[$date] == (int) $row[$date] ? $row[$date] : strtotime($row[$date]); |
|
268
|
|
|
if ($_date !== false) { |
|
269
|
|
|
$_date = $_date + $this->modx->config['server_offset_time']; |
|
270
|
|
|
$dateFormat = $this->getCFGDef('dateFormat', 'd.m.Y H:i'); |
|
271
|
|
|
if ($dateFormat) { |
|
272
|
|
|
$row['date'] = date($dateFormat, $_date); |
|
273
|
|
|
} |
|
274
|
|
|
} |
|
275
|
|
|
} |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
if (array('1') == $fields || in_array('title', $fields)) { |
|
279
|
|
|
if (isset($row['pagetitle'])) { |
|
280
|
|
|
$row['title'] = empty($row['menutitle']) ? $row['pagetitle'] : $row['menutitle']; |
|
281
|
|
|
} |
|
282
|
|
|
} |
|
283
|
|
|
if ((bool) $this->getCFGDef('makeUrl', 1) && (array('1') == $fields || in_array('url', $fields)) |
|
284
|
|
|
) { |
|
285
|
|
|
if (isset($row['type']) && $row['type'] == 'reference' && isset($row['content'])) { |
|
286
|
|
|
$row['url'] = is_numeric($row['content']) ? $this->modx->makeUrl( |
|
287
|
|
|
$row['content'], |
|
288
|
|
|
'', |
|
289
|
|
|
'', |
|
290
|
|
|
$this->getCFGDef('urlScheme', '') |
|
291
|
|
|
) : $row['content']; |
|
292
|
|
|
} elseif (isset($row['id'])) { |
|
293
|
|
|
$row['url'] = $this->modx->makeUrl($row['id'], '', '', $this->getCFGDef('urlScheme', '')); |
|
294
|
|
|
} |
|
295
|
|
|
} |
|
296
|
|
|
if ($extE && $tmp = $extE->init($this, array('data' => $row))) { |
|
297
|
|
|
if (is_array($tmp)) { |
|
298
|
|
|
$row = $tmp; |
|
299
|
|
|
} |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
if ($extPrepare) { |
|
303
|
|
|
$row = $extPrepare->init($this, array('data' => $row)); |
|
304
|
|
|
if ($row === false) { |
|
305
|
9 |
|
continue; |
|
306
|
|
|
} |
|
307
|
9 |
|
} |
|
308
|
9 |
|
$out[$num] = $row; |
|
309
|
9 |
|
} |
|
310
|
9 |
|
|
|
311
|
9 |
|
return parent::getJSON($out, $fields, $out); |
|
312
|
9 |
|
} |
|
313
|
9 |
|
|
|
314
|
9 |
|
/** |
|
315
|
9 |
|
* @abstract |
|
316
|
9 |
|
*/ |
|
317
|
9 |
|
public function getChildrenCount() |
|
|
|
|
|
|
318
|
|
|
{ |
|
319
|
|
|
$out = $this->extCache->load('childrenCount'); |
|
|
|
|
|
|
320
|
9 |
|
if ($out === false) { |
|
|
|
|
|
|
321
|
|
|
$out = 0; |
|
322
|
9 |
|
$sanitarInIDs = $this->sanitarIn($this->IDs); |
|
323
|
9 |
|
if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
324
|
9 |
|
$q_true = $this->getCFGDef('ignoreEmpty', '0'); |
|
325
|
9 |
|
$q_true = $q_true ? $q_true : $this->getCFGDef('idType', 'parents') == 'parents'; |
|
326
|
9 |
|
$where = $this->getCFGDef('addWhereList', ''); |
|
327
|
|
|
$where = sqlHelper::trimLogicalOp($where); |
|
328
|
|
|
$where = ($where ? $where . ' AND ' : '') . $this->_filters['where']; |
|
329
|
|
|
if ($where != '' && $this->_filters['where'] != '') { |
|
330
|
9 |
|
$where .= " AND "; |
|
331
|
|
|
} |
|
332
|
9 |
|
$where = sqlHelper::trimLogicalOp($where); |
|
333
|
9 |
|
|
|
334
|
9 |
|
$where = "WHERE {$where}"; |
|
335
|
9 |
|
$whereArr = array(); |
|
336
|
9 |
|
if (!$this->getCFGDef('showNoPublish', 0)) { |
|
|
|
|
|
|
337
|
3 |
|
$whereArr[] = "c.deleted=0 AND c.published=1"; |
|
338
|
3 |
|
} else { |
|
339
|
6 |
|
$q_true = 1; |
|
340
|
3 |
|
} |
|
341
|
3 |
|
|
|
342
|
3 |
|
$tbl_site_content = $this->getTable('site_content', 'c'); |
|
343
|
3 |
|
|
|
344
|
3 |
|
if ($sanitarInIDs != "''") { |
|
345
|
3 |
|
switch ($this->getCFGDef('idType', 'parents')) { |
|
346
|
9 |
|
case 'parents': |
|
347
|
9 |
|
switch ($this->getCFGDef('showParent', '0')) { |
|
348
|
6 |
|
case '-1': |
|
349
|
6 |
|
$tmpWhere = "c.parent IN (" . $sanitarInIDs . ")"; |
|
350
|
6 |
|
break; |
|
351
|
3 |
|
case 0: |
|
352
|
|
|
$tmpWhere = "c.parent IN ({$sanitarInIDs}) AND c.id NOT IN({$sanitarInIDs})"; |
|
353
|
|
|
break; |
|
354
|
9 |
|
case 1: |
|
355
|
|
|
default: |
|
356
|
|
|
$tmpWhere = "(c.parent IN ({$sanitarInIDs}) OR c.id IN({$sanitarInIDs}))"; |
|
357
|
|
|
break; |
|
358
|
9 |
|
} |
|
359
|
9 |
|
if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
|
360
|
9 |
|
$addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
|
361
|
9 |
|
$whereArr[] = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))"; |
|
362
|
|
|
} else { |
|
363
|
9 |
|
$whereArr[] = $tmpWhere; |
|
364
|
|
|
} |
|
365
|
9 |
|
|
|
366
|
3 |
|
break; |
|
367
|
3 |
|
case 'documents': |
|
368
|
|
|
$whereArr[] = "c.id IN({$sanitarInIDs})"; |
|
369
|
9 |
|
break; |
|
370
|
9 |
|
} |
|
371
|
|
|
} |
|
372
|
9 |
|
$from = $tbl_site_content . " " . $this->_filters['join']; |
|
373
|
|
|
$where = sqlHelper::trimLogicalOp($where); |
|
374
|
|
|
|
|
375
|
9 |
|
$q_true = $q_true ? $q_true : trim($where) != 'WHERE'; |
|
376
|
|
|
|
|
377
|
9 |
|
if (trim($where) != 'WHERE') { |
|
378
|
9 |
|
$where .= " AND "; |
|
379
|
9 |
|
} |
|
380
|
9 |
|
|
|
381
|
9 |
|
$where .= implode(" AND ", $whereArr); |
|
382
|
9 |
|
$where = sqlHelper::trimLogicalOp($where); |
|
383
|
9 |
|
|
|
384
|
|
|
if (trim($where) == 'WHERE') { |
|
385
|
|
|
$where = ''; |
|
386
|
9 |
|
} |
|
387
|
9 |
|
$group = $this->getGroupSQL($this->getCFGDef('groupBy', $this->getPK())); |
|
388
|
9 |
|
|
|
389
|
|
|
$q_true = $q_true ? $q_true : $group != ''; |
|
390
|
9 |
|
if ($q_true) { |
|
391
|
|
|
$maxDocs = $this->getCFGDef('maxDocs', 0); |
|
392
|
|
|
$limit = $maxDocs > 0 ? $this->LimitSQL($this->getCFGDef('maxDocs', 0)) : ''; |
|
393
|
|
|
$rs = $this->dbQuery("SELECT count(*) FROM (SELECT count(*) FROM {$from} {$where} {$group} {$limit}) as `tmp`"); |
|
394
|
|
|
$out = $this->modx->db->getValue($rs); |
|
395
|
|
|
} else { |
|
396
|
|
|
$out = count($this->IDs); |
|
397
|
|
|
} |
|
398
|
|
|
} |
|
399
|
|
|
$this->extCache->save($out, 'childrenCount'); |
|
400
|
|
|
} |
|
401
|
|
|
|
|
402
|
|
|
return $out; |
|
|
|
|
|
|
403
|
|
|
} |
|
404
|
|
|
|
|
405
|
|
|
/** |
|
406
|
|
|
* @return array |
|
407
|
|
|
*/ |
|
408
|
|
|
protected function getDocList() |
|
409
|
|
|
{ |
|
410
|
|
|
$out = array(); |
|
411
|
|
|
$sanitarInIDs = $this->sanitarIn($this->IDs); |
|
412
|
|
|
if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
413
|
|
|
$where = $this->getCFGDef('addWhereList', ''); |
|
414
|
|
|
$where = sqlHelper::trimLogicalOp($where); |
|
415
|
|
|
|
|
416
|
|
|
$where = ($where ? $where . ' AND ' : '') . $this->_filters['where']; |
|
417
|
|
|
$where = sqlHelper::trimLogicalOp($where); |
|
418
|
|
|
|
|
419
|
|
|
$tbl_site_content = $this->getTable('site_content', 'c'); |
|
420
|
|
|
if ($sanitarInIDs != "''") { |
|
421
|
|
|
$where .= ($where ? " AND " : "") . "c.id IN ({$sanitarInIDs}) AND"; |
|
422
|
|
|
} |
|
423
|
|
|
$where = sqlHelper::trimLogicalOp($where); |
|
424
|
|
|
|
|
425
|
|
|
if ($this->getCFGDef('showNoPublish', 0)) { |
|
426
|
|
|
if ($where != '') { |
|
427
|
|
|
$where = "WHERE {$where}"; |
|
428
|
|
|
} else { |
|
429
|
|
|
$where = ''; |
|
430
|
|
|
} |
|
431
|
|
|
} else { |
|
432
|
|
|
if ($where != '') { |
|
433
|
|
|
$where = "WHERE {$where} AND "; |
|
434
|
|
|
} else { |
|
435
|
|
|
$where = "WHERE {$where} "; |
|
436
|
|
|
} |
|
437
|
|
|
$where .= "c.deleted=0 AND c.published=1"; |
|
438
|
|
|
} |
|
439
|
|
|
|
|
440
|
|
|
$fields = $this->getCFGDef('selectFields', 'c.*'); |
|
441
|
|
|
$group = $this->getGroupSQL($this->getCFGDef('groupBy', $this->getPK())); |
|
442
|
|
|
$sort = $this->SortOrderSQL("if(c.pub_date=0,c.createdon,c.pub_date)"); |
|
443
|
|
|
list($tbl_site_content, $sort) = $this->injectSortByTV( |
|
444
|
|
|
$tbl_site_content . ' ' . $this->_filters['join'], |
|
445
|
|
|
$sort |
|
446
|
|
|
); |
|
447
|
|
|
|
|
448
|
|
|
$limit = $this->LimitSQL($this->getCFGDef('queryLimit', 0)); |
|
449
|
|
|
|
|
450
|
|
|
$rs = $this->dbQuery("SELECT {$fields} FROM {$tbl_site_content} {$where} {$group} {$sort} {$limit}"); |
|
451
|
|
|
|
|
452
|
|
|
while ($item = $this->modx->db->getRow($rs)) { |
|
453
|
|
|
$out[$item['id']] = $item; |
|
454
|
|
|
}; |
|
455
|
|
|
} |
|
456
|
|
|
|
|
457
|
|
|
return $out; |
|
458
|
|
|
} |
|
459
|
|
|
|
|
460
|
|
|
/** |
|
461
|
|
|
* @param string|array $id |
|
462
|
|
|
* @return array |
|
463
|
|
|
*/ |
|
464
|
|
|
public function getChildrenFolder($id) |
|
465
|
|
|
{ |
|
466
|
|
|
$out = array(); |
|
467
|
|
|
$where = $this->getCFGDef('addWhereFolder', ''); |
|
468
|
|
|
$where = sqlHelper::trimLogicalOp($where); |
|
469
|
|
|
if ($where != '') { |
|
470
|
|
|
$where .= " AND "; |
|
471
|
|
|
} |
|
472
|
|
|
|
|
473
|
|
|
$tbl_site_content = $this->getTable('site_content', 'c'); |
|
474
|
|
|
$sanitarInIDs = $this->sanitarIn($id); |
|
475
|
|
|
if ($this->getCFGDef('showNoPublish', 0)) { |
|
476
|
|
|
$where = "WHERE {$where} c.parent IN ({$sanitarInIDs}) AND c.isfolder=1"; |
|
477
|
|
|
} else { |
|
478
|
|
|
$where = "WHERE {$where} c.parent IN ({$sanitarInIDs}) AND c.deleted=0 AND c.published=1 AND c.isfolder=1"; |
|
479
|
|
|
} |
|
480
|
|
|
|
|
481
|
|
|
$rs = $this->dbQuery("SELECT id FROM {$tbl_site_content} {$where}"); |
|
482
|
|
|
|
|
483
|
|
|
while ($item = $this->modx->db->getRow($rs)) { |
|
484
|
18 |
|
$out[] = $item['id']; |
|
485
|
|
|
} |
|
486
|
18 |
|
|
|
487
|
18 |
|
return $out; |
|
488
|
|
|
} |
|
489
|
|
|
|
|
490
|
|
|
/** |
|
491
|
18 |
|
* @param $table |
|
492
|
|
|
* @param $sort |
|
493
|
|
|
* @return array |
|
494
|
|
|
*/ |
|
495
|
|
|
protected function injectSortByTV($table, $sort) |
|
|
|
|
|
|
496
|
|
|
{ |
|
497
|
9 |
|
$out = $this->getExtender('tv', true, true)->injectSortByTV($table, $sort); |
|
|
|
|
|
|
498
|
|
|
if (!is_array($out) || empty($out)) { |
|
|
|
|
|
|
499
|
9 |
|
$out = array($table, $sort); |
|
500
|
9 |
|
} |
|
501
|
|
|
|
|
502
|
9 |
|
return $out; |
|
503
|
9 |
|
} |
|
504
|
9 |
|
|
|
505
|
3 |
|
/** |
|
506
|
3 |
|
* @return array |
|
507
|
|
|
*/ |
|
508
|
9 |
|
protected function getChildrenList() |
|
509
|
9 |
|
{ |
|
510
|
|
|
$where = array(); |
|
511
|
|
|
$out = array(); |
|
512
|
|
|
|
|
513
|
9 |
|
$tmpWhere = $this->getCFGDef('addWhereList', ''); |
|
514
|
|
|
$tmpWhere = sqlHelper::trimLogicalOp($tmpWhere); |
|
515
|
9 |
|
if (!empty($tmpWhere)) { |
|
|
|
|
|
|
516
|
9 |
|
$where[] = $tmpWhere; |
|
517
|
9 |
|
} |
|
518
|
|
|
|
|
519
|
9 |
|
$tmpWhere = sqlHelper::trimLogicalOp($this->_filters['where']); |
|
520
|
9 |
|
if (!empty($tmpWhere)) { |
|
|
|
|
|
|
521
|
9 |
|
$where[] = $tmpWhere; |
|
522
|
9 |
|
} |
|
523
|
3 |
|
|
|
524
|
3 |
|
$tbl_site_content = $this->getTable('site_content', 'c'); |
|
525
|
6 |
|
|
|
526
|
3 |
|
$sort = $this->SortOrderSQL("if(c.pub_date=0,c.createdon,c.pub_date)"); |
|
527
|
3 |
|
list($from, $sort) = $this->injectSortByTV($tbl_site_content . ' ' . $this->_filters['join'], $sort); |
|
528
|
3 |
|
$sanitarInIDs = $this->sanitarIn($this->IDs); |
|
529
|
3 |
|
|
|
530
|
3 |
|
$tmpWhere = null; |
|
531
|
3 |
|
if ($sanitarInIDs != "''") { |
|
532
|
9 |
|
switch ($this->getCFGDef('showParent', '0')) { |
|
533
|
9 |
|
case '-1': |
|
534
|
9 |
|
$tmpWhere = "c.parent IN (" . $sanitarInIDs . ")"; |
|
535
|
6 |
|
break; |
|
536
|
6 |
|
case 0: |
|
537
|
|
|
$tmpWhere = "c.parent IN (" . $sanitarInIDs . ") AND c.id NOT IN(" . $sanitarInIDs . ")"; |
|
538
|
|
|
break; |
|
539
|
6 |
|
case 1: |
|
540
|
|
|
default: |
|
541
|
6 |
|
$tmpWhere = "(c.parent IN (" . $sanitarInIDs . ") OR c.id IN({$sanitarInIDs}))"; |
|
542
|
9 |
|
break; |
|
543
|
9 |
|
} |
|
544
|
9 |
|
} |
|
545
|
9 |
|
if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
|
546
|
9 |
|
$addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
|
547
|
9 |
|
if (empty($tmpWhere)) { |
|
548
|
9 |
|
$tmpWhere = "c.id IN({$addDocs})"; |
|
549
|
9 |
|
} else { |
|
550
|
9 |
|
$tmpWhere = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))"; |
|
551
|
|
|
} |
|
552
|
|
|
} |
|
553
|
9 |
|
if (!empty($tmpWhere)) { |
|
|
|
|
|
|
554
|
9 |
|
$where[] = $tmpWhere; |
|
555
|
|
|
} |
|
556
|
9 |
|
if (!$this->getCFGDef('showNoPublish', 0)) { |
|
|
|
|
|
|
557
|
9 |
|
$where[] = "c.deleted=0 AND c.published=1"; |
|
558
|
9 |
|
} |
|
559
|
9 |
|
if (!empty($where)) { |
|
|
|
|
|
|
560
|
9 |
|
$where = "WHERE " . implode(" AND ", $where); |
|
561
|
|
|
} else { |
|
562
|
9 |
|
$where = ''; |
|
563
|
|
|
} |
|
564
|
|
|
$fields = $this->getCFGDef('selectFields', 'c.*'); |
|
565
|
9 |
|
$group = $this->getGroupSQL($this->getCFGDef('groupBy', $this->getPK())); |
|
566
|
|
|
|
|
567
|
9 |
|
if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
568
|
|
|
$rs = $this->dbQuery("SELECT {$fields} FROM " . $from . " " . $where . " " . |
|
569
|
|
|
$group . " " . |
|
570
|
|
|
$sort . " " . |
|
571
|
|
|
$this->LimitSQL($this->getCFGDef('queryLimit', 0))); |
|
572
|
|
|
|
|
573
|
|
|
while ($item = $this->modx->db->getRow($rs)) { |
|
574
|
|
|
$out[$item['id']] = $item; |
|
575
|
9 |
|
} |
|
576
|
|
|
} |
|
577
|
9 |
|
|
|
578
|
9 |
|
return $out; |
|
579
|
9 |
|
} |
|
580
|
1 |
|
|
|
581
|
1 |
|
/** |
|
582
|
8 |
|
* @param string $field |
|
583
|
8 |
|
* @param string $type |
|
584
|
9 |
|
* @return string |
|
585
|
|
|
*/ |
|
586
|
9 |
|
public function changeSortType($field, $type) |
|
587
|
|
|
{ |
|
588
|
|
|
$type = trim($type); |
|
589
|
|
|
switch (strtoupper($type)) { |
|
590
|
|
|
case 'TVDATETIME': |
|
591
|
|
|
$field = "STR_TO_DATE(" . $field . ",'%d-%m-%Y %H:%i:%s')"; |
|
592
|
|
|
break; |
|
593
|
|
|
default: |
|
594
|
|
|
$field = parent::changeSortType($field, $type); |
|
595
|
|
|
} |
|
596
|
|
|
|
|
597
|
|
|
return $field; |
|
598
|
|
|
} |
|
599
|
|
|
} |
|
600
|
|
|
|
Classes in PHP are usually named in CamelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.
Thus the name database provider becomes
DatabaseProvider.