|
@@ -2,7 +2,7 @@
|
|
|
|
|
|
/**
|
|
|
* This file has all the main functions in it that relate to, well, everything.
|
|
|
- *
|
|
|
+ *
|
|
|
* Simple Machines Forum (SMF)
|
|
|
*
|
|
|
* @package SMF
|
|
@@ -18,8 +18,8 @@ if (!defined('SMF'))
|
|
|
|
|
|
/**
|
|
|
* Update some basic statistics.
|
|
|
- *
|
|
|
- * 'member' statistic updates the latest member, the total member
|
|
|
+ *
|
|
|
+ * 'member' statistic updates the latest member, the total member
|
|
|
* count, and the number of unapproved members.
|
|
|
* 'member' also only counts approved members when approval is on, but
|
|
|
* is much more efficient with it off.
|
|
@@ -31,12 +31,12 @@ if (!defined('SMF'))
|
|
|
* 'topic' updates the total number of topics, or if parameter1 is true
|
|
|
* simply increments them.
|
|
|
*
|
|
|
- * 'subject' updateds the log_search_subjects in the event of a topic being
|
|
|
+ * 'subject' updateds the log_search_subjects in the event of a topic being
|
|
|
* moved, removed or split. parameter1 is the topicid, parameter2 is the new subject
|
|
|
- *
|
|
|
+ *
|
|
|
* 'postgroups' case updates those members who match condition's
|
|
|
* post-based membergroups in the database (restricted by parameter1).
|
|
|
- *
|
|
|
+ *
|
|
|
* @param string $type Stat type - can be 'member', 'message', 'topic', 'subject' or 'postgroups'
|
|
|
* @param mixed $parameter1 = null
|
|
|
* @param mixed $parameter2 = null
|
|
@@ -249,10 +249,10 @@ function updateStats($type, $parameter1 = null, $parameter2 = null)
|
|
|
|
|
|
/**
|
|
|
* Updates the columns in the members table.
|
|
|
- * Assumes the data has been htmlspecialchar'd.
|
|
|
+ * Assumes the data has been htmlspecialchar'd.
|
|
|
* this function should be used whenever member data needs to be
|
|
|
* updated in place of an UPDATE query.
|
|
|
- *
|
|
|
+ *
|
|
|
* id_member is either an int or an array of ints to be updated.
|
|
|
*
|
|
|
* data is an associative array of the columns to be updated and their respective values.
|
|
@@ -405,7 +405,7 @@ function updateMemberData($members, $data)
|
|
|
|
|
|
/**
|
|
|
* Updates the settings table as well as $modSettings... only does one at a time if $update is true.
|
|
|
- *
|
|
|
+ *
|
|
|
* - updates both the settings table and $modSettings array.
|
|
|
* - all of changeArray's indexes and values are assumed to have escaped apostrophes (')!
|
|
|
* - if a variable is already set to what you want to change it to, that
|
|
@@ -413,7 +413,7 @@ function updateMemberData($members, $data)
|
|
|
* - When use_update is true, UPDATEs will be used instead of REPLACE.
|
|
|
* - when use_update is true, the value can be true or false to increment
|
|
|
* or decrement it, respectively.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param array $changeArray
|
|
|
* @param bool $update = false
|
|
|
* @param bool $debug = false
|
|
@@ -492,7 +492,7 @@ function updateSettings($changeArray, $update = false, $debug = false)
|
|
|
*
|
|
|
* an example is available near the function definition.
|
|
|
* $pageindex = constructPageIndex($scripturl . '?board=' . $board, $_REQUEST['start'], $num_messages, $maxindex, true);
|
|
|
- *
|
|
|
+ *
|
|
|
* @param string $base_url
|
|
|
* @param int $start
|
|
|
* @param int $max_value
|
|
@@ -633,13 +633,13 @@ function comma_format($number, $override_decimal_count = false)
|
|
|
|
|
|
/**
|
|
|
* Format a time to make it look purdy.
|
|
|
- *
|
|
|
+ *
|
|
|
* - returns a pretty formated version of time based on the user's format in $user_info['time_format'].
|
|
|
* - applies all necessary time offsets to the timestamp, unless offset_type is set.
|
|
|
* - if todayMod is set and show_today was not not specified or true, an
|
|
|
* alternate format string is used to show the date with something to show it is "today" or "yesterday".
|
|
|
* - performs localization (more than just strftime would do alone.)
|
|
|
- *
|
|
|
+ *
|
|
|
* @param int $log_time
|
|
|
* @param bool $show_today = true
|
|
|
* @param string $offset_type = false
|
|
@@ -728,7 +728,7 @@ function timeformat($log_time, $show_today = true, $offset_type = false)
|
|
|
*
|
|
|
* - removes the base entities (<, ", etc.) from text.
|
|
|
* - additionally converts and '.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param string $string
|
|
|
* @return the string without entities
|
|
|
*/
|
|
@@ -744,12 +744,12 @@ function un_htmlspecialchars($string)
|
|
|
|
|
|
/**
|
|
|
* Shorten a subject + internationalization concerns.
|
|
|
- *
|
|
|
+ *
|
|
|
* - shortens a subject so that it is either shorter than length, or that length plus an ellipsis.
|
|
|
* - respects internationalization characters and entities as one character.
|
|
|
* - avoids trailing entities.
|
|
|
* - returns the shortened string.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param string $subject
|
|
|
* @param int $len
|
|
|
*/
|
|
@@ -790,7 +790,7 @@ function forum_time($use_user_offset = true, $timestamp = null)
|
|
|
* Calculates all the possible permutations (orders) of array.
|
|
|
* should not be called on huge arrays (bigger than like 10 elements.)
|
|
|
* returns an array containing each permutation.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param array $array
|
|
|
* @return array
|
|
|
*/
|
|
@@ -829,7 +829,7 @@ function permute($array)
|
|
|
* - applies the fixLongWords magic if the setting is set to on.
|
|
|
* - uses the cache_id as a unique identifier to facilitate any caching it may do.
|
|
|
* -returns the modified message.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param string $message
|
|
|
* @param bool $smileys = true
|
|
|
* @param string $cache_id = ''
|
|
@@ -841,7 +841,7 @@ function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = arra
|
|
|
global $txt, $scripturl, $context, $modSettings, $user_info, $smcFunc;
|
|
|
static $bbc_codes = array(), $itemcodes = array(), $no_autolink_tags = array();
|
|
|
static $disabled;
|
|
|
-
|
|
|
+
|
|
|
// Don't waste cycles
|
|
|
if ($message === '')
|
|
|
return '';
|
|
@@ -849,7 +849,7 @@ function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = arra
|
|
|
// Just in case it wasn't determined yet whether UTF-8 is enabled.
|
|
|
if (!isset($context['utf8']))
|
|
|
$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
|
|
|
-
|
|
|
+
|
|
|
// Clean up any cut/paste issues we may have
|
|
|
$message = sanitizeMSCutPaste($message);
|
|
|
|
|
@@ -880,10 +880,10 @@ function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = arra
|
|
|
$temp_bbc = $bbc_codes;
|
|
|
$bbc_codes = array();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// Allow mods access before entering the main parse_bbc loop
|
|
|
call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
|
|
|
-
|
|
|
+
|
|
|
// Sift out the bbc for a performance improvement.
|
|
|
if (empty($bbc_codes) || $message === false || !empty($parse_tags))
|
|
|
{
|
|
@@ -1143,7 +1143,7 @@ function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = arra
|
|
|
'tag' => 'flash',
|
|
|
'type' => 'unparsed_commas_content',
|
|
|
'test' => '\d+,\d+\]',
|
|
|
- 'content' => (isBrowser('ie') && !isBrowser('mac_ie') ? '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="$2" height="$3"><param name="movie" value="$1" /><param name="play" value="true" /><param name="loop" value="true" /><param name="quality" value="high" /><param name="AllowScriptAccess" value="never" /><embed src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never" /><noembed><a href="$1" target="_blank" class="new_win">$1</a></noembed></object>' : '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never" /><noembed><a href="$1" target="_blank" class="new_win">$1</a></noembed>'),
|
|
|
+ 'content' => (isBrowser('ie') ? '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="$2" height="$3"><param name="movie" value="$1" /><param name="play" value="true" /><param name="loop" value="true" /><param name="quality" value="high" /><param name="AllowScriptAccess" value="never" /><embed src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never" /><noembed><a href="$1" target="_blank" class="new_win">$1</a></noembed></object>' : '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never" /><noembed><a href="$1" target="_blank" class="new_win">$1</a></noembed>'),
|
|
|
'validate' => create_function('&$tag, &$data, $disabled', '
|
|
|
if (isset($disabled[\'url\']))
|
|
|
$tag[\'content\'] = \'$1\';
|
|
@@ -2380,7 +2380,7 @@ function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = arra
|
|
|
|
|
|
// Allow mods access to what parse_bbc created
|
|
|
call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
|
|
|
-
|
|
|
+
|
|
|
// Cache the output if it took some time...
|
|
|
if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
|
|
|
cache_put_data($cache_key, $message, 240);
|
|
@@ -2408,7 +2408,7 @@ function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = arra
|
|
|
* These are specifically not parsed in code tags [url=mailto:[email protected]]
|
|
|
* Caches the smileys from the database or array in memory.
|
|
|
* Doesn't return anything, but rather modifies message directly.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param string &$message
|
|
|
*/
|
|
|
function parsesmileys(&$message)
|
|
@@ -2707,7 +2707,7 @@ function obExit($header = null, $do_footer = null, $from_index = false, $from_fa
|
|
|
function url_image_size($url)
|
|
|
{
|
|
|
global $sourcedir;
|
|
|
-
|
|
|
+
|
|
|
// Make sure it is a proper URL.
|
|
|
$url = str_replace(' ', '%20', $url);
|
|
|
|
|
@@ -2905,8 +2905,6 @@ function setupThemeContext($forceload = false)
|
|
|
// If we've upgraded recently, go easy on the passwords.
|
|
|
if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
|
|
|
$context['disable_login_hashing'] = true;
|
|
|
- elseif (isBrowser('ie5') || isBrowser('ie5.5'))
|
|
|
- $context['disable_login_hashing'] = true;
|
|
|
}
|
|
|
|
|
|
// Setup the main menu items.
|
|
@@ -2941,7 +2939,7 @@ function setupThemeContext($forceload = false)
|
|
|
var smf_avatarMaxWidth = ' . (int) $modSettings['avatar_max_width_external'] . ';
|
|
|
var smf_avatarMaxHeight = ' . (int) $modSettings['avatar_max_height_external'] . ';';
|
|
|
|
|
|
- if (!isBrowser('ie') && !isBrowser('mac_ie'))
|
|
|
+ if (!isBrowser('ie'))
|
|
|
$context['html_headers'] .= '
|
|
|
window.addEventListener("load", smf_avatarResize, false);';
|
|
|
else
|
|
@@ -2997,7 +2995,7 @@ function setMemoryLimit($needed, $in_use = false)
|
|
|
$memory_used = 0;
|
|
|
$memory_current = memoryReturnBytes(ini_get('memory_limit'));
|
|
|
$memory_needed = memoryReturnBytes($needed);
|
|
|
-
|
|
|
+
|
|
|
// should we account for how much is currently being used?
|
|
|
if ($in_use)
|
|
|
$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
|
|
@@ -3025,12 +3023,12 @@ function memoryReturnBytes($val)
|
|
|
{
|
|
|
if (is_integer($val))
|
|
|
return $val;
|
|
|
-
|
|
|
+
|
|
|
// Separate the number from the designator
|
|
|
$val = trim($val);
|
|
|
$num = intval(substr($val, 0, strlen($val) - 1));
|
|
|
$last = strtolower(substr($val, -1));
|
|
|
-
|
|
|
+
|
|
|
// convert to bytes
|
|
|
switch ($last)
|
|
|
{
|
|
@@ -3055,7 +3053,7 @@ function template_rawdata()
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
+ *
|
|
|
*/
|
|
|
function template_header()
|
|
|
{
|
|
@@ -3198,7 +3196,7 @@ function theme_copyright()
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
+ *
|
|
|
*/
|
|
|
function template_footer()
|
|
|
{
|
|
@@ -3222,7 +3220,7 @@ function template_footer()
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Output the Javascript files
|
|
|
+ * Output the Javascript files
|
|
|
* - tabbing in this function is to make the HTML source look good proper
|
|
|
* - if defered is set function will output all JS (source & inline) set to load at page end
|
|
|
*
|
|
@@ -3234,7 +3232,7 @@ function template_javascript($do_defered = false)
|
|
|
|
|
|
// Use this hook to minify/optimize Javascript files and vars
|
|
|
call_integration_hook('pre_javascript_output');
|
|
|
-
|
|
|
+
|
|
|
// Ouput the declared Javascript variables.
|
|
|
if (!empty($context['javascript_vars']) && !$do_defered)
|
|
|
{
|
|
@@ -3255,7 +3253,7 @@ function template_javascript($do_defered = false)
|
|
|
if ((!$do_defered && empty($js_file['options']['defer'])) || ($do_defered && !empty($js_file['options']['defer'])))
|
|
|
echo '
|
|
|
<script type="text/javascript" src="', $js_file['filename'], '" id="', $id,'"' , !empty($js_file['options']['async']) ? ' async="async"' : '' ,'></script>';
|
|
|
-
|
|
|
+
|
|
|
// If we are loading JQuery and we are set to 'auto' load, put in our remote success or load local check
|
|
|
if ($id == 'jquery' && (!isset($modSettings['jquery_source']) || !in_array($modSettings['jquery_source'],array('local', 'cdn'))))
|
|
|
echo '
|
|
@@ -3264,7 +3262,7 @@ function template_javascript($do_defered = false)
|
|
|
// ]]></script>';
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// Inline JavaScript - Actually useful some times!
|
|
|
if (!empty($context['javascript_inline']))
|
|
|
{
|
|
@@ -3275,7 +3273,7 @@ function template_javascript($do_defered = false)
|
|
|
|
|
|
foreach ($context['javascript_inline']['defer'] as $js_code)
|
|
|
echo $js_code;
|
|
|
-
|
|
|
+
|
|
|
echo'
|
|
|
// ]]></script>';
|
|
|
}
|
|
@@ -3287,7 +3285,7 @@ function template_javascript($do_defered = false)
|
|
|
|
|
|
foreach ($context['javascript_inline']['standard'] as $js_code)
|
|
|
echo $js_code;
|
|
|
-
|
|
|
+
|
|
|
echo'
|
|
|
// ]]></script>';
|
|
|
}
|
|
@@ -3585,7 +3583,7 @@ function text2words($text, $max_chars = 20, $encrypt = false)
|
|
|
|
|
|
/**
|
|
|
* Creates an image/text button
|
|
|
- *
|
|
|
+ *
|
|
|
* @param string $filename
|
|
|
* @param string $alt
|
|
|
* @param string $label = ''
|
|
@@ -3619,12 +3617,12 @@ function create_button($name, $alt, $label = '', $custom = '', $force_use = fals
|
|
|
* - If no type is specified will perfom a complete cache clearing
|
|
|
* For cache engines that do not distinguish on types, a full cache flush will be done
|
|
|
*
|
|
|
- * @param string $type = ''
|
|
|
+ * @param string $type = ''
|
|
|
*/
|
|
|
function clean_cache($type = '')
|
|
|
{
|
|
|
global $cachedir, $sourcedir, $cache_accelerator, $modSettings, $memcached;
|
|
|
-
|
|
|
+
|
|
|
switch ($cache_accelerator)
|
|
|
{
|
|
|
case 'memcached':
|
|
@@ -3645,11 +3643,11 @@ function clean_cache($type = '')
|
|
|
break;
|
|
|
case 'eaccelerator':
|
|
|
if (function_exists('eaccelerator_clear') && function_exists('eaccelerator_clean') )
|
|
|
- {
|
|
|
+ {
|
|
|
// Clean out the already expired items
|
|
|
@eaccelerator_clean();
|
|
|
-
|
|
|
- // Remove all unused scripts and data from shared memory and disk cache,
|
|
|
+
|
|
|
+ // Remove all unused scripts and data from shared memory and disk cache,
|
|
|
// e.g. all data that isn't used in the current requests.
|
|
|
eaccelerator_clear();
|
|
|
}
|
|
@@ -3681,7 +3679,7 @@ function clean_cache($type = '')
|
|
|
case 'xcache':
|
|
|
if (function_exists('xcache_clear_cache'))
|
|
|
{
|
|
|
- //
|
|
|
+ //
|
|
|
if ($type === '')
|
|
|
{
|
|
|
xcache_clear_cache(XC_TYPE_VAR, 0);
|
|
@@ -3734,7 +3732,7 @@ function loadClassFile($filename)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
+ *
|
|
|
*/
|
|
|
function setupMenuContext()
|
|
|
{
|
|
@@ -4176,10 +4174,10 @@ function remove_integration_function($hook, $function)
|
|
|
function sanitizeMSCutPaste($string)
|
|
|
{
|
|
|
global $context;
|
|
|
-
|
|
|
+
|
|
|
if (empty($string))
|
|
|
return $string;
|
|
|
-
|
|
|
+
|
|
|
// UTF-8 occurences of MS special characters
|
|
|
$findchars_utf8 = array(
|
|
|
"\xe2\80\x9a", // single low-9 quotation mark
|
|
@@ -4192,7 +4190,7 @@ function sanitizeMSCutPaste($string)
|
|
|
"\xe2\x80\x93", // en dash
|
|
|
"\xe2\x80\x94", // em dash
|
|
|
);
|
|
|
-
|
|
|
+
|
|
|
// windows 1252 / iso equivalents
|
|
|
$findchars_iso = array(
|
|
|
chr(130),
|
|
@@ -4218,7 +4216,7 @@ function sanitizeMSCutPaste($string)
|
|
|
'-', // –
|
|
|
'--', // —
|
|
|
);
|
|
|
-
|
|
|
+
|
|
|
if ($context['utf8'])
|
|
|
$string = str_replace($findchars_utf8, $replacechars, $string);
|
|
|
else
|