Skip to content

Commit

Permalink
* Renamed $context['protocol'] to PROTOCOL. (Class-System.php, Credit…
Browse files Browse the repository at this point in the history
…s.php, ManageServer.php, PrettyUrls-Filters.php, QueryString.php)

* Renamed hidden variable $settings['forum_alias_urls'] to $aliases, which can be set in Settings.php, of course. (QueryString.php, Subs-Auth.php)

* Renamed $settings['pretty_remove_index'] to $remove_index. (ManageSettings.php, OriginalFiles.php, QueryString.php)

* Renamed loadPaths to loadConstants, because it now initializes other constants, such as PROTOCOL and AJAX. (index.php, SSI.php, QueryString.php)

+ Added German to the list of detected languages for the installer. (install.php)

@ Constant problems in the installer (and potentially, upgrader) should now be fixed, thanks to loadConstants() being callable *before* database settings are loaded.

@ I think I'm done with constants, at least for now... :)
  • Loading branch information
Nao committed Mar 25, 2014
1 parent 61f16c8 commit c38bfa9
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 53 deletions.
3 changes: 2 additions & 1 deletion SSI.php
Expand Up @@ -32,7 +32,7 @@
define('ROOT_DIR', str_replace('\\', '/', dirname(__FILE__)));
define('APP_DIR', ROOT_DIR . '/core/app');

// Get the forum's settings for database and file paths.
// Get the forum's settings and loadSource() definition.
require_once(dirname(__FILE__) . '/Settings.php');
require_once(dirname(__FILE__) . '/index.php');

Expand Down Expand Up @@ -61,6 +61,7 @@
));

// Initiate the database connection and load $settings data.
loadConstants();
loadDatabase();
loadSettings();

Expand Down
2 changes: 1 addition & 1 deletion core/app/Class-System.php
Expand Up @@ -436,7 +436,7 @@ protected static function init_user()
// Fill in the server URL for the current user. This is user-specific, as they may be using a different URL than the script's default URL (Pretty URL, secure access...)
// Note that HTTP_X_FORWARDED_SERVER is mostly used by proxy servers. If the client doesn't provide anything, it's probably a bot.
$user['host'] = empty($_SERVER['REAL_HTTP_HOST']) ? (empty($_SERVER['HTTP_HOST']) ? (empty($_SERVER['HTTP_X_FORWARDED_SERVER']) ? substr(strrchr(ROOT, ':'), 3) : $_SERVER['HTTP_X_FORWARDED_SERVER']) : $_SERVER['HTTP_HOST']) : $_SERVER['REAL_HTTP_HOST'];
$user['server'] = $context['protocol'] . $user['host'];
$user['server'] = PROTOCOL . $user['host'];

// The URL in your address bar. Also contains the query string.
// Do not print this without sanitizing first!
Expand Down
2 changes: 1 addition & 1 deletion core/app/Credits.php
Expand Up @@ -55,7 +55,7 @@ function Credits()
array(
'title' => $txt['credits_groups_dev'],
'members' => array(
'<img src="' . $context['protocol'] . ($context['protocol'] == 'https://' ? 'secure.' : '') . 'gravatar.com/avatar/0879c588019800e5349fe171d69e1c28" class="opaque left" style="margin: 8px 20px 8px -24px"><br><br>Ren&eacute;-Gilles Deberdt<br>(Nao &#23578;)<br class="clear">',
'<img src="' . PROTOCOL . (PROTOCOL == 'https://' ? 'secure.' : '') . 'gravatar.com/avatar/0879c588019800e5349fe171d69e1c28" class="opaque left" style="margin: 8px 20px 8px -24px"><br><br>Ren&eacute;-Gilles Deberdt<br>(Nao &#23578;)<br class="clear">',
),
),
array(
Expand Down
8 changes: 0 additions & 8 deletions core/app/Load.php
Expand Up @@ -35,11 +35,6 @@ function loadSettings()
'app_error_count' => 0,
);

