introduce global $cfg variable that one day will get rid of all the $GLOBALS pollution
This commit is contained in:
parent
524b1056a6
commit
9a57269b23
@ -208,6 +208,8 @@ $tableprefix = 'sc_';
|
||||
*/
|
||||
$dbneedssetnames = true;
|
||||
|
||||
$dbpersist = false;
|
||||
|
||||
|
||||
/***************************************************
|
||||
* Users
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -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;
|
||||
}
|
||||
|
@ -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'];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user