-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetLinkedResources.snippet.php
75 lines (66 loc) · 1.66 KB
/
getLinkedResources.snippet.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
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$docId = $modx->getOption('docId', $scriptProperties, $modx->resource->get('id'));
$tpl = $modx->getOption('tpl', $scriptProperties, '');
if (!is_numeric($docId) && empty($docId)) {
return false;
}
$currentResource = $modx->getObject('modResource', $docId);
if ($currentResource->get('class_key') == 'modSymLink') {
//is symlink
$docId = $currentResource->get('content');
if (!is_numeric($docId) && empty($docId)) {
return false;
}
}
$modDocument = $modx->getObject('modResource', $docId);
$symlinkObjs = $modx->getCollection('modResource', array('content' => $docId));
if (count($symlinkObjs) != 0) {
if ($tpl != '' ) {
$output .= $modx->getChunk(
$tpl,
array(
'id' => $modDocument->get('id'),
'parent' => $modDocument->get('parent'),
'pagetitle' => $modDocument->get('pagetitle'),
'alias' => $modDocument->get('alias')
)
);
}
// loop tru each symlink
foreach($symlinkObjs as $page) {
if ($tpl != '') {
$output .= $modx->getChunk(
$tpl,
array(
'id' => $page->get('id'),
'parent' => $page->get('parent'),
'pagetitle' => $page->get('pagetitle'),
'alias' => $page->get('alias')
)
);
}
else {
$output[] = intval($page->get('id'));
}
}
} else {
// no symlinks lets return the current resource
if ($tpl != '' ) {
$output .= $modx->getChunk(
$tpl,
array(
'id' => $docId,
'parent' => $currentResource->get('parent'),
'pagetitle' => $currentResource->get('pagetitle'),
'alias' => $currentResource->get('alias')
)
);
}
}
if (is_array($output)) {
$output[] = $docId;
$output = implode(',', $output);
}
return $output;