From f0e7d14c218696142b41e0183dc734ddff162018 Mon Sep 17 00:00:00 2001 From: cash Date: Mon, 29 Nov 2010 12:36:38 +0000 Subject: Refs #2428 added elgg_get_config(), elgg_set_config(), and elgg_save_config() git-svn-id: http://code.elgg.org/elgg/trunk@7470 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/configuration.php | 86 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) (limited to 'engine/lib') diff --git a/engine/lib/configuration.php b/engine/lib/configuration.php index b222b6b4f..bf5122653 100644 --- a/engine/lib/configuration.php +++ b/engine/lib/configuration.php @@ -17,6 +17,92 @@ * @subpackage Configuration */ +/** + * Get an Elgg configuration value + * + * @param string $name Name of the configuration value + * @param int $site_guid NULL for installation setting, 0 for default site + * + * @return mixed Configuration value or false if it does not exist + * @since 1.8.0 + */ +function elgg_get_config($name, $site_guid = 0) { + global $CONFIG; + + $name = trim($name); + + if (isset($CONFIG->$name)) { + return $CONFIG->$name; + } + + if ($site_guid === NULL) { + // installation wide setting + $value = datalist_get($name); + } else { + // site specific setting + if ($site_guid == 0) { + $site_guid = (int) $CONFIG->site_id; + } + $value = get_config($name, $site_guid); + } + + if ($value !== false) { + $CONFIG->$name = $value; + return $value; + } + + return false; +} + +/** + * Set an Elgg configuration value + * + * @warning This does not persist the configuration setting. Use elgg_save_config() + * + * @param string $name Name of the configuration value + * @param mixed $value Value + * + * @return void + * @since 1.8.0 + */ +function elgg_set_config($name, $value) { + global $CONFIG; + + $name = trim($name); + + $CONFIG->$name = $value; +} + +/** + * Save a configuration setting + * + * @param string $name Configuration name + * @param mixed $value Configuration value. Should be string for installation setting + * @param int $site_guid NULL for installation setting, 0 for default site + * + * @return bool + * @since 1.8.0 + */ +function elgg_save_config($name, $value, $site_guid = 0) { + global $CONFIG; + + $name = trim($name); + + elgg_set_config($name, $value); + + if ($site_guid === NULL) { + if (is_array($value) || is_object($value)) { + return false; + } + return datalist_set($name, $value); + } else { + if ($site_guid == 0) { + $site_guid = (int) $CONFIG->site_id; + } + return set_config($name, $value, $site_guid); + } +} + /** * Check that installation has completed and the database is populated. * -- cgit v1.2.3