summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2011-08-24 23:17:43 +0200
committerChristian Weiske <cweiske@cweiske.de>2014-03-26 21:54:41 +0100
commit9a57269b231dda4a06b93a89a08ef19f69d3fd5d (patch)
tree0cce001199b654a234a02cb842c75739dffb6b78
parent524b1056a6be1a44890c42b8c7364ceeff4d0ec2 (diff)
downloadSemanticScuttle-9a57269b231dda4a06b93a89a08ef19f69d3fd5d.zip
SemanticScuttle-9a57269b231dda4a06b93a89a08ef19f69d3fd5d.tar.gz
SemanticScuttle-9a57269b231dda4a06b93a89a08ef19f69d3fd5d.tar.bz2
introduce global $cfg variable that one day will get rid of all the $GLOBALS pollution
-rw-r--r--data/config.default.php2
-rw-r--r--src/SemanticScuttle/Config.php143
-rw-r--r--src/SemanticScuttle/Service/Factory.php10
-rw-r--r--src/SemanticScuttle/header.php20
4 files changed, 159 insertions, 16 deletions
diff --git a/data/config.default.php b/data/config.default.php
index 2f32df7..30883c0 100644
--- a/data/config.default.php
+++ b/data/config.default.php
@@ -208,6 +208,8 @@ $tableprefix = 'sc_';
*/
$dbneedssetnames = true;
+$dbpersist = false;
+
/***************************************************
* Users
diff --git a/src/SemanticScuttle/Config.php b/src/SemanticScuttle/Config.php
index 08d8f8d..2f10475 100644
--- a/src/SemanticScuttle/Config.php
+++ b/src/SemanticScuttle/Config.php
@@ -20,7 +20,7 @@
* @license AGPL http://www.gnu.org/licenses/agpl.html
* @link http://sourceforge.net/projects/semanticscuttle
*/
-class SemanticScuttle_Config
+class SemanticScuttle_Config implements ArrayAccess
{
/**
* Prefix for configuration files.
@@ -30,6 +30,121 @@ class SemanticScuttle_Config
*/
public $filePrefix = '';
+ /**
+ * Array with all configuration data
+ */
+ protected $configData = array();
+
+
+ /**
+ * Loads the variables from the given configuration file
+ * into $GLOBALS
+ *
+ * @param string $file Configuration file path to load
+ *
+ * @return void
+ */
+ public function load($file)
+ {
+ // ack \\$ data/config.default.php |sed 's/ .*$//'|grep -v ^$|sort
+ //this here is required because setting $GLOBALS doesnt'
+ // automatically set "global" :/
+ global
+ $adminemail,
+ $adminsAreAdvisedTagsFromOtherAdmins,
+ $adminsCanModifyBookmarksFromOtherUsers,
+ $admin_users,
+ $allowedProtocols,
+ $allowUnittestMode,
+ $antispamAnswer,
+ $antispamQuestion,
+ $authDebug,
+ $authEmailSuffix,
+ $authOptions,
+ $authType,
+ $avahiServiceFilePath,
+ $avahiServiceFilePrefix,
+ $avahiTagName,
+ $blankDescription,
+ $bottom_include,
+ $cleanurls,
+ $dateOrderField,
+ $dbhost,
+ $dbname,
+ $dbneedssetnames,
+ $dbpass,
+ $dbpersist,
+ $dbport,
+ $dbtype,
+ $dbuser,
+ $debugMode,
+ $defaultOrderBy,
+ $defaultPerPage,
+ $defaultPerPageForAdmins,
+ $defaultRecentDays,
+ $defaultRssEntries,
+ $defaults,
+ $descriptionAnchors,
+ $dir_cache,
+ $enableAdminColors,
+ $enableCommonBookmarkDescription,
+ $enableCommonTagDescription,
+ $enableCommonTagDescriptionEditedByAll,
+ $enableGoogleCustomSearch,
+ $enableRegistration,
+ $enableVoting,
+ $enableWebsiteThumbnails,
+ $filetypes,
+ $footerMessage,
+ $googleAnalyticsCode,
+ $hideBelowVoting,
+ $index_sidebar_blocks,
+ $locale,
+ $longdate,
+ $maxRssEntries,
+ $maxSizeMenuBlock,
+ $menu2Tags,
+ $menuTag,
+ $nofollow,
+ $reservedusers,
+ $root,
+ $serviceoverrides,
+ $shortdate,
+ $shorturl,
+ $sidebarBottomMessage,
+ $sidebarTopMessage,
+ $sitename,
+ $sizeSearchHistory,
+ $tableprefix,
+ $TEMPLATES_DIR,
+ $theme,
+ $thumbnailsKey,
+ $thumbnailsUserId,
+ $top_include,
+ $unittestUrl,
+ $url_redir,
+ $usecache,
+ $useredir,
+ $votingMode,
+ $welcomeMessage;
+
+ require_once $file;
+
+ //make them global
+ //does not really work because many parts still access the variables
+ // without $cfg/$GLOBALS
+ //unset($file);
+ //$GLOBALS = get_defined_vars() + $GLOBALS;
+ }
+
+ /**
+ * Assigns GLOBALS to configData
+ */
+ public function __construct()
+ {
+ $this->configData =& $GLOBALS;
+ }
+
/**
@@ -141,6 +256,32 @@ class SemanticScuttle_Config
}
return array($configfile, $defaultfile);
}
+
+
+
+ public function offsetExists($offset)
+ {
+ return isset($this->configData[$offset]);
+ }
+
+ public function offsetGet($offset)
+ {
+ return $this->configData[$offset];
+ }
+
+ public function offsetSet($offset, $value)
+ {
+ if (is_null($offset)) {
+ $this->configData[] = $value;
+ } else {
+ $this->configData[$offset] = $value;
+ }
+ }
+
+ public function offsetUnset($offset)
+ {
+ unset($this->configData[$offset]);
+ }
}
?> \ No newline at end of file
diff --git a/src/SemanticScuttle/Service/Factory.php b/src/SemanticScuttle/Service/Factory.php
index b661cdb..096c1c3 100644
--- a/src/SemanticScuttle/Service/Factory.php
+++ b/src/SemanticScuttle/Service/Factory.php
@@ -113,16 +113,14 @@ class SemanticScuttle_Service_Factory
*/
protected static function loadDb()
{
- global $dbhost, $dbuser, $dbpass, $dbname,
- $dbport, $dbpersist, $dbtype, $dbneedssetnames;
-
if (self::$db !== null) {
return;
}
- include_once 'SemanticScuttle/db/'. $dbtype .'.php';
+ include_once 'SemanticScuttle/db/'. $GLOBALS['dbtype'] .'.php';
$db = new sql_db();
$db->sql_connect(
- $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist
+ $GLOBALS['dbhost'], $GLOBALS['dbuser'], $GLOBALS['dbpass'],
+ $GLOBALS['dbname'], $GLOBALS['dbport'], $GLOBALS['dbpersist']
);
if (!$db->db_connect_id) {
message_die(
@@ -132,7 +130,7 @@ class SemanticScuttle_Service_Factory
);
}
- $dbneedssetnames && $db->sql_query('SET NAMES UTF8');
+ $GLOBALS['dbneedssetnames'] && $db->sql_query('SET NAMES UTF8');
self::$db = $db;
}
diff --git a/src/SemanticScuttle/header.php b/src/SemanticScuttle/header.php
index 1f2f12c..fd140ec 100644
--- a/src/SemanticScuttle/header.php
+++ b/src/SemanticScuttle/header.php
@@ -29,6 +29,8 @@ require_once dirname(__FILE__) . '/Environment.php';
require_once dirname(__FILE__) . '/Config.php';
$cfg = new SemanticScuttle_Config();
+$GLOBALS['cfg'] = $cfg;
+
list($configfile, $defaultfile) = $cfg->findFiles();
if ($defaultfile === null) {
header('HTTP/1.0 500 Internal Server Error');
@@ -48,8 +50,8 @@ set_include_path(
);
// 1 // First requirements part (before debug management)
-require_once $defaultfile;
-require_once $configfile;
+$cfg->load($defaultfile);
+$cfg->load($configfile);
if (isset($_GET['unittestMode']) && $_GET['unittestMode'] == 1
) {
@@ -106,11 +108,11 @@ require_once 'SemanticScuttle/Model/Bookmark.php';
require_once 'SemanticScuttle/Model/UserArray.php';
require_once 'SemanticScuttle/Model/User/SslClientCert.php';
-if (count($GLOBALS['serviceoverrides']) > 0
+if (count($cfg['serviceoverrides']) > 0
&& !defined('UNIT_TEST_MODE')
) {
SemanticScuttle_Service_Factory::$serviceoverrides
- = $GLOBALS['serviceoverrides'];
+ = $cfg['serviceoverrides'];
}
// 3 // Third requirements part which import functions from includes/ directory
@@ -121,7 +123,7 @@ require_once 'SemanticScuttle/utf8.php';
// Translation
require_once 'php-gettext/gettext.inc';
$domain = 'messages';
-T_setlocale(LC_MESSAGES, $locale);
+T_setlocale(LC_MESSAGES, $cfg['locale']);
T_bindtextdomain($domain, realpath($datadir . 'locales/'));
T_bind_textdomain_codeset($domain, 'UTF-8');
T_textdomain($domain);
@@ -129,15 +131,15 @@ T_textdomain($domain);
// 4 // Session
if (isset($_SERVER['REMOTE_ADDR'])) {
session_start();
- if ($GLOBALS['enableVoting']) {
+ if ($cfg['enableVoting']) {
if (isset($_SESSION['lastUrl'])) {
- $GLOBALS['lastUrl'] = $_SESSION['lastUrl'];
+ $cfg['lastUrl'] = $_SESSION['lastUrl'];
}
//this here is hacky, but currently the only way to
// differentiate between css/js php files and normal
// http files
- if (!isset($GLOBALS['saveInLastUrl'])
- || $GLOBALS['saveInLastUrl']
+ if (!isset($cfg['saveInLastUrl'])
+ || $cfg['saveInLastUrl']
) {
$_SESSION['lastUrl'] = $_SERVER['REQUEST_URI'];
}