', '"');
$split = false;
foreach ($chars as $char) {
$next_split = strpos($url, $char);
if ($next_split !== false) {
$split = ($split !== false) ? min($split, $next_split) : $next_split;
}
}
if ($split !== false) {
$url = substr($url, 0, $split);
$relative_url = '';
} else if ($relative_url) {
$split = false;
foreach ($chars as $char) {
$next_split = strpos($relative_url, $char);
if ($next_split !== false) {
$split = ($split !== false) ? min($split, $next_split) : $next_split;
}
}
if ($split !== false) {
$relative_url = substr($relative_url, 0, $split);
}
}
$last_char = ($relative_url) ? $relative_url[strlen($relative_url) - 1] : $url[strlen($url) - 1];
switch ($last_char)
{
case '.':
case '?':
case '!':
case ':':
case ',':
$append = $last_char;
if ($relative_url) $relative_url = substr($relative_url, 0, -1);
else $url = substr($url, 0, -1);
break;
default:
$append = '';
break;
}
$short_url = (mb_strlen($url) > 40) ? mb_substr($url, 0, 30) . ' ... ' . mb_substr($url, -5) : $url;
switch ($type)
{
case 1:
$relative_url = preg_replace('/[&?]sid=[0-9a-f]{32}$/', '', preg_replace('/([&?])sid=[0-9a-f]{32}&/', '$1', $relative_url));
$url = $url . '/' . $relative_url;
$text = $relative_url;
if (!$relative_url) {
return $whitespace . $orig_url . '/' . $orig_relative;
}
break;
case 2:
$text = $short_url;
if (!isset(core::$user_set['direct_url']) || !core::$user_set['direct_url']) {
$url = core::$system_set['homeurl'] . '/go.php?url=' . rawurlencode($url);
}
break;
case 3:
$url = 'http://' . $url;
$text = $short_url;
if (!isset(core::$user_set['direct_url']) || !core::$user_set['direct_url']) {
$url = core::$system_set['homeurl'] . '/go.php?url=' . rawurlencode($url);
}
break;
case 4:
$text = $short_url;
$url = 'mailto:' . $url;
break;
}
$url = htmlspecialchars($url);
$text = htmlspecialchars($text);
$append = htmlspecialchars($append);
return $whitespace . '' . $text . '' . $append;
}
}
static $url_match;
static $url_replace;
if (!is_array($url_match)) {
$url_match = $url_replace = array();
// Обработка внутренние ссылки
$url_match[] = '#(^|[\n\t (>.])(' . preg_quote(core::$system_set['homeurl'], '#') . ')/((?:[a-zа-яё0-9\-._~!$&\'(*+,;=:@|]+|%[\dA-F]{2})*(?:/(?:[a-zа-яё0-9\-._~!$&\'(*+,;=:@|]+|%[\dA-F]{2})*)*(?:\?(?:[a-zа-яё0-9\-._~!$&\'(*+,;=:@/?|]+|%[\dA-F]{2})*)?(?:\#(?:[a-zа-яё0-9\-._~!$&\'(*+,;=:@/?|]+|%[\dA-F]{2})*)?)#ieu';
$url_replace[] = "url_callback(1, '\$1', '\$2', '\$3')";
// Обработка обычных ссылок типа xxxx://aaaaa.bbb.cccc. ...
$url_match[] = '#(^|[\n\t (>.])([a-z][a-z\d+]*:/{2}(?:(?:[a-zа-яё0-9\-._~!$&\'(*+,;=:@|]+|%[\dA-F]{2})+|[0-9.]+|\[[a-zа-яё0-9.]+:[a-zа-яё0-9.]+:[a-zа-яё0-9.:]+\])(?::\d*)?(?:/(?:[a-zа-яё0-9\-._~!$&\'(*+,;=:@|]+|%[\dA-F]{2})*)*(?:\?(?:[a-zа-яё0-9\-._~!$&\'(*+,;=:@/?|]+|%[\dA-F]{2})*)?(?:\#(?:[a-zа-яё0-9\-._~!$&\'(*+,;=:@/?|]+|%[\dA-F]{2})*)?)#ieu';
$url_replace[] = "url_callback(2, '\$1', '\$2', '')";
// Обработка сокращенных ссылок, без указания протокола "www.xxxx.yyyy[/zzzz]"
$url_match[] = '#(^|[\n\t (>])(www\.(?:[a-zа-яё0-9\-._~!$&\'(*+,;=:@|]+|%[\dA-F]{2})+(?::\d*)?(?:/(?:[a-zа-яё0-9\-._~!$&\'(*+,;=:@|]+|%[\dA-F]{2})*)*(?:\?(?:[a-zа-яё0-9\-._~!$&\'(*+,;=:@/?|]+|%[\dA-F]{2})*)?(?:\#(?:[a-zа-яё0-9\-._~!$&\'(*+,;=:@/?|]+|%[\dA-F]{2})*)?)#ieu';
$url_replace[] = "url_callback(3, '\$1', '\$2', '')";
}
return preg_replace($url_match, $url_replace, $text);
}
/*
-----------------------------------------------------------------
Удаление bbCode из текста
-----------------------------------------------------------------
*/
static function notags($var = '')
{
$var = preg_replace('#\[color=(.+?)\](.+?)\[/color]#si', '$2', $var);
$var = preg_replace('!\[bg=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z\-]+)](.+?)\[/bg]!is', '$2', $var);
$var = preg_replace('#\[spoiler=(.+?)\](.+?)\[/spoiler]#si', '$2', $var);
$replace = array(
'[small]' => '',
'[/small]' => '',
'[big]' => '',
'[/big]' => '',
'[green]' => '',
'[/green]' => '',
'[red]' => '',
'[/red]' => '',
'[blue]' => '',
'[/blue]' => '',
'[b]' => '',
'[/b]' => '',
'[i]' => '',
'[/i]' => '',
'[u]' => '',
'[/u]' => '',
'[s]' => '',
'[/s]' => '',
'[quote]' => '',
'[/quote]' => '',
'[c]' => '',
'[/c]' => '',
'[*]' => '',
'[/*]' => ''
);
return strtr($var, $replace);
}
/*
-----------------------------------------------------------------
Подсветка кода
-----------------------------------------------------------------
*/
private static function highlight_code($var)
{
if (!function_exists('process_code')) {
function process_code($php)
{
$php = strtr($php, array('
' => '', '\\' => 'slash_JOHNCMS'));
$php = html_entity_decode(trim($php), ENT_QUOTES, 'UTF-8');
$php = substr($php, 0, 2) != "" ? "" : $php;
$php = highlight_string(stripslashes($php), true);
$php = strtr($php, array('slash_JOHNCMS' => '\', ':' => ':', '[' => '['));
return '