Skip to content

Commit

Permalink
! I'm not sure what made me think I was done with removing $cachedir …
Browse files Browse the repository at this point in the history
…and $boarddir from Wedge... Let's not talk about it, okay? (SSI.php, Subs-Cache.php, Subs-Plugins.php, install.php, install/ssi_examples.php)
  • Loading branch information
Nao committed Mar 23, 2014
1 parent 253119c commit 36986c1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 48 deletions.
6 changes: 1 addition & 5 deletions SSI.php
Expand Up @@ -17,7 +17,7 @@
// We're going to want a few globals... these are all set later.
global $settings, $context, $sc, $topic, $board, $txt;
global $time_start, $maintenance, $msubject, $mmessage, $mbname;
global $boardurl, $boarddir, $webmaster_email, $cookiename;
global $boardurl, $webmaster_email, $cookiename;
global $db_server, $db_connection, $db_name, $db_user, $db_prefix, $db_persist;
global $db_error_send, $db_last_error, $ssi_db_user, $ssi_db_passwd, $db_passwd;

Expand All @@ -37,10 +37,6 @@
require_once(dirname(__FILE__) . '/Settings.php');
require_once(dirname(__FILE__) . '/index.php');

$boarddir = ROOT_DIR;
foreach (array('cache' => 'gz', 'css' => 'gz/css', 'js' => 'gz/js') as $var => $path)
${$var . 'dir'} = ROOT_DIR . '/' . $path;

$ssi_error_reporting = error_reporting(E_ALL | E_STRICT);
/*
Set this to one of three values depending on what you want to happen in the case of a fatal error.
Expand Down
37 changes: 18 additions & 19 deletions core/app/Subs-Cache.php
Expand Up @@ -1659,9 +1659,9 @@ function uncache()
*/
function clean_cache($extensions = 'php', $filter = '', $force_folder = '', $remove_folder = false)
{
global $cache_system, $cachedir;
global $cache_system;

$folder = $cachedir . '/keys';
$folder = CACHE_DIR . '/keys';
$is_recursive = false;
$there_is_another = false;
if ($extensions === 'css')
Expand Down Expand Up @@ -1695,7 +1695,7 @@ function clean_cache($extensions = 'php', $filter = '', $force_folder = '', $rem
$filter_is_folder = !$filter || strpos($force_folder, $filter) !== false;

// If we're emptying the regular cache, chances are we also want to reset non-file-based cached data if possible.
if ($folder == $cachedir . '/keys')
if ($folder == CACHE_DIR . '/keys')
{
cache_get_type();
if ($cache_system === 'apc')
Expand All @@ -1713,8 +1713,8 @@ function clean_cache($extensions = 'php', $filter = '', $force_folder = '', $rem
clean_cache('', '', $zend_cache_folder . '/.php_cache_api');

// Also get the source and language caches!
clean_cache('php', '', $cachedir . '/app');
clean_cache('php', '', $cachedir . '/lang');
clean_cache('php', '', CACHE_DIR . '/app');
clean_cache('php', '', CACHE_DIR . '/lang');
}

// Remove the files in Wedge's own disk cache, if any.
Expand All @@ -1738,7 +1738,7 @@ function clean_cache($extensions = 'php', $filter = '', $force_folder = '', $rem
// Invalidate cache, to be sure!
if (!$force_folder && !is_array($extensions))
{
@fclose(@fopen($cachedir . '/cache.lock', 'w'));
@fclose(@fopen(CACHE_DIR . '/cache.lock', 'w'));
clearstatcache();
}
elseif ($remove_folder && !$there_is_another)
Expand Down Expand Up @@ -1811,7 +1811,7 @@ function cache_quick_get($key, $file, $function, $params, $level = 1)
function cache_put_data($key, $val, $ttl = 120)
{
global $cache_system, $cache_hits, $cache_count;
global $settings, $db_show_debug, $cachedir;
global $settings, $db_show_debug;

if (empty($settings['cache_enable']) && !empty($settings))
return;
Expand Down Expand Up @@ -1852,14 +1852,14 @@ function cache_put_data($key, $val, $ttl = 120)
else
{
if ($val === null)
@unlink($cachedir . '/keys/' . $key . '.php');
@unlink(CACHE_DIR . '/keys/' . $key . '.php');
else
{
$cache_data = '<' . '?php if(defined(\'WEDGE\')&&$valid=' . ($ttl === PHP_INT_MAX ? '1' : 'time()<' . (time() + $ttl)) . ')$val=\'' . addcslashes($val, '\\\'') . '\';';

// Check that the cache write was successful. If it fails due to low diskspace, remove the cache file.
if (file_put_contents($cachedir . '/keys/' . $key . '.php', $cache_data, LOCK_EX) !== strlen($cache_data))
@unlink($cachedir . '/keys/' . $key . '.php');
if (file_put_contents(CACHE_DIR . '/keys/' . $key . '.php', $cache_data, LOCK_EX) !== strlen($cache_data))
@unlink(CACHE_DIR . '/keys/' . $key . '.php');
}
}

Expand All @@ -1878,8 +1878,7 @@ function cache_put_data($key, $val, $ttl = 120)
*/
function cache_get_data($orig_key, $ttl = 120, $put_callback = null)
{
global $cache_system, $cache_hits, $cache_count;
global $settings, $db_show_debug, $cachedir;
global $cache_system, $cache_hits, $cache_count, $settings, $db_show_debug;

if (empty($settings['cache_enable']) && !empty($settings))
return;
Expand All @@ -1902,11 +1901,11 @@ function cache_get_data($orig_key, $ttl = 120, $put_callback = null)
elseif ($cache_system === 'xcache')
$val = xcache_get($key);
// Otherwise it's the file cache!
elseif (file_exists($cachedir . '/keys/' . $key . '.php') && @filesize($cachedir . '/keys/' . $key . '.php') > 10)
elseif (file_exists(CACHE_DIR . '/keys/' . $key . '.php') && @filesize(CACHE_DIR . '/keys/' . $key . '.php') > 10)
{
@include($cachedir . '/keys/' . $key . '.php');
@include(CACHE_DIR . '/keys/' . $key . '.php');
if (empty($valid))
@unlink($cachedir . '/keys/' . $key . '.php');
@unlink(CACHE_DIR . '/keys/' . $key . '.php');
}

if (!empty($db_show_debug))
Expand All @@ -1928,17 +1927,17 @@ function cache_get_data($orig_key, $ttl = 120, $put_callback = null)

function cache_prepare_key($key, $val = '', $type = 'get')
{
global $boardurl, $settings, $cache_hits, $cache_count, $db_show_debug, $cachedir;
global $boardurl, $settings, $cache_hits, $cache_count, $db_show_debug;

$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
if (!empty($db_show_debug))
$cache_hits[$cache_count] = $type == 'get' ? array('k' => $key, 'd' => 'get') : array('k' => $key, 'd' => 'put', 's' => $val === null ? 0 : strlen(serialize($val)));

if (empty($settings['cache_hash']))
{
if (!file_exists($cachedir . '/cache.lock'))
@fclose(@fopen($cachedir . '/cache.lock', 'w'));
$settings['cache_hash'] = md5($boardurl . filemtime($cachedir . '/cache.lock'));
if (!file_exists(CACHE_DIR . '/cache.lock'))
@fclose(@fopen(CACHE_DIR . '/cache.lock', 'w'));
$settings['cache_hash'] = md5($boardurl . filemtime(CACHE_DIR . '/cache.lock'));
}

return $settings['cache_hash'] . '-' . bin2hex($key);
Expand Down
30 changes: 13 additions & 17 deletions core/app/Subs-Plugins.php
Expand Up @@ -184,7 +184,7 @@ function deleteFiletree(&$class, $dir, $delete_dir = true)
*/
function uploadedPluginValidate()
{
global $context, $txt, $cachedir;
global $context, $txt;

// It's just possible, however unlikely, that the user has done something silly.
if (isset($_SESSION['uploadplugin']))
Expand Down Expand Up @@ -266,7 +266,7 @@ function uploadedPluginValidate()
// What we do need to do, though, is check against plugins that we have currently enabled. (Not enabled... they can fix that themselves from the main listing.)
// And we need to store this and make sure it won't be automatically garbage collected.
$new_file = 'post_plugin_' . MID . '.zip';
if (!move_uploaded_file($_FILES['plugin']['tmp_name'], $cachedir . '/' . $new_file))
if (!move_uploaded_file($_FILES['plugin']['tmp_name'], CACHE_DIR . '/' . $new_file))
fatal_lang_error('plugins_invalid_upload', false);

$id = (string) $manifest['id'];
Expand All @@ -275,8 +275,8 @@ function uploadedPluginValidate()
'file' => $new_file,
'size' => $_FILES['plugin']['size'],
'name' => $_FILES['plugin']['name'],
'mtime' => filemtime($cachedir . '/' . $new_file),
'md5' => md5_file($cachedir . '/' . $new_file),
'mtime' => filemtime(CACHE_DIR . '/' . $new_file),
'md5' => md5_file(CACHE_DIR . '/' . $new_file),
'id' => $id,
'manifest' => $idx[0],
);
Expand All @@ -302,7 +302,7 @@ function uploadedPluginValidate()

function uploadedPluginConnection()
{
global $cachedir, $settings, $context, $txt;
global $settings, $context, $txt;

// If we already have details, pass through to the next stage.
if (isset($_SESSION['plugin_ftp']))
Expand All @@ -321,7 +321,7 @@ function uploadedPluginConnection()
if (isset($_POST['cancel']))
{
// OK, so we're not proceeding with this one, fair enough.
@unlink($cachedir . '/' . $_SESSION['uploadplugin']['file']);
@unlink(CACHE_DIR . '/' . $_SESSION['uploadplugin']['file']);
unset($_SESSION['uploadplugin']);
redirectexit('action=admin;area=plugins');
}
Expand Down Expand Up @@ -547,7 +547,7 @@ function uploadedPluginPrune()

function uploadedPluginFolders()
{
global $context, $txt, $cachedir;
global $context, $txt;

if (!empty($_SESSION['uploadplugin']['folders']))
redirectexit('action=admin;area=plugins;sa=add;upload;stage=4;' . $context['session_query']);
Expand All @@ -567,7 +567,7 @@ function uploadedPluginFolders()
$file_count = 0;
try
{
$zip = new wextr($cachedir . '/' . $_SESSION['uploadplugin']['file']);
$zip = new wextr(CACHE_DIR . '/' . $_SESSION['uploadplugin']['file']);
$list = $zip->list_contents();

if (!empty($_SESSION['uploadplugin']['trunc']))
Expand Down Expand Up @@ -649,7 +649,7 @@ function uploadedPluginFolders()

function uploadedPluginFiles()
{
global $context, $txt, $cachedir;
global $context, $txt;

if (isset($_SESSION['uploadplugin']['flist']) && empty($_SESSION['uploadplugin']['flist']))
{
Expand Down Expand Up @@ -677,7 +677,7 @@ function uploadedPluginFiles()
{
try
{
$zip = new wextr($cachedir . '/' . $_SESSION['uploadplugin']['file']);
$zip = new wextr(CACHE_DIR . '/' . $_SESSION['uploadplugin']['file']);
$list = $zip->list_contents();

$files = array();
Expand Down Expand Up @@ -711,7 +711,7 @@ function uploadedPluginFiles()
try
{
if (!isset($zip))
$zip = new wextr($cachedir . '/' . $_SESSION['uploadplugin']['file']);
$zip = new wextr(CACHE_DIR . '/' . $_SESSION['uploadplugin']['file']);

while (!empty($_SESSION['uploadplugin']['flist']))
{
Expand Down Expand Up @@ -762,12 +762,10 @@ function obfuscate_pass($pass)
*/
function validate_plugin_session()
{
global $cachedir;

if (empty($_SESSION['uploadplugin']) || empty($_SESSION['uploadplugin']['file']))
return 'plugins_unable_read';

$filename = $cachedir . '/' . $_SESSION['uploadplugin']['file'];
$filename = CACHE_DIR . '/' . $_SESSION['uploadplugin']['file'];
if (!file_exists($filename) || filesize($filename) != $_SESSION['uploadplugin']['size'])
return 'plugins_uploaded_error';

Expand Down Expand Up @@ -902,9 +900,7 @@ function test_hooks_conflict($manifest)

function clean_up_plugin_session()
{
global $cachedir;

if (!empty($_SESSION['uploadplugin']['file']))
@unlink($cachedir . '/' . $_SESSION['uploadplugin']['file']);
@unlink(CACHE_DIR . '/' . $_SESSION['uploadplugin']['file']);
unset($_SESSION['uploadplugin'], $_SESSION['plugin_ftp']);
}
10 changes: 7 additions & 3 deletions install/install.php
Expand Up @@ -1857,10 +1857,12 @@ function fixModSecurity()
function init_variables()
{
global $incontext, $txt, $boardurl;
global $boarddir, $context, $settings;
global $context, $settings;

// Load Wedge's default paths and pray that it works...
$boarddir = dirname(__DIR__);
define('ROOT_DIR', str_replace('\\', '/', dirname(__FILE__)));
define('APP_DIR', ROOT_DIR . '/core/app');

// !!! Dunno if we need to load all of these. Better safe than sorry.
loadSource(array('Load', 'Subs-Auth', 'Class-String', 'Class-System', 'QueryString', 'Subs', 'Errors', 'Security'));

Expand All @@ -1872,11 +1874,13 @@ function init_variables()
// Define our constants. (cf. QueryString.php)
define('ROOT', $boardurl);
define('SCRIPT', $boarddir . '/index.php');
define('TEMPLATES', $boardurl . '/core/html'); define('TEMPLATES_DIR', $boarddir . '/core/html');
define('TEMPLATES', ROOT . '/core/html'); define('TEMPLATES_DIR', ROOT_DIR . '/core/html');
define('SKINS', ROOT . '/core/skins'); define('SKINS_DIR', ROOT_DIR . '/core/skins');
define('LANGUAGES', ROOT . '/core/languages'); define('LANGUAGES_DIR', ROOT_DIR . '/core/languages');
define('ASSETS', ROOT . '/assets'); define('ASSETS_DIR', ROOT_DIR . '/assets');
define('CACHE', ROOT . '/gz'); define('CACHE_DIR', ROOT_DIR . '/gz');
define('SMILEYS', ROOT . '/assets/smileys');
define('AVATARS', ROOT . '/assets/avatars');

westr::getInstance();
we::getInstance(false);
Expand Down
6 changes: 2 additions & 4 deletions install/ssi_examples.php
Expand Up @@ -30,7 +30,7 @@

<h2>Include Code</h2>
<p>To use SSI.php in your page add at the very top of your page before the &lt;html&gt; tag on line 1 of your php file:</p>
<div class="bbc_code"><header>Code: <a href="#" onclick="return weSelectText(this);" class="codeoperation">[Select]</a></header><code>&lt;?php require(&quot;<?php echo addslashes(we::$is_admin ? realpath($boarddir . '/SSI.php') : 'SSI.php'); ?>&quot;); ?&gt;</code></div>
<div class="bbc_code"><header>Code: <a href="#" onclick="return weSelectText(this);" class="codeoperation">[Select]</a></header><code>&lt;?php require(&quot;<?php echo addslashes(we::$is_admin ? realpath(ROOT_DIR . '/SSI.php') : 'SSI.php'); ?>&quot;); ?&gt;</code></div>

<h2>Some notes on usage</h2>
<p>All the functions have an output method parameter. This can either be &quot;echo&quot; (the default) or &quot;array&quot;.</p>
Expand Down Expand Up @@ -468,8 +468,6 @@ function template_ssi_below()

function template_homepage_sample1($method = 'source')
{
global $boarddir;

$header = '<!DOCTYPE html>
<html>
<head>
Expand Down Expand Up @@ -516,7 +514,7 @@ function template_homepage_sample1($method = 'source')

if ($method == 'source')
{
$header = '<' . '?php require("' . (we::$is_admin ? addslashes(realpath($boarddir . '/SSI.php')) : 'SSI.php') . '"); ?' . ">\n" . $header;
$header = '<' . '?php require("' . (we::$is_admin ? addslashes(realpath(ROOT_DIR . '/SSI.php')) : 'SSI.php') . '"); ?' . ">\n" . $header;
return $header . template_homepage_sample1_html() . $footer;
}
else
Expand Down

0 comments on commit 36986c1

Please sign in to comment.