1
|
|
|
<?php |
2
|
|
|
if (!defined('IN_MANAGER_MODE') || IN_MANAGER_MODE !== true) { |
3
|
|
|
die('<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the EVO Content Manager instead of accessing this file directly.'); |
4
|
|
|
} |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @param int $indent |
8
|
|
|
* @param int $parent |
9
|
|
|
* @param int $expandAll |
10
|
|
|
* @param string $hereid |
11
|
|
|
* @return string |
12
|
|
|
*/ |
13
|
|
|
function makeHTML($indent, $parent, $expandAll, $hereid = '') |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
global $modx, $icons, $_style, $_lang, $opened, $opened2, $closed2, $modx_textdir; |
16
|
|
|
|
17
|
|
|
$output = ''; |
18
|
|
|
|
19
|
|
|
// setup spacer |
20
|
|
|
$level = 0; |
21
|
|
|
$spacer = '<span class="indent">'; |
22
|
|
|
for ($i = 2; $i <= $indent; $i++) { |
23
|
|
|
$spacer .= '<i></i>'; |
24
|
|
|
$level++; |
25
|
|
|
} |
26
|
|
|
$spacer .= '</span>'; |
27
|
|
|
|
28
|
|
|
// manage order-by |
29
|
|
|
if (!isset($_SESSION['tree_sortby']) && !isset($_SESSION['tree_sortdir'])) { |
30
|
|
|
// This is the first startup, set default sort order |
31
|
|
|
$_SESSION['tree_sortby'] = 'menuindex'; |
32
|
|
|
$_SESSION['tree_sortdir'] = 'ASC'; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
switch ($_SESSION['tree_sortby']) { |
36
|
|
|
case 'createdon': |
37
|
|
|
case 'editedon': |
38
|
|
|
case 'publishedon': |
39
|
|
|
case 'pub_date': |
40
|
|
|
case 'unpub_date': |
41
|
|
|
$sortby = sprintf('CASE WHEN %s IS NULL THEN 1 ELSE 0 END, %s', 'sc.' . $_SESSION['tree_sortby'], 'sc.' . $_SESSION['tree_sortby']); |
42
|
|
|
break; |
43
|
|
|
default: |
44
|
|
|
$sortby = 'sc.' . $_SESSION['tree_sortby']; |
45
|
|
|
}; |
46
|
|
|
|
47
|
|
|
$orderby = $modx->db->escape($sortby . ' ' . $_SESSION['tree_sortdir']); |
48
|
|
|
|
49
|
|
|
// Folder sorting gets special setup ;) Add menuindex and pagetitle |
50
|
|
|
if ($_SESSION['tree_sortby'] == 'isfolder') { |
51
|
|
|
$orderby .= ', menuindex ASC, pagetitle'; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$tblsc = $modx->getFullTableName('site_content'); |
55
|
|
|
$tbldg = $modx->getFullTableName('document_groups'); |
56
|
|
|
$tblst = $modx->getFullTableName('site_templates'); |
57
|
|
|
// get document groups for current user |
58
|
|
|
$docgrp = (isset($_SESSION['mgrDocgroups']) && is_array($_SESSION['mgrDocgroups'])) ? implode(',', $_SESSION['mgrDocgroups']) : ''; |
59
|
|
|
$showProtected = false; |
60
|
|
|
if (isset ($modx->config['tree_show_protected'])) { |
61
|
|
|
$showProtected = (boolean)$modx->config['tree_show_protected']; |
62
|
|
|
} |
63
|
|
|
$mgrRole = (isset ($_SESSION['mgrRole']) && (string)$_SESSION['mgrRole'] === '1') ? '1' : '0'; |
64
|
|
|
if ($showProtected == false) { |
|
|
|
|
65
|
|
|
$access = "AND (1={$mgrRole} OR sc.privatemgr=0" . (!$docgrp ? ')' : " OR dg.document_group IN ({$docgrp}))"); |
66
|
|
|
} else { |
67
|
|
|
$access = ''; |
68
|
|
|
} |
69
|
|
|
$docgrp_cond = $docgrp ? "OR dg.document_group IN ({$docgrp})" : ''; |
70
|
|
|
$field = "DISTINCT sc.id, pagetitle, longtitle, menutitle, parent, isfolder, published, pub_date, unpub_date, richtext, searchable, cacheable, deleted, type, template, templatename, menuindex, donthit, hidemenu, alias, contentType, privateweb, privatemgr, |
71
|
|
|
MAX(IF(1={$mgrRole} OR sc.privatemgr=0 {$docgrp_cond}, 1, 0)) AS hasAccess, GROUP_CONCAT(document_group SEPARATOR ',') AS roles"; |
72
|
|
|
$from = "{$tblsc} AS sc LEFT JOIN {$tbldg} dg on dg.document = sc.id LEFT JOIN {$tblst} st on st.id = sc.template"; |
73
|
|
|
$where = "(parent={$parent}) {$access} GROUP BY sc.id"; |
74
|
|
|
$result = $modx->db->select($field, $from, $where, $orderby); |
75
|
|
|
if ($modx->db->getRecordCount($result) == 0) { |
76
|
|
|
$output .= sprintf('<div><a class="empty">%s%s <span class="empty">%s</span></a></div>', $spacer, $_style['tree_deletedpage'], $_lang['empty_folder']); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$nodeNameSource = $_SESSION['tree_nodename'] == 'default' ? $modx->config['resource_tree_node_name'] : $_SESSION['tree_nodename']; |
80
|
|
|
|
81
|
|
|
while ($row = $modx->db->getRow($result)) { |
82
|
|
|
$node = ''; |
83
|
|
|
$nodetitle = getNodeTitle($nodeNameSource, $row); |
84
|
|
|
$nodetitleDisplay = $nodetitle; |
85
|
|
|
$treeNodeClass = 'node'; |
86
|
|
|
$treeNodeClass .= $row['hasAccess'] == 0 ? ' protected' : ''; |
87
|
|
|
|
88
|
|
|
if ($row['deleted'] == 1) { |
89
|
|
|
$treeNodeClass .= ' deleted'; |
90
|
|
|
} elseif ($row['published'] == 0) { |
91
|
|
|
$treeNodeClass .= ' unpublished'; |
92
|
|
|
} elseif ($row['hidemenu'] == 1) { |
93
|
|
|
$treeNodeClass .= ' hidemenu'; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
if ($row['id'] == $hereid) { |
97
|
|
|
$treeNodeClass .= ' current'; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$weblinkDisplay = $row['type'] == 'reference' ? sprintf(' %s', $_style['tree_linkgo']) : ''; |
101
|
|
|
$pageIdDisplay = '<small>(' . ($modx_textdir ? '‏' : '') . $row['id'] . ')</small>'; |
102
|
|
|
|
103
|
|
|
// Prepare displaying user-locks |
104
|
|
|
$lockedByUser = ''; |
105
|
|
|
$rowLock = $modx->elementIsLocked(7, $row['id'], true); |
106
|
|
|
if ($rowLock && $modx->hasPermission('display_locks')) { |
107
|
|
|
if ($rowLock['sid'] == $modx->sid) { |
108
|
|
|
$title = $modx->parseText($_lang["lock_element_editing"], array( |
109
|
|
|
'element_type' => $_lang["lock_element_type_7"], |
110
|
|
|
'lasthit_df' => $rowLock['lasthit_df'] |
111
|
|
|
)); |
112
|
|
|
$lockedByUser = '<span title="' . $title . '" class="editResource">' . $_style['tree_preview_resource'] . '</span>'; |
113
|
|
|
} else { |
114
|
|
|
$title = $modx->parseText($_lang["lock_element_locked_by"], array( |
115
|
|
|
'element_type' => $_lang["lock_element_type_7"], |
116
|
|
|
'username' => $rowLock['username'], |
117
|
|
|
'lasthit_df' => $rowLock['lasthit_df'] |
118
|
|
|
)); |
119
|
|
View Code Duplication |
if ($modx->hasPermission('remove_locks')) { |
120
|
|
|
$lockedByUser = '<span onclick="modx.tree.unlockElement(7, ' . $row['id'] . ', this);return false;" title="' . $title . '" class="lockedResource">' . $_style['icons_secured'] . '</span>'; |
121
|
|
|
} else { |
122
|
|
|
$lockedByUser = '<span title="' . $title . '" class="lockedResource">' . $_style['icons_secured'] . '</span>'; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
$url = $modx->makeUrl($row['id']); |
128
|
|
|
|
129
|
|
|
$title = ''; |
130
|
|
|
if (isDateNode($nodeNameSource)) { |
131
|
|
|
$title = $_lang['pagetitle'] . ': ' . $row['pagetitle'] . '[+lf+]'; |
132
|
|
|
} |
133
|
|
|
$title .= $_lang['id'] . ': ' . $row['id']; |
134
|
|
|
$title .= '[+lf+]' . $_lang['resource_opt_menu_title'] . ': ' . $row['menutitle']; |
135
|
|
|
$title .= '[+lf+]' . $_lang['resource_opt_menu_index'] . ': ' . $row['menuindex']; |
136
|
|
|
$title .= '[+lf+]' . $_lang['alias'] . ': ' . (!empty($row['alias']) ? $row['alias'] : '-'); |
137
|
|
|
$title .= '[+lf+]' . $_lang['template'] . ': ' . $row['templatename']; |
138
|
|
|
$title .= '[+lf+]' . $_lang['publish_date'] . ': ' . $modx->toDateFormat($row['pub_date']); |
139
|
|
|
$title .= '[+lf+]' . $_lang['unpublish_date'] . ': ' . $modx->toDateFormat($row['unpub_date']); |
140
|
|
|
$title .= '[+lf+]' . $_lang['page_data_web_access'] . ': ' . ($row['privateweb'] ? $_lang['private'] : $_lang['public']); |
141
|
|
|
$title .= '[+lf+]' . $_lang['page_data_mgr_access'] . ': ' . ($row['privatemgr'] ? $_lang['private'] : $_lang['public']); |
142
|
|
|
$title .= '[+lf+]' . $_lang['resource_opt_richtext'] . ': ' . ($row['richtext'] == 0 ? $_lang['no'] : $_lang['yes']); |
143
|
|
|
$title .= '[+lf+]' . $_lang['page_data_searchable'] . ': ' . ($row['searchable'] == 0 ? $_lang['no'] : $_lang['yes']); |
144
|
|
|
$title .= '[+lf+]' . $_lang['page_data_cacheable'] . ': ' . ($row['cacheable'] == 0 ? $_lang['no'] : $_lang['yes']); |
145
|
|
|
$title = $modx->htmlspecialchars($title); |
146
|
|
|
$title = str_replace('[+lf+]', ' ', $title); // replace line-breaks with empty space as fall-back |
147
|
|
|
|
148
|
|
|
$data = array( |
149
|
|
|
'id' => $row['id'], |
150
|
|
|
'pagetitle' => $row['pagetitle'], |
151
|
|
|
'longtitle' => $row['longtitle'], |
152
|
|
|
'menutitle' => $row['menutitle'], |
153
|
|
|
'parent' => $parent, |
154
|
|
|
'isfolder' => $row['isfolder'], |
155
|
|
|
'published' => $row['published'], |
156
|
|
|
'deleted' => $row['deleted'], |
157
|
|
|
'type' => $row['type'], |
158
|
|
|
'menuindex' => $row['menuindex'], |
159
|
|
|
'donthit' => $row['donthit'], |
160
|
|
|
'hidemenu' => $row['hidemenu'], |
161
|
|
|
'alias' => $row['alias'], |
162
|
|
|
'contenttype' => $row['contentType'], |
163
|
|
|
'privateweb' => $row['privateweb'], |
164
|
|
|
'privatemgr' => $row['privatemgr'], |
165
|
|
|
'hasAccess' => $row['hasAccess'], |
166
|
|
|
'template' => $row['template'], |
167
|
|
|
'nodetitle' => $nodetitle, |
168
|
|
|
'url' => $url, |
169
|
|
|
'title' => $title, |
170
|
|
|
'nodetitleDisplay' => $nodetitleDisplay, |
171
|
|
|
'weblinkDisplay' => $weblinkDisplay, |
172
|
|
|
'pageIdDisplay' => $pageIdDisplay, |
173
|
|
|
'lockedByUser' => $lockedByUser, |
174
|
|
|
'treeNodeClass' => $treeNodeClass, |
175
|
|
|
'treeNodeSelected' => $row['id'] == $hereid ? ' treeNodeSelected' : '', |
176
|
|
|
'tree_page_click' => $modx->config['tree_page_click'], |
177
|
|
|
'showChildren' => 1, |
178
|
|
|
'openFolder' => 1, |
179
|
|
|
'contextmenu' => '', |
180
|
|
|
'tree_minusnode' => $_style['tree_minusnode'], |
181
|
|
|
'tree_plusnode' => $_style['tree_plusnode'], |
182
|
|
|
'spacer' => $spacer, |
183
|
|
|
'subMenuState' => '', |
184
|
|
|
'level' => $level, |
185
|
|
|
'isPrivate' => 0, |
186
|
|
|
'roles' => ($row['roles'] ? $row['roles'] : '') |
187
|
|
|
); |
188
|
|
|
|
189
|
|
|
$ph = $data; |
|
|
|
|
190
|
|
|
$ph['nodetitle_esc'] = addslashes($nodetitle); |
191
|
|
|
$ph['indent'] = $indent + 1; |
192
|
|
|
$ph['expandAll'] = $expandAll; |
193
|
|
|
$ph['isPrivate'] = ($row['privateweb'] || $row['privatemgr']) ? 1 : 0; |
194
|
|
|
|
195
|
|
|
if (!$row['isfolder']) { |
196
|
|
|
$tpl = getTplSingleNode(); |
197
|
|
|
switch ($row['id']) { |
198
|
|
|
case $modx->config['site_start'] : |
|
|
|
|
199
|
|
|
$icon = $_style['tree_page_home']; |
200
|
|
|
break; |
201
|
|
|
case $modx->config['error_page'] : |
|
|
|
|
202
|
|
|
$icon = $_style['tree_page_404']; |
203
|
|
|
break; |
204
|
|
|
case $modx->config['site_unavailable_page'] : |
|
|
|
|
205
|
|
|
$icon = $_style['tree_page_hourglass']; |
206
|
|
|
break; |
207
|
|
|
case $modx->config['unauthorized_page'] : |
|
|
|
|
208
|
|
|
$icon = $_style['tree_page_info']; |
209
|
|
|
break; |
210
|
|
|
default: |
211
|
|
View Code Duplication |
if (isset($icons[$row['contentType']])) { |
212
|
|
|
$icon = $icons[$row['contentType']]; |
213
|
|
|
} else { |
214
|
|
|
$icon = $_style['tree_page']; |
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
$ph['icon'] = $icon; |
218
|
|
|
|
219
|
|
|
// invoke OnManagerNodePrerender event |
220
|
|
|
$prenode = $modx->invokeEvent("OnManagerNodePrerender", array('ph' => $ph)); |
221
|
|
View Code Duplication |
if (is_array($prenode)) { |
222
|
|
|
$phnew = array(); |
223
|
|
|
foreach ($prenode as $pnode) { |
224
|
|
|
$phnew = array_merge($phnew, unserialize($pnode)); |
225
|
|
|
} |
226
|
|
|
$ph = (count($phnew) > 0) ? $phnew : $ph; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
View Code Duplication |
if ($ph['contextmenu']) { |
230
|
|
|
$ph['contextmenu'] = ' data-contextmenu="' . _htmlentities($ph['contextmenu']) . '"'; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
if ($_SESSION['tree_show_only_folders']) { |
234
|
|
|
if ($row['parent'] == 0) { |
235
|
|
|
$node .= $modx->parseText($tpl, $ph); |
236
|
|
|
} else { |
237
|
|
|
$node .= ''; |
238
|
|
|
} |
239
|
|
|
} else { |
240
|
|
|
$node .= $modx->parseText($tpl, $ph); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
} else { |
244
|
|
|
$ph['icon_folder_open'] = $_style['tree_folderopen_new']; |
245
|
|
|
$ph['icon_folder_close'] = $_style['tree_folder_new']; |
246
|
|
|
|
247
|
|
|
if ($_SESSION['tree_show_only_folders']) { |
248
|
|
|
$tpl = getTplFolderNodeNotChildren(); |
249
|
|
|
$checkFolders = checkIsFolder($row['id'], 1) ? 1 : 0; // folders |
250
|
|
|
$checkDocs = checkIsFolder($row['id'], 0) ? 1 : 0; // no folders |
251
|
|
|
$ph['tree_page_click'] = 3; |
252
|
|
|
|
253
|
|
|
// expandAll: two type for partial expansion |
254
|
|
|
if ($expandAll == 1 || ($expandAll == 2 && in_array($row['id'], $opened))) { |
255
|
|
|
if ($expandAll == 1) { |
256
|
|
|
$opened2[] = $row['id']; |
257
|
|
|
} |
258
|
|
|
$ph['icon'] = $ph['icon_folder_open']; |
259
|
|
|
$ph['icon_node_toggle'] = $ph['tree_minusnode']; |
260
|
|
|
$ph['node_toggle'] = 1; |
261
|
|
|
$ph['subMenuState'] = ' open'; |
262
|
|
|
|
263
|
|
|
if (($checkDocs && !$checkFolders) || (!$checkDocs && !$checkFolders)) { |
264
|
|
|
$ph['showChildren'] = 1; |
265
|
|
|
$ph['icon_node_toggle'] = ''; |
266
|
|
|
$ph['icon'] = $ph['icon_folder_close']; |
267
|
|
|
} elseif (!$checkDocs && $checkFolders) { |
268
|
|
|
$ph['showChildren'] = 0; |
269
|
|
|
$ph['openFolder'] = 2; |
270
|
|
|
} else { |
271
|
|
|
$ph['openFolder'] = 2; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
// invoke OnManagerNodePrerender event |
275
|
|
|
$prenode = $modx->invokeEvent("OnManagerNodePrerender", array( |
276
|
|
|
'ph' => $ph, |
277
|
|
|
'opened' => '1' |
278
|
|
|
)); |
279
|
|
View Code Duplication |
if (is_array($prenode)) { |
280
|
|
|
$phnew = array(); |
281
|
|
|
foreach ($prenode as $pnode) { |
282
|
|
|
$phnew = array_merge($phnew, unserialize($pnode)); |
283
|
|
|
} |
284
|
|
|
$ph = (count($phnew) > 0) ? $phnew : $ph; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
View Code Duplication |
if ($ph['contextmenu']) { |
288
|
|
|
$ph['contextmenu'] = ' data-contextmenu="' . _htmlentities($ph['contextmenu']) . '"'; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
$node .= $modx->parseText($tpl, $ph); |
292
|
|
|
if ($checkFolders) { |
293
|
|
|
$node .= makeHTML($indent + 1, $row['id'], $expandAll, $hereid); |
294
|
|
|
} |
295
|
|
|
$node .= '</div></div>'; |
296
|
|
|
} else { |
297
|
|
|
$closed2[] = $row['id']; |
298
|
|
|
$ph['icon'] = $ph['icon_folder_close']; |
299
|
|
|
$ph['icon_node_toggle'] = $ph['tree_plusnode']; |
300
|
|
|
$ph['node_toggle'] = 0; |
301
|
|
|
|
302
|
|
|
if (($checkDocs && !$checkFolders) || (!$checkDocs && !$checkFolders)) { |
303
|
|
|
$ph['showChildren'] = 1; |
304
|
|
|
$ph['icon_node_toggle'] = ''; |
305
|
|
|
} elseif (!$checkDocs && $checkFolders) { |
306
|
|
|
$ph['showChildren'] = 0; |
307
|
|
|
$ph['openFolder'] = 2; |
308
|
|
|
} else { |
309
|
|
|
$ph['openFolder'] = 2; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
// invoke OnManagerNodePrerender event |
313
|
|
|
$prenode = $modx->invokeEvent("OnManagerNodePrerender", array( |
314
|
|
|
'ph' => $ph, |
315
|
|
|
'opened' => '0' |
316
|
|
|
)); |
317
|
|
View Code Duplication |
if (is_array($prenode)) { |
318
|
|
|
$phnew = array(); |
319
|
|
|
foreach ($prenode as $pnode) { |
320
|
|
|
$phnew = array_merge($phnew, unserialize($pnode)); |
321
|
|
|
} |
322
|
|
|
$ph = (count($phnew) > 0) ? $phnew : $ph; |
323
|
|
|
} |
324
|
|
|
|
325
|
|
View Code Duplication |
if ($ph['contextmenu']) { |
326
|
|
|
$ph['contextmenu'] = ' data-contextmenu="' . _htmlentities($ph['contextmenu']) . '"'; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
$node .= $modx->parseText($tpl, $ph); |
330
|
|
|
$node .= '</div></div>'; |
331
|
|
|
} |
332
|
|
|
} else { |
333
|
|
|
$tpl = getTplFolderNode(); |
334
|
|
|
// expandAll: two type for partial expansion |
335
|
|
|
if ($expandAll == 1 || ($expandAll == 2 && in_array($row['id'], $opened))) { |
336
|
|
|
if ($expandAll == 1) { |
337
|
|
|
$opened2[] = $row['id']; |
338
|
|
|
} |
339
|
|
|
$ph['icon'] = $ph['icon_folder_open']; |
340
|
|
|
$ph['icon_node_toggle'] = $ph['tree_minusnode']; |
341
|
|
|
$ph['node_toggle'] = 1; |
342
|
|
|
$ph['subMenuState'] = ' open'; |
343
|
|
|
|
344
|
|
View Code Duplication |
if ($ph['donthit'] == 1) { |
345
|
|
|
$ph['tree_page_click'] = 3; |
346
|
|
|
$ph['icon_node_toggle'] = ''; |
347
|
|
|
$ph['icon'] = $ph['icon_folder_close']; |
348
|
|
|
$ph['showChildren'] = 0; |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
// invoke OnManagerNodePrerender event |
352
|
|
|
$prenode = $modx->invokeEvent("OnManagerNodePrerender", array( |
353
|
|
|
'ph' => $ph, |
354
|
|
|
'opened' => '1' |
355
|
|
|
)); |
356
|
|
|
if (is_array($prenode)) { |
357
|
|
|
$phnew = array(); |
358
|
|
|
foreach ($prenode as $pnode) { |
359
|
|
|
$phnew = array_merge($phnew, unserialize($pnode)); |
360
|
|
|
} |
361
|
|
|
$ph = (count($phnew) > 0) ? $phnew : $ph; |
362
|
|
|
if ($ph['showChildren'] == 0) { |
363
|
|
|
unset($opened2[$row['id']]); |
364
|
|
|
$ph['node_toggle'] = 0; |
365
|
|
|
$ph['subMenuState'] = ''; |
366
|
|
|
} |
367
|
|
|
} |
368
|
|
|
|
369
|
|
View Code Duplication |
if ($ph['showChildren'] == 0) { |
370
|
|
|
$ph['icon_node_toggle'] = ''; |
371
|
|
|
$ph['donthit'] = 1; |
372
|
|
|
$ph['icon'] = $ph['icon_folder_close']; |
373
|
|
|
$tpl = getTplFolderNodeNotChildren(); |
374
|
|
|
} |
375
|
|
|
|
376
|
|
View Code Duplication |
if ($ph['contextmenu']) { |
377
|
|
|
$ph['contextmenu'] = ' data-contextmenu="' . _htmlentities($ph['contextmenu']) . '"'; |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
$node .= $modx->parseText($tpl, $ph); |
381
|
|
|
if ($ph['donthit'] == 0) { |
382
|
|
|
$node .= makeHTML($indent + 1, $row['id'], $expandAll, $hereid); |
383
|
|
|
} |
384
|
|
|
$node .= '</div></div>'; |
385
|
|
|
} else { |
386
|
|
|
$closed2[] = $row['id']; |
387
|
|
|
$ph['icon'] = $ph['icon_folder_close']; |
388
|
|
|
$ph['icon_node_toggle'] = $ph['tree_plusnode']; |
389
|
|
|
$ph['node_toggle'] = 0; |
390
|
|
|
|
391
|
|
View Code Duplication |
if ($ph['donthit'] == 1) { |
392
|
|
|
$ph['tree_page_click'] = 3; |
393
|
|
|
$ph['icon_node_toggle'] = ''; |
394
|
|
|
$ph['icon'] = $ph['icon_folder_close']; |
395
|
|
|
$ph['showChildren'] = 0; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
// invoke OnManagerNodePrerender event |
399
|
|
|
$prenode = $modx->invokeEvent("OnManagerNodePrerender", array( |
400
|
|
|
'ph' => $ph, |
401
|
|
|
'opened' => '0' |
402
|
|
|
)); |
403
|
|
View Code Duplication |
if (is_array($prenode)) { |
404
|
|
|
$phnew = array(); |
405
|
|
|
foreach ($prenode as $pnode) { |
406
|
|
|
$phnew = array_merge($phnew, unserialize($pnode)); |
407
|
|
|
} |
408
|
|
|
$ph = (count($phnew) > 0) ? $phnew : $ph; |
409
|
|
|
} |
410
|
|
|
|
411
|
|
View Code Duplication |
if ($ph['showChildren'] == 0) { |
412
|
|
|
$ph['icon_node_toggle'] = ''; |
413
|
|
|
$ph['donthit'] = 1; |
414
|
|
|
$ph['icon'] = $ph['icon_folder_close']; |
415
|
|
|
$tpl = getTplFolderNodeNotChildren(); |
416
|
|
|
} |
417
|
|
|
|
418
|
|
View Code Duplication |
if ($ph['contextmenu']) { |
419
|
|
|
$ph['contextmenu'] = ' data-contextmenu="' . _htmlentities($ph['contextmenu']) . '"'; |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
$node .= $modx->parseText($tpl, $ph); |
423
|
|
|
$node .= '</div></div>'; |
424
|
|
|
} |
425
|
|
|
} |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
// invoke OnManagerNodeRender event |
429
|
|
|
$data['node'] = $node; |
430
|
|
|
$evtOut = $modx->invokeEvent('OnManagerNodeRender', $data); |
431
|
|
|
if (is_array($evtOut)) { |
432
|
|
|
$evtOut = implode("\n", $evtOut); |
433
|
|
|
} |
434
|
|
|
if ($evtOut != '') { |
435
|
|
|
$node = trim($evtOut); |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
$output .= $node; |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
return $output; |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
/** |
445
|
|
|
* @param array $_style |
446
|
|
|
* @return array |
447
|
|
|
*/ |
448
|
|
|
function getIconInfo($_style) |
449
|
|
|
{ |
450
|
|
|
if (!isset($_style['tree_page_gif'])) { |
451
|
|
|
$_style['tree_page_gif'] = $_style['tree_page']; |
452
|
|
|
} |
453
|
|
|
if (!isset($_style['tree_page_jpg'])) { |
454
|
|
|
$_style['tree_page_jpg'] = $_style['tree_page']; |
455
|
|
|
} |
456
|
|
|
if (!isset($_style['tree_page_png'])) { |
457
|
|
|
$_style['tree_page_png'] = $_style['tree_page']; |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
return array( |
461
|
|
|
'text/html' => $_style['tree_page_html'], |
462
|
|
|
'text/plain' => $_style['tree_page'], |
463
|
|
|
'text/xml' => $_style['tree_page_xml'], |
464
|
|
|
'text/css' => $_style['tree_page_css'], |
465
|
|
|
'text/javascript' => $_style['tree_page_js'], |
466
|
|
|
'application/rss+xml' => $_style['tree_page_rss'], |
467
|
|
|
'application/pdf' => $_style['tree_page_pdf'], |
468
|
|
|
'application/vnd.ms-word' => $_style['tree_page_word'], |
469
|
|
|
'application/vnd.ms-excel' => $_style['tree_page_excel'], |
470
|
|
|
'image/gif' => $_style['tree_page_gif'], |
471
|
|
|
'image/jpg' => $_style['tree_page_jpg'], |
472
|
|
|
'image/png' => $_style['tree_page_png'] |
473
|
|
|
); |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
/** |
477
|
|
|
* @param string $nodeNameSource |
478
|
|
|
* @param array $row |
479
|
|
|
* @return string |
480
|
|
|
*/ |
481
|
|
|
function getNodeTitle($nodeNameSource, $row) |
482
|
|
|
{ |
483
|
|
|
global $modx; |
484
|
|
|
|
485
|
|
|
switch ($nodeNameSource) { |
486
|
|
|
case 'menutitle': |
487
|
|
|
$nodetitle = $row['menutitle'] ? $row['menutitle'] : $row['pagetitle']; |
488
|
|
|
break; |
489
|
|
|
case 'alias': |
490
|
|
|
$nodetitle = $row['alias'] ? $row['alias'] : $row['id']; |
491
|
|
|
if (strpos($row['alias'], '.') === false) { |
492
|
|
|
if ($row['isfolder'] != 1 || $modx->config['make_folders'] != 1) { |
493
|
|
|
$nodetitle .= $modx->config['friendly_url_suffix']; |
494
|
|
|
} |
495
|
|
|
} |
496
|
|
|
$nodetitle = $modx->config['friendly_url_prefix'] . $nodetitle; |
497
|
|
|
break; |
498
|
|
|
case 'pagetitle': |
499
|
|
|
$nodetitle = $row['pagetitle']; |
500
|
|
|
break; |
501
|
|
|
case 'longtitle': |
502
|
|
|
$nodetitle = $row['longtitle'] ? $row['longtitle'] : $row['pagetitle']; |
503
|
|
|
break; |
504
|
|
|
case 'createdon': |
505
|
|
|
case 'editedon': |
506
|
|
|
case 'publishedon': |
507
|
|
|
case 'pub_date': |
508
|
|
|
case 'unpub_date': |
509
|
|
|
$doc = $modx->getDocumentObject('id', $row['id']); |
510
|
|
|
$date = $doc[$nodeNameSource]; |
511
|
|
|
if (!empty($date)) { |
512
|
|
|
$nodetitle = $modx->toDateFormat($date); |
513
|
|
|
} else { |
514
|
|
|
$nodetitle = '- - -'; |
515
|
|
|
} |
516
|
|
|
break; |
517
|
|
|
default: |
518
|
|
|
$nodetitle = $row['pagetitle']; |
519
|
|
|
} |
520
|
|
|
$nodetitle = $modx->htmlspecialchars(str_replace(array( |
521
|
|
|
"\r\n", |
522
|
|
|
"\n", |
523
|
|
|
"\r" |
524
|
|
|
), ' ', $nodetitle), ENT_COMPAT); |
525
|
|
|
|
526
|
|
|
return $nodetitle; |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
/** |
530
|
|
|
* @param string $nodeNameSource |
531
|
|
|
* @return bool |
532
|
|
|
*/ |
533
|
|
|
function isDateNode($nodeNameSource) |
534
|
|
|
{ |
535
|
|
|
switch ($nodeNameSource) { |
536
|
|
|
case 'createdon': |
537
|
|
|
case 'editedon': |
538
|
|
|
case 'publishedon': |
539
|
|
|
case 'pub_date': |
540
|
|
|
case 'unpub_date': |
541
|
|
|
return true; |
542
|
|
|
default: |
543
|
|
|
return false; |
544
|
|
|
} |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
/** |
548
|
|
|
* @param int $parent |
549
|
|
|
* @param int $isfolder |
550
|
|
|
* @return int |
551
|
|
|
*/ |
552
|
|
|
function checkIsFolder($parent = 0, $isfolder = 1) |
553
|
|
|
{ |
554
|
|
|
global $modx; |
555
|
|
|
|
556
|
|
|
return (int)$modx->db->getValue($modx->db->query('SELECT count(*) FROM ' . $modx->getFullTableName('site_content') . ' WHERE parent=' . $parent . ' AND isfolder=' . $isfolder . ' ')); |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
/** |
560
|
|
|
* @param mixed $array |
561
|
|
|
* @return string |
562
|
|
|
*/ |
563
|
|
|
function _htmlentities($array) |
564
|
|
|
{ |
565
|
|
|
global $modx; |
566
|
|
|
|
567
|
|
|
$array = json_encode($array, JSON_UNESCAPED_UNICODE); |
|
|
|
|
568
|
|
|
$array = htmlentities($array, ENT_COMPAT, $modx->config['modx_charset']); |
569
|
|
|
|
570
|
|
|
return $array; |
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
/** |
574
|
|
|
* @return string |
575
|
|
|
*/ |
576
|
|
|
function getTplSingleNode() |
577
|
|
|
{ |
578
|
|
|
return '<div id="node[+id+]"><a class="[+treeNodeClass+]" |
579
|
|
|
onclick="modx.tree.treeAction(event,[+id+]);" |
580
|
|
|
oncontextmenu="modx.tree.showPopup(event,[+id+],\'[+nodetitle_esc+]\');" |
581
|
|
|
data-id="[+id+]" |
582
|
|
|
data-title-esc="[+nodetitle_esc+]" |
583
|
|
|
data-published="[+published+]" |
584
|
|
|
data-deleted="[+deleted+]" |
585
|
|
|
data-isfolder="[+isfolder+]" |
586
|
|
|
data-href="[+url+]" |
587
|
|
|
data-private="[+isPrivate+]" |
588
|
|
|
data-roles="[+roles+]" |
589
|
|
|
data-level="[+level+]" |
590
|
|
|
data-treepageclick="[+tree_page_click+]" |
591
|
|
|
[+contextmenu+] |
592
|
|
|
>[+spacer+]<span |
593
|
|
|
class="icon" |
594
|
|
|
onclick="modx.tree.showPopup(event,[+id+],\'[+nodetitle_esc+]\');return false;" |
595
|
|
|
oncontextmenu="this.onclick(event);return false;" |
596
|
|
|
>[+icon+]</span>[+lockedByUser+]<span |
597
|
|
|
class="title" |
598
|
|
|
title="[+title+]">[+nodetitleDisplay+][+weblinkDisplay+]</span>[+pageIdDisplay+]</a></div>'; |
599
|
|
|
} |
600
|
|
|
|
601
|
|
|
/** |
602
|
|
|
* @return string |
603
|
|
|
*/ |
604
|
|
|
function getTplFolderNode() |
605
|
|
|
{ |
606
|
|
|
return '<div id="node[+id+]"><a class="[+treeNodeClass+]" |
607
|
|
|
onclick="modx.tree.treeAction(event,[+id+]);" |
608
|
|
|
oncontextmenu="modx.tree.showPopup(event,[+id+],\'[+nodetitle_esc+]\');" |
609
|
|
|
data-id="[+id+]" |
610
|
|
|
data-title-esc="[+nodetitle_esc+]" |
611
|
|
|
data-published="[+published+]" |
612
|
|
|
data-deleted="[+deleted+]" |
613
|
|
|
data-isfolder="[+isfolder+]" |
614
|
|
|
data-href="[+url+]" |
615
|
|
|
data-private="[+isPrivate+]" |
616
|
|
|
data-roles="[+roles+]" |
617
|
|
|
data-level="[+level+]" |
618
|
|
|
data-icon-expanded="[+tree_plusnode+]" |
619
|
|
|
data-icon-collapsed="[+tree_minusnode+]" |
620
|
|
|
data-icon-folder-open="[+icon_folder_open+]" |
621
|
|
|
data-icon-folder-close="[+icon_folder_close+]" |
622
|
|
|
data-treepageclick="[+tree_page_click+]" |
623
|
|
|
data-showchildren="[+showChildren+]" |
624
|
|
|
data-openfolder="[+openFolder+]" |
625
|
|
|
data-indent="[+indent+]" |
626
|
|
|
data-expandall="[+expandAll+]" |
627
|
|
|
[+contextmenu+] |
628
|
|
|
>[+spacer+]<span |
629
|
|
|
class="toggle" |
630
|
|
|
onclick="modx.tree.toggleNode(event, [+id+]);" |
631
|
|
|
oncontextmenu="this.onclick(event);" |
632
|
|
|
>[+icon_node_toggle+]</span><span |
633
|
|
|
class="icon" |
634
|
|
|
onclick="modx.tree.showPopup(event,[+id+],\'[+nodetitle_esc+]\');return false;" |
635
|
|
|
oncontextmenu="this.onclick(event);return false;" |
636
|
|
|
>[+icon+]</span>[+lockedByUser+]<span |
637
|
|
|
class="title" |
638
|
|
|
title="[+title+]">[+nodetitleDisplay+][+weblinkDisplay+]</span>[+pageIdDisplay+]</a><div>'; |
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
/** |
642
|
|
|
* @return string |
643
|
|
|
*/ |
644
|
|
|
function getTplFolderNodeNotChildren() |
645
|
|
|
{ |
646
|
|
|
return '<div id="node[+id+]"><a class="[+treeNodeClass+]" |
647
|
|
|
onclick="modx.tree.treeAction(event,[+id+]);" |
648
|
|
|
oncontextmenu="modx.tree.showPopup(event,[+id+],\'[+nodetitle_esc+]\');" |
649
|
|
|
data-id="[+id+]" |
650
|
|
|
data-title-esc="[+nodetitle_esc+]" |
651
|
|
|
data-published="[+published+]" |
652
|
|
|
data-deleted="[+deleted+]" |
653
|
|
|
data-isfolder="[+isfolder+]" |
654
|
|
|
data-href="[+url+]" |
655
|
|
|
data-private="[+isPrivate+]" |
656
|
|
|
data-roles="[+roles+]" |
657
|
|
|
data-level="[+level+]" |
658
|
|
|
data-icon-expanded="[+tree_plusnode+]" |
659
|
|
|
data-icon-collapsed="[+tree_minusnode+]" |
660
|
|
|
data-icon-folder-open="[+icon_folder_open+]" |
661
|
|
|
data-icon-folder-close="[+icon_folder_close+]" |
662
|
|
|
data-treepageclick="[+tree_page_click+]" |
663
|
|
|
data-showchildren="[+showChildren+]" |
664
|
|
|
data-openfolder="[+openFolder+]" |
665
|
|
|
data-indent="[+indent+]" |
666
|
|
|
data-expandall="[+expandAll+]" |
667
|
|
|
[+contextmenu+] |
668
|
|
|
>[+spacer+]<span |
669
|
|
|
class="icon" |
670
|
|
|
onclick="modx.tree.showPopup(event,[+id+],\'[+nodetitle_esc+]\');return false;" |
671
|
|
|
oncontextmenu="this.onclick(event);return false;" |
672
|
|
|
>[+icon+]</span>[+lockedByUser+]<span |
673
|
|
|
class="title" |
674
|
|
|
title="[+title+]">[+nodetitleDisplay+][+weblinkDisplay+]</span>[+pageIdDisplay+]</a><div>'; |
675
|
|
|
} |
676
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: