aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/elgglib.php
diff options
context:
space:
mode:
Diffstat (limited to 'engine/lib/elgglib.php')
-rw-r--r--engine/lib/elgglib.php320
1 files changed, 314 insertions, 6 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index e6c71813d..e8d47eaca 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -214,7 +214,7 @@ function elgg_register_external_file($type, $url, $id, $location) {
}
if (!isset($CONFIG->externals[$type])) {
- $CONFIG->externals[$type] = array();
+ $CONFIG->externals[$type] = array();
}
if (!isset($CONFIG->externals[$type][$location])) {
@@ -387,6 +387,22 @@ function elgg_count_comments($entity) {
}
/**
+ * Returns all php files in a directory.
+ *
+ * @deprecated 1.7 Use elgg_get_file_list() instead
+ *
+ * @param string $directory Directory to look in
+ * @param array $exceptions Array of extensions (with .!) to ignore
+ * @param array $list A list files to include in the return
+ *
+ * @return array
+ */
+function get_library_files($directory, $exceptions = array(), $list = array()) {
+ elgg_deprecated_notice('get_library_files() deprecated by elgg_get_file_list()', 1.7);
+ return elgg_get_file_list($directory, $exceptions, $list, array('.php'));
+}
+
+/**
* Returns a list of files in $directory.
*
* Only returns files. Does not recurse into subdirs.
@@ -476,7 +492,7 @@ $children_array = array()) {
}
if (!isset($CONFIG->registers[$register_name])) {
- $CONFIG->registers[$register_name] = array();
+ $CONFIG->registers[$register_name] = array();
}
$subregister = new stdClass;
@@ -552,6 +568,25 @@ function make_register_object($register_name, $register_value, $children_array =
}
/**
+ * If it exists, returns a particular register as an array
+ *
+ * @param string $register_name The name of the register
+ *
+ * @return array|false Depending on success
+ * @deprecated 1.8
+ */
+function get_register($register_name) {
+ elgg_deprecated_notice("get_register() has been deprecated", 1.8);
+ global $CONFIG;
+
+ if (isset($CONFIG->registers[$register_name])) {
+ return $CONFIG->registers[$register_name];
+ }
+
+ return false;
+}
+
+/**
* Queues a message to be displayed.
*
* Messages will not be displayed immediately, but are stored in
@@ -657,6 +692,33 @@ function register_error($error) {
}
/**
+ * Deprecated events core function. Code divided between elgg_register_event_handler()
+ * and trigger_elgg_event().
+ *
+ * @param string $event The type of event (eg 'init', 'update', 'delete')
+ * @param string $object_type The type of object (eg 'system', 'blog', 'user')
+ * @param string $function The name of the function that will handle the event
+ * @param int $priority Priority to call handler. Lower numbers called first (default 500)
+ * @param boolean $call Set to true to call the event rather than add to it (default false)
+ * @param mixed $object Optionally, the object the event is being performed on (eg a user)
+ *
+ * @return true|false Depending on success
+ * @deprecated 1.8 Use explicit register/trigger event functions
+ */
+function events($event = "", $object_type = "", $function = "", $priority = 500,
+$call = false, $object = null) {
+
+ elgg_deprecated_notice('events() has been deprecated.', 1.8);
+
+ // leaving this here just in case someone was directly calling this internal function
+ if (!$call) {
+ return elgg_register_event_handler($event, $object_type, $function, $priority);
+ } else {
+ return trigger_elgg_event($event, $object_type, $object);
+ }
+}
+
+/**
* Register a callback as an Elgg event handler.
*
* Events are emitted by Elgg when certain actions occur. Plugins
@@ -747,6 +809,14 @@ function elgg_register_event_handler($event, $object_type, $callback, $priority
}
/**
+ * @deprecated 1.8 Use elgg_register_event_handler() instead
+ */
+function register_elgg_event_handler($event, $object_type, $callback, $priority = 500) {
+ elgg_deprecated_notice("register_elgg_event_handler() was deprecated by elgg_register_event_handler()", 1.8);
+ return elgg_register_event_handler($event, $object_type, $callback, $priority);
+}
+
+/**
* Unregisters a callback for an event.
*
* @param string $event The event type
@@ -766,6 +836,14 @@ function elgg_unregister_event_handler($event, $object_type, $callback) {
}
/**
+ * @deprecated 1.8 Use elgg_unregister_event_handler instead
+ */
+function unregister_elgg_event_handler($event, $object_type, $callback) {
+ elgg_deprecated_notice('unregister_elgg_event_handler => elgg_unregister_event_handler', 1.8);
+ elgg_unregister_event_handler($event, $object_type, $callback);
+}
+
+/**
* Trigger an Elgg Event and run all handler callbacks registered to that event, type.
*
* This function runs all handlers registered to $event, $object_type or
@@ -829,6 +907,14 @@ function elgg_trigger_event($event, $object_type, $object = null) {
}
/**
+ * @deprecated 1.8 Use elgg_trigger_event() instead
+ */
+function trigger_elgg_event($event, $object_type, $object = null) {
+ elgg_deprecated_notice('trigger_elgg_event() was deprecated by elgg_trigger_event()', 1.8);
+ return elgg_trigger_event($event, $object_type, $object);
+}
+
+/**
* Register a callback as a plugin hook handler.
*
* Plugin hooks allow developers to losely couple plugins and features by
@@ -926,6 +1012,14 @@ function elgg_register_plugin_hook_handler($hook, $type, $callback, $priority =
}
/**
+ * @deprecated 1.8 Use elgg_register_plugin_hook_handler() instead
+ */
+function register_plugin_hook($hook, $type, $callback, $priority = 500) {
+ elgg_deprecated_notice("register_plugin_hook() was deprecated by elgg_register_plugin_hook_handler()", 1.8);
+ return elgg_register_plugin_hook_handler($hook, $type, $callback, $priority);
+}
+
+/**
* Unregister a callback as a plugin hook.
*
* @param string $hook The name of the hook
@@ -945,6 +1039,14 @@ function elgg_unregister_plugin_hook_handler($hook, $entity_type, $callback) {
}
/**
+ * @deprecated 1.8 Use elgg_unregister_plugin_hook_handler() instead
+ */
+function unregister_plugin_hook($hook, $entity_type, $callback) {
+ elgg_deprecated_notice("unregister_plugin_hook() was deprecated by elgg_unregister_plugin_hook_handler()", 1.8);
+ elgg_unregister_plugin_hook_handler($hook, $entity_type, $callback);
+}
+
+/**
* Trigger a Plugin Hook and run all handler callbacks registered to that hook:type.
*
* This function runs all handlers regsitered to $hook, $type or
@@ -1019,6 +1121,14 @@ function elgg_trigger_plugin_hook($hook, $type, $params = null, $returnvalue = n
}
/**
+ * @deprecated 1.8 Use elgg_trigger_plugin_hook() instead
+ */
+function trigger_plugin_hook($hook, $type, $params = null, $returnvalue = null) {
+ elgg_deprecated_notice("trigger_plugin_hook() was deprecated by elgg_trigger_plugin_hook()", 1.8);
+ return elgg_trigger_plugin_hook($hook, $type, $params, $returnvalue);
+}
+
+/**
* Intercepts, logs, and display uncaught exceptions.
*
* @warning This function should never be called directly.
@@ -1079,8 +1189,8 @@ function _elgg_php_error_handler($errno, $errmsg, $filename, $linenum, $vars) {
throw new Exception($error);
break;
- case E_WARNING:
- case E_USER_WARNING:
+ case E_WARNING :
+ case E_USER_WARNING :
error_log("PHP WARNING: $error");
break;
@@ -1259,6 +1369,163 @@ function elgg_deprecated_notice($msg, $dep_version) {
return TRUE;
}
+
+/**
+ * Checks if code is being called from a certain function.
+ *
+ * To use, call this function with the function name (and optional
+ * file location) that it has to be called from, it will either
+ * return true or false.
+ *
+ * e.g.
+ *
+ * function my_secure_function()
+ * {
+ * if (!call_gatekeeper("my_call_function"))
+ * return false;
+ *
+ * ... do secure stuff ...
+ * }
+ *
+ * function my_call_function()
+ * {
+ * // will work
+ * my_secure_function();
+ * }
+ *
+ * function bad_function()
+ * {
+ * // Will not work
+ * my_secure_function();
+ * }
+ *
+ * @param mixed $function The function that this function must have in its call stack,
+ * to test against a method pass an array containing a class and
+ * method name.
+ * @param string $file Optional file that the function must reside in.
+ *
+ * @return bool
+ *
+ * @deprecated 1.8 A neat but pointless function
+ */
+function call_gatekeeper($function, $file = "") {
+ elgg_deprecated_notice("call_gatekeeper() is neat but pointless", 1.8);
+ // Sanity check
+ if (!$function) {
+ return false;
+ }
+
+ // Check against call stack to see if this is being called from the correct location
+ $callstack = debug_backtrace();
+ $stack_element = false;
+
+ foreach ($callstack as $call) {
+ if (is_array($function)) {
+ if (
+ (strcmp($call['class'], $function[0]) == 0) &&
+ (strcmp($call['function'], $function[1]) == 0)
+ ) {
+ $stack_element = $call;
+ }
+ } else {
+ if (strcmp($call['function'], $function) == 0) {
+ $stack_element = $call;
+ }
+ }
+ }
+
+ if (!$stack_element) {
+ return false;
+ }
+
+ // If file then check that this it is being called from this function
+ if ($file) {
+ $mirror = null;
+
+ if (is_array($function)) {
+ $mirror = new ReflectionMethod($function[0], $function[1]);
+ } else {
+ $mirror = new ReflectionFunction($function);
+ }
+
+ if ((!$mirror) || (strcmp($file, $mirror->getFileName()) != 0)) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+/**
+ * This function checks to see if it is being called at somepoint by a function defined somewhere
+ * on a given path (optionally including subdirectories).
+ *
+ * This function is similar to call_gatekeeper() but returns true if it is being called
+ * by a method or function which has been defined on a given path or by a specified file.
+ *
+ * @param string $path The full path and filename that this function must have
+ * in its call stack If a partial path is given and
+ * $include_subdirs is true, then the function will return
+ * true if called by any function in or below the specified path.
+ * @param bool $include_subdirs Are subdirectories of the path ok, or must you specify an
+ * absolute path and filename.
+ * @param bool $strict_mode If true then the calling method or function must be directly
+ * called by something on $path, if false the whole call stack is
+ * searched.
+ *
+ * @return void
+ *
+ * @deprecated 1.8 A neat but pointless function
+ */
+function callpath_gatekeeper($path, $include_subdirs = true, $strict_mode = false) {
+ elgg_deprecated_notice("callpath_gatekeeper() is neat but pointless", 1.8);
+
+ global $CONFIG;
+
+ $path = sanitise_string($path);
+
+ if ($path) {
+ $callstack = debug_backtrace();
+
+ foreach ($callstack as $call) {
+ $call['file'] = str_replace("\\", "/", $call['file']);
+
+ if ($include_subdirs) {
+ if (strpos($call['file'], $path) === 0) {
+
+ if ($strict_mode) {
+ $callstack[1]['file'] = str_replace("\\", "/", $callstack[1]['file']);
+ if ($callstack[1] === $call) {
+ return true;
+ }
+ } else {
+ return true;
+ }
+ }
+ } else {
+ if (strcmp($path, $call['file']) == 0) {
+ if ($strict_mode) {
+ if ($callstack[1] === $call) {
+ return true;
+ }
+ } else {
+ return true;
+ }
+ }
+ }
+
+ }
+ return false;
+ }
+
+ if (isset($CONFIG->debug)) {
+ system_message("Gatekeeper'd function called from {$callstack[1]['file']}:"
+ . "{$callstack[1]['line']}\n\nStack trace:\n\n" . print_r($callstack, true));
+ }
+
+ return false;
+}
+
/**
* Returns the current page's complete URL.
*
@@ -1391,6 +1658,23 @@ function elgg_add_action_tokens_to_url($url, $html_encode = FALSE) {
return elgg_http_build_url($components, $html_encode);
}
+
+/**
+ * Add action tokens to URL.
+ *
+ * @param string $url URL
+ *
+ * @return string
+ *
+ * @deprecated 1.7 final
+ */
+function elgg_validate_action_url($url) {
+ elgg_deprecated_notice('elgg_validate_action_url() deprecated by elgg_add_action_tokens_to_url().',
+ '1.7b');
+
+ return elgg_add_action_tokens_to_url($url);
+}
+
/**
* Removes an element from a URL's query string.
*
@@ -1726,7 +2010,7 @@ $sort_type = SORT_LOCALE_STRING) {
} else {
$sort[] = NULL;
}
- }
+ };
return array_multisort($sort, $sort_order, $sort_type, $array);
}
@@ -1767,7 +2051,7 @@ function elgg_get_ini_setting_in_bytes($setting) {
// convert INI setting when shorthand notation is used
$last = strtolower($val[strlen($val) - 1]);
- switch ($last) {
+ switch($last) {
case 'g':
$val *= 1024;
case 'm':
@@ -1834,6 +2118,30 @@ function elgg_normalise_plural_options_array($options, $singulars) {
}
/**
+ * Does nothing.
+ *
+ * @deprecated 1.7
+ * @return 0
+ */
+function test_ip() {
+ elgg_deprecated_notice('test_ip() was removed because of licensing issues.', 1.7);
+
+ return 0;
+}
+
+/**
+ * Does nothing.
+ *
+ * @return bool
+ * @deprecated 1.7
+ */
+function is_ip_in_array() {
+ elgg_deprecated_notice('is_ip_in_array() was removed because of licensing issues.', 1.7);
+
+ return false;
+}
+
+/**
* Emits a shutdown:system event upon PHP shutdown, but before database connections are dropped.
*
* @tip Register for the shutdown:system event to perform functions at the end of page loads.