Skip to content

Commit

Permalink
* And... $boardurl is almost entirely replaced with ROOT! I think I'm…
Browse files Browse the repository at this point in the history
… done with replacements, phew..! (SSI.php, install.php, Class-System.php, Load.php, ManageNews.php, ManagePaid.php, ManageSettings.php, PrettyUrls-Filters.php, Security.php, Subs-Auth.php, Subs-Cache.php, Subs-PrettyUrls.php, Subscriptions-PayPal.php, Upgrade.php, Aeva-Embed.php, Admin.template.php, Media.template.php, index.template.php)

@ So, as a reminder... These variables are replaced with their equivalent in parenthesis: $boardurl (ROOT), $boarddir (ROOT_DIR), $sourcedir (APP_DIR), $settings['theme_url'] (TEMPLATES), $settings['theme_dir'] (TEMPLATES_DIR), $settings['images_url'] (ASSETS), $settings['images_dir'] (ASSETS_DIR), and $cachedir (CACHE_DIR). Do not use the $variables, except for $boardurl if you're trying to override it before it's set in stone. I'm not even sure there's a hook for that, though...
  • Loading branch information
Nao committed Mar 25, 2014
1 parent 0c03c5d commit 962885b
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 66 deletions.
15 changes: 7 additions & 8 deletions SSI.php
Expand Up @@ -14,10 +14,9 @@

define('WEDGE', 'SSI');

