1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Elgg page owner library |
4
|
|
|
* Contains functions for managing page ownership and context |
5
|
|
|
* |
6
|
|
|
* @package Elgg.Core |
7
|
|
|
* @subpackage PageOwner |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Gets the guid of the entity that owns the current page. |
12
|
|
|
* |
13
|
|
|
* @see default_page_owner_handler() Used to guess the page owner if it's not been set. |
14
|
|
|
* |
15
|
|
|
* @param int $guid Optional parameter used by elgg_set_page_owner_guid(). |
16
|
|
|
* |
17
|
|
|
* @return int The current page owner guid (0 if none). |
18
|
|
|
* @since 1.8.0 |
19
|
|
|
*/ |
20
|
|
|
function elgg_get_page_owner_guid($guid = 0) { |
21
|
|
|
$page_owner = _elgg_services()->pageOwner; |
22
|
|
|
if ($guid === 0) { |
23
|
97 |
|
return $page_owner->getPageOwnerGuid(); |
24
|
|
|
} |
25
|
97 |
|
|
26
|
1 |
|
elgg_deprecated_notice(__METHOD__ . ' should not be used to set the page owner. Use elgg_set_page_owner_guid().', '3.1'); |
27
|
1 |
|
|
28
|
|
|
// calling function for BC |
29
|
|
|
elgg_set_page_owner_guid($guid); |
30
|
97 |
|
|
31
|
24 |
|
return $page_owner->getPageOwnerGuid(); |
32
|
|
|
} |
33
|
|
|
|
34
|
97 |
|
/** |
35
|
88 |
|
* Gets the owner entity for the current page. |
36
|
|
|
* |
37
|
|
|
* @return \ElggEntity|false The current page owner or false if none. |
38
|
9 |
|
* |
39
|
9 |
|
* @since 1.8.0 |
40
|
2 |
|
*/ |
41
|
2 |
|
function elgg_get_page_owner_entity() { |
42
|
|
|
return _elgg_services()->pageOwner->getPageOwnerEntity(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Set the guid of the entity that owns this page |
47
|
|
|
* |
48
|
|
|
* @param int $guid The guid of the page owner |
49
|
9 |
|
* @return void |
50
|
|
|
* @since 1.8.0 |
51
|
9 |
|
*/ |
52
|
|
|
function elgg_set_page_owner_guid($guid) { |
53
|
|
|
$page_owner = _elgg_services()->pageOwner; |
54
|
|
|
|
55
|
9 |
|
if ((int) $guid >= 0) { |
56
|
|
|
$page_owner->setPageOwnerGuid((int) $guid); |
57
|
|
|
return; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
// removes page owner |
61
|
|
|
$page_owner->setPageOwnerGuid(0); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Sets the page context |
66
|
76 |
|
* |
67
|
76 |
|
* Views can modify their output based on the local context. You may want to |
68
|
34 |
|
* display a list of blogs on a blog page or in a small widget. The rendered |
69
|
|
|
* output could be different for those two contexts ('blog' vs 'widget'). |
70
|
|
|
* |
71
|
42 |
|
* Pages that pass through the page handling system set the context to the |
72
|
|
|
* first string after the root url. Example: http://example.org/elgg/bookmarks/ |
73
|
|
|
* results in the initial context being set to 'bookmarks'. |
74
|
|
|
* |
75
|
|
|
* The context is a stack so that for a widget on a profile, the context stack |
76
|
|
|
* may contain first 'profile' and then 'widget'. |
77
|
|
|
* |
78
|
|
|
* If no context was been set, the default context returned is 'main'. |
79
|
|
|
* |
80
|
|
|
* @warning The context is not available until the page_handler runs (after |
81
|
|
|
* the 'init, system' event processing has completed). |
82
|
25 |
|
* |
83
|
25 |
|
* @param string $context The context of the page |
84
|
|
|
* @return bool |
85
|
|
|
* @since 1.8.0 |
86
|
|
|
*/ |
87
|
|
|
function elgg_set_context($context) { |
88
|
|
|
return _elgg_services()->request->getContextStack()->set($context); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get the current context. |
93
|
|
|
* |
94
|
|
|
* Since context is a stack, this is equivalent to a peek. |
95
|
|
|
* |
96
|
|
|
* @return string|null |
97
|
|
|
* @since 1.8.0 |
98
|
|
|
*/ |
99
|
|
|
function elgg_get_context() { |
100
|
|
|
return _elgg_services()->request->getContextStack()->peek(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Push a context onto the top of the stack |
105
|
|
|
* |
106
|
|
|
* @param string $context The context string to add to the context stack |
107
|
|
|
* @return void |
108
|
|
|
* @since 1.8.0 |
109
|
|
|
*/ |
110
|
|
|
function elgg_push_context($context) { |
111
|
|
|
_elgg_services()->request->getContextStack()->push($context); |
112
|
4 |
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Removes and returns the top context string from the stack |
116
|
4 |
|
* |
117
|
|
|
* @return string|null |
118
|
4 |
|
* @since 1.8.0 |
119
|
4 |
|
*/ |
120
|
|
|
function elgg_pop_context() { |
121
|
|
|
return _elgg_services()->request->getContextStack()->pop(); |
122
|
|
|
} |
123
|
|
|
|
124
|
4 |
|
/** |
125
|
4 |
|
* Check if this context exists anywhere in the stack |
126
|
|
|
* |
127
|
|
|
* This is useful for situations with more than one element in the stack. For |
128
|
|
|
* example, a widget has a context of 'widget'. If a widget view needs to render |
129
|
|
|
* itself differently based on being on the dashboard or profile pages, it |
130
|
|
|
* can check the stack. |
131
|
|
|
* |
132
|
|
|
* @param string $context The context string to check for |
133
|
4 |
|
* @return bool |
134
|
4 |
|
* @since 1.8.0 |
135
|
|
|
*/ |
136
|
|
|
function elgg_in_context($context) { |
137
|
|
|
return _elgg_services()->request->getContextStack()->contains($context); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Get the entire context stack (e.g. for backing it up) |
142
|
|
|
* |
143
|
|
|
* @return string[] |
144
|
|
|
* @since 1.11 |
145
|
|
|
*/ |
146
|
|
|
function elgg_get_context_stack() { |
147
|
|
|
return _elgg_services()->request->getContextStack()->toArray(); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Set the entire context stack |
152
|
|
|
* |
153
|
|
|
* @param string[] $stack All contexts to be placed on the stack |
154
|
|
|
* @return void |
155
|
|
|
* @since 1.11 |
156
|
|
|
*/ |
157
|
|
|
function elgg_set_context_stack(array $stack) { |
158
|
|
|
_elgg_services()->request->getContextStack()->fromArray($stack); |
159
|
|
|
} |
160
|
|
|
|