Completed
Push — develop ( db0854...16e54b )
by
unknown
05:27
created

nodes.functions.inc.php ➔ getPrivateIconInfo()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 26
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 21
nc 8
nop 1
dl 0
loc 26
rs 8.5806
c 0
b 0
f 0
1
<?php
2
if (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 $indent
8
 * @param $parent
9
 * @param $expandAll
10
 * @param string $hereid
11
 * @return string
12
 */
13
function makeHTML($indent, $parent, $expandAll, $hereid = '')
0 ignored issues
show
Coding Style introduced by
makeHTML uses the super-global variable $_SESSION which is generally not recommended.

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:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
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) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
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&nbsp;<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
84
        $nodetitle = getNodeTitle($nodeNameSource, $row);
85
        $nodetitleDisplay = $nodetitle;
86
87
        $treeNodeClass = 'node';
88
        $treeNodeClass .= $row['hasAccess'] == 0 ? ' protected' : '';
89
90
        if ($row['deleted'] == 1) {
91
            $treeNodeClass .= ' deleted';
92
        } elseif ($row['published'] == 0) {
93
            $treeNodeClass .= ' unpublished';
94
        } elseif ($row['hidemenu'] == 1) {
95
            $treeNodeClass .= ' hidemenu';
96
        } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
97
        }
98
99
        if ($row['id'] == $hereid) {
100
            $treeNodeClass .= ' current';
101
        }
102
103
        $weblinkDisplay = $row['type'] == 'reference' ? sprintf('&nbsp;%s', $_style['tree_linkgo']) : '';
104
        $pageIdDisplay = '<small>(' . ($modx_textdir ? '&rlm;' : '') . $row['id'] . ')</small>';
105
106
        // Prepare displaying user-locks
107
        $lockedByUser = '';
108
        $rowLock = $modx->elementIsLocked(7, $row['id'], true);
109
        if ($rowLock && $modx->hasPermission('display_locks')) {
110
            if ($rowLock['sid'] == $modx->sid) {
111
                $title = $modx->parseText($_lang["lock_element_editing"], array(
112
                    'element_type' => $_lang["lock_element_type_7"],
113
                    'lasthit_df' => $rowLock['lasthit_df']
114
                ));
115
                $lockedByUser = '<span title="' . $title . '" class="editResource">' . $_style['tree_preview_resource'] . '</span>';
116
            } else {
117
                $title = $modx->parseText($_lang["lock_element_locked_by"], array(
118
                    'element_type' => $_lang["lock_element_type_7"],
119
                    'username' => $rowLock['username'],
120
                    'lasthit_df' => $rowLock['lasthit_df']
121
                ));
122 View Code Duplication
                if ($modx->hasPermission('remove_locks')) {
123
                    $lockedByUser = '<span onclick="modx.tree.unlockElement(7, ' . $row['id'] . ', this);return false;" title="' . $title . '" class="lockedResource">' . $_style['icons_secured'] . '</span>';
124
                } else {
125
                    $lockedByUser = '<span title="' . $title . '" class="lockedResource">' . $_style['icons_secured'] . '</span>';
126
                }
127
            }
128
        }
129
130
        $url = $modx->makeUrl($row['id']);
131
132
        $title = '';
133
        if (isDateNode($nodeNameSource)) {
134
            $title = $_lang['pagetitle'] . ': ' . $row['pagetitle'] . '[+lf+]';
135
        }
136
        $title .= $_lang['id'] . ': ' . $row['id'];
137
        $title .= '[+lf+]' . $_lang['resource_opt_menu_title'] . ': ' . $row['menutitle'];
138
        $title .= '[+lf+]' . $_lang['resource_opt_menu_index'] . ': ' . $row['menuindex'];
139
        $title .= '[+lf+]' . $_lang['alias'] . ': ' . (!empty($row['alias']) ? $row['alias'] : '-');
140
        $title .= '[+lf+]' . $_lang['template'] . ': ' . $row['templatename'];
141
        $title .= '[+lf+]' . $_lang['publish_date'] . ': ' . $modx->toDateFormat($row['pub_date']);
142
        $title .= '[+lf+]' . $_lang['unpublish_date'] . ': ' . $modx->toDateFormat($row['unpub_date']);
143
        $title .= '[+lf+]' . $_lang['page_data_web_access'] . ': ' . ($row['privateweb'] ? $_lang['private'] : $_lang['public']);
