1<?php
2
3/**
4 * Delete a directory and all its contents
5 *
6 * @param string $directory Directory to delete
7 *
8 * @return bool
9 *
10 * @deprecated 3.1 Use elgg_delete_directory()
11 */
12function delete_directory($directory) {
13
14	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_delete_directory().', '3.1');
15
16	if (!is_string($directory)) {
17		return false;
18	}
19
20	return elgg_delete_directory($directory);
21}
22
23/**
24 * Register a JavaScript file for inclusion
25 *
26 * This function handles adding JavaScript to a web page. If multiple
27 * calls are made to register the same JavaScript file based on the $id
28 * variable, only the last file is included. This allows a plugin to add
29 * JavaScript from a view that may be called more than once. It also handles
30 * more than one plugin adding the same JavaScript.
31 *
32 * jQuery plugins often have filenames such as jquery.rating.js. A best practice
33 * is to base $name on the filename: "jquery.rating". It is recommended to not
34 * use version numbers in the name.
35 *
36 * The JavaScript files can be local to the server or remote (such as
37 * Google's CDN).
38 *
39 * @note Since 2.0, scripts with location "head" will also be output in the footer, but before
40 *       those with location "footer".
41 *
42 * @param string $name     An identifier for the JavaScript library
43 * @param string $url      URL of the JavaScript file
44 * @param string $location Page location: head or footer. (default: head)
45 * @param int    $priority Priority of the JS file (lower numbers load earlier)
46 *
47 * @return bool
48 * @since 1.8.0
49 *
50 * @deprecated 3.1 Use AMD modules and elgg_require_js()
51 */
52function elgg_register_js($name, $url, $location = 'head', $priority = null) {
53	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use AMD modules and elgg_require_js().', '3.1');
54
55	return elgg_register_external_file('js', $name, $url, $location, $priority);
56}
57
58/**
59 * Load a JavaScript resource on this page
60 *
61 * This must be called before elgg_view_page(). It can be called before the
62 * script is registered. If you do not want a script loaded, unregister it.
63 *
64 * @param string $name Identifier of the JavaScript resource
65 *
66 * @return void
67 * @since 1.8.0
68 *
69 * @deprecated 3.1 Use AMD modules and elgg_require_js()
70 */
71function elgg_load_js($name) {
72	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use AMD modules and elgg_require_js().', '3.1');
73
74	elgg_load_external_file('js', $name);
75}
76
77/**
78 * Unregister a JavaScript file
79 *
80 * @param string $name The identifier for the JavaScript library
81 *
82 * @return bool
83 * @since 1.8.0
84 *
85 * @deprecated 3.1
86 */
87function elgg_unregister_js($name) {
88	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated.', '3.1');
89
90	return elgg_unregister_external_file('js', $name);
91}
92
93/**
94 * Register a CSS file for inclusion in the HTML head
95 *
96 * @param string $name     An identifier for the CSS file
97 * @param string $url      URL of the CSS file
98 * @param int    $priority Priority of the CSS file (lower numbers load earlier)
99 *
100 * @return bool
101 * @since 1.8.0
102 *
103 * @deprecated 3.1 Use elgg_require_css()
104 */
105function elgg_register_css($name, $url, $priority = null) {
106	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_require_css().', '3.1');
107
108	return elgg_register_external_file('css', $name, $url, 'head', $priority);
109}
110
111/**
112 * Unregister a CSS file
113 *
114 * @param string $name The identifier for the CSS file
115 *
116 * @return bool
117 * @since 1.8.0
118 *
119 * @deprecated 3.1
120 */
121function elgg_unregister_css($name) {
122	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated.', '3.1');
123
124	return elgg_unregister_external_file('css', $name);
125}
126
127/**
128 * Load a CSS file for this page
129 *
130 * This must be called before elgg_view_page(). It can be called before the
131 * CSS file is registered. If you do not want a CSS file loaded, unregister it.
132 *
133 * @param string $name Identifier of the CSS file
134 *
135 * @return void
136 * @since 1.8.0
137 *
138 * @deprecated 3.1 Use elgg_require_css()
139 */
140function elgg_load_css($name) {
141	elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_require_css().', '3.1');
142
143	elgg_load_external_file('css', $name);
144}
145
146/**
147 * Checks if $entity is an \ElggEntity and optionally for type and subtype.
148 *
149 * @tip Use this function in actions and views to check that you are dealing
150 * with the correct type of entity.
151 *
152 * @param mixed  $entity  Entity
153 * @param string $type    Entity type
154 * @param string $subtype Entity subtype
155 *
156 * @return bool
157 * @since 1.8.0
158 *
159 * @deprecated 3.1 Use PHP instanceof type operator
160 */
161function elgg_instanceof($entity, $type = null, $subtype = null) {
162	elgg_deprecated_notice(__METHOD__ . ' is deprecated. Use PHP instanceof type operator.', '3.1');
163
164	$return = ($entity instanceof \ElggEntity);
165
166	if ($type) {
167		/* @var \ElggEntity $entity */
168		$return = $return && ($entity->getType() == $type);
169	}
170
171	if ($subtype) {
172		$return = $return && ($entity->getSubtype() == $subtype);
173	}
174
175	return $return;
176}
177
178/**
179 * Check if the given user has full access.
180 *
181 * @todo: Will always return full access if the user is an admin.
182 *
183 * @param int $user_guid The user to check
184 *
185 * @return bool
186 * @since 1.7.1
187 *
188 * @deprecated 3.1 Use ElggUser::isAdmin()
189 */
190function elgg_is_admin_user($user_guid) {
191	elgg_deprecated_notice(__METHOD__ . ' is deprecated. Use ElggUser::isAdmin().', '3.1');
192
193	$user_guid = (int) $user_guid;
194
195	$entity = get_user($user_guid);
196	if (!$entity) {
197		return false;
198	}
199
200	return $entity->isAdmin();
201}
202
203/**
204 * Return a string of access_ids for $user_guid appropriate for inserting into an SQL IN clause.
205 *
206 * @uses get_access_array
207 *
208 * @see get_access_array()
209 *
210 * @param int  $user_guid User ID; defaults to currently logged in user
211 * @param int  $ignored   Ignored parameter
212 * @param bool $flush     If set to true, will refresh the access list from the
213 *                        database rather than using this function's cache.
214 *
215 * @return string A list of access collections suitable for using in an SQL call
216 * @internal
217 *
218 * @deprecated 3.1 Use get_access_array()
219 */
220function get_access_list($user_guid = 0, $ignored = 0, $flush = false) {
221	elgg_deprecated_notice(__METHOD__ . ' is deprecated. Use get_access_array().', '3.1');
222
223	return _elgg_services()->accessCollections->getAccessList($user_guid, $flush);
224}
225
226/**
227 * Updates the membership in an access collection.
228 *
229 * @warning Expects a full list of all members that should
230 * be part of the access collection
231 *
232 * @note This will run all hooks associated with adding or removing
233 * members to access collections.
234 *
235 * @param int   $collection_id The ID of the collection.
236 * @param array $members       Array of member GUIDs
237 *
238 * @return bool
239 * @see add_user_to_access_collection()
240 * @see remove_user_from_access_collection()
241 *
242 * @deprecated 3.1
243 */
244function update_access_collection($collection_id, $members) {
245	elgg_deprecated_notice(__METHOD__ . ' is deprecated.', '3.1');
246
247	return _elgg_services()->accessCollections->update($collection_id, $members);
248}
249
250/**
251 * Returns a list of files in $directory.
252 *
253 * Only returns files.  Does not recurse into subdirs.
254 *
255 * @param string $directory  Directory to look in
256 * @param array  $exceptions Array of filenames to ignore
257 * @param array  $list       Array of files to append to
258 * @param mixed  $extensions Array of extensions to allow, null for all. Use a dot: array('.php').
259 *
260 * @return array Filenames in $directory, in the form $directory/filename.
261 *
262 * @deprecated 3.1 Use a PHP directory iterator
263 */
264function elgg_get_file_list($directory, $exceptions = [], $list = [], $extensions = null) {
265	elgg_deprecated_notice(__METHOD__ . ' is deprecated. Use a PHP directory iterator.', '3.1');
266
267	$directory = \Elgg\Project\Paths::sanitize($directory);
268	if ($handle = opendir($directory)) {
269		while (($file = readdir($handle)) !== false) {
270			if (!is_file($directory . $file) || in_array($file, $exceptions)) {
271				continue;
272			}
273
274			if (is_array($extensions)) {
275				if (in_array(strrchr($file, '.'), $extensions)) {
276					$list[] = $directory . $file;
277				}
278			} else {
279				$list[] = $directory . $file;
280			}
281		}
282		closedir($handle);
283	}
284
285	return $list;
286}
287
288/**
289 * Counts the number of messages, either globally or in a particular register
290 *
291 * @param string $register Optionally, the register
292 *
293 * @return integer The number of messages
294 *
295 * @deprecated 3.1 Use elgg()->system_messages->count()
296 */
297function count_messages($register = "") {
298	elgg_deprecated_notice(__METHOD__ . ' is deprecated. Use elgg()->system_messages->count().', '3.1');
299
300	return elgg()->system_messages->count($register);
301}
302
303/**
304 * Sorts a 3d array by specific element.
305 *
306 * @warning Will re-index numeric indexes.
307 *
308 * @note This operates the same as the built-in sort functions.
309 * It sorts the array and returns a bool for success.
310 *
311 * Do this: elgg_sort_3d_array_by_value($my_array);
312 * Not this: $my_array = elgg_sort_3d_array_by_value($my_array);
313 *
314 * @param array  $array      Array to sort
315 * @param string $element    Element to sort by
316 * @param int    $sort_order PHP sort order {@link http://us2.php.net/array_multisort}
317 * @param int    $sort_type  PHP sort type {@link http://us2.php.net/sort}
318 *
319 * @return bool
320 *
321 * @deprecated 3.1
322 */
323function elgg_sort_3d_array_by_value(&$array, $element, $sort_order = SORT_ASC, $sort_type = SORT_LOCALE_STRING) {
324	elgg_deprecated_notice(__METHOD__ . ' is deprecated.', '3.1');
325
326	$sort = [];
327
328	foreach ($array as $v) {
329		if (isset($v[$element])) {
330			$sort[] = strtolower($v[$element]);
331		} else {
332			$sort[] = null;
333		}
334	};
335
336	return array_multisort($sort, $sort_order, $sort_type, $array);
337}
338
339/**
340 * Return the state of a php.ini setting as a bool
341 *
342 * @warning Using this on ini settings that are not boolean
343 * will be inaccurate!
344 *
345 * @param string $ini_get_arg The INI setting
346 *
347 * @return bool Depending on whether it's on or off
348 *
349 * @deprecated 3.1
350 */
351function ini_get_bool($ini_get_arg) {
352	elgg_deprecated_notice(__METHOD__ . ' is deprecated.', '3.1');
353
354	$temp = strtolower(ini_get($ini_get_arg));
355
356	if ($temp == '1' || $temp == 'on' || $temp == 'true') {
357		return true;
358	}
359	return false;
360}
361
362/**
363 * Returns true is string is not empty, false, or null.
364 *
365 * Function to be used in array_filter which returns true if $string is not null.
366 *
367 * @param string $string The string to test
368 *
369 * @return bool
370 *
371 * @deprecated 3.1
372 */
373function is_not_null($string) {
374	elgg_deprecated_notice(__METHOD__ . ' is deprecated.', '3.1');
375
376	if (($string === '') || ($string === false) || ($string === null)) {
377		return false;
378	}
379
380	return true;
381}
382
383/**
384 * Enable an entity.
385 *
386 * @param int  $guid      GUID of entity to enable
387 * @param bool $recursive Recursively enable all entities disabled with the entity?
388 *
389 * @return bool
390 * @since 1.9.0
391 *
392 * @deprecated 3.1 Use ElggEntity::enable()
393 */
394function elgg_enable_entity($guid, $recursive = true) {
395	elgg_deprecated_notice(__METHOD__ . ' is deprecated. Use ElggEntity::enable().', '3.1');
396
397	return _elgg_services()->entityTable->enable($guid, $recursive);
398}
399
400/**
401 * Detect the current system/user language or false.
402 *
403 * @return string The language code (eg "en") or false if not set
404 *
405 * @deprecated 3.1 Use get_current_language()
406 */
407function get_language() {
408	elgg_deprecated_notice(__METHOD__ . ' is deprecated. Use get_current_language().', '3.1');
409
410	return elgg()->translator->getCurrentLanguage();
411}
412
413/**
414 * Return the number of users registered in the system.
415 *
416 * @param bool $show_deactivated Count not enabled users?
417 *
418 * @return int
419 *
420 * @deprecated 3.1 Use elgg_count_entities()
421 */
422function get_number_users($show_deactivated = false) {
423	elgg_deprecated_notice(__METHOD__ . ' is deprecated. Use elgg_count_entities().', '3.1');
424
425	$where = new \Elgg\Database\Clauses\EntityWhereClause();
426	$where->type_subtype_pairs = [
427		'user' => null,
428	];
429
430	if ($show_deactivated) {
431		$where->use_enabled_clause = false;
432	}
433
434	$select = \Elgg\Database\Select::fromTable('entities', 'e');
435	$select->select('COUNT(DISTINCT e.guid) AS count');
436	$select->addClause($where, 'e');
437
438	$result = _elgg_services()->db->getDataRow($select);
439	if (!empty($result)) {
440		return (int) $result->count;
441	}
442
443	return 0;
444}
445
446/**
447 * Disables all of a user's entities
448 *
449 * @param int $owner_guid The owner GUID
450 *
451 * @return bool Depending on success
452 *
453 * @deprecated 3.1
454 */
455function disable_user_entities($owner_guid) {
456	elgg_deprecated_notice(__METHOD__ . ' is deprecated.', '3.1');
457
458	try {
459		$entity = get_entity($owner_guid);
460		if (!$entity) {
461			return false;
462		}
463		return _elgg_services()->entityTable->disableEntities($entity);
464	} catch (DatabaseException $ex) {
465		elgg_log($ex, 'ERROR');
466
467		return false;
468	}
469}
470
471/**
472 * Auto-registers views from a location.
473 *
474 * @note Views in plugin/views/ are automatically registered for active plugins.
475 * Plugin authors would only need to call this if optionally including
476 * an entire views structure.
477 *
478 * @param string $view_base Optional The base of the view name without the view type.
479 * @param string $folder    Required The folder to begin looking in
480 * @param string $ignored   This argument is ignored
481 * @param string $viewtype  The type of view we're looking at (default, rss, etc)
482 *
483 * @return bool returns false if folder can't be read
484 * @since 1.7.0
485 * @see elgg_set_view_location()
486 * @internal
487 *
488 * @deprecated 3.1
489 */
490function autoregister_views($view_base, $folder, $ignored, $viewtype) {
491	elgg_deprecated_notice(__METHOD__ . ' is deprecated.', '3.1');
492
493	return _elgg_services()->views->autoregisterViews($view_base, $folder, $viewtype);
494}
495
496/**
497 * Show or hide disabled entities.
498 *
499 * @param bool $show_hidden Show disabled entities.
500 * @return bool
501 *
502 * @deprecated 3.1 Use elgg_call() with ELGG_SHOW_DISABLED_ENTITIES flag
503 */
504function access_show_hidden_entities($show_hidden) {
505	elgg_deprecated_notice(__METHOD__ . ' is deprecated. Use elgg_call() with ELGG_SHOW_DISABLED_ENTITIES flag.', '3.1');
506
507	elgg()->session->setDisabledEntityVisibility($show_hidden);
508}
509
510/**
511 * Set if Elgg's access system should be ignored.
512 *
513 * The access system will not return entities in any getter functions if the
514 * user doesn't have access. This removes this restriction.
515 *
516 * When the access system is being ignored, all checks for create, retrieve,
517 * update, and delete should pass. This affects all the canEdit() and related
518 * methods.
519 *
520 * @tip Use this to access entities in automated scripts
521 * when no user is logged in.
522 *
523 * @note Internal: The access override is checked in elgg_override_permissions(). It is
524 * registered for the 'permissions_check' hooks to override the access system for
525 * the canEdit() and canWriteToContainer() methods.
526 *
527 * @note Internal: This clears the access cache.
528 *
529 * @note Internal: For performance reasons this is done at the database access clause level.
530 *
531 * @param bool $ignore If true, disables all access checks.
532 *
533 * @return bool Previous ignore_access setting.
534 * @since 1.7.0
535 * @see elgg_get_ignore_access()
536 *
537 * @deprecated 3.1 Use elgg_call() with ELGG_IGNORE_ACCESS flag
538 */
539function elgg_set_ignore_access($ignore = true) {
540	elgg_deprecated_notice(__METHOD__ . ' is deprecated. Use elgg_call() with ELGG_IGNORE_ACCESS flag.', '3.1');
541
542	return elgg()->session->setIgnoreAccess($ignore);
543}
544