Skip to content

Commit

Permalink
* Replaced all $boarddir occurrences with ROOT_DIR. Replaced most $bo…
Browse files Browse the repository at this point in the history
…ardurl with ROOT. Getting close! (Class-Editor.php, Class-FileWritable.php, ManageErrors.php, ManagePlugins.php, ManageServer.php, QueryString.php, Subs-Admin.php, Subs-Plugins.php, Subs-Template.php, Themes.php, ViewQuery.php, Aeva-Foxy.php, Aeva-Gallery.php, ManageMedia.php)
  • Loading branch information
Nao committed Mar 23, 2014
1 parent b79f3d6 commit 7c3a6b3
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 79 deletions.
14 changes: 6 additions & 8 deletions core/app/Class-Editor.php
Expand Up @@ -2148,12 +2148,10 @@ public static function fixTags(&$message)
// Fix a specific class of tag - ie. url with =.
public static function fixTag(&$message, $myTag, $protocols, $embeddedUrl = false, $hasEqualSign = false, $hasExtra = false)
{
global $boardurl;

if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0)
if (preg_match('~^([^:]+://[^/]+)~', ROOT, $match) != 0)
$domain_url = $match[1];
else
$domain_url = $boardurl . '/';
$domain_url = ROOT . '/';

$replaces = array();

Expand Down Expand Up @@ -2439,7 +2437,7 @@ public static function preparseWYSIWYG($id)

public function outputEditor()
{
global $context, $txt, $settings, $boarddir, $boardurl, $smiley_css_done;
global $context, $txt, $settings, $smiley_css_done;

$smileycontainer = empty($this->editorOptions['custom_smiley_div']) ? 'smileyBox_' . $this->id : $this->editorOptions['custom_smiley_div'];
$bbccontainer = empty($this->editorOptions['custom_bbc_div']) ? 'bbcBox_' . $this->id : $this->editorOptions['custom_bbc_div'];
Expand Down Expand Up @@ -2487,14 +2485,14 @@ public function outputEditor()
updateSettings(array($var_name => time() % 1000));
$context['smiley_now'] = $settings[$var_name];
$filename = '/gz/css/smileys' . $extra . (we::$user['smiley_set'] == 'default' ? '' : '-' . we::$user['smiley_set']) . '-' . $context['smiley_now'] . $context['smiley_ext'];
$exists = file_exists($boarddir . $filename);
$exists = file_exists(ROOT_DIR . $filename);
if (!$exists)
parsesmileys($dummy);
}

if (empty($smiley_css_done) && strpos($context['header'], $boardurl . $filename) === false)
if (empty($smiley_css_done) && strpos($context['header'], ROOT . $filename) === false)
$context['header'] .= '
<link rel="stylesheet" href="' . $boardurl . $filename . '">';
<link rel="stylesheet" href="' . ROOT . $filename . '">';

$js = '';
foreach ($this->smileys as $location => $smileyRows)
Expand Down
3 changes: 1 addition & 2 deletions core/app/Class-FileWritable.php
Expand Up @@ -19,11 +19,10 @@ class weFileWritable
// This is essentially pure placeholder but it makes everything much more convenient later.
public function __construct($server = null, $port = null, $user = null, $pass = null)
{
global $boarddir;
$this->connection = false;
$this->error = false;
$this->pasv = array();
$this->path = $boarddir;
$this->path = ROOT_DIR;
}

public function connect($server = null, $port = null, $user = null, $pass = null)
Expand Down
4 changes: 2 additions & 2 deletions core/app/ManageErrors.php
Expand Up @@ -633,7 +633,7 @@ function updateErrorCount($count = 0)

function ViewFile()
{
global $context, $txt, $boarddir, $cachedir;
global $context, $txt;

loadTemplate('GenericPopup');
loadLanguage('Help');
Expand All @@ -646,7 +646,7 @@ function ViewFile()
$basename = strtolower(basename($file));

// Make sure the file we are looking for is one they are allowed to look at
if (strrchr($basename, '.') != '.php' || $basename == 'settings.php' || $basename == 'settings_bak.php' || !strhas($file, array(realpath($boarddir), realpath(APP_DIR), realpath($cachedir . '/php'))) || !is_readable($file))
if (strrchr($basename, '.') != '.php' || $basename == 'settings.php' || $basename == 'settings_bak.php' || !strhas($file, array(realpath(ROOT_DIR), realpath(APP_DIR), realpath(ROOT_DIR . '/gz/php'))) || !is_readable($file))
fatal_lang_error('error_bad_file', true, array(htmlspecialchars(base64_decode($_REQUEST['file']))));

// Get the min and max lines
Expand Down
4 changes: 2 additions & 2 deletions core/app/ManagePlugins.php
Expand Up @@ -1434,8 +1434,8 @@ function executePluginScript($type, $file)
if (empty($file) || substr($file, -4) != '.php' || strpos($file, '$plugindir/') !== 0 || !file_exists($full_path))
fatal_lang_error('fatal_install_' . $type . '_missing', false, empty($file) ? $txt['not_applicable'] : htmlspecialchars($file));

// This is just here as reference for what is available.
global $txt, $boarddir, $settings, $context;
// Make these available to plugins.
global $txt, $settings, $context;
require($full_path);
}
}
Expand Down
6 changes: 3 additions & 3 deletions core/app/ManageServer.php
Expand Up @@ -123,7 +123,7 @@
// This is the main pass through function, it creates tabs and the like.
function ModifySettings()
{
global $context, $txt, $boarddir;
global $context, $txt;

// This is just to keep the database password more secure.
isAllowedTo('admin_forum');
Expand Down Expand Up @@ -165,8 +165,8 @@ function ModifySettings()
if ($_REQUEST['sa'] != 'phpinfo')
{
// Warn the user if the backup of Settings.php failed.
$context['settings_not_writable'] = !is_writable($boarddir . '/Settings.php');
$settings_backup_fail = !@is_writable($boarddir . '/Settings_bak.php') || !@copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
$context['settings_not_writable'] = !is_writable(ROOT_DIR . '/Settings.php');
$settings_backup_fail = !@is_writable(ROOT_DIR . '/Settings_bak.php') || !@copy(ROOT_DIR . '/Settings.php', ROOT_DIR . '/Settings_bak.php');

if ($context['settings_not_writable'])
$context['settings_message'] = '<p class="center"><strong>' . $txt['settings_not_writable'] . '</strong></p><br>';
Expand Down
6 changes: 3 additions & 3 deletions core/app/QueryString.php
Expand Up @@ -16,7 +16,7 @@
*/
function loadPaths()
{
global $boardurl, $boarddir, $settings, $context;
global $boardurl, $settings, $context;

// $scripturl is your board URL if you asked to remove index.php or the user visits for the first time
// (in which case they'll get the annoying PHPSESSID stuff in their URL and we need index.php in them.)
Expand Down Expand Up @@ -109,7 +109,7 @@ function loadPaths()
*/
function cleanRequest()
{
global $board, $topic, $boarddir, $settings, $context, $action_list;
global $board, $topic, $settings, $context, $action_list;

// These were deprecated years ago. Save some memory.
unset($GLOBALS['HTTP_POST_VARS'], $GLOBALS['HTTP_POST_FILES']);
Expand Down Expand Up @@ -311,7 +311,7 @@ function cleanRequest()
if (preg_match($regex, $full_request, $filename))
{
// There are probably faster ways to retrieve an 'existing' cached version.
$matches = glob($boarddir . '/' . $filename[1] . '*.' . $filename[2]);
$matches = glob(ROOT_DIR . '/' . $filename[1] . '*.' . $filename[2]);
if (!empty($matches) && preg_match($regex, (string) reset($matches), $new_filename))
{
header('HTTP/1.1 301 Moved Permanently');
Expand Down
30 changes: 12 additions & 18 deletions core/app/Subs-Admin.php
Expand Up @@ -140,8 +140,6 @@ function getServerVersions($checkFor)
// Search through source, theme and language files to determine their version.
function getFileVersions(&$versionOptions)
{
global $boarddir;

// Default place to find the languages would be the default theme dir.
$lang_dir = LANGUAGES_DIR;

Expand All @@ -152,9 +150,9 @@ function getFileVersions(&$versionOptions)
);

// Find the version in SSI.php's file header.
if (!empty($versionOptions['include_ssi']) && file_exists($boarddir . '/SSI.php'))
if (!empty($versionOptions['include_ssi']) && file_exists(ROOT_DIR . '/SSI.php'))
{
$fp = fopen($boarddir . '/SSI.php', 'rb');
$fp = fopen(ROOT_DIR . '/SSI.php', 'rb');
$header = fread($fp, 4096);
fclose($fp);

Expand All @@ -167,9 +165,9 @@ function getFileVersions(&$versionOptions)
}

// Do the paid subscriptions handler?
if (!empty($versionOptions['include_subscriptions']) && file_exists($boarddir . '/subscriptions.php'))
if (!empty($versionOptions['include_subscriptions']) && file_exists(ROOT_DIR . '/subscriptions.php'))
{
$fp = fopen($boarddir . '/subscriptions.php', 'rb');
$fp = fopen(ROOT_DIR . '/subscriptions.php', 'rb');
$header = fread($fp, 4096);
fclose($fp);

Expand Down Expand Up @@ -265,13 +263,11 @@ function getFileVersions(&$versionOptions)
// Update the Settings.php file.
function updateSettingsFile($config_vars)
{
global $boarddir, $cachedir;

// When was Settings.php last changed?
$last_settings_change = filemtime($boarddir . '/Settings.php');
$last_settings_change = filemtime(ROOT_DIR . '/Settings.php');

// Load the file. Break it up based on \r or \n, and then clean out extra characters.
$settingsArray = trim(file_get_contents($boarddir . '/Settings.php'));
$settingsArray = trim(file_get_contents(ROOT_DIR . '/Settings.php'));
if (strpos($settingsArray, "\n") !== false)
$settingsArray = explode("\n", $settingsArray);
elseif (strpos($settingsArray, "\r") !== false)
Expand Down Expand Up @@ -352,17 +348,15 @@ function updateSettingsFile($config_vars)

// Check before you act: do a simple test in the cache folder.
// Can we even write things on this filesystem?
if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/gz'))
$cachedir = $boarddir . '/gz';
$test_fp = @fopen($cachedir . '/settings_update.tmp', 'w+');
$test_fp = @fopen(ROOT_DIR . '/gz/settings_update.tmp', 'w+');
if ($test_fp)
{
fclose($test_fp);

$test_fp = @fopen($cachedir . '/settings_update.tmp', 'r+');
$test_fp = @fopen(ROOT_DIR . '/gz/settings_update.tmp', 'r+');
$written_bytes = fwrite($test_fp, 'test');
fclose($test_fp);
@unlink($cachedir . '/settings_update.tmp');
@unlink(ROOT_DIR . '/gz/settings_update.tmp');

if ($written_bytes !== strlen('test'))
{
Expand All @@ -373,18 +367,18 @@ function updateSettingsFile($config_vars)

// Protect me from what I want! :P
clearstatcache();
if (filemtime($boarddir . '/Settings.php') === $last_settings_change)
if (filemtime(ROOT_DIR . '/Settings.php') === $last_settings_change)
{
// You asked for it...
// Blank out the file - done to fix a oddity with some servers.
$fp = @fopen($boarddir . '/Settings.php', 'w');
$fp = @fopen(ROOT_DIR . '/Settings.php', 'w');

// Is it even writable, though?
if ($fp)
{
fclose($fp);

$fp = fopen($boarddir . '/Settings.php', 'r+');
$fp = fopen(ROOT_DIR . '/Settings.php', 'r+');
foreach ($settingsArray as $line)
fwrite($fp, strtr($line, "\r", ''));
fclose($fp);
Expand Down
6 changes: 3 additions & 3 deletions core/app/Subs-Plugins.php
Expand Up @@ -12,7 +12,7 @@

function getWritableObject()
{
global $context, $settings, $boarddir;
global $context, $settings;

// Normally it'll be on the plugins folder, but there's no reason for it to absolutely be.
// !! Is $path supposed to be set earlier..?
Expand Down Expand Up @@ -66,12 +66,12 @@ function getWritableObject()

if (!in_array($_POST['ftp_path'], array('', '/')))
{
$ftp_root = strtr($boarddir, array($_POST['connect_path'] => ''));
$ftp_root = strtr(ROOT_DIR, array($_POST['connect_path'] => ''));
if (substr($ftp_root, -1) == '/' && ($_POST['connect_path'] == '' || substr($_POST['connect_path'], 0, 1) == '/'))
$ftp_root = substr($ftp_root, 0, -1);
}
else
$ftp_root = $boarddir;
$ftp_root = ROOT_DIR;

$context['connect_details']['path'] = $ftp_root;
}
Expand Down
14 changes: 7 additions & 7 deletions core/app/Subs-Template.php
Expand Up @@ -829,7 +829,7 @@ function start_output()
*/
function while_we_re_here()
{
global $txt, $settings, $context, $boarddir, $cachedir;
global $txt, $settings, $context;
static $checked_security_files = false, $showed_banned = false, $showed_behav_error = false;

// If this page was loaded through jQuery, it's likely we've already had the warning shown in its container...
Expand All @@ -856,10 +856,10 @@ function while_we_re_here()
$security_files = array('import.php', 'install.php', 'webinstall.php', 'upgrade.php', 'convert.php', 'repair_paths.php', 'repair_settings.php', 'Settings.php~', 'Settings_bak.php~');

foreach ($security_files as $i => $security_file)
if (!file_exists($boarddir . '/' . $security_file))
if (!file_exists(ROOT_DIR . '/' . $security_file))
unset($security_files[$i]);

if (!empty($security_files) || (!empty($settings['cache_enable']) && !is_writable($cachedir)))
if (!empty($security_files) || $cache_not_writable = (!empty($settings['cache_enable']) && !is_writable(ROOT_DIR . '/gz')))
{
loadLanguage('Errors');

Expand All @@ -879,7 +879,7 @@ function while_we_re_here()
', sprintf($txt['not_removed_extra'], $security_file, substr($security_file, 0, -1)), '<br>';
}

if (!empty($settings['cache_enable']) && !is_writable($cachedir))
if (!empty($cache_not_writable))
echo '
<strong>', $txt['cache_writable'], '</strong><br>';

Expand Down Expand Up @@ -934,7 +934,7 @@ function while_we_re_here()
*/
function db_debug_junk()
{
global $context, $boarddir, $settings, $txt;
global $txt, $settings, $context;
global $db_cache, $db_count, $db_show_debug, $cache_count, $cache_hits;

// Is debugging on? (i.e. it is set, and it is true, and we're not on action=viewquery or an help popup.
Expand Down Expand Up @@ -990,7 +990,7 @@ function db_debug_junk()
{
if (file_exists($files[$i]))
$total_size += filesize($files[$i]);
$files[$i] = strtr($files[$i], array($boarddir => '.'));
$files[$i] = strtr($files[$i], array(ROOT_DIR => '.'));
}

// A small trick to avoid repeating block names ad nauseam...
Expand Down Expand Up @@ -1062,7 +1062,7 @@ function db_debug_junk()

// Make the filenames look a bit better.
if (isset($qq['f']))
$qq['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $qq['f']);
$qq['f'] = preg_replace('~^' . preg_quote(ROOT_DIR, '~') . '~', '...', $qq['f']);

$temp .= '
<strong>' . ($is_select ? '<a href="' . SCRIPT . '?action=viewquery;qq=' . ($q + 1) . '#qq' . $q . '" target="_blank" class="new_win">' : '') . westr::nl2br(str_replace("\t", '&nbsp;&nbsp;&nbsp;', htmlspecialchars(ltrim($qq['q'], "\n\r")))) . ($is_select ? '</a></strong>' : '</strong>') . '<br>
Expand Down

0 comments on commit 7c3a6b3

Please sign in to comment.