// Is this a page requested through jQuery? If yes, set the AJAX constant so we can choose to show only the template's default block.
$ajax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
define('INFINITE', $ajax && !empty($_POST['infinite']));
define('AJAX', $ajax && !INFINITE);

// Try to load settings from the cache first; they'll never get cached if the setting is off.
if (($settings = cache_get_data('settings', 'forever')) === null)
{
Expand Down Expand Up @@ -162,9 +157,6 @@ function loadSettings()
// If an action should not influence the who's online list, please add it to the $action_no_log global from your own action.
$action_no_log = array('ajax', 'dlattach', 'feed', 'like', 'notification', 'verification', 'viewquery', 'viewremote');

// Set up path constants.
loadPaths();

// Deal with loading plugins.
$context['enabled_plugins'] = array();
if (!empty($settings['enabled_plugins']))
Expand Down
2 changes: 1 addition & 1 deletion core/app/ManageServer.php
Expand Up @@ -331,7 +331,7 @@ function ModifyCookieSettings($return_config = false)
array('int', 'cookieTime'),
array('check', 'localCookies', 'subtext' => $txt['localCookies_subtext']),
array('check', 'globalCookies', 'subtext' => $txt['globalCookies_subtext']),
array('check', 'secureCookies', 'disabled' => $context['protocol'] != 'https://', 'subtext' => $txt['secureCookies_subtext']),
array('check', 'secureCookies', 'disabled' => PROTOCOL != 'https://', 'subtext' => $txt['secureCookies_subtext']),
'',
// Sessions
array('check', 'databaseSession_enable'),
Expand Down
6 changes: 3 additions & 3 deletions core/app/ManageSettings.php
Expand Up @@ -494,7 +494,7 @@ function ModifyPmSettings($return_config = false)
// Shell for all the Pretty URL interfaces
function ModifyPrettyURLs($return_config = false)
{
global $context, $settings, $txt;
global $context, $settings, $txt, $remove_index;

// For the administrative search function not to get upset.
if ($return_config)
Expand Down Expand Up @@ -542,12 +542,12 @@ function ModifyPrettyURLs($return_config = false)
array(
'pretty_enable_filters' => $is_enabled,
'pretty_enable_cache' => isset($_POST['pretty_cache']) ? ($_POST['pretty_cache'] == 'on' ? 'on' : '') : '',
'pretty_remove_index' => isset($_POST['pretty_remove_index']) ? ($_POST['pretty_remove_index'] == 'on' ? 'on' : '') : '',
'pretty_filters' => serialize($settings['pretty_filters']),
'pretty_prefix_action' => $action,
'pretty_prefix_profile' => $profile,
)
);
updateSettingsFile(array('remove_index' => isset($_POST['pretty_remove_index']) ? ($_POST['pretty_remove_index'] == 'on' ? 1 : 0) : 1));
$settings['pretty_filters'] = unserialize($settings['pretty_filters']);

if (isset($_REQUEST['pretty_cache']))
Expand All @@ -565,7 +565,7 @@ function ModifyPrettyURLs($return_config = false)

$context['pretty']['settings'] = array(
'cache' => !empty($settings['pretty_enable_cache']) ? $settings['pretty_enable_cache'] : 0,
'index' => !empty($settings['pretty_remove_index']) ? $settings['pretty_remove_index'] : 0,
'index' => !empty($remove_index) ? $remove_index : 0,
);
}

