1<?php
2
3use Elgg\Database\Entities;
4use Elgg\Database\Clauses\OrderByClause;
5
6/**
7 * Allow disabled entities and metadata to be returned by getter functions
8 *
9 * @todo when removing this global, make sure it is no longer used in ElggSession
10 *
11 * @global bool $ENTITY_SHOW_HIDDEN_OVERRIDE
12 * @internal
13 * @deprecated 3.0
14 */
15global $ENTITY_SHOW_HIDDEN_OVERRIDE;
16
17/**
18 * Removes a config setting.
19 *
20 * @param string $name The name of the field.
21 *
22 * @return bool Success or failure
23 *
24 * @see get_config()
25 * @see set_config()
26 *
27 * @deprecated 3.0 Use elgg_remove_config()
28 */
29function unset_config($name) {
30	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_remove_config().', '3.0');
31	return elgg_remove_config($name);
32}
33
34/**
35 * Add or update a config setting.
36 *
37 * Plugin authors should use elgg_set_config().
38 *
39 * If the config name already exists, it will be updated to the new value.
40 *
41 * @param string $name      The name of the configuration value
42 * @param mixed  $value     Its value
43 *
44 * @return bool
45 * @see unset_config()
46 * @see get_config()
47 * @internal
48 *
49 * @deprecated 3.0 Use elgg_save_config()
50 */
51function set_config($name, $value) {
52	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_save_config().', '3.0');
53	return elgg_save_config($name, $value);
54}
55
56/**
57 * Gets a configuration value
58 *
59 * Plugin authors should use elgg_get_config().
60 *
61 * @param string $name      The name of the config value
62 *
63 * @return mixed|null
64 * @see set_config()
65 * @see unset_config()
66 * @internal
67 *
68 * @deprecated 3.0 Use elgg_get_config()
69 */
70function get_config($name) {
71	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_get_config().', '3.0');
72	return elgg_get_config($name);
73}
74
75/**
76 * Add an admin area section or child section.
77 * This is a wrapper for elgg_register_menu_item().
78 *
79 * Used in conjuction with http://elgg.org/admin/section_id/child_section style
80 * page handler. See the documentation at the top of this file for more details
81 * on that.
82 *
83 * The text of the menu item is obtained from elgg_echo(admin:$parent_id:$menu_id)
84 *
85 * This function handles registering the parent if it has not been registered.
86 *
87 * @param string $section   The menu section to add to
88 * @param string $menu_id   The unique ID of section
89 * @param string $parent_id If a child section, the parent section id
90 * @param int    $priority  The menu item priority
91 *
92 * @return bool
93 * @since 1.8.0
94 *
95 * @deprecated 3.0 Use elgg_register_menu_item()
96 */
97function elgg_register_admin_menu_item($section, $menu_id, $parent_id = null, $priority = 100) {
98	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_register_menu_item().', '3.0');
99	// make sure parent is registered
100	if ($parent_id && !elgg_is_menu_item_registered('page', $parent_id)) {
101		elgg_register_admin_menu_item($section, $parent_id);
102	}
103
104	// in the admin section parents never have links
105	if ($parent_id) {
106		$href = "admin/$parent_id/$menu_id";
107	} else {
108		$href = "admin/$menu_id";
109	}
110
111	$name = $menu_id;
112	if ($parent_id) {
113		$name = "$parent_id:$name";
114	}
115
116	return elgg_register_menu_item('page', [
117		'name' => $name,
118		'href' => $href,
119		'text' => elgg_echo("admin:$name"),
120		'context' => 'admin',
121		'parent_name' => $parent_id,
122		'priority' => $priority,
123		'section' => $section
124	]);
125}
126
127/**
128 * Mark entities with a particular type and subtype as having access permissions
129 * that can be changed independently from their parent entity
130 *
131 * @param string $type    The type - object, user, etc
132 * @param string $subtype The subtype; all subtypes by default
133 *
134 * @return void
135 *
136 * @deprecated 3.0
137 */
138function register_metadata_as_independent($type, $subtype = '*') {
139	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Metadata no longer is access bound.', '3.0');
140}
141
142/**
143 * Determines whether entities of a given type and subtype should not change
144 * their metadata in line with their parent entity
145 *
146 * @param string $type    The type - object, user, etc
147 * @param string $subtype The entity subtype
148 *
149 * @return bool
150 *
151 * @deprecated 3.0
152 */
153function is_metadata_independent($type, $subtype) {
154	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Metadata no longer is access bound.', '3.0');
155
156	return false;
157}
158
159/**
160 * Gets entities based upon attributes in secondary tables.
161 *
162 * @warning requires that the entity type be specified and there can only be one
163 * type.
164 *
165 * @see elgg_get_entities()
166 *
167 * @param array $options Array in format:
168 *
169 * 	attribute_name_value_pairs => ARR (
170 *                                   'name' => 'name',
171 *                                   'value' => 'value',
172 *                                   'operand' => '=', (optional)
173 *                                   'case_sensitive' => false (optional)
174 *                                  )
175 * 	                             If multiple values are sent via
176 *                               an array ('value' => array('value1', 'value2')
177 *                               the pair's operand will be forced to "IN".
178 *
179 * 	attribute_name_value_pairs_operator => null|STR The operator to use for combining
180 *                                        (name = value) OPERATOR (name = value); default is AND
181 *
182 * @return \ElggEntity[]|mixed If count, int. If not count, array. false on errors.
183 * @since 1.9.0
184 * @throws InvalidArgumentException
185 * @deprecated 3.0 Use elgg_get_entities()
186 */
187function elgg_get_entities_from_attributes(array $options = []) {
188    elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_get_entities.', '3.0');
189
190    $options['metadata_name_value_pairs'] = elgg_extract('attribute_name_value_pairs', $options, []);
191    $options['metadata_name_value_pairs_operator'] = elgg_extract('attribute_name_value_pairs_operator', $options, []);
192
193    unset($options['attribute_name_value_pairs']);
194    unset($options['attribute_name_value_pairs_operator']);
195
196    return elgg_get_entities($options);
197}
198
199/**
200 * Ban a user
201 *
202 * @param int    $user_guid The user guid
203 * @param string $reason    A reason
204 *
205 * @return bool
206 *
207 * @deprecated 3.0 Use \ElggUser->ban()
208 */
209function ban_user($user_guid, $reason = "") {
210	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser::ban()', '3.0');
211
212	$user = get_user($user_guid);
213	if (!$user) {
214		return false;
215	}
216
217	return $user->ban($reason);
218}
219
220/**
221 * Unban a user.
222 *
223 * @param int $user_guid Unban a user.
224 *
225 * @return bool
226 *
227 * @deprecated 3.0 Use \ElggUser->unban()
228 */
229function unban_user($user_guid) {
230	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser::unban()', '3.0');
231
232	$user = get_user($user_guid);
233	if (!$user) {
234		return false;
235	}
236
237	return $user->unban();
238}
239
240/**
241 * Makes user $guid an admin.
242 *
243 * @param int $user_guid User guid
244 *
245 * @return bool
246 *
247 * @deprecated 3.0 Use \ElggUser->makeAdmin()
248 */
249function make_user_admin($user_guid) {
250	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser::makeAdmin()', '3.0');
251
252	$user = get_user($user_guid);
253	if (!$user) {
254		return false;
255	}
256
257	return $user->makeAdmin();
258}
259
260/**
261 * Removes user $guid's admin flag.
262 *
263 * @param int $user_guid User GUID
264 *
265 * @return bool
266 *
267 * @deprecated 3.0 Use \ElggUser->removeAdmin()
268 */
269function remove_user_admin($user_guid) {
270	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser::removeAdmin()', '3.0');
271
272	$user = get_user($user_guid);
273	if (!$user) {
274		return false;
275	}
276
277	return $user->removeAdmin();
278}
279
280/**
281 * Gets the validation status of a user.
282 *
283 * @param int $user_guid The user's GUID
284 * @return bool|null Null means status was not set for this user.
285 * @since 1.8.0
286 *
287 * @deprecated 3.0 Use \ElggUser->isValidated()
288 */
289function elgg_get_user_validation_status($user_guid) {
290	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser::isValidated()', '3.0');
291
292	$user = get_user($user_guid);
293	if (!$user) {
294		return false;
295	}
296
297	return $user->isValidated();
298}
299
300/**
301 * Set the validation status for a user.
302 *
303 * @param int    $user_guid The user's GUID
304 * @param bool   $status    Validated (true) or unvalidated (false)
305 * @param string $method    Optional method to say how a user was validated
306 * @return bool
307 * @since 1.8.0
308 *
309 * @deprecated 3.0 Use \ElggUser->setValidationStatus()
310 */
311function elgg_set_user_validation_status($user_guid, $status, $method = '') {
312	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser::setValidationStatus()', '3.0');
313
314	$user = get_user($user_guid);
315	if (!$user) {
316		return false;
317	}
318
319	$user->setValidationStatus($status, $method);
320	return true;
321}
322
323/**
324 * Sets the last action time of the given user to right now.
325 *
326 * @param ElggUser|int $user The user or GUID
327 * @return void
328 *
329 * @deprecated 3.0 Use \ElggUser->setLastAction()
330 */
331function set_last_action($user) {
332	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser::setLastAction()', '3.0');
333
334	if (!$user instanceof ElggUser) {
335		$user = get_user($user);
336	}
337	if (!$user) {
338		return;
339	}
340
341	$user->setLastAction();
342}
343
344/**
345 * Sets the last logon time of the given user to right now.
346 *
347 * @param int $user_guid The user GUID
348 * @return void
349 *
350 * @deprecated 3.0 Use \ElggUser->setLastLogin()
351 */
352function set_last_login($user_guid) {
353	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser::setLastLogin()', '3.0');
354
355	$user = get_user($user_guid);
356	if (!$user) {
357		return;
358	}
359
360	$user->setLastLogin();
361}
362
363/**
364 * Update a specific piece of metadata.
365 *
366 * @param int    $id         ID of the metadata to update
367 * @param string $name       Metadata name
368 * @param string $value      Metadata value
369 * @param string $value_type Value type
370 *
371 * @return bool
372 *
373 * @deprecated 3.0 Use \ElggMetadata->save()
374 */
375function update_metadata($id, $name, $value, $value_type) {
376	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use ElggEntity setter or ElggEntity::setMetadata()', '3.0');
377
378	$metadata = elgg_get_metadata_from_id($id);
379	if (!$metadata) {
380		return false;
381	}
382
383	$metadata->name = $name;
384	$metadata->value_type = $value_type;
385	$metadata->value = $value;
386
387	return $metadata->save();
388}
389
390/**
391 * Create a new metadata object, or update an existing one.
392 *
393 * Metadata can be an array by setting allow_multiple to true, but it is an
394 * indexed array with no control over the indexing.
395 *
396 * @param int    $entity_guid    The entity to attach the metadata to
397 * @param string $name           Name of the metadata
398 * @param string $value          Value of the metadata
399 * @param string $value_type     'text', 'integer', or '' for automatic detection
400 * @param int    $ignored1       This argument is not used
401 * @param null   $ignored2       This argument is not used
402 * @param bool   $allow_multiple Allow multiple values for one key. Default is false
403 *
404 * @return int|false id of metadata or false if failure
405 *
406 * @deprecated 3.0 Use \ElggEntity setter or \Entity->setMetadata()
407 */
408function create_metadata($entity_guid, $name, $value, $value_type = '', $ignored1 = null,
409						 $ignored2 = null, $allow_multiple = false) {
410	elgg_deprecated_notice(
411		__FUNCTION__ . ' is deprecated.
412		Use ElggEntity setter or ElggEntity::setMetadata()',
413		'3.0');
414
415	$entity = get_entity($entity_guid);
416	if (!$entity) {
417		return false;
418	}
419
420	if ($allow_multiple) {
421		return $entity->setMetadata($name, $value, $value_type, $allow_multiple);
422	}
423
424	$metadata = new ElggMetadata();
425	$metadata->entity_guid = $entity_guid;
426	$metadata->name = $name;
427	$metadata->value_type = $value_type;
428	$metadata->value = $value;
429	return $metadata->save();
430}
431
432/**
433 * Returns access collections owned by the entity
434 *
435 * @see add_access_collection()
436 * @see get_members_of_access_collection()
437 *
438 * @param int $owner_guid GUID of the owner
439 * @return \ElggAccessCollection[]|false
440 *
441 * @deprecated 3.0 Use \Entity->getOwnedAccessCollections() or elgg_get_access_collections()
442 */
443function get_user_access_collections($owner_guid) {
444	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggEntity->getOwnedAccessCollections() or elgg_get_access_collections()', '3.0');
445
446	return _elgg_services()->accessCollections->getEntityCollections(['owner_guid' => $owner_guid]);
447}
448
449
450/**
451 * Returns entities based upon metadata.  Also accepts all
452 * options available to elgg_get_entities().  Supports
453 * the singular option shortcut.
454 *
455 * @note Using metadata_names and metadata_values results in a
456 * "names IN (...) AND values IN (...)" clause.  This is subtly
457 * differently than default multiple metadata_name_value_pairs, which use
458 * "(name = value) AND (name = value)" clauses.
459 *
460 * When in doubt, use name_value_pairs.
461 *
462 * To ask for entities that do not have a metadata value, use a custom
463 * where clause like this:
464 *
465 * 	$options['wheres'][] = "NOT EXISTS (
466 *			SELECT 1 FROM {$dbprefix}metadata md
467 *			WHERE md.entity_guid = e.guid
468 *				AND md.name = $name
469 *				AND md.value = $value)";
470 *
471 * @see elgg_get_entities()
472 *
473 * @param array $options Array in format:
474 *
475 * 	metadata_names => null|ARR metadata names
476 *
477 * 	metadata_values => null|ARR metadata values
478 *
479 * 	metadata_name_value_pairs => null|ARR (
480 *                                         name => 'name',
481 *                                         value => 'value',
482 *                                         'operand' => '=',
483 *                                         'case_sensitive' => true
484 *                                        )
485 *                               Currently if multiple values are sent via
486 *                               an array (value => array('value1', 'value2')
487 *                               the pair's operand will be forced to "IN".
488 *                               If passing "IN" as the operand and a string as the value,
489 *                               the value must be a properly quoted and escaped string.
490 *
491 * 	metadata_name_value_pairs_operator => null|STR The operator to use for combining
492 *                                        (name = value) OPERATOR (name = value); default AND
493 *
494 * 	metadata_case_sensitive => BOOL Overall Case sensitive
495 *
496 *  order_by_metadata => null|ARR array(
497 *                                      'name' => 'metadata_text1',
498 *                                      'direction' => ASC|DESC,
499 *                                      'as' => text|integer
500 *                                     )
501 *                                Also supports array('name' => 'metadata_text1')
502 *
503 * @return \ElggEntity[]|mixed If count, int. If not count, array. false on errors.
504 * @since 1.7.0
505 *
506 * @deprecated 3.0 Use elgg_get_entities()
507 */
508function elgg_get_entities_from_metadata(array $options = []) {
509	elgg_deprecated_notice(
510		__FUNCTION__ . ' has been deprecated.
511		elgg_get_entities() now accepts all metadata options.
512	', '3.0');
513
514	return elgg_get_entities($options);
515}
516
517/**
518 * Returns a list of entities filtered by provided metadata.
519 *
520 * @see elgg_get_entities()
521 *
522 * @param array $options Options array
523 *
524 * @return array
525 * @since 1.7.0
526 * @deprecated 3.0 Use elgg_list_entities()
527 */
528function elgg_list_entities_from_metadata($options) {
529	elgg_deprecated_notice(
530		__FUNCTION__ . ' has been deprecated. Use elgg_list_entities().
531	', '3.0');
532
533	return elgg_list_entities($options);
534}
535
536/**
537 * Returns entities based upon annotations.
538 *
539 * Entity creation time is selected as maxtime. To sort based upon
540 * this, pass 'order_by' => 'maxtime asc' || 'maxtime desc'
541 *
542 * @see elgg_get_entities()
543 *
544 * @param array $options Array in format:
545 *
546 * 	annotation_names => null|ARR annotations names
547 *
548 * 	annotation_values => null|ARR annotations values
549 *
550 * 	annotation_name_value_pairs => null|ARR (name = 'name', value => 'value',
551 * 	'operator' => '=', 'case_sensitive' => true) entries.
552 * 	Currently if multiple values are sent via an array (value => array('value1', 'value2')
553 * 	the pair's operator will be forced to "IN".
554 *
555 * 	annotation_name_value_pairs_operator => null|STR The operator to use for combining
556 *  (name = value) OPERATOR (name = value); default AND
557 *
558 * 	annotation_case_sensitive => BOOL Overall Case sensitive
559 *
560 *  order_by_annotation => null|ARR (array('name' => 'annotation_text1', 'direction' => ASC|DESC,
561 *  'as' => text|integer),
562 *
563 *  Also supports array('name' => 'annotation_text1')
564 *
565 *  annotation_owner_guids => null|ARR guids for annotaiton owners
566 *
567 * @return mixed If count, int. If not count, array. false on errors.
568 * @since 1.7.0
569 * @deprecated 3.0 Use elgg_get_entities()
570 */
571function elgg_get_entities_from_annotations(array $options = []) {
572	elgg_deprecated_notice(
573		__FUNCTION__ . ' has been deprecated.
574		elgg_get_entities() now accepts all annotation options
575	', '3.0');
576
577	return elgg_get_entities($options);
578}
579
580/**
581 * Returns a viewable list of entities from annotations.
582 *
583 * @param array $options Options array
584 *
585 * @see elgg_get_entities_from_annotations()
586 * @see elgg_list_entities()
587 *
588 * @return string
589 * @deprecated 3.0 Use elgg_list_entities()
590 */
591function elgg_list_entities_from_annotations($options = []) {
592	elgg_deprecated_notice(
593		__FUNCTION__ . ' has been deprecated. Use elgg_list_entities().
594	', '3.0');
595	return elgg_list_entities($options);
596}
597
598
599/**
600 * Return entities matching a given query joining against a relationship.
601 *
602 * By default the function finds relationship targets. E.g.:
603 *
604 *   // find groups with a particular member:
605 *   $options = [
606 *       'relationship' => 'member',
607 *       'relationship_guid' => $member->guid,
608 *   ];
609 *
610 *   // find people the user has friended
611 *   $options = [
612 *       'relationship' => 'friend',
613 *       'relationship_guid' => $user->guid,
614 *   ];
615 *
616 *   // find stuff created by friends (not in groups)
617 *   $options = [
618 *       'relationship' => 'friend',
619 *       'relationship_guid' => $user->guid,
620 *       'relationship_join_on' => 'container_guid',
621 *   ];
622 *
623 * To find relationship subjects, set "inverse_relationship" to true. E.g.:
624 *
625 *   // find members of a particular group
626 *   $options = [
627 *       'relationship' => 'member',
628 *       'relationship_guid' => $group->guid,
629 *       'inverse_relationship' => true,
630 *   ];
631 *
632 *   // find users who have friended the current user
633 *   $options = [
634 *       'relationship' => 'friend',
635 *       'relationship_guid' => $user->guid,
636 *       'inverse_relationship' => true,
637 *   ];
638 *
639 * @note You may want to specify "type" because relationship types might be used for other entities.
640 *
641 * To ask for entities that do not have a particular relationship to an entity,
642 * use a custom where clause like the following:
643 *
644 * 	$options['wheres'][] = "NOT EXISTS (
645 *			SELECT 1 FROM {$db_prefix}entity_relationships
646 *				WHERE guid_one = e.guid
647 *				AND relationship = '$relationship'
648 *		)";
649 *
650 * @see elgg_get_entities()
651 *
652 * @param array $options Array in format:
653 *
654 *  relationship => null|STR Type of the relationship. E.g. "member"
655 *
656 *  relationship_guid => null|INT GUID of the subject of the relationship, unless "inverse_relationship" is set
657 *                                to true, in which case this will specify the target.
658 *
659 *  inverse_relationship => false|BOOL Are we searching for relationship subjects? By default, the query finds
660 *                                     targets of relationships.
661 *
662 *  relationship_join_on => null|STR How the entities relate: guid (default), container_guid, or owner_guid
663 *                                   Examples using the relationship 'friend':
664 *                                   1. use 'guid' if you want the user's friends
665 *                                   2. use 'owner_guid' if you want the entities the user's friends own
666 *                                      (including in groups)
667 *                                   3. use 'container_guid' if you want the entities in the user's personal
668 *                                      space (non-group)
669 *
670 * 	relationship_created_time_lower => null|INT Relationship created time lower boundary in epoch time
671 *
672 * 	relationship_created_time_upper => null|INT Relationship created time upper boundary in epoch time
673 *
674 * @return \ElggEntity[]|mixed If count, int. If not count, array. false on errors.
675 * @since 1.7.0
676 *
677 * @deprecated 3.0 Use elgg_get_entities()
678 */
679function elgg_get_entities_from_relationship($options) {
680	elgg_deprecated_notice(
681		__FUNCTION__ . ' has been deprecated.
682		elgg_get_entities() now accepts all relationship options.
683	', '3.0');
684
685	return elgg_get_entities($options);
686}
687
688/**
689 * Returns a viewable list of entities by relationship
690 *
691 * @param array $options Options array for retrieval of entities
692 *
693 * @see elgg_list_entities()
694 * @see elgg_get_entities_from_relationship()
695 *
696 * @return string The viewable list of entities
697 * @deprecated 3.0 Use elgg_list_entities()
698 */
699function elgg_list_entities_from_relationship(array $options = []) {
700	elgg_deprecated_notice(
701		__FUNCTION__ . ' has been deprecated. Use elgg_list_entities().
702	', '3.0');
703
704	return elgg_list_entities($options);
705}
706
707/**
708 * Returns entities based upon private settings.  Also accepts all
709 * options available to elgg_get_entities().  Supports
710 * the singular option shortcut.
711 *
712 * @see elgg_get_entities()
713 *
714 * @param array $options Array in format:
715 *
716 * 	private_setting_names => null|ARR private setting names
717 *
718 * 	private_setting_values => null|ARR metadata values
719 *
720 * 	private_setting_name_value_pairs => null|ARR (
721 *                                         name => 'name',
722 *                                         value => 'value',
723 *                                         'operand' => '=',
724 *                                        )
725 * 	                             Currently if multiple values are sent via
726 *                               an array (value => array('value1', 'value2')
727 *                               the pair's operand will be forced to "IN".
728 *
729 * 	private_setting_name_value_pairs_operator => null|STR The operator to use for combining
730 *                                        (name = value) OPERATOR (name = value); default AND
731 *
732 *  private_setting_name_prefix => STR A prefix to apply to all private settings. Used to
733 *                                     namespace plugin user settings or by plugins to namespace
734 *                                     their own settings.
735 *
736 *
737 * @return mixed int If count, int. If not count, array. false on errors.
738 * @since 1.8.0
739 * @deprecated 3.0 Use elgg_get_entities()
740 */
741function elgg_get_entities_from_private_settings(array $options = []) {
742	elgg_deprecated_notice(
743		__FUNCTION__ . ' has been deprecated.
744		elgg_get_entities() now accepts all private settings options.
745	', '3.0');
746
747	return elgg_get_entities($options);
748}
749
750/**
751 * Lists entities from an access collection
752 *
753 * @param array $options See elgg_list_entities() and elgg_get_entities_from_access_id()
754 *
755 * @see elgg_list_entities()
756 * @see elgg_get_entities_from_access_id()
757 *
758 * @return string
759 * @deprecated 3.0 Use elgg_list_entities()
760 */
761function elgg_list_entities_from_access_id(array $options = []) {
762	elgg_deprecated_notice(
763		__FUNCTION__ . ' has been deprecated. Use elgg_list_entities().
764	', '3.0');
765
766	return elgg_list_entities($options);
767}
768
769/**
770 * Return entities based upon access id.
771 *
772 * @param array $options Any options accepted by {@link elgg_get_entities()} and
773 * 	access_id => int The access ID of the entity.
774 *
775 * @see elgg_get_entities()
776 * @return mixed If count, int. If not count, array. false on errors.
777 * @since 1.7.0
778 *
779 * @deprected 3.0 Use elgg_get_entities()
780 */
781function elgg_get_entities_from_access_id(array $options = []) {
782
783	elgg_deprecated_notice(
784		__FUNCTION__ . ' has been deprecated.
785		Use elgg_get_entities() with "access_ids" option.
786	', '3.0');
787
788	// restrict the resultset to access collection provided
789	if (!isset($options['access_id']) && !isset($options['access_ids'])) {
790		return false;
791	}
792
793	return elgg_get_entities($options);
794}
795
796/**
797 * Get entities ordered by a mathematical calculation on annotation values
798 *
799 * @tip Note that this function uses { @link elgg_get_annotations() } to return a list of entities ordered by a mathematical
800 * calculation on annotation values, and { @link elgg_get_entities_from_annotations() } to return a count of entities
801 * if $options['count'] is set to a truthy value
802 *
803 * @param array $options An options array:
804 * 	'calculation'            => The calculation to use. Must be a valid MySQL function.
805 *                              Defaults to sum.  Result selected as 'annotation_calculation'.
806 *                              Don't confuse this "calculation" option with the
807 *                              "annotation_calculation" option to elgg_get_annotations().
808 *                              This "calculation" option is applied to each entity's set of
809 *                              annotations and is selected as annotation_calculation for that row.
810 *                              See the docs for elgg_get_annotations() for proper use of the
811 *                              "annotation_calculation" option.
812 *	'order_by'               => The order for the sorting. Defaults to 'annotation_calculation desc'.
813 *	'annotation_names'       => The names of annotations on the entity.
814 *	'annotation_values'	     => The values of annotations on the entity.
815 *
816 *	'metadata_names'         => The name of metadata on the entity.
817 *	'metadata_values'        => The value of metadata on the entitiy.
818 *	'callback'               => Callback function to pass each row through.
819 *                              @tip This function is different from other ege* functions,
820 *                              as it uses a metastring-based getter function { @link elgg_get_annotations() },
821 *                              therefore the callback function should be a derivative of { @link entity_row_to_elggstar() }
822 *                              and not of { @link row_to_annotation() }
823 *
824 * @return \ElggEntity[]|int An array or a count of entities
825 * @see elgg_get_annotations()
826 * @see elgg_get_entities_from_annotations()
827 *
828 * @deprecated 3.0 Use elgg_get_entities()
829 */
830function elgg_get_entities_from_annotation_calculation($options) {
831	elgg_deprecated_notice(
832		__FUNCTION__ . ' has been deprecated.
833		Use elgg_get_entities() with "annotation_sort_by_calculation" option.
834		To sort in an ascending order, pass "order_by" => new OrderByClause("annotation_calculation", "asc")
835	', '3.0');
836
837	if (empty($options['count'])) {
838		$options['annotation_sort_by_calculation'] = elgg_extract('calculation', $options, 'sum', false);
839	}
840	return Entities::find($options);
841}
842
843/**
844 * List entities from an annotation calculation.
845 *
846 * @see elgg_get_entities_from_annotation_calculation()
847 *
848 * @param array $options An options array.
849 *
850 * @return string
851 *
852 * @deprecated 3.0 Use elgg_list_entities()
853 */
854function elgg_list_entities_from_annotation_calculation($options) {
855	elgg_deprecated_notice(
856		__FUNCTION__ . ' has been deprecated.
857		Use elgg_list_entities() with "annotation_sort_by_calculation" option.
858		To sort in an ascending order, pass "order_by" => new OrderByClause("annotation_calculation", "asc")
859	', '3.0');
860
861	if (empty($options['count'])) {
862		$options['annotation_sort_by_calculation'] = elgg_extract('calculation', $options, 'sum', false);
863	}
864
865	return elgg_list_entities($options, 'elgg_get_entities');
866}
867
868
869/**
870 * Enables or disables a metastrings-based object by its id.
871 *
872 * @warning To enable disabled metastrings you must first use
873 * {@link access_show_hidden_entities()}.
874 *
875 * @param int    $id      The object's ID
876 * @param string $enabled Value to set to: yes or no
877 * @param string $type    Metastring type: metadata or annotation
878 *
879 * @return bool
880 * @throws InvalidParameterException
881 * @internal
882 *
883 * @deprecated 3.0 Use \ElggAnnotation::enable()
884 */
885function _elgg_set_metastring_based_object_enabled_by_id($id, $enabled, $type) {
886
887	elgg_deprecated_notice(
888		__FUNCTION__ . ' has been deprecated.
889		Use ElggAnnotation::enable()
890	', '3.0');
891
892	if (!in_array($type, ['annotation', 'annotations'])) {
893		return false;
894	}
895
896	$annotation = elgg_get_annotation_from_id($id);
897	if (!$annotation) {
898		return false;
899	}
900
901	if ($enabled === 'no' || $enabled === 0 || $enabled === false) {
902		return $annotation->disable();
903	} else if ($enabled === 'yes' || $enabled === 1 || $enabled === true) {
904		return $annotation->enable();
905	}
906
907	return false;
908}
909
910/**
911 * Returns a singular metastring-based object by its ID.
912 *
913 * @param int    $id   The metastring-based object's ID
914 * @param string $type The type: annotation or metadata
915 * @return \ElggExtender
916 * @internal
917 *
918 * @deprecated 3.0 Use elgg_get_metadata_from_id()
919 */
920function _elgg_get_metastring_based_object_from_id($id, $type) {
921
922	elgg_deprecated_notice(
923		__FUNCTION__ . ' has been deprecated.
924		Use elgg_get_metadata_from_id() and elgg_get_annotation_from_id()
925	', '3.0');
926
927	$id = (int) $id;
928	if (!$id) {
929		return false;
930	}
931
932	if ($type == 'metadata') {
933		$object = elgg_get_metadata_from_id($id);
934	} else {
935		$object = elgg_get_annotation_from_id($id);
936	}
937
938	return $object;
939}
940
941/**
942 * Deletes a metastring-based object by its id
943 *
944 * @param int    $id   The object's ID
945 * @param string $type The object's metastring type: annotation or metadata
946 * @return bool
947 * @internal
948 *
949 * @deprecated 3.0 Use \ElggMetadata::delete()
950 */
951function _elgg_delete_metastring_based_object_by_id($id, $type) {
952
953	elgg_deprecated_notice(
954		__FUNCTION__ . ' has been deprecated.
955		Use ElggMetadata::delete() and ElggAnnotation::delete()
956	', '3.0');
957
958	switch ($type) {
959		case 'annotations':
960		case 'annotation':
961			$object = elgg_get_annotation_from_id($id);
962			break;
963
964		case 'metadata':
965			$object = elgg_get_metadata_from_id($id);
966			break;
967
968		default:
969			return false;
970	}
971
972	if ($object) {
973		return $object->delete();
974	}
975
976	return false;
977}
978
979/**
980 * Get the URL for this metadata
981 *
982 * By default this links to the export handler in the current view.
983 *
984 * @param int $id Metadata ID
985 *
986 * @return mixed
987 * @deprecated 3.0
988 */
989function get_metadata_url($id) {
990	elgg_deprecated_notice(__FUNCTION__ . ' has been deprecated and will be removed', '3.0');
991	$metadata = elgg_get_metadata_from_id($id);
992	if (!$metadata instanceof ElggMetadata) {
993		return;
994	}
995
996	return $metadata->getURL();
997}
998
999
1000/**
1001 * Create a new annotation.
1002 *
1003 * @param int    $entity_guid GUID of entity to be annotated
1004 * @param string $name        Name of annotation
1005 * @param string $value       Value of annotation
1006 * @param string $value_type  Type of value (default is auto detection)
1007 * @param int    $owner_guid  Owner of annotation (default is logged in user)
1008 * @param int    $access_id   Access level of annotation
1009 *
1010 * @return int|bool id on success or false on failure
1011 * @deprecated 3.0 Use \ElggAnnotation::save() or \ElggEntity::annotate()
1012 */
1013function create_annotation($entity_guid, $name, $value, $value_type = '', $owner_guid = 0, $access_id = ACCESS_PRIVATE) {
1014	elgg_deprecated_notice(
1015		__FUNCTION__ . ' has been deprecated.
1016		Use ElggAnnotation::save() or ElggEntity::annotate()
1017		', '3.0'
1018	);
1019
1020	$annotation = new ElggAnnotation();
1021	$annotation->entity_guid = $entity_guid;
1022	$annotation->name = $name;
1023	$annotation->value_type = $value_type;
1024	$annotation->value = $value;
1025	$annotation->owner_guid = $owner_guid;
1026	$annotation->access_id = $access_id;
1027
1028	return $annotation->save();
1029}
1030
1031/**
1032 * Update an annotation.
1033 *
1034 * @param int    $annotation_id Annotation ID
1035 * @param string $name          Name of annotation
1036 * @param string $value         Value of annotation
1037 * @param string $value_type    Type of value
1038 * @param int    $owner_guid    Owner of annotation
1039 * @param int    $access_id     Access level of annotation
1040 *
1041 * @return bool
1042 * @deprecated 3.0 Use \ElggAnnotation::save() or \ElggEntity::annotate()
1043 */
1044function update_annotation($annotation_id, $name, $value, $value_type, $owner_guid, $access_id) {
1045	elgg_deprecated_notice(
1046		__FUNCTION__ . ' has been deprecated.
1047		Use ElggAnnotation::save() or ElggEntity::annotate()
1048		', '3.0'
1049	);
1050
1051	$annotation = elgg_get_annotation_from_id($annotation_id);
1052	if (!$annotation) {
1053		return false;
1054	}
1055
1056	$annotation->name = $name;
1057	$annotation->value_type = $value_type;
1058	$annotation->value = $value;
1059	$annotation->owner_guid = $owner_guid;
1060	$annotation->access_id = $access_id;
1061
1062	return $annotation->save();
1063}
1064
1065/**
1066 * Delete objects with a delete() method.
1067 *
1068 * Used as a callback for \ElggBatch.
1069 *
1070 * @param object $object The object to disable
1071 * @return bool
1072 * @internal
1073 *
1074 * @deprecated 3.0
1075 */
1076function elgg_batch_delete_callback($object) {
1077	elgg_deprecated_notice(__FUNCTION__ . ' has been deprecated.', '3.0');
1078
1079	// our db functions return the number of rows affected...
1080	return $object->delete() ? true : false;
1081}
1082
1083/**
1084 * Sanitise file paths ensuring that they begin and end with slashes etc.
1085 *
1086 * @param string $path         The path
1087 * @param bool   $append_slash Add tailing slash
1088 *
1089 * @return string
1090 * @deprecated 3.0 Use \Elgg\Project\Paths::sanitize()
1091 */
1092function sanitise_filepath($path, $append_slash = true) {
1093	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \\Elgg\\Project\\Paths::sanitize().', 3.0);
1094
1095	return \Elgg\Project\Paths::sanitize($path, $append_slash);
1096}
1097
1098/**
1099 * Gets a private setting for an entity.
1100 *
1101 * Plugin authors can set private data on entities.  By default
1102 * private data will not be searched or exported.
1103 *
1104 * @note Internal: Private data is used to store settings for plugins
1105 * and user settings.
1106 *
1107 * @param int    $entity_guid The entity GUID
1108 * @param string $name        The name of the setting
1109 *
1110 * @return mixed The setting value, or null if does not exist
1111 * @see set_private_setting()
1112 * @see get_all_private_settings()
1113 * @see remove_private_setting()
1114 * @see remove_all_private_settings()
1115 * @deprecated 3.0 Use \ElggEntity::getPrivateSetting()
1116 */
1117function get_private_setting($entity_guid, $name) {
1118	elgg_deprecated_notice(
1119		__FUNCTION__ . ' has been deprecated.
1120		Use ElggEntity::getPrivateSetting()
1121	', '3.0');
1122
1123	$ia = elgg_set_ignore_access(true);
1124	$entity = get_entity($entity_guid);
1125	elgg_set_ignore_access($ia);
1126
1127	if (!$entity) {
1128		return null;
1129	}
1130
1131	return $entity->getPrivateSetting($name);
1132}
1133
1134/**
1135 * Return an array of all private settings.
1136 *
1137 * @param int $entity_guid The entity GUID
1138 *
1139 * @return string[] empty array if no settings
1140 * @see set_private_setting()
1141 * @see get_private_settings()
1142 * @see remove_private_setting()
1143 * @see remove_all_private_settings()
1144 * @deprecated 3.0 Use \ElggEntity::getAllPrivateSettings()
1145 */
1146function get_all_private_settings($entity_guid) {
1147	elgg_deprecated_notice(
1148		__FUNCTION__ . ' has been deprecated.
1149		Use ElggEntity::getAllPrivateSettings()
1150	', '3.0');
1151
1152	$ia = elgg_set_ignore_access(true);
1153	$entity = get_entity($entity_guid);
1154	elgg_set_ignore_access($ia);
1155
1156	if (!$entity) {
1157		return null;
1158	}
1159
1160	return $entity->getAllPrivateSettings();
1161}
1162
1163/**
1164 * Sets a private setting for an entity.
1165 *
1166 * @param int    $entity_guid The entity GUID
1167 * @param string $name        The name of the setting
1168 * @param string $value       The value of the setting
1169 *
1170 * @return bool
1171 * @see get_private_setting()
1172 * @see get_all_private_settings()
1173 * @see remove_private_setting()
1174 * @see remove_all_private_settings()
1175 * @deprecated 3.0 Use \ElggEntity::setPrivateSetting()
1176 */
1177function set_private_setting($entity_guid, $name, $value) {
1178	elgg_deprecated_notice(
1179		__FUNCTION__ . ' has been deprecated.
1180		Use ElggEntity::setPrivateSetting()
1181	', '3.0');
1182
1183	$ia = elgg_set_ignore_access(true);
1184	$entity = get_entity($entity_guid);
1185	elgg_set_ignore_access($ia);
1186
1187	if (!$entity) {
1188		return false;
1189	}
1190
1191	return $entity->setPrivateSetting($name, $value);
1192}
1193
1194/**
1195 * Deletes a private setting for an entity.
1196 *
1197 * @param int    $entity_guid The Entity GUID
1198 * @param string $name        The name of the setting
1199 *
1200 * @return bool
1201 * @see get_private_setting()
1202 * @see get_all_private_settings()
1203 * @see set_private_setting()
1204 * @see remove_all_private_settings()
1205 * @deprecated 3.0 Use \ElggEntity::removePrivateSetting()
1206 */
1207function remove_private_setting($entity_guid, $name) {
1208	elgg_deprecated_notice(
1209		__FUNCTION__ . ' has been deprecated.
1210		Use ElggEntity::removePrivateSetting()
1211	', '3.0');
1212
1213	$ia = elgg_set_ignore_access(true);
1214	$entity = get_entity($entity_guid);
1215	elgg_set_ignore_access($ia);
1216
1217	if (!$entity) {
1218		return null;
1219	}
1220
1221	return $entity->removePrivateSetting($name);
1222}
1223
1224/**
1225 * Deletes all private settings for an entity.
1226 *
1227 * @param int $entity_guid The Entity GUID
1228 *
1229 * @return bool
1230 * @see get_private_setting()
1231 * @see get_all_private_settings()
1232 * @see set_private_setting()
1233 * @see remove_private_settings()
1234 * @deprecated 3.0 \ElggEntity::removeAllPrivateSettings()
1235 */
1236function remove_all_private_settings($entity_guid) {
1237	elgg_deprecated_notice(
1238		__FUNCTION__ . ' has been deprecated.
1239		Use ElggEntity::removeAllPrivateSettings()
1240	', '3.0');
1241
1242	$ia = elgg_set_ignore_access(true);
1243	$entity = get_entity($entity_guid);
1244	elgg_set_ignore_access($ia);
1245
1246	if (!$entity) {
1247		return null;
1248	}
1249
1250	return $entity->removeAllPrivateSettings();
1251}
1252
1253/**
1254 * Enable objects with an enable() method.
1255 *
1256 * Used as a callback for \ElggBatch.
1257 *
1258 * @param object $object The object to enable
1259 * @return bool
1260 * @internal
1261 * @deprecated 3.0
1262 */
1263function elgg_batch_enable_callback($object) {
1264	elgg_deprecated_notice(
1265		__FUNCTION__ . ' has been deprecated.
1266		Perform batch operations on members of the batch.
1267	', '3.0');
1268	// our db functions return the number of rows affected...
1269	return $object->enable() ? true : false;
1270}
1271
1272/**
1273 * Disable objects with a disable() method.
1274 *
1275 * Used as a callback for \ElggBatch.
1276 *
1277 * @param object $object The object to disable
1278 * @return bool
1279 * @internal
1280 * @deprecated 3.0
1281 */
1282function elgg_batch_disable_callback($object) {
1283	elgg_deprecated_notice(
1284		__FUNCTION__ . ' has been deprecated.
1285		Perform batch operations on members of the batch.
1286	', '3.0');
1287	// our db functions return the number of rows affected...
1288	return $object->disable() ? true : false;
1289}
1290
1291/**
1292 * Registers a page handler for a particular identifier
1293 *
1294 * For example, you can register a function called 'blog_page_handler' for the identifier 'blog'
1295 * For all URLs  http://yoururl/blog/*, the blog_page_handler() function will be called.
1296 * The part of the URL marked with * above will be exploded on '/' characters and passed as an
1297 * array to that function.
1298 * For example, the URL http://yoururl/blog/username/friends/ would result in the call:
1299 * blog_page_handler(array('username','friends'), blog);
1300 *
1301 * A request to register a page handler with the same identifier as previously registered
1302 * handler will replace the previous one.
1303 *
1304 * The context is set to the identifier before the registered
1305 * page handler function is called. For the above example, the context is set to 'blog'.
1306 *
1307 * Page handlers should return true to indicate that they handled the request.
1308 * Requests not handled are forwarded to the front page with a reason of 404.
1309 * Plugins can register for the 'forward', '404' plugin hook. @see forward()
1310 *
1311 * @param string   $identifier The page type identifier
1312 * @param callable $function   Your function name
1313 *
1314 * @return bool Depending on success
1315 * @deprecated 3.0 Use elgg_register_route() to register a named route
1316 * @see elgg_register_route()
1317 */
1318function elgg_register_page_handler($identifier, callable $function) {
1319	elgg_deprecated_notice(
1320		__FUNCTION__ . ' has been deprecated.
1321		Use elgg_register_route() to register a named route or define it in elgg-plugin.php',
1322		'3.0'
1323	);
1324	return _elgg_services()->routes->registerPageHandler($identifier, $function);
1325}
1326
1327/**
1328 * Unregister a page handler for an identifier
1329 *
1330 * Note: to replace a page handler, call elgg_register_page_handler()
1331 *
1332 * @param string $identifier The page type identifier
1333 *
1334 * @since 1.7.2
1335 * @return void
1336 * @deprecated 3.0
1337 */
1338function elgg_unregister_page_handler($identifier) {
1339	elgg_deprecated_notice(
1340		__FUNCTION__ . ' has been deprecated.
1341		Use new routing API to register and unregister routes.',
1342		'3.0'
1343	);
1344	_elgg_services()->routes->unregisterPageHandler($identifier);
1345}
1346
1347/**
1348 * Alias of elgg_gatekeeper()
1349 *
1350 * Used at the top of a page to mark it as logged in users only.
1351 *
1352 * @return void
1353 * @throws \Elgg\GatekeeperException
1354 * @deprecated 3.0 Use elgg_gatekeeper()
1355 */
1356function gatekeeper() {
1357	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_gatekeeper()', '3.0');
1358	elgg_gatekeeper();
1359}
1360
1361/**
1362 * Alias of elgg_admin_gatekeeper()
1363 *
1364 * Used at the top of a page to mark it as logged in admin or siteadmin only.
1365 *
1366 * @return void
1367 * @throws \Elgg\GatekeeperException
1368 * @deprecated 3.0 Use elgg_admin_gatekeeper()
1369 */
1370function admin_gatekeeper() {
1371	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_admin_gatekeeper()', '3.0');
1372	elgg_admin_gatekeeper();
1373}
1374
1375/**
1376 * May the current user access item(s) on this page? If the page owner is a group,
1377 * membership, visibility, and logged in status are taken into account.
1378 *
1379 * @param bool $forward         If set to true (default), will forward the page;
1380 *                              if set to false, will return true or false.
1381 *
1382 * @param int  $page_owner_guid The current page owner guid. If not set, this
1383 *                              will be pulled from elgg_get_page_owner_guid().
1384 *
1385 * @return bool Will return if $forward is set to false.
1386 * @deprecated 3.0 Use elgg_group_gatekeeper()
1387 */
1388function group_gatekeeper($forward = true, $page_owner_guid = null) {
1389	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_group_gatekeeper()', '3.0');
1390	return elgg_group_gatekeeper($forward, $page_owner_guid);
1391}
1392
1393
1394/**
1395 * May the current user access item(s) on this page? If the page owner is a group,
1396 * membership, visibility, and logged in status are taken into account.
1397 *
1398 * @param bool $forward    If set to true (default), will forward the page;
1399 *                         if set to false, will return true or false.
1400 *
1401 * @param int  $group_guid The group that owns the page. If not set, this
1402 *                         will be pulled from elgg_get_page_owner_guid().
1403 *
1404 * @return bool Will return if $forward is set to false.
1405 * @throws InvalidParameterException
1406 * @throws SecurityException
1407 * @since 1.9.0
1408 * @deprecated 3.0 Use elgg_entity_gatekeeper()
1409 */
1410function elgg_group_gatekeeper($forward = true, $group_guid = null) {
1411	elgg_deprecated_notice(__FUNCTION__ . ' has been deprecated. Use elgg_entity_gatekeeper()', '3.0');
1412	if (null === $group_guid) {
1413		$group_guid = elgg_get_page_owner_guid();
1414	}
1415
1416	if (!$group_guid) {
1417		return true;
1418	}
1419
1420	try {
1421		return elgg_entity_gatekeeper($group_guid);
1422	} catch (Exception $ex) {
1423		if ($forward) {
1424			throw $ex;
1425		} else {
1426			return false;
1427		}
1428	}
1429}
1430
1431/**
1432 * Retrieve rows from the database.
1433 *
1434 * Queries are executed with {@link \Elgg\Database::getResults} and results
1435 * are retrieved with {@link \PDO::fetchObject()}.  If a callback
1436 * function $callback is defined, each row will be passed as the single
1437 * argument to $callback.  If no callback function is defined, the
1438 * entire result set is returned as an array.
1439 *
1440 * @param string   $query    The query being passed.
1441 * @param callable $callback Optionally, the name of a function to call back to on each row
1442 * @param array    $params   Query params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve']
1443 *
1444 * @return array An array of database result objects or callback function results. If the query
1445 *               returned nothing, an empty array.
1446 * @throws DatabaseException
1447 * @deprecated 3.0 Use elgg()->db->getData()
1448 */
1449function get_data($query, $callback = null, array $params = []) {
1450	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg()->db', '3.0');
1451	return elgg()->db->getData($query, $callback, $params);
1452}
1453
1454/**
1455 * Retrieve a single row from the database.
1456 *
1457 * Similar to {@link get_data()} but returns only the first row
1458 * matched.  If a callback function $callback is specified, the row will be passed
1459 * as the only argument to $callback.
1460 *
1461 * @param string   $query    The query to execute.
1462 * @param callable $callback A callback function to apply to the row
1463 * @param array    $params   Query params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve']
1464 *
1465 * @return mixed A single database result object or the result of the callback function.
1466 * @throws DatabaseException
1467 * @deprecated 3.0 Use elgg()->db->getDataRow()
1468 */
1469function get_data_row($query, $callback = null, array $params = []) {
1470	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg()->db', '3.0');
1471	return elgg()->db->getDataRow($query, $callback, $params);
1472}
1473
1474/**
1475 * Insert a row into the database.
1476 *
1477 * @note       Altering the DB invalidates all queries in the query cache
1478 *
1479 * @param string $query  The query to execute.
1480 * @param array  $params Query params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve']
1481 *
1482 * @return int|false The database id of the inserted row if a AUTO_INCREMENT field is
1483 *                   defined, 0 if not, and false on failure.
1484 * @throws DatabaseException
1485 * @deprecated 3.0 Use elgg()->db->insertData()
1486 */
1487function insert_data($query, array $params = []) {
1488	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg()->db', '3.0');
1489	return elgg()->db->insertData($query, $params);
1490}
1491
1492/**
1493 * Update a row in the database.
1494 *
1495 * @note       Altering the DB invalidates all queries in the query cache
1496 *
1497 * @param string $query        The query to run.
1498 * @param array  $params       Query params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve']
1499 * @param bool   $get_num_rows Return the number of rows affected (default: false).
1500 *
1501 * @return bool
1502 * @throws DatabaseException
1503 * @deprecated 3.0 Use elgg()->db->updateData()
1504 */
1505function update_data($query, array $params = [], $get_num_rows = false) {
1506	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg()->db', '3.0');
1507	return elgg()->db->updateData($query, $get_num_rows, $params);
1508}
1509
1510/**
1511 * Remove a row from the database.
1512 *
1513 * @note       Altering the DB invalidates all queries in the query cache
1514 *
1515 * @param string $query  The SQL query to run
1516 * @param array  $params Query params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve']
1517 *
1518 * @return int|false The number of affected rows or false on failure
1519 * @throws DatabaseException
1520 * @deprecated 3.0 Use elgg()->db->deleteData()
1521 */
1522function delete_data($query, array $params = []) {
1523	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg()->db', '3.0');
1524	return elgg()->db->deleteData($query, $params);
1525}
1526
1527/**
1528 * When given a full path, finds translation files and loads them
1529 *
1530 * @param string $path     Full path
1531 * @param bool   $load_all If true all languages are loaded, if
1532 *                         false only the current language + en are loaded
1533 * @param string $language Language code if other than current + en
1534 *
1535 * @return bool success
1536 * @deprecated 3.0
1537 */
1538function register_translations($path, $load_all = false, $language = null) {
1539	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated and should not be used', '3.0');
1540
1541	return elgg()->translator->registerTranslations($path, $load_all, $language);
1542}
1543
1544/**
1545 * Reload all translations from all registered paths.
1546 *
1547 * This is only called by functions which need to know all possible translations.
1548 *
1549 * @todo Better on demand loading based on language_paths array
1550 *
1551 * @return void
1552 * @deprecated 3.0
1553 */
1554function reload_all_translations() {
1555	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated and should not be used', '3.0');
1556
1557	return elgg()->translator->reloadAllTranslations();
1558}
1559
1560/**
1561 * Returns a viewable list of entities based on the registered types.
1562 *
1563 * @see elgg_view_entity_list()
1564 *
1565 * @param array $options Any elgg_get_entity() options plus:
1566 *
1567 * 	full_view => BOOL Display full view entities
1568 *
1569 * 	list_type_toggle => BOOL Display gallery / list switch
1570 *
1571 * 	allowed_types => true|ARRAY True to show all types or an array of valid types.
1572 *
1573 * 	pagination => BOOL Display pagination links
1574 *
1575 * @return string A viewable list of entities
1576 * @since 1.7.0
1577 *
1578 * @deprecated 3.0 Use elgg_list_entities()
1579 */
1580function elgg_list_registered_entities(array $options = []) {
1581	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_list_entities()', '3.0');
1582
1583	elgg_register_rss_link();
1584
1585	$defaults = [
1586		'full_view' => false,
1587		'allowed_types' => true,
1588		'list_type_toggle' => false,
1589		'pagination' => true,
1590		'offset' => 0,
1591		'types' => [],
1592		'type_subtype_pairs' => [],
1593	];
1594
1595	$options = array_merge($defaults, $options);
1596
1597	$types = get_registered_entity_types();
1598
1599	foreach ($types as $type => $subtype_array) {
1600		if (in_array($type, $options['allowed_types']) || $options['allowed_types'] === true) {
1601			// you must explicitly register types to show up in here and in search for objects
1602			if ($type == 'object') {
1603				if (is_array($subtype_array) && count($subtype_array)) {
1604					$options['type_subtype_pairs'][$type] = $subtype_array;
1605				}
1606			} else {
1607				if (is_array($subtype_array) && count($subtype_array)) {
1608					$options['type_subtype_pairs'][$type] = $subtype_array;
1609				} else {
1610					$options['type_subtype_pairs'][$type] = ELGG_ENTITIES_ANY_VALUE;
1611				}
1612			}
1613		}
1614	}
1615
1616	if (!empty($options['type_subtype_pairs'])) {
1617		$count = elgg_get_entities(array_merge(['count' => true], $options));
1618		if ($count > 0) {
1619			$entities = elgg_get_entities($options);
1620		} else {
1621			$entities = [];
1622		}
1623	} else {
1624		$count = 0;
1625		$entities = [];
1626	}
1627
1628	$options['count'] = $count;
1629	return elgg_view_entity_list($entities, $options);
1630}
1631
1632/**
1633 * Returns the version of the upgrade filename.
1634 *
1635 * @param string $filename The upgrade filename. No full path.
1636 * @return int|false
1637 * @since 1.8.0
1638 * @deprecated 3.0 Use asynchronous upgrades
1639 */
1640function elgg_get_upgrade_file_version($filename) {
1641	elgg_deprecated_notice(__FUNCTION__ . ' has been deprecated. Use asynchronous upgrades instead', '3.0');
1642
1643	preg_match('/^([0-9]{10})([\.a-z0-9-_]+)?\.(php)$/i', $filename, $matches);
1644
1645	if (isset($matches[1])) {
1646		return (int) $matches[1];
1647	}
1648
1649	return false;
1650}
1651
1652/**
1653 * Returns a list of upgrade files relative to the $upgrade_path dir.
1654 *
1655 * @param string $upgrade_path The directory that has upgrade scripts
1656 * @return array|false
1657 * @internal
1658 * @deprecated 3.0 Use asynchronous upgrades
1659 */
1660function elgg_get_upgrade_files($upgrade_path = null) {
1661	elgg_deprecated_notice(__FUNCTION__ . ' has been deprecated. Use asynchronous upgrades instead', '3.0');
1662
1663	if (!$upgrade_path) {
1664		$upgrade_path = elgg_get_engine_path() . '/lib/upgrades/';
1665	}
1666	$upgrade_path = \Elgg\Project\Paths::sanitize($upgrade_path);
1667
1668	if (!is_dir($upgrade_path)) {
1669		return false;
1670	}
1671	$handle = opendir($upgrade_path);
1672	if (!$handle) {
1673		return false;
1674	}
1675
1676	$upgrade_files = [];
1677
1678	while (($upgrade_file = readdir($handle)) !== false) {
1679		// make sure this is a well formed upgrade.
1680		if (!is_file($upgrade_path . $upgrade_file)) {
1681			continue;
1682		}
1683		$upgrade_version = elgg_get_upgrade_file_version($upgrade_file);
1684		if (!$upgrade_version) {
1685			continue;
1686		}
1687		$upgrade_files[] = $upgrade_file;
1688	}
1689
1690	sort($upgrade_files);
1691
1692	return $upgrade_files;
1693}
1694
1695/**
1696 * Returns a list of months in which entities were updated or created.
1697 *
1698 * @tip Use this to generate a list of archives by month for when entities were added or updated.
1699 *
1700 * @warning Months are returned in the form YYYYMM.
1701 *
1702 * @param string $type           The type of entity
1703 * @param string $subtype        The subtype of entity
1704 * @param int    $container_guid The container GUID that the entities belong to
1705 * @param int    $ignored        Ignored parameter
1706 * @param string $order_by       Order_by SQL order by clause
1707 *
1708 * @deprecated 3.0 use elgg_get_entity_dates()
1709 *
1710 * @return array|false Either an array months as YYYYMM, or false on failure
1711 */
1712function get_entity_dates($type = '', $subtype = '', $container_guid = 0, $ignored = 0, $order_by = 'e.time_created') {
1713	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated, please use elgg_get_entity_dates()', '3.0');
1714
1715	$options = [
1716		'types' => $type,
1717		'subtypes' => $subtype,
1718		'container_guids' => $container_guid,
1719		'order_by' => [
1720			new OrderByClause($order_by),
1721		],
1722	];
1723
1724	return elgg_get_entity_dates($options);
1725}
1726
1727/**
1728 * Adds a group tool option
1729 *
1730 * @see        remove_group_tool_option()
1731 *
1732 * @param string $name    Tool ID
1733 * @param array  $options Tool config options
1734 *
1735 * @option string   $label      Label to appear on the group edit form
1736 * @option bool     $default_on Is the tool enabled by default?
1737 * @option int      $priority   Module priority
1738 * @return void
1739 *
1740 * @since 1.5.0
1741 * @deprecated 3.0 Use elgg()->group_tools
1742 */
1743function add_group_tool_option($name, $options = []) {
1744	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg()->group_tools service', '3.0');
1745
1746	if (!is_array($options)) {
1747		$arguments = func_get_args();
1748		$options = [
1749			'label' => elgg_extract(1, $arguments),
1750			'default_on' => elgg_extract(2, $arguments),
1751			'priority' => null,
1752		];
1753	}
1754
1755	elgg()->group_tools->register($name, $options);
1756}
1757
1758/**
1759 * Removes a group tool option based on name
1760 *
1761 * @see add_group_tool_option()
1762 *
1763 * @param string $name Name of the group tool option
1764 *
1765 * @return void
1766 * @since 1.7.5
1767 * @deprecated 3.0 Use elgg()->group_tools
1768 */
1769function remove_group_tool_option($name) {
1770	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg()->group_tools service', '3.0');
1771
1772	elgg()->group_tools->unregister($name);
1773}
1774
1775/**
1776 * Function to return available group tool options
1777 *
1778 * @param \ElggGroup $group optional group
1779 *
1780 * @return Collection|Tool[]
1781 * @deprecated 3.0
1782 */
1783function elgg_get_group_tool_options(\ElggGroup $group = null) {
1784	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg()->group_tools service', '3.0');
1785
1786	if ($group) {
1787		return elgg()->group_tools->group($group);
1788	}
1789
1790	return elgg()->group_tools->all();
1791}
1792