// 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, $webmaster_email, $cookiename;
// For reference, mainly.
global $settings, $context, $sc, $topic, $board, $txt, $time_start;
global $maintenance, $msubject, $mmessage, $mbname, $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 Down Expand Up @@ -1023,7 +1022,7 @@ function ssi_topPoll($output_method = 'echo')
// Show the most recently posted poll.
function ssi_recentPoll($topPollInstead = false, $output_method = 'echo')
{
global $txt, $boardurl, $context, $settings;
global $txt, $context, $settings;

$boardsAllowed = array_intersect(boardsAllowedTo('poll_view'), boardsAllowedTo('poll_vote'));

Expand Down Expand Up @@ -1133,7 +1132,7 @@ function ssi_recentPoll($topPollInstead = false, $output_method = 'echo')
if ($allow_view_results)
{
echo '
<form class="ssi_poll" action="', $boardurl, '/SSI.php?ssi_function=pollVote" method="post" accept-charset="UTF-8">
<form class="ssi_poll" action="', ROOT, '/SSI.php?ssi_function=pollVote" method="post" accept-charset="UTF-8">
<strong>', $return['question'], '</strong><br />
', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br />' : '';

Expand All @@ -1153,7 +1152,7 @@ function ssi_recentPoll($topPollInstead = false, $output_method = 'echo')

function ssi_showPoll($id_topic = null, $output_method = 'echo')
{
global $txt, $boardurl, $context;
global $txt, $context;

$boardsAllowed = boardsAllowedTo('poll_view');

Expand Down Expand Up @@ -1283,7 +1282,7 @@ function ssi_showPoll($id_topic = null, $output_method = 'echo')
if ($return['allow_vote'])
{
echo '
<form class="ssi_poll" action="', $boardurl, '/SSI.php?ssi_function=pollVote" method="post" accept-charset="UTF-8">
<form class="ssi_poll" action="', ROOT, '/SSI.php?ssi_function=pollVote" method="post" accept-charset="UTF-8">
<strong>', $return['question'], '</strong><br />
', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br />' : '';

Expand Down
4 changes: 2 additions & 2 deletions core/app/Class-System.php
Expand Up @@ -56,7 +56,7 @@ public static function &getInstance($load_user = true)
*/
protected static function init_user()
{
global $context, $settings, $user_settings, $cookiename, $boardurl;
global $context, $settings, $user_settings, $cookiename;

$id_member = 0;

Expand Down Expand Up @@ -435,7 +435,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($boardurl, ':'), 3) : $_SERVER['HTTP_X_FORWARDED_SERVER']) : $_SERVER['HTTP_HOST']) : $_SERVER['REAL_HTTP_HOST'];
$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'];

// The URL in your address bar. Also contains the query string.
Expand Down
4 changes: 2 additions & 2 deletions core/app/Load.php
Expand Up @@ -2145,7 +2145,7 @@ function getLanguages($use_cache = true)
*/
function loadSession()
{
global $settings, $boardurl, $sc;
global $settings, $sc;

// Attempt to change a few PHP settings.
ini_set('session.use_cookies', true);
Expand All @@ -2156,7 +2156,7 @@ function loadSession()

if (!empty($settings['globalCookies']))
{
$parsed_url = parse_url($boardurl);
$parsed_url = parse_url(ROOT);

if (!preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) && preg_match('~(?:[^.]+\.)?([^.]{2,}\..+)\z~i', $parsed_url['host'], $parts))
ini_set('session.cookie_domain', '.' . $parts[1]);
Expand Down
6 changes: 3 additions & 3 deletions core/app/ManageNews.php
Expand Up @@ -473,7 +473,7 @@ function ComposeMailing()
// Send out the mailing!
function SendMailing($clean_only = false)
{
global $txt, $context, $boardurl, $settings;
global $txt, $context, $settings;

// How many to send at once? Quantity depends on whether we are queueing or not.
$num_at_once = empty($settings['mail_queue']) ? 60 : 1000;
Expand Down Expand Up @@ -602,15 +602,15 @@ function SendMailing($clean_only = false)
// Replace in all the standard things.
$_POST['message'] = str_replace($variables,
array(
!empty($_POST['send_html']) ? '<a href="' . $boardurl . '">' . $boardurl . '</a>' : $boardurl,
!empty($_POST['send_html']) ? '<a href="' . ROOT . '">' . ROOT . '</a>' : ROOT,
timeformat(forum_time(), false),
!empty($_POST['send_html']) ? '<a href="' . SCRIPT . '?action=profile;u=' . $settings['latestMember'] . '">' . $cleanLatestMember . '</a>' : ($context['send_pm'] ? '[url=' . SCRIPT . '?action=profile;u=' . $settings['latestMember'] . ']' . $cleanLatestMember . '[/url]' : $cleanLatestMember),
$settings['latestMember'],
$cleanLatestMember
), $_POST['message']);
$_POST['subject'] = str_replace($variables,
array(
$boardurl,
ROOT,
timeformat(forum_time(), false),
$settings['latestRealName'],
$settings['latestMember'],
Expand Down
4 changes: 2 additions & 2 deletions core/app/ManagePaid.php
Expand Up @@ -111,7 +111,7 @@ function ManagePaidSubscriptions()
// Modify which payment methods are to be used.
function ModifySubscriptionSettings($return_config = false)
{
global $context, $txt, $settings, $boardurl;
global $context, $txt, $settings;

// If the currency is set to something different then we need to set it to other for this to work and set it back shortly.
$settings['paid_currency'] = !empty($settings['paid_currency_code']) ? $settings['paid_currency_code'] : '';
Expand Down Expand Up @@ -159,7 +159,7 @@ function ModifySubscriptionSettings($return_config = false)
// Some important context stuff
$context['page_title'] = $txt['settings'];
wetem::load('show_settings');
$context['settings_message'] = str_replace('{board_url}', $boardurl, $txt['paid_note']);
$context['settings_message'] = str_replace('{board_url}', ROOT, $txt['paid_note']);
$context[$context['admin_menu_name']]['current_subsection'] = 'settings';

// Get the final touches in place.
Expand Down
4 changes: 2 additions & 2 deletions core/app/ManageSettings.php
Expand Up @@ -488,8 +488,8 @@ function ModifyPmSettings($return_config = false)

// !!! To-do:
// - Specifically allow for subdomains
// - Disable the area and subdomain feature, and explain why, if $boardurl has a subfolder name in it!
// i.e. if (preg_match('~://[^/]+/[^/]+~', $boardurl))
// - Disable the area and subdomain feature, and explain why, if ROOT has a subfolder name in it!
// i.e. if (preg_match('~://[^/]+/[^/]+~', ROOT))

// Shell for all the Pretty URL interfaces
function ModifyPrettyURLs($return_config = false)
Expand Down
20 changes: 10 additions & 10 deletions core/app/PrettyUrls-Filters.php
Expand Up @@ -93,15 +93,15 @@ function pretty_synchronize_topic_urls()
*/
function pretty_filter_actions(&$urls)
{
global $boardurl, $settings;
global $settings;

$action_pattern = '~(?<=[?;&])action=([^;]+)~';
$action_replacement = isset($settings['pretty_prefix_action']) ? $settings['pretty_prefix_action'] : 'do/';

foreach ($urls as &$url)
{
if (!isset($url['replacement']))
$url['replacement'] = $boardurl . '/' . $url['url'];
$url['replacement'] = ROOT . '/' . $url['url'];
if (strpos($url['replacement'], 'action=') !== false && preg_match($action_pattern, $url['replacement'], $action))
$url['replacement'] = str_replace($action[0], '', substr_replace($url['replacement'], $action_replacement . $action[1] . '/', strpos($url['replacement'], '?'), 0));
}
Expand All @@ -112,7 +112,7 @@ function pretty_filter_actions(&$urls)
*/
function pretty_filter_topics(&$urls)
{
global $boardurl, $settings, $context;
global $settings, $context;

$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'] : $boardurl,
'pretty_board' => !empty($row['url']) ? $context['protocol'] . $row['url'] : ROOT,
'pretty_url' => $row['pretty_url'],
);
else
Expand Down Expand Up @@ -240,7 +240,7 @@ function pretty_filter_topics(&$urls)
*/
function pretty_filter_boards(&$urls)
{
global $boardurl, $context;
global $context;

$pattern = '~(.*[?;&])\bboard=([.0-9$%d]+)(?:;(cat|tag)=([^;&]+))?(?:;month=(\d{6,8}))?(.*)~S';
$bo_list = array();
Expand Down Expand Up @@ -287,11 +287,11 @@ 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']] : $boardurl) . '/' . $url['cattag'] . $url['epoch'] . $url['start'] . $url['match1'] . $url['match6'];
$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'];
}

$cat_pattern = '~(.*)\bcategory=([^;]+)~S';
$cat_replacement = $boardurl . '/category/$2/$1';
$cat_replacement = ROOT . '/category/$2/$1';

foreach ($urls as &$url)
if (!isset($url['replacement']) && strpos($url['url'], 'category=') !== false && preg_match($cat_pattern, $url['url']))
Expand All @@ -303,7 +303,7 @@ function pretty_filter_boards(&$urls)
*/
function pretty_filter_profiles(&$urls)
{
global $boardurl, $settings;
global $settings;

$pattern = '~(.*)\baction=profile(;u=([0-9]+))?(.*)~S';
$query_data = array();
Expand All @@ -321,7 +321,7 @@ function pretty_filter_profiles(&$urls)
if ($url['profile_id'] > 0)
$query_data[$url['profile_id']] = true;
else
$url['replacement'] = $boardurl . $prefix . ($url['this_is_me'] ? $me_postfix : 'guest/') . $url['match1'] . $url['match3'];
$url['replacement'] = ROOT . $prefix . ($url['this_is_me'] ? $me_postfix : 'guest/') . $url['match1'] . $url['match3'];
}
}

Expand All @@ -346,6 +346,6 @@ function pretty_filter_profiles(&$urls)
// Build the replacement URLs
foreach ($urls as &$url)
if (isset($url['profile_id']))
$url['replacement'] = $boardurl . $prefix . (!empty($memberNames[$url['profile_id']]) ? $memberNames[$url['profile_id']] . '/' : ($url['this_is_me'] ? $me_postfix : 'guest/')) . $url['match1'] . $url['match3'];
$url['replacement'] = ROOT . $prefix . (!empty($memberNames[$url['profile_id']]) ? $memberNames[$url['profile_id']] . '/' : ($url['this_is_me'] ? $me_postfix : 'guest/')) . $url['match1'] . $url['match3'];
}
}
4 changes: 2 additions & 2 deletions core/app/Security.php
Expand Up @@ -795,7 +795,7 @@ function query_for_bans($type)
// Make sure the user's correct session was passed, and they came from here. (type can be post, get, or request.)
function checkSession($type = 'post', $from_action = '', $is_fatal = true)
{
global $sc, $settings, $boardurl;
global $sc, $settings;

// Is it in as $_POST?
if ($type == 'post')
Expand Down Expand Up @@ -842,7 +842,7 @@ function checkSession($type = 'post', $from_action = '', $is_fatal = true)
else
$real_host = $_SERVER['HTTP_HOST'];

$parsed_url = parse_url($boardurl);
$parsed_url = parse_url(ROOT);

// Are global cookies on? If so, let's check them ;)
if (!empty($settings['globalCookies']))
Expand Down
6 changes: 2 additions & 4 deletions core/app/Subs-Auth.php
Expand Up @@ -124,7 +124,7 @@ function setLoginCookie($cookie_length, $id, $password = '')

foreach ($aliases as $alias)
{
// Fake the $boardurl so we can set a different cookie.
// Fake the ROOT so we can set a different cookie.
$alias = strtr(trim($alias), array('http://' => '', 'https://' => ''));
$cookie_url = url_parts(!empty($settings['localCookies']), !empty($settings['globalCookies']), 'http://' . $alias);

Expand Down Expand Up @@ -157,10 +157,8 @@ function setLoginCookie($cookie_length, $id, $password = '')
// Get the domain and path for the cookie...
function url_parts($local, $global, $force_url = '')
{
global $boardurl;

// Parse the URL with PHP to make life easier.
$parsed_url = parse_url(empty($url) ? $boardurl : $force_url);
$parsed_url = parse_url(empty($url) ? ROOT : $force_url);

// Is local cookies off?
if (empty($parsed_url['path']) || !$local)
Expand Down
4 changes: 2 additions & 2 deletions core/app/Subs-Cache.php
Expand Up @@ -1927,7 +1927,7 @@ 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;
global $settings, $cache_hits, $cache_count, $db_show_debug;

$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
if (!empty($db_show_debug))
Expand All @@ -1937,7 +1937,7 @@ function cache_prepare_key($key, $val = '', $type = 'get')
{
if (!file_exists(CACHE_DIR . '/cache.lock'))
@fclose(@fopen(CACHE_DIR . '/cache.lock', 'w'));
$settings['cache_hash'] = md5($boardurl . filemtime(CACHE_DIR . '/cache.lock'));
$settings['cache_hash'] = md5(ROOT_DIR . filemtime(CACHE_DIR . '/cache.lock'));
}

return $settings['cache_hash'] . '-' . bin2hex($key);
Expand Down
4 changes: 2 additions & 2 deletions core/app/Subs-PrettyUrls.php
Expand Up @@ -88,10 +88,10 @@ function pretty_generate_url($text, $is_board = false, $slash = false)
// Check a new pretty URL against the list of existing boards to ensure there won't be a conflict.
function is_already_taken($url, $id, $id_owner)
{
global $context, $action_list, $boardurl;
global $context, $action_list;

// Is the board name in the action list?
$board_name = substr($url, strlen($boardurl) + 1);
$board_name = substr($url, strlen(ROOT) + 1);
$forbidden = array_merge($action_list, array('do' => true));

foreach (explode('/', $board_name) as $name)
Expand Down
4 changes: 2 additions & 2 deletions core/app/Subscriptions-PayPal.php
Expand Up @@ -40,7 +40,7 @@ public function gatewayEnabled()
// What do we want?
public function fetchGatewayFields($unique_id, $sub_data, $value, $period, $return_url)
{
global $settings, $txt, $boardurl;
global $settings, $txt;

$return_data = array(
'form' => 'https://www.' . (!empty($settings['paidsubs_test']) ? 'sandbox.' : '') . 'paypal.com/cgi-bin/webscr',
Expand All @@ -63,7 +63,7 @@ public function fetchGatewayFields($unique_id, $sub_data, $value, $period, $retu
$return_data['hidden']['cmd'] = !$sub_data['repeatable'] ? '_xclick' : '_xclick-subscriptions';
$return_data['hidden']['return'] = $return_url;
$return_data['hidden']['src'] = 1;
$return_data['hidden']['notify_url'] = $boardurl . '/subscriptions.php';
$return_data['hidden']['notify_url'] = ROOT . '/subscriptions.php';

// Now then, what language should we use? A language pack should indicate the language PayPal should use.
$return_data['hidden']['lc'] = isset($txt['lang_paypal']) ? $txt['lang_paypal'] : 'US';
Expand Down
1 change: 1 addition & 0 deletions core/app/Upgrade.php
Expand Up @@ -32,6 +32,7 @@ function upgrade_db()
}

// We might want to add some message here...
// Note: ROOT isn't defined at this point, so stick to $boardurl!
redirectexit($boardurl . '/index.php?' . ($v < WEDGE ? 'upgrading-step-' . $v : 'upgraded'));
}

Expand Down
4 changes: 2 additions & 2 deletions core/app/media/Aeva-Embed.php
Expand Up @@ -1098,7 +1098,7 @@ function aeva_embed_video($message, $id_media = 0, $id_preview = 0)

function aeva_check_embed_link($link)
{
global $sites, $boardurl, $settings;
global $sites, $settings;

if (empty($settings['embed_enabled']))
return false;
Expand All @@ -1109,7 +1109,7 @@ function aeva_check_embed_link($link)
return $link2;

// Parse the boardurl to grab the domain we're on.
$x = @parse_url($boardurl);
$x = @parse_url(ROOT);
$x['scheme'] = !empty($x['scheme']) ? $x['scheme'] : 'http';
$x['host'] = !empty($x['host']) ? $x['host'] : null;

Expand Down
10 changes: 5 additions & 5 deletions core/html/Admin.template.php
Expand Up @@ -1669,7 +1669,7 @@ function doAutoSubmit()
// Pretty URLs
function template_pretty_urls()
{
global $context, $txt, $settings, $boardurl;
global $context, $txt, $settings;

if (!empty($context['pretty']['chrome']['menu']))
{
Expand Down Expand Up @@ -1721,8 +1721,8 @@ function template_pretty_urls()
$prefix = empty($settings['pretty_prefix_action']) ? '' : $settings['pretty_prefix_action'];
echo '
<select name="pretty_prefix_action" class="pretty_prefix', $enabled ? '' : ' hide', '">
<option value=""', $prefix == '' ? ' selected' : '', '>', $boardurl, '/action</option>
<option value="do/"', $prefix == 'do/' ? ' selected' : '', '>', $boardurl, '/do/action</option>
<option value=""', $prefix == '' ? ' selected' : '', '>', ROOT, '/action</option>
<option value="do/"', $prefix == 'do/' ? ' selected' : '', '>', ROOT, '/do/action</option>
</select>';
}

Expand All @@ -1731,8 +1731,8 @@ function template_pretty_urls()
$prefix = empty($settings['pretty_prefix_profile']) ? '' : $settings['pretty_prefix_profile'];
echo '
<select name="pretty_prefix_profile" class="pretty_prefix', $enabled ? '' : ' hide', '">
<option value="~"', $prefix == '~' ? ' selected' : '', '>', $boardurl, '/~UserName/</option>
<option value="profile/"', $prefix == 'profile/' ? ' selected' : '', '>', $boardurl, '/profile/UserName/</option>
<option value="~"', $prefix == '~' ? ' selected' : '', '>', ROOT, '/~UserName/</option>
<option value="profile/"', $prefix == 'profile/' ? ' selected' : '', '>', ROOT, '/profile/UserName/</option>
</select>';
}

Expand Down

0 comments on commit 962885b

Please sign in to comment.