Skip to content

Commit

Permalink
Merge pull request #446 from norv/cleanups
Browse files Browse the repository at this point in the history
Cleanups
  • Loading branch information
norv committed May 23, 2013
2 parents e363de7 + 8327e93 commit ca96444
Show file tree
Hide file tree
Showing 72 changed files with 524 additions and 581 deletions.
17 changes: 8 additions & 9 deletions SSI.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ function ssi_fetchPosts($post_ids = array(), $override_permissions = false, $out
function ssi_queryPosts($query_where = '', $query_where_params = array(), $query_limit = 10, $query_order = 'm.id_msg DESC', $output_method = 'echo', $limit_body = false, $override_permissions = false)
{
global $context, $settings, $scripturl, $txt, $db_prefix, $user_info;
global $modSettings, $smcFunc;
global $modSettings;

$db = database();

Expand Down Expand Up @@ -457,7 +457,7 @@ function ssi_queryPosts($query_where = '', $query_where_params = array(), $query
),
'subject' => $row['subject'],
'short_subject' => shorten_subject($row['subject'], 25),
'preview' => $smcFunc['strlen']($preview) > 128 ? $smcFunc['substr']($preview, 0, 128) . '...' : $preview,
'preview' => Util::strlen($preview) > 128 ? Util::substr($preview, 0, 128) . '...' : $preview,
'body' => $row['body'],
'time' => standardTime($row['poster_time']),
'timestamp' => forum_time(true, $row['poster_time']),
Expand Down Expand Up @@ -507,7 +507,7 @@ function ssi_queryPosts($query_where = '', $query_where_params = array(), $query
function ssi_recentTopics($num_recent = 8, $exclude_boards = null, $include_boards = null, $output_method = 'echo')
{
global $context, $settings, $scripturl, $txt, $db_prefix, $user_info;
global $modSettings, $smcFunc;
global $modSettings;

$db = database();

Expand Down Expand Up @@ -568,8 +568,8 @@ function ssi_recentTopics($num_recent = 8, $exclude_boards = null, $include_boar
while ($row = $db->fetch_assoc($request))
{
$row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), array('<br />' => '&#10;')));
if ($smcFunc['strlen']($row['body']) > 128)
$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
if (Util::strlen($row['body']) > 128)
$row['body'] = Util::substr($row['body'], 0, 128) . '...';

// Censor the subject.
censorText($row['subject']);
Expand Down Expand Up @@ -1839,7 +1839,6 @@ function ssi_todaysCalendar($output_method = 'echo')
function ssi_boardNews($board = null, $limit = null, $start = null, $length = null, $output_method = 'echo')
{
global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;
global $smcFunc;

loadLanguage('Stats');

Expand Down Expand Up @@ -1938,9 +1937,9 @@ function ssi_boardNews($board = null, $limit = null, $start = null, $length = nu
while ($row = $db->fetch_assoc($request))
{
// If we want to limit the length of the post.
if (!empty($length) && $smcFunc['strlen']($row['body']) > $length)
if (!empty($length) && Util::strlen($row['body']) > $length)
{
$row['body'] = $smcFunc['substr']($row['body'], 0, $length);
$row['body'] = Util::substr($row['body'], 0, $length);
$cutoff = false;

$last_space = strrpos($row['body'], ' ');
Expand All @@ -1952,7 +1951,7 @@ function ssi_boardNews($board = null, $limit = null, $start = null, $length = nu
$cutoff = $last_space;

if ($cutoff !== false)
$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
$row['body'] = Util::substr($row['body'], 0, $cutoff);
$row['body'] .= '...';
}

Expand Down
18 changes: 9 additions & 9 deletions sources/Load.php
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ function loadMemberData($users, $is_name = false, $set = 'normal')
function loadMemberContext($user, $display_custom_fields = false)
{
global $memberContext, $user_profile, $txt, $scripturl, $user_info;
global $context, $modSettings, $board_info, $settings, $smcFunc;
global $context, $modSettings, $board_info, $settings;
static $dataLoaded = array();

// If this person's data is already loaded, skip it.
Expand Down Expand Up @@ -1044,14 +1044,14 @@ function loadMemberContext($user, $display_custom_fields = false)
'ip2' => htmlspecialchars($profile['member_ip2']),
'online' => array(
'is_online' => $profile['is_online'],
'text' => $smcFunc['htmlspecialchars']($txt[$profile['is_online'] ? 'online' : 'offline']),
'member_online_text' => sprintf($txt[$profile['is_online'] ? 'member_is_online' : 'member_is_offline'], $smcFunc['htmlspecialchars']($profile['real_name'])),
'text' => Util::htmlspecialchars($txt[$profile['is_online'] ? 'online' : 'offline']),
'member_online_text' => sprintf($txt[$profile['is_online'] ? 'member_is_online' : 'member_is_offline'], Util::htmlspecialchars($profile['real_name'])),
'href' => $scripturl . '?action=pm;sa=send;u=' . $profile['id_member'],
'link' => '<a href="' . $scripturl . '?action=pm;sa=send;u=' . $profile['id_member'] . '">' . $txt[$profile['is_online'] ? 'online' : 'offline'] . '</a>',
'image_href' => $settings['images_url'] . '/profile/' . ($profile['buddy'] ? 'buddy_' : '') . ($profile['is_online'] ? 'useron' : 'useroff') . '.png',
'label' => $txt[$profile['is_online'] ? 'online' : 'offline']
),
'language' => $smcFunc['ucwords'](strtr($profile['lngfile'], array('_' => ' '))),
'language' => Util::ucwords(strtr($profile['lngfile'], array('_' => ' '))),
'is_activated' => isset($profile['is_activated']) ? $profile['is_activated'] : 1,
'is_banned' => isset($profile['is_activated']) ? $profile['is_activated'] >= 10 : 0,
'options' => $profile['options'],
Expand Down Expand Up @@ -1149,7 +1149,7 @@ function loadTheme($id_theme = 0, $initialize = true)
{
global $user_info, $user_settings, $board_info;
global $txt, $boardurl, $scripturl, $mbname, $modSettings;
global $context, $settings, $options, $ssi_theme, $smcFunc;
global $context, $settings, $options, $ssi_theme;

$db = database();

Expand Down Expand Up @@ -1403,8 +1403,8 @@ function loadTheme($id_theme = 0, $initialize = true)
$context['session_var'] = $_SESSION['session_var'];
$context['session_id'] = $_SESSION['session_value'];
$context['forum_name'] = $mbname;
$context['forum_name_html_safe'] = $smcFunc['htmlspecialchars']($context['forum_name']);
$context['header_logo_url_html_safe'] = empty($settings['header_logo_url']) ? '' : $smcFunc['htmlspecialchars']($settings['header_logo_url']);
$context['forum_name_html_safe'] = Util::htmlspecialchars($context['forum_name']);
$context['header_logo_url_html_safe'] = empty($settings['header_logo_url']) ? '' : Util::htmlspecialchars($settings['header_logo_url']);
$context['current_action'] = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
Expand Down Expand Up @@ -2183,7 +2183,7 @@ function getBoardParents($id_parent)
*/
function getLanguages($use_cache = true)
{
global $settings, $modSettings, $smcFunc;
global $settings, $modSettings;

// Either we don't use the cache, or its expired.
if (!$use_cache || ($languages = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
Expand Down Expand Up @@ -2219,7 +2219,7 @@ function getLanguages($use_cache = true)
continue;

$languages[$matches[1]] = array(
'name' => $smcFunc['ucwords'](strtr($matches[1], array('_' => ' '))),
'name' => Util::ucwords(strtr($matches[1], array('_' => ' '))),
'selected' => false,
'filename' => $matches[1],
'location' => $language_dir . '/index.' . $matches[1] . '.php',
Expand Down
8 changes: 2 additions & 6 deletions sources/QueryString.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,8 @@ function escapestring__recursive($var)
*/
function htmlspecialchars__recursive($var, $level = 0)
{
global $smcFunc;

if (!is_array($var))
return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
return Util::htmlspecialchars($var, ENT_QUOTES);

// Add the htmlspecialchars to every element.
foreach ($var as $k => $v)
Expand Down Expand Up @@ -534,11 +532,9 @@ function stripslashes__recursive($var, $level = 0)
*/
function htmltrim__recursive($var, $level = 0)
{
global $smcFunc;

// Remove spaces (32), tabs (9), returns (13, 10, and 11), nulls (0), and hard spaces. (160)
if (!is_array($var))
return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
return Util::htmltrim($var);

// Go through all the elements and remove the whitespace.
foreach ($var as $k => $v)
Expand Down
2 changes: 1 addition & 1 deletion sources/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ function checkSession($type = 'post', $from_action = '', $is_fatal = true)

$parsed_url = parse_url($boardurl);

// Are global cookies on? If so, let's check them ;).
// Are global cookies on? If so, let's check them ;).
if (!empty($modSettings['globalCookies']))
{
if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
Expand Down
26 changes: 11 additions & 15 deletions sources/Subs.php
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ function comma_format($number, $override_decimal_count = false)
*/
function standardTime($log_time, $show_today = true, $offset_type = false)
{
global $context, $user_info, $txt, $modSettings, $smcFunc;
global $context, $user_info, $txt, $modSettings;
static $non_twelve_hour;

// Offset the time.
Expand Down Expand Up @@ -699,7 +699,7 @@ function standardTime($log_time, $show_today = true, $offset_type = false)

foreach (array('%a', '%A', '%b', '%B') as $token)
if (strpos($str, $token) !== false)
$str = str_replace($token, !empty($txt['lang_capitalize_dates']) ? $smcFunc['ucwords'](strftime($token, $time)) : strftime($token, $time), $str);
$str = str_replace($token, !empty($txt['lang_capitalize_dates']) ? Util::ucwords(strftime($token, $time)) : strftime($token, $time), $str);
}
else
{
Expand Down Expand Up @@ -817,14 +817,12 @@ function un_htmlspecialchars($string)
*/
function shorten_subject($subject, $len)
{
global $smcFunc;

// It was already short enough!
if ($smcFunc['strlen']($subject) <= $len)
if (Util::strlen($subject) <= $len)
return $subject;

// Shorten it by the length it was too long, and strip off junk from the end.
return $smcFunc['substr']($subject, 0, $len) . '...';
return Util::substr($subject, 0, $len) . '...';
}

/**
Expand All @@ -842,9 +840,7 @@ function shorten_subject($subject, $len)
*/
function shorten_text($text, $len = 384, $buffer = 12)
{
global $smcFunc;

$current = $smcFunc['strlen']($text);
$current = Util::strlen($text);

// Its to long so lets cut it down to size
if ($current > $len)
Expand All @@ -853,7 +849,7 @@ function shorten_text($text, $len = 384, $buffer = 12)
preg_match('~(.{' . $len . '}.*?)\b~s', $text, $matches);

// Always one clown in the audience who likes long words or not using the spacebar
if ($smcFunc['strlen']($matches[1]) > $len + $buffer)
if (Util::strlen($matches[1]) > $len + $buffer)
$matches[1] = substr($matches[1], 0, $len);

return rtrim($matches[1]) . '...';
Expand Down Expand Up @@ -2636,7 +2632,7 @@ function redirectexit($setLocation = '', $refresh = false)
*/
function obExit($header = null, $do_footer = null, $from_index = false, $from_fatal_error = false)
{
global $context, $settings, $modSettings, $txt, $smcFunc;
global $context, $settings, $modSettings, $txt;

static $header_done = false, $footer_done = false, $level = 0, $has_fatal_error = false;

Expand Down Expand Up @@ -2664,7 +2660,7 @@ function obExit($header = null, $do_footer = null, $from_index = false, $from_fa
{
// Was the page title set last minute? Also update the HTML safe one.
if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
$context['page_title_html_safe'] = Util::htmlspecialchars(un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');

// Start up the session URL fixer.
ob_start('ob_sessrewrite');
Expand Down Expand Up @@ -2775,7 +2771,7 @@ function determineTopicClass(&$topic_context)
function setupThemeContext($forceload = false)
{
global $modSettings, $user_info, $scripturl, $context, $settings, $options, $txt, $maintenance;
global $user_settings, $smcFunc;
global $user_settings;

static $loaded = false;

Expand Down Expand Up @@ -2934,8 +2930,8 @@ function setupThemeContext($forceload = false)
$context['page_title'] = '';

// Set some specific vars.
$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
$context['meta_keywords'] = !empty($modSettings['meta_keywords']) ? $smcFunc['htmlspecialchars']($modSettings['meta_keywords']) : '';
$context['page_title_html_safe'] = Util::htmlspecialchars(un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
$context['meta_keywords'] = !empty($modSettings['meta_keywords']) ? Util::htmlspecialchars($modSettings['meta_keywords']) : '';
}

/**
Expand Down
8 changes: 4 additions & 4 deletions sources/admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ class Admin_Controller
*/
public function action_home()
{
global $forum_version, $txt, $scripturl, $context, $user_info;
global $forum_version, $txt, $scripturl, $context, $user_info;

// we need a little help
require_once(SUBSDIR . '/Membergroups.subs.php');
Expand Down Expand Up @@ -724,7 +724,7 @@ public function action_home()
*/
public function action_credits()
{
global $forum_version, $txt, $scripturl, $context, $user_info;
global $forum_version, $txt, $scripturl, $context, $user_info;

// we need a little help from our friends
require_once(SUBSDIR . '/Membergroups.subs.php');
Expand Down Expand Up @@ -840,7 +840,7 @@ public function action_credits()
*/
public function action_search()
{
global $txt, $context, $smcFunc;
global $txt, $context;

isAllowedTo('admin_forum');

Expand All @@ -852,7 +852,7 @@ public function action_search()
);

$context['search_type'] = !isset($_REQUEST['search_type']) || !isset($subactions[$_REQUEST['search_type']]) ? 'internal' : $_REQUEST['search_type'];
$context['search_term'] = isset($_REQUEST['search_term']) ? $smcFunc['htmlspecialchars']($_REQUEST['search_term'], ENT_QUOTES) : '';
$context['search_term'] = isset($_REQUEST['search_term']) ? Util::htmlspecialchars($_REQUEST['search_term'], ENT_QUOTES) : '';

$context['sub_template'] = 'admin_search_results';
$context['page_title'] = $txt['admin_search_results'];
Expand Down
6 changes: 3 additions & 3 deletions sources/admin/ManageAttachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ public function action_repair()
*/
public function action_attachpaths()
{
global $modSettings, $scripturl, $context, $txt, $smcFunc;
global $modSettings, $scripturl, $context, $txt;

$db = database();

Expand Down Expand Up @@ -1691,11 +1691,11 @@ public function action_attachpaths()
$errors = array();
if (!empty($_SESSION['errors']['dir']))
foreach ($_SESSION['errors']['dir'] as $error)
$errors['dir'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES);
$errors['dir'][] = Util::htmlspecialchars($error, ENT_QUOTES);

if (!empty($_SESSION['errors']['base']))
foreach ($_SESSION['errors']['base'] as $error)
$errors['base'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES);
$errors['base'][] = Util::htmlspecialchars($error, ENT_QUOTES);
}
unset($_SESSION['errors']);
}
Expand Down
16 changes: 6 additions & 10 deletions sources/admin/ManageBans.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ public function action_log()
*/
public function action_edit2()
{
global $context, $smcFunc;
global $context;

require_once(SUBSDIR . '/Bans.subs.php');

Expand All @@ -658,9 +658,9 @@ public function action_edit2()
);
$ban_info['db_expiration'] = $ban_info['expiration']['status'] == 'never' ? 'NULL' : ($ban_info['expiration']['status'] == 'one_day' ? time() + 24 * 60 * 60 * $ban_info['expire_date'] : 0);
$ban_info['full_ban'] = empty($_POST['full_ban']) ? 0 : 1;
$ban_info['reason'] = !empty($_POST['reason']) ? $smcFunc['htmlspecialchars']($_POST['reason'], ENT_QUOTES) : '';
$ban_info['name'] = !empty($_POST['ban_name']) ? $smcFunc['htmlspecialchars']($_POST['ban_name'], ENT_QUOTES) : '';
$ban_info['notes'] = isset($_POST['notes']) ? $smcFunc['htmlspecialchars']($_POST['notes'], ENT_QUOTES) : '';
$ban_info['reason'] = !empty($_POST['reason']) ? Util::htmlspecialchars($_POST['reason'], ENT_QUOTES) : '';
$ban_info['name'] = !empty($_POST['ban_name']) ? Util::htmlspecialchars($_POST['ban_name'], ENT_QUOTES) : '';
$ban_info['notes'] = isset($_POST['notes']) ? Util::htmlspecialchars($_POST['notes'], ENT_QUOTES) : '';
$ban_info['notes'] = str_replace(array("\r", "\n", ' '), array('', '<br />', '&nbsp; '), $ban_info['notes']);
$ban_info['cannot']['access'] = empty($ban_info['full_ban']) ? 0 : 1;
$ban_info['cannot']['post'] = !empty($ban_info['full_ban']) || empty($_POST['cannot_post']) ? 0 : 1;
Expand Down Expand Up @@ -996,9 +996,7 @@ public function action_browse()
{
$listOptions['columns']['banned_entity']['data'] = array(
'function' => create_function('$rowData', '
global $smcFunc;
return strtr($smcFunc[\'htmlspecialchars\']($rowData[\'hostname\']), array(\'%\' => \'*\'));
return strtr(Util::htmlspecialchars($rowData[\'hostname\']), array(\'%\' => \'*\'));
'),
);
$listOptions['columns']['banned_entity']['sort'] = array(
Expand All @@ -1010,9 +1008,7 @@ public function action_browse()
{
$listOptions['columns']['banned_entity']['data'] = array(
'function' => create_function('$rowData', '
global $smcFunc;
return strtr($smcFunc[\'htmlspecialchars\']($rowData[\'email_address\']), array(\'%\' => \'*\'));
return strtr(Util::htmlspecialchars($rowData[\'email_address\']), array(\'%\' => \'*\'));
'),
);
$listOptions['columns']['banned_entity']['sort'] = array(
Expand Down
4 changes: 2 additions & 2 deletions sources/admin/ManageCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function action_holidays()
*/
public function action_editholiday()
{
global $txt, $context, $smcFunc;
global $txt, $context;

//We need this, really..
require_once(SUBSDIR . '/Calendar.subs.php');
Expand All @@ -217,7 +217,7 @@ public function action_editholiday()
checkSession();

// Not too long good sir?
$_REQUEST['title'] = $smcFunc['substr']($_REQUEST['title'], 0, 60);
$_REQUEST['title'] = Util::substr($_REQUEST['title'], 0, 60);
$_REQUEST['holiday'] = isset($_REQUEST['holiday']) ? (int) $_REQUEST['holiday'] : 0;

if (isset($_REQUEST['delete']))
Expand Down

0 comments on commit ca96444

Please sign in to comment.