aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-12-27 20:23:07 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-12-27 20:23:07 +0000
commit4ec370d484881acd99e8b7c3ae5ecda954f8ee99 (patch)
tree904fdeedd249d3159d0a0f528be29a3230a3ae48
parent4c94f8809f1131e2d8e073518195b6b65b26aceb (diff)
downloadelgg-4ec370d484881acd99e8b7c3ae5ecda954f8ee99.tar.gz
elgg-4ec370d484881acd99e8b7c3ae5ecda954f8ee99.tar.bz2
Refs #2543: set_default_config() uses better names. get_config() rewrites old names to new, but have to double up assignments in $CONFIG for ppl not using get_config().
git-svn-id: http://code.elgg.org/elgg/trunk@7725 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/configuration.php119
1 files changed, 73 insertions, 46 deletions
diff --git a/engine/lib/configuration.php b/engine/lib/configuration.php
index 5adc4bddc..9e1b82880 100644
--- a/engine/lib/configuration.php
+++ b/engine/lib/configuration.php
@@ -94,7 +94,7 @@ function elgg_get_config($name, $site_guid = 0) {
$CONFIG->$name = $value;
return $value;
}
-
+
return false;
}
@@ -399,16 +399,53 @@ function set_config($name, $value, $site_guid = 0) {
function get_config($name, $site_guid = 0) {
global $CONFIG;
+ $name = sanitise_string($name);
+ $site_guid = (int) $site_guid;
+
+ // check for deprecated values.
+ // @todo might be a better spot to define this?
+ $new_name = false;
+ switch($name) {
+ case 'viewpath':
+ $new_name = 'view_path';
+ $dep_version = 1.8;
+ break;
+
+ case 'pluginspath':
+ $new_name = 'plugins_path';
+ $dep_version = 1.8;
+ break;
+
+ case 'wwwroot':
+ $new_name = 'www_root';
+ $dep_version = 1.8;
+ break;
+
+ case 'sitename':
+ $new_name = 'site_name';
+ $dep_version = 1.8;
+ break;
+ }
+
+ // show dep message
+ if ($new_name) {
+ $name = $new_name;
+ elgg_deprecated_notice($msg, $dep_version);
+ }
+
+ // decide from where to return the value
if (isset($CONFIG->$name)) {
return $CONFIG->$name;
}
- $name = sanitise_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 = get_data_row("SELECT value FROM {$CONFIG->dbprefix}config
+ WHERE name = '{$name}' and site_guid = {$site_guid}");
+
+ if ($result) {
$result = $result->value;
$result = unserialize($result->value);
$CONFIG->$name = $result;
@@ -450,54 +487,44 @@ function get_all_config($site_guid = 0) {
* Sets defaults for or attempts to autodetect some common config values and
* loads them into $CONFIG.
*
- * @return void
+ * @return true
*/
function set_default_config() {
global $CONFIG;
- if (empty($CONFIG->path)) {
- $CONFIG->path = str_replace("\\", "/", dirname(dirname(dirname(__FILE__)))) . "/";
- }
-
- if (empty($CONFIG->viewpath)) {
- $CONFIG->viewpath = $CONFIG->path . "views/";
- }
-
- if (empty($CONFIG->pluginspath)) {
- $CONFIG->pluginspath = $CONFIG->path . "mod/";
- }
-
- if (empty($CONFIG->wwwroot)) {
- /*
- $CONFIG->wwwroot = "http://" . $_SERVER['SERVER_NAME'];
-
- $request = $_SERVER['REQUEST_URI'];
-
- if (strripos($request,"/") < (strlen($request) - 1)) {
- // addressing a file directly, not a dir
- $request = substr($request, 0, strripos($request,"/")+1);
+ $install_root = str_replace("\\", "/", dirname(dirname(dirname(__FILE__))));
+
+ // @todo this seldom works right.
+ $pathpart = str_replace("//", "/", str_replace($_SERVER['DOCUMENT_ROOT'], "", $install_root));
+ if (substr($pathpart, 0, 1) != "/") {
+ $pathpart = "/" . $pathpart;
+ }
+ $www_root = "http://" . $_SERVER['HTTP_HOST'] . $pathpart;
+
+ $defaults = array(
+ 'path' => "$install_root/",
+ 'view_path' => "$install_root/views/",
+ 'plugins_path' => "$install_root/mod/",
+ 'www_root' => $www_root,
+ 'url' => $www_root,
+ 'site_name' => 'New Elgg site',
+ 'language' => 'en',
+
+ // compatibility with old names for ppl not using get_config()
+ 'viewpath' => "$install_root/views/",
+ 'pluginspath' => "$install_root/mod/",
+ 'wwwroot' => $www_root,
+ 'url' => $www_root,
+ 'sitename' => 'New Elgg site',
+ );
+
+ foreach ($defaults as $name => $value) {
+ if (empty($CONFIG->$name)) {
+ $CONFIG->$name = $value;
}
-
- $CONFIG->wwwroot .= $request;
- */
- $pathpart = str_replace("//", "/", str_replace($_SERVER['DOCUMENT_ROOT'], "", $CONFIG->path));
- if (substr($pathpart, 0, 1) != "/") {
- $pathpart = "/" . $pathpart;
- }
- $CONFIG->wwwroot = "http://" . $_SERVER['HTTP_HOST'] . $pathpart;
- }
-
- if (empty($CONFIG->url)) {
- $CONFIG->url = $CONFIG->wwwroot;
}
- if (empty($CONFIG->sitename)) {
- $CONFIG->sitename = "New Elgg site";
- }
-
- if (empty($CONFIG->language)) {
- $CONFIG->language = "en";
- }
+ return true;
}
/**