1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Pages function library |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Prepare the add/edit form variables |
8
|
|
|
* |
9
|
|
|
* @param ElggObject $page |
10
|
|
|
* @return array |
11
|
|
|
*/ |
12
|
|
|
function pages_prepare_form_vars($page = null, $parent_guid = 0) { |
13
|
|
|
|
14
|
|
|
// input names => defaults |
15
|
|
|
$values = array( |
16
|
|
|
'title' => '', |
17
|
|
|
'description' => '', |
18
|
|
|
'access_id' => ACCESS_DEFAULT, |
19
|
|
|
'write_access_id' => ACCESS_DEFAULT, |
20
|
|
|
'tags' => '', |
21
|
|
|
'container_guid' => elgg_get_page_owner_guid(), |
22
|
|
|
'guid' => null, |
23
|
|
|
'entity' => $page, |
24
|
|
|
'parent_guid' => $parent_guid, |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
if ($page) { |
28
|
|
|
foreach (array_keys($values) as $field) { |
29
|
|
|
if (isset($page->$field)) { |
30
|
|
|
$values[$field] = $page->$field; |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
if (elgg_is_sticky_form('page')) { |
36
|
|
|
$sticky_values = elgg_get_sticky_values('page'); |
37
|
|
|
foreach ($sticky_values as $key => $value) { |
38
|
|
|
$values[$key] = $value; |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
elgg_clear_sticky_form('page'); |
43
|
|
|
|
44
|
|
|
return $values; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Recurses the page tree and adds the breadcrumbs for all ancestors |
49
|
|
|
* |
50
|
|
|
* @param ElggObject $page Page entity |
51
|
|
|
*/ |
52
|
|
View Code Duplication |
function pages_prepare_parent_breadcrumbs($page) { |
53
|
|
|
if ($page && $page->parent_guid) { |
54
|
|
|
$parents = array(); |
55
|
|
|
$parent = get_entity($page->parent_guid); |
56
|
|
|
while ($parent) { |
57
|
|
|
array_push($parents, $parent); |
58
|
|
|
$parent = get_entity($parent->parent_guid); |
59
|
|
|
} |
60
|
|
|
while ($parents) { |
|
|
|
|
61
|
|
|
$parent = array_pop($parents); |
62
|
|
|
elgg_push_breadcrumb($parent->title, $parent->getURL()); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Register the navigation menu |
69
|
|
|
* |
70
|
|
|
* @param ElggEntity $container Container entity for the pages |
71
|
|
|
*/ |
72
|
|
|
function pages_register_navigation_tree($container) { |
73
|
|
|
if (!$container) { |
74
|
|
|
return; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$top_pages = elgg_get_entities(array( |
78
|
|
|
'type' => 'object', |
79
|
|
|
'subtypes' => array('page_top', 'etherpad'), |
80
|
|
|
'container_guid' => $container->getGUID(), |
81
|
|
|
)); |
82
|
|
|
|
83
|
|
View Code Duplication |
foreach ($top_pages as $page) { |
84
|
|
|
elgg_register_menu_item('pages_nav', array( |
85
|
|
|
'name' => $page->getGUID(), |
86
|
|
|
'text' => $page->title, |
87
|
|
|
'href' => $page->getURL(), |
88
|
|
|
)); |
89
|
|
|
|
90
|
|
|
$stack = array(); |
91
|
|
|
array_push($stack, $page); |
92
|
|
|
while (count($stack) > 0) { |
93
|
|
|
$parent = array_pop($stack); |
94
|
|
|
$children = elgg_get_entities_from_metadata(array( |
95
|
|
|
'type' => 'object', |
96
|
|
|
'subtypes' => array('page', 'subpad'), |
97
|
|
|
'metadata_name' => 'parent_guid', |
98
|
|
|
'metadata_value' => $parent->getGUID(), |
99
|
|
|
)); |
100
|
|
|
|
101
|
|
|
foreach ($children as $child) { |
102
|
|
|
elgg_register_menu_item('pages_nav', array( |
103
|
|
|
'name' => $child->getGUID(), |
104
|
|
|
'text' => $child->title, |
105
|
|
|
'href' => $child->getURL(), |
106
|
|
|
'parent_name' => $parent->getGUID(), |
107
|
|
|
)); |
108
|
|
|
array_push($stack, $child); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.