Skip to content

Commit

Permalink
Replace $GLOBALS configuration with the configuration manager in the …
Browse files Browse the repository at this point in the history
…whole code base
  • Loading branch information
ArthurHoaro committed Jun 11, 2016
1 parent 59404d7 commit 684e662
Show file tree
Hide file tree
Showing 23 changed files with 422 additions and 856 deletions.
26 changes: 13 additions & 13 deletions application/ApplicationUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,32 +132,32 @@ public static function checkPHPVersion($minVersion, $curVersion)
/**
* Checks Shaarli has the proper access permissions to its resources
*
* @param array $globalConfig The $GLOBALS['config'] array
*
* @return array A list of the detected configuration issues
*/
public static function checkResourcePermissions($globalConfig)
public static function checkResourcePermissions()
{
$errors = array();
$conf = ConfigManager::getInstance();

// Check script and template directories are readable
foreach (array(
'application',
'inc',
'plugins',
$globalConfig['RAINTPL_TPL']
$conf->get('config.RAINTPL_TPL'),
) as $path) {
if (! is_readable(realpath($path))) {
$errors[] = '"'.$path.'" directory is not readable';
}
}

$datadir = $conf->get('config.DATADIR');
// Check cache and data directories are readable and writeable
foreach (array(
$globalConfig['CACHEDIR'],
$globalConfig['DATADIR'],
$globalConfig['PAGECACHE'],
$globalConfig['RAINTPL_TMP']
$conf->get('config.CACHEDIR'),
$datadir,
$conf->get('config.PAGECACHE'),
$conf->get('config.RAINTPL_TMP'),
) as $path) {
if (! is_readable(realpath($path))) {
$errors[] = '"'.$path.'" directory is not readable';
Expand All @@ -169,11 +169,11 @@ public static function checkResourcePermissions($globalConfig)

// Check configuration files are readable and writeable
foreach (array(
$globalConfig['CONFIG_FILE'],
$globalConfig['DATASTORE'],
$globalConfig['IPBANS_FILENAME'],
$globalConfig['LOG_FILE'],
$globalConfig['UPDATECHECK_FILENAME']
$conf->getConfigFile(),
$conf->get('config.DATASTORE'),
$conf->get('config.IPBANS_FILENAME'),
$conf->get('config.LOG_FILE'),
$conf->get('config.UPDATECHECK_FILENAME'),
) as $path) {
if (! is_file(realpath($path))) {
# the file may not exist yet
Expand Down
221 changes: 0 additions & 221 deletions application/Config.php

This file was deleted.

8 changes: 5 additions & 3 deletions application/FileUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ class IOException extends Exception
/**
* Construct a new IOException
*
* @param string $path path to the ressource that cannot be accessed
* @param string $path path to the resource that cannot be accessed
* @param string $message Custom exception message.
*/
public function __construct($path)
public function __construct($path, $message = '')
{
$this->path = $path;
$this->message = 'Error accessing '.$this->path;
$this->message = empty($message) ? 'Error accessing' : $message;
$this->message .= PHP_EOL . $this->path;
}
}
28 changes: 16 additions & 12 deletions application/PageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,22 @@ function __construct()
private function initialize()
{
$this->tpl = new RainTPL();
$conf = ConfigManager::getInstance();

try {
$version = ApplicationUtils::checkUpdate(
shaarli_version,
$GLOBALS['config']['UPDATECHECK_FILENAME'],
$GLOBALS['config']['UPDATECHECK_INTERVAL'],
$GLOBALS['config']['ENABLE_UPDATECHECK'],
$conf->get('config.UPDATECHECK_FILENAME'),
$conf->get('config.UPDATECHECK_INTERVAL'),
$conf->get('config.ENABLE_UPDATECHECK'),
isLoggedIn(),
$GLOBALS['config']['UPDATECHECK_BRANCH']
$conf->get('config.UPDATECHECK_BRANCH')
);
$this->tpl->assign('newVersion', escape($version));
$this->tpl->assign('versionError', '');

} catch (Exception $exc) {
logm($GLOBALS['config']['LOG_FILE'], $_SERVER['REMOTE_ADDR'], $exc->getMessage());
logm($conf->get('config.LOG_FILE'), $_SERVER['REMOTE_ADDR'], $exc->getMessage());
$this->tpl->assign('newVersion', '');
$this->tpl->assign('versionError', escape($exc->getMessage()));
}
Expand All @@ -62,16 +63,19 @@ private function initialize()
$this->tpl->assign('scripturl', index_url($_SERVER));
$this->tpl->assign('pagetitle', 'Shaarli');
$this->tpl->assign('privateonly', !empty($_SESSION['privateonly'])); // Show only private links?
if (!empty($GLOBALS['title'])) {
$this->tpl->assign('pagetitle', $GLOBALS['title']);
if ($conf->exists('title')) {
$this->tpl->assign('pagetitle', $conf->get('title'));
}
if (!empty($GLOBALS['titleLink'])) {
$this->tpl->assign('titleLink', $GLOBALS['titleLink']);
if ($conf->exists('titleLink')) {
$this->tpl->assign('titleLink', $conf->get('titleLink'));
}
if (!empty($GLOBALS['pagetitle'])) {
$this->tpl->assign('pagetitle', $GLOBALS['pagetitle']);
if ($conf->exists('pagetitle')) {
$this->tpl->assign('pagetitle', $conf->get('pagetitle'));
}
$this->tpl->assign('shaarlititle', empty($GLOBALS['title']) ? 'Shaarli': $GLOBALS['title']);
$this->tpl->assign('shaarlititle', $conf->get('title', 'Shaarli'));
$this->tpl->assign('openshaarli', $conf->get('config.OPEN_SHAARLI', false));
$this->tpl->assign('showatom', $conf->get('config.SHOW_ATOM', false));
// FIXME! Globals
if (!empty($GLOBALS['plugin_errors'])) {
$this->tpl->assign('plugin_errors', $GLOBALS['plugin_errors']);
}
Expand Down
Loading

0 comments on commit 684e662

Please sign in to comment.