Expand Down
1 change: 1 addition & 0 deletions core/app/OriginalFiles.php
Expand Up @@ -36,6 +36,7 @@ function create_settings_file()
$webmaster_email = \'noreply@myserver.com\';
$cookiename = \'WedgeCookie01\';
$cache_type = \'file\';
$remove_index = 0;
$we_shot = ' . WEDGE . ';
# MySQL server
Expand Down
10 changes: 4 additions & 6 deletions core/app/PrettyUrls-Filters.php
Expand Up @@ -112,7 +112,7 @@ function pretty_filter_actions(&$urls)
*/
function pretty_filter_topics(&$urls)
{
global $settings, $context;
global $settings;

$pattern = '~(?<=[?;&])topic=(\d+)(?:\.([a-zA-Z0-9$%]+))?~';
$query_data = array();
Expand Down Expand Up @@ -148,7 +148,7 @@ function pretty_filter_topics(&$urls)
{
if (isset($row['pretty_url']))
$topicData[$row['id_topic']] = array(
'pretty_board' => !empty($row['url']) ? $context['protocol'] . $row['url'] : ROOT,
'pretty_board' => !empty($row['url']) ? PROTOCOL . $row['url'] : ROOT,
'pretty_url' => $row['pretty_url'],
);
else
Expand Down Expand Up @@ -210,7 +210,7 @@ function pretty_filter_topics(&$urls)
$add_new[] = array($row['id_topic'], $pretty_text);
// Add to the original array of topic URLs
$topicData[$row['id_topic']] = array(
'pretty_board' => $context['protocol'] . (!empty($row['board_url']) ? $row['board_url'] : $row['id_board']),
'pretty_board' => PROTOCOL . (!empty($row['board_url']) ? $row['board_url'] : $row['id_board']),
'pretty_url' => $pretty_text,
);
}
Expand Down Expand Up @@ -240,8 +240,6 @@ function pretty_filter_topics(&$urls)
*/
function pretty_filter_boards(&$urls)
{
global $context;

$pattern = '~(.*[?;&])\bboard=([.0-9$%d]+)(?:;(cat|tag)=([^;&]+))?(?:;month=(\d{6,8}))?(.*)~S';
$bo_list = array();
foreach ($urls as &$url)
Expand Down Expand Up @@ -287,7 +285,7 @@ function pretty_filter_boards(&$urls)

foreach ($urls as &$url)
if (!isset($url['replacement']) && isset($url['board_id']))
$url['replacement'] = (!empty($url_list[$url['board_id']]) ? $context['protocol'] . $url_list[$url['board_id']] : ROOT) . '/' . $url['cattag'] . $url['epoch'] . $url['start'] . $url['match1'] . $url['match6'];
$url['replacement'] = (!empty($url_list[$url['board_id']]) ? PROTOCOL . $url_list[$url['board_id']] : ROOT) . '/' . $url['cattag'] . $url['epoch'] . $url['start'] . $url['match1'] . $url['match6'];
}

$cat_pattern = '~(.*)\bcategory=([^;]+)~S';
Expand Down
33 changes: 17 additions & 16 deletions core/app/QueryString.php
Expand Up @@ -12,23 +12,28 @@
die('Hacking attempt...');

/**
* Initializes all of the path constants.
* Initializes all of the constants, especially all paths.
*/
function loadPaths()
function loadConstants()
{
global $boardurl, $settings, $context;
global $boardurl, $remove_index, $aliases;

// Is this a page requested through jQuery? If yes, set the AJAX constant so we can choose to show only the template's default block.
$ajax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
define('INFINITE', $ajax && !empty($_POST['infinite']));
define('AJAX', $ajax && !INFINITE);

// $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.)
$scripturl = $boardurl . (!empty($settings['pretty_remove_index']) && isset($_COOKIE[session_name()]) ? '/' : '/index.php');
$scripturl = $boardurl . (!empty($remove_index) && isset($_COOKIE[session_name()]) ? '/' : '/index.php');

$is_secure = (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1)) || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https');
$context['protocol'] = $is_secure ? 'https://' : 'http://';
define('PROTOCOL', $is_secure ? 'https://' : 'http://');

// Check to see if they're accessing it from the wrong place.
if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
{
$detected_url = $context['protocol'];
$detected_url = PROTOCOL;
$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
if ($temp != '/')
Expand All @@ -38,16 +43,12 @@ function loadPaths()
// Is everything all right, URL-wise..? Then waste no more.
if (isset($detected_url) && $detected_url != $boardurl)
{
// Try #1 - check if it's in a list of alias addresses
if (!empty($settings['forum_alias_urls']))
{
$aliases = explode(',', $settings['forum_alias_urls']);

// Rip off all the boring parts, spaces, etc.
foreach ($aliases as $alias)
// Try #1 - check if it's in a list of alias addresses.
// Define these in Settings.php! e.g. $aliases = 'mainsite.com,altsite.org,anothersite.net'.
if (!empty($aliases))
foreach (explode(',', $aliases) as $alias)
if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
$do_fix = true;
}

// Hmm... check #2 - is it just different by a www? Send them to the correct place!!
if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && WEDGE != 'SSI')
Expand All @@ -63,7 +64,7 @@ function loadPaths()
if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
$do_fix = true;

// Okay, #4 - perhaps it's an IP address? We're gonna want to use that one, then. (assuming it's the IP or something...)
// Okay, #4 - perhaps it's an IP address? We're gonna want to use that one, then. (Assuming it's the IP or something...)
if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
{
// Fix $boardurl and $scripturl
Expand Down Expand Up @@ -571,7 +572,7 @@ function cleanRequest()
if (empty($_SERVER['REQUEST_URI']))
$_SERVER['REQUEST_URL'] = SCRIPT . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
else
$_SERVER['REQUEST_URL'] = $context['protocol'] . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$_SERVER['REQUEST_URL'] = PROTOCOL . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

// And make sure HTTP_USER_AGENT is set.
$_SERVER['HTTP_USER_AGENT'] = isset($_SERVER['HTTP_USER_AGENT']) ? htmlspecialchars(wesql::unescape_string($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES) : '';
Expand Down
8 changes: 3 additions & 5 deletions core/app/Subs-Auth.php
Expand Up @@ -87,7 +87,7 @@
// Actually set the login cookie...
function setLoginCookie($cookie_length, $id, $password = '')
{
global $cookiename, $settings;
global $cookiename, $settings, $aliases;

// If changing state force them to re-address some permission caching.
$_SESSION['mc']['time'] = 0;
Expand Down Expand Up @@ -118,11 +118,9 @@ function setLoginCookie($cookie_length, $id, $password = '')
setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], '', !empty($settings['secureCookies']), true);

// Any alias URLs? This is mainly for use with frames, etc.
if (!empty($settings['forum_alias_urls']))
if (!empty($aliases))
{
$aliases = explode(',', $settings['forum_alias_urls']);

foreach ($aliases as $alias)
foreach (explode(',', $aliases) as $alias)
{
// Fake the ROOT so we can set a different cookie.
$alias = strtr(trim($alias), array('http://' => '', 'https://' => ''));
Expand Down
3 changes: 3 additions & 0 deletions index.php
Expand Up @@ -49,6 +49,9 @@
'Security',
));

// Load paths.
loadConstants();

// Are we installing, or doing something that needs the forum to be down?
if (!empty($maintenance) && $maintenance > 1)
{
Expand Down
16 changes: 5 additions & 11 deletions install/install.php
Expand Up @@ -24,16 +24,9 @@
$boardurl = 'http' . (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off' ? 's' : '') . '://' . $host;
$boardurl .= substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/'));

// Define our constants. (cf. QueryString.php)
define('ROOT', $boardurl);
define('SCRIPT', ROOT_DIR . '/index.php');
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');
// Define our paths and constants.
require_once(ROOT_DIR . '/core/QueryString.php');
loadConstants();

define('INVALID_IP', '00000000000000000000000000000000');
define('IS_WINDOWS', strpos(__FILE__, ':\\') !== false);
Expand Down Expand Up @@ -282,11 +275,12 @@ function load_lang_file()
arsort($preferred, SORT_NUMERIC);
}

// This is the list of known Wedge language packs/mappings as of March 2013.
// This is the list of known Wedge language packs/mappings as of March 2014.
$langs = array(
'en' => 'Install.english.php',
'en-gb' => 'Install.english-uk.php',
'fr' => 'Install.french.php',
'de' => 'Install.german.php',
);

foreach ($preferred as $key => $value)
Expand Down

0 comments on commit c38bfa9

Please sign in to comment.