From 0f2141e90dd03bb66318ec8776fada3ef8569ef9 Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 1 May 2008 14:55:30 +0000 Subject: Get and set per-site configuration values from the database git-svn-id: https://code.elgg.org/elgg/trunk@600 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/configuration.php | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'engine') diff --git a/engine/lib/configuration.php b/engine/lib/configuration.php index 6b2bfbb49..efffb5e8d 100644 --- a/engine/lib/configuration.php +++ b/engine/lib/configuration.php @@ -12,6 +12,55 @@ * @link http://elgg.org/ */ + + /** + * Enter description here... + * + * @param unknown_type $name + * @param unknown_type $value + * @param unknown_type $site_guid + * @return unknown + */ + function set_config($name, $value, $site_guid = 0) { + + global $CONFIG; + $name = mysql_real_escape_string($name); + $value = mysql_real_escape_string($value); + $site_guid = (int) $site_guid; + if ($site_guid == 0) + $site_guid = (int) $CONFIG->site_id; + $CONFIG->$name = $value; + $value = serialize($value); + return insert_data("insert into {$CONFIG->dbprefix}config set name = '{$name}', value = '{$value}', site_guid = {$site_guid}"); + + } + + /** + * Gets a configuration value + * + * @param string $name The name of the config value + * @param int $site_guid Optionally, the GUID of the site (current site is assumed by default) + * @return mixed|false Depending on success + */ + function get_config($name, $site_guid = 0) { + + global $CONFIG; + if (isset($CONFIG->$name)) + return $CONFIG->$name; + $name = mysql_real_escape_string($name); + $site_guid = (int) $site_guid; + if ($site_guid == 0) + $site_guid = (int) $CONFIG->site_id; + if ($result = get_data_row("select value from {$CONFIG->dbprefix}config where name = '{$name}' and site_guid = {$site_guid}")) { + $result = $result->value; + $result = unserialize($result->value); + $CONFIG->$name = $result; + return $result; + } + return false; + + } + /** * If certain configuration elements don't exist, autodetect sensible defaults * -- cgit v1.2.3