';
return $index;
}
/* Constructs a page list.
ie. $pageindex = constructPageIndex($scripturl . '?board=' . $board, $_REQUEST['start'], $num_messages, $maxindex, true); */
function constructPageIndex($base_url, &$start, $max_value, $num_per_page, $compact_start = false, $additional = '')
{
global $modSettings;
// Save whether $start was less than 0 or not.
$start_invalid = $start < 0;
// Make sure $start is a proper variable - not less than 0.
if ($start_invalid)
$start = 0;
// Not greater than the upper bound.
elseif ($start >= $max_value)
$start = (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page));
// And it has to be a multiple of $num_per_page!
else
$start = (int) $start - ((int) $start % (int) $num_per_page);
// Somehow $start ended up zero through the subtractions... fix it.
if ($start < 0)
$start = 0;
// Wireless will need the protocol on the URL somewhere.
if (WIRELESS)
{
$base_url .= ';' . WIRELESS_PROTOCOL;
$compact_start = false;
}
$base_link = '« ';
// Show all the pages.
$display_page = 1;
for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
$pageindex .= $start == $counter && !$start_invalid ? $display_page++ : $base_link . $counter . ($additional == '' ? '': ';' . $additional) . '">' . $display_page++ . ' ';
// Show the right arrow.
$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
if ($start != $counter - $max_value && !$start_invalid)
$pageindex .= $display_page > $counter - $num_per_page ? ' ' : $base_link . $display_page . ($additional == '' ? '': ';' . $additional) . '">» ';
}
else
{
// If they didn't enter an odd value, pretend they did.
$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
// Show the first page. (>1< ... 6 7 [8] 9 10 ... 15)
if ($start > $num_per_page * $PageContiguous)
$pageindex = $base_link . '0">1 ';
else
$pageindex = '';
// Show the ... after the first page. (1 >...< 6 7 [8] 9 10 ... 15)
if ($start > $num_per_page * ($PageContiguous + 1))
$pageindex .= ' ... ';
// Show the pages before the current one. (1 ... >6 7< [8] 9 10 ... 15)
for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
if ($start >= $num_per_page * $nCont)
{
$tmpStart = $start - $num_per_page * $nCont;
$pageindex.= $base_link . $tmpStart . ($additional == '' ? '': ';' . $additional) . '">' . ($tmpStart / $num_per_page + 1) . ' ';
}
// Show the current page. (1 ... 6 7 >[8]< 9 10 ... 15)
if (!$start_invalid)
$pageindex .= '[' . ($start / $num_per_page + 1) . '] ';
else
$pageindex .= $base_link . $start . ($additional == '' ? '': ';' . $additional) . '">' . ($start / $num_per_page + 1) . ' ';
// Show the pages after the current one... (1 ... 6 7 [8] >9 10< ... 15)
$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
if ($start + $num_per_page * $nCont <= $tmpMaxPages)
{
$tmpStart = $start + $num_per_page * $nCont;
$pageindex .= $base_link . $tmpStart . ($additional == '' ? '': ';' . $additional) . '">' . ($tmpStart / $num_per_page + 1) . ' ';
}
// Show the '...' part near the end. (1 ... 6 7 [8] 9 10 >...< 15)
if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
$pageindex .= ' ... ';
// Show the last number in the list. (1 ... 6 7 [8] 9 10 ... >15<)
if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
$pageindex .= $base_link . $tmpMaxPages . ($additional == '' ? '': ';' . $additional) . '">' . ($tmpMaxPages / $num_per_page + 1) . ' ';
}
return $pageindex;
}
// Formats a number to display in the style of the admin's choosing.
function comma_format($number)
{
global $modSettings;
static $thousands_separator = null, $decimal_separator = null, $decimal_count = null;
// Cache these values...
if ($decimal_separator === null)
{
// Not set for whatever reason?
if (empty($modSettings['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $modSettings['number_format'], $matches) != 1)
return $number;
// Cache these each load...
$thousands_separator = $matches[1];
$decimal_separator = $matches[2];
$decimal_count = strlen($matches[3]);
}
// Format the string with our friend, number_format.
return number_format($number, is_float($number) ? $decimal_count : 0, $decimal_separator, $thousands_separator);
}
// Format a time to make it look purdy.
function timeformat($logTime, $show_today = true)
{
global $user_info, $txt, $db_prefix, $modSettings;
global $days, $months, $days_short, $months_short;
// Offset the time.
$time = $logTime + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
// We can't have a negative date!
if ($time < 0)
$time = 0;
// Today and Yesterday?
if ($modSettings['todayMod'] >= 1 && $show_today)
{
// Get the current time.
$nowtime = forum_time();
$then = @getdate($time);
$now = @getdate($nowtime);
// Try to make something of a time format string...
if (strpos($user_info['time_format'], '%H') === false && strpos($user_info['time_format'], '%T') === false)
$today_fmt = '%I:%M %p';
else
$today_fmt = '%H:%M';
// Same day of the year, same year.... Today!
if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
return $txt['smf10'] . strftime($today_fmt, $time);
// Day-of-year is one less and same year, or it's the first of the year and that's the last of the year...
if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
return $txt['smf10b'] . strftime($today_fmt, $time);
}
// Strip slashes off the time format string.
/* $str = $user_info['time_format'];
if (setlocale(LC_TIME, @$txt['lang_locale']))
{
$str = preg_replace('#%a#', ucwords(strftime('%a', $time)), $str);
$str = preg_replace('#%A#', ucwords(strftime('%A', $time)), $str);
$str = preg_replace('#%b#', ucwords(strftime('%b', $time)), $str);
$str = preg_replace('#%B#', ucwords(strftime('%B', $time)), $str);
}
else
{
// Do-it-yourself time localization. Fun.
$str = preg_replace('#%a#', @$days_short[(int) strftime('%w', $time)], $str);
$str = preg_replace('#%A#', @$days[(int) strftime('%w', $time)], $str);
$str = preg_replace('#%b#', @$months_short[(int) strftime('%m', $time)], $str);
$str = preg_replace('#%B#', @$months[(int) strftime('%m', $time)], $str);
$str = preg_replace('#%p#', (strftime('%H', $time) < 12 ? 'am' : 'pm'), $str);
}
// Format any other characters..
return strftime($str, $time);
*/
$fmt = datefmt_create("ru_RU", NULL, NULL, 'Europe/Minsk', NULL, "d MMMM yyyy, HH:mm");
return str_replace(' ', ' ', datefmt_format($fmt, $time));
}
// Removes special entities from strings. Compatibility...
function un_htmlspecialchars($string)
{
return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES)) + array(''' => '\'', ' ' => ' '));
}
// The current time with offset.
function forum_time($use_user_offset = true)
{
global $user_info, $modSettings;
return time() + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
}
// Parse smileys (if $enableSmileys is true) and BBC in $message.
function doUBBC($message, $enableSmileys = true, $disabledBBC = '')
{
global $txt, $modSettings, $context;
// Item codes - for
types. Used with [*], [@], [o], etc.
static $itemcode = array(
'[*]' => '
',
'[@]' => '
',
'[+]' => '
',
'[x]' => '
',
'[#]' => '
',
'[o]' => '
',
'[O]' => '
',
'[upload]' => ''
);
if (empty($modSettings['enableBBC']))
return $message;
if (substr($message, 0, 1) == ' ')
$message = ' ' . substr($message, 1);
// Rip apart code tags.
$parts = preg_split('~\[/?code\]( )?~', ' ' . strtr($message, array("\n" => ' ')));
// For each part....
for ($i = 0, $n = count($parts); $i < $n; $i++)
{
// If we're outside a block... (0: outside, 1: inside, 2: outside, 3: inside, etc.)
if ($i % 2 == 0)
{
// Close the Code block, unless this is the first block. (meaning it wasn't opened yet.)
if ($i > 0)
$parts[$i] = '' . $parts[$i];
// Find any [php] code tags.... CAPTURING the delimiter.
$php_parts = preg_split('~(\[php\])(?: )?|(\[/php\])~', $parts[$i], -1, PREG_SPLIT_DELIM_CAPTURE);
for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
{
// Do PHP code coloring. (this is a start tag, so everything until a [/php] should be highlighted.)
if ($php_parts[$php_i] == '[php]')
{
// Get rid of the start tag.
$php_parts[$php_i] = '';
$php_string = '';
while ($php_i < count($php_parts) && $php_parts[$php_i] != '[/php]')
{
$php_string .= $php_parts[$php_i];
// This makes it easier; jut clear it out and let the implode do all the work.
$php_parts[$php_i++] = '';
}
// Highlight the PHP code, and then remove the ?php and ? we added to do so.
$php_parts[$php_i] = highlight_php_code(substr(trim($php_string), 0, 5) != '<?' ? '<?php' . $php_string . '?>' : $php_string);
if (substr(trim($php_string), 0, 5) != '<?')
$php_parts[$php_i] = preg_replace(array('~^(.+?)<\?php~', '~\?>((?:)*)$~'), '$1', $php_parts[$php_i], 1);
$did_php = true;
}
else
$did_php = false;
// Parse any URLs.... have to get rid of the @ problems some things cause... stupid email addresses.
if (!empty($modSettings['autoLinkUrls']) && (strpos($php_parts[$php_i], '://') !== false || strpos($php_parts[$php_i], 'www.') !== false))
{
// Switch out quotes really quick because they can cause problems.
$php_parts[$php_i] = strtr($php_parts[$php_i], array(''' => '\'', ' ' => '\xA0', '"' => '>">', '"' => '<"<', '<' => '\.(;\'"])((?:http|https|ftp|ftps)://[\w\-_@:|]+(?:\.[\w\-_]+)*(?::\d+)?(?:/[\w\-_\~%\.@,\?&;=#+:\']*|\([\w\-_\~%\.@,\?&;=#()+:\']*)*[/\w\-_\~%@\?;=#])~i', '~(?<=[\s>(\'])(www(?:\.[\w\-_]+)+(?::\d+)?(?:/[\w\-_\~%\.@,\?&;=#+:\']*|\([\w\-_\~%\.@,\?&;=#()+:\']*)*[/\w\-_\~%@\?;=#])~i'), array('[url]$1[/url]', '[url=http://$1]$1[/url]'), $php_parts[$php_i]);
$php_parts[$php_i] = strtr($php_parts[$php_i], array('\'' => ''', '\xA0' => ' ', '>">' => '"', '<"<' => '"', ' '<'));
}
// Parse code.....
parsecode($php_parts[$php_i],$disabledBBC);
// Parse smileys?
if (!$enableSmileys || $did_php)
continue;
// This isn't code; change any tabs to spaces.
$php_parts[$php_i] = strtr($php_parts[$php_i], array("\t" => ' '));
// Often requested but also very kludgey; break long words.
if (!empty($modSettings['fixLongWords']))
{
// This is SADLY and INCREDIBLY browser dependent.
if ($context['browser']['is_gecko'] || strpos($_SERVER['HTTP_USER_AGENT'], 'Konqueror') !== false)
$breaker = '';
// Opera...
elseif ($context['browser']['is_opera'])
$breaker = '';
// Internet Explorer...
else
$breaker = '';
// The idea is, find words xx long, and then replace them with xx + space + more.
$php_parts[$php_i] = preg_replace(
'/(?<=[>;:\?\.\! \xA0\]()])(\w{' . $modSettings['fixLongWords'] . ',})/e',
"preg_replace('/(.{" . $modSettings['fixLongWords'] . "})/', '\\\$1$breaker', '\$1')",
$php_parts[$php_i]);
}
// Figure out smileys...
parsesmileys($php_parts[$php_i]);
// List items - warning they might disrupt your code...
if (empty($modSettings['disabledBBC']) || preg_match('~[\s,](list|li)[\s,]~', $modSettings['disabledBBC']) == 0)
{
$php_parts[$php_i] = strtr($php_parts[$php_i], $itemcode);
// Now do the [0], which is special and sometimes annoying.
$php_parts[$php_i] = preg_replace('~([ \t>]| )\[0\]~', '$1
',
// An email address they just typed in. Don't match if there's already a mailto: or = before it.
'~(?<=[\?\s\xA0[\]()*\\\;>]|^)([\w\-\.]{1,80}@[\w\-]+\.[\w\-\.]+[\w\-])(?=[?,\s\xA0\[\]()*\\\]|$| | |>|<|"|'|\.(?:\.| |\s|$| ))~i' => '$1',
'~(?<= )([\w\-\.]{1,80}@[\w\-]+\.[\w\-\.]+[\w\-])(?=[?\.,\s\xA0\[\]()*\\\]|$| | |>|<|"|')~i' => '$1',
// This last one fixes spaces at the beginning of lines.
'~ ~' => ' ',
// Match a table... hopefully with everything in the right place.
'~\[table\](?:\s|\xA0| | )*((?:\[tr\](?:\s|\xA0| | )*\[td\]).*?(?:(?:\s|\xA0| | )*\[/td\]\[/tr\])*)(?:\s|\xA0| | )*\[/table\](?:\s|\xA0| | )?~i' => '