144
        $title .= '[+lf+]' . $_lang['page_data_mgr_access'] . ': ' . ($row['privatemgr'] ? $_lang['private'] : $_lang['public']);
145
        $title .= '[+lf+]' . $_lang['resource_opt_richtext'] . ': ' . ($row['richtext'] == 0 ? $_lang['no'] : $_lang['yes']);
146
        $title .= '[+lf+]' . $_lang['page_data_searchable'] . ': ' . ($row['searchable'] == 0 ? $_lang['no'] : $_lang['yes']);
147
        $title .= '[+lf+]' . $_lang['page_data_cacheable'] . ': ' . ($row['cacheable'] == 0 ? $_lang['no'] : $_lang['yes']);
148
        $title = $modx->htmlspecialchars($title);
149
        $title = str_replace('[+lf+]', ' &#13;', $title);   // replace line-breaks with empty space as fall-back
150
151
        $data = array(
152
            'id' => $row['id'],
153
            'pagetitle' => $row['pagetitle'],
154
            'longtitle' => $row['longtitle'],
155
            'menutitle' => $row['menutitle'],
156
            'parent' => $parent,
157
            'isfolder' => $row['isfolder'],
158
            'published' => $row['published'],
159
            'deleted' => $row['deleted'],
160
            'type' => $row['type'],
161
            'menuindex' => $row['menuindex'],
162
            'donthit' => $row['donthit'],
163
            'hidemenu' => $row['hidemenu'],
164
            'alias' => $row['alias'],
165
            'contenttype' => $row['contentType'],
166
            'privateweb' => $row['privateweb'],
167
            'privatemgr' => $row['privatemgr'],
168
            'hasAccess' => $row['hasAccess'],
169
            'template' => $row['template'],
170
            'nodetitle' => $nodetitle,
171
            'url' => $url,
172
            'title' => $title,
173
            'nodetitleDisplay' => $nodetitleDisplay,
174
            'weblinkDisplay' => $weblinkDisplay,
175
            'pageIdDisplay' => $pageIdDisplay,
176
            'lockedByUser' => $lockedByUser,
177
            'treeNodeClass' => $treeNodeClass,
178
            'treeNodeSelected' => $row['id'] == $hereid ? ' treeNodeSelected' : '',
179
            'tree_page_click' => $modx->config['tree_page_click'],
180
            'showChildren' => 1,
181
            'openFolder' => 1,
182
            'contextmenu' => '',
183
            'tree_minusnode' => $_style['tree_minusnode'],
184
            'tree_plusnode' => $_style['tree_plusnode'],
185
            'spacer' => $spacer,
186
            'subMenuState' => '',
187
            'level' => $level,
188
            'isPrivate' => 0,
189
            'roles' => ($row['roles'] ? $row['roles'] : '')
190
        );
191
192
        $ph = $data;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $ph. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
193
        $ph['nodetitle_esc'] = addslashes($nodetitle);
194
        $ph['indent'] = $indent + 1;
195
        $ph['expandAll'] = $expandAll;
196
        $ph['isPrivate'] = ($row['privateweb'] || $row['privatemgr']) ? 1 : 0;
197
198
        if (!$row['isfolder']) {
199
            $tpl = getTplSingleNode();
200
            switch ($row['id']) {
201
                case $modx->config['site_start']            :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
202
                    $icon = $_style['tree_page_home'];
203
                    break;
204
                case $modx->config['error_page']            :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
205
                    $icon = $_style['tree_page_404'];
206
                    break;
207
                case $modx->config['site_unavailable_page'] :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
208
                    $icon = $_style['tree_page_hourglass'];
209
                    break;
210
                case $modx->config['unauthorized_page']     :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
211
                    $icon = $_style['tree_page_info'];
212
                    break;
213
                default:
214 View Code Duplication
                    if (isset($icons[$row['contentType']])) {
215
                        $icon = $icons[$row['contentType']];
216
                    } else {
217
                        $icon = $_style['tree_page'];
218
                    }
219
            }
220
            $ph['icon'] = $icon;
221
222
            // invoke OnManagerNodePrerender event
223
            $prenode = $modx->invokeEvent("OnManagerNodePrerender", array('ph' => $ph));
224 View Code Duplication
            if (is_array($prenode)) {
225
                $phnew = array();
226
                foreach ($prenode as $pnode) {
227
                    $phnew = array_merge($phnew, unserialize($pnode));
228
                }
229
                $ph = (count($phnew) > 0) ? $phnew : $ph;
230
            }
231
232 View Code Duplication
            if ($ph['contextmenu']) {
233
                $ph['contextmenu'] = ' data-contextmenu="' . _htmlentities($ph['contextmenu']) . '"';
234
            }
235
236
            if ($_SESSION['tree_show_only_folders']) {
237
                if ($row['parent'] == 0) {
238
                    $node .= $modx->parseText($tpl, $ph);
239
                } else {
240
                    $node .= '';
241
                }
242
            } else {
243
                $node .= $modx->parseText($tpl, $ph);
244
            }
245
246
        } else {
247
            $ph['icon_folder_open'] = $_style['tree_folderopen_new'];
248
            $ph['icon_folder_close'] = $_style['tree_folder_new'];
249
250
            if ($_SESSION['tree_show_only_folders']) {
251
                $tpl = getTplFolderNodeNotChildren();
252
                $checkFolders = checkIsFolder($row['id'], 1) ? 1 : 0; // folders
253
                $checkDocs = checkIsFolder($row['id'], 0) ? 1 : 0; // no folders
254
                $ph['tree_page_click'] = 3;
255
256
                // expandAll: two type for partial expansion
257
                if ($expandAll == 1 || ($expandAll == 2 && in_array($row['id'], $opened))) {
258
                    if ($expandAll == 1) {
259
                        $opened2[] = $row['id'];
260
                    }
261
                    $ph['icon'] = $ph['icon_folder_open'];
262
                    $ph['icon_node_toggle'] = $ph['tree_minusnode'];
263
                    $ph['node_toggle'] = 1;
264
                    $ph['subMenuState'] = ' open';
265
266
                    if (($checkDocs && !$checkFolders) || (!$checkDocs && !$checkFolders)) {
267
                        $ph['showChildren'] = 1;
268
                        $ph['icon_node_toggle'] = '';
269
                        $ph['icon'] = $ph['icon_folder_close'];
270
                    } elseif (!$checkDocs && $checkFolders) {
271
                        $ph['showChildren'] = 0;
272
                        $ph['openFolder'] = 2;
273
                    } else {
274
                        $ph['openFolder'] = 2;
275
                    }
276
277
                    // invoke OnManagerNodePrerender event
278
                    $prenode = $modx->invokeEvent("OnManagerNodePrerender", array(
279
                        'ph' => $ph,
280
                        'opened' => '1'
281
                    ));
282 View Code Duplication
                    if (is_array($prenode)) {
283
                        $phnew = array();
284
                        foreach ($prenode as $pnode) {
285
                            $phnew = array_merge($phnew, unserialize($pnode));
286
                        }
287
                        $ph = (count($phnew) > 0) ? $phnew : $ph;
288
                    }
289
290 View Code Duplication
                    if ($ph['contextmenu']) {
291
                        $ph['contextmenu'] = ' data-contextmenu="' . _htmlentities($ph['contextmenu']) . '"';
292
                    }
293
294
                    $node .= $modx->parseText($tpl, $ph);
295
                    if ($checkFolders) {
296
                        $node .= makeHTML($indent + 1, $row['id'], $expandAll, $hereid);
297
                    }
298
                    $node .= '</div></div>';
299
                } else {
300
                    $closed2[] = $row['id'];
301
                    $ph['icon'] = $ph['icon_folder_close'];
302
                    $ph['icon_node_toggle'] = $ph['tree_plusnode'];
303
                    $ph['node_toggle'] = 0;
304
305
                    if (($checkDocs && !$checkFolders) || (!$checkDocs && !$checkFolders)) {
306
                        $ph['showChildren'] = 1;
307
                        $ph['icon_node_toggle'] = '';
308
                    } elseif (!$checkDocs && $checkFolders) {
309
                        $ph['showChildren'] = 0;
310
                        $ph['openFolder'] = 2;
311
                    } else {
312
                        $ph['openFolder'] = 2;
313
                    }
314
315
                    // invoke OnManagerNodePrerender event
316
                    $prenode = $modx->invokeEvent("OnManagerNodePrerender", array(
317
                        'ph' => $ph,
318
                        'opened' => '0'
319
                    ));
320 View Code Duplication
                    if (is_array($prenode)) {
321
                        $phnew = array();
322
                        foreach ($prenode as $pnode) {
323
                            $phnew = array_merge($phnew, unserialize($pnode));
324
                        }
325
                        $ph = (count($phnew) > 0) ? $phnew : $ph;
326
                    }
327
328 View Code Duplication
                    if ($ph['contextmenu']) {
329
                        $ph['contextmenu'] = ' data-contextmenu="' . _htmlentities($ph['contextmenu']) . '"';
330
                    }
331
332
                    $node .= $modx->parseText($tpl, $ph);
333
                    $node .= '</div></div>';
334
                }
335
            } else {
336
                $tpl = getTplFolderNode();
337
                // expandAll: two type for partial expansion
338
                if ($expandAll == 1 || ($expandAll == 2 && in_array($row['id'], $opened))) {
339
                    if ($expandAll == 1) {
340
                        $opened2[] = $row['id'];
341
                    }
342
                    $ph['icon'] = $ph['icon_folder_open'];
343
                    $ph['icon_node_toggle'] = $ph['tree_minusnode'];
344
                    $ph['node_toggle'] = 1;
345
                    $ph['subMenuState'] = ' open';
346
347 View Code Duplication
                    if ($ph['donthit'] == 1) {
348
                        $ph['tree_page_click'] = 3;
349
                        $ph['icon_node_toggle'] = '';
350
                        $ph['icon'] = $ph['icon_folder_close'];
351
                        $ph['showChildren'] = 0;
352
                    }
353
354
                    // invoke OnManagerNodePrerender event
355
                    $prenode = $modx->invokeEvent("OnManagerNodePrerender", array(
356
                        'ph' => $ph,
357
                        'opened' => '1'
358
                    ));
359
                    if (is_array($prenode)) {
360
                        $phnew = array();
361
                        foreach ($prenode as $pnode) {
362
                            $phnew = array_merge($phnew, unserialize($pnode));
363
                        }
364
                        $ph = (count($phnew) > 0) ? $phnew : $ph;
365
                        if ($ph['showChildren'] == 0) {
366
                            unset($opened2[$row['id']]);
367
                            $ph['node_toggle'] = 0;
368
                            $ph['subMenuState'] = '';
369
                        }
370
                    }
371
372 View Code Duplication
                    if ($ph['showChildren'] == 0) {
373
                        $ph['icon_node_toggle'] = '';
374
                        $ph['donthit'] = 1;
375
                        $ph['icon'] = $ph['icon_folder_close'];
376
                        $tpl = getTplFolderNodeNotChildren();
377
                    }
378
379 View Code Duplication
                    if ($ph['contextmenu']) {
380
                        $ph['contextmenu'] = ' data-contextmenu="' . _htmlentities($ph['contextmenu']) . '"';
381
                    }
382
383
                    $node .= $modx->parseText($tpl, $ph);
384
                    if ($ph['donthit'] == 0) {
385
                        $node .= makeHTML($indent + 1, $row['id'], $expandAll, $hereid);
386
                    }
387
                    $node .= '</div></div>';
388
                } else {
389
                    $closed2[] = $row['id'];
390
                    $ph['icon'] = $ph['icon_folder_close'];
391
                    $ph['icon_node_toggle'] = $ph['tree_plusnode'];
392
                    $ph['node_toggle'] = 0;
393
394 View Code Duplication
                    if ($ph['donthit'] == 1) {
395
                        $ph['tree_page_click'] = 3;
396
                        $ph['icon_node_toggle'] = '';
397
                        $ph['icon'] = $ph['icon_folder_close'];
398
                        $ph['showChildren'] = 0;
399
                    }
400
401
                    // invoke OnManagerNodePrerender event
402
                    $prenode = $modx->invokeEvent("OnManagerNodePrerender", array(
403
                        'ph' => $ph,
404
                        'opened' => '0'
405
                    ));
406
407 View Code Duplication
                    if (is_array($prenode)) {
408
                        $phnew = array();
409
                        foreach ($prenode as $pnode) {
410
                            $phnew = array_merge($phnew, unserialize($pnode));
411
                        }
412
                        $ph = (count($phnew) > 0) ? $phnew : $ph;
413
                    }
414
415 View Code Duplication
                    if ($ph['showChildren'] == 0) {
416
                        $ph['icon_node_toggle'] = '';
417
                        $ph['donthit'] = 1;
418
                        $ph['icon'] = $ph['icon_folder_close'];
419
                        $tpl = getTplFolderNodeNotChildren();
420
                    }
421
422 View Code Duplication
                    if ($ph['contextmenu']) {
423
                        $ph['contextmenu'] = ' data-contextmenu="' . _htmlentities($ph['contextmenu']) . '"';
424
                    }
425
426
                    $node .= $modx->parseText($tpl, $ph);
427
                    $node .= '</div></div>';
428
                }
429
            }
430
        }
431
432
        // invoke OnManagerNodeRender event
433
        $data['node'] = $node;
434
        $evtOut = $modx->invokeEvent('OnManagerNodeRender', $data);
435
        if (is_array($evtOut)) {
436
            $evtOut = implode("\n", $evtOut);
437
        }
438
        if ($evtOut != '') {
439
            $node = trim($evtOut);
440
        }
441
442
        $output .= $node;
443
    }
444
445
    return $output;
446
}
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
function getNodeTitle($nodeNameSource, $row)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
477
{
478
    global $modx;
479
480
    switch ($nodeNameSource) {
481
        case 'menutitle':
482
            $nodetitle = $row['menutitle'] ? $row['menutitle'] : $row['pagetitle'];
483
            break;
484
        case 'alias':
485
            $nodetitle = $row['alias'] ? $row['alias'] : $row['id'];
486
            if (strpos($row['alias'], '.') === false) {
487
                if ($row['isfolder'] != 1 || $modx->config['make_folders'] != 1) {
488
                    $nodetitle .= $modx->config['friendly_url_suffix'];
489
                }
490
            }
491
            $nodetitle = $modx->config['friendly_url_prefix'] . $nodetitle;
492
            break;
493
        case 'pagetitle':
494
            $nodetitle = $row['pagetitle'];
495
            break;
496
        case 'longtitle':
497
            $nodetitle = $row['longtitle'] ? $row['longtitle'] : $row['pagetitle'];
498
            break;
499
        case 'createdon':
500
        case 'editedon':
501
        case 'publishedon':
502
        case 'pub_date':
503
        case 'unpub_date':
504
            $doc = $modx->getDocumentObject('id', $row['id']);
505
            $date = $doc[$nodeNameSource];
506
            if (!empty($date)) {
507
                $nodetitle = $modx->toDateFormat($date);
508
            } else {
509
                $nodetitle = '- - -';
510
            }
511
            break;
512
        default:
513
            $nodetitle = $row['pagetitle'];
514
    }
515
    $nodetitle = $modx->htmlspecialchars(str_replace(array(
516
        "\r\n",
517
        "\n",
518
        "\r"
519
    ), ' ', $nodetitle), ENT_COMPAT);
520
    return $nodetitle;
521
}
522
523
function isDateNode($nodeNameSource)
524
{
525
    switch ($nodeNameSource) {
526
        case 'createdon':
527
        case 'editedon':
528
        case 'publishedon':
529
        case 'pub_date':
530
        case 'unpub_date':
531
            return true;
532
        default:
533
            return false;
534
    }
535
}
536
537
function checkIsFolder($parent = 0, $isfolder = 1)
538
{
539
    global $modx;
540
541
    return (int)$modx->db->getValue($modx->db->query('SELECT count(*) FROM ' . $modx->getFullTableName('site_content') . ' WHERE parent=' . $parent . ' AND isfolder=' . $isfolder . ' '));
542
}
543
544
function _htmlentities($array)
545
{
546
    global $modx;
547
548
    $array = json_encode($array, JSON_UNESCAPED_UNICODE);
0 ignored issues
show
Unused Code introduced by
The call to json_encode() has too many arguments starting with JSON_UNESCAPED_UNICODE.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
549
    $array = htmlentities($array, ENT_COMPAT, $modx->config['modx_charset']);
550
551
    return $array;
552
}
553
554
function getTplSingleNode()
555
{
556
    return '<div id="node[+id+]"><a class="[+treeNodeClass+]"
557
        onclick="modx.tree.treeAction(event,[+id+]);"
558
        oncontextmenu="modx.tree.showPopup(event,[+id+],\'[+nodetitle_esc+]\');"
559
        data-id="[+id+]"
560
        data-title-esc="[+nodetitle_esc+]"
561
        data-published="[+published+]"
562
        data-deleted="[+deleted+]"
563
        data-isfolder="[+isfolder+]"
564
        data-href="[+url+]"
565
        data-private="[+isPrivate+]"
566
        data-roles="[+roles+]"
567
        data-level="[+level+]"
568
        data-treepageclick="[+tree_page_click+]"
569
        [+contextmenu+]
570
        >[+spacer+]<span
571
        class="icon"
572
        onclick="modx.tree.showPopup(event,[+id+],\'[+nodetitle_esc+]\');return false;"
573
        oncontextmenu="this.onclick(event);return false;"
574
        >[+icon+]</span>[+lockedByUser+]<span
575
        class="title"
576
        title="[+title+]">[+nodetitleDisplay+][+weblinkDisplay+]</span>[+pageIdDisplay+]</a></div>';
577
}
578
579
function getTplFolderNode()
580
{
581
    return '<div id="node[+id+]"><a class="[+treeNodeClass+]"
582
        onclick="modx.tree.treeAction(event,[+id+]);"
583
        oncontextmenu="modx.tree.showPopup(event,[+id+],\'[+nodetitle_esc+]\');"
584
        data-id="[+id+]"
585
        data-title-esc="[+nodetitle_esc+]"
586
        data-published="[+published+]"
587
        data-deleted="[+deleted+]"
588
        data-isfolder="[+isfolder+]"
589
        data-href="[+url+]"
590
        data-private="[+isPrivate+]"
591
        data-roles="[+roles+]"
592
        data-level="[+level+]"
593
        data-icon-expanded="[+tree_plusnode+]"
594
        data-icon-collapsed="[+tree_minusnode+]"
595
        data-icon-folder-open="[+icon_folder_open+]"
596
        data-icon-folder-close="[+icon_folder_close+]"
597
        data-treepageclick="[+tree_page_click+]"
598
        data-showchildren="[+showChildren+]"
599
        data-openfolder="[+openFolder+]"
600
        data-indent="[+indent+]"
601
        data-expandall="[+expandAll+]"
602
        [+contextmenu+]
603
        >[+spacer+]<span
604
        class="toggle"
605
        onclick="modx.tree.toggleNode(event, [+id+]);"
606
        oncontextmenu="this.onclick(event);"
607
        >[+icon_node_toggle+]</span><span
608
        class="icon"
609
        onclick="modx.tree.showPopup(event,[+id+],\'[+nodetitle_esc+]\');return false;"
610
        oncontextmenu="this.onclick(event);return false;"
611
        >[+icon+]</span>[+lockedByUser+]<span
612
        class="title"
613
        title="[+title+]">[+nodetitleDisplay+][+weblinkDisplay+]</span>[+pageIdDisplay+]</a><div>';
614
}
615
616
function getTplFolderNodeNotChildren()
617
{
618
    return '<div id="node[+id+]"><a class="[+treeNodeClass+]"
619
        onclick="modx.tree.treeAction(event,[+id+]);"
620
        oncontextmenu="modx.tree.showPopup(event,[+id+],\'[+nodetitle_esc+]\');"
621
        data-id="[+id+]"
622
        data-title-esc="[+nodetitle_esc+]"
623
        data-published="[+published+]"
624
        data-deleted="[+deleted+]"
625
        data-isfolder="[+isfolder+]"
626
        data-href="[+url+]"
627
        data-private="[+isPrivate+]"
628
        data-roles="[+roles+]"
629
        data-level="[+level+]"
630
        data-icon-expanded="[+tree_plusnode+]"
631
        data-icon-collapsed="[+tree_minusnode+]"
632
        data-icon-folder-open="[+icon_folder_open+]"
633
        data-icon-folder-close="[+icon_folder_close+]"
634
        data-treepageclick="[+tree_page_click+]"
635
        data-showchildren="[+showChildren+]"
636
        data-openfolder="[+openFolder+]"
637
        data-indent="[+indent+]"
638
        data-expandall="[+expandAll+]"
639
        [+contextmenu+]
640
        >[+spacer+]<span
641
        class="icon"
642
        onclick="modx.tree.showPopup(event,[+id+],\'[+nodetitle_esc+]\');return false;"
643
        oncontextmenu="this.onclick(event);return false;"
644
        >[+icon+]</span>[+lockedByUser+]<span
645
        class="title"
646
        title="[+title+]">[+nodetitleDisplay+][+weblinkDisplay+]</span>[+pageIdDisplay+]</a><div>';
647
}
648