diff --git a/core/app/Class-CSS.php b/core/app/Class-CSS.php index a80af649..27ddd001 100644 --- a/core/app/Class-CSS.php +++ b/core/app/Class-CSS.php @@ -708,8 +708,6 @@ class wess_func extends wess { function process(&$css) { - global $boardurl, $boarddir; - if (!preg_match_all('~\b(width|height)\(([^)]+)\)~i', $css, $matches)) return; @@ -721,7 +719,7 @@ function process(&$css) $done[$file] = true; // Get dimensions from file. Try to turn it into absolute path if a URL was given. - list ($width, $height) = @getimagesize(str_replace($boardurl, $boarddir, $file)); + list ($width, $height) = @getimagesize(str_replace(ROOT, ROOT_DIR, $file)); $css = str_replace(array('width(' . $file . ')', 'height(' . $file . ')'), array($width, $height), $css); } } diff --git a/core/app/Load.php b/core/app/Load.php index dfb50d38..0dfb9b85 100644 --- a/core/app/Load.php +++ b/core/app/Load.php @@ -25,7 +25,7 @@ */ function loadSettings() { - global $settings, $context, $pluginsdir, $pluginsurl, $action_list, $action_no_log; + global $settings, $context, $action_list, $action_no_log; // This is where it all began. $context = array( @@ -171,16 +171,15 @@ function loadSettings() { // Step through the list we think we have enabled. $plugins = explode(',', $settings['enabled_plugins']); - $sane_path = str_replace('\\', '/', $pluginsdir); $hook_stack = array(); foreach ($plugins as $plugin) { - if (!empty($settings['plugin_' . $plugin]) && file_exists($sane_path . '/' . $plugin . '/plugin-info.xml')) + if (!empty($settings['plugin_' . $plugin]) && file_exists(ROOT_DIR . '/plugins/' . $plugin . '/plugin-info.xml')) { $plugin_details = @unserialize($settings['plugin_' . $plugin]); $context['enabled_plugins'][$plugin_details['id']] = $plugin; - $context['plugins_dir'][$plugin_details['id']] = $sane_path . '/' . $plugin; - $context['plugins_url'][$plugin_details['id']] = $pluginsurl . '/' . $plugin; + $context['plugins_dir'][$plugin_details['id']] = ROOT_DIR . '/plugins/' . $plugin; + $context['plugins_url'][$plugin_details['id']] = ROOT . '/plugins/' . $plugin; if (isset($plugin_details['actions'])) foreach ($plugin_details['actions'] as $action) { diff --git a/core/app/ManagePlugins.php b/core/app/ManagePlugins.php index d5911599..8f9d85a4 100644 --- a/core/app/ManagePlugins.php +++ b/core/app/ManagePlugins.php @@ -49,7 +49,7 @@ function PluginsHome() function ListPlugins() { - global $txt, $context, $pluginsdir, $maintenance; + global $txt, $context, $maintenance; wetem::load('browse'); $context['page_title'] = $txt['plugin_manager']; @@ -61,143 +61,141 @@ function ListPlugins() // 1. Step through the directory, figure out what's there and what's not, and store everything that's valid in $context['available_plugins']. // Since we explicitly want folders at this point, we don't want to use scandir. - if (!empty($pluginsdir)) + + // !! libxml_use_internal_errors(true); ?? + if ($handle = opendir($plug_dir = ROOT_DIR . '/plugins/')) { - // !! libxml_use_internal_errors(true); ?? - if ($handle = opendir($pluginsdir)) + while (($folder = readdir($handle)) !== false) { - while (($folder = readdir($handle)) !== false) + if ($folder[0] == '.' || strpos($folder, ',') !== false) + continue; + + if (filetype($plug_dir . $folder) == 'dir' && file_exists($plug_dir . $folder . '/plugin-info.xml')) { - if ($folder[0] == '.' || strpos($folder, ',') !== false) + $manifest = safe_sxml_load($plug_dir . $folder . '/plugin-info.xml'); + if ($manifest === false || empty($manifest['id']) || empty($manifest->name) || empty($manifest->author) || empty($manifest->version)) continue; - if (filetype($pluginsdir . '/' . $folder) == 'dir' && file_exists($pluginsdir . '/' . $folder . '/plugin-info.xml')) - { - $manifest = safe_sxml_load($pluginsdir . '/' . $folder . '/plugin-info.xml'); - if ($manifest === false || empty($manifest['id']) || empty($manifest->name) || empty($manifest->author) || empty($manifest->version)) - continue; - - $plugin = array( - 'folder' => $folder, - 'id' => (string) $manifest['id'], - 'name' => westr::htmlspecialchars((string) $manifest->name), - 'author' => westr::htmlspecialchars($manifest->author), - 'author_url' => (string) $manifest->author['url'], - 'author_email' => (string) $manifest->author['email'], - 'website' => (string) $manifest->website, - 'version' => westr::htmlspecialchars($manifest->version), - 'description' => westr::htmlspecialchars($manifest->description), - 'hooks' => array(), - 'provide_hooks' => array(), - 'optional_hooks' => array( - 'function' => array(), - 'language' => array(), - ), - 'readmes' => array(), - 'acp_url' => '', - 'install_errors' => array(), - 'enabled' => false, - 'maint' => array(), - ); + $plugin = array( + 'folder' => $folder, + 'id' => (string) $manifest['id'], + 'name' => westr::htmlspecialchars((string) $manifest->name), + 'author' => westr::htmlspecialchars($manifest->author), + 'author_url' => (string) $manifest->author['url'], + 'author_email' => (string) $manifest->author['email'], + 'website' => (string) $manifest->website, + 'version' => westr::htmlspecialchars($manifest->version), + 'description' => westr::htmlspecialchars($manifest->description), + 'hooks' => array(), + 'provide_hooks' => array(), + 'optional_hooks' => array( + 'function' => array(), + 'language' => array(), + ), + 'readmes' => array(), + 'acp_url' => '', + 'install_errors' => array(), + 'enabled' => false, + 'maint' => array(), + ); - // Use the supplied link if, well, given, but failing that check to see if they used an auto admin page. - if (!empty($manifest->{'acp-url'})) - $plugin['acp_url'] = (string) $manifest->{'acp-url'}; - elseif (!empty($manifest->{'settings-page'}['area'])) - $plugin['acp_url'] = 'action=admin;area=' . (string) $manifest->{'settings-page'}['area']; - - // Do some sanity checking, to validate that any given URL or email are at least vaguely legal. - if (empty($plugin['author_url']) || (strpos($plugin['author_url'], 'http://') !== 0 && strpos($plugin['author_url'], 'https://') !== 0)) - $plugin['author_url'] = ''; - if (empty($plugin['website']) || (strpos($plugin['website'], 'http://') !== 0 && strpos($plugin['website'], 'https://') !== 0)) - $plugin['website'] = ''; - if (empty($plugin['author_email']) || !is_valid_email($plugin['author_email'])) - $plugin['author_email'] = ''; - - // Test minimum versions of things. - if (!empty($manifest->{'min-versions'})) - { - $min_versions = testRequiredVersions($manifest->{'min-versions'}); - foreach (array('php', 'mysql') as $test) - if (isset($min_versions[$test])) - $plugin['install_errors']['min' . $test] = sprintf($txt['install_error_min' . $test], $min_versions[$test][0], $min_versions[$test][1]); - } + // Use the supplied link if, well, given, but failing that check to see if they used an auto admin page. + if (!empty($manifest->{'acp-url'})) + $plugin['acp_url'] = (string) $manifest->{'acp-url'}; + elseif (!empty($manifest->{'settings-page'}['area'])) + $plugin['acp_url'] = 'action=admin;area=' . (string) $manifest->{'settings-page'}['area']; + + // Do some sanity checking, to validate that any given URL or email are at least vaguely legal. + if (empty($plugin['author_url']) || (strpos($plugin['author_url'], 'http://') !== 0 && strpos($plugin['author_url'], 'https://') !== 0)) + $plugin['author_url'] = ''; + if (empty($plugin['website']) || (strpos($plugin['website'], 'http://') !== 0 && strpos($plugin['website'], 'https://') !== 0)) + $plugin['website'] = ''; + if (empty($plugin['author_email']) || !is_valid_email($plugin['author_email'])) + $plugin['author_email'] = ''; + + // Test minimum versions of things. + if (!empty($manifest->{'min-versions'})) + { + $min_versions = testRequiredVersions($manifest->{'min-versions'}); + foreach (array('php', 'mysql') as $test) + if (isset($min_versions[$test])) + $plugin['install_errors']['min' . $test] = sprintf($txt['install_error_min' . $test], $min_versions[$test][0], $min_versions[$test][1]); + } - // Required functions? - if (!empty($manifest->{'required-functions'})) - { - $required_functions = testRequiredFunctions($manifest->{'required-functions'}); - if (!empty($required_functions)) - $plugin['install_errors']['reqfunc'] = sprintf($txt['install_error_reqfunc'], implode(', ', $required_functions)); - } + // Required functions? + if (!empty($manifest->{'required-functions'})) + { + $required_functions = testRequiredFunctions($manifest->{'required-functions'}); + if (!empty($required_functions)) + $plugin['install_errors']['reqfunc'] = sprintf($txt['install_error_reqfunc'], implode(', ', $required_functions)); + } - // Hooks associated with this plugin. - if (!empty($manifest->hooks)) + // Hooks associated with this plugin. + if (!empty($manifest->hooks)) + { + $hooks_listed = $manifest->hooks->children(); + foreach ($hooks_listed as $each_hook) { - $hooks_listed = $manifest->hooks->children(); - foreach ($hooks_listed as $each_hook) + switch ($each_hook->getName()) { - switch ($each_hook->getName()) - { - case 'function': - if (!empty($each_hook['point'])) - $plugin['hooks']['function'][] = $each_hook['point']; - if (!empty($each_hook['optional']) && $each_hook['optional'] == 'yes') - $plugin['optional_hooks']['function'][] = $each_hook['point']; - break; - case 'language': - if (!empty($each_hook['point'])) - $plugin['hooks']['language'][] = $each_hook['point']; - if (!empty($each_hook['optional']) && $each_hook['optional'] == 'yes') - $plugin['optional_hooks']['language'][] = $each_hook['point']; - break; - case 'provides': - $provided_hooks = $each_hook->children(); - - foreach ($provided_hooks as $hook) - if (!empty($hook['type']) && ((string) $hook['type'] == 'function' || (string) $hook['type'] == 'language')) - { - // Only deal with hooks provided by a plugin if it's enabled. - if (in_array($folder, $context['enabled_plugins'])) - $hooks[(string) $hook['type']][] = (string) $hook; - - if (empty($plugin['provide_hooks'][(string) $hook['type']])) - $plugin['provide_hooks'][(string) $hook['type']] = array(); - $plugin['provide_hooks'][(string) $hook['type']][] = (string) $hook; - } - break; - } + case 'function': + if (!empty($each_hook['point'])) + $plugin['hooks']['function'][] = $each_hook['point']; + if (!empty($each_hook['optional']) && $each_hook['optional'] == 'yes') + $plugin['optional_hooks']['function'][] = $each_hook['point']; + break; + case 'language': + if (!empty($each_hook['point'])) + $plugin['hooks']['language'][] = $each_hook['point']; + if (!empty($each_hook['optional']) && $each_hook['optional'] == 'yes') + $plugin['optional_hooks']['language'][] = $each_hook['point']; + break; + case 'provides': + $provided_hooks = $each_hook->children(); + + foreach ($provided_hooks as $hook) + if (!empty($hook['type']) && ((string) $hook['type'] == 'function' || (string) $hook['type'] == 'language')) + { + // Only deal with hooks provided by a plugin if it's enabled. + if (in_array($folder, $context['enabled_plugins'])) + $hooks[(string) $hook['type']][] = (string) $hook; + + if (empty($plugin['provide_hooks'][(string) $hook['type']])) + $plugin['provide_hooks'][(string) $hook['type']] = array(); + $plugin['provide_hooks'][(string) $hook['type']][] = (string) $hook; + } + break; } } + } - // Readme files. $context['languages'] contains all the languages we have - no sense offering readmes we don't have installed languages for. - if (!empty($manifest->readmes)) + // Readme files. $context['languages'] contains all the languages we have - no sense offering readmes we don't have installed languages for. + if (!empty($manifest->readmes)) + { + foreach ($manifest->readmes->readme as $readme) { - foreach ($manifest->readmes->readme as $readme) - { - $lang = (string) $readme['lang']; - if (!empty($lang) && isset($context['languages'][$lang])) - $plugin['readmes'][$lang] = true; - } + $lang = (string) $readme['lang']; + if (!empty($lang) && isset($context['languages'][$lang])) + $plugin['readmes'][$lang] = true; + } - // We'll put them in alphabetic order, but English first because that's guaranteed to be available as an installed language. - ksort($plugin['readmes']); - if (isset($plugin['readmes']['english'])) - { - unset($plugin['readmes']['english']); - $plugin['readmes'] = array_merge(array('english' => true), $plugin['readmes']); - } + // We'll put them in alphabetic order, but English first because that's guaranteed to be available as an installed language. + ksort($plugin['readmes']); + if (isset($plugin['readmes']['english'])) + { + unset($plugin['readmes']['english']); + $plugin['readmes'] = array_merge(array('english' => true), $plugin['readmes']); } + } - // Is there anything it has to do in maintenance mode? - $plugin['maint'] = get_maint_requirements($manifest); + // Is there anything it has to do in maintenance mode? + $plugin['maint'] = get_maint_requirements($manifest); - // OK, add to the list. - $context['available_plugins'][strtolower($plugin['name'] . $folder)] = $plugin; - } + // OK, add to the list. + $context['available_plugins'][strtolower($plugin['name'] . $folder)] = $plugin; } - closedir($handle); } + closedir($handle); } // 1a. We want the packages in a nice order. The array key is the name of the plugin, then with the folder appended in the case of duplicates. @@ -293,7 +291,7 @@ function ListPlugins() function PluginReadme() { - global $context, $txt, $pluginsdir; + global $context, $txt; // Let's start and fire up the template. We're reusing the nice popup, so load templates and set up various things. loadTemplate('GenericPopup'); @@ -318,7 +316,7 @@ function PluginReadme() // Lastly, does the package know this readme? if ($valid) { - $manifest = safe_sxml_load($pluginsdir . '/' . $_GET['plugin'] . '/plugin-info.xml'); + $manifest = safe_sxml_load(ROOT_DIR . '/plugins/' . $_GET['plugin'] . '/plugin-info.xml'); if (!empty($manifest->readmes)) { @@ -343,7 +341,7 @@ function PluginReadme() // So, the readme is valid. Read it, it's probably bbcode, so preparse and parse it. if ($valid) { - $path = strtr($readme, array('$plugindir' => $pluginsdir . '/' . $_GET['plugin'])); + $path = strtr($readme, array('$plugindir' => ROOT_DIR . '/plugins/' . $_GET['plugin'])); $contents = file_get_contents($path); loadSource('Class-Editor'); @@ -370,7 +368,7 @@ function PluginReadme() function EnablePlugin() { - global $context, $pluginsdir, $settings, $maintenance; + global $context, $settings, $maintenance; checkSession('request'); @@ -378,7 +376,7 @@ function EnablePlugin() if (!isViablePlugin()) fatal_lang_error('fatal_not_valid_plugin', false); - $manifest = safe_sxml_load($pluginsdir . '/' . $_GET['plugin'] . '/plugin-info.xml'); + $manifest = safe_sxml_load(ROOT_DIR . '/plugins/' . $_GET['plugin'] . '/plugin-info.xml'); if ($manifest === false || empty($manifest['id']) || empty($manifest->name) || empty($manifest->author) || empty($manifest->version)) fatal_lang_error('fatal_not_valid_plugin', false); @@ -1089,7 +1087,7 @@ function EnablePlugin() function DisablePlugin($manifest = null, $plugin = null) { - global $context, $pluginsdir, $settings; + global $context, $settings; // We might be coming from the user's request or a separate process. If from elsewhere, we don't need to do all the checks. if (empty($manifest) || empty($plugin)) @@ -1100,7 +1098,7 @@ function DisablePlugin($manifest = null, $plugin = null) if (!isViablePlugin()) fatal_lang_error('fatal_not_valid_plugin', false); - $manifest = safe_sxml_load($pluginsdir . '/' . $_GET['plugin'] . '/plugin-info.xml'); + $manifest = safe_sxml_load(ROOT_DIR . '/plugins/' . $_GET['plugin'] . '/plugin-info.xml'); if ($manifest === false || empty($manifest['id']) || empty($manifest->name) || empty($manifest->author) || empty($manifest->version)) fatal_lang_error('fatal_not_valid_plugin', false); @@ -1200,13 +1198,13 @@ function DisablePlugin($manifest = null, $plugin = null) function RemovePlugin() { - global $txt, $context, $pluginsdir, $maintenance; + global $txt, $context, $maintenance; // !! libxml_use_internal_errors(true); ?? if (!isViablePlugin()) fatal_lang_error('fatal_not_valid_plugin', false); - $manifest = safe_sxml_load($pluginsdir . '/' . $_GET['plugin'] . '/plugin-info.xml'); + $manifest = safe_sxml_load(ROOT_DIR . '/plugins/' . $_GET['plugin'] . '/plugin-info.xml'); if ($manifest === false || empty($manifest->name) || empty($manifest->version)) fatal_lang_error('fatal_not_valid_plugin_remove', false); @@ -1255,7 +1253,7 @@ function RemovePlugin() // Check that the entire tree is deletable. $all_writable = true; - $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($pluginsdir . '/' . $_GET['plugin']), RecursiveIteratorIterator::SELF_FIRST); + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(ROOT_DIR . '/plugins/' . $_GET['plugin']), RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $path) if (!$path->isWritable()) { @@ -1286,8 +1284,6 @@ function RemovePlugin() // This ugly function deals with actually removing a plugin. function commitRemovePlugin($fullclean, &$manifest, &$remote_class) { - global $pluginsdir; - // So, as far as we know, it's valid to remove, because RemovePlugin() should have checked all this for us, even writability. // Database changes: remove/remove-clean script @@ -1422,7 +1418,7 @@ function commitRemovePlugin($fullclean, &$manifest, &$remote_class) updateSettings(array('settings_updated' => time())); // Lastly, actually do the delete. - $result = deleteFiletree($remote_class, $pluginsdir . '/' . $_GET['plugin'], true); + $result = deleteFiletree($remote_class, ROOT_DIR . '/plugins/' . $_GET['plugin'], true); if (empty($result)) fatal_lang_error('remove_plugin_files_still_there', false, $_GET['plugin']); else @@ -1432,11 +1428,9 @@ function commitRemovePlugin($fullclean, &$manifest, &$remote_class) // Handles running any change-state scripts, e.g. on-enable. The type is primarily for the error message if the file couldn't be found. function executePluginScript($type, $file) { - global $pluginsdir; - if (!empty($file)) { - $full_path = strtr($file, array('$plugindir' => $pluginsdir . '/' . $_GET['plugin'])); + $full_path = strtr($file, array('$plugindir' => ROOT_DIR . '/plugins/' . $_GET['plugin'])); 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)); @@ -1449,9 +1443,11 @@ function executePluginScript($type, $file) // Identify whether the plugin requested is a viable plugin or not. function isViablePlugin() { - global $pluginsdir; - - return (!empty($_GET['plugin']) && strpos($_GET['plugin'], DIRECTORY_SEPARATOR) === false && $_GET['plugin'][0] != '.' && filetype($pluginsdir . '/' . $_GET['plugin']) == 'dir' && file_exists($pluginsdir . '/' . $_GET['plugin'] . '/plugin-info.xml')); + return !empty($_GET['plugin']) + && strpos($_GET['plugin'], DIRECTORY_SEPARATOR) === false + && $_GET['plugin'][0] != '.' + && filetype(ROOT_DIR . '/plugins/' . $_GET['plugin']) == 'dir' + && file_exists(ROOT_DIR . '/plugins/' . $_GET['plugin'] . '/plugin-info.xml'); } // This is a routing agent to the relevant aspect of adding plugins to the system. diff --git a/core/app/ManageSettings.php b/core/app/ManageSettings.php index f16bed9e..3834b51f 100644 --- a/core/app/ManageSettings.php +++ b/core/app/ManageSettings.php @@ -171,11 +171,6 @@ function ModifyPathSettings($return_config = false) $config_vars = array( array('text', 'boardurl', 36, 'file' => true), - array('text', 'boarddir', 36, 'file' => true), - array('text', 'sourcedir', 36, 'file' => true), - array('text', 'cachedir', 36, 'file' => true), - array('text', 'pluginsdir', 36, 'file' => true), - array('text', 'pluginsurl', 36, 'file' => true), '', array('text', 'theme_url', 36), array('text', 'theme_dir', 36), diff --git a/core/app/OriginalFiles.php b/core/app/OriginalFiles.php index 700da982..fb67d714 100644 --- a/core/app/OriginalFiles.php +++ b/core/app/OriginalFiles.php @@ -11,13 +11,8 @@ if (!defined('WEDGE')) die('Hacking attempt...'); -function create_settings_file($root_dir = '') +function create_settings_file() { - global $boarddir; - - if (empty($boarddir)) - $boarddir = $root_dir; - $file = '<' . '?php /** * Contains the master settings for Wedge, including database credentials. @@ -55,20 +50,11 @@ function create_settings_file($root_dir = '') $db_error_send = 1; $db_show_debug = false; $db_last_error = 0; - -# Paths and folders -$boarddir = dirname(__FILE__); # The absolute path to the forum folder. -$sourcedir = $boarddir . \'/core/app\'; # Path to the sources directory. -$cachedir = $boarddir . \'/gz\'; # Path to the cache directory. -$cssdir = $boarddir . \'/gz/css\'; # Path to the CSS cache directory. -$jsdir = $boarddir . \'/gz/js\'; # Path to the JS cache directory. -$pluginsdir = $boarddir . \'/plugins\'; # Path to the plugins directory. -$pluginsurl = $boardurl . \'/plugins\'; # URL to plugins. '; foreach (array('/Settings_bak.php', '/Settings.php') as $target) - if (!file_exists($boarddir . $target)) - file_put_contents($boarddir . $target, $file . "\n?" . '>'); + if (!file_exists(ROOT_DIR . $target)) + file_put_contents(ROOT_DIR . $target, $file . "\n?" . '>'); } function create_generic_folders($root_dir = '') diff --git a/core/app/QueryString.php b/core/app/QueryString.php index 6619fe92..4f8e2f7e 100644 --- a/core/app/QueryString.php +++ b/core/app/QueryString.php @@ -17,7 +17,6 @@ function loadPaths() { global $boardurl, $boarddir, $settings, $context; - global $sourcedir, $pluginsdir, $cachedir, $cssdir, $jsdir; // $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.) @@ -81,11 +80,9 @@ function loadPaths() define('SCRIPT', $scripturl); define('ROOT', $boardurl); define('ROOT_DIR', $boarddir); - define('CORE', ROOT . '/core'); define('CORE_DIR', ROOT_DIR . '/core'); 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('PLUGINS', ROOT . '/plugins'); define('PLUGINS_DIR', ROOT_DIR . '/plugins'); define('ASSETS', ROOT . '/assets'); define('ASSETS_DIR', ROOT_DIR . '/assets'); define('SMILEYS', ROOT . '/assets/smileys'); define('AVATARS', ROOT . '/assets/avatars'); diff --git a/core/app/Subs-Admin.php b/core/app/Subs-Admin.php index f17a4ce4..dc3a08d9 100644 --- a/core/app/Subs-Admin.php +++ b/core/app/Subs-Admin.php @@ -285,7 +285,7 @@ function updateSettingsFile($config_vars) $temp = trim(implode("\n", $settingsArray)); if (substr($temp, 0, 5) != '') return; - if (strpos($temp, 'sourcedir') === false || strpos($temp, 'boarddir') === false || strpos($temp, 'cookiename') === false) + if (strpos($temp, 'boardurl') === false || strpos($temp, 'cookiename') === false) return; } diff --git a/core/app/Subs-Plugins.php b/core/app/Subs-Plugins.php index 4f1ff8a7..d3377973 100644 --- a/core/app/Subs-Plugins.php +++ b/core/app/Subs-Plugins.php @@ -12,11 +12,11 @@ function getWritableObject() { - global $pluginsdir, $context, $settings, $boarddir; + global $context, $settings, $boarddir; // 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..? - $path = $pluginsdir; + $path = ROOT_DIR . '/plugins'; // Easy case, it's directly writable. if (is_writable($path)) @@ -302,7 +302,7 @@ function uploadedPluginValidate() function uploadedPluginConnection() { - global $cachedir, $settings, $context, $pluginsdir, $txt; + global $cachedir, $settings, $context, $txt; // If we already have details, pass through to the next stage. if (isset($_SESSION['plugin_ftp'])) @@ -335,7 +335,7 @@ function uploadedPluginConnection() 'password' => '', 'port' => '21', 'type' => 'ftp', - 'path' => realpath($pluginsdir), + 'path' => realpath(ROOT_DIR . '/plugins'), ); if (!empty($settings['ftp_settings'])) @@ -547,7 +547,7 @@ function uploadedPluginPrune() function uploadedPluginFolders() { - global $context, $txt, $cachedir, $pluginsdir; + global $context, $txt, $cachedir; if (!empty($_SESSION['uploadplugin']['folders'])) redirectexit('action=admin;area=plugins;sa=add;upload;stage=4;' . $context['session_query']); @@ -607,10 +607,10 @@ function uploadedPluginFolders() $filename = 'plugin'; // Having come up with a hopefully sane name, were there any duplicates? - if (is_dir($pluginsdir . '/' . $filename)) + if (is_dir(ROOT_DIR . '/plugins/' . $filename)) { $count = 1; - while (is_dir($pluginsdir . '/' . $filename . '_' . $count)) + while (is_dir(ROOT_DIR . '/plugins/' . $filename . '_' . $count)) $count++; $filename .= '_' . $count; @@ -850,7 +850,7 @@ function get_maint_requirements($manifest) function test_hooks_conflict($manifest) { - global $pluginsdir, $settings; + global $settings; // This could be interesting, actually. Does this plugin declare any hooks that any other active plugin uses? if (!empty($manifest->hooks->provides)) @@ -864,6 +864,7 @@ function test_hooks_conflict($manifest) $hooks_provided[$hook_name] = true; } + $plug_dir = ROOT_DIR . '/plugins/'; $conflicted_plugins = array(); // So now we know what hooks this plugin offers. Now let's see what other plugins use this. if (!empty($hooks_provided)) @@ -871,12 +872,12 @@ function test_hooks_conflict($manifest) $plugins = explode(',', $settings['enabled_plugins']); foreach ($plugins as $plugin) { - if ($plugin == $_GET['plugin'] || !file_exists($pluginsdir . '/' . $plugin . '/plugin-info.xml')) + if ($plugin == $_GET['plugin'] || !file_exists($plug_dir . $plugin . '/plugin-info.xml')) continue; // Now, we have to go and get the XML manifest for these plugins, because we have to be able to differentiate // optional from required hooks, and we can't do that with what's in context, only the actual manifest. - $other_manifest = safe_sxml_load($pluginsdir . '/' . $plugin . '/plugin-info.xml'); + $other_manifest = safe_sxml_load($plug_dir . $plugin . '/plugin-info.xml'); $hooks = $other_manifest->hooks->children(); foreach ($hooks as $hook) { diff --git a/core/app/Subs-Template.php b/core/app/Subs-Template.php index ce68797d..ce94be49 100644 --- a/core/app/Subs-Template.php +++ b/core/app/Subs-Template.php @@ -1087,7 +1087,7 @@ function db_debug_junk() */ function template_include($filename, $once = false) { - global $context, $txt, $settings, $boarddir, $boardurl; + global $context, $txt, $settings, $boardurl; global $maintenance, $mtitle, $mmessage; static $templates = array(); @@ -1165,7 +1165,7 @@ function template_include($filename, $once = false) else { loadSource('Class-WebGet'); - $weget = new weget($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); + $weget = new weget(str_replace(ROOT_DIR, $boardurl, $filename)); $error = $weget->get(); if (empty($error)) @@ -1178,12 +1178,12 @@ function template_include($filename, $once = false)

', $txt['template_parse_error'], '

- ', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); + ', sprintf($txt['template_parse_error_details'], str_replace(ROOT_DIR, '', $filename)); if (!empty($error)) echo '
-
', strtr(strtr($error, array('' . $boarddir => '...', '' . strtr($boarddir, '\\', '/') => '...')), '\\', '/'), '
'; +
', str_replace('' . ROOT_DIR, '...', $error), '
'; // Yes, this is VERY complicated... Still, it's good. if (preg_match('~ (\d+)$~i', $error, $match) != 0) @@ -1306,9 +1306,9 @@ function loadTemplate($template_name, $fatal = true) } // Hmmm... doesn't exist?! I don't suppose the directory is wrong, is it? // !! @todo: remove this..? - elseif (!file_exists(TEMPLATES_DIR) && file_exists(CORE_DIR . '/html')) + elseif (!file_exists(TEMPLATES_DIR) && file_exists(ROOT_DIR . '/core/html')) { - $context['template_folders'][] = $settings['theme_dir'] = CORE_DIR . '/html'; + $context['template_folders'][] = $settings['theme_dir'] = ROOT_DIR . '/core/html'; if (we::$is_admin) { diff --git a/core/languages/ManageSettings.english.php b/core/languages/ManageSettings.english.php index 200e2a07..b4835923 100644 --- a/core/languages/ManageSettings.english.php +++ b/core/languages/ManageSettings.english.php @@ -116,11 +116,6 @@ $txt['likes_own_posts'] = 'Users can like their own posts'; $txt['boardurl'] = 'Forum URL'; -$txt['boarddir'] = 'Path to Wedge folder'; -$txt['sourcedir'] = 'Path to app folder'; -$txt['cachedir'] = 'Path to cache folder'; -$txt['pluginsdir'] = 'Path to plugins folder'; -$txt['pluginsurl'] = 'URL to plugins folder'; $txt['theme_dir'] = 'Path to HTML templates'; $txt['theme_url'] = 'URL to HTML templates'; $txt['images_url'] = 'URL to assets folder'; diff --git a/index.php b/index.php index 238bbf79..b8bd1cf1 100644 --- a/index.php +++ b/index.php @@ -15,7 +15,7 @@ define('WEDGE', 2); // Internal snapshot number. // Get everything started up... -if (function_exists('set_magic_quotes_runtime') && version_compare(PHP_VERSION, '5.4') < 0) +if (version_compare(PHP_VERSION, '5.4') < 0 && function_exists('set_magic_quotes_runtime')) @set_magic_quotes_runtime(0); error_reporting(E_ALL | E_STRICT); @@ -24,29 +24,22 @@ // Makes sure that headers can be sent! ob_start(); +define('ROOT_DIR', str_replace('\\', '/', dirname(__FILE__))); + // Is it our first run..? -$here = dirname(__FILE__); -if (!file_exists($here . '/Settings.php')) +if (!file_exists(ROOT_DIR . '/Settings.php')) { - require_once($here . '/core/app/OriginalFiles.php'); - create_settings_file($here); - create_generic_folders($here); + require_once(ROOT_DIR . '/core/app/OriginalFiles.php'); + create_settings_file(ROOT_DIR); + create_generic_folders(ROOT_DIR); } // Load the settings... -require_once($here . '/Settings.php'); - -// Make sure the paths are correct... at least try to fix them. -if (!file_exists($boarddir = rtrim($boarddir, '/')) && file_exists(dirname(__FILE__) . '/SSI.php')) - $boarddir = dirname(__FILE__); +require_once(ROOT_DIR . '/Settings.php'); -foreach (array('source' => 'core/app', 'plugins' => 'plugins', 'cache' => 'gz', 'css' => 'gz/css', 'js' => 'gz/js') as $var => $path) -{ - $dir = $var . 'dir'; - if ((empty($$dir) || ($$dir !== $boarddir . '/' . $path && !file_exists($$dir))) && file_exists($boarddir . '/' . $path)) - $$dir = $boarddir . '/' . $path; - if (!file_exists($$dir)) - exit('Missing folder: $' . $dir . ' (' . $$dir . ')'); -} +// Crucial paths. +$boarddir = ROOT_DIR; +foreach (array('source' => 'core/app', 'cache' => 'gz', 'css' => 'gz/css', 'js' => 'gz/js') as $var => $path) + ${$var . 'dir'} = ROOT_DIR . '/' . $path; // And important files. loadSource(array( @@ -62,7 +55,7 @@ if (!empty($maintenance) && $maintenance > 1) { if ($maintenance == 2) // Installing - require_once(__DIR__ . '/install/install.php'); + require_once(ROOT_DIR . '/install/install.php'); else // Downtime show_db_error(); return; @@ -104,6 +97,7 @@ we::getInstance(); // Get rid of ?PHPSESSID for robots. +// !! Probably useless, thanks to canonical URLs. if (we::$user['possibly_robot'] && strpos(we::$user['url'], 'PHPSESSID=') !== false) { $correcturl = preg_replace('~([?&]PHPSESSID=[^&]*)~', '', we::$user['url']); diff --git a/install/install.php b/install/install.php index 7e400ad5..b3cc6e27 100644 --- a/install/install.php +++ b/install/install.php @@ -824,11 +824,6 @@ function ForumSettings() // Save these variables. $vars = array( 'boardurl' => $_POST['boardurl'], - 'boarddir' => addslashes(ROOT_DIR), - 'sourcedir' => addslashes(ROOT_DIR) . '/core/app', - 'cachedir' => addslashes(ROOT_DIR) . '/gz', - 'pluginsdir' => addslashes(ROOT_DIR) . '/plugins', - 'pluginsurl' => $_POST['boardurl'] . '/plugins', 'mbname' => strtr($_POST['mbname'], array('\"' => '"')), ); @@ -1883,16 +1878,14 @@ function init_variables() // Define our constants. (cf. QueryString.php) define('SCRIPT', $boarddir . '/index.php'); define('ROOT', $boardurl); - define('CORE', $boardurl . '/core'); - define('CORE_DIR', $boarddir . '/core'); define('TEMPLATES', $settings['theme_url']); define('TEMPLATES_DIR', $settings['theme_dir']); - define('SKINS', CORE . '/skins'); - define('SKINS_DIR', CORE_DIR . '/skins'); - define('LANGUAGES', CORE . '/languages'); - define('LANGUAGES_DIR', CORE_DIR . '/languages'); - define('ASSETS', ROOT . '/assets'); - define('ASSETS_DIR', ROOT_DIR . '/assets'); + 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'); westr::getInstance(); we::getInstance(false);