Permalink
Browse files

feature(core): Makes several commonly-used functions public

This also adds elgg_enable_query_cache, elgg_disable_query_cache, and
elgg_html_decode.

Fixes #7838
  • Loading branch information...
mrclay committed Jul 30, 2015
1 parent c59f905 commit 4b58e4f5db3a1411e891ca34754e9a5c9c4d9681
View
@@ -37,10 +37,10 @@
// must decode in utf8 or string corruption occurs. see #1567.
if (is_array($value)) {
array_walk_recursive($value, function(&$v) {
- $v = _elgg_html_decode($v);
+ $v = elgg_html_decode($v);
});
} else {
- $value = _elgg_html_decode($value);
+ $value = elgg_html_decode($value);
}
// limit to reasonable sizes
View
@@ -154,7 +154,6 @@ function get_default_access(ElggUser $user = null, array $input_params = array()
*
* @param bool $show_hidden Show disabled entities.
* @return bool
- * @access private
*/
function access_show_hidden_entities($show_hidden) {
global $ENTITY_SHOW_HIDDEN_OVERRIDE;
@@ -167,7 +166,6 @@ function access_show_hidden_entities($show_hidden) {
* Return current status of showing disabled entities.
*
* @return bool
- * @access private
*/
function access_get_show_hidden_status() {
global $ENTITY_SHOW_HIDDEN_OVERRIDE;
View
@@ -162,7 +162,6 @@ function action_gatekeeper($action) {
* @see @elgg_view input/form
*
* @return string|false
- * @access private
*/
function generate_action_token($timestamp) {
return _elgg_services()->actions->generateActionToken($timestamp);
View
@@ -178,6 +178,30 @@ function sanitise_int($int, $signed = true) {
return sanitize_int($int, $signed);
}
+/**
+ * Enable the MySQL query cache
+ *
+ * @return void
+ *
+ * @since 2.0.0
+ */
+function elgg_enable_query_cache() {
+ _elgg_services()->db->enableQueryCache();
+}
+
+/**
+ * Disable the MySQL query cache
+ *
+ * @note Elgg already manages the query cache sensibly, so you probably don't need to use this.
+ *
+ * @return void
+ *
+ * @since 2.0.0
+ */
+function elgg_disable_query_cache() {
+ _elgg_services()->db->disableQueryCache();
+}
+
/**
* Log db profiling information at NOTICE debug level upon shutdown.
*
View
@@ -800,6 +800,34 @@ function elgg_trigger_plugin_hook($hook, $type, $params = null, $returnvalue = n
return _elgg_services()->hooks->trigger($hook, $type, $params, $returnvalue);
}
+/**
+ * Returns an ordered array of hook handlers registered for $hook and $type.
+ *
+ * @param string $hook Hook name
+ * @param string $type Hook type
+ *
+ * @return array
+ *
+ * @since 2.0.0
+ */
+function elgg_get_ordered_hook_handlers($hook, $type) {
+ return _elgg_services()->hooks->getOrderedHandlers($hook, $type);
+}
+
+/**
+ * Returns an ordered array of event handlers registered for $event and $type.
+ *
+ * @param string $event Event name
+ * @param string $type Object type
+ *
+ * @return array
+ *
+ * @since 2.0.0
+ */
+function elgg_get_ordered_event_handlers($event, $type) {
+ return _elgg_services()->events->getOrderedHandlers($event, $type);
+}
+
/**
* Intercepts, logs, and displays uncaught exceptions.
*
View
@@ -152,7 +152,6 @@ function _elgg_retrieve_cached_entity($guid) {
*
* @return int Subtype ID
* @see get_subtype_from_id()
- * @access private
*/
function get_subtype_id($type, $subtype) {
return _elgg_services()->subtypeTable->getId($type, $subtype);
@@ -205,7 +204,6 @@ function _elgg_populate_subtype_cache() {
* @return string|null a class name or null
* @see get_subtype_from_id()
* @see get_subtype_class_from_id()
- * @access private
*/
function get_subtype_class($type, $subtype) {
return _elgg_services()->subtypeTable->getClass($type, $subtype);
View
@@ -458,7 +458,9 @@ function elgg_strip_tags($string, $allowable_tags = null) {
}
/**
- * Apply html_entity_decode() to a string while re-entitising HTML
+ * Decode HTML markup into a raw text string
+ *
+ * This applies html_entity_decode() to a string while re-entitising HTML
* special char entities to prevent them from being decoded back to their
* unsafe original forms.
*
@@ -469,22 +471,20 @@ function elgg_strip_tags($string, $allowable_tags = null) {
* usually decoded, i.e. a lone > is not decoded, but <foo> would
* be decoded to <foo> since it creates a full tag.
*
- * Note: This function is poorly explained in the manual - which is really
+ * Note: html_entity_decode() is poorly explained in the manual - which is really
* bad given its potential for misuse on user input already escaped elsewhere.
* Stackoverflow is littered with advice to use this function in the precise
* way that would lead to user input being capable of injecting arbitrary HTML.
*
- * @param string $string
+ * @param string $string Encoded HTML
*
* @return string
*
* @author Pádraic Brady
* @copyright Copyright (c) 2010 Pádraic Brady (http://blog.astrumfutura.com)
* @license Released under dual-license GPL2/MIT by explicit permission of Pádraic Brady
- *
- * @access private
*/
-function _elgg_html_decode($string) {
+function elgg_html_decode($string) {
$string = str_replace(
array('&gt;', '&lt;', '&amp;', '&quot;', '&#039;'),
array('&amp;gt;', '&amp;lt;', '&amp;amp;', '&amp;quot;', '&amp;#039;'),
@@ -499,6 +499,22 @@ function _elgg_html_decode($string) {
return $string;
}
+/**
+ * Alias of elgg_html_decode
+ *
+ * This is kept in 2.0 because it was used in public views and might have been copied into plugins.
+ *
+ * @param string $string Encoded HTML
+ *
+ * @return string
+ * @see elgg_html_decode
+ * @deprecated
+ */
+function _elgg_html_decode($string) {
+ elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_html_decode()', '2.0');
+ return elgg_html_decode($string);
+}
+
/**
* Prepares query string for output to prevent CSRF attacks.
*
View
@@ -28,7 +28,6 @@ function elgg_set_processed_upgrades(array $processed_upgrades) {
* @param string $filename The upgrade filename. No full path.
* @return int|false
* @since 1.8.0
- * @access private
* @todo used by elgg_get_upgrade_files
*/
function elgg_get_upgrade_file_version($filename) {
View
@@ -954,7 +954,6 @@ function elgg_view_annotation(\ElggAnnotation $annotation, array $vars = array()
* 'no_results' Message to display if no results (string|Closure)
*
* @return string The rendered list of entities
- * @access private
*/
function elgg_view_entity_list($entities, array $vars = array()) {
$offset = (int)get_input('offset', 0);
@@ -54,7 +54,7 @@
$excerpt_input = elgg_view('input/text', array(
'name' => 'excerpt',
'id' => 'blog_excerpt',
- 'value' => _elgg_html_decode($vars['excerpt'])
+ 'value' => elgg_html_decode($vars['excerpt'])
));
$body_label = elgg_echo('blog:body');
@@ -25,10 +25,10 @@
// @todo treat profile fields as unescaped: don't filter, encode on output
if (is_array($input[$shortname])) {
array_walk_recursive($input[$shortname], function (&$v) {
- $v = _elgg_html_decode($v);
+ $v = elgg_html_decode($v);
});
} else {
- $input[$shortname] = _elgg_html_decode($input[$shortname]);
+ $input[$shortname] = elgg_html_decode($input[$shortname]);
}
if ($valuetype == 'tags') {

0 comments on commit 4b58e4f

Please sign in to comment.