1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Return the full URL of the current page. |
5
|
|
|
* |
6
|
|
|
* @return string The URL |
7
|
|
|
* @todo Combine / replace with current_page_url(). full_url() is based on the |
8
|
|
|
* request only while current_page_url() uses the configured site url. |
9
|
|
|
* @deprecated 1.9 Use current_page_url() |
10
|
|
|
*/ |
11
|
|
|
function full_url() { |
12
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use current_page_url()', 1.9); |
13
|
|
|
$request = _elgg_services()->request; |
14
|
|
|
$url = $request->getSchemeAndHttpHost(); |
15
|
|
|
|
16
|
|
|
// This is here to prevent XSS in poorly written browsers used by 80% of the population. |
17
|
|
|
// svn commit [5813]: https://github.com/Elgg/Elgg/commit/0c947e80f512cb0a482b1864fd0a6965c8a0cd4a |
18
|
|
|
// @todo encoding like this should occur when inserting into web page, not here |
19
|
|
|
$quotes = array('\'', '"'); |
20
|
|
|
$encoded = array('%27', '%22'); |
21
|
|
|
return $url . str_replace($quotes, $encoded, $request->getRequestUri()); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Sets the URL handler for a particular entity type and subtype |
26
|
|
|
* |
27
|
|
|
* @param string $entity_type The entity type |
28
|
|
|
* @param string $entity_subtype The entity subtype |
29
|
|
|
* @param string $function_name The function to register |
30
|
|
|
* |
31
|
|
|
* @return bool Depending on success |
32
|
|
|
* @see get_entity_url() |
33
|
|
|
* @see \ElggEntity::getURL() |
34
|
|
|
* @since 1.8.0 |
35
|
|
|
* @deprecated 1.9.0 Use the plugin hook in \ElggEntity::getURL() |
36
|
|
|
*/ |
37
|
|
View Code Duplication |
function elgg_register_entity_url_handler($entity_type, $entity_subtype, $function_name) { |
|
|
|
|
38
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use the plugin hook in \ElggEntity::getURL()', 1.9); |
39
|
|
|
global $CONFIG; |
40
|
|
|
|
41
|
|
|
if (!is_callable($function_name, true)) { |
42
|
|
|
return false; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if (!isset($CONFIG->entity_url_handler)) { |
46
|
|
|
$CONFIG->entity_url_handler = array(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
if (!isset($CONFIG->entity_url_handler[$entity_type])) { |
50
|
|
|
$CONFIG->entity_url_handler[$entity_type] = array(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$CONFIG->entity_url_handler[$entity_type][$entity_subtype] = $function_name; |
54
|
|
|
|
55
|
|
|
return true; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Sets the URL handler for a particular relationship type |
60
|
|
|
* |
61
|
|
|
* @param string $relationship_type The relationship type. |
62
|
|
|
* @param string $function_name The function to register |
63
|
|
|
* |
64
|
|
|
* @return bool Depending on success |
65
|
|
|
* @deprecated 1.9 Use the plugin hook in \ElggRelationship::getURL() |
66
|
|
|
*/ |
67
|
|
|
function elgg_register_relationship_url_handler($relationship_type, $function_name) { |
68
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use the plugin hook in getURL()', 1.9); |
69
|
|
|
global $CONFIG; |
70
|
|
|
|
71
|
|
|
if (!is_callable($function_name, true)) { |
72
|
|
|
return false; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
if (!isset($CONFIG->relationship_url_handler)) { |
76
|
|
|
$CONFIG->relationship_url_handler = array(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$CONFIG->relationship_url_handler[$relationship_type] = $function_name; |
80
|
|
|
|
81
|
|
|
return true; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get the url for a given relationship. |
86
|
|
|
* |
87
|
|
|
* @param int $id Relationship ID |
88
|
|
|
* |
89
|
|
|
* @return string |
90
|
|
|
* @deprecated 1.9 Use \ElggRelationship::getURL() |
91
|
|
|
*/ |
92
|
|
|
function get_relationship_url($id) { |
93
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggRelationship::getURL()', 1.9); |
94
|
|
|
global $CONFIG; |
95
|
|
|
|
96
|
|
|
$id = (int)$id; |
97
|
|
|
|
98
|
|
|
if ($relationship = get_relationship($id)) { |
99
|
|
|
$view = elgg_get_viewtype(); |
100
|
|
|
|
101
|
|
|
$guid = $relationship->guid_one; |
102
|
|
|
$type = $relationship->relationship; |
103
|
|
|
|
104
|
|
|
$url = ""; |
105
|
|
|
|
106
|
|
|
$function = ""; |
107
|
|
|
if (isset($CONFIG->relationship_url_handler[$type])) { |
108
|
|
|
$function = $CONFIG->relationship_url_handler[$type]; |
109
|
|
|
} |
110
|
|
|
if (isset($CONFIG->relationship_url_handler['all'])) { |
111
|
|
|
$function = $CONFIG->relationship_url_handler['all']; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
if (is_callable($function)) { |
115
|
|
|
$url = call_user_func($function, $relationship); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
if ($url == "") { |
119
|
|
|
$nameid = $relationship->id; |
120
|
|
|
|
121
|
|
|
$url = elgg_get_site_url() . "export/$view/$guid/relationship/$nameid/"; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
return $url; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
return false; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Sets the URL handler for a particular extender type and name. |
132
|
|
|
* It is recommended that you do not call this directly, instead use |
133
|
|
|
* one of the wrapper functions such as elgg_register_annotation_url_handler(). |
134
|
|
|
* |
135
|
|
|
* @param string $extender_type Extender type ('annotation', 'metadata') |
136
|
|
|
* @param string $extender_name The name of the extender |
137
|
|
|
* @param string $function_name The function to register |
138
|
|
|
* |
139
|
|
|
* @return bool |
140
|
|
|
* @deprecated 1.9 Use plugin hook in \ElggExtender::getURL() |
141
|
|
|
*/ |
142
|
|
View Code Duplication |
function elgg_register_extender_url_handler($extender_type, $extender_name, $function_name) { |
|
|
|
|
143
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use the plugin hook in getURL()', 1.9, 2); |
144
|
|
|
|
145
|
|
|
global $CONFIG; |
146
|
|
|
|
147
|
|
|
if (!is_callable($function_name, true)) { |
148
|
|
|
return false; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
if (!isset($CONFIG->extender_url_handler)) { |
152
|
|
|
$CONFIG->extender_url_handler = array(); |
153
|
|
|
} |
154
|
|
|
if (!isset($CONFIG->extender_url_handler[$extender_type])) { |
155
|
|
|
$CONFIG->extender_url_handler[$extender_type] = array(); |
156
|
|
|
} |
157
|
|
|
$CONFIG->extender_url_handler[$extender_type][$extender_name] = $function_name; |
158
|
|
|
|
159
|
|
|
return true; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Get the URL of a given elgg extender. |
164
|
|
|
* Used by get_annotation_url and get_metadata_url. |
165
|
|
|
* |
166
|
|
|
* @param \ElggExtender $extender An extender object |
167
|
|
|
* |
168
|
|
|
* @return string |
169
|
|
|
* @deprecated 1.9 Use method getURL() |
170
|
|
|
*/ |
171
|
|
|
function get_extender_url(\ElggExtender $extender) { |
172
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggExtender::getURL()', 1.9); |
173
|
|
|
global $CONFIG; |
174
|
|
|
|
175
|
|
|
$view = elgg_get_viewtype(); |
176
|
|
|
|
177
|
|
|
$guid = $extender->entity_guid; |
178
|
|
|
$type = $extender->type; |
179
|
|
|
|
180
|
|
|
$url = ""; |
181
|
|
|
|
182
|
|
|
$function = ""; |
183
|
|
|
if (isset($CONFIG->extender_url_handler[$type][$extender->name])) { |
184
|
|
|
$function = $CONFIG->extender_url_handler[$type][$extender->name]; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
View Code Duplication |
if (isset($CONFIG->extender_url_handler[$type]['all'])) { |
188
|
|
|
$function = $CONFIG->extender_url_handler[$type]['all']; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
View Code Duplication |
if (isset($CONFIG->extender_url_handler['all']['all'])) { |
192
|
|
|
$function = $CONFIG->extender_url_handler['all']['all']; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
if (is_callable($function)) { |
196
|
|
|
$url = call_user_func($function, $extender); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
if ($url == "") { |
200
|
|
|
$nameid = $extender->id; |
201
|
|
|
if ($type == 'volatile') { |
202
|
|
|
$nameid = $extender->name; |
203
|
|
|
} |
204
|
|
|
$url = "export/$view/$guid/$type/$nameid/"; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
return elgg_normalize_url($url); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Get the URL for this annotation. |
212
|
|
|
* |
213
|
|
|
* @param int $id Annotation id |
214
|
|
|
* |
215
|
|
|
* @return string|bool False on failure |
216
|
|
|
* @deprecated 1.9 Use method getURL() on annotation object |
217
|
|
|
*/ |
218
|
|
|
function get_annotation_url($id) { |
219
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggAnnotation::getURL()', 1.9); |
220
|
|
|
$id = (int)$id; |
221
|
|
|
|
222
|
|
|
if ($extender = elgg_get_annotation_from_id($id)) { |
223
|
|
|
return get_extender_url($extender); |
|
|
|
|
224
|
|
|
} |
225
|
|
|
return false; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Register a metadata url handler. |
230
|
|
|
* |
231
|
|
|
* @param string $extender_name The name, default 'all'. |
232
|
|
|
* @param string $function The function name. |
233
|
|
|
* |
234
|
|
|
* @return bool |
235
|
|
|
* @deprecated 1.9 Use the plugin hook in \ElggExtender::getURL() |
236
|
|
|
*/ |
237
|
|
|
function elgg_register_metadata_url_handler($extender_name, $function) { |
238
|
|
|
// deprecation notice comes from elgg_register_extender_url_handler() |
239
|
|
|
return elgg_register_extender_url_handler('metadata', $extender_name, $function); |
|
|
|
|
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Register an annotation url handler. |
244
|
|
|
* |
245
|
|
|
* @param string $extender_name The name, default 'all'. |
246
|
|
|
* @param string $function_name The function. |
247
|
|
|
* |
248
|
|
|
* @return string |
249
|
|
|
* @deprecated 1.9 Use the plugin hook in \ElggExtender::getURL() |
250
|
|
|
*/ |
251
|
|
|
function elgg_register_annotation_url_handler($extender_name = "all", $function_name) { |
252
|
|
|
// deprecation notice comes from elgg_register_extender_url_handler() |
253
|
|
|
return elgg_register_extender_url_handler('annotation', $extender_name, $function_name); |
|
|
|
|
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* Return a list of this group's members. |
258
|
|
|
* |
259
|
|
|
* @param int $group_guid The ID of the container/group. |
260
|
|
|
* @param int $limit The limit |
261
|
|
|
* @param int $offset The offset |
262
|
|
|
* @param int $site_guid The site |
263
|
|
|
* @param bool $count Return the users (false) or the count of them (true) |
264
|
|
|
* |
265
|
|
|
* @return mixed |
266
|
|
|
* @deprecated 1.9 Use \ElggGroup::getMembers() |
267
|
|
|
*/ |
268
|
|
|
function get_group_members($group_guid, $limit = 10, $offset = 0, $site_guid = 0, $count = false) { |
269
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggGroup::getMembers()', 1.9); |
270
|
|
|
|
271
|
|
|
// in 1.7 0 means "not set." rewrite to make sense. |
272
|
|
|
if (!$site_guid) { |
273
|
|
|
$site_guid = ELGG_ENTITIES_ANY_VALUE; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
return elgg_get_entities_from_relationship(array( |
277
|
|
|
'relationship' => 'member', |
278
|
|
|
'relationship_guid' => $group_guid, |
279
|
|
|
'inverse_relationship' => true, |
280
|
|
|
'type' => 'user', |
281
|
|
|
'limit' => $limit, |
282
|
|
|
'offset' => $offset, |
283
|
|
|
'count' => $count, |
284
|
|
|
'site_guid' => $site_guid |
285
|
|
|
)); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* Add an object to the given group. |
290
|
|
|
* |
291
|
|
|
* @param int $group_guid The group to add the object to. |
292
|
|
|
* @param int $object_guid The guid of the elgg object (must be \ElggObject or a child thereof) |
293
|
|
|
* |
294
|
|
|
* @return bool |
295
|
|
|
* @throws InvalidClassException |
296
|
|
|
* @deprecated 1.9 Use \ElggGroup::addObjectToGroup() |
297
|
|
|
*/ |
298
|
|
View Code Duplication |
function add_object_to_group($group_guid, $object_guid) { |
|
|
|
|
299
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggGroup::addObjectToGroup()', 1.9); |
300
|
|
|
$group_guid = (int)$group_guid; |
301
|
|
|
$object_guid = (int)$object_guid; |
302
|
|
|
|
303
|
|
|
$group = get_entity($group_guid); |
304
|
|
|
$object = get_entity($object_guid); |
305
|
|
|
|
306
|
|
|
if ((!$group) || (!$object)) { |
307
|
|
|
return false; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
if (!($group instanceof \ElggGroup)) { |
311
|
|
|
$msg = "GUID:" . $group_guid . " is not a valid " . '\ElggGroup'; |
312
|
|
|
throw new \InvalidClassException($msg); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
if (!($object instanceof \ElggObject)) { |
316
|
|
|
$msg = "GUID:" . $object_guid . " is not a valid " . '\ElggObject'; |
317
|
|
|
throw new \InvalidClassException($msg); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
$object->container_guid = $group_guid; |
321
|
|
|
return $object->save(); |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* Remove an object from the given group. |
326
|
|
|
* |
327
|
|
|
* @param int $group_guid The group to remove the object from |
328
|
|
|
* @param int $object_guid The object to remove |
329
|
|
|
* |
330
|
|
|
* @return bool |
331
|
|
|
* @throws InvalidClassException |
332
|
|
|
* @deprecated 1.9 Use \ElggGroup::removeObjectFromGroup() |
333
|
|
|
*/ |
334
|
|
View Code Duplication |
function remove_object_from_group($group_guid, $object_guid) { |
|
|
|
|
335
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggGroup::removeObjectFromGroup()', 1.9); |
336
|
|
|
$group_guid = (int)$group_guid; |
337
|
|
|
$object_guid = (int)$object_guid; |
338
|
|
|
|
339
|
|
|
$group = get_entity($group_guid); |
340
|
|
|
$object = get_entity($object_guid); |
341
|
|
|
|
342
|
|
|
if ((!$group) || (!$object)) { |
343
|
|
|
return false; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
if (!($group instanceof \ElggGroup)) { |
347
|
|
|
$msg = "GUID:" . $group_guid . " is not a valid " . '\ElggGroup'; |
348
|
|
|
throw new \InvalidClassException($msg); |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
if (!($object instanceof \ElggObject)) { |
352
|
|
|
$msg = "GUID:" . $object_guid . " is not a valid " . '\ElggObject'; |
353
|
|
|
throw new \InvalidClassException($msg); |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
$object->container_guid = $object->owner_guid; |
357
|
|
|
return $object->save(); |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* Return whether a given user is a member of the group or not. |
362
|
|
|
* |
363
|
|
|
* @param int $group_guid The group ID |
364
|
|
|
* @param int $user_guid The user guid |
365
|
|
|
* |
366
|
|
|
* @return bool |
367
|
|
|
* @deprecated 1.9 Use Use \ElggGroup::isMember() |
368
|
|
|
*/ |
369
|
|
|
function is_group_member($group_guid, $user_guid) { |
370
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggGroup::isMember()', 1.9); |
371
|
|
|
$object = check_entity_relationship($user_guid, 'member', $group_guid); |
372
|
|
|
if ($object) { |
373
|
|
|
return true; |
374
|
|
|
} else { |
375
|
|
|
return false; |
376
|
|
|
} |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* Return all groups a user is a member of. |
382
|
|
|
* |
383
|
|
|
* @param int $user_guid GUID of user |
384
|
|
|
* |
385
|
|
|
* @return array|false |
386
|
|
|
* @deprecated 1.9 Use \ElggUser::getGroups() |
387
|
|
|
*/ |
388
|
|
|
function get_users_membership($user_guid) { |
389
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser::getGroups()', 1.9); |
390
|
|
|
$options = array( |
391
|
|
|
'type' => 'group', |
392
|
|
|
'relationship' => 'member', |
393
|
|
|
'relationship_guid' => $user_guid, |
394
|
|
|
'inverse_relationship' => false, |
395
|
|
|
'limit' => false, |
396
|
|
|
); |
397
|
|
|
return elgg_get_entities_from_relationship($options); |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
/** |
401
|
|
|
* Determines whether or not a user is another user's friend. |
402
|
|
|
* |
403
|
|
|
* @param int $user_guid The GUID of the user |
404
|
|
|
* @param int $friend_guid The GUID of the friend |
405
|
|
|
* |
406
|
|
|
* @return bool |
407
|
|
|
* @deprecated 1.9 Use \ElggUser::isFriendsOf() or \ElggUser::isFriendsWith() |
408
|
|
|
*/ |
409
|
|
|
function user_is_friend($user_guid, $friend_guid) { |
410
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser::isFriendsOf() or \ElggUser::isFriendsWith()', 1.9); |
411
|
|
|
return check_entity_relationship($user_guid, "friend", $friend_guid) !== false; |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
/** |
415
|
|
|
* Obtains a given user's friends |
416
|
|
|
* |
417
|
|
|
* @param int $user_guid The user's GUID |
418
|
|
|
* @param string $subtype The subtype of users, if any |
419
|
|
|
* @param int $limit Number of results to return (default 10) |
420
|
|
|
* @param int $offset Indexing offset, if any |
421
|
|
|
* |
422
|
|
|
* @return \ElggUser[]|false Either an array of \ElggUsers or false, depending on success |
423
|
|
|
* @deprecated 1.9 Use \ElggUser::getFriends() |
424
|
|
|
*/ |
425
|
|
|
function get_user_friends($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $limit = 10, |
426
|
|
|
$offset = 0) { |
427
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser::getFriends()', 1.9); |
428
|
|
|
|
429
|
|
|
return elgg_get_entities_from_relationship(array( |
430
|
|
|
'relationship' => 'friend', |
431
|
|
|
'relationship_guid' => $user_guid, |
432
|
|
|
'type' => 'user', |
433
|
|
|
'subtype' => $subtype, |
434
|
|
|
'limit' => $limit, |
435
|
|
|
'offset' => $offset |
436
|
|
|
)); |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
/** |
440
|
|
|
* Obtains the people who have made a given user a friend |
441
|
|
|
* |
442
|
|
|
* @param int $user_guid The user's GUID |
443
|
|
|
* @param string $subtype The subtype of users, if any |
444
|
|
|
* @param int $limit Number of results to return (default 10) |
445
|
|
|
* @param int $offset Indexing offset, if any |
446
|
|
|
* |
447
|
|
|
* @return \ElggUser[]|false Either an array of \ElggUsers or false, depending on success |
448
|
|
|
* @deprecated 1.9 Use \ElggUser::getFriendsOf() |
449
|
|
|
*/ |
450
|
|
View Code Duplication |
function get_user_friends_of($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $limit = 10, |
|
|
|
|
451
|
|
|
$offset = 0) { |
452
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser::getFriendsOf()', 1.9); |
453
|
|
|
|
454
|
|
|
return elgg_get_entities_from_relationship(array( |
455
|
|
|
'relationship' => 'friend', |
456
|
|
|
'relationship_guid' => $user_guid, |
457
|
|
|
'inverse_relationship' => true, |
458
|
|
|
'type' => 'user', |
459
|
|
|
'subtype' => $subtype, |
460
|
|
|
'limit' => $limit, |
461
|
|
|
'offset' => $offset |
462
|
|
|
)); |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
/** |
466
|
|
|
* Adds a user to another user's friends list. |
467
|
|
|
* |
468
|
|
|
* @param int $user_guid The GUID of the friending user |
469
|
|
|
* @param int $friend_guid The GUID of the user to friend |
470
|
|
|
* |
471
|
|
|
* @return bool Depending on success |
472
|
|
|
* @deprecated 1.9 Use \ElggUser::addFriend() |
473
|
|
|
*/ |
474
|
|
|
function user_add_friend($user_guid, $friend_guid) { |
475
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser::addFriend()', 1.9); |
476
|
|
|
$user_guid = (int) $user_guid; |
477
|
|
|
$friend_guid = (int) $friend_guid; |
478
|
|
|
if ($user_guid == $friend_guid) { |
479
|
|
|
return false; |
480
|
|
|
} |
481
|
|
|
if (!$friend = get_entity($friend_guid)) { |
482
|
|
|
return false; |
483
|
|
|
} |
484
|
|
|
if (!$user = get_entity($user_guid)) { |
485
|
|
|
return false; |
486
|
|
|
} |
487
|
|
|
if ((!($user instanceof \ElggUser)) || (!($friend instanceof \ElggUser))) { |
488
|
|
|
return false; |
489
|
|
|
} |
490
|
|
|
return add_entity_relationship($user_guid, "friend", $friend_guid); |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
/** |
494
|
|
|
* Removes a user from another user's friends list. |
495
|
|
|
* |
496
|
|
|
* @param int $user_guid The GUID of the friending user |
497
|
|
|
* @param int $friend_guid The GUID of the user on the friends list |
498
|
|
|
* |
499
|
|
|
* @return bool Depending on success |
500
|
|
|
* @deprecated 1.9 Use \ElggUser::removeFriend() |
501
|
|
|
*/ |
502
|
|
|
function user_remove_friend($user_guid, $friend_guid) { |
503
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser::removeFriend()', 1.9); |
504
|
|
|
$user_guid = (int) $user_guid; |
505
|
|
|
$friend_guid = (int) $friend_guid; |
506
|
|
|
|
507
|
|
|
// perform cleanup for access lists. |
508
|
|
|
$collections = get_user_access_collections($user_guid); |
509
|
|
|
if ($collections) { |
510
|
|
|
foreach ($collections as $collection) { |
511
|
|
|
remove_user_from_access_collection($friend_guid, $collection->id); |
512
|
|
|
} |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
return remove_entity_relationship($user_guid, "friend", $friend_guid); |
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
/** |
519
|
|
|
* Add a user to a site. |
520
|
|
|
* |
521
|
|
|
* @param int $site_guid Site guid |
522
|
|
|
* @param int $user_guid User guid |
523
|
|
|
* |
524
|
|
|
* @return bool |
525
|
|
|
* @deprecated 1.9 Use \ElggSite::addEntity() |
526
|
|
|
*/ |
527
|
|
|
function add_site_user($site_guid, $user_guid) { |
528
|
|
|
elgg_deprecated_notice('add_site_user() is deprecated. Use \ElggEntity::addEntity()', 1.9); |
529
|
|
|
$site_guid = (int)$site_guid; |
530
|
|
|
$user_guid = (int)$user_guid; |
531
|
|
|
|
532
|
|
|
return add_entity_relationship($user_guid, "member_of_site", $site_guid); |
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
/** |
536
|
|
|
* Remove a user from a site. |
537
|
|
|
* |
538
|
|
|
* @param int $site_guid Site GUID |
539
|
|
|
* @param int $user_guid User GUID |
540
|
|
|
* |
541
|
|
|
* @return bool |
542
|
|
|
* @deprecated 1.9 Use \ElggSite::removeEntity() |
543
|
|
|
*/ |
544
|
|
|
function remove_site_user($site_guid, $user_guid) { |
545
|
|
|
elgg_deprecated_notice('remove_site_user() is deprecated. Use \ElggEntity::removeEntity()', 1.9); |
546
|
|
|
$site_guid = (int)$site_guid; |
547
|
|
|
$user_guid = (int)$user_guid; |
548
|
|
|
|
549
|
|
|
return remove_entity_relationship($user_guid, "member_of_site", $site_guid); |
550
|
|
|
} |
551
|
|
|
|
552
|
|
|
/** |
553
|
|
|
* Add an object to a site. |
554
|
|
|
* |
555
|
|
|
* @param int $site_guid Site GUID |
556
|
|
|
* @param int $object_guid Object GUID |
557
|
|
|
* |
558
|
|
|
* @return mixed |
559
|
|
|
* @deprecated 1.9 Use \ElggSite::addEntity() |
560
|
|
|
*/ |
561
|
|
|
function add_site_object($site_guid, $object_guid) { |
562
|
|
|
elgg_deprecated_notice('add_site_object() is deprecated. Use \ElggEntity::addEntity()', 1.9); |
563
|
|
|
$site_guid = (int)$site_guid; |
564
|
|
|
$object_guid = (int)$object_guid; |
565
|
|
|
|
566
|
|
|
return add_entity_relationship($object_guid, "member_of_site", $site_guid); |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
/** |
570
|
|
|
* Remove an object from a site. |
571
|
|
|
* |
572
|
|
|
* @param int $site_guid Site GUID |
573
|
|
|
* @param int $object_guid Object GUID |
574
|
|
|
* |
575
|
|
|
* @return bool |
576
|
|
|
* @deprecated 1.9 Use \ElggSite::removeEntity() |
577
|
|
|
*/ |
578
|
|
|
function remove_site_object($site_guid, $object_guid) { |
579
|
|
|
elgg_deprecated_notice('remove_site_object() is deprecated. Use \ElggEntity::removeEntity()', 1.9); |
580
|
|
|
$site_guid = (int)$site_guid; |
581
|
|
|
$object_guid = (int)$object_guid; |
582
|
|
|
|
583
|
|
|
return remove_entity_relationship($object_guid, "member_of_site", $site_guid); |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
/** |
587
|
|
|
* Get the objects belonging to a site. |
588
|
|
|
* |
589
|
|
|
* @param int $site_guid Site GUID |
590
|
|
|
* @param string $subtype Subtype |
591
|
|
|
* @param int $limit Limit |
592
|
|
|
* @param int $offset Offset |
593
|
|
|
* |
594
|
|
|
* @return mixed |
595
|
|
|
* @deprecated 1.9 Use \ElggSite::getEntities() |
596
|
|
|
*/ |
597
|
|
View Code Duplication |
function get_site_objects($site_guid, $subtype = "", $limit = 10, $offset = 0) { |
|
|
|
|
598
|
|
|
elgg_deprecated_notice('get_site_objects() is deprecated. Use \ElggSite::getEntities()', 1.9); |
599
|
|
|
$site_guid = (int)$site_guid; |
600
|
|
|
$limit = (int)$limit; |
601
|
|
|
$offset = (int)$offset; |
602
|
|
|
|
603
|
|
|
return elgg_get_entities_from_relationship(array( |
604
|
|
|
'relationship' => 'member_of_site', |
605
|
|
|
'relationship_guid' => $site_guid, |
606
|
|
|
'inverse_relationship' => true, |
607
|
|
|
'type' => 'object', |
608
|
|
|
'subtype' => $subtype, |
609
|
|
|
'limit' => $limit, |
610
|
|
|
'offset' => $offset |
611
|
|
|
)); |
612
|
|
|
} |
613
|
|
|
|
614
|
|
|
/** |
615
|
|
|
* Get the sites this object is part of |
616
|
|
|
* |
617
|
|
|
* @param int $object_guid The object's GUID |
618
|
|
|
* @param int $limit Number of results to return |
619
|
|
|
* @param int $offset Any indexing offset |
620
|
|
|
* |
621
|
|
|
* @return array On success, an array of \ElggSites |
622
|
|
|
* @deprecated 1.9 Use \ElggEntity::getSites() |
623
|
|
|
*/ |
624
|
|
|
function get_object_sites($object_guid, $limit = 10, $offset = 0) { |
625
|
|
|
elgg_deprecated_notice('get_object_sites() is deprecated. Use \ElggEntity::getSites()', 1.9); |
626
|
|
|
$object_guid = (int)$object_guid; |
627
|
|
|
$limit = (int)$limit; |
628
|
|
|
$offset = (int)$offset; |
629
|
|
|
|
630
|
|
|
return elgg_get_entities_from_relationship(array( |
631
|
|
|
'relationship' => 'member_of_site', |
632
|
|
|
'relationship_guid' => $object_guid, |
633
|
|
|
'type' => 'site', |
634
|
|
|
'limit' => $limit, |
635
|
|
|
'offset' => $offset, |
636
|
|
|
)); |
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
/** |
640
|
|
|
* Get the sites this user is part of |
641
|
|
|
* |
642
|
|
|
* @param int $user_guid The user's GUID |
643
|
|
|
* @param int $limit Number of results to return |
644
|
|
|
* @param int $offset Any indexing offset |
645
|
|
|
* |
646
|
|
|
* @return \ElggSite[]|false On success, an array of \ElggSites |
647
|
|
|
* @deprecated 1.9 Use \ElggEntity::getSites() |
648
|
|
|
*/ |
649
|
|
View Code Duplication |
function get_user_sites($user_guid, $limit = 10, $offset = 0) { |
|
|
|
|
650
|
|
|
elgg_deprecated_notice('get_user_sites() is deprecated. Use \ElggEntity::getSites()', 1.9); |
651
|
|
|
$user_guid = (int)$user_guid; |
652
|
|
|
$limit = (int)$limit; |
653
|
|
|
$offset = (int)$offset; |
654
|
|
|
|
655
|
|
|
return elgg_get_entities_from_relationship(array( |
656
|
|
|
'site_guids' => ELGG_ENTITIES_ANY_VALUE, |
657
|
|
|
'relationship' => 'member_of_site', |
658
|
|
|
'relationship_guid' => $user_guid, |
659
|
|
|
'inverse_relationship' => false, |
660
|
|
|
'type' => 'site', |
661
|
|
|
'limit' => $limit, |
662
|
|
|
'offset' => $offset, |
663
|
|
|
)); |
664
|
|
|
} |
665
|
|
|
|
666
|
|
|
/** |
667
|
|
|
* Determines whether or not the specified user can edit the specified piece of extender |
668
|
|
|
* |
669
|
|
|
* @param int $extender_id The ID of the piece of extender |
670
|
|
|
* @param string $type 'metadata' or 'annotation' |
671
|
|
|
* @param int $user_guid The GUID of the user |
672
|
|
|
* |
673
|
|
|
* @return bool |
674
|
|
|
* @deprecated 1.9 Use the appropriate canEdit() method on metadata or annotations |
675
|
|
|
*/ |
676
|
|
|
function can_edit_extender($extender_id, $type, $user_guid = 0) { |
677
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggExtender::canEdit()', 1.9); |
678
|
|
|
|
679
|
|
|
// Since Elgg 1.0, Elgg has returned false from can_edit_extender() |
680
|
|
|
// if no user was logged in. This breaks the access override so we add this |
681
|
|
|
// special check here. |
682
|
|
|
if (!elgg_check_access_overrides($user_guid)) { |
683
|
|
|
if (!elgg_is_logged_in()) { |
684
|
|
|
return false; |
685
|
|
|
} |
686
|
|
|
} |
687
|
|
|
|
688
|
|
|
$user_guid = (int)$user_guid; |
689
|
|
|
$user = get_user($user_guid); |
690
|
|
|
if (!$user) { |
691
|
|
|
$user = elgg_get_logged_in_user_entity(); |
692
|
|
|
$user_guid = elgg_get_logged_in_user_guid(); |
693
|
|
|
} |
694
|
|
|
|
695
|
|
|
$functionname = "elgg_get_{$type}_from_id"; |
696
|
|
|
if (is_callable($functionname)) { |
697
|
|
|
$extender = call_user_func($functionname, $extender_id); |
698
|
|
|
} else { |
699
|
|
|
return false; |
700
|
|
|
} |
701
|
|
|
|
702
|
|
|
if (!($extender instanceof \ElggExtender)) { |
703
|
|
|
return false; |
704
|
|
|
} |
705
|
|
|
/* @var \ElggExtender $extender */ |
706
|
|
|
|
707
|
|
|
// If the owner is the specified user, great! They can edit. |
708
|
|
|
if ($extender->getOwnerGUID() == $user_guid) { |
709
|
|
|
return true; |
710
|
|
|
} |
711
|
|
|
|
712
|
|
|
// If the user can edit the entity this is attached to, great! They can edit. |
713
|
|
|
$entity = $extender->getEntity(); |
714
|
|
|
if ($entity->canEdit($user_guid)) { |
715
|
|
|
return true; |
716
|
|
|
} |
717
|
|
|
|
718
|
|
|
// Trigger plugin hook - note that $user may be null |
719
|
|
|
$params = array('entity' => $entity, 'user' => $user); |
720
|
|
|
return elgg_trigger_plugin_hook('permissions_check', $type, $params, false); |
721
|
|
|
} |
722
|
|
|
|
723
|
|
|
/** |
724
|
|
|
* The algorithm working out the size of font based on the number of tags. |
725
|
|
|
* This is quick and dirty. |
726
|
|
|
* |
727
|
|
|
* @param int $min Min size |
728
|
|
|
* @param int $max Max size |
729
|
|
|
* @param int $number_of_tags The number of tags |
730
|
|
|
* @param int $buckets The number of buckets |
731
|
|
|
* |
732
|
|
|
* @return int |
733
|
|
|
* @access private |
734
|
|
|
* @deprecated 1.9 |
735
|
|
|
*/ |
736
|
|
|
function calculate_tag_size($min, $max, $number_of_tags, $buckets = 6) { |
737
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); |
738
|
|
|
$delta = (($max - $min) / $buckets); |
739
|
|
|
$thresholds = array(); |
740
|
|
|
|
741
|
|
|
for ($n = 1; $n <= $buckets; $n++) { |
742
|
|
|
$thresholds[$n - 1] = ($min + $n) * $delta; |
743
|
|
|
} |
744
|
|
|
|
745
|
|
|
// Correction |
746
|
|
|
if ($thresholds[$buckets - 1] > $max) { |
747
|
|
|
$thresholds[$buckets - 1] = $max; |
748
|
|
|
} |
749
|
|
|
|
750
|
|
|
$size = 0; |
751
|
|
|
for ($n = 0; $n < count($thresholds); $n++) { |
|
|
|
|
752
|
|
|
if ($number_of_tags >= $thresholds[$n]) { |
753
|
|
|
$size = $n; |
754
|
|
|
} |
755
|
|
|
} |
756
|
|
|
|
757
|
|
|
return $size; |
758
|
|
|
} |
759
|
|
|
|
760
|
|
|
/** |
761
|
|
|
* This function generates an array of tags with a weighting. |
762
|
|
|
* |
763
|
|
|
* @param array $tags The array of tags. |
764
|
|
|
* @param int $buckets The number of buckets |
765
|
|
|
* |
766
|
|
|
* @return array An associated array of tags with a weighting, this can then be mapped to a display class. |
767
|
|
|
* @access private |
768
|
|
|
* @deprecated 1.9 |
769
|
|
|
*/ |
770
|
|
|
function generate_tag_cloud(array $tags, $buckets = 6) { |
771
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); |
772
|
|
|
$cloud = array(); |
773
|
|
|
|
774
|
|
|
$min = 65535; |
775
|
|
|
$max = 0; |
776
|
|
|
|
777
|
|
|
foreach ($tags as $tag) { |
778
|
|
|
$cloud[$tag]++; |
779
|
|
|
|
780
|
|
|
if ($cloud[$tag] > $max) { |
781
|
|
|
$max = $cloud[$tag]; |
782
|
|
|
} |
783
|
|
|
|
784
|
|
|
if ($cloud[$tag] < $min) { |
785
|
|
|
$min = $cloud[$tag]; |
786
|
|
|
} |
787
|
|
|
} |
788
|
|
|
|
789
|
|
|
foreach ($cloud as $k => $v) { |
790
|
|
|
$cloud[$k] = calculate_tag_size($min, $max, $v, $buckets); |
|
|
|
|
791
|
|
|
} |
792
|
|
|
|
793
|
|
|
return $cloud; |
794
|
|
|
} |
795
|
|
|
|
796
|
|
|
/** |
797
|
|
|
* Invalidate the metadata cache based on options passed to various *_metadata functions |
798
|
|
|
* |
799
|
|
|
* @param string $action Action performed on metadata. "delete", "disable", or "enable" |
800
|
|
|
* @param array $options Options passed to elgg_(delete|disable|enable)_metadata |
801
|
|
|
* @return void |
802
|
|
|
* @deprecated 1.9 |
803
|
|
|
*/ |
804
|
|
|
function elgg_invalidate_metadata_cache($action, array $options) { |
805
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); |
806
|
|
|
_elgg_invalidate_metadata_cache($action, $options); |
807
|
|
|
} |
808
|
|
|
|
809
|
|
|
global $METASTRINGS_DEADNAME_CACHE; |
810
|
|
|
$METASTRINGS_DEADNAME_CACHE = array(); |
811
|
|
|
|
812
|
|
|
/** |
813
|
|
|
* Return the meta string id for a given tag, or false. |
814
|
|
|
* |
815
|
|
|
* @param string $string The value to store |
816
|
|
|
* @param bool $case_sensitive Do we want to make the query case sensitive? |
817
|
|
|
* If not there may be more than one result |
818
|
|
|
* |
819
|
|
|
* @return int|array|false meta string id, array of ids or false if none found |
820
|
|
|
* @deprecated 1.9 Use elgg_get_metastring_id() |
821
|
|
|
*/ |
822
|
|
|
function get_metastring_id($string, $case_sensitive = TRUE) { |
823
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_get_metastring_id()', 1.9); |
824
|
|
|
global $CONFIG, $METASTRINGS_CACHE, $METASTRINGS_DEADNAME_CACHE; |
825
|
|
|
|
826
|
|
|
$string = sanitise_string($string); |
827
|
|
|
|
828
|
|
|
// caching doesn't work for case insensitive searches |
829
|
|
|
if ($case_sensitive) { |
830
|
|
|
$result = array_search($string, $METASTRINGS_CACHE, true); |
831
|
|
|
|
832
|
|
|
if ($result !== false) { |
833
|
|
|
return $result; |
834
|
|
|
} |
835
|
|
|
|
836
|
|
|
// See if we have previously looked for this and found nothing |
837
|
|
|
if (in_array($string, $METASTRINGS_DEADNAME_CACHE, true)) { |
838
|
|
|
return false; |
839
|
|
|
} |
840
|
|
|
|
841
|
|
|
// Experimental memcache |
842
|
|
|
$msfc = null; |
843
|
|
|
static $metastrings_memcache; |
844
|
|
|
if ((!$metastrings_memcache) && (is_memcache_available())) { |
845
|
|
|
$metastrings_memcache = new \ElggMemcache('metastrings_memcache'); |
846
|
|
|
} |
847
|
|
|
if ($metastrings_memcache) { |
848
|
|
|
$msfc = $metastrings_memcache->load($string); |
849
|
|
|
} |
850
|
|
|
if ($msfc) { |
851
|
|
|
return $msfc; |
852
|
|
|
} |
853
|
|
|
} |
854
|
|
|
|
855
|
|
|
// Case sensitive |
856
|
|
|
if ($case_sensitive) { |
857
|
|
|
$query = "SELECT * from {$CONFIG->dbprefix}metastrings where string= BINARY '$string' limit 1"; |
858
|
|
|
} else { |
859
|
|
|
$query = "SELECT * from {$CONFIG->dbprefix}metastrings where string = '$string'"; |
860
|
|
|
} |
861
|
|
|
|
862
|
|
|
$row = FALSE; |
863
|
|
|
$metaStrings = get_data($query); |
864
|
|
|
if (is_array($metaStrings)) { |
865
|
|
|
if (sizeof($metaStrings) > 1) { |
866
|
|
|
$ids = array(); |
867
|
|
|
foreach ($metaStrings as $metaString) { |
868
|
|
|
$ids[] = $metaString->id; |
869
|
|
|
} |
870
|
|
|
return $ids; |
871
|
|
|
} else if (isset($metaStrings[0])) { |
872
|
|
|
$row = $metaStrings[0]; |
873
|
|
|
} |
874
|
|
|
} |
875
|
|
|
|
876
|
|
|
if ($row) { |
877
|
|
|
$METASTRINGS_CACHE[$row->id] = $row->string; // Cache it |
878
|
|
|
|
879
|
|
|
// Attempt to memcache it if memcache is available |
880
|
|
|
if ($metastrings_memcache) { |
881
|
|
|
$metastrings_memcache->save($row->string, $row->id); |
|
|
|
|
882
|
|
|
} |
883
|
|
|
|
884
|
|
|
return $row->id; |
885
|
|
|
} else { |
886
|
|
|
$METASTRINGS_DEADNAME_CACHE[$string] = $string; |
887
|
|
|
} |
888
|
|
|
|
889
|
|
|
return false; |
890
|
|
|
} |
891
|
|
|
|
892
|
|
|
/** |
893
|
|
|
* Add a metastring. |
894
|
|
|
* It returns the id of the metastring. If it does not exist, it will be created. |
895
|
|
|
* |
896
|
|
|
* @param string $string The value (whatever that is) to be stored |
897
|
|
|
* @param bool $case_sensitive Do we want to make the query case sensitive? |
898
|
|
|
* |
899
|
|
|
* @return mixed Integer tag or false. |
900
|
|
|
* @deprecated 1.9 Use elgg_get_metastring_id() |
901
|
|
|
*/ |
902
|
|
|
function add_metastring($string, $case_sensitive = true) { |
903
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_get_metastring_id()', 1.9); |
904
|
|
|
global $CONFIG, $METASTRINGS_CACHE, $METASTRINGS_DEADNAME_CACHE; |
905
|
|
|
|
906
|
|
|
$sanstring = sanitise_string($string); |
907
|
|
|
|
908
|
|
|
$id = get_metastring_id($string, $case_sensitive); |
|
|
|
|
909
|
|
|
if ($id) { |
910
|
|
|
return $id; |
911
|
|
|
} |
912
|
|
|
|
913
|
|
|
$result = insert_data("INSERT into {$CONFIG->dbprefix}metastrings (string) values ('$sanstring')"); |
914
|
|
|
if ($result) { |
|
|
|
|
915
|
|
|
$METASTRINGS_CACHE[$result] = $string; |
916
|
|
|
if (isset($METASTRINGS_DEADNAME_CACHE[$string])) { |
917
|
|
|
unset($METASTRINGS_DEADNAME_CACHE[$string]); |
918
|
|
|
} |
919
|
|
|
} |
920
|
|
|
|
921
|
|
|
return $result; |
922
|
|
|
} |
923
|
|
|
|
924
|
|
|
/** |
925
|
|
|
* When given an ID, returns the corresponding metastring |
926
|
|
|
* |
927
|
|
|
* @param int $id Metastring ID |
928
|
|
|
* |
929
|
|
|
* @return string Metastring |
930
|
|
|
* @deprecated 1.9 |
931
|
|
|
*/ |
932
|
|
|
function get_metastring($id) { |
933
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated.', 1.9); |
934
|
|
|
global $CONFIG, $METASTRINGS_CACHE; |
935
|
|
|
|
936
|
|
|
$id = (int) $id; |
937
|
|
|
|
938
|
|
|
if (isset($METASTRINGS_CACHE[$id])) { |
939
|
|
|
return $METASTRINGS_CACHE[$id]; |
940
|
|
|
} |
941
|
|
|
|
942
|
|
|
$row = get_data_row("SELECT * from {$CONFIG->dbprefix}metastrings where id='$id' limit 1"); |
943
|
|
|
if ($row) { |
|
|
|
|
944
|
|
|
$METASTRINGS_CACHE[$id] = $row->string; |
945
|
|
|
return $row->string; |
946
|
|
|
} |
947
|
|
|
|
948
|
|
|
return false; |
949
|
|
|
} |
950
|
|
|
|
951
|
|
|
/** |
952
|
|
|
* Obtains a list of objects owned by a user's friends |
953
|
|
|
* |
954
|
|
|
* @param int $user_guid The GUID of the user to get the friends of |
955
|
|
|
* @param string $subtype Optionally, the subtype of objects |
956
|
|
|
* @param int $limit The number of results to return (default 10) |
957
|
|
|
* @param int $offset Indexing offset, if any |
958
|
|
|
* @param int $timelower The earliest time the entity can have been created. Default: all |
959
|
|
|
* @param int $timeupper The latest time the entity can have been created. Default: all |
960
|
|
|
* |
961
|
|
|
* @return \ElggObject[]|false An array of \ElggObjects or false, depending on success |
962
|
|
|
* @deprecated 1.9 Use elgg_get_entities_from_relationship() |
963
|
|
|
*/ |
964
|
|
|
function get_user_friends_objects($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $limit = 10, |
965
|
|
|
$offset = 0, $timelower = 0, $timeupper = 0) { |
966
|
|
|
|
967
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_get_entities_from_relationship()', 1.9); |
968
|
|
|
return elgg_get_entities_from_relationship(array( |
969
|
|
|
'type' => 'object', |
970
|
|
|
'subtype' => $subtype, |
971
|
|
|
'limit' => $limit, |
972
|
|
|
'offset' => $offset, |
973
|
|
|
'created_time_lower' => $timelower, |
974
|
|
|
'created_time_upper' => $timeupper, |
975
|
|
|
'relationship' => 'friend', |
976
|
|
|
'relationship_guid' => $user_guid, |
977
|
|
|
'relationship_join_on' => 'container_guid', |
978
|
|
|
)); |
979
|
|
|
} |
980
|
|
|
|
981
|
|
|
/** |
982
|
|
|
* Counts the number of objects owned by a user's friends |
983
|
|
|
* |
984
|
|
|
* @param int $user_guid The GUID of the user to get the friends of |
985
|
|
|
* @param string $subtype Optionally, the subtype of objects |
986
|
|
|
* @param int $timelower The earliest time the entity can have been created. Default: all |
987
|
|
|
* @param int $timeupper The latest time the entity can have been created. Default: all |
988
|
|
|
* |
989
|
|
|
* @return int The number of objects |
990
|
|
|
* @deprecated 1.9 Use elgg_get_entities_from_relationship() |
991
|
|
|
*/ |
992
|
|
View Code Duplication |
function count_user_friends_objects($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, |
|
|
|
|
993
|
|
|
$timelower = 0, $timeupper = 0) { |
994
|
|
|
|
995
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_get_entities_from_relationship()', 1.9); |
996
|
|
|
return elgg_get_entities_from_relationship(array( |
997
|
|
|
'type' => 'object', |
998
|
|
|
'subtype' => $subtype, |
999
|
|
|
'created_time_lower' => $timelower, |
1000
|
|
|
'created_time_upper' => $timeupper, |
1001
|
|
|
'relationship' => 'friend', |
1002
|
|
|
'relationship_guid' => $user_guid, |
1003
|
|
|
'relationship_join_on' => 'container_guid', |
1004
|
|
|
'count' => true, |
1005
|
|
|
)); |
1006
|
|
|
} |
1007
|
|
|
|
1008
|
|
|
/** |
1009
|
|
|
* Displays a list of a user's friends' objects of a particular subtype, with navigation. |
1010
|
|
|
* |
1011
|
|
|
* @see elgg_view_entity_list |
1012
|
|
|
* |
1013
|
|
|
* @param int $user_guid The GUID of the user |
1014
|
|
|
* @param string $subtype The object subtype |
1015
|
|
|
* @param int $limit The number of entities to display on a page |
1016
|
|
|
* @param bool $full_view Whether or not to display the full view (default: true) |
1017
|
|
|
* @param bool $listtypetoggle Whether or not to allow you to flip to gallery mode (default: true) |
1018
|
|
|
* @param bool $pagination Whether to display pagination (default: true) |
1019
|
|
|
* @param int $timelower The earliest time the entity can have been created. Default: all |
1020
|
|
|
* @param int $timeupper The latest time the entity can have been created. Default: all |
1021
|
|
|
* |
1022
|
|
|
* @return string |
1023
|
|
|
* @deprecated 1.9 Use elgg_list_entities_from_relationship() |
1024
|
|
|
*/ |
1025
|
|
|
function list_user_friends_objects($user_guid, $subtype = "", $limit = 10, $full_view = true, |
1026
|
|
|
$listtypetoggle = true, $pagination = true, $timelower = 0, $timeupper = 0) { |
1027
|
|
|
|
1028
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_list_entities_from_relationship()', 1.9); |
1029
|
|
|
return elgg_list_entities_from_relationship(array( |
1030
|
|
|
'type' => 'object', |
1031
|
|
|
'subtype' => $subtype, |
1032
|
|
|
'limit' => $limit, |
1033
|
|
|
'created_time_lower' => $timelower, |
1034
|
|
|
'created_time_upper' => $timeupper, |
1035
|
|
|
'full_view' => $full_view, |
1036
|
|
|
'list_type_toggle' => $listtypetoggle, |
1037
|
|
|
'pagination' => $pagination, |
1038
|
|
|
'relationship' => 'friend', |
1039
|
|
|
'relationship_guid' => $user_guid, |
1040
|
|
|
'relationship_join_on' => 'container_guid', |
1041
|
|
|
)); |
1042
|
|
|
} |
1043
|
|
|
|
1044
|
|
|
/** |
1045
|
|
|
* Encode a location into a latitude and longitude, caching the result. |
1046
|
|
|
* |
1047
|
|
|
* Works by triggering the 'geocode' 'location' plugin |
1048
|
|
|
* hook, and requires a geocoding plugin to be installed. |
1049
|
|
|
* |
1050
|
|
|
* @param string $location The location, e.g. "London", or "24 Foobar Street, Gotham City" |
1051
|
|
|
* @return string|false |
1052
|
|
|
* @deprecated 1.9.0 See geolocation plugin on github |
1053
|
|
|
*/ |
1054
|
|
|
function elgg_geocode_location($location) { |
1055
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. See geolocation plugin on github', 1.9); |
1056
|
|
|
global $CONFIG; |
1057
|
|
|
|
1058
|
|
|
if (is_array($location)) { |
1059
|
|
|
return false; |
1060
|
|
|
} |
1061
|
|
|
|
1062
|
|
|
$location = sanitise_string($location); |
1063
|
|
|
|
1064
|
|
|
// Look for cached version |
1065
|
|
|
$query = "SELECT * from {$CONFIG->dbprefix}geocode_cache WHERE location='$location'"; |
1066
|
|
|
$cached_location = get_data_row($query); |
1067
|
|
|
|
1068
|
|
|
if ($cached_location) { |
|
|
|
|
1069
|
|
|
return array('lat' => $cached_location->lat, 'long' => $cached_location->long); |
1070
|
|
|
} |
1071
|
|
|
|
1072
|
|
|
// Trigger geocode event if not cached |
1073
|
|
|
$return = false; |
1074
|
|
|
$return = elgg_trigger_plugin_hook('geocode', 'location', array('location' => $location), $return); |
1075
|
|
|
|
1076
|
|
|
// If returned, cache and return value |
1077
|
|
|
if (($return) && (is_array($return))) { |
1078
|
|
|
$lat = (float)$return['lat']; |
1079
|
|
|
$long = (float)$return['long']; |
1080
|
|
|
|
1081
|
|
|
// Put into cache at the end of the page since we don't really care that much |
1082
|
|
|
$query = "INSERT DELAYED INTO {$CONFIG->dbprefix}geocode_cache " |
1083
|
|
|
. " (location, lat, `long`) VALUES ('$location', '{$lat}', '{$long}')" |
1084
|
|
|
. " ON DUPLICATE KEY UPDATE lat='{$lat}', `long`='{$long}'"; |
1085
|
|
|
execute_delayed_write_query($query); |
1086
|
|
|
} |
1087
|
|
|
|
1088
|
|
|
return $return; |
1089
|
|
|
} |
1090
|
|
|
|
1091
|
|
|
/** |
1092
|
|
|
* Return entities within a given geographic area. |
1093
|
|
|
* |
1094
|
|
|
* Also accepts all options available to elgg_get_entities(). |
1095
|
|
|
* |
1096
|
|
|
* @see elgg_get_entities |
1097
|
|
|
* |
1098
|
|
|
* @param array $options Array in format: |
1099
|
|
|
* |
1100
|
|
|
* latitude => FLOAT Latitude of the location |
1101
|
|
|
* |
1102
|
|
|
* longitude => FLOAT Longitude of the location |
1103
|
|
|
* |
1104
|
|
|
* distance => FLOAT/ARR ( |
1105
|
|
|
* latitude => float, |
1106
|
|
|
* longitude => float, |
1107
|
|
|
* ) |
1108
|
|
|
* The distance in degrees that determines the search box. A |
1109
|
|
|
* single float will result in a square in degrees. |
1110
|
|
|
* @warning The Earth is round. |
1111
|
|
|
* |
1112
|
|
|
* @see \ElggEntity::setLatLong() |
1113
|
|
|
* |
1114
|
|
|
* @return mixed If count, int. If not count, array. false on errors. |
1115
|
|
|
* @since 1.8.0 |
1116
|
|
|
* @deprecated 1.9.0 See geolocation plugin on github |
1117
|
|
|
*/ |
1118
|
|
|
function elgg_get_entities_from_location(array $options = array()) { |
1119
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. See geolocation plugin on github', 1.9); |
1120
|
|
|
global $CONFIG; |
1121
|
|
|
|
1122
|
|
|
if (!isset($options['latitude']) || !isset($options['longitude']) || |
1123
|
|
|
!isset($options['distance'])) { |
1124
|
|
|
return false; |
1125
|
|
|
} |
1126
|
|
|
|
1127
|
|
|
if (!is_array($options['distance'])) { |
1128
|
|
|
$lat_distance = (float)$options['distance']; |
1129
|
|
|
$long_distance = (float)$options['distance']; |
1130
|
|
|
} else { |
1131
|
|
|
$lat_distance = (float)$options['distance']['latitude']; |
1132
|
|
|
$long_distance = (float)$options['distance']['longitude']; |
1133
|
|
|
} |
1134
|
|
|
|
1135
|
|
|
$lat = (float)$options['latitude']; |
1136
|
|
|
$long = (float)$options['longitude']; |
1137
|
|
|
$lat_min = $lat - $lat_distance; |
1138
|
|
|
$lat_max = $lat + $lat_distance; |
1139
|
|
|
$long_min = $long - $long_distance; |
1140
|
|
|
$long_max = $long + $long_distance; |
1141
|
|
|
|
1142
|
|
|
$wheres = array(); |
1143
|
|
|
$wheres[] = "lat_name.string='geo:lat'"; |
1144
|
|
|
$wheres[] = "lat_value.string >= $lat_min"; |
1145
|
|
|
$wheres[] = "lat_value.string <= $lat_max"; |
1146
|
|
|
$wheres[] = "lon_name.string='geo:long'"; |
1147
|
|
|
$wheres[] = "lon_value.string >= $long_min"; |
1148
|
|
|
$wheres[] = "lon_value.string <= $long_max"; |
1149
|
|
|
|
1150
|
|
|
$joins = array(); |
1151
|
|
|
$joins[] = "JOIN {$CONFIG->dbprefix}metadata lat on e.guid=lat.entity_guid"; |
1152
|
|
|
$joins[] = "JOIN {$CONFIG->dbprefix}metastrings lat_name on lat.name_id=lat_name.id"; |
1153
|
|
|
$joins[] = "JOIN {$CONFIG->dbprefix}metastrings lat_value on lat.value_id=lat_value.id"; |
1154
|
|
|
$joins[] = "JOIN {$CONFIG->dbprefix}metadata lon on e.guid=lon.entity_guid"; |
1155
|
|
|
$joins[] = "JOIN {$CONFIG->dbprefix}metastrings lon_name on lon.name_id=lon_name.id"; |
1156
|
|
|
$joins[] = "JOIN {$CONFIG->dbprefix}metastrings lon_value on lon.value_id=lon_value.id"; |
1157
|
|
|
|
1158
|
|
|
// merge wheres to pass to get_entities() |
1159
|
|
|
if (isset($options['wheres']) && !is_array($options['wheres'])) { |
1160
|
|
|
$options['wheres'] = array($options['wheres']); |
1161
|
|
|
} elseif (!isset($options['wheres'])) { |
1162
|
|
|
$options['wheres'] = array(); |
1163
|
|
|
} |
1164
|
|
|
$options['wheres'] = array_merge($options['wheres'], $wheres); |
1165
|
|
|
|
1166
|
|
|
// merge joins to pass to get_entities() |
1167
|
|
|
if (isset($options['joins']) && !is_array($options['joins'])) { |
1168
|
|
|
$options['joins'] = array($options['joins']); |
1169
|
|
|
} elseif (!isset($options['joins'])) { |
1170
|
|
|
$options['joins'] = array(); |
1171
|
|
|
} |
1172
|
|
|
$options['joins'] = array_merge($options['joins'], $joins); |
1173
|
|
|
|
1174
|
|
|
return elgg_get_entities_from_relationship($options); |
1175
|
|
|
} |
1176
|
|
|
|
1177
|
|
|
/** |
1178
|
|
|
* Returns a viewable list of entities from location |
1179
|
|
|
* |
1180
|
|
|
* @param array $options Options array |
1181
|
|
|
* |
1182
|
|
|
* @see elgg_list_entities() |
1183
|
|
|
* @see elgg_get_entities_from_location() |
1184
|
|
|
* |
1185
|
|
|
* @return string The viewable list of entities |
1186
|
|
|
* @since 1.8.0 |
1187
|
|
|
* @deprecated 1.9.0 See geolocation plugin on github |
1188
|
|
|
*/ |
1189
|
|
|
function elgg_list_entities_from_location(array $options = array()) { |
1190
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. See geolocation plugin on github', 1.9); |
1191
|
|
|
return elgg_list_entities($options, 'elgg_get_entities_from_location'); |
1192
|
|
|
} |
1193
|
|
|
|
1194
|
|
|
// Some distances in degrees (approximate) |
1195
|
|
|
// @todo huh? see warning on elgg_get_entities_from_location() |
1196
|
|
|
// @deprecated 1.9.0 |
1197
|
|
|
define("MILE", 0.01515); |
1198
|
|
|
define("KILOMETER", 0.00932); |
1199
|
|
|
|
1200
|
|
|
/** |
1201
|
|
|
* Get the current Elgg version information |
1202
|
|
|
* |
1203
|
|
|
* @param bool $humanreadable Whether to return a human readable version (default: false) |
1204
|
|
|
* |
1205
|
|
|
* @return string|false Depending on success |
1206
|
|
|
* @deprecated 1.9 Use elgg_get_version() |
1207
|
|
|
*/ |
1208
|
|
|
function get_version($humanreadable = false) { |
1209
|
|
|
elgg_deprecated_notice('get_version() has been deprecated by elgg_get_version()', 1.9); |
1210
|
|
|
return elgg_get_version($humanreadable); |
1211
|
|
|
} |
1212
|
|
|
|
1213
|
|
|
/** |
1214
|
|
|
* Sanitise a string for database use, but with the option of escaping extra characters. |
1215
|
|
|
* |
1216
|
|
|
* @param string $string The string to sanitise |
1217
|
|
|
* @param string $extra_escapeable Extra characters to escape with '\\' |
1218
|
|
|
* |
1219
|
|
|
* @return string The escaped string |
1220
|
|
|
* @deprecated 1.9 |
1221
|
|
|
*/ |
1222
|
|
|
function sanitise_string_special($string, $extra_escapeable = '') { |
1223
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated.', 1.9); |
1224
|
|
|
$string = sanitise_string($string); |
1225
|
|
|
|
1226
|
|
|
for ($n = 0; $n < strlen($extra_escapeable); $n++) { |
1227
|
|
|
$string = str_replace($extra_escapeable[$n], "\\" . $extra_escapeable[$n], $string); |
1228
|
|
|
} |
1229
|
|
|
|
1230
|
|
|
return $string; |
1231
|
|
|
} |
1232
|
|
|
|
1233
|
|
|
/** |
1234
|
|
|
* Establish database connections |
1235
|
|
|
* |
1236
|
|
|
* If the configuration has been set up for multiple read/write databases, set those |
1237
|
|
|
* links up separately; otherwise just create the one database link. |
1238
|
|
|
* |
1239
|
|
|
* @return void |
1240
|
|
|
* @access private |
1241
|
|
|
* @deprecated 1.9 |
1242
|
|
|
*/ |
1243
|
|
|
function setup_db_connections() { |
1244
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is a private function and should not be used.', 1.9); |
1245
|
|
|
_elgg_services()->db->setupConnections(); |
1246
|
|
|
} |
1247
|
|
|
|
1248
|
|
|
/** |
1249
|
|
|
* Returns (if required, also creates) a database link resource. |
1250
|
|
|
* |
1251
|
|
|
* Database link resources are stored in the {@link $dblink} global. These |
1252
|
|
|
* resources are created by {@link setup_db_connections()}, which is called if |
1253
|
|
|
* no links exist. |
1254
|
|
|
* |
1255
|
|
|
* @param string $dblinktype The type of link we want: "read", "write" or "readwrite". |
1256
|
|
|
* |
1257
|
|
|
* @return resource Database link |
1258
|
|
|
* @access private |
1259
|
|
|
* @deprecated 1.9 |
1260
|
|
|
*/ |
1261
|
|
|
function get_db_link($dblinktype) { |
1262
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is a private function and should not be used.', 1.9); |
1263
|
|
|
return _elgg_services()->db->getLink($dblinktype); |
1264
|
|
|
} |
1265
|
|
|
|
1266
|
|
|
/** |
1267
|
|
|
* Optimize a table. |
1268
|
|
|
* |
1269
|
|
|
* Executes an OPTIMIZE TABLE query on $table. Useful after large DB changes. |
1270
|
|
|
* |
1271
|
|
|
* @param string $table The name of the table to optimise |
1272
|
|
|
* |
1273
|
|
|
* @return bool |
1274
|
|
|
* @access private |
1275
|
|
|
* @deprecated 1.9 |
1276
|
|
|
*/ |
1277
|
|
|
function optimize_table($table) { |
1278
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is a private function and should not be used.', 1.9); |
1279
|
|
|
$table = sanitise_string($table); |
1280
|
|
|
return _elgg_services()->db->updateData("OPTIMIZE TABLE $table"); |
1281
|
|
|
} |
1282
|
|
|
|
1283
|
|
|
/** |
1284
|
|
|
* Return tables matching the database prefix {@link $CONFIG->dbprefix}% in the currently |
1285
|
|
|
* selected database. |
1286
|
|
|
* |
1287
|
|
|
* @return array|false List of tables or false on failure |
1288
|
|
|
* @static array $tables Tables found matching the database prefix |
1289
|
|
|
* @access private |
1290
|
|
|
* @deprecated 1.9 |
1291
|
|
|
*/ |
1292
|
|
|
function get_db_tables() { |
1293
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is a private function and should not be used.', 1.9); |
1294
|
|
|
static $tables; |
1295
|
|
|
|
1296
|
|
|
if (isset($tables)) { |
1297
|
|
|
return $tables; |
1298
|
|
|
} |
1299
|
|
|
|
1300
|
|
|
$table_prefix = elgg_get_config('dbprefix'); |
1301
|
|
|
$result = get_data("SHOW TABLES LIKE '$table_prefix%'"); |
1302
|
|
|
|
1303
|
|
|
$tables = array(); |
1304
|
|
View Code Duplication |
if (is_array($result) && !empty($result)) { |
1305
|
|
|
foreach ($result as $row) { |
1306
|
|
|
$row = (array) $row; |
1307
|
|
|
if (is_array($row) && !empty($row)) { |
1308
|
|
|
foreach ($row as $element) { |
1309
|
|
|
$tables[] = $element; |
1310
|
|
|
} |
1311
|
|
|
} |
1312
|
|
|
} |
1313
|
|
|
} |
1314
|
|
|
|
1315
|
|
|
return $tables; |
1316
|
|
|
} |
1317
|
|
|
|
1318
|
|
|
/** |
1319
|
|
|
* Get the last database error for a particular database link |
1320
|
|
|
* |
1321
|
|
|
* @param resource $dblink The DB link |
1322
|
|
|
* |
1323
|
|
|
* @return string Database error message |
1324
|
|
|
* @access private |
1325
|
|
|
* @deprecated 1.9 |
1326
|
|
|
*/ |
1327
|
|
|
function get_db_error($dblink) { |
1328
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is a private function and should not be used.', 1.9); |
1329
|
|
|
return mysql_error($dblink); |
1330
|
|
|
} |
1331
|
|
|
|
1332
|
|
|
/** |
1333
|
|
|
* Queue a query for execution upon shutdown. |
1334
|
|
|
* |
1335
|
|
|
* You can specify a handler function if you care about the result. This function will accept |
1336
|
|
|
* the raw result from {@link mysql_query()}. |
1337
|
|
|
* |
1338
|
|
|
* @param string $query The query to execute |
1339
|
|
|
* @param resource $dblink The database link to use or the link type (read | write) |
1340
|
|
|
* @param string $handler A callback function to pass the results array to |
1341
|
|
|
* |
1342
|
|
|
* @return boolean Whether successful. |
1343
|
|
|
* @deprecated 1.9 Use execute_delayed_write_query() or execute_delayed_read_query() |
1344
|
|
|
*/ |
1345
|
|
|
function execute_delayed_query($query, $dblink, $handler = "") { |
1346
|
|
|
elgg_deprecated_notice("execute_delayed_query() has been deprecated", 1.9); |
1347
|
|
|
return _elgg_services()->db->registerDelayedQuery($query, $dblink, $handler); |
|
|
|
|
1348
|
|
|
} |
1349
|
|
|
|
1350
|
|
|
/** |
1351
|
|
|
* Return a timestamp for the start of a given day (defaults today). |
1352
|
|
|
* |
1353
|
|
|
* @param int $day Day |
1354
|
|
|
* @param int $month Month |
1355
|
|
|
* @param int $year Year |
1356
|
|
|
* |
1357
|
|
|
* @return int |
1358
|
|
|
* @access private |
1359
|
|
|
* @deprecated 1.9 |
1360
|
|
|
*/ |
1361
|
|
|
function get_day_start($day = null, $month = null, $year = null) { |
1362
|
|
|
elgg_deprecated_notice('get_day_start() has been deprecated', 1.9); |
1363
|
|
|
return mktime(0, 0, 0, $month, $day, $year); |
1364
|
|
|
} |
1365
|
|
|
|
1366
|
|
|
/** |
1367
|
|
|
* Return a timestamp for the end of a given day (defaults today). |
1368
|
|
|
* |
1369
|
|
|
* @param int $day Day |
1370
|
|
|
* @param int $month Month |
1371
|
|
|
* @param int $year Year |
1372
|
|
|
* |
1373
|
|
|
* @return int |
1374
|
|
|
* @access private |
1375
|
|
|
* @deprecated 1.9 |
1376
|
|
|
*/ |
1377
|
|
|
function get_day_end($day = null, $month = null, $year = null) { |
1378
|
|
|
elgg_deprecated_notice('get_day_end() has been deprecated', 1.9); |
1379
|
|
|
return mktime(23, 59, 59, $month, $day, $year); |
1380
|
|
|
} |
1381
|
|
|
|
1382
|
|
|
/** |
1383
|
|
|
* Return the notable entities for a given time period. |
1384
|
|
|
* |
1385
|
|
|
* @todo this function also accepts an array(type => subtypes) for 3rd arg. Should we document this? |
1386
|
|
|
* |
1387
|
|
|
* @param int $start_time The start time as a unix timestamp. |
1388
|
|
|
* @param int $end_time The end time as a unix timestamp. |
1389
|
|
|
* @param string $type The type of entity (eg "user", "object" etc) |
1390
|
|
|
* @param string $subtype The arbitrary subtype of the entity |
1391
|
|
|
* @param int $owner_guid The GUID of the owning user |
1392
|
|
|
* @param string $order_by The field to order by; by default, time_created desc |
1393
|
|
|
* @param int $limit The number of entities to return; 10 by default |
1394
|
|
|
* @param int $offset The indexing offset, 0 by default |
1395
|
|
|
* @param boolean $count Set to true to get a count instead of entities. Defaults to false. |
1396
|
|
|
* @param int $site_guid Site to get entities for. Default 0 = current site. -1 = any. |
1397
|
|
|
* @param mixed $container_guid Container or containers to get entities from (default: any). |
1398
|
|
|
* |
1399
|
|
|
* @return array|false |
1400
|
|
|
* @access private |
1401
|
|
|
* @deprecated 1.9 |
1402
|
|
|
*/ |
1403
|
|
|
function get_notable_entities($start_time, $end_time, $type = "", $subtype = "", $owner_guid = 0, |
1404
|
|
|
$order_by = "asc", $limit = 10, $offset = 0, $count = false, $site_guid = 0, |
1405
|
|
|
$container_guid = null) { |
1406
|
|
|
elgg_deprecated_notice('get_notable_entities() has been deprecated', 1.9); |
1407
|
|
|
global $CONFIG; |
1408
|
|
|
|
1409
|
|
View Code Duplication |
if ($subtype === false || $subtype === null || $subtype === 0) { |
|
|
|
|
1410
|
|
|
return false; |
1411
|
|
|
} |
1412
|
|
|
|
1413
|
|
|
$start_time = (int)$start_time; |
1414
|
|
|
$end_time = (int)$end_time; |
1415
|
|
|
$order_by = sanitise_string($order_by); |
1416
|
|
|
$limit = (int)$limit; |
1417
|
|
|
$offset = (int)$offset; |
1418
|
|
|
$site_guid = (int) $site_guid; |
1419
|
|
|
if ($site_guid == 0) { |
1420
|
|
|
$site_guid = $CONFIG->site_guid; |
1421
|
|
|
} |
1422
|
|
|
|
1423
|
|
|
$where = array(); |
1424
|
|
|
|
1425
|
|
|
if (is_array($type)) { |
1426
|
|
|
$tempwhere = ""; |
1427
|
|
View Code Duplication |
if (sizeof($type)) { |
1428
|
|
|
foreach ($type as $typekey => $subtypearray) { |
1429
|
|
|
foreach ($subtypearray as $subtypeval) { |
1430
|
|
|
$typekey = sanitise_string($typekey); |
1431
|
|
|
if (!empty($subtypeval)) { |
1432
|
|
|
$subtypeval = (int) get_subtype_id($typekey, $subtypeval); |
1433
|
|
|
} else { |
1434
|
|
|
$subtypeval = 0; |
1435
|
|
|
} |
1436
|
|
|
if (!empty($tempwhere)) { |
1437
|
|
|
$tempwhere .= " or "; |
1438
|
|
|
} |
1439
|
|
|
$tempwhere .= "(e.type = '{$typekey}' and e.subtype = {$subtypeval})"; |
1440
|
|
|
} |
1441
|
|
|
} |
1442
|
|
|
} |
1443
|
|
|
if (!empty($tempwhere)) { |
1444
|
|
|
$where[] = "({$tempwhere})"; |
1445
|
|
|
} |
1446
|
|
|
} else { |
1447
|
|
|
$type = sanitise_string($type); |
1448
|
|
|
$subtype = get_subtype_id($type, $subtype); |
1449
|
|
|
|
1450
|
|
|
if ($type != "") { |
1451
|
|
|
$where[] = "e.type='$type'"; |
1452
|
|
|
} |
1453
|
|
|
|
1454
|
|
|
if ($subtype !== "") { |
|
|
|
|
1455
|
|
|
$where[] = "e.subtype=$subtype"; |
1456
|
|
|
} |
1457
|
|
|
} |
1458
|
|
|
|
1459
|
|
|
if ($owner_guid != "") { |
1460
|
|
View Code Duplication |
if (!is_array($owner_guid)) { |
1461
|
|
|
$owner_array = array($owner_guid); |
1462
|
|
|
$owner_guid = (int) $owner_guid; |
1463
|
|
|
$where[] = "e.owner_guid = '$owner_guid'"; |
1464
|
|
|
} else if (sizeof($owner_guid) > 0) { |
1465
|
|
|
$owner_array = array_map('sanitise_int', $owner_guid); |
1466
|
|
|
// Cast every element to the owner_guid array to int |
1467
|
|
|
$owner_guid = implode(",", $owner_guid); |
1468
|
|
|
$where[] = "e.owner_guid in ({$owner_guid})"; |
1469
|
|
|
} |
1470
|
|
|
if (is_null($container_guid)) { |
1471
|
|
|
$container_guid = $owner_array; |
|
|
|
|
1472
|
|
|
} |
1473
|
|
|
} |
1474
|
|
|
|
1475
|
|
|
if ($site_guid > 0) { |
1476
|
|
|
$where[] = "e.site_guid = {$site_guid}"; |
1477
|
|
|
} |
1478
|
|
|
|
1479
|
|
View Code Duplication |
if (!is_null($container_guid)) { |
1480
|
|
|
if (is_array($container_guid)) { |
1481
|
|
|
foreach ($container_guid as $key => $val) { |
1482
|
|
|
$container_guid[$key] = (int) $val; |
1483
|
|
|
} |
1484
|
|
|
$where[] = "e.container_guid in (" . implode(",", $container_guid) . ")"; |
1485
|
|
|
} else { |
1486
|
|
|
$container_guid = (int) $container_guid; |
1487
|
|
|
$where[] = "e.container_guid = {$container_guid}"; |
1488
|
|
|
} |
1489
|
|
|
} |
1490
|
|
|
|
1491
|
|
|
// Add the calendar stuff |
1492
|
|
|
$cal_join = " |
1493
|
|
|
JOIN {$CONFIG->dbprefix}metadata cal_start on e.guid=cal_start.entity_guid |
1494
|
|
|
JOIN {$CONFIG->dbprefix}metastrings cal_start_name on cal_start.name_id=cal_start_name.id |
1495
|
|
|
JOIN {$CONFIG->dbprefix}metastrings cal_start_value on cal_start.value_id=cal_start_value.id |
1496
|
|
|
|
1497
|
|
|
JOIN {$CONFIG->dbprefix}metadata cal_end on e.guid=cal_end.entity_guid |
1498
|
|
|
JOIN {$CONFIG->dbprefix}metastrings cal_end_name on cal_end.name_id=cal_end_name.id |
1499
|
|
|
JOIN {$CONFIG->dbprefix}metastrings cal_end_value on cal_end.value_id=cal_end_value.id |
1500
|
|
|
"; |
1501
|
|
|
$where[] = "cal_start_name.string='calendar_start'"; |
1502
|
|
|
$where[] = "cal_start_value.string>=$start_time"; |
1503
|
|
|
$where[] = "cal_end_name.string='calendar_end'"; |
1504
|
|
|
$where[] = "cal_end_value.string <= $end_time"; |
1505
|
|
|
|
1506
|
|
|
|
1507
|
|
|
if (!$count) { |
1508
|
|
|
$query = "SELECT e.* from {$CONFIG->dbprefix}entities e $cal_join where "; |
1509
|
|
|
} else { |
1510
|
|
|
$query = "SELECT count(e.guid) as total from {$CONFIG->dbprefix}entities e $cal_join where "; |
1511
|
|
|
} |
1512
|
|
|
foreach ($where as $w) { |
1513
|
|
|
$query .= " $w and "; |
1514
|
|
|
} |
1515
|
|
|
|
1516
|
|
|
$query .= _elgg_get_access_where_sql(); |
1517
|
|
|
|
1518
|
|
View Code Duplication |
if (!$count) { |
1519
|
|
|
$query .= " order by n.calendar_start $order_by"; |
1520
|
|
|
// Add order and limit |
1521
|
|
|
if ($limit) { |
1522
|
|
|
$query .= " limit $offset, $limit"; |
1523
|
|
|
} |
1524
|
|
|
$dt = get_data($query, "entity_row_to_elggstar"); |
1525
|
|
|
|
1526
|
|
|
return $dt; |
1527
|
|
|
} else { |
1528
|
|
|
$total = get_data_row($query); |
1529
|
|
|
return $total->total; |
1530
|
|
|
} |
1531
|
|
|
} |
1532
|
|
|
|
1533
|
|
|
/** |
1534
|
|
|
* Return the notable entities for a given time period based on an item of metadata. |
1535
|
|
|
* |
1536
|
|
|
* @param int $start_time The start time as a unix timestamp. |
1537
|
|
|
* @param int $end_time The end time as a unix timestamp. |
1538
|
|
|
* @param mixed $meta_name Metadata name |
1539
|
|
|
* @param mixed $meta_value Metadata value |
1540
|
|
|
* @param string $entity_type The type of entity to look for, eg 'site' or 'object' |
1541
|
|
|
* @param string $entity_subtype The subtype of the entity. |
1542
|
|
|
* @param int $owner_guid Owner GUID |
1543
|
|
|
* @param int $limit Limit |
1544
|
|
|
* @param int $offset Offset |
1545
|
|
|
* @param string $order_by Optional ordering. |
1546
|
|
|
* @param int $site_guid Site to get entities for. Default 0 = current site. -1 = any. |
1547
|
|
|
* @param bool $count If true, returns count instead of entities. (Default: false) |
1548
|
|
|
* |
1549
|
|
|
* @return int|array A list of entities, or a count if $count is set to true |
1550
|
|
|
* @access private |
1551
|
|
|
* @deprecated 1.9 |
1552
|
|
|
*/ |
1553
|
|
|
function get_notable_entities_from_metadata($start_time, $end_time, $meta_name, $meta_value = "", |
1554
|
|
|
$entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", |
1555
|
|
|
$site_guid = 0, $count = false) { |
1556
|
|
|
elgg_deprecated_notice('get_notable_entities_from_metadata() has been deprecated', 1.9); |
1557
|
|
|
|
1558
|
|
|
global $CONFIG; |
1559
|
|
|
|
1560
|
|
|
$meta_n = get_metastring_id($meta_name); |
|
|
|
|
1561
|
|
|
$meta_v = get_metastring_id($meta_value); |
|
|
|
|
1562
|
|
|
|
1563
|
|
|
$start_time = (int)$start_time; |
1564
|
|
|
$end_time = (int)$end_time; |
1565
|
|
|
$entity_type = sanitise_string($entity_type); |
1566
|
|
|
$entity_subtype = get_subtype_id($entity_type, $entity_subtype); |
1567
|
|
|
$limit = (int)$limit; |
1568
|
|
|
$offset = (int)$offset; |
1569
|
|
|
if ($order_by == "") { |
1570
|
|
|
$order_by = "e.time_created desc"; |
1571
|
|
|
} |
1572
|
|
|
$order_by = sanitise_string($order_by); |
1573
|
|
|
$site_guid = (int) $site_guid; |
1574
|
|
View Code Duplication |
if ((is_array($owner_guid) && (count($owner_guid)))) { |
1575
|
|
|
foreach ($owner_guid as $key => $guid) { |
1576
|
|
|
$owner_guid[$key] = (int) $guid; |
1577
|
|
|
} |
1578
|
|
|
} else { |
1579
|
|
|
$owner_guid = (int) $owner_guid; |
1580
|
|
|
} |
1581
|
|
|
|
1582
|
|
|
if ($site_guid == 0) { |
1583
|
|
|
$site_guid = $CONFIG->site_guid; |
1584
|
|
|
} |
1585
|
|
|
|
1586
|
|
|
//$access = get_access_list(); |
1587
|
|
|
|
1588
|
|
|
$where = array(); |
1589
|
|
|
|
1590
|
|
|
if ($entity_type != "") { |
1591
|
|
|
$where[] = "e.type='$entity_type'"; |
1592
|
|
|
} |
1593
|
|
|
|
1594
|
|
|
if ($entity_subtype) { |
1595
|
|
|
$where[] = "e.subtype=$entity_subtype"; |
1596
|
|
|
} |
1597
|
|
|
|
1598
|
|
|
if ($meta_name != "") { |
1599
|
|
|
$where[] = "m.name_id='$meta_n'"; |
1600
|
|
|
} |
1601
|
|
|
|
1602
|
|
|
if ($meta_value != "") { |
1603
|
|
|
$where[] = "m.value_id='$meta_v'"; |
1604
|
|
|
} |
1605
|
|
|
|
1606
|
|
|
if ($site_guid > 0) { |
1607
|
|
|
$where[] = "e.site_guid = {$site_guid}"; |
1608
|
|
|
} |
1609
|
|
|
|
1610
|
|
View Code Duplication |
if (is_array($owner_guid)) { |
1611
|
|
|
$where[] = "e.container_guid in (" . implode(",", $owner_guid) . ")"; |
1612
|
|
|
} else if ($owner_guid > 0) { |
1613
|
|
|
$where[] = "e.container_guid = {$owner_guid}"; |
1614
|
|
|
} |
1615
|
|
|
|
1616
|
|
|
// Add the calendar stuff |
1617
|
|
|
$cal_join = " |
1618
|
|
|
JOIN {$CONFIG->dbprefix}metadata cal_start on e.guid=cal_start.entity_guid |
1619
|
|
|
JOIN {$CONFIG->dbprefix}metastrings cal_start_name on cal_start.name_id=cal_start_name.id |
1620
|
|
|
JOIN {$CONFIG->dbprefix}metastrings cal_start_value on cal_start.value_id=cal_start_value.id |
1621
|
|
|
|
1622
|
|
|
JOIN {$CONFIG->dbprefix}metadata cal_end on e.guid=cal_end.entity_guid |
1623
|
|
|
JOIN {$CONFIG->dbprefix}metastrings cal_end_name on cal_end.name_id=cal_end_name.id |
1624
|
|
|
JOIN {$CONFIG->dbprefix}metastrings cal_end_value on cal_end.value_id=cal_end_value.id |
1625
|
|
|
"; |
1626
|
|
|
|
1627
|
|
|
$where[] = "cal_start_name.string='calendar_start'"; |
1628
|
|
|
$where[] = "cal_start_value.string>=$start_time"; |
1629
|
|
|
$where[] = "cal_end_name.string='calendar_end'"; |
1630
|
|
|
$where[] = "cal_end_value.string <= $end_time"; |
1631
|
|
|
|
1632
|
|
|
if (!$count) { |
1633
|
|
|
$query = "SELECT distinct e.* "; |
1634
|
|
|
} else { |
1635
|
|
|
$query = "SELECT count(distinct e.guid) as total "; |
1636
|
|
|
} |
1637
|
|
|
|
1638
|
|
|
$query .= "from {$CONFIG->dbprefix}entities e" |
1639
|
|
|
. " JOIN {$CONFIG->dbprefix}metadata m on e.guid = m.entity_guid $cal_join where"; |
1640
|
|
|
|
1641
|
|
|
foreach ($where as $w) { |
1642
|
|
|
$query .= " $w and "; |
1643
|
|
|
} |
1644
|
|
|
|
1645
|
|
|
// Add access controls |
1646
|
|
|
$query .= _elgg_get_access_where_sql(array('table_alias' => 'e')); |
1647
|
|
|
$query .= ' and ' . _elgg_get_access_where_sql(array('table_alias' => "m")); |
1648
|
|
|
|
1649
|
|
|
if (!$count) { |
1650
|
|
|
// Add order and limit |
1651
|
|
|
$query .= " order by $order_by limit $offset, $limit"; |
1652
|
|
|
return get_data($query, "entity_row_to_elggstar"); |
1653
|
|
|
} else { |
1654
|
|
|
if ($row = get_data_row($query)) { |
1655
|
|
|
return $row->total; |
1656
|
|
|
} |
1657
|
|
|
} |
1658
|
|
|
|
1659
|
|
|
return false; |
1660
|
|
|
} |
1661
|
|
|
|
1662
|
|
|
/** |
1663
|
|
|
* Return the notable entities for a given time period based on their relationship. |
1664
|
|
|
* |
1665
|
|
|
* @param int $start_time The start time as a unix timestamp. |
1666
|
|
|
* @param int $end_time The end time as a unix timestamp. |
1667
|
|
|
* @param string $relationship The relationship eg "friends_of" |
1668
|
|
|
* @param int $relationship_guid The guid of the entity to use query |
1669
|
|
|
* @param bool $inverse_relationship Reverse the normal function of the query to say |
1670
|
|
|
* "give me all entities for whom $relationship_guid is a |
1671
|
|
|
* $relationship of" |
1672
|
|
|
* @param string $type Entity type |
1673
|
|
|
* @param string $subtype Entity subtype |
1674
|
|
|
* @param int $owner_guid Owner GUID |
1675
|
|
|
* @param string $order_by Optional Order by |
1676
|
|
|
* @param int $limit Limit |
1677
|
|
|
* @param int $offset Offset |
1678
|
|
|
* @param boolean $count If true returns a count of entities (default false) |
1679
|
|
|
* @param int $site_guid Site to get entities for. Default 0 = current site. -1 = any |
1680
|
|
|
* |
1681
|
|
|
* @return array|int|false An array of entities, or the number of entities, or false on failure |
1682
|
|
|
* @access private |
1683
|
|
|
* @deprecated 1.9 |
1684
|
|
|
*/ |
1685
|
|
|
function get_noteable_entities_from_relationship($start_time, $end_time, $relationship, |
1686
|
|
|
$relationship_guid, $inverse_relationship = false, $type = "", $subtype = "", $owner_guid = 0, |
1687
|
|
|
$order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0) { |
1688
|
|
|
elgg_deprecated_notice('get_noteable_entities_from_relationship() has been deprecated', 1.9); |
1689
|
|
|
|
1690
|
|
|
global $CONFIG; |
1691
|
|
|
|
1692
|
|
|
$start_time = (int)$start_time; |
1693
|
|
|
$end_time = (int)$end_time; |
1694
|
|
|
$relationship = sanitise_string($relationship); |
1695
|
|
|
$relationship_guid = (int)$relationship_guid; |
1696
|
|
|
$inverse_relationship = (bool)$inverse_relationship; |
1697
|
|
|
$type = sanitise_string($type); |
1698
|
|
|
$subtype = get_subtype_id($type, $subtype); |
1699
|
|
|
$owner_guid = (int)$owner_guid; |
1700
|
|
|
if ($order_by == "") { |
1701
|
|
|
$order_by = "time_created desc"; |
1702
|
|
|
} |
1703
|
|
|
$order_by = sanitise_string($order_by); |
1704
|
|
|
$limit = (int)$limit; |
1705
|
|
|
$offset = (int)$offset; |
1706
|
|
|
$site_guid = (int) $site_guid; |
1707
|
|
|
if ($site_guid == 0) { |
1708
|
|
|
$site_guid = $CONFIG->site_guid; |
1709
|
|
|
} |
1710
|
|
|
|
1711
|
|
|
//$access = get_access_list(); |
1712
|
|
|
|
1713
|
|
|
$where = array(); |
1714
|
|
|
|
1715
|
|
|
if ($relationship != "") { |
1716
|
|
|
$where[] = "r.relationship='$relationship'"; |
1717
|
|
|
} |
1718
|
|
|
if ($relationship_guid) { |
1719
|
|
|
$where[] = $inverse_relationship ? |
1720
|
|
|
"r.guid_two='$relationship_guid'" : "r.guid_one='$relationship_guid'"; |
1721
|
|
|
} |
1722
|
|
|
if ($type != "") { |
1723
|
|
|
$where[] = "e.type='$type'"; |
1724
|
|
|
} |
1725
|
|
|
if ($subtype) { |
1726
|
|
|
$where[] = "e.subtype=$subtype"; |
1727
|
|
|
} |
1728
|
|
|
if ($owner_guid != "") { |
1729
|
|
|
$where[] = "e.container_guid='$owner_guid'"; |
1730
|
|
|
} |
1731
|
|
|
if ($site_guid > 0) { |
1732
|
|
|
$where[] = "e.site_guid = {$site_guid}"; |
1733
|
|
|
} |
1734
|
|
|
|
1735
|
|
|
// Add the calendar stuff |
1736
|
|
|
$cal_join = " |
1737
|
|
|
JOIN {$CONFIG->dbprefix}metadata cal_start on e.guid=cal_start.entity_guid |
1738
|
|
|
JOIN {$CONFIG->dbprefix}metastrings cal_start_name on cal_start.name_id=cal_start_name.id |
1739
|
|
|
JOIN {$CONFIG->dbprefix}metastrings cal_start_value on cal_start.value_id=cal_start_value.id |
1740
|
|
|
|
1741
|
|
|
JOIN {$CONFIG->dbprefix}metadata cal_end on e.guid=cal_end.entity_guid |
1742
|
|
|
JOIN {$CONFIG->dbprefix}metastrings cal_end_name on cal_end.name_id=cal_end_name.id |
1743
|
|
|
JOIN {$CONFIG->dbprefix}metastrings cal_end_value on cal_end.value_id=cal_end_value.id |
1744
|
|
|
"; |
1745
|
|
|
$where[] = "cal_start_name.string='calendar_start'"; |
1746
|
|
|
$where[] = "cal_start_value.string>=$start_time"; |
1747
|
|
|
$where[] = "cal_end_name.string='calendar_end'"; |
1748
|
|
|
$where[] = "cal_end_value.string <= $end_time"; |
1749
|
|
|
|
1750
|
|
|
// Select what we're joining based on the options |
1751
|
|
|
$joinon = "e.guid = r.guid_one"; |
1752
|
|
|
if (!$inverse_relationship) { |
1753
|
|
|
$joinon = "e.guid = r.guid_two"; |
1754
|
|
|
} |
1755
|
|
|
|
1756
|
|
|
if ($count) { |
1757
|
|
|
$query = "SELECT count(distinct e.guid) as total "; |
1758
|
|
|
} else { |
1759
|
|
|
$query = "SELECT distinct e.* "; |
1760
|
|
|
} |
1761
|
|
|
$query .= " from {$CONFIG->dbprefix}entity_relationships r" |
1762
|
|
|
. " JOIN {$CONFIG->dbprefix}entities e on $joinon $cal_join where "; |
1763
|
|
|
|
1764
|
|
|
foreach ($where as $w) { |
1765
|
|
|
$query .= " $w and "; |
1766
|
|
|
} |
1767
|
|
|
// Add access controls |
1768
|
|
|
$query .= _elgg_get_access_where_sql(); |
1769
|
|
|
if (!$count) { |
1770
|
|
|
$query .= " order by $order_by limit $offset, $limit"; // Add order and limit |
1771
|
|
|
return get_data($query, "entity_row_to_elggstar"); |
1772
|
|
|
} else { |
1773
|
|
|
if ($count = get_data_row($query)) { |
1774
|
|
|
return $count->total; |
1775
|
|
|
} |
1776
|
|
|
} |
1777
|
|
|
return false; |
1778
|
|
|
} |
1779
|
|
|
|
1780
|
|
|
/** |
1781
|
|
|
* Get all entities for today. |
1782
|
|
|
* |
1783
|
|
|
* @param string $type The type of entity (eg "user", "object" etc) |
1784
|
|
|
* @param string $subtype The arbitrary subtype of the entity |
1785
|
|
|
* @param int $owner_guid The GUID of the owning user |
1786
|
|
|
* @param string $order_by The field to order by; by default, time_created desc |
1787
|
|
|
* @param int $limit The number of entities to return; 10 by default |
1788
|
|
|
* @param int $offset The indexing offset, 0 by default |
1789
|
|
|
* @param boolean $count If true returns a count of entities (default false) |
1790
|
|
|
* @param int $site_guid Site to get entities for. Default 0 = current site. -1 = any |
1791
|
|
|
* @param mixed $container_guid Container(s) to get entities from (default: any). |
1792
|
|
|
* |
1793
|
|
|
* @return array|false |
1794
|
|
|
* @access private |
1795
|
|
|
* @deprecated 1.9 |
1796
|
|
|
*/ |
1797
|
|
View Code Duplication |
function get_todays_entities($type = "", $subtype = "", $owner_guid = 0, $order_by = "", |
|
|
|
|
1798
|
|
|
$limit = 10, $offset = 0, $count = false, $site_guid = 0, $container_guid = null) { |
1799
|
|
|
elgg_deprecated_notice('get_todays_entities() has been deprecated', 1.9); |
1800
|
|
|
|
1801
|
|
|
$day_start = get_day_start(); |
|
|
|
|
1802
|
|
|
$day_end = get_day_end(); |
|
|
|
|
1803
|
|
|
|
1804
|
|
|
return get_notable_entities($day_start, $day_end, $type, $subtype, $owner_guid, $order_by, |
|
|
|
|
1805
|
|
|
$limit, $offset, $count, $site_guid, $container_guid); |
1806
|
|
|
} |
1807
|
|
|
|
1808
|
|
|
/** |
1809
|
|
|
* Get entities for today from metadata. |
1810
|
|
|
* |
1811
|
|
|
* @param mixed $meta_name Metadata name |
1812
|
|
|
* @param mixed $meta_value Metadata value |
1813
|
|
|
* @param string $entity_type The type of entity to look for, eg 'site' or 'object' |
1814
|
|
|
* @param string $entity_subtype The subtype of the entity. |
1815
|
|
|
* @param int $owner_guid Owner GUID |
1816
|
|
|
* @param int $limit Limit |
1817
|
|
|
* @param int $offset Offset |
1818
|
|
|
* @param string $order_by Optional ordering. |
1819
|
|
|
* @param int $site_guid Site to get entities for. Default 0 = current site. -1 = any. |
1820
|
|
|
* @param bool $count If true, returns count instead of entities. (Default: false) |
1821
|
|
|
* |
1822
|
|
|
* @return int|array A list of entities, or a count if $count is set to true |
1823
|
|
|
* @access private |
1824
|
|
|
* @deprecated 1.9 |
1825
|
|
|
*/ |
1826
|
|
View Code Duplication |
function get_todays_entities_from_metadata($meta_name, $meta_value = "", $entity_type = "", |
|
|
|
|
1827
|
|
|
$entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, |
1828
|
|
|
$count = false) { |
1829
|
|
|
elgg_deprecated_notice('get_todays_entities_from_metadata() has been deprecated', 1.9); |
1830
|
|
|
|
1831
|
|
|
$day_start = get_day_start(); |
|
|
|
|
1832
|
|
|
$day_end = get_day_end(); |
|
|
|
|
1833
|
|
|
|
1834
|
|
|
return get_notable_entities_from_metadata($day_start, $day_end, $meta_name, $meta_value, |
|
|
|
|
1835
|
|
|
$entity_type, $entity_subtype, $owner_guid, $limit, $offset, $order_by, $site_guid, $count); |
1836
|
|
|
} |
1837
|
|
|
|
1838
|
|
|
/** |
1839
|
|
|
* Get entities for today from a relationship |
1840
|
|
|
* |
1841
|
|
|
* @param string $relationship The relationship eg "friends_of" |
1842
|
|
|
* @param int $relationship_guid The guid of the entity to use query |
1843
|
|
|
* @param bool $inverse_relationship Reverse the normal function of the query to say |
1844
|
|
|
* "give me all entities for whom $relationship_guid is a |
1845
|
|
|
* $relationship of" |
1846
|
|
|
* @param string $type Entity type |
1847
|
|
|
* @param string $subtype Entity subtype |
1848
|
|
|
* @param int $owner_guid Owner GUID |
1849
|
|
|
* @param string $order_by Optional Order by |
1850
|
|
|
* @param int $limit Limit |
1851
|
|
|
* @param int $offset Offset |
1852
|
|
|
* @param boolean $count If true returns a count of entities (default false) |
1853
|
|
|
* @param int $site_guid Site to get entities for. Default 0 = current site. -1 = any |
1854
|
|
|
* |
1855
|
|
|
* @return array|int|false An array of entities, or the number of entities, or false on failure |
1856
|
|
|
* @access private |
1857
|
|
|
* @deprecated 1.9 |
1858
|
|
|
*/ |
1859
|
|
View Code Duplication |
function get_todays_entities_from_relationship($relationship, $relationship_guid, |
|
|
|
|
1860
|
|
|
$inverse_relationship = false, $type = "", $subtype = "", $owner_guid = 0, |
1861
|
|
|
$order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0) { |
1862
|
|
|
elgg_deprecated_notice('get_todays_entities_from_relationship() has been deprecated', 1.9); |
1863
|
|
|
|
1864
|
|
|
$day_start = get_day_start(); |
|
|
|
|
1865
|
|
|
$day_end = get_day_end(); |
|
|
|
|
1866
|
|
|
|
1867
|
|
|
return get_notable_entities_from_relationship($day_start, $day_end, $relationship, |
1868
|
|
|
$relationship_guid, $inverse_relationship, $type, $subtype, $owner_guid, $order_by, |
1869
|
|
|
$limit, $offset, $count, $site_guid); |
1870
|
|
|
} |
1871
|
|
|
|
1872
|
|
|
/** |
1873
|
|
|
* Returns a viewable list of entities for a given time period. |
1874
|
|
|
* |
1875
|
|
|
* @see elgg_view_entity_list |
1876
|
|
|
* |
1877
|
|
|
* @param int $start_time The start time as a unix timestamp. |
1878
|
|
|
* @param int $end_time The end time as a unix timestamp. |
1879
|
|
|
* @param string $type The type of entity (eg "user", "object" etc) |
1880
|
|
|
* @param string $subtype The arbitrary subtype of the entity |
1881
|
|
|
* @param int $owner_guid The GUID of the owning user |
1882
|
|
|
* @param int $limit The number of entities to return; 10 by default |
1883
|
|
|
* @param boolean $fullview Whether or not to display the full view (default: true) |
1884
|
|
|
* @param boolean $listtypetoggle Whether or not to allow gallery view |
1885
|
|
|
* @param boolean $navigation Display pagination? Default: true |
1886
|
|
|
* |
1887
|
|
|
* @return string A viewable list of entities |
1888
|
|
|
* @access private |
1889
|
|
|
* @deprecated 1.9 |
1890
|
|
|
*/ |
1891
|
|
|
function list_notable_entities($start_time, $end_time, $type= "", $subtype = "", $owner_guid = 0, |
1892
|
|
|
$limit = 10, $fullview = true, $listtypetoggle = false, $navigation = true) { |
1893
|
|
|
elgg_deprecated_notice('list_notable_entities() has been deprecated', 1.9); |
1894
|
|
|
|
1895
|
|
|
$offset = (int) get_input('offset'); |
1896
|
|
|
$count = get_notable_entities($start_time, $end_time, $type, $subtype, |
|
|
|
|
1897
|
|
|
$owner_guid, "", $limit, $offset, true); |
1898
|
|
|
|
1899
|
|
|
$entities = get_notable_entities($start_time, $end_time, $type, $subtype, |
|
|
|
|
1900
|
|
|
$owner_guid, "", $limit, $offset); |
1901
|
|
|
|
1902
|
|
|
return elgg_view_entity_list($entities, $count, $offset, $limit, |
|
|
|
|
1903
|
|
|
$fullview, $listtypetoggle, $navigation); |
1904
|
|
|
} |
1905
|
|
|
|
1906
|
|
|
/** |
1907
|
|
|
* Return a list of today's entities. |
1908
|
|
|
* |
1909
|
|
|
* @see list_notable_entities |
1910
|
|
|
* |
1911
|
|
|
* @param string $type The type of entity (eg "user", "object" etc) |
1912
|
|
|
* @param string $subtype The arbitrary subtype of the entity |
1913
|
|
|
* @param int $owner_guid The GUID of the owning user |
1914
|
|
|
* @param int $limit The number of entities to return; 10 by default |
1915
|
|
|
* @param boolean $fullview Whether or not to display the full view (default: true) |
1916
|
|
|
* @param boolean $listtypetoggle Whether or not to allow gallery view |
1917
|
|
|
* @param boolean $navigation Display pagination? Default: true |
1918
|
|
|
* |
1919
|
|
|
* @return string A viewable list of entities |
1920
|
|
|
* @access private |
1921
|
|
|
* @deprecated 1.9 |
1922
|
|
|
*/ |
1923
|
|
|
function list_todays_entities($type= "", $subtype = "", $owner_guid = 0, $limit = 10, |
1924
|
|
|
$fullview = true, $listtypetoggle = false, $navigation = true) { |
1925
|
|
|
elgg_deprecated_notice('list_todays_entities() has been deprecated', 1.9); |
1926
|
|
|
|
1927
|
|
|
$day_start = get_day_start(); |
|
|
|
|
1928
|
|
|
$day_end = get_day_end(); |
|
|
|
|
1929
|
|
|
|
1930
|
|
|
return list_notable_entities($day_start, $day_end, $type, $subtype, $owner_guid, $limit, |
|
|
|
|
1931
|
|
|
$fullview, $listtypetoggle, $navigation); |
1932
|
|
|
} |
1933
|
|
|
|
1934
|
|
|
/** |
1935
|
|
|
* Regenerates the simple cache. |
1936
|
|
|
* |
1937
|
|
|
* Not required any longer since cached files are created on demand. |
1938
|
|
|
* |
1939
|
|
|
* @warning This does not invalidate the cache, but actively rebuilds it. |
1940
|
|
|
* |
1941
|
|
|
* @param string $viewtype Optional viewtype to regenerate. Defaults to all valid viewtypes. |
1942
|
|
|
* |
1943
|
|
|
* @return void |
1944
|
|
|
* @since 1.8.0 |
1945
|
|
|
* @deprecated 1.9 Use elgg_invalidate_simplecache() |
1946
|
|
|
*/ |
1947
|
|
|
function elgg_regenerate_simplecache($viewtype = NULL) { |
1948
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_invalidate_simplecache()', 1.9); |
1949
|
|
|
elgg_invalidate_simplecache(); |
1950
|
|
|
} |
1951
|
|
|
|
1952
|
|
|
/** |
1953
|
|
|
* @access private |
1954
|
|
|
* @deprecated 1.9 Use elgg_get_system_cache() |
1955
|
|
|
*/ |
1956
|
|
|
function elgg_get_filepath_cache() { |
1957
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_get_system_cache()', 1.9); |
1958
|
|
|
return elgg_get_system_cache(); |
1959
|
|
|
} |
1960
|
|
|
/** |
1961
|
|
|
* @access private |
1962
|
|
|
* @deprecated 1.9 Use elgg_reset_system_cache() |
1963
|
|
|
*/ |
1964
|
|
|
function elgg_filepath_cache_reset() { |
1965
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_reset_system_cache()', 1.9); |
1966
|
|
|
elgg_reset_system_cache(); |
1967
|
|
|
} |
1968
|
|
|
/** |
1969
|
|
|
* @access private |
1970
|
|
|
* @deprecated 1.9 Use elgg_save_system_cache() |
1971
|
|
|
*/ |
1972
|
|
|
function elgg_filepath_cache_save($type, $data) { |
1973
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_save_system_cache()', 1.9); |
1974
|
|
|
return elgg_save_system_cache($type, $data); |
1975
|
|
|
} |
1976
|
|
|
/** |
1977
|
|
|
* @access private |
1978
|
|
|
* @deprecated 1.9 Use elgg_load_system_cache() |
1979
|
|
|
*/ |
1980
|
|
|
function elgg_filepath_cache_load($type) { |
1981
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_load_system_cache()', 1.9); |
1982
|
|
|
return elgg_load_system_cache($type); |
1983
|
|
|
} |
1984
|
|
|
/** |
1985
|
|
|
* @access private |
1986
|
|
|
* @deprecated 1.9 Use elgg_enable_system_cache() |
1987
|
|
|
*/ |
1988
|
|
|
function elgg_enable_filepath_cache() { |
1989
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_enable_system_cache()', 1.9); |
1990
|
|
|
elgg_enable_system_cache(); |
1991
|
|
|
} |
1992
|
|
|
/** |
1993
|
|
|
* @access private |
1994
|
|
|
* @deprecated 1.9 Use elgg_disable_system_cache() |
1995
|
|
|
*/ |
1996
|
|
|
function elgg_disable_filepath_cache() { |
1997
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_disable_system_cache()', 1.9); |
1998
|
|
|
elgg_disable_system_cache(); |
1999
|
|
|
} |
2000
|
|
|
|
2001
|
|
|
/** |
2002
|
|
|
* Unregisters an entity type and subtype as a public-facing type. |
2003
|
|
|
* |
2004
|
|
|
* @warning With a blank subtype, it unregisters that entity type including |
2005
|
|
|
* all subtypes. This must be called after all subtypes have been registered. |
2006
|
|
|
* |
2007
|
|
|
* @param string $type The type of entity (object, site, user, group) |
2008
|
|
|
* @param string $subtype The subtype to register (may be blank) |
2009
|
|
|
* |
2010
|
|
|
* @return true|false Depending on success |
2011
|
|
|
* @deprecated 1.9 Use {@link elgg_unregister_entity_type()} |
2012
|
|
|
*/ |
2013
|
|
|
function unregister_entity_type($type, $subtype) { |
2014
|
|
|
elgg_deprecated_notice("unregister_entity_type() was deprecated by elgg_unregister_entity_type()", 1.9); |
2015
|
|
|
return elgg_unregister_entity_type($type, $subtype); |
2016
|
|
|
} |
2017
|
|
|
|
2018
|
|
|
/** |
2019
|
|
|
* Function to determine if the object trying to attach to other, has already done so |
2020
|
|
|
* |
2021
|
|
|
* @param int $guid_one This is the target object |
2022
|
|
|
* @param int $guid_two This is the object trying to attach to $guid_one |
2023
|
|
|
* |
2024
|
|
|
* @return bool |
2025
|
|
|
* @access private |
2026
|
|
|
* @deprecated 1.9 Use check_entity_relationship() |
2027
|
|
|
*/ |
2028
|
|
|
function already_attached($guid_one, $guid_two) { |
2029
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); |
2030
|
|
|
if ($attached = check_entity_relationship($guid_one, "attached", $guid_two)) { |
|
|
|
|
2031
|
|
|
return true; |
2032
|
|
|
} else { |
2033
|
|
|
return false; |
2034
|
|
|
} |
2035
|
|
|
} |
2036
|
|
|
|
2037
|
|
|
/** |
2038
|
|
|
* Function to get all objects attached to a particular object |
2039
|
|
|
* |
2040
|
|
|
* @param int $guid Entity GUID |
2041
|
|
|
* @param string $type The type of object to return e.g. 'file', 'friend_of' etc |
2042
|
|
|
* |
2043
|
|
|
* @return ElggObject[] array of objects |
2044
|
|
|
* @access private |
2045
|
|
|
* @deprecated 1.9 Use elgg_get_entities_from_relationship() |
2046
|
|
|
*/ |
2047
|
|
|
function get_attachments($guid, $type = "") { |
2048
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); |
2049
|
|
|
$options = array( |
2050
|
|
|
'relationship' => 'attached', |
2051
|
|
|
'relationship_guid' => $guid, |
2052
|
|
|
'inverse_relationship' => false, |
2053
|
|
|
'types' => $type, |
2054
|
|
|
'subtypes' => '', |
2055
|
|
|
'owner_guid' => 0, |
2056
|
|
|
'order_by' => 'time_created desc', |
2057
|
|
|
'limit' => 10, |
2058
|
|
|
'offset' => 0, |
2059
|
|
|
'count' => false, |
2060
|
|
|
'site_guid' => 0 |
2061
|
|
|
); |
2062
|
|
|
$attached = elgg_get_entities_from_relationship($options); |
2063
|
|
|
return $attached; |
2064
|
|
|
} |
2065
|
|
|
|
2066
|
|
|
/** |
2067
|
|
|
* Function to remove a particular attachment between two objects |
2068
|
|
|
* |
2069
|
|
|
* @param int $guid_one This is the target object |
2070
|
|
|
* @param int $guid_two This is the object to remove from $guid_one |
2071
|
|
|
* |
2072
|
|
|
* @return void |
2073
|
|
|
* @access private |
2074
|
|
|
* @deprecated 1.9 Use remove_entity_relationship() |
2075
|
|
|
*/ |
2076
|
|
|
function remove_attachment($guid_one, $guid_two) { |
2077
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); |
2078
|
|
|
if (already_attached($guid_one, $guid_two)) { |
|
|
|
|
2079
|
|
|
remove_entity_relationship($guid_one, "attached", $guid_two); |
2080
|
|
|
} |
2081
|
|
|
} |
2082
|
|
|
|
2083
|
|
|
/** |
2084
|
|
|
* Function to start the process of attaching one object to another |
2085
|
|
|
* |
2086
|
|
|
* @param int $guid_one This is the target object |
2087
|
|
|
* @param int $guid_two This is the object trying to attach to $guid_one |
2088
|
|
|
* |
2089
|
|
|
* @return true|void |
2090
|
|
|
* @access private |
2091
|
|
|
* @deprecated 1.9 Use add_entity_relationship() |
2092
|
|
|
*/ |
2093
|
|
|
function make_attachment($guid_one, $guid_two) { |
2094
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); |
2095
|
|
|
if (!(already_attached($guid_one, $guid_two))) { |
|
|
|
|
2096
|
|
|
if (add_entity_relationship($guid_one, "attached", $guid_two)) { |
2097
|
|
|
return true; |
2098
|
|
|
} |
2099
|
|
|
} |
2100
|
|
|
} |
2101
|
|
|
|
2102
|
|
|
/** |
2103
|
|
|
* Returns the URL for an entity. |
2104
|
|
|
* |
2105
|
|
|
* @param int $entity_guid The GUID of the entity |
2106
|
|
|
* |
2107
|
|
|
* @return string The URL of the entity |
2108
|
|
|
* @deprecated 1.9 Use \ElggEntity::getURL() |
2109
|
|
|
*/ |
2110
|
|
|
function get_entity_url($entity_guid) { |
2111
|
|
|
elgg_deprecated_notice('get_entity_url has been deprecated in favor of \ElggEntity::getURL', '1.9'); |
2112
|
|
|
if ($entity = get_entity($entity_guid)) { |
2113
|
|
|
return $entity->getURL(); |
2114
|
|
|
} |
2115
|
|
|
|
2116
|
|
|
return false; |
2117
|
|
|
} |
2118
|
|
|
|
2119
|
|
|
/** |
2120
|
|
|
* Delete an entity. |
2121
|
|
|
* |
2122
|
|
|
* Removes an entity and its metadata, annotations, relationships, river entries, |
2123
|
|
|
* and private data. |
2124
|
|
|
* |
2125
|
|
|
* Optionally can remove entities contained and owned by $guid. |
2126
|
|
|
* |
2127
|
|
|
* @warning If deleting recursively, this bypasses ownership of items contained by |
2128
|
|
|
* the entity. That means that if the container_guid = $guid, the item will be deleted |
2129
|
|
|
* regardless of who owns it. |
2130
|
|
|
* |
2131
|
|
|
* @param int $guid The guid of the entity to delete |
2132
|
|
|
* @param bool $recursive If true (default) then all entities which are |
2133
|
|
|
* owned or contained by $guid will also be deleted. |
2134
|
|
|
* |
2135
|
|
|
* @return bool |
2136
|
|
|
* @access private |
2137
|
|
|
* @deprecated 1.9 Use \ElggEntity::delete() instead. |
2138
|
|
|
*/ |
2139
|
|
View Code Duplication |
function delete_entity($guid, $recursive = true) { |
|
|
|
|
2140
|
|
|
elgg_deprecated_notice('delete_entity has been deprecated in favor of \ElggEntity::delete', '1.9'); |
2141
|
|
|
$guid = (int)$guid; |
2142
|
|
|
if ($entity = get_entity($guid)) { |
2143
|
|
|
return $entity->delete($recursive); |
2144
|
|
|
} |
2145
|
|
|
return false; |
2146
|
|
|
} |
2147
|
|
|
|
2148
|
|
|
/** |
2149
|
|
|
* Enable an entity. |
2150
|
|
|
* |
2151
|
|
|
* @warning In order to enable an entity using \ElggEntity::enable(), |
2152
|
|
|
* you must first use {@link access_show_hidden_entities()}. |
2153
|
|
|
* |
2154
|
|
|
* @param int $guid GUID of entity to enable |
2155
|
|
|
* @param bool $recursive Recursively enable all entities disabled with the entity? |
2156
|
|
|
* |
2157
|
|
|
* @return bool |
2158
|
|
|
* @deprecated 1.9 Use elgg_enable_entity() |
2159
|
|
|
*/ |
2160
|
|
|
function enable_entity($guid, $recursive = true) { |
2161
|
|
|
elgg_deprecated_notice('enable_entity has been deprecated in favor of elgg_enable_entity', '1.9'); |
2162
|
|
|
|
2163
|
|
|
$guid = (int)$guid; |
2164
|
|
|
|
2165
|
|
|
// Override access only visible entities |
2166
|
|
|
$old_access_status = access_get_show_hidden_status(); |
2167
|
|
|
access_show_hidden_entities(true); |
2168
|
|
|
|
2169
|
|
|
$result = false; |
2170
|
|
|
if ($entity = get_entity($guid)) { |
2171
|
|
|
$result = $entity->enable($recursive); |
2172
|
|
|
} |
2173
|
|
|
|
2174
|
|
|
access_show_hidden_entities($old_access_status); |
2175
|
|
|
return $result; |
2176
|
|
|
} |
2177
|
|
|
|
2178
|
|
|
/** |
2179
|
|
|
* Returns if $user_guid can edit the metadata on $entity_guid. |
2180
|
|
|
* |
2181
|
|
|
* @tip Can be overridden by by registering for the permissions_check:metadata |
2182
|
|
|
* plugin hook. |
2183
|
|
|
* |
2184
|
|
|
* @warning If a $user_guid isn't specified, the currently logged in user is used. |
2185
|
|
|
* |
2186
|
|
|
* @param int $entity_guid The GUID of the entity |
2187
|
|
|
* @param int $user_guid The GUID of the user |
2188
|
|
|
* @param \ElggMetadata $metadata The metadata to specifically check (if any; default null) |
2189
|
|
|
* |
2190
|
|
|
* @return bool Whether the user can edit metadata on the entity. |
2191
|
|
|
* @deprecated 1.9 Use \ElggEntity::canEditMetadata |
2192
|
|
|
*/ |
2193
|
|
|
function can_edit_entity_metadata($entity_guid, $user_guid = 0, $metadata = null) { |
2194
|
|
|
elgg_deprecated_notice('can_edit_entity_metadata has been deprecated in favor of \ElggEntity::canEditMetadata', '1.9'); |
2195
|
|
|
if ($entity = get_entity($entity_guid)) { |
2196
|
|
|
return $entity->canEditMetadata($metadata, $user_guid); |
2197
|
|
|
} else { |
2198
|
|
|
return false; |
2199
|
|
|
} |
2200
|
|
|
} |
2201
|
|
|
|
2202
|
|
|
/** |
2203
|
|
|
* Disable an entity. |
2204
|
|
|
* |
2205
|
|
|
* Disabled entities do not show up in list or elgg_get_entities() |
2206
|
|
|
* calls, but still exist in the database. |
2207
|
|
|
* |
2208
|
|
|
* Entities are disabled by setting disabled = yes in the |
2209
|
|
|
* entities table. |
2210
|
|
|
* |
2211
|
|
|
* You can ignore the disabled field by using {@link access_show_hidden_entities()}. |
2212
|
|
|
* |
2213
|
|
|
* @param int $guid The guid |
2214
|
|
|
* @param string $reason Optional reason |
2215
|
|
|
* @param bool $recursive Recursively disable all entities owned or contained by $guid? |
2216
|
|
|
* |
2217
|
|
|
* @return bool |
2218
|
|
|
* @see access_show_hidden_entities() |
2219
|
|
|
* @access private |
2220
|
|
|
* @deprecated 1.9 Use \ElggEntity::disable instead. |
2221
|
|
|
*/ |
2222
|
|
View Code Duplication |
function disable_entity($guid, $reason = "", $recursive = true) { |
|
|
|
|
2223
|
|
|
elgg_deprecated_notice('disable_entity was deprecated in favor of \ElggEntity::disable', '1.9'); |
2224
|
|
|
|
2225
|
|
|
if ($entity = get_entity($guid)) { |
2226
|
|
|
return $entity->disable($reason, $recursive); |
2227
|
|
|
} |
2228
|
|
|
|
2229
|
|
|
return false; |
2230
|
|
|
} |
2231
|
|
|
|
2232
|
|
|
/** |
2233
|
|
|
* Returns if $user_guid is able to edit $entity_guid. |
2234
|
|
|
* |
2235
|
|
|
* @tip Can be overridden by registering for the permissions_check plugin hook. |
2236
|
|
|
* |
2237
|
|
|
* @warning If a $user_guid is not passed it will default to the logged in user. |
2238
|
|
|
* |
2239
|
|
|
* @param int $entity_guid The GUID of the entity |
2240
|
|
|
* @param int $user_guid The GUID of the user |
2241
|
|
|
* |
2242
|
|
|
* @return bool |
2243
|
|
|
* @deprecated 1.9 Use \ElggEntity::canEdit instead |
2244
|
|
|
*/ |
2245
|
|
|
function can_edit_entity($entity_guid, $user_guid = 0) { |
2246
|
|
|
elgg_deprecated_notice('can_edit_entity was deprecated in favor of \ElggEntity::canEdit', '1.9'); |
2247
|
|
|
if ($entity = get_entity($entity_guid)) { |
2248
|
|
|
return $entity->canEdit($user_guid); |
2249
|
|
|
} |
2250
|
|
|
|
2251
|
|
|
return false; |
2252
|
|
|
} |
2253
|
|
|
|
2254
|
|
|
/** |
2255
|
|
|
* Join a user to a group. |
2256
|
|
|
* |
2257
|
|
|
* @param int $group_guid The group GUID. |
2258
|
|
|
* @param int $user_guid The user GUID. |
2259
|
|
|
* |
2260
|
|
|
* @return bool |
2261
|
|
|
* @deprecated 1.9 Use \ElggGroup::join instead. |
2262
|
|
|
*/ |
2263
|
|
View Code Duplication |
function join_group($group_guid, $user_guid) { |
|
|
|
|
2264
|
|
|
elgg_deprecated_notice('join_group was deprecated in favor of \ElggGroup::join', '1.9'); |
2265
|
|
|
|
2266
|
|
|
$group = get_entity($group_guid); |
2267
|
|
|
$user = get_entity($user_guid); |
2268
|
|
|
|
2269
|
|
|
if ($group instanceof \ElggGroup && $user instanceof \ElggUser) { |
2270
|
|
|
return $group->join($user); |
2271
|
|
|
} |
2272
|
|
|
|
2273
|
|
|
return false; |
2274
|
|
|
} |
2275
|
|
|
|
2276
|
|
|
/** |
2277
|
|
|
* Remove a user from a group. |
2278
|
|
|
* |
2279
|
|
|
* @param int $group_guid The group. |
2280
|
|
|
* @param int $user_guid The user. |
2281
|
|
|
* |
2282
|
|
|
* @return bool Whether the user was removed from the group. |
2283
|
|
|
* @deprecated 1.9 Use \ElggGroup::leave() |
2284
|
|
|
*/ |
2285
|
|
View Code Duplication |
function leave_group($group_guid, $user_guid) { |
|
|
|
|
2286
|
|
|
elgg_deprecated_notice('leave_group was deprecated in favor of \ElggGroup::leave', '1.9'); |
2287
|
|
|
$group = get_entity($group_guid); |
2288
|
|
|
$user = get_entity($user_guid); |
2289
|
|
|
|
2290
|
|
|
if ($group instanceof \ElggGroup && $user instanceof \ElggUser) { |
2291
|
|
|
return $group->leave($user); |
2292
|
|
|
} |
2293
|
|
|
|
2294
|
|
|
return false; |
2295
|
|
|
} |
2296
|
|
|
|
2297
|
|
|
/** |
2298
|
|
|
* Create paragraphs from text with line spacing |
2299
|
|
|
* |
2300
|
|
|
* @param string $string The string |
2301
|
|
|
* @return string |
2302
|
|
|
* @deprecated 1.9 Use elgg_autop instead |
2303
|
|
|
**/ |
2304
|
|
|
function autop($string) { |
2305
|
|
|
elgg_deprecated_notice('autop has been deprecated in favor of elgg_autop', '1.9'); |
2306
|
|
|
return elgg_autop($string); |
2307
|
|
|
} |
2308
|
|
|
|
2309
|
|
|
/** |
2310
|
|
|
* Register a function as a web service method |
2311
|
|
|
* |
2312
|
|
|
* @deprecated 1.9 Enable the web services plugin and use elgg_ws_expose_function(). |
2313
|
|
|
*/ |
2314
|
|
|
function expose_function($method, $function, array $parameters = NULL, $description = "", |
2315
|
|
|
$call_method = "GET", $require_api_auth = false, $require_user_auth = false) { |
2316
|
|
|
elgg_deprecated_notice("expose_function() deprecated for the function elgg_ws_expose_function() in web_services plugin", 1.9); |
2317
|
|
|
if (!elgg_admin_notice_exists("elgg:ws:1.9")) { |
2318
|
|
|
elgg_add_admin_notice("elgg:ws:1.9", "The web services are now a plugin in Elgg 1.9. |
2319
|
|
|
You must enable this plugin and update your web services to use elgg_ws_expose_function()."); |
2320
|
|
|
} |
2321
|
|
|
|
2322
|
|
|
if (function_exists("elgg_ws_expose_function")) { |
2323
|
|
|
return elgg_ws_expose_function($method, $function, $parameters, $description, $call_method, $require_api_auth, $require_user_auth); |
2324
|
|
|
} |
2325
|
|
|
} |
2326
|
|
|
|
2327
|
|
|
/** |
2328
|
|
|
* Unregister a web services method |
2329
|
|
|
* |
2330
|
|
|
* @param string $method The api name that was exposed |
2331
|
|
|
* @return void |
2332
|
|
|
* @deprecated 1.9 Enable the web services plugin and use elgg_ws_unexpose_function(). |
2333
|
|
|
*/ |
2334
|
|
|
function unexpose_function($method) { |
2335
|
|
|
elgg_deprecated_notice("unexpose_function() deprecated for the function elgg_ws_unexpose_function() in web_services plugin", 1.9); |
2336
|
|
|
if (function_exists("elgg_ws_unexpose_function")) { |
2337
|
|
|
return elgg_ws_unexpose_function($method); |
2338
|
|
|
} |
2339
|
|
|
} |
2340
|
|
|
|
2341
|
|
|
/** |
2342
|
|
|
* Registers a web services handler |
2343
|
|
|
* |
2344
|
|
|
* @param string $handler Web services type |
2345
|
|
|
* @param string $function Your function name |
2346
|
|
|
* @return bool Depending on success |
2347
|
|
|
* @deprecated 1.9 Enable the web services plugin and use elgg_ws_register_service_handler(). |
2348
|
|
|
*/ |
2349
|
|
|
function register_service_handler($handler, $function) { |
2350
|
|
|
elgg_deprecated_notice("register_service_handler() deprecated for the function elgg_ws_register_service_handler() in web_services plugin", 1.9); |
2351
|
|
|
if (function_exists("elgg_ws_register_service_handler")) { |
2352
|
|
|
return elgg_ws_register_service_handler($handler, $function); |
2353
|
|
|
} |
2354
|
|
|
} |
2355
|
|
|
|
2356
|
|
|
/** |
2357
|
|
|
* Remove a web service |
2358
|
|
|
* To replace a web service handler, register the desired handler over the old on |
2359
|
|
|
* with register_service_handler(). |
2360
|
|
|
* |
2361
|
|
|
* @param string $handler web services type |
2362
|
|
|
* @return void |
2363
|
|
|
* @deprecated 1.9 Enable the web services plugin and use elgg_ws_unregister_service_handler(). |
2364
|
|
|
*/ |
2365
|
|
|
function unregister_service_handler($handler) { |
2366
|
|
|
elgg_deprecated_notice("unregister_service_handler() deprecated for the function elgg_ws_unregister_service_handler() in web_services plugin", 1.9); |
2367
|
|
|
if (function_exists("elgg_ws_unregister_service_handler")) { |
2368
|
|
|
return elgg_ws_unregister_service_handler($handler); |
2369
|
|
|
} |
2370
|
|
|
} |
2371
|
|
|
|
2372
|
|
|
/** |
2373
|
|
|
* Create or update the entities table for a given site. |
2374
|
|
|
* Call create_entity first. |
2375
|
|
|
* |
2376
|
|
|
* @param int $guid Site GUID |
2377
|
|
|
* @param string $name Site name |
2378
|
|
|
* @param string $description Site Description |
2379
|
|
|
* @param string $url URL of the site |
2380
|
|
|
* |
2381
|
|
|
* @return bool |
2382
|
|
|
* @access private |
2383
|
|
|
* @deprecated 1.9 Use \ElggSite constructor |
2384
|
|
|
*/ |
2385
|
|
|
function create_site_entity($guid, $name, $description, $url) { |
2386
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggSite constructor', 1.9); |
2387
|
|
|
global $CONFIG; |
2388
|
|
|
|
2389
|
|
|
$guid = (int)$guid; |
2390
|
|
|
$name = sanitise_string($name); |
2391
|
|
|
$description = sanitise_string($description); |
2392
|
|
|
$url = sanitise_string($url); |
2393
|
|
|
|
2394
|
|
|
$row = get_entity_as_row($guid); |
2395
|
|
|
|
2396
|
|
View Code Duplication |
if ($row) { |
2397
|
|
|
// Exists and you have access to it |
2398
|
|
|
$query = "SELECT guid from {$CONFIG->dbprefix}sites_entity where guid = {$guid}"; |
2399
|
|
|
if ($exists = get_data_row($query)) { |
|
|
|
|
2400
|
|
|
$query = "UPDATE {$CONFIG->dbprefix}sites_entity |
2401
|
|
|
set name='$name', description='$description', url='$url' where guid=$guid"; |
2402
|
|
|
$result = update_data($query); |
2403
|
|
|
|
2404
|
|
|
if ($result != false) { |
2405
|
|
|
// Update succeeded, continue |
2406
|
|
|
$entity = get_entity($guid); |
2407
|
|
|
if (elgg_trigger_event('update', $entity->type, $entity)) { |
|
|
|
|
2408
|
|
|
return $guid; |
2409
|
|
|
} else { |
2410
|
|
|
$entity->delete(); |
2411
|
|
|
//delete_entity($guid); |
2412
|
|
|
} |
2413
|
|
|
} |
2414
|
|
|
} else { |
2415
|
|
|
// Update failed, attempt an insert. |
2416
|
|
|
$query = "INSERT into {$CONFIG->dbprefix}sites_entity |
2417
|
|
|
(guid, name, description, url) values ($guid, '$name', '$description', '$url')"; |
2418
|
|
|
$result = insert_data($query); |
2419
|
|
|
|
2420
|
|
|
if ($result !== false) { |
2421
|
|
|
$entity = get_entity($guid); |
2422
|
|
|
if (elgg_trigger_event('create', $entity->type, $entity)) { |
|
|
|
|
2423
|
|
|
return $guid; |
2424
|
|
|
} else { |
2425
|
|
|
$entity->delete(); |
2426
|
|
|
//delete_entity($guid); |
2427
|
|
|
} |
2428
|
|
|
} |
2429
|
|
|
} |
2430
|
|
|
} |
2431
|
|
|
|
2432
|
|
|
return false; |
2433
|
|
|
} |
2434
|
|
|
|
2435
|
|
|
/** |
2436
|
|
|
* Create or update the entities table for a given group. |
2437
|
|
|
* Call create_entity first. |
2438
|
|
|
* |
2439
|
|
|
* @param int $guid GUID |
2440
|
|
|
* @param string $name Name |
2441
|
|
|
* @param string $description Description |
2442
|
|
|
* |
2443
|
|
|
* @return bool |
2444
|
|
|
* @access private |
2445
|
|
|
* @deprecated 1.9 Use \ElggGroup constructor |
2446
|
|
|
*/ |
2447
|
|
|
function create_group_entity($guid, $name, $description) { |
2448
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggGroup constructor', 1.9); |
2449
|
|
|
global $CONFIG; |
2450
|
|
|
|
2451
|
|
|
$guid = (int)$guid; |
2452
|
|
|
$name = sanitise_string($name); |
2453
|
|
|
$description = sanitise_string($description); |
2454
|
|
|
|
2455
|
|
|
$row = get_entity_as_row($guid); |
2456
|
|
|
|
2457
|
|
|
if ($row) { |
2458
|
|
|
// Exists and you have access to it |
2459
|
|
|
$exists = get_data_row("SELECT guid from {$CONFIG->dbprefix}groups_entity WHERE guid = {$guid}"); |
2460
|
|
|
if ($exists) { |
|
|
|
|
2461
|
|
|
$query = "UPDATE {$CONFIG->dbprefix}groups_entity set" |
2462
|
|
|
. " name='$name', description='$description' where guid=$guid"; |
2463
|
|
|
$result = update_data($query); |
2464
|
|
|
if ($result != false) { |
2465
|
|
|
// Update succeeded, continue |
2466
|
|
|
$entity = get_entity($guid); |
2467
|
|
|
if (elgg_trigger_event('update', $entity->type, $entity)) { |
|
|
|
|
2468
|
|
|
return $guid; |
2469
|
|
|
} else { |
2470
|
|
|
$entity->delete(); |
2471
|
|
|
} |
2472
|
|
|
} |
2473
|
|
|
} else { |
2474
|
|
|
// Update failed, attempt an insert. |
2475
|
|
|
$query = "INSERT into {$CONFIG->dbprefix}groups_entity" |
2476
|
|
|
. " (guid, name, description) values ($guid, '$name', '$description')"; |
2477
|
|
|
|
2478
|
|
|
$result = insert_data($query); |
2479
|
|
|
if ($result !== false) { |
2480
|
|
|
$entity = get_entity($guid); |
2481
|
|
|
if (elgg_trigger_event('create', $entity->type, $entity)) { |
|
|
|
|
2482
|
|
|
return $guid; |
2483
|
|
|
} else { |
2484
|
|
|
$entity->delete(); |
2485
|
|
|
} |
2486
|
|
|
} |
2487
|
|
|
} |
2488
|
|
|
} |
2489
|
|
|
|
2490
|
|
|
return false; |
2491
|
|
|
} |
2492
|
|
|
|
2493
|
|
|
/** |
2494
|
|
|
* Create or update the entities table for a given user. |
2495
|
|
|
* Call create_entity first. |
2496
|
|
|
* |
2497
|
|
|
* @param int $guid The user's GUID |
2498
|
|
|
* @param string $name The user's display name |
2499
|
|
|
* @param string $username The username |
2500
|
|
|
* @param string $password The password |
2501
|
|
|
* @param string $salt A salt for the password |
2502
|
|
|
* @param string $email The user's email address |
2503
|
|
|
* @param string $language The user's default language |
2504
|
|
|
* @param string $code A code |
2505
|
|
|
* |
2506
|
|
|
* @return bool |
2507
|
|
|
* @access private |
2508
|
|
|
* @deprecated 1.9 Use \ElggUser constructor |
2509
|
|
|
*/ |
2510
|
|
|
function create_user_entity($guid, $name, $username, $password, $salt, $email, $language, $code) { |
2511
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser constructor', 1.9); |
2512
|
|
|
global $CONFIG; |
2513
|
|
|
|
2514
|
|
|
$guid = (int)$guid; |
2515
|
|
|
$name = sanitise_string($name); |
2516
|
|
|
$username = sanitise_string($username); |
2517
|
|
|
$password = sanitise_string($password); |
2518
|
|
|
$salt = sanitise_string($salt); |
2519
|
|
|
$email = sanitise_string($email); |
2520
|
|
|
$language = sanitise_string($language); |
2521
|
|
|
|
2522
|
|
|
$row = get_entity_as_row($guid); |
2523
|
|
|
if ($row) { |
2524
|
|
|
// Exists and you have access to it |
2525
|
|
|
$query = "SELECT guid from {$CONFIG->dbprefix}users_entity where guid = {$guid}"; |
2526
|
|
View Code Duplication |
if ($exists = get_data_row($query)) { |
|
|
|
|
2527
|
|
|
$query = "UPDATE {$CONFIG->dbprefix}users_entity |
2528
|
|
|
SET name='$name', username='$username', password='$password', salt='$salt', |
2529
|
|
|
email='$email', language='$language' |
2530
|
|
|
WHERE guid = $guid"; |
2531
|
|
|
|
2532
|
|
|
$result = update_data($query); |
2533
|
|
|
if ($result != false) { |
2534
|
|
|
// Update succeeded, continue |
2535
|
|
|
$entity = get_entity($guid); |
2536
|
|
|
if (elgg_trigger_event('update', $entity->type, $entity)) { |
|
|
|
|
2537
|
|
|
return $guid; |
2538
|
|
|
} else { |
2539
|
|
|
$entity->delete(); |
2540
|
|
|
} |
2541
|
|
|
} |
2542
|
|
|
} else { |
2543
|
|
|
// Exists query failed, attempt an insert. |
2544
|
|
|
$query = "INSERT into {$CONFIG->dbprefix}users_entity |
2545
|
|
|
(guid, name, username, password, salt, email, language) |
2546
|
|
|
values ($guid, '$name', '$username', '$password', '$salt', '$email', '$language')"; |
2547
|
|
|
|
2548
|
|
|
$result = insert_data($query); |
2549
|
|
|
if ($result !== false) { |
2550
|
|
|
$entity = get_entity($guid); |
2551
|
|
|
if (elgg_trigger_event('create', $entity->type, $entity)) { |
|
|
|
|
2552
|
|
|
return $guid; |
2553
|
|
|
} else { |
2554
|
|
|
$entity->delete(); |
2555
|
|
|
} |
2556
|
|
|
} |
2557
|
|
|
} |
2558
|
|
|
} |
2559
|
|
|
|
2560
|
|
|
return false; |
2561
|
|
|
} |
2562
|
|
|
|
2563
|
|
|
/** |
2564
|
|
|
* Create or update the extras table for a given object. |
2565
|
|
|
* Call create_entity first. |
2566
|
|
|
* |
2567
|
|
|
* @param int $guid The guid of the entity you're creating (as obtained by create_entity) |
2568
|
|
|
* @param string $title The title of the object |
2569
|
|
|
* @param string $description The object's description |
2570
|
|
|
* |
2571
|
|
|
* @return bool |
2572
|
|
|
* @access private |
2573
|
|
|
* @deprecated 1.9 Use \ElggObject constructor |
2574
|
|
|
*/ |
2575
|
|
|
function create_object_entity($guid, $title, $description) { |
2576
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggObject constructor', 1.9); |
2577
|
|
|
global $CONFIG; |
2578
|
|
|
|
2579
|
|
|
$guid = (int)$guid; |
2580
|
|
|
$title = sanitise_string($title); |
2581
|
|
|
$description = sanitise_string($description); |
2582
|
|
|
|
2583
|
|
|
$row = get_entity_as_row($guid); |
2584
|
|
|
|
2585
|
|
|
if ($row) { |
2586
|
|
|
// Core entities row exists and we have access to it |
2587
|
|
|
$query = "SELECT guid from {$CONFIG->dbprefix}objects_entity where guid = {$guid}"; |
2588
|
|
|
if ($exists = get_data_row($query)) { |
|
|
|
|
2589
|
|
|
$query = "UPDATE {$CONFIG->dbprefix}objects_entity |
2590
|
|
|
set title='$title', description='$description' where guid=$guid"; |
2591
|
|
|
|
2592
|
|
|
$result = update_data($query); |
2593
|
|
|
if ($result != false) { |
2594
|
|
|
// Update succeeded, continue |
2595
|
|
|
$entity = get_entity($guid); |
2596
|
|
|
elgg_trigger_event('update', $entity->type, $entity); |
|
|
|
|
2597
|
|
|
return $guid; |
2598
|
|
|
} |
2599
|
|
|
} else { |
2600
|
|
|
// Update failed, attempt an insert. |
2601
|
|
|
$query = "INSERT into {$CONFIG->dbprefix}objects_entity |
2602
|
|
|
(guid, title, description) values ($guid, '$title','$description')"; |
2603
|
|
|
|
2604
|
|
|
$result = insert_data($query); |
2605
|
|
|
if ($result !== false) { |
2606
|
|
|
$entity = get_entity($guid); |
2607
|
|
|
if (elgg_trigger_event('create', $entity->type, $entity)) { |
|
|
|
|
2608
|
|
|
return $guid; |
2609
|
|
|
} else { |
2610
|
|
|
$entity->delete(); |
2611
|
|
|
} |
2612
|
|
|
} |
2613
|
|
|
} |
2614
|
|
|
} |
2615
|
|
|
|
2616
|
|
|
return false; |
2617
|
|
|
} |
2618
|
|
|
|
2619
|
|
|
/** |
2620
|
|
|
* Attempt to construct an ODD object out of a XmlElement or sub-elements. |
2621
|
|
|
* |
2622
|
|
|
* @param XmlElement $element The element(s) |
2623
|
|
|
* |
2624
|
|
|
* @return mixed An ODD object if the element can be handled, or false. |
2625
|
|
|
* @access private |
2626
|
|
|
* @deprecated 1.9 |
2627
|
|
|
*/ |
2628
|
|
|
function ODD_factory (XmlElement $element) { |
2629
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); |
2630
|
|
|
$name = $element->name; |
2631
|
|
|
$odd = false; |
2632
|
|
|
|
2633
|
|
|
switch ($name) { |
2634
|
|
|
case 'entity' : |
2635
|
|
|
$odd = new ODDEntity("", "", ""); |
|
|
|
|
2636
|
|
|
break; |
2637
|
|
|
case 'metadata' : |
2638
|
|
|
$odd = new ODDMetaData("", "", "", ""); |
|
|
|
|
2639
|
|
|
break; |
2640
|
|
|
case 'relationship' : |
2641
|
|
|
$odd = new ODDRelationship("", "", ""); |
|
|
|
|
2642
|
|
|
break; |
2643
|
|
|
} |
2644
|
|
|
|
2645
|
|
|
// Now populate values |
2646
|
|
|
if ($odd) { |
2647
|
|
|
// Attributes |
2648
|
|
|
foreach ($element->attributes as $k => $v) { |
2649
|
|
|
$odd->setAttribute($k, $v); |
2650
|
|
|
} |
2651
|
|
|
|
2652
|
|
|
// Body |
2653
|
|
|
$body = $element->content; |
2654
|
|
|
$a = stripos($body, "<![CDATA"); |
2655
|
|
|
$b = strripos($body, "]]>"); |
2656
|
|
|
if (($body) && ($a !== false) && ($b !== false)) { |
2657
|
|
|
$body = substr($body, $a + 8, $b - ($a + 8)); |
2658
|
|
|
} |
2659
|
|
|
|
2660
|
|
|
$odd->setBody($body); |
2661
|
|
|
} |
2662
|
|
|
|
2663
|
|
|
return $odd; |
2664
|
|
|
} |
2665
|
|
|
|
2666
|
|
|
/** |
2667
|
|
|
* Utility function used by import_entity_plugin_hook() to |
2668
|
|
|
* process an ODDEntity into an unsaved \ElggEntity. |
2669
|
|
|
* |
2670
|
|
|
* @param ODDEntity $element The OpenDD element |
2671
|
|
|
* |
2672
|
|
|
* @return \ElggEntity the unsaved entity which should be populated by items. |
2673
|
|
|
* @todo Remove this. |
2674
|
|
|
* @access private |
2675
|
|
|
* |
2676
|
|
|
* @throws ClassException|InstallationException|ImportException |
2677
|
|
|
* @deprecated 1.9 |
2678
|
|
|
*/ |
2679
|
|
|
function oddentity_to_elggentity(ODDEntity $element) { |
2680
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); |
2681
|
|
|
$class = $element->getAttribute('class'); |
2682
|
|
|
$subclass = $element->getAttribute('subclass'); |
2683
|
|
|
|
2684
|
|
|
// See if we already have imported this uuid |
2685
|
|
|
$tmp = get_entity_from_uuid($element->getAttribute('uuid')); |
|
|
|
|
2686
|
|
|
|
2687
|
|
|
if (!$tmp) { |
2688
|
|
|
// Construct new class with owner from session |
2689
|
|
|
$classname = get_subtype_class($class, $subclass); |
2690
|
|
|
if ($classname) { |
|
|
|
|
2691
|
|
View Code Duplication |
if (class_exists($classname)) { |
2692
|
|
|
$tmp = new $classname(); |
2693
|
|
|
|
2694
|
|
|
if (!($tmp instanceof \ElggEntity)) { |
2695
|
|
|
$msg = $classname . " is not a " . get_class() . "."; |
2696
|
|
|
throw new \ClassException($msg); |
2697
|
|
|
} |
2698
|
|
|
} else { |
2699
|
|
|
error_log("Class '" . $classname . "' was not found, missing plugin?"); |
2700
|
|
|
} |
2701
|
|
|
} else { |
2702
|
|
|
switch ($class) { |
2703
|
|
|
case 'object' : |
2704
|
|
|
$tmp = new \ElggObject(); |
2705
|
|
|
break; |
2706
|
|
|
case 'user' : |
2707
|
|
|
$tmp = new \ElggUser(); |
2708
|
|
|
break; |
2709
|
|
|
case 'group' : |
2710
|
|
|
$tmp = new \ElggGroup(); |
2711
|
|
|
break; |
2712
|
|
|
case 'site' : |
2713
|
|
|
$tmp = new \ElggSite(); |
2714
|
|
|
break; |
2715
|
|
|
default: |
2716
|
|
|
$msg = "Type " . $class . " is not supported. This indicates an error in your installation, most likely caused by an incomplete upgrade."; |
2717
|
|
|
throw new \InstallationException($msg); |
2718
|
|
|
} |
2719
|
|
|
} |
2720
|
|
|
} |
2721
|
|
|
|
2722
|
|
|
if ($tmp) { |
2723
|
|
|
if (!$tmp->import($element)) { |
|
|
|
|
2724
|
|
|
$msg = "Could not import element " . $element->getAttribute('uuid'); |
2725
|
|
|
throw new \ImportException($msg); |
|
|
|
|
2726
|
|
|
} |
2727
|
|
|
|
2728
|
|
|
return $tmp; |
2729
|
|
|
} |
2730
|
|
|
|
2731
|
|
|
return NULL; |
2732
|
|
|
} |
2733
|
|
|
|
2734
|
|
|
/** |
2735
|
|
|
* Import an ODD document. |
2736
|
|
|
* |
2737
|
|
|
* @param string $xml The XML ODD. |
2738
|
|
|
* |
2739
|
|
|
* @return ODDDocument |
2740
|
|
|
* @access private |
2741
|
|
|
* @deprecated 1.9 |
2742
|
|
|
*/ |
2743
|
|
|
function ODD_Import($xml) { |
2744
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); |
2745
|
|
|
// Parse XML to an array |
2746
|
|
|
$elements = xml_to_object($xml); |
|
|
|
|
2747
|
|
|
|
2748
|
|
|
// Sanity check 1, was this actually XML? |
2749
|
|
|
if ((!$elements) || (!$elements->children)) { |
2750
|
|
|
return false; |
2751
|
|
|
} |
2752
|
|
|
|
2753
|
|
|
// Create ODDDocument |
2754
|
|
|
$document = new ODDDocument(); |
|
|
|
|
2755
|
|
|
|
2756
|
|
|
// Itterate through array of elements and construct ODD document |
2757
|
|
|
$cnt = 0; |
2758
|
|
|
|
2759
|
|
|
foreach ($elements->children as $child) { |
2760
|
|
|
$odd = ODD_factory($child); |
|
|
|
|
2761
|
|
|
|
2762
|
|
|
if ($odd) { |
2763
|
|
|
$document->addElement($odd); |
2764
|
|
|
$cnt++; |
2765
|
|
|
} |
2766
|
|
|
} |
2767
|
|
|
|
2768
|
|
|
// Check that we actually found something |
2769
|
|
|
if ($cnt == 0) { |
2770
|
|
|
return false; |
2771
|
|
|
} |
2772
|
|
|
|
2773
|
|
|
return $document; |
2774
|
|
|
} |
2775
|
|
|
|
2776
|
|
|
/** |
2777
|
|
|
* Export an ODD Document. |
2778
|
|
|
* |
2779
|
|
|
* @param ODDDocument $document The Document. |
2780
|
|
|
* |
2781
|
|
|
* @return string |
2782
|
|
|
* @access private |
2783
|
|
|
* @deprecated 1.9 |
2784
|
|
|
*/ |
2785
|
|
|
function ODD_Export(ODDDocument $document) { |
2786
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); |
2787
|
|
|
return "$document"; |
2788
|
|
|
} |
2789
|
|
|
|
2790
|
|
|
/** |
2791
|
|
|
* Get a UUID from a given object. |
2792
|
|
|
* |
2793
|
|
|
* @param mixed $object The object either an \ElggEntity, \ElggRelationship or \ElggExtender |
2794
|
|
|
* |
2795
|
|
|
* @return string|false the UUID or false |
2796
|
|
|
* @deprecated 1.9 |
2797
|
|
|
*/ |
2798
|
|
|
function get_uuid_from_object($object) { |
2799
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); |
2800
|
|
|
if ($object instanceof \ElggEntity) { |
2801
|
|
|
return guid_to_uuid($object->guid); |
|
|
|
|
2802
|
|
|
} else if ($object instanceof \ElggExtender) { |
2803
|
|
|
$type = $object->type; |
2804
|
|
|
if ($type == 'volatile') { |
2805
|
|
|
$uuid = guid_to_uuid($object->entity_guid) . $type . "/{$object->name}/"; |
|
|
|
|
2806
|
|
|
} else { |
2807
|
|
|
$uuid = guid_to_uuid($object->entity_guid) . $type . "/{$object->id}/"; |
|
|
|
|
2808
|
|
|
} |
2809
|
|
|
|
2810
|
|
|
return $uuid; |
2811
|
|
|
} else if ($object instanceof \ElggRelationship) { |
2812
|
|
|
return guid_to_uuid($object->guid_one) . "relationship/{$object->id}/"; |
|
|
|
|
2813
|
|
|
} |
2814
|
|
|
|
2815
|
|
|
return false; |
2816
|
|
|
} |
2817
|
|
|
|
2818
|
|
|
/** |
2819
|
|
|
* Generate a UUID from a given GUID. |
2820
|
|
|
* |
2821
|
|
|
* @param int $guid The GUID of an object. |
2822
|
|
|
* |
2823
|
|
|
* @return string |
2824
|
|
|
* @deprecated 1.9 |
2825
|
|
|
*/ |
2826
|
|
|
function guid_to_uuid($guid) { |
2827
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); |
2828
|
|
|
return elgg_get_site_url() . "export/opendd/$guid/"; |
2829
|
|
|
} |
2830
|
|
|
|
2831
|
|
|
/** |
2832
|
|
|
* Test to see if a given uuid is for this domain, returning true if so. |
2833
|
|
|
* |
2834
|
|
|
* @param string $uuid A unique ID |
2835
|
|
|
* |
2836
|
|
|
* @return bool |
2837
|
|
|
* @deprecated 1.9 |
2838
|
|
|
*/ |
2839
|
|
|
function is_uuid_this_domain($uuid) { |
2840
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); |
2841
|
|
|
if (strpos($uuid, elgg_get_site_url()) === 0) { |
2842
|
|
|
return true; |
2843
|
|
|
} |
2844
|
|
|
|
2845
|
|
|
return false; |
2846
|
|
|
} |
2847
|
|
|
|
2848
|
|
|
/** |
2849
|
|
|
* This function attempts to retrieve a previously imported entity via its UUID. |
2850
|
|
|
* |
2851
|
|
|
* @param string $uuid A unique ID |
2852
|
|
|
* |
2853
|
|
|
* @return \ElggEntity|false |
2854
|
|
|
* @deprecated 1.9 |
2855
|
|
|
*/ |
2856
|
|
View Code Duplication |
function get_entity_from_uuid($uuid) { |
|
|
|
|
2857
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); |
2858
|
|
|
$uuid = sanitise_string($uuid); |
2859
|
|
|
|
2860
|
|
|
$options = array('metadata_name' => 'import_uuid', 'metadata_value' => $uuid); |
2861
|
|
|
$entities = elgg_get_entities_from_metadata($options); |
2862
|
|
|
|
2863
|
|
|
if ($entities) { |
2864
|
|
|
return $entities[0]; |
2865
|
|
|
} |
2866
|
|
|
|
2867
|
|
|
return false; |
2868
|
|
|
} |
2869
|
|
|
|
2870
|
|
|
/** |
2871
|
|
|
* Tag a previously created guid with the uuid it was imported on. |
2872
|
|
|
* |
2873
|
|
|
* @param int $guid A GUID |
2874
|
|
|
* @param string $uuid A Unique ID |
2875
|
|
|
* |
2876
|
|
|
* @return bool |
2877
|
|
|
* @deprecated 1.9 |
2878
|
|
|
*/ |
2879
|
|
|
function add_uuid_to_guid($guid, $uuid) { |
2880
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); |
2881
|
|
|
$guid = (int)$guid; |
2882
|
|
|
$uuid = sanitise_string($uuid); |
2883
|
|
|
|
2884
|
|
|
$result = create_metadata($guid, "import_uuid", $uuid); |
2885
|
|
|
return (bool)$result; |
2886
|
|
|
} |
2887
|
|
|
|
2888
|
|
|
|
2889
|
|
|
$IMPORTED_DATA = array(); |
2890
|
|
|
$IMPORTED_OBJECT_COUNTER = 0; |
2891
|
|
|
|
2892
|
|
|
/** |
2893
|
|
|
* This function processes an element, passing elements to the plugin stack to see if someone will |
2894
|
|
|
* process it. |
2895
|
|
|
* |
2896
|
|
|
* If nobody processes the top level element, the sub level elements are processed. |
2897
|
|
|
* |
2898
|
|
|
* @param ODD $odd The odd element to process |
2899
|
|
|
* |
2900
|
|
|
* @return bool |
2901
|
|
|
* @access private |
2902
|
|
|
* @deprecated 1.9 |
2903
|
|
|
*/ |
2904
|
|
|
function _process_element(ODD $odd) { |
2905
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); |
2906
|
|
|
global $IMPORTED_DATA, $IMPORTED_OBJECT_COUNTER; |
2907
|
|
|
|
2908
|
|
|
// See if anyone handles this element, return true if it is. |
2909
|
|
|
$to_be_serialised = null; |
2910
|
|
|
if ($odd) { |
2911
|
|
|
$handled = elgg_trigger_plugin_hook("import", "all", array("element" => $odd), $to_be_serialised); |
2912
|
|
|
|
2913
|
|
|
// If not, then see if any of its sub elements are handled |
2914
|
|
|
if ($handled) { |
2915
|
|
|
// Increment validation counter |
2916
|
|
|
$IMPORTED_OBJECT_COUNTER ++; |
2917
|
|
|
// Return the constructed object |
2918
|
|
|
$IMPORTED_DATA[] = $handled; |
2919
|
|
|
|
2920
|
|
|
return true; |
2921
|
|
|
} |
2922
|
|
|
} |
2923
|
|
|
|
2924
|
|
|
return false; |
2925
|
|
|
} |
2926
|
|
|
|
2927
|
|
|
/** |
2928
|
|
|
* Exports an entity as an array |
2929
|
|
|
* |
2930
|
|
|
* @param int $guid Entity GUID |
2931
|
|
|
* |
2932
|
|
|
* @return array |
2933
|
|
|
* @throws ExportException |
2934
|
|
|
* @access private |
2935
|
|
|
* @deprecated 1.9 |
2936
|
|
|
*/ |
2937
|
|
|
function exportAsArray($guid) { |
2938
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); |
2939
|
|
|
$guid = (int)$guid; |
2940
|
|
|
|
2941
|
|
|
// Trigger a hook to |
2942
|
|
|
$to_be_serialised = elgg_trigger_plugin_hook("export", "all", array("guid" => $guid), array()); |
2943
|
|
|
|
2944
|
|
|
// Sanity check |
2945
|
|
|
if ((!is_array($to_be_serialised)) || (count($to_be_serialised) == 0)) { |
2946
|
|
|
throw new \ExportException("No such entity GUID:" . $guid); |
|
|
|
|
2947
|
|
|
} |
2948
|
|
|
|
2949
|
|
|
return $to_be_serialised; |
2950
|
|
|
} |
2951
|
|
|
|
2952
|
|
|
/** |
2953
|
|
|
* Export a GUID. |
2954
|
|
|
* |
2955
|
|
|
* This function exports a GUID and all information related to it in an XML format. |
2956
|
|
|
* |
2957
|
|
|
* This function makes use of the "serialise" plugin hook, which is passed an array to which plugins |
2958
|
|
|
* should add data to be serialised to. |
2959
|
|
|
* |
2960
|
|
|
* @param int $guid The GUID. |
2961
|
|
|
* |
2962
|
|
|
* @return string XML |
2963
|
|
|
* @see \ElggEntity for an example of its usage. |
2964
|
|
|
* @access private |
2965
|
|
|
* @deprecated 1.9 |
2966
|
|
|
*/ |
2967
|
|
|
function export($guid) { |
2968
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); |
2969
|
|
|
$odd = new ODDDocument(exportAsArray($guid)); |
|
|
|
|
2970
|
|
|
|
2971
|
|
|
return ODD_Export($odd); |
|
|
|
|
2972
|
|
|
} |
2973
|
|
|
|
2974
|
|
|
/** |
2975
|
|
|
* Import an XML serialisation of an object. |
2976
|
|
|
* This will make a best attempt at importing a given xml doc. |
2977
|
|
|
* |
2978
|
|
|
* @param string $xml XML string |
2979
|
|
|
* |
2980
|
|
|
* @return bool |
2981
|
|
|
* @throws ImportException if there was a problem importing the data. |
2982
|
|
|
* @access private |
2983
|
|
|
* @deprecated 1.9 |
2984
|
|
|
*/ |
2985
|
|
|
function import($xml) { |
2986
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); |
2987
|
|
|
global $IMPORTED_DATA, $IMPORTED_OBJECT_COUNTER; |
2988
|
|
|
|
2989
|
|
|
$IMPORTED_DATA = array(); |
2990
|
|
|
$IMPORTED_OBJECT_COUNTER = 0; |
2991
|
|
|
|
2992
|
|
|
$document = ODD_Import($xml); |
|
|
|
|
2993
|
|
|
if (!$document) { |
2994
|
|
|
throw new \ImportException("No OpenDD elements found in import data, import failed."); |
|
|
|
|
2995
|
|
|
} |
2996
|
|
|
|
2997
|
|
|
foreach ($document as $element) { |
2998
|
|
|
_process_element($element); |
|
|
|
|
2999
|
|
|
} |
3000
|
|
|
|
3001
|
|
|
if ($IMPORTED_OBJECT_COUNTER != count($IMPORTED_DATA)) { |
3002
|
|
|
throw new \ImportException("Not all elements were imported."); |
|
|
|
|
3003
|
|
|
} |
3004
|
|
|
|
3005
|
|
|
return true; |
3006
|
|
|
} |
3007
|
|
|
|
3008
|
|
|
/** |
3009
|
|
|
* Register the OpenDD import action |
3010
|
|
|
* |
3011
|
|
|
* @return void |
3012
|
|
|
* @access private |
3013
|
|
|
* @deprecated 1.9 |
3014
|
|
|
*/ |
3015
|
|
|
function _export_init() { |
3016
|
|
|
global $CONFIG; |
3017
|
|
|
|
3018
|
|
|
elgg_register_action("import/opendd"); |
3019
|
|
|
} |
3020
|
|
|
|
3021
|
|
|
/** |
3022
|
|
|
* Returns the name of views for in a directory. |
3023
|
|
|
* |
3024
|
|
|
* Use this to get all namespaced views under the first element. |
3025
|
|
|
* |
3026
|
|
|
* @param string $dir The main directory that holds the views. (mod/profile/views/) |
3027
|
|
|
* @param string $base The root name of the view to use, without the viewtype. (profile) |
3028
|
|
|
* |
3029
|
|
|
* @return array |
3030
|
|
|
* @since 1.7.0 |
3031
|
|
|
* @todo Why isn't this used anywhere else but in elgg_view_tree()? |
3032
|
|
|
* Seems like a useful function for autodiscovery. |
3033
|
|
|
* @access private |
3034
|
|
|
* @deprecated 1.9 |
3035
|
|
|
*/ |
3036
|
|
|
function elgg_get_views($dir, $base) { |
3037
|
|
|
$return = array(); |
3038
|
|
|
if (file_exists($dir) && is_dir($dir)) { |
3039
|
|
|
if ($handle = opendir($dir)) { |
3040
|
|
|
while ($view = readdir($handle)) { |
3041
|
|
|
if (!in_array($view, array('.', '..', '.svn', 'CVS'))) { |
3042
|
|
|
if (is_dir($dir . '/' . $view)) { |
3043
|
|
|
if ($val = elgg_get_views($dir . '/' . $view, $base . '/' . $view)) { |
|
|
|
|
3044
|
|
|
$return = array_merge($return, $val); |
3045
|
|
|
} |
3046
|
|
|
} else { |
3047
|
|
|
$view = str_replace('.php', '', $view); |
3048
|
|
|
$return[] = $base . '/' . $view; |
3049
|
|
|
} |
3050
|
|
|
} |
3051
|
|
|
} |
3052
|
|
|
} |
3053
|
|
|
} |
3054
|
|
|
|
3055
|
|
|
return $return; |
3056
|
|
|
} |
3057
|
|
|
|
3058
|
|
|
/** |
3059
|
|
|
* Returns all views below a partial view. |
3060
|
|
|
* |
3061
|
|
|
* Settings $view_root = 'profile' will show all available views under |
3062
|
|
|
* the "profile" namespace. |
3063
|
|
|
* |
3064
|
|
|
* @param string $view_root The root view |
3065
|
|
|
* @param string $viewtype Optionally specify a view type |
3066
|
|
|
* other than the current one. |
3067
|
|
|
* |
3068
|
|
|
* @return array A list of view names underneath that root view |
3069
|
|
|
* @todo This is used once in the deprecated get_activity_stream_data() function. |
3070
|
|
|
* @access private |
3071
|
|
|
* @deprecated 1.9 |
3072
|
|
|
*/ |
3073
|
|
|
function elgg_view_tree($view_root, $viewtype = "") { |
3074
|
|
|
global $CONFIG; |
3075
|
|
|
static $treecache = array(); |
3076
|
|
|
|
3077
|
|
|
// Get viewtype |
3078
|
|
|
if (!$viewtype) { |
3079
|
|
|
$viewtype = elgg_get_viewtype(); |
3080
|
|
|
} |
3081
|
|
|
|
3082
|
|
|
// A little light internal caching |
3083
|
|
|
if (!empty($treecache[$view_root])) { |
3084
|
|
|
return $treecache[$view_root]; |
3085
|
|
|
} |
3086
|
|
|
|
3087
|
|
|
// Examine $CONFIG->views->locations |
3088
|
|
|
if (isset($CONFIG->views->locations[$viewtype])) { |
3089
|
|
|
foreach ($CONFIG->views->locations[$viewtype] as $view => $path) { |
3090
|
|
|
$pos = strpos($view, $view_root); |
3091
|
|
|
if ($pos === 0) { |
3092
|
|
|
$treecache[$view_root][] = $view; |
3093
|
|
|
} |
3094
|
|
|
} |
3095
|
|
|
} |
3096
|
|
|
|
3097
|
|
|
// Now examine core |
3098
|
|
|
$location = $CONFIG->viewpath; |
3099
|
|
|
$viewtype = elgg_get_viewtype(); |
3100
|
|
|
$root = $location . $viewtype . '/' . $view_root; |
3101
|
|
|
|
3102
|
|
|
if (file_exists($root) && is_dir($root)) { |
3103
|
|
|
$val = elgg_get_views($root, $view_root); |
|
|
|
|
3104
|
|
|
if (!is_array($treecache[$view_root])) { |
3105
|
|
|
$treecache[$view_root] = array(); |
3106
|
|
|
} |
3107
|
|
|
$treecache[$view_root] = array_merge($treecache[$view_root], $val); |
3108
|
|
|
} |
3109
|
|
|
|
3110
|
|
|
return $treecache[$view_root]; |
3111
|
|
|
} |
3112
|
|
|
|
3113
|
|
|
/** |
3114
|
|
|
* Adds an item to the river. |
3115
|
|
|
* |
3116
|
|
|
* @param string $view The view that will handle the river item (must exist) |
3117
|
|
|
* @param string $action_type An arbitrary string to define the action (eg 'comment', 'create') |
3118
|
|
|
* @param int $subject_guid The GUID of the entity doing the action |
3119
|
|
|
* @param int $object_guid The GUID of the entity being acted upon |
3120
|
|
|
* @param int $access_id The access ID of the river item (default: same as the object) |
3121
|
|
|
* @param int $posted The UNIX epoch timestamp of the river item (default: now) |
3122
|
|
|
* @param int $annotation_id The annotation ID associated with this river entry |
3123
|
|
|
* @param int $target_guid The GUID of the the object entity's container |
3124
|
|
|
* |
3125
|
|
|
* @return int/bool River ID or false on failure |
|
|
|
|
3126
|
|
|
* @deprecated 1.9 Use elgg_create_river_item() |
3127
|
|
|
*/ |
3128
|
|
|
function add_to_river($view, $action_type, $subject_guid, $object_guid, $access_id = "", |
3129
|
|
|
$posted = 0, $annotation_id = 0, $target_guid = 0) { |
3130
|
|
|
elgg_deprecated_notice('add_to_river was deprecated in favor of elgg_create_river_item', '1.9'); |
3131
|
|
|
|
3132
|
|
|
// Make sure old parameters are passed in correct format |
3133
|
|
|
$access_id = ($access_id == '') ? null : $access_id; |
3134
|
|
|
$posted = ($posted == 0) ? null : $posted; |
3135
|
|
|
|
3136
|
|
|
return elgg_create_river_item(array( |
3137
|
|
|
'view' => $view, |
3138
|
|
|
'action_type' => $action_type, |
3139
|
|
|
'subject_guid' => $subject_guid, |
3140
|
|
|
'object_guid' => $object_guid, |
3141
|
|
|
'target_guid' => $target_guid, |
3142
|
|
|
'access_id' => $access_id, |
3143
|
|
|
'posted' => $posted, |
3144
|
|
|
'annotation_id' => $annotation_id, |
3145
|
|
|
)); |
3146
|
|
|
} |
3147
|
|
|
|
3148
|
|
|
/** |
3149
|
|
|
* This function serialises an object recursively into an XML representation. |
3150
|
|
|
* |
3151
|
|
|
* The function attempts to call $data->export() which expects a \stdClass in return, |
3152
|
|
|
* otherwise it will attempt to get the object variables using get_object_vars (which |
3153
|
|
|
* will only return public variables!) |
3154
|
|
|
* |
3155
|
|
|
* @param mixed $data The object to serialise. |
3156
|
|
|
* @param string $name The name? |
3157
|
|
|
* @param int $n Level, only used for recursion. |
3158
|
|
|
* |
3159
|
|
|
* @return string The serialised XML output. |
3160
|
|
|
* @deprecated 1.9 |
3161
|
|
|
*/ |
3162
|
|
|
function serialise_object_to_xml($data, $name = "", $n = 0) { |
3163
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated.', 1.9); |
3164
|
|
|
|
3165
|
|
|
$classname = ($name == "" ? get_class($data) : $name); |
3166
|
|
|
|
3167
|
|
|
$vars = method_exists($data, "export") ? get_object_vars($data->export()) : get_object_vars($data); |
3168
|
|
|
|
3169
|
|
|
$output = ""; |
3170
|
|
|
|
3171
|
|
View Code Duplication |
if (($n == 0) || ( is_object($data) && !($data instanceof \stdClass))) { |
3172
|
|
|
$output = "<$classname>"; |
3173
|
|
|
} |
3174
|
|
|
|
3175
|
|
|
foreach ($vars as $key => $value) { |
3176
|
|
|
$output .= "<$key type=\"" . gettype($value) . "\">"; |
3177
|
|
|
|
3178
|
|
View Code Duplication |
if (is_object($value)) { |
3179
|
|
|
$output .= serialise_object_to_xml($value, $key, $n + 1); |
|
|
|
|
3180
|
|
|
} else if (is_array($value)) { |
3181
|
|
|
$output .= serialise_array_to_xml($value, $n + 1); |
|
|
|
|
3182
|
|
|
} else if (gettype($value) == "boolean") { |
3183
|
|
|
$output .= $value ? "true" : "false"; |
3184
|
|
|
} else { |
3185
|
|
|
$output .= htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8'); |
3186
|
|
|
} |
3187
|
|
|
|
3188
|
|
|
$output .= "</$key>\n"; |
3189
|
|
|
} |
3190
|
|
|
|
3191
|
|
View Code Duplication |
if (($n == 0) || (is_object($data) && !($data instanceof \stdClass))) { |
3192
|
|
|
$output .= "</$classname>\n"; |
3193
|
|
|
} |
3194
|
|
|
|
3195
|
|
|
return $output; |
3196
|
|
|
} |
3197
|
|
|
|
3198
|
|
|
/** |
3199
|
|
|
* Serialise an array. |
3200
|
|
|
* |
3201
|
|
|
* @param array $data The data to serialize |
3202
|
|
|
* @param int $n Used for recursion |
3203
|
|
|
* |
3204
|
|
|
* @return string |
3205
|
|
|
* @deprecated 1.9 |
3206
|
|
|
*/ |
3207
|
|
|
function serialise_array_to_xml(array $data, $n = 0) { |
3208
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated.', 1.9); |
3209
|
|
|
|
3210
|
|
|
$output = ""; |
3211
|
|
|
|
3212
|
|
|
if ($n == 0) { |
3213
|
|
|
$output = "<array>\n"; |
3214
|
|
|
} |
3215
|
|
|
|
3216
|
|
|
foreach ($data as $key => $value) { |
3217
|
|
|
$item = "array_item"; |
3218
|
|
|
|
3219
|
|
|
if (is_numeric($key)) { |
3220
|
|
|
$output .= "<$item name=\"$key\" type=\"" . gettype($value) . "\">"; |
3221
|
|
|
} else { |
3222
|
|
|
$item = $key; |
3223
|
|
|
$output .= "<$item type=\"" . gettype($value) . "\">"; |
3224
|
|
|
} |
3225
|
|
|
|
3226
|
|
View Code Duplication |
if (is_object($value)) { |
3227
|
|
|
$output .= serialise_object_to_xml($value, "", $n + 1); |
|
|
|
|
3228
|
|
|
} else if (is_array($value)) { |
3229
|
|
|
$output .= serialise_array_to_xml($value, $n + 1); |
|
|
|
|
3230
|
|
|
} else if (gettype($value) == "boolean") { |
3231
|
|
|
$output .= $value ? "true" : "false"; |
3232
|
|
|
} else { |
3233
|
|
|
$output .= htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8'); |
3234
|
|
|
} |
3235
|
|
|
|
3236
|
|
|
$output .= "</$item>\n"; |
3237
|
|
|
} |
3238
|
|
|
|
3239
|
|
|
if ($n == 0) { |
3240
|
|
|
$output .= "</array>\n"; |
3241
|
|
|
} |
3242
|
|
|
|
3243
|
|
|
return $output; |
3244
|
|
|
} |
3245
|
|
|
|
3246
|
|
|
/** |
3247
|
|
|
* Parse an XML file into an object. |
3248
|
|
|
* |
3249
|
|
|
* @param string $xml The XML |
3250
|
|
|
* |
3251
|
|
|
* @return \ElggXMLElement |
3252
|
|
|
* @deprecated 1.9 Use \ElggXMLElement |
3253
|
|
|
*/ |
3254
|
|
|
function xml_to_object($xml) { |
3255
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by \ElggXMLElement', 1.9); |
3256
|
|
|
return new \ElggXMLElement($xml); |
3257
|
|
|
} |
3258
|
|
|
|
3259
|
|
|
/** |
3260
|
|
|
* Retrieve a site and return the domain portion of its url. |
3261
|
|
|
* |
3262
|
|
|
* @param int $guid \ElggSite GUID |
3263
|
|
|
* |
3264
|
|
|
* @return string |
3265
|
|
|
* @deprecated 1.9 Use \ElggSite::getDomain() |
3266
|
|
|
*/ |
3267
|
|
|
function get_site_domain($guid) { |
3268
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggSite::getDomain()', 1.9); |
3269
|
|
|
$guid = (int)$guid; |
3270
|
|
|
|
3271
|
|
|
$site = get_entity($guid); |
3272
|
|
|
if ($site instanceof \ElggSite) { |
3273
|
|
|
$breakdown = parse_url($site->url); |
3274
|
|
|
return $breakdown['host']; |
3275
|
|
|
} |
3276
|
|
|
|
3277
|
|
|
return false; |
3278
|
|
|
} |
3279
|
|
|
|
3280
|
|
|
/** |
3281
|
|
|
* Register an entity type and subtype to be eligible for notifications |
3282
|
|
|
* |
3283
|
|
|
* @param string $entity_type The type of entity |
3284
|
|
|
* @param string $object_subtype Its subtype |
3285
|
|
|
* @param string $language_name Its localized notification string (eg "New blog post") |
3286
|
|
|
* |
3287
|
|
|
* @return void |
3288
|
|
|
* @deprecated 1.9 Use elgg_register_notification_event(). The 3rd argument was used |
3289
|
|
|
* as the subject line in a notification. As of Elgg 1.9, it is now set by a callback |
3290
|
|
|
* for a plugin hook. See the documentation at the top of the notifications library |
3291
|
|
|
* titled "Adding a New Notification Event" for more details. |
3292
|
|
|
*/ |
3293
|
|
|
function register_notification_object($entity_type, $object_subtype, $language_name) { |
3294
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_register_notification_event()', 1.9); |
3295
|
|
|
|
3296
|
|
|
elgg_register_notification_event($entity_type, $object_subtype); |
3297
|
|
|
_elgg_services()->notifications->setDeprecatedNotificationSubject($entity_type, $object_subtype, $language_name); |
3298
|
|
|
} |
3299
|
|
|
|
3300
|
|
|
/** |
3301
|
|
|
* Establish a 'notify' relationship between the user and a content author |
3302
|
|
|
* |
3303
|
|
|
* @param int $user_guid The GUID of the user who wants to follow a user's content |
3304
|
|
|
* @param int $author_guid The GUID of the user whose content the user wants to follow |
3305
|
|
|
* |
3306
|
|
|
* @return bool Depending on success |
3307
|
|
|
* @deprecated 1.9 Use elgg_add_subscription() |
3308
|
|
|
*/ |
3309
|
|
|
function register_notification_interest($user_guid, $author_guid) { |
3310
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_add_subscription()', 1.9); |
3311
|
|
|
return add_entity_relationship($user_guid, 'notify', $author_guid); |
3312
|
|
|
} |
3313
|
|
|
|
3314
|
|
|
/** |
3315
|
|
|
* Remove a 'notify' relationship between the user and a content author |
3316
|
|
|
* |
3317
|
|
|
* @param int $user_guid The GUID of the user who is following a user's content |
3318
|
|
|
* @param int $author_guid The GUID of the user whose content the user wants to unfollow |
3319
|
|
|
* |
3320
|
|
|
* @return bool Depending on success |
3321
|
|
|
* @deprecated 1.9 Use elgg_remove_subscription() |
3322
|
|
|
*/ |
3323
|
|
|
function remove_notification_interest($user_guid, $author_guid) { |
3324
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_remove_subscription()', 1.9); |
3325
|
|
|
return remove_entity_relationship($user_guid, 'notify', $author_guid); |
3326
|
|
|
} |
3327
|
|
|
|
3328
|
|
|
/** |
3329
|
|
|
* Automatically triggered notification on 'create' events that looks at registered |
3330
|
|
|
* objects and attempts to send notifications to anybody who's interested |
3331
|
|
|
* |
3332
|
|
|
* @see register_notification_object |
3333
|
|
|
* |
3334
|
|
|
* @param string $event create |
3335
|
|
|
* @param string $object_type mixed |
3336
|
|
|
* @param mixed $object The object created |
3337
|
|
|
* |
3338
|
|
|
* @return bool |
3339
|
|
|
* @access private |
3340
|
|
|
* @deprecated 1.9 |
3341
|
|
|
*/ |
3342
|
|
|
function object_notifications($event, $object_type, $object) { |
3343
|
|
|
throw new \BadFunctionCallException("object_notifications is a private function and should not be called directly"); |
3344
|
|
|
} |
3345
|
|
|
|
3346
|
|
|
/** |
3347
|
|
|
* This function registers a handler for a given notification type (eg "email") |
3348
|
|
|
* |
3349
|
|
|
* @param string $method The method |
3350
|
|
|
* @param string $handler The handler function, in the format |
3351
|
|
|
* "handler(\ElggEntity $from, \ElggUser $to, $subject, |
3352
|
|
|
* $message, array $params = NULL)". This function should |
3353
|
|
|
* return false on failure, and true/a tracking message ID on success. |
3354
|
|
|
* @param array $params An associated array of other parameters for this handler |
3355
|
|
|
* defining some properties eg. supported msg length or rich text support. |
3356
|
|
|
* |
3357
|
|
|
* @return bool |
3358
|
|
|
* @deprecated 1.9 Use elgg_register_notification_method() |
3359
|
|
|
*/ |
3360
|
|
|
function register_notification_handler($method, $handler, $params = NULL) { |
3361
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_register_notification_method()', 1.9); |
3362
|
|
|
elgg_register_notification_method($method); |
3363
|
|
|
_elgg_services()->notifications->registerDeprecatedHandler($method, $handler); |
3364
|
|
|
} |
3365
|
|
|
|
3366
|
|
|
/** |
3367
|
|
|
* This function unregisters a handler for a given notification type (eg "email") |
3368
|
|
|
* |
3369
|
|
|
* @param string $method The method |
3370
|
|
|
* |
3371
|
|
|
* @return void |
3372
|
|
|
* @since 1.7.1 |
3373
|
|
|
* @deprecated 1.9 Use elgg_unregister_notification_method() |
3374
|
|
|
*/ |
3375
|
|
|
function unregister_notification_handler($method) { |
3376
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_unregister_notification_method()', 1.9); |
3377
|
|
|
elgg_unregister_notification_method($method); |
3378
|
|
|
} |
3379
|
|
|
|
3380
|
|
|
/** |
3381
|
|
|
* Import an entity. |
3382
|
|
|
* |
3383
|
|
|
* This function checks the passed XML doc (as array) to see if it is |
3384
|
|
|
* a user, if so it constructs a new elgg user and returns "true" |
3385
|
|
|
* to inform the importer that it's been handled. |
3386
|
|
|
* |
3387
|
|
|
* @param string $hook import |
3388
|
|
|
* @param string $entity_type all |
3389
|
|
|
* @param mixed $returnvalue Value from previous hook |
3390
|
|
|
* @param mixed $params Array of params |
3391
|
|
|
* |
3392
|
|
|
* @return mixed |
3393
|
|
|
* @elgg_plugin_hook_handler import all |
3394
|
|
|
* @todo document |
3395
|
|
|
* @access private |
3396
|
|
|
* |
3397
|
|
|
* @throws ImportException |
3398
|
|
|
* @deprecated 1.9 |
3399
|
|
|
*/ |
3400
|
|
|
function import_entity_plugin_hook($hook, $entity_type, $returnvalue, $params) { |
3401
|
|
|
$element = $params['element']; |
3402
|
|
|
|
3403
|
|
|
$tmp = null; |
|
|
|
|
3404
|
|
|
|
3405
|
|
|
if ($element instanceof ODDEntity) { |
3406
|
|
|
$tmp = oddentity_to_elggentity($element); |
|
|
|
|
3407
|
|
|
|
3408
|
|
|
if ($tmp) { |
3409
|
|
|
// Make sure its saved |
3410
|
|
|
if (!$tmp->save()) { |
3411
|
|
|
$msg = "There was a problem saving " . $element->getAttribute('uuid'); |
3412
|
|
|
throw new \ImportException($msg); |
|
|
|
|
3413
|
|
|
} |
3414
|
|
|
|
3415
|
|
|
// Belts and braces |
3416
|
|
|
if (!$tmp->guid) { |
3417
|
|
|
throw new \ImportException("New entity created but has no GUID, this should not happen."); |
|
|
|
|
3418
|
|
|
} |
3419
|
|
|
|
3420
|
|
|
// We have saved, so now tag |
3421
|
|
|
add_uuid_to_guid($tmp->guid, $element->getAttribute('uuid')); |
|
|
|
|
3422
|
|
|
|
3423
|
|
|
return $tmp; |
3424
|
|
|
} |
3425
|
|
|
} |
3426
|
|
|
} |
3427
|
|
|
|
3428
|
|
|
/** |
3429
|
|
|
* Exports all attributes of an entity. |
3430
|
|
|
* |
3431
|
|
|
* @warning Only exports fields in the entity and entity type tables. |
3432
|
|
|
* |
3433
|
|
|
* @param string $hook export |
3434
|
|
|
* @param string $entity_type all |
3435
|
|
|
* @param mixed $returnvalue Previous hook return value |
3436
|
|
|
* @param array $params Parameters |
3437
|
|
|
* |
3438
|
|
|
* @elgg_event_handler export all |
3439
|
|
|
* @return mixed |
3440
|
|
|
* @access private |
3441
|
|
|
* |
3442
|
|
|
* @throws InvalidParameterException|InvalidClassException |
3443
|
|
|
* @deprecated 1.9 |
3444
|
|
|
*/ |
3445
|
|
|
function export_entity_plugin_hook($hook, $entity_type, $returnvalue, $params) { |
3446
|
|
|
// Sanity check values |
3447
|
|
|
if ((!is_array($params)) && (!isset($params['guid']))) { |
3448
|
|
|
throw new \InvalidParameterException("GUID has not been specified during export, this should never happen."); |
3449
|
|
|
} |
3450
|
|
|
|
3451
|
|
|
if (!is_array($returnvalue)) { |
3452
|
|
|
throw new \InvalidParameterException("Entity serialisation function passed a non-array returnvalue parameter"); |
3453
|
|
|
} |
3454
|
|
|
|
3455
|
|
|
$guid = (int)$params['guid']; |
3456
|
|
|
|
3457
|
|
|
// Get the entity |
3458
|
|
|
$entity = get_entity($guid); |
3459
|
|
|
if (!($entity instanceof \ElggEntity)) { |
3460
|
|
|
$msg = "GUID:" . $guid . " is not a valid " . get_class(); |
3461
|
|
|
throw new \InvalidClassException($msg); |
3462
|
|
|
} |
3463
|
|
|
|
3464
|
|
|
$export = $entity->export(); |
|
|
|
|
3465
|
|
|
|
3466
|
|
|
if (is_array($export)) { |
3467
|
|
|
foreach ($export as $e) { |
3468
|
|
|
$returnvalue[] = $e; |
3469
|
|
|
} |
3470
|
|
|
} else { |
3471
|
|
|
$returnvalue[] = $export; |
3472
|
|
|
} |
3473
|
|
|
|
3474
|
|
|
return $returnvalue; |
3475
|
|
|
} |
3476
|
|
|
|
3477
|
|
|
/** |
3478
|
|
|
* Exports attributes generated on the fly (volatile) about an entity. |
3479
|
|
|
* |
3480
|
|
|
* @param string $hook volatile |
3481
|
|
|
* @param string $entity_type metadata |
3482
|
|
|
* @param string $returnvalue Return value from previous hook |
3483
|
|
|
* @param array $params The parameters, passed 'guid' and 'varname' |
3484
|
|
|
* |
3485
|
|
|
* @return \ElggMetadata|null |
3486
|
|
|
* @elgg_plugin_hook_handler volatile metadata |
3487
|
|
|
* @todo investigate more. |
3488
|
|
|
* @access private |
3489
|
|
|
* @todo document |
3490
|
|
|
* @deprecated 1.9 |
3491
|
|
|
*/ |
3492
|
|
|
function volatile_data_export_plugin_hook($hook, $entity_type, $returnvalue, $params) { |
3493
|
|
|
$guid = (int)$params['guid']; |
3494
|
|
|
$variable_name = sanitise_string($params['varname']); |
3495
|
|
|
|
3496
|
|
|
if (($hook == 'volatile') && ($entity_type == 'metadata')) { |
3497
|
|
|
if (($guid) && ($variable_name)) { |
3498
|
|
|
switch ($variable_name) { |
3499
|
|
|
case 'renderedentity' : |
3500
|
|
|
elgg_set_viewtype('default'); |
3501
|
|
|
$view = elgg_view_entity(get_entity($guid)); |
3502
|
|
|
elgg_set_viewtype(); |
3503
|
|
|
|
3504
|
|
|
$tmp = new \ElggMetadata(); |
3505
|
|
|
$tmp->type = 'volatile'; |
3506
|
|
|
$tmp->name = 'renderedentity'; |
3507
|
|
|
$tmp->value = $view; |
3508
|
|
|
$tmp->entity_guid = $guid; |
3509
|
|
|
|
3510
|
|
|
return $tmp; |
3511
|
|
|
|
3512
|
|
|
break; |
|
|
|
|
3513
|
|
|
} |
3514
|
|
|
} |
3515
|
|
|
} |
3516
|
|
|
} |
3517
|
|
|
|
3518
|
|
|
/** |
3519
|
|
|
* Export the annotations for the specified entity |
3520
|
|
|
* |
3521
|
|
|
* @param string $hook 'export' |
3522
|
|
|
* @param string $type 'all' |
3523
|
|
|
* @param mixed $returnvalue Default return value |
3524
|
|
|
* @param mixed $params Parameters determining what annotations to export |
3525
|
|
|
* |
3526
|
|
|
* @elgg_plugin_hook export all |
3527
|
|
|
* |
3528
|
|
|
* @return array |
3529
|
|
|
* @throws InvalidParameterException |
3530
|
|
|
* @access private |
3531
|
|
|
* @deprecated 1.9 |
3532
|
|
|
*/ |
3533
|
|
|
function export_annotation_plugin_hook($hook, $type, $returnvalue, $params) { |
3534
|
|
|
// Sanity check values |
3535
|
|
|
if ((!is_array($params)) && (!isset($params['guid']))) { |
3536
|
|
|
throw new \InvalidParameterException("GUID has not been specified during export, this should never happen."); |
3537
|
|
|
} |
3538
|
|
|
|
3539
|
|
|
if (!is_array($returnvalue)) { |
3540
|
|
|
throw new \InvalidParameterException("Entity serialization function passed a non-array returnvalue parameter"); |
3541
|
|
|
} |
3542
|
|
|
|
3543
|
|
|
$guid = (int)$params['guid']; |
3544
|
|
|
$options = array('guid' => $guid, 'limit' => 0); |
3545
|
|
|
if (isset($params['name'])) { |
3546
|
|
|
$options['annotation_name'] = $params['name']; |
3547
|
|
|
} |
3548
|
|
|
|
3549
|
|
|
$result = elgg_get_annotations($options); |
3550
|
|
|
|
3551
|
|
|
if ($result) { |
3552
|
|
|
foreach ($result as $r) { |
|
|
|
|
3553
|
|
|
$returnvalue[] = $r->export(); |
3554
|
|
|
} |
3555
|
|
|
} |
3556
|
|
|
|
3557
|
|
|
return $returnvalue; |
3558
|
|
|
} |
3559
|
|
|
|
3560
|
|
|
/** |
3561
|
|
|
* Handler called by trigger_plugin_hook on the "import" event. |
3562
|
|
|
* |
3563
|
|
|
* @param string $hook volatile |
3564
|
|
|
* @param string $entity_type metadata |
3565
|
|
|
* @param string $returnvalue Return value from previous hook |
3566
|
|
|
* @param array $params The parameters |
3567
|
|
|
* |
3568
|
|
|
* @return null |
3569
|
|
|
* @elgg_plugin_hook_handler volatile metadata |
3570
|
|
|
* @todo investigate more. |
3571
|
|
|
* @throws ImportException |
3572
|
|
|
* @access private |
3573
|
|
|
* @deprecated 1.9 |
3574
|
|
|
*/ |
3575
|
|
|
function import_extender_plugin_hook($hook, $entity_type, $returnvalue, $params) { |
3576
|
|
|
$element = $params['element']; |
3577
|
|
|
|
3578
|
|
|
$tmp = NULL; |
|
|
|
|
3579
|
|
|
|
3580
|
|
|
if ($element instanceof ODDMetaData) { |
3581
|
|
|
/* @var ODDMetaData $element */ |
3582
|
|
|
// Recall entity |
3583
|
|
|
$entity_uuid = $element->getAttribute('entity_uuid'); |
3584
|
|
|
$entity = get_entity_from_uuid($entity_uuid); |
|
|
|
|
3585
|
|
|
if (!$entity) { |
3586
|
|
|
throw new \ImportException("Entity '" . $entity_uuid . "' could not be found."); |
|
|
|
|
3587
|
|
|
} |
3588
|
|
|
|
3589
|
|
|
oddmetadata_to_elggextender($entity, $element); |
|
|
|
|
3590
|
|
|
|
3591
|
|
|
// Save |
3592
|
|
|
if (!$entity->save()) { |
3593
|
|
|
$attr_name = $element->getAttribute('name'); |
3594
|
|
|
$msg = "There was a problem updating '" . $attr_name . "' on entity '" . $entity_uuid . "'"; |
3595
|
|
|
throw new \ImportException($msg); |
|
|
|
|
3596
|
|
|
} |
3597
|
|
|
|
3598
|
|
|
return true; |
3599
|
|
|
} |
3600
|
|
|
} |
3601
|
|
|
|
3602
|
|
|
/** |
3603
|
|
|
* Utility function used by import_extender_plugin_hook() to process |
3604
|
|
|
* an ODDMetaData and add it to an entity. This function does not |
3605
|
|
|
* hit ->save() on the entity (this lets you construct in memory) |
3606
|
|
|
* |
3607
|
|
|
* @param \ElggEntity $entity The entity to add the data to. |
3608
|
|
|
* @param ODDMetaData $element The OpenDD element |
3609
|
|
|
* |
3610
|
|
|
* @return bool |
3611
|
|
|
* @access private |
3612
|
|
|
* @deprecated 1.9 |
3613
|
|
|
*/ |
3614
|
|
|
function oddmetadata_to_elggextender(\ElggEntity $entity, ODDMetaData $element) { |
3615
|
|
|
// Get the type of extender (metadata, type, attribute etc) |
3616
|
|
|
$type = $element->getAttribute('type'); |
3617
|
|
|
$attr_name = $element->getAttribute('name'); |
3618
|
|
|
$attr_val = $element->getBody(); |
3619
|
|
|
|
3620
|
|
|
switch ($type) { |
3621
|
|
|
// Ignore volatile items |
3622
|
|
|
case 'volatile' : |
3623
|
|
|
break; |
3624
|
|
|
case 'annotation' : |
3625
|
|
|
$entity->annotate($attr_name, $attr_val); |
3626
|
|
|
break; |
3627
|
|
|
case 'metadata' : |
3628
|
|
|
$entity->setMetadata($attr_name, $attr_val, "", true); |
3629
|
|
|
break; |
3630
|
|
|
default : // Anything else assume attribute |
3631
|
|
|
$entity->set($attr_name, $attr_val); |
|
|
|
|
3632
|
|
|
} |
3633
|
|
|
|
3634
|
|
|
// Set time if appropriate |
3635
|
|
|
$attr_time = $element->getAttribute('published'); |
3636
|
|
|
if ($attr_time) { |
3637
|
|
|
$entity->set('time_updated', $attr_time); |
|
|
|
|
3638
|
|
|
} |
3639
|
|
|
|
3640
|
|
|
return true; |
3641
|
|
|
} |
3642
|
|
|
|
3643
|
|
|
/** |
3644
|
|
|
* Handler called by trigger_plugin_hook on the "export" event. |
3645
|
|
|
* |
3646
|
|
|
* @param string $hook export |
3647
|
|
|
* @param string $entity_type all |
3648
|
|
|
* @param mixed $returnvalue Value returned from previous hook |
3649
|
|
|
* @param mixed $params Params |
3650
|
|
|
* |
3651
|
|
|
* @return array |
3652
|
|
|
* @access private |
3653
|
|
|
* |
3654
|
|
|
* @throws InvalidParameterException |
3655
|
|
|
* @deprecated 1.9 |
3656
|
|
|
*/ |
3657
|
|
|
function export_metadata_plugin_hook($hook, $entity_type, $returnvalue, $params) { |
3658
|
|
|
// Sanity check values |
3659
|
|
|
if ((!is_array($params)) && (!isset($params['guid']))) { |
3660
|
|
|
throw new \InvalidParameterException("GUID has not been specified during export, this should never happen."); |
3661
|
|
|
} |
3662
|
|
|
|
3663
|
|
|
if (!is_array($returnvalue)) { |
3664
|
|
|
throw new \InvalidParameterException("Entity serialisation function passed a non-array returnvalue parameter"); |
3665
|
|
|
} |
3666
|
|
|
|
3667
|
|
|
$result = elgg_get_metadata(array( |
3668
|
|
|
'guid' => (int)$params['guid'], |
3669
|
|
|
'limit' => 0, |
3670
|
|
|
)); |
3671
|
|
|
|
3672
|
|
|
if ($result) { |
3673
|
|
|
/* @var \ElggMetadata[] $result */ |
3674
|
|
|
foreach ($result as $r) { |
3675
|
|
|
$returnvalue[] = $r->export(); |
|
|
|
|
3676
|
|
|
} |
3677
|
|
|
} |
3678
|
|
|
|
3679
|
|
|
return $returnvalue; |
3680
|
|
|
} |
3681
|
|
|
|
3682
|
|
|
/** |
3683
|
|
|
* Handler called by trigger_plugin_hook on the "export" event. |
3684
|
|
|
* |
3685
|
|
|
* @param string $hook export |
3686
|
|
|
* @param string $entity_type all |
3687
|
|
|
* @param mixed $returnvalue Previous hook return value |
3688
|
|
|
* @param array $params Parameters |
3689
|
|
|
* |
3690
|
|
|
* @elgg_event_handler export all |
3691
|
|
|
* @return mixed |
3692
|
|
|
* @throws InvalidParameterException |
3693
|
|
|
* @access private |
3694
|
|
|
* @deprecated 1.9 |
3695
|
|
|
*/ |
3696
|
|
|
function export_relationship_plugin_hook($hook, $entity_type, $returnvalue, $params) { |
3697
|
|
|
// Sanity check values |
3698
|
|
|
if ((!is_array($params)) && (!isset($params['guid']))) { |
3699
|
|
|
throw new \InvalidParameterException("GUID has not been specified during export, this should never happen."); |
3700
|
|
|
} |
3701
|
|
|
|
3702
|
|
|
if (!is_array($returnvalue)) { |
3703
|
|
|
throw new \InvalidParameterException("Entity serialisation function passed a non-array returnvalue parameter"); |
3704
|
|
|
} |
3705
|
|
|
|
3706
|
|
|
$guid = (int)$params['guid']; |
3707
|
|
|
|
3708
|
|
|
$result = get_entity_relationships($guid); |
3709
|
|
|
|
3710
|
|
|
if ($result) { |
|
|
|
|
3711
|
|
|
foreach ($result as $r) { |
3712
|
|
|
$returnvalue[] = $r->export(); |
|
|
|
|
3713
|
|
|
} |
3714
|
|
|
} |
3715
|
|
|
|
3716
|
|
|
return $returnvalue; |
3717
|
|
|
} |
3718
|
|
|
|
3719
|
|
|
/** |
3720
|
|
|
* Handler called by trigger_plugin_hook on the "import" event. |
3721
|
|
|
* |
3722
|
|
|
* @param string $hook import |
3723
|
|
|
* @param string $entity_type all |
3724
|
|
|
* @param mixed $returnvalue Value from previous hook |
3725
|
|
|
* @param mixed $params Array of params |
3726
|
|
|
* |
3727
|
|
|
* @return mixed |
3728
|
|
|
* @access private |
3729
|
|
|
* @deprecated 1.9 |
3730
|
|
|
*/ |
3731
|
|
|
function import_relationship_plugin_hook($hook, $entity_type, $returnvalue, $params) { |
3732
|
|
|
$element = $params['element']; |
3733
|
|
|
|
3734
|
|
|
$tmp = NULL; |
3735
|
|
|
|
3736
|
|
|
if ($element instanceof ODDRelationship) { |
3737
|
|
|
$tmp = new \ElggRelationship(); |
3738
|
|
|
$tmp->import($element); |
|
|
|
|
3739
|
|
|
|
3740
|
|
|
return $tmp; |
3741
|
|
|
} |
3742
|
|
|
return $tmp; |
3743
|
|
|
} |
3744
|
|
|
|
3745
|
|
|
/** |
3746
|
|
|
* Returns the SQL where clause for a table with access_id and enabled columns. |
3747
|
|
|
* |
3748
|
|
|
* This handles returning where clauses for ACCESS_FRIENDS in addition to using |
3749
|
|
|
* get_access_list() for access collections and the standard access levels. |
3750
|
|
|
* |
3751
|
|
|
* Note that if this code is executed in privileged mode it will return (1=1). |
3752
|
|
|
* |
3753
|
|
|
* @param string $table_prefix Optional table prefix for the access code. |
3754
|
|
|
* @param int $owner Optional user guid to get access information for. Defaults |
3755
|
|
|
* to logged in user. |
3756
|
|
|
* @return string |
3757
|
|
|
* @access private |
3758
|
|
|
* @deprecated 1.9 Use _elgg_get_access_where_sql() |
3759
|
|
|
*/ |
3760
|
|
|
function get_access_sql_suffix($table_prefix = '', $owner = null) { |
3761
|
|
|
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by _elgg_get_access_where_sql()', 1.9); |
3762
|
|
|
return _elgg_get_access_where_sql(array( |
3763
|
|
|
'table_alias' => $table_prefix, |
3764
|
|
|
'user_guid' => (int)$owner, |
3765
|
|
|
)); |
3766
|
|
|
} |
3767
|
|
|
|
3768
|
|
|
/** |
3769
|
|
|
* Get the name of the most recent plugin to be called in the |
3770
|
|
|
* call stack (or the plugin that owns the current page, if any). |
3771
|
|
|
* |
3772
|
|
|
* i.e., if the last plugin was in /mod/foobar/, this would return foo_bar. |
3773
|
|
|
* |
3774
|
|
|
* @param boolean $mainfilename If set to true, this will instead determine the |
3775
|
|
|
* context from the main script filename called by |
3776
|
|
|
* the browser. Default = false. |
3777
|
|
|
* |
3778
|
|
|
* @return string|false Plugin name, or false if no plugin name was called |
3779
|
|
|
* @since 1.8.0 |
3780
|
|
|
* @access private |
3781
|
|
|
* @deprecated 1.9 |
3782
|
|
|
*/ |
3783
|
|
|
function elgg_get_calling_plugin_id($mainfilename = false) { |
|
|
|
|
3784
|
|
|
elgg_deprecated_notice('elgg_get_calling_plugin_id() is deprecated', 1.9); |
3785
|
|
|
if (!$mainfilename) { |
3786
|
|
View Code Duplication |
if ($backtrace = debug_backtrace()) { |
3787
|
|
|
foreach ($backtrace as $step) { |
3788
|
|
|
$file = $step['file']; |
3789
|
|
|
$file = str_replace("\\", "/", $file); |
3790
|
|
|
$file = str_replace("//", "/", $file); |
3791
|
|
|
if (preg_match("/mod\/([a-zA-Z0-9\-\_]*)\/start\.php$/", $file, $matches)) { |
3792
|
|
|
return $matches[1]; |
3793
|
|
|
} |
3794
|
|
|
} |
3795
|
|
|
} |
3796
|
|
|
} else { |
3797
|
|
|
//@todo this is a hack -- plugins do not have to match their page handler names! |
3798
|
|
View Code Duplication |
if ($handler = get_input('handler', false)) { |
3799
|
|
|
return $handler; |
3800
|
|
|
} else { |
3801
|
|
|
$file = $_SERVER["SCRIPT_NAME"]; |
3802
|
|
|
$file = str_replace("\\", "/", $file); |
3803
|
|
|
$file = str_replace("//", "/", $file); |
3804
|
|
|
if (preg_match("/mod\/([a-zA-Z0-9\-\_]*)\//", $file, $matches)) { |
3805
|
|
|
return $matches[1]; |
3806
|
|
|
} |
3807
|
|
|
} |
3808
|
|
|
} |
3809
|
|
|
return false; |
3810
|
|
|
} |
3811
|
|
|
|
3812
|
|
|
/** |
3813
|
|
|
* Returns the \ElggPlugin entity of the last plugin called. |
3814
|
|
|
* |
3815
|
|
|
* @return ElggPlugin|false |
3816
|
|
|
* @since 1.8.0 |
3817
|
|
|
* @access private |
3818
|
|
|
* @deprecated 1.9 |
3819
|
|
|
*/ |
3820
|
|
View Code Duplication |
function elgg_get_calling_plugin_entity() { |
|
|
|
|
3821
|
|
|
elgg_deprecated_notice("elgg_get_calling_plugin_entity() is deprecated.", 1.9); |
3822
|
|
|
$plugin_id = elgg_get_calling_plugin_id(); |
|
|
|
|
3823
|
|
|
|
3824
|
|
|
if ($plugin_id) { |
|
|
|
|
3825
|
|
|
return elgg_get_plugin_from_id($plugin_id); |
3826
|
|
|
} |
3827
|
|
|
|
3828
|
|
|
return false; |
3829
|
|
|
} |
3830
|
|
|
|
3831
|
|
|
return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
3832
|
|
|
// Register a startup event |
3833
|
|
|
$events->registerHandler('init', 'system', '_export_init', 100); |
3834
|
|
|
|
3835
|
|
|
/** Register the import hook */ |
3836
|
|
|
$hooks->registerHandler("import", "all", "import_entity_plugin_hook", 0); |
3837
|
|
|
$hooks->registerHandler("import", "all", "import_extender_plugin_hook", 2); |
3838
|
|
|
$hooks->registerHandler("import", "all", "import_relationship_plugin_hook", 3); |
3839
|
|
|
|
3840
|
|
|
/** Register the hook, ensuring entities are serialised first */ |
3841
|
|
|
$hooks->registerHandler("export", "all", "export_entity_plugin_hook", 0); |
3842
|
|
|
$hooks->registerHandler("export", "all", "export_annotation_plugin_hook", 2); |
3843
|
|
|
$hooks->registerHandler("export", "all", "export_metadata_plugin_hook", 2); |
3844
|
|
|
$hooks->registerHandler("export", "all", "export_relationship_plugin_hook", 3); |
3845
|
|
|
|
3846
|
|
|
/** Hook to get certain named bits of volatile data about an entity */ |
3847
|
|
|
$hooks->registerHandler('volatile', 'metadata', 'volatile_data_export_plugin_hook'); |
3848
|
|
|
}; |
3849
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.