Быстрый лёгкий надёжный форумный движок
Вы не вошли.
Страницы 1
@47linux, атрибут rel="nofollow" в ссылках сейчас сделанный не устраивает?
P.S. https://support.google.com/webmasters/a … 6569?hl=ru
Моя сборка FluxBB 1.5, ForkBB · сообщество
Offline
Реализация в fluxbb
There are two hard things in computer science: cache invalidation, naming things, and off-by-one errors.
Offline
Да, вопрос сложный ...
яваскриптом убирать nofollow
<?php if ($signature != '') echo "\t\t\t\t\t".'<div id="signature" class="postsignature postmsg"><hr />'.$signature.'</div>'."\n"; ?>
просто как вариант и не для поисковика
Offline
Хак для скрытия всех внешних ссылок через редирект на Fluxbb
(с возможностью оставить открытой любую необходимую ссылку)
Когда хак будет настроен, все внешние ссылки с сайта, включая ссылки в бб-кодах url, в описаниях профилей и на страницах профилей, будут работать редиректом через файл go.php
Таким образом все внешние ссылки будут иметь следующий вид:
http://site.ru/go.php?to=http://yandex.ru
Затем данный файл для надежности закрывается от индексации в robots.txt с помощью такой директивы:
Disallow: go.php
Чтобы иметь возможность оставлять некоторые ссылки открытыми, мы добавим на форум дополнительный бб-код [rurl]. Далее в инструкции в коде в качестве бб-кода будет использоваться rurl, но вы можете использовать любой другой (скажем [refurl231], чтобы защитить свой форум от спамеров, которые возможно набредут на инструкцию по этому хаку. Это маловероятно, но всё же.
Инструкция для Fluxbb 1.5.10:
1) Создаем в корне форума файл с названием go.php и таким содержанием:
<?php
$to_link = $_GET["to"];
$URL = substr_replace($URL, $to_link, 0);
header ("Location: $URL");
?>
2) Находим в файле /includes/parser.php функцию handle_url_tag, в которой нас интересует вот эта часть:
return '<a href="'.$full_url.'" rel="nofollow">'.$link.'</a>';
Заменяем её на это, изменив site.ru на ваш домен:
return '<a href="http://site.ru/go.php?to='.$full_url.'" rel="nofollow">'.$link.'</a>';
Теперь все ссылки в бб-коде url будут идти редиректом через go.php
3) Чтобы иметь возможность оставлять некоторые ссылки прямыми, без редиректов и rel=nofollow, нам нужна точно такая же функция, но которая будет обрабатывать ссылки, скажем, в бб-коде [rurl] и выдавать их напрямую, без подстановки go.php.
Для этого мы полностью копируем функцию handle_url_tag, переименовываем её в handle_rurl_tag, приводим строчку return к такому виду:
return '<a href="'.$full_url.'">'.$link.'</a>';
А также находим вот этот кусок кода:
if ($bbcode)
{
if ($full_url == $link)
return '[url]'.$link.'[/url]';
else
return '[url='.$full_url.']'.$link.'[/url]';
}
И заменяем в нём все url, на rurl. Получится вот так:
if ($bbcode)
{
if ($full_url == $link)
return '[rurl]'.$link.'[/rurl]';
else
return '[rurl='.$full_url.']'.$link.'[/rurl]';
}
Вы могли заметить, что помимо отсутствия go.php мы также убрали и rel="nofollow".
Напоминаю, что если вы хотите получить в итоге не [rurl] бб-код для открытых ссылок, а какой-то другой, то начиная с этого момента и далее все rurl вам надо заменять на свой вариант.
В итоге у вас должна получиться вот такая картина:
function handle_rurl_tag($url, $link = '', $bbcode = false)
{
$url = pun_trim($url);
// Deal with [url][img]http://example.com/test.png[/img][/url]
if (preg_match('%<img src=\"(.*?)\"%', $url, $matches))
return handle_url_tag($matches[1], $url, $bbcode);
$full_url = str_replace(array(' ', '\'', '`', '"'), array('%20', '', '', ''), $url);
if (!preg_match('#^([a-z0-9]{3,6})://#', $url)) // Else if it doesn't start with abcdef://, we add http://
$full_url = 'http://'.$full_url;
// Ok, not very pretty :-)
if ($bbcode)
{
if ($full_url == $link)
return '[rurl]'.$link.'[/rurl]';
else
return '[rurl='.$full_url.']'.$link.'[/rurl]';
}
else
{
if ($link == '' || $link == $url)
{
$url = pun_htmlspecialchars_decode($url);
$link = utf8_strlen($url) > 55 ? utf8_substr($url, 0 , 39).' … '.utf8_substr($url, -10) : $url;
$link = pun_htmlspecialchars($link);
}
else
$link = stripslashes($link);
return '<a href="'.$full_url.'">'.$link.'</a>';
}
}
Вот пример parser.php для Fluxbb v1.5.10.39:
<?php
/**
* Copyright (C) 2008-2012 FluxBB
* based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
* License: [url]http://www.gnu.org/licenses/gpl.html[/url] GPL version 2 or higher
*/
// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
exit;
// Global variables
/* regular expression to match nested BBCode LIST tags
'%
\[list # match opening bracket and tag name of outermost LIST tag
(?:=([1a*]))?+ # optional attribute capture in group 1
\] # closing bracket of outermost opening LIST tag
( # capture contents of LIST tag in group 2
(?: # non capture group for either contents or whole nested LIST
[^\[]*+ # unroll the loop! consume everything up to next [ (normal *)
(?: # (See "Mastering Regular Expressions" chapter 6 for details)
(?! # negative lookahead ensures we are NOT on [LIST*] or [/LIST]
\[list # opening LIST tag
(?:=[1a*])?+ # with optional attribute
\] # closing bracket of opening LIST tag
| # or...
\[/list\] # a closing LIST tag
) # end negative lookahead assertion (we are not on a LIST tag)
\[ # match the [ which is NOT the start of LIST tag (special)
[^\[]*+ # consume everything up to next [ (normal *)
)*+ # finish up "unrolling the loop" technique (special (normal*))*
| # or...
(?R) # recursively match a whole nested LIST element
)* # as many times as necessary until deepest nested LIST tag grabbed
) # end capturing contents of LIST tag into group 2
\[/list\] # match outermost closing LIST tag
%iex' */
$re_list = '%\[list(?:=([1a*]))?+\]((?:[^\[]*+(?:(?!\[list(?:=[1a*])?+\]|\[/list\])\[[^\[]*+)*+|(?R))*)\[/list\]%i';
// Here you can add additional smilies if you like (please note that you must escape single quote and backslash)
$smilies = array(
':)' => 'smile.png',
'=)' => 'smile.png',
':|' => 'neutral.png',
'=|' => 'neutral.png',
':(' => 'sad.png',
'=(' => 'sad.png',
':D' => 'big_smile.png',
'=D' => 'big_smile.png',
':o' => 'yikes.png',
':O' => 'yikes.png',
';)' => 'wink.png',
':/' => 'hmm.png',
':P' => 'tongue.png',
':p' => 'tongue.png',
':lol:' => 'lol.png',
':mad:' => 'mad.png',
':rolleyes:' => 'roll.png',
':cool:' => 'cool.png');
//
// Make sure all BBCodes are lower case and do a little cleanup
//
function preparse_bbcode($text, &$errors, $is_signature = false)
{
global $pun_config, $lang_common, $lang_post, $re_list;
// Remove empty tags
while (($new_text = strip_empty_bbcode($text)) !== false)
{
if ($new_text != $text)
{
$text = $new_text;
if ($new_text == '')
{
$errors[] = $lang_post['Empty after strip'];
return '';
}
}
else
break;
}
if ($is_signature)
{
global $lang_profile;
if (preg_match('%\[/?(?:quote|code|list|h)\b[^\]]*\]%i', $text))
$errors[] = $lang_profile['Signature quote/code/list/h'];
}
// If the message contains a code tag we have to split it up (text within shouldn't be touched)
if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false)
list($inside, $text) = extract_blocks($text, '[code]', '[/code]');
// Tidy up lists
$temp = preg_replace_callback($re_list, create_function('$matches', 'return preparse_list_tag($matches[2], $matches[1]);'), $text);
// If the regex failed
if (is_null($temp))
$errors[] = $lang_common['BBCode list size error'];
else
$text = str_replace('*'."\0".']', '*]', $temp);
if ($pun_config['o_make_links'] == '1')
$text = do_clickable($text);
$temp_text = false;
if (empty($errors))
$temp_text = preparse_tags($text, $errors, $is_signature);
if ($temp_text !== false)
$text = $temp_text;
// If we split up the message before we have to concatenate it together again (code tags)
if (isset($inside))
{
$outside = explode("\1", $text);
$text = '';
$num_tokens = count($outside);
for ($i = 0; $i < $num_tokens; ++$i)
{
$text .= $outside[$i];
if (isset($inside[$i]))
$text .= '[code]'.$inside[$i].'[/code]';
}
unset($inside);
}
// Remove empty tags
while (($new_text = strip_empty_bbcode($text)) !== false)
{
if ($new_text != $text)
{
$text = $new_text;
if ($new_text == '')
{
$errors[] = $lang_post['Empty after strip'];
break;
}
}
else
break;
}
return pun_trim($text);
}
//
// Strip empty bbcode tags from some text
//
function strip_empty_bbcode($text)
{
// If the message contains a code tag we have to split it up (empty tags within are fine)
if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false)
list($inside, $text) = extract_blocks($text, '[code]', '[/code]');
// Remove empty tags
while (!is_null($new_text = preg_replace('%\[(b|u|s|ins|del|em|i|h|colou?r|quote|img|url|email|list|topic|post|forum|user)(?:\=[^\]]*)?\]\s*\[/\1\]%', '', $text)))
{
if ($new_text != $text)
$text = $new_text;
else
break;
}
// If we split up the message before we have to concatenate it together again (code tags)
if (isset($inside))
{
$parts = explode("\1", $text);
$text = '';
foreach ($parts as $i => $part)
{
$text .= $part;
if (isset($inside[$i]))
$text .= '[code]'.$inside[$i].'[/code]';
}
}
// Remove empty code tags
while (!is_null($new_text = preg_replace('%\[(code)\]\s*\[/\1\]%', '', $text)))
{
if ($new_text != $text)
$text = $new_text;
else
break;
}
return $text;
}
//
// Check the structure of bbcode tags and fix simple mistakes where possible
//
function preparse_tags($text, &$errors, $is_signature = false)
{
global $lang_common, $pun_config, $pun_user;
// Start off by making some arrays of bbcode tags and what we need to do with each one
// List of all the tags
$tags = array('quote', 'code', 'b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'img', 'list', '*', 'h', 'topic', 'post', 'forum', 'user');
// List of tags that we need to check are open (You could not put b,i,u in here then illegal nesting like [b][i][/b][/i] would be allowed)
$tags_opened = $tags;
// and tags we need to check are closed (the same as above, added it just in case)
$tags_closed = $tags;
// Tags we can nest and the depth they can be nested to
$tags_nested = array('quote' => $pun_config['o_quote_depth'], 'list' => 5, '*' => 5);
// Tags to ignore the contents of completely (just code)
$tags_ignore = array('code');
// Tags not allowed
$tags_forbidden = array();
// Block tags, block tags can only go within another block tag, they cannot be in a normal tag
$tags_block = array('quote', 'code', 'list', 'h', '*');
// Inline tags, we do not allow new lines in these
$tags_inline = array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'h', 'topic', 'post', 'forum', 'user');
// Tags we trim interior space
$tags_trim = array('img');
// Tags we remove quotes from the argument
$tags_quotes = array('url', 'email', 'img', 'topic', 'post', 'forum', 'user');
// Tags we limit bbcode in
$tags_limit_bbcode = array(
'*' => array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'list', 'img', 'code', 'topic', 'post', 'forum', 'user'),
'list' => array('*'),
'url' => array('img'),
'email' => array('img'),
'topic' => array('img'),
'post' => array('img'),
'forum' => array('img'),
'user' => array('img'),
'img' => array(),
'h' => array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'topic', 'post', 'forum', 'user'),
);
// Tags we can automatically fix bad nesting
$tags_fix = array('quote', 'b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'h', 'topic', 'post', 'forum', 'user');
// Disallow URL tags
if ($pun_user['g_post_links'] != '1')
$tags_forbidden[] = 'url';
$split_text = preg_split('%(\[[\*a-zA-Z0-9-/]*?(?:=.*?)?\])%', $text, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
$open_tags = array('fluxbb-bbcode');
$open_args = array('');
$opened_tag = 0;
$new_text = '';
$current_ignore = '';
$current_nest = '';
$current_depth = array();
$limit_bbcode = $tags;
$count_ignored = array();
foreach ($split_text as $current)
{
if ($current == '')
continue;
// Are we dealing with a tag?
if (substr($current, 0, 1) != '[' || substr($current, -1, 1) != ']')
{
// It's not a bbcode tag so we put it on the end and continue
// If we are nested too deeply don't add to the end
if ($current_nest)
continue;
$current = str_replace("\r\n", "\n", $current);
$current = str_replace("\r", "\n", $current);
if (in_array($open_tags[$opened_tag], $tags_inline) && strpos($current, "\n") !== false)
{
// Deal with new lines
$split_current = preg_split('%(\n\n+)%', $current, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
$current = '';
if (!pun_trim($split_current[0], "\n")) // The first part is a linebreak so we need to handle any open tags first
array_unshift($split_current, '');
for ($i = 1; $i < count($split_current); $i += 2)
{
$temp_opened = array();
$temp_opened_arg = array();
$temp = $split_current[$i - 1];
while (!empty($open_tags))
{
$temp_tag = array_pop($open_tags);
$temp_arg = array_pop($open_args);
if (in_array($temp_tag , $tags_inline))
{
array_push($temp_opened, $temp_tag);
array_push($temp_opened_arg, $temp_arg);
$temp .= '[/'.$temp_tag.']';
}
else
{
array_push($open_tags, $temp_tag);
array_push($open_args, $temp_arg);
break;
}
}
$current .= $temp.$split_current[$i];
$temp = '';
while (!empty($temp_opened))
{
$temp_tag = array_pop($temp_opened);
$temp_arg = array_pop($temp_opened_arg);
if (empty($temp_arg))
$temp .= '['.$temp_tag.']';
else
$temp .= '['.$temp_tag.'='.$temp_arg.']';
array_push($open_tags, $temp_tag);
array_push($open_args, $temp_arg);
}
$current .= $temp;
}
if (array_key_exists($i - 1, $split_current))
$current .= $split_current[$i - 1];
}
if (in_array($open_tags[$opened_tag], $tags_trim))
$new_text .= pun_trim($current);
else
$new_text .= $current;
continue;
}
// Get the name of the tag
$current_arg = '';
if (strpos($current, '/') === 1)
{
$current_tag = substr($current, 2, -1);
}
else if (strpos($current, '=') === false)
{
$current_tag = substr($current, 1, -1);
}
else
{
$current_tag = substr($current, 1, strpos($current, '=')-1);
$current_arg = substr($current, strpos($current, '=')+1, -1);
}
$current_tag = strtolower($current_tag);
// Is the tag defined?
if (!in_array($current_tag, $tags))
{
// It's not a bbcode tag so we put it on the end and continue
if (!$current_nest)
$new_text .= $current;
continue;
}
// We definitely have a bbcode tag
// Make the tag string lower case
if ($equalpos = strpos($current,'='))
{
// We have an argument for the tag which we don't want to make lowercase
if (strlen(substr($current, $equalpos)) == 2)
{
// Empty tag argument
$errors[] = sprintf($lang_common['BBCode error empty attribute'], $current_tag);
return false;
}
$current = strtolower(substr($current, 0, $equalpos)).substr($current, $equalpos);
}
else
$current = strtolower($current);
// This is if we are currently in a tag which escapes other bbcode such as code
// We keep a count of ignored bbcodes (code tags) so we can nest them, but
// only balanced sets of tags can be nested
if ($current_ignore)
{
// Increase the current ignored tags counter
if ('['.$current_ignore.']' == $current)
$count_ignored[$current_tag]++;
// Decrease the current ignored tags counter
if ('[/'.$current_ignore.']' == $current)
$count_ignored[$current_tag]--;
if ('[/'.$current_ignore.']' == $current && $count_ignored[$current_tag] == 0)
{
// We've finished the ignored section
$current = '[/'.$current_tag.']';
$current_ignore = '';
$count_ignored = array();
}
$new_text .= $current;
continue;
}
// Is the tag forbidden?
if (in_array($current_tag, $tags_forbidden))
{
if (isset($lang_common['BBCode error tag '.$current_tag.' not allowed']))
$errors[] = sprintf($lang_common['BBCode error tag '.$current_tag.' not allowed']);
else
$errors[] = sprintf($lang_common['BBCode error tag not allowed'], $current_tag);
return false;
}
if ($current_nest)
{
// We are currently too deeply nested so lets see if we are closing the tag or not
if ($current_tag != $current_nest)
continue;
if (substr($current, 1, 1) == '/')
$current_depth[$current_nest]--;
else
$current_depth[$current_nest]++;
if ($current_depth[$current_nest] <= $tags_nested[$current_nest])
$current_nest = '';
continue;
}
// Check the current tag is allowed here
if (!in_array($current_tag, $limit_bbcode) && $current_tag != $open_tags[$opened_tag])
{
$errors[] = sprintf($lang_common['BBCode error invalid nesting'], $current_tag, $open_tags[$opened_tag]);
return false;
}
if (substr($current, 1, 1) == '/')
{
// This is if we are closing a tag
if ($opened_tag == 0 || !in_array($current_tag, $open_tags))
{
// We tried to close a tag which is not open
if (in_array($current_tag, $tags_opened))
{
$errors[] = sprintf($lang_common['BBCode error no opening tag'], $current_tag);
return false;
}
}
else
{
// Check nesting
while (true)
{
// Nesting is ok
if ($open_tags[$opened_tag] == $current_tag)
{
array_pop($open_tags);
array_pop($open_args);
$opened_tag--;
break;
}
// Nesting isn't ok, try to fix it
if (in_array($open_tags[$opened_tag], $tags_closed) && in_array($current_tag, $tags_closed))
{
if (in_array($current_tag, $open_tags))
{
$temp_opened = array();
$temp_opened_arg = array();
$temp = '';
while (!empty($open_tags))
{
$temp_tag = array_pop($open_tags);
$temp_arg = array_pop($open_args);
if (!in_array($temp_tag, $tags_fix))
{
// We couldn't fix nesting
$errors[] = sprintf($lang_common['BBCode error no closing tag'], $temp_tag);
return false;
}
array_push($temp_opened, $temp_tag);
array_push($temp_opened_arg, $temp_arg);
if ($temp_tag == $current_tag)
break;
else
$temp .= '[/'.$temp_tag.']';
}
$current = $temp.$current;
$temp = '';
array_pop($temp_opened);
array_pop($temp_opened_arg);
while (!empty($temp_opened))
{
$temp_tag = array_pop($temp_opened);
$temp_arg = array_pop($temp_opened_arg);
if (empty($temp_arg))
$temp .= '['.$temp_tag.']';
else
$temp .= '['.$temp_tag.'='.$temp_arg.']';
array_push($open_tags, $temp_tag);
array_push($open_args, $temp_arg);
}
$current .= $temp;
$opened_tag--;
break;
}
else
{
// We couldn't fix nesting
$errors[] = sprintf($lang_common['BBCode error no opening tag'], $current_tag);
return false;
}
}
else if (in_array($open_tags[$opened_tag], $tags_closed))
break;
else
{
array_pop($open_tags);
array_pop($open_args);
$opened_tag--;
}
}
}
if (in_array($current_tag, array_keys($tags_nested)))
{
if (isset($current_depth[$current_tag]))
$current_depth[$current_tag]--;
}
if (in_array($open_tags[$opened_tag], array_keys($tags_limit_bbcode)))
$limit_bbcode = $tags_limit_bbcode[$open_tags[$opened_tag]];
else
$limit_bbcode = $tags;
$new_text .= $current;
continue;
}
else
{
// We are opening a tag
if (in_array($current_tag, array_keys($tags_limit_bbcode)))
$limit_bbcode = $tags_limit_bbcode[$current_tag];
else
$limit_bbcode = $tags;
if (in_array($current_tag, $tags_block) && !in_array($open_tags[$opened_tag], $tags_block) && $opened_tag != 0)
{
// We tried to open a block tag within a non-block tag
$errors[] = sprintf($lang_common['BBCode error invalid nesting'], $current_tag, $open_tags[$opened_tag]);
return false;
}
if (in_array($current_tag, $tags_ignore))
{
// It's an ignore tag so we don't need to worry about what's inside it
$current_ignore = $current_tag;
$count_ignored[$current_tag] = 1;
$new_text .= $current;
continue;
}
// Deal with nested tags
if (in_array($current_tag, $open_tags) && !in_array($current_tag, array_keys($tags_nested)))
{
// We nested a tag we shouldn't
$errors[] = sprintf($lang_common['BBCode error invalid self-nesting'], $current_tag);
return false;
}
else if (in_array($current_tag, array_keys($tags_nested)))
{
// We are allowed to nest this tag
if (isset($current_depth[$current_tag]))
$current_depth[$current_tag]++;
else
$current_depth[$current_tag] = 1;
// See if we are nested too deep
if ($current_depth[$current_tag] > $tags_nested[$current_tag])
{
$current_nest = $current_tag;
continue;
}
}
// Remove quotes from arguments for certain tags
if (strpos($current, '=') !== false && in_array($current_tag, $tags_quotes))
{
$current = preg_replace('%\['.$current_tag.'=("|\'|)(.*?)\\1\]\s*%i', '['.$current_tag.'=$2]', $current);
}
if (in_array($current_tag, array_keys($tags_limit_bbcode)))
$limit_bbcode = $tags_limit_bbcode[$current_tag];
$open_tags[] = $current_tag;
$open_args[] = $current_arg;
$opened_tag++;
$new_text .= $current;
continue;
}
}
// Check we closed all the tags we needed to
foreach ($tags_closed as $check)
{
if (in_array($check, $open_tags))
{
// We left an important tag open
$errors[] = sprintf($lang_common['BBCode error no closing tag'], $check);
return false;
}
}
if ($current_ignore)
{
// We left an ignore tag open
$errors[] = sprintf($lang_common['BBCode error no closing tag'], $current_ignore);
return false;
}
return $new_text;
}
//
// Preparse the contents of [list=*]
[*]bbcode
//
function preparse_list_tag($content, $type = '*')
{
global $lang_common, $re_list;
if (strlen($type) != 1)
$type = '*';
if (strpos($content,'[list') !== false)
{
$content = preg_replace_callback($re_list, create_function('$matches', 'return preparse_list_tag($matches[2], $matches[1]);'), $content);
}
$items = explode('[/*]
[*]', str_replace('"', '"', $content));
$content = '';
foreach ($items as $item)
{
if (pun_trim($item) != '')
$content .= '[*'."\0".']'.str_replace('', '', pun_trim($item)).'[/*'."\0".']'."\n";
}
return '[list='.$type.']'."\n".$content.'[/*]
[/list]';
}
//
// Truncate URL if longer than 55 characters (add http:// or ftp:// if missing)
//
function handle_url_tag($url, $link = '', $bbcode = false)
{
$url = pun_trim($url);
// Deal with [url][img]http://example.com/test.png[/img][/url]
if (preg_match('%<img src=\"(.*?)\"%', $url, $matches))
return handle_url_tag($matches[1], $url, $bbcode);
$full_url = str_replace(array(' ', '\'', '`', '"'), array('%20', '', '', ''), $url);
if (strpos($url, 'www.') === 0) // If it starts with www, we add http://
$full_url = 'http://'.$full_url;
else if (strpos($url, 'ftp.') === 0) // Else if it starts with ftp, we add ftp://
$full_url = 'ftp://'.$full_url;
else if (strpos($url, '/') === 0) // Allow for relative URLs that start with a slash
$full_url = get_base_url(true).$full_url;
else if (!preg_match('#^([a-z0-9]{3,6})://#', $url)) // Else if it doesn't start with abcdef://, we add http://
$full_url = 'http://'.$full_url;
// Ok, not very pretty :-)
if ($bbcode)
{
if ($full_url == $link)
return '[url]'.$link.'[/url]';
else
return '[url='.$full_url.']'.$link.'[/url]';
}
else
{
if ($link == '' || $link == $url)
{
$url = pun_htmlspecialchars_decode($url);
$link = utf8_strlen($url) > 55 ? utf8_substr($url, 0 , 39).' … '.utf8_substr($url, -10) : $url;
$link = pun_htmlspecialchars($link);
}
else
$link = stripslashes($link);
return '<a href="http://forum.ru/go.php?to='.$full_url.'" rel="nofollow">'.$link.'</a>';
}
}
function handle_rurl_tag($url, $link = '', $bbcode = false)
{
$url = pun_trim($url);
// Deal with [url][img]http://example.com/test.png[/img][/url]
if (preg_match('%<img src=\"(.*?)\"%', $url, $matches))
return handle_url_tag($matches[1], $url, $bbcode);
$full_url = str_replace(array(' ', '\'', '`', '"'), array('%20', '', '', ''), $url);
if (!preg_match('#^([a-z0-9]{3,6})://#', $url)) // Else if it doesn't start with abcdef://, we add http://
$full_url = 'http://'.$full_url;
// Ok, not very pretty :-)
if ($bbcode)
{
if ($full_url == $link)
return '[rurl]'.$link.'[/rurl]';
else
return '[rurl='.$full_url.']'.$link.'[/rurl]';
}
else
{
if ($link == '' || $link == $url)
{
$url = pun_htmlspecialchars_decode($url);
$link = utf8_strlen($url) > 55 ? utf8_substr($url, 0 , 39).' … '.utf8_substr($url, -10) : $url;
$link = pun_htmlspecialchars($link);
}
else
$link = stripslashes($link);
return '<a href="'.$full_url.'">'.$link.'</a>';
}
}
//
// Turns an URL from the [img] tag into an <img> tag or a <a href...> tag
//
function handle_img_tag($url, $is_signature = false, $alt = null)
{
global $lang_common, $pun_user;
if (is_null($alt))
$alt = basename($url);
$img_tag = '<a href="'.$url.'" rel="nofollow"><'.$lang_common['Image link'].' - '.$alt.'></a>';
if ($is_signature && $pun_user['show_img_sig'] != '0')
$img_tag = '<img class="sigimage" src="'.$url.'" alt="'.$alt.'" />';
else if (!$is_signature && $pun_user['show_img'] != '0')
$img_tag = '<span class="postimg"><img src="'.$url.'" alt="'.$alt.'" /></span>';
return $img_tag;
}
//
// Parse the contents of [list] bbcode
//
function handle_list_tag($content, $type = '*')
{
global $re_list;
if (strlen($type) != 1)
$type = '*';
if (strpos($content,'[list') !== false)
{
$content = preg_replace_callback($re_list, create_function('$matches', 'return handle_list_tag($matches[2], $matches[1]);'), $content);
}
$content = preg_replace('#\s*\[\*\](.*?)\[/\*\]\s*#s', '<li><p>$1</p></li>', pun_trim($content));
if ($type == '*')
$content = '<ul>'.$content.'</ul>';
else
if ($type == 'a')
$content = '<ol class="alpha">'.$content.'</ol>';
else
$content = '<ol class="decimal">'.$content.'</ol>';
return '</p>'.$content.'<p>';
}
//
// Convert BBCodes to their HTML equivalent
//
function do_bbcode($text, $is_signature = false)
{
global $lang_common, $pun_user, $pun_config, $re_list;
if (strpos($text, '[quote') !== false)
{
$text = preg_replace('%\[quote\]\s*%', '</p><div class="quotebox"><blockquote><div><p>', $text);
$text = preg_replace_callback('%\[quote=("|&\#039;|"|\'|)([^\r\n]*?)\\1\]%s', create_function('$matches', 'global $lang_common; return "</p><div class=\"quotebox\"><cite>".str_replace(array(\'[\', \'\\"\'), array(\'[\', \'"\'), $matches[2])." ".$lang_common[\'wrote\']."</cite><blockquote><div><p>";'), $text);
$text = preg_replace('%\s*\[\/quote\]%S', '</p></div></blockquote></div><p>', $text);
}
if (!$is_signature)
{
$pattern_callback[] = $re_list;
$replace_callback[] = 'handle_list_tag($matches[2], $matches[1])';
}
$pattern[] = '%\[b\](.*?)\[/b\]%ms';
$pattern[] = '%\[i\](.*?)\[/i\]%ms';
$pattern[] = '%\[u\](.*?)\[/u\]%ms';
$pattern[] = '%\[s\](.*?)\[/s\]%ms';
$pattern[] = '%\[del\](.*?)\[/del\]%ms';
$pattern[] = '%\[ins\](.*?)\[/ins\]%ms';
$pattern[] = '%\[em\](.*?)\[/em\]%ms';
$pattern[] = '%\[colou?r=([a-zA-Z]{3,20}|\#[0-9a-fA-F]{6}|\#[0-9a-fA-F]{3})](.*?)\[/colou?r\]%ms';
$pattern[] = '%\[h\](.*?)\[/h\]%ms';
$replace[] = '<strong>$1</strong>';
$replace[] = '<em>$1</em>';
$replace[] = '<span class="bbu">$1</span>';
$replace[] = '<span class="bbs">$1</span>';
$replace[] = '<del>$1</del>';
$replace[] = '<ins>$1</ins>';
$replace[] = '<em>$1</em>';
$replace[] = '<span style="color: $1">$2</span>';
$replace[] = '</p><h5>$1</h5><p>';
if (($is_signature && $pun_config['p_sig_img_tag'] == '1') || (!$is_signature && $pun_config['p_message_img_tag'] == '1'))
{
$pattern_callback[] = '%\[img\]((ht|f)tps?://)([^\s<"]*?)\[/img\]%';
$pattern_callback[] = '%\[img=([^\[]*?)\]((ht|f)tps?://)([^\s<"]*?)\[/img\]%';
if ($is_signature)
{
$replace_callback[] = 'handle_img_tag($matches[1].$matches[3], true)';
$replace_callback[] = 'handle_img_tag($matches[2].$matches[4], true, $matches[1])';
}
else
{
$replace_callback[] = 'handle_img_tag($matches[1].$matches[3], false)';
$replace_callback[] = 'handle_img_tag($matches[2].$matches[4], false, $matches[1])';
}
}
$pattern_callback[] = '%\[url\]([^\[]*?)\[/url\]%';
$pattern_callback[] = '%\[url=([^\[]+?)\](.*?)\[/url\]%';
$pattern_callback[] = '%\[rurl\]([^\[]*?)\[/rurl\]%';
$pattern_callback[] = '%\[rurl=([^\[]+?)\](.*?)\[/rurl\]%';
$pattern[] = '%\[email\]([^\[]*?)\[/email\]%';
$pattern[] = '%\[email=([^\[]+?)\](.*?)\[/email\]%';
$pattern_callback[] = '%\[topic\]([1-9]\d*)\[/topic\]%';
$pattern_callback[] = '%\[topic=([1-9]\d*)\](.*?)\[/topic\]%';
$pattern_callback[] = '%\[post\]([1-9]\d*)\[/post\]%';
$pattern_callback[] = '%\[post=([1-9]\d*)\](.*?)\[/post\]%';
$pattern_callback[] = '%\[forum\]([1-9]\d*)\[/forum\]%';
$pattern_callback[] = '%\[forum=([1-9]\d*)\](.*?)\[/forum\]%';
$pattern_callback[] = '%\[user\]([1-9]\d*)\[/user\]%';
$pattern_callback[] = '%\[user=([1-9]\d*)\](.*?)\[/user\]%';
$replace_callback[] = 'handle_url_tag($matches[1])';
$replace_callback[] = 'handle_url_tag($matches[1], $matches[2])';
$replace_callback[] = 'handle_rurl_tag($matches[1])';
$replace_callback[] = 'handle_rurl_tag($matches[1], $matches[2])';
$replace[] = '<a href="mailto:$1">$1</a>';
$replace[] = '<a href="mailto:$1">$2</a>';
$replace_callback[] = 'handle_url_tag(\''.get_base_url(true).'/viewtopic.php?id=\'.$matches[1])';
$replace_callback[] = 'handle_url_tag(\''.get_base_url(true).'/viewtopic.php?id=\'.$matches[1], $matches[2])';
$replace_callback[] = 'handle_url_tag(\''.get_base_url(true).'/viewtopic.php?pid=\'.$matches[1].\'#p\'.$matches[1])';
$replace_callback[] = 'handle_url_tag(\''.get_base_url(true).'/viewtopic.php?pid=\'.$matches[1].\'#p\'.$matches[1], $matches[2])';
$replace_callback[] = 'handle_url_tag(\''.get_base_url(true).'/viewforum.php?id=\'.$matches[1])';
$replace_callback[] = 'handle_url_tag(\''.get_base_url(true).'/viewforum.php?id=\'.$matches[1], $matches[2])';
$replace_callback[] = 'handle_url_tag(\''.get_base_url(true).'/profile.php?id=\'.$matches[1])';
$replace_callback[] = 'handle_url_tag(\''.get_base_url(true).'/profile.php?id=\'.$matches[1], $matches[2])';
// This thing takes a while! :)
$text = preg_replace($pattern, $replace, $text);
$count = count($pattern_callback);
for($i = 0 ; $i < $count ; $i++)
{
$text = preg_replace_callback($pattern_callback[$i], create_function('$matches', 'return '.$replace_callback[$i].';'), $text);
}
return $text;
}
//
// Make hyperlinks clickable
//
function do_clickable($text)
{
$text = ' '.$text;
$text = ucp_preg_replace_callback('%(?<=[\s\]\)])(<)?(\[)?(\()?([\'"]?)(https?|ftp|news){1}://([\p{L}\p{N}\-]+\.([\p{L}\p{N}\-]+\.)*[\p{L}\p{N}]+(:[0-9]+)?(/(?:[^\s\[]*[^\s.,?!\[;:-])?)?)\4(?(3)(\)))(?(2)(\]))(?(1)(>))(?![^\s]*\[/(?:url|img)\])%ui', 'stripslashes($matches[1].$matches[2].$matches[3].$matches[4]).handle_url_tag($matches[5]."://".$matches[6], $matches[5]."://".$matches[6], true).stripslashes($matches[4].forum_array_key($matches, 10).forum_array_key($matches, 11).forum_array_key($matches, 12))', $text);
$text = ucp_preg_replace_callback('%(?<=[\s\]\)])(<)?(\[)?(\()?([\'"]?)(www|ftp)\.(([\p{L}\p{N}\-]+\.)+[\p{L}\p{N}]+(:[0-9]+)?(/(?:[^\s\[]*[^\s.,?!\[;:-])?)?)\4(?(3)(\)))(?(2)(\]))(?(1)(>))(?![^\s]*\[/(?:url|img)\])%ui','stripslashes($matches[1].$matches[2].$matches[3].$matches[4]).handle_url_tag($matches[5].".".$matches[6], $matches[5].".".$matches[6], true).stripslashes($matches[4].forum_array_key($matches, 10).forum_array_key($matches, 11).forum_array_key($matches, 12))', $text);
return substr($text, 1);
}
//
// Return an array key, if it exists, otherwise return an empty string
//
function forum_array_key($arr, $key)
{
return isset($arr[$key]) ? $arr[$key] : '';
}
//
// Convert a series of smilies to images
//
function do_smilies($text)
{
global $smilies;
$text = ' '.$text.' ';
foreach ($smilies as $smiley_text => $smiley_img)
{
if (strpos($text, $smiley_text) !== false)
$text = ucp_preg_replace('%(?<=[>\s])'.preg_quote($smiley_text, '%').'(?=[^\p{L}\p{N}])%um', '<img src="'.pun_htmlspecialchars(get_base_url(true).'/img/smilies/'.$smiley_img).'" width="15" height="15" alt="'.substr($smiley_img, 0, strrpos($smiley_img, '.')).'" />', $text);
}
return substr($text, 1, -1);
}
//
// Parse message text
//
function parse_message($text, $hide_smilies)
{
global $pun_config, $lang_common, $pun_user;
if ($pun_config['o_censoring'] == '1')
$text = censor_words($text);
// Convert applicable characters to HTML entities
$text = pun_htmlspecialchars($text);
// If the message contains a code tag we have to split it up (text within shouldn't be touched)
if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false)
list($inside, $text) = extract_blocks($text, '[code]', '[/code]');
if ($pun_config['p_message_bbcode'] == '1' && strpos($text, '[') !== false && strpos($text, ']') !== false)
$text = do_bbcode($text);
if ($pun_config['o_smilies'] == '1' && $pun_user['show_smilies'] == '1' && $hide_smilies == '0')
$text = do_smilies($text);
// Deal with newlines, tabs and multiple spaces
$pattern = array("\n", "\t", ' ', ' ');
$replace = array('<br />', '    ', '  ', '  ');
$text = str_replace($pattern, $replace, $text);
// If we split up the message before we have to concatenate it together again (code tags)
if (isset($inside))
{
$parts = explode("\1", $text);
$text = '';
foreach ($parts as $i => $part)
{
$text .= $part;
if (isset($inside[$i]))
{
$num_lines = (substr_count($inside[$i], "\n"));
$text .= '</p><div class="codebox"><pre'.(($num_lines > 28) ? ' class="vscroll"' : '').'><code>'.pun_trim($inside[$i], "\n\r").'</code></pre></div><p>';
}
}
}
return clean_paragraphs($text);
}
//
// Clean up paragraphs and line breaks
//
function clean_paragraphs($text)
{
// Add paragraph tag around post, but make sure there are no empty paragraphs
$text = '<p>'.$text.'</p>';
// Replace any breaks next to paragraphs so our replace below catches them
$text = preg_replace('%(</?p>)(?:\s*?<br />){1,2}%i', '$1', $text);
$text = preg_replace('%(?:<br />\s*?){1,2}(</?p>)%i', '$1', $text);
// Remove any empty paragraph tags (inserted via quotes/lists/code/etc) which should be stripped
$text = str_replace('<p></p>', '', $text);
$text = preg_replace('%<br />\s*?<br />%i', '</p><p>', $text);
$text = str_replace('<p><br />', '<br /><p>', $text);
$text = str_replace('<br /></p>', '</p><br />', $text);
$text = str_replace('<p></p>', '<br /><br />', $text);
return $text;
}
//
// Parse signature text
//
function parse_signature($text)
{
global $pun_config, $lang_common, $pun_user;
if ($pun_config['o_censoring'] == '1')
$text = censor_words($text);
// Convert applicable characters to HTML entities
$text = pun_htmlspecialchars($text);
if ($pun_config['p_sig_bbcode'] == '1' && strpos($text, '[') !== false && strpos($text, ']') !== false)
$text = do_bbcode($text, true);
if ($pun_config['o_smilies_sig'] == '1' && $pun_user['show_smilies'] == '1')
$text = do_smilies($text);
// Deal with newlines, tabs and multiple spaces
$pattern = array("\n", "\t", ' ', ' ');
$replace = array('<br />', '    ', '  ', '  ');
$text = str_replace($pattern, $replace, $text);
return clean_paragraphs($text);
}
Не забываем про замену site.ru на ваш домен.
Необязательное улучшение
Хотите немного сэкономить ресурсы сервера? Для этого можно удалить лишние обработчики неправильного написания ссылок в нашей новой функции.
Убираем из handle_rurl_tag данный кусок кода:
if (strpos($url, 'www.') === 0) // If it starts with www, we add http://
$full_url = 'http://'.$full_url;
else if (strpos($url, 'ftp.') === 0) // Else if it starts with ftp, we add ftp://
$full_url = 'ftp://'.$full_url;
else if (strpos($url, '/') === 0) // Allow for relative URLs that start with a slash
$full_url = get_base_url(true).$full_url;
и заменяем оставшуюсся
else if (!preg_match('#^([a-z0-9]{3,6})://#', $url)) // Else if it doesn't start with abcdef://, we add http://
$full_url = 'http://'.$full_url;
на
if (!preg_match('#^([a-z0-9]{3,6})://#', $url)) // Else if it doesn't start with abcdef://, we add http://
$full_url = 'http://'.$full_url;
В итоге наша функция handle_rurl_tag станет на несколько операций короче и будет выглядеть так:
function handle_rurl_tag($url, $link = '', $bbcode = false)
{
$url = pun_trim($url);
// Deal with [url][img]http://example.com/test.png[/img][/url]
if (preg_match('%<img src=\"(.*?)\"%', $url, $matches))
return handle_url_tag($matches[1], $url, $bbcode);
$full_url = str_replace(array(' ', '\'', '`', '"'), array('%20', '', '', ''), $url);
if (!preg_match('#^([a-z0-9]{3,6})://#', $url)) // Else if it doesn't start with abcdef://, we add http://
$full_url = 'http://'.$full_url;
// Ok, not very pretty :-)
if ($bbcode)
{
if ($full_url == $link)
return '[rurl]'.$link.'[/rurl]';
else
return '[rurl='.$full_url.']'.$link.'[/rurl]';
}
else
{
if ($link == '' || $link == $url)
{
$url = pun_htmlspecialchars_decode($url);
$link = utf8_strlen($url) > 55 ? utf8_substr($url, 0 , 39).' … '.utf8_substr($url, -10) : $url;
$link = pun_htmlspecialchars($link);
}
else
$link = stripslashes($link);
return '<a href="'.$full_url.'">'.$link.'</a>';
}
}
С такой функцией в тэгах [rurl] ссылки нужно будет обязательно прописывать с http:// в начале. Вот так:
[rurl=http://yandex.ru]анкор ссылки[/rurl]
Если указать ссылку без http:// - она не будет работать, потому что мы удалили код, отвечающий за преобразование неправильных ссылок без протокола к виду с протоколом: http://site.ru
Зато сэкономили немного серверных ресурсов на будущее.
3) Теперь нам надо связать новую функцию handle_rurl_tag с, собственно, бб-кодом rurl, который нам кстати тоже сперва надо добавить.
Для этого находим в файле /includes/parser.php функцию do_bbcode, а в ней такие строки:
$pattern_callback[] = '%\[url\]([^\[]*?)\[/url\]%';
$pattern_callback[] = '%\[url=([^\[]+?)\](.*?)\[/url\]%';
Делаем дубль этих двух строк.
Меняем в дублированных строках url на rurl или ваш бб-код.
В итоге получаем такой код:
$pattern_callback[] = '%\[url\]([^\[]*?)\[/url\]%';
$pattern_callback[] = '%\[url=([^\[]+?)\](.*?)\[/url\]%';
$pattern_callback[] = '%\[rurl\]([^\[]*?)\[/rurl\]%';
$pattern_callback[] = '%\[rurl=([^\[]+?)\](.*?)\[/rurl\]%';
Далее опускаемся ниже и находим такие строки:
$replace_callback[] = 'handle_url_tag($matches[1])';
$replace_callback[] = 'handle_url_tag($matches[1], $matches[2])';
Поясню подробнее. Данные строки отвечают за то, чтобы бб-код url обрабатывался функцией handle_url_tag.
Наша задача теперь привязать только что созданный [rurl] бб-код к новой функции handle_rurl_tag.
Для этого мы также делаем дубль этих двух строк и заменяем в них handle_url_tag на handle_rurl_tag.
В итоге у нас получится вот это:
$replace_callback[] = 'handle_url_tag($matches[1])';
$replace_callback[] = 'handle_url_tag($matches[1], $matches[2])';
$replace_callback[] = 'handle_rurl_tag($matches[1])';
$replace_callback[] = 'handle_rurl_tag($matches[1], $matches[2])';
Сохраняем файл на сервере вместо стандартного, заходим на форум и создаём пост с двумя ссылками:
Одну через url бб-код, другую через rurl бб-код. Если вы всё сделали правильно, то обычная ссылка будет идти через редирект, а rurl-ссылка будет прямой и без атрибута rel="nofollow".
4) Осталось дело за малым. Помимо текстов постов, нам надо закрыть ещё и ссылки в описаниях профилей и на страницах профилей.
а) Чтобы такие ссылки в описаниях профилей тоже работали через редирект:
Открываем файл /viewtopic.php и заменяем вот эту строку:
$user_contacts[] = '<span class="website"><a href="'.pun_htmlspecialchars($cur_post['url']).'" rel="nofollow">'.$lang_topic['Website'].'</a></span>';
на это, заменив site.ru на свой домен:
$user_contacts[] = '<span class="website"><a href="http://site.ru/go.php?to='.pun_htmlspecialchars($cur_post['url']).'" rel="nofollow">'.$lang_topic['Website'].'</a></span>';
б) Чтобы редиректить ссылки со страниц профилей, открываем файл /profile.php и аналогичным образом заменяем это:
$user_personal[] = '<dd><span class="website"><a href="'.$user['url'].'" rel="nofollow">'.$user['url'].'</a></span></dd>';
на это, заменив site.ru на свой домен:
$user_personal[] = '<dd><span class="website"><a href="http://site.ru/go.php?to='.$user['url'].'" rel="nofollow">'.$user['url'].'</a></span></dd>';
Инструкция для Fluxbb 1.4
В файле include/parser.php также дублируем функцию function handle_url_tag
и меняем
{
if ($full_url == $link)
return '[url]'.$link.'[/url]';
else
return '[url='.$full_url.']'.$link.'[/url]';
}
на
{
if ($full_url == $link)
return '[rurl]'.$link.'[/rurl]';
else
return '[rurl='.$full_url.']'.$link.'[/rurl]';
}
Добавляем бб-тэг rurl и связываем его с нашей новой функцией. Для этого находим в файле include/parser.php такие строчки:
$pattern[] = '#\[url\]([^\[]*?)\[/url\]#e';
$pattern[] = '#\[url=([^\[]+?)\](.*?)\[/url\]#e';
Дублируем их и в продублированных строчках заменяем url на rurl
Далее находим строки:
$replace[] = 'handle_url_tag(\'$1\')';
$replace[] = 'handle_url_tag(\'$1\', \'$2\')';
Дублируем их и также заменяем url на rurl
Вот include/parser.php для Fluxbb 1.4 (ревизию не помню):
<?php
/**
* Copyright (C) 2008-2011 FluxBB
* based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
exit;
// Global variables
/* regular expression to match nested BBCode LIST tags
'%
\[list # match opening bracket and tag name of outermost LIST tag
(?:=([1a*]))?+ # optional attribute capture in group 1
\] # closing bracket of outermost opening LIST tag
( # capture contents of LIST tag in group 2
(?: # non capture group for either contents or whole nested LIST
[^\[]*+ # unroll the loop! consume everything up to next [ (normal *)
(?: # (See "Mastering Regular Expressions" chapter 6 for details)
(?! # negative lookahead ensures we are NOT on [LIST*] or [/LIST]
\[list # opening LIST tag
(?:=[1a*])?+ # with optional attribute
\] # closing bracket of opening LIST tag
| # or...
\[/list\] # a closing LIST tag
) # end negative lookahead assertion (we are not on a LIST tag)
\[ # match the [ which is NOT the start of LIST tag (special)
[^\[]*+ # consume everything up to next [ (normal *)
)*+ # finish up "unrolling the loop" technique (special (normal*))*
| # or...
(?R) # recursively match a whole nested LIST element
)* # as many times as necessary until deepest nested LIST tag grabbed
) # end capturing contents of LIST tag into group 2
\[/list\] # match outermost closing LIST tag
%iex' */
$re_list = '%\[list(?:=([1a*]))?+\]((?:[^\[]*+(?:(?!\[list(?:=[1a*])?+\]|\[/list\])\[[^\[]*+)*+|(?R))*)\[/list\]%ie';
// Here you can add additional smilies if you like (please note that you must escape single quote and backslash)
// Load smilies cache - Visman
if (!isset($smilies))
{
if (file_exists(FORUM_CACHE_DIR.'cache_smilies.php'))
include FORUM_CACHE_DIR.'cache_smilies.php';
else
{
require_once PUN_ROOT.'include/cache_smilies.php';
generate_smiley_cache();
require FORUM_CACHE_DIR.'cache_smilies.php';
}
}
//
// Make sure all BBCodes are lower case and do a little cleanup
//
function preparse_bbcode($text, &$errors, $is_signature = false)
{
global $pun_config, $lang_common, $lang_post, $re_list;
if ($is_signature)
{
global $lang_profile;
if (preg_match('%\[/?(?:quote|code|list|h|hr|size|video|audio|after|spoiler)\b[^\]]*\]%i', $text))
$errors[] = $lang_profile['Signature quote/code/list/h'];
}
// If the message contains a code tag we have to split it up (text within shouldn't be touched)
if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false)
{
list($inside, $outside) = split_text($text, '[code]', '[/code]', $errors);
$text = implode("\1", $outside);
}
// Tidy up lists
$temp = preg_replace($re_list, 'preparse_list_tag(\'$2\', \'$1\', $errors)', $text);
// If the regex failed
if ($temp === null)
$errors[] = $lang_common['BBCode list size error'];
else
$text = str_replace('*'."\0".']', '*]', $temp);
if ($pun_config['o_make_links'] == '1')
$text = do_clickable($text);
// If we split up the message before we have to concatenate it together again (code tags)
if (isset($inside))
{
$outside = explode("\1", $text);
$text = '';
$num_tokens = count($outside);
for ($i = 0; $i < $num_tokens; ++$i)
{
$text .= $outside[$i];
if (isset($inside[$i]))
$text .= '[code]'.$inside[$i].'[/code]';
}
unset($inside);
}
$temp_text = false;
if (empty($errors))
$temp_text = preparse_tags($text, $errors, $is_signature);
if ($temp_text !== false)
$text = $temp_text;
// Remove empty tags
while (($new_text = strip_empty_bbcode($text, $errors)) !== false)
{
if ($new_text != $text)
{
$text = $new_text;
if ($new_text == '')
{
$errors[] = $lang_post['Empty after strip'];
break;
}
}
else
break;
}
return pun_trim($text);
}
//
// Strip empty bbcode tags from some text
//
function strip_empty_bbcode($text, &$errors)
{
// If the message contains a code tag we have to split it up (empty tags within are fine)
if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false)
{
list($inside, $outside) = split_text($text, '[code]', '[/code]', $errors);
$text = implode("\1", $outside);
}
// Remove empty tags
while (($new_text = preg_replace('/\[(b|u|s|ins|del|em|i|h|colou?r|quote|img|imgl|imgr|url|email|list|hr|size|video|audio|after|spoiler|right|center|justify|mono)(?:\=[^\]]*)?\]\s*\[\/\1\]/', '', $text)) !== NULL)
{
if ($new_text != $text)
$text = $new_text;
else
break;
}
// If we split up the message before we have to concatenate it together again (code tags)
if (isset($inside))
{
$outside = explode("\1", $text);
$text = '';
$num_tokens = count($outside);
for ($i = 0; $i < $num_tokens; ++$i)
{
$text .= $outside[$i];
if (isset($inside[$i]))
$text .= '[code]'.$inside[$i].'[/code]';
}
}
// Remove empty code tags
while (($new_text = preg_replace('/\[(code)\]\s*\[\/\1\]/', '', $text)) !== NULL)
{
if ($new_text != $text)
$text = $new_text;
else
break;
}
return $text;
}
//
// Check the structure of bbcode tags and fix simple mistakes where possible
//
function preparse_tags($text, &$errors, $is_signature = false)
{
global $lang_common, $pun_config;
// Start off by making some arrays of bbcode tags and what we need to do with each one
// List of all the tags
$tags = array('quote', 'code', 'b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'img', 'imgl', 'imgr', 'list', '*', 'h','size', 'video', 'audio', 'spoiler', 'right', 'center', 'justify', 'mono');
// List of tags that we need to check are open (You could not put b,i,u in here then illegal nesting like [b][i][/b][/i] would be allowed)
$tags_opened = $tags;
// and tags we need to check are closed (the same as above, added it just in case)
$tags_closed = $tags;
// Tags we can nest and the depth they can be nested to
$tags_nested = array('quote' => $pun_config['o_quote_depth'], 'list' => 5, '*' => 5, 'spoiler' => 5);
// Tags to ignore the contents of completely (just code)
$tags_ignore = array('code');
// Block tags, block tags can only go within another block tag, they cannot be in a normal tag
$tags_block = array('quote', 'code', 'list', 'h', '*', 'spoiler');
// Inline tags, we do not allow new lines in these
$tags_inline = array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'h');
// Tags we trim interior space
$tags_trim = array('img', 'imgl', 'imgr');
// Tags we remove quotes from the argument
$tags_quotes = array('url', 'email', 'img', 'imgl', 'imgr', 'audio', 'video');
// Tags we limit bbcode in
$tags_limit_bbcode = array(
'*' => array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'list', 'img', 'imgl', 'imgr', 'code'),
'list' => array('*'),
'url' => array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'img', 'imgr', 'imgl'),
'email' => array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'img', 'imgr', 'imgl'),
'img' => array(),
'imgr' => array(),
'imgl' => array(),
'h' => array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email'),
);
// Tags we can automatically fix bad nesting
$tags_fix = array('quote', 'b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'h');
$split_text = preg_split("/(\[[\*a-zA-Z0-9-\/]*?(?:=.*?)?\])/", $text, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
$open_tags = array('post');
$open_args = array('');
$opened_tag = 0;
$new_text = '';
$current_ignore = '';
$current_nest = '';
$current_depth = array();
$limit_bbcode = $tags;
foreach ($split_text as $current)
{
if ($current == '')
continue;
// Are we dealing with a tag?
if (substr($current, 0, 1) != '[' || substr($current, -1, 1) != ']')
{
// It's not a bbcode tag so we put it on the end and continue
// If we are nested too deeply don't add to the end
if ($current_nest)
continue;
$current = str_replace("\r\n", "\n", $current);
$current = str_replace("\r", "\n", $current);
if (in_array($open_tags[$opened_tag], $tags_inline) && strpos($current, "\n") !== false)
{
// Deal with new lines
$split_current = preg_split("/(\n\n+)/", $current, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
$current = '';
if (!pun_trim($split_current[0], "\n")) // The first part is a linebreak so we need to handle any open tags first
array_unshift($split_current, '');
for ($i = 1; $i < count($split_current); $i += 2)
{
$temp_opened = array();
$temp_opened_arg = array();
$temp = $split_current[$i - 1];
while (!empty($open_tags))
{
$temp_tag = array_pop($open_tags);
$temp_arg = array_pop($open_args);
if (in_array($temp_tag , $tags_inline))
{
array_push($temp_opened, $temp_tag);
array_push($temp_opened_arg, $temp_arg);
$temp .= '[/'.$temp_tag.']';
}
else
{
array_push($open_tags, $temp_tag);
array_push($open_args, $temp_arg);
break;
}
}
$current .= $temp.$split_current[$i];
$temp = '';
while (!empty($temp_opened))
{
$temp_tag = array_pop($temp_opened);
$temp_arg = array_pop($temp_opened_arg);
if (empty($temp_arg))
$temp .= '['.$temp_tag.']';
else
$temp .= '['.$temp_tag.'='.$temp_arg.']';
array_push($open_tags, $temp_tag);
array_push($open_args, $temp_arg);
}
$current .= $temp;
}
if (array_key_exists($i - 1, $split_current))
$current .= $split_current[$i - 1];
}
if (in_array($open_tags[$opened_tag], $tags_trim))
$new_text .= pun_trim($current);
else
$new_text .= $current;
continue;
}
// Get the name of the tag
$current_arg = '';
if (strpos($current, '/') === 1)
{
$current_tag = substr($current, 2, -1);
}
else if (strpos($current, '=') === false)
{
$current_tag = substr($current, 1, -1);
}
else
{
$current_tag = substr($current, 1, strpos($current, '=')-1);
$current_arg = substr($current, strpos($current, '=')+1, -1);
}
$current_tag = strtolower($current_tag);
// Is the tag defined?
if (!in_array($current_tag, $tags))
{
// It's not a bbcode tag so we put it on the end and continue
if (!$current_nest)
$new_text .= $current;
continue;
}
// We definitely have a bbcode tag
// Make the tag string lower case
if ($equalpos = strpos($current,'='))
{
// We have an argument for the tag which we don't want to make lowercase
if (strlen(substr($current, $equalpos)) == 2)
{
// Empty tag argument
$errors[] = sprintf($lang_common['BBCode error empty attribute'], $current_tag);
return false;
}
$current = strtolower(substr($current, 0, $equalpos)).substr($current, $equalpos);
}
else
$current = strtolower($current);
// This is if we are currently in a tag which escapes other bbcode such as code
if ($current_ignore)
{
if ('[/'.$current_ignore.']' == $current)
{
// We've finished the ignored section
$current = '[/'.$current_tag.']';
$current_ignore = '';
}
$new_text .= $current;
continue;
}
if ($current_nest)
{
// We are currently too deeply nested so lets see if we are closing the tag or not
if ($current_tag != $current_nest)
continue;
if (substr($current, 1, 1) == '/')
$current_depth[$current_nest]--;
else
$current_depth[$current_nest]++;
if ($current_depth[$current_nest] <= $tags_nested[$current_nest])
$current_nest = '';
continue;
}
// Check the current tag is allowed here
if (!in_array($current_tag, $limit_bbcode) && $current_tag != $open_tags[$opened_tag])
{
$errors[] = sprintf($lang_common['BBCode error invalid nesting'], $current_tag, $open_tags[$opened_tag]);
return false;
}
if (substr($current, 1, 1) == '/')
{
// This is if we are closing a tag
if ($opened_tag == 0 || !in_array($current_tag, $open_tags))
{
// We tried to close a tag which is not open
if (in_array($current_tag, $tags_opened))
{
$errors[] = sprintf($lang_common['BBCode error no opening tag'], $current_tag);
return false;
}
}
else
{
// Check nesting
while (true)
{
// Nesting is ok
if ($open_tags[$opened_tag] == $current_tag)
{
array_pop($open_tags);
array_pop($open_args);
$opened_tag--;
break;
}
// Nesting isn't ok, try to fix it
if (in_array($open_tags[$opened_tag], $tags_closed) && in_array($current_tag, $tags_closed))
{
if (in_array($current_tag, $open_tags))
{
$temp_opened = array();
$temp_opened_arg = array();
$temp = '';
while (!empty($open_tags))
{
$temp_tag = array_pop($open_tags);
$temp_arg = array_pop($open_args);
if (!in_array($temp_tag, $tags_fix))
{
// We couldn't fix nesting
$errors[] = sprintf($lang_common['BBCode error no closing tag'], array_pop($temp_opened));
return false;
}
array_push($temp_opened, $temp_tag);
array_push($temp_opened_arg, $temp_arg);
if ($temp_tag == $current_tag)
break;
else
$temp .= '[/'.$temp_tag.']';
}
$current = $temp.$current;
$temp = '';
array_pop($temp_opened);
array_pop($temp_opened_arg);
while (!empty($temp_opened))
{
$temp_tag = array_pop($temp_opened);
$temp_arg = array_pop($temp_opened_arg);
if (empty($temp_arg))
$temp .= '['.$temp_tag.']';
else
$temp .= '['.$temp_tag.'='.$temp_arg.']';
array_push($open_tags, $temp_tag);
array_push($open_args, $temp_arg);
}
$current .= $temp;
$opened_tag--;
break;
}
else
{
// We couldn't fix nesting
$errors[] = sprintf($lang_common['BBCode error no opening tag'], $current_tag);
return false;
}
}
else if (in_array($open_tags[$opened_tag], $tags_closed))
break;
else
{
array_pop($open_tags);
array_pop($open_args);
$opened_tag--;
}
}
}
if (in_array($current_tag, array_keys($tags_nested)))
{
if (isset($current_depth[$current_tag]))
$current_depth[$current_tag]--;
}
if (in_array($open_tags[$opened_tag], array_keys($tags_limit_bbcode)))
$limit_bbcode = $tags_limit_bbcode[$open_tags[$opened_tag]];
else
$limit_bbcode = $tags;
$new_text .= $current;
continue;
}
else
{
// We are opening a tag
if (in_array($current_tag, array_keys($tags_limit_bbcode)))
$limit_bbcode = $tags_limit_bbcode[$current_tag];
else
$limit_bbcode = $tags;
if (in_array($current_tag, $tags_block) && !in_array($open_tags[$opened_tag], $tags_block) && $opened_tag != 0)
{
// We tried to open a block tag within a non-block tag
$errors[] = sprintf($lang_common['BBCode error invalid nesting'], $current_tag, $open_tags[$opened_tag]);
return false;
}
if (in_array($current_tag, $tags_ignore))
{
// It's an ignore tag so we don't need to worry about what's inside it
$current_ignore = $current_tag;
$new_text .= $current;
continue;
}
// Deal with nested tags
if (in_array($current_tag, $open_tags) && !in_array($current_tag, array_keys($tags_nested)))
{
// We nested a tag we shouldn't
$errors[] = sprintf($lang_common['BBCode error invalid self-nesting'], $current_tag);
return false;
}
else if (in_array($current_tag, array_keys($tags_nested)))
{
// We are allowed to nest this tag
if (isset($current_depth[$current_tag]))
$current_depth[$current_tag]++;
else
$current_depth[$current_tag] = 1;
// See if we are nested too deep
if ($current_depth[$current_tag] > $tags_nested[$current_tag])
{
$current_nest = $current_tag;
continue;
}
}
// Remove quotes from arguments for certain tags
if (strpos($current, '=') !== false && in_array($current_tag, $tags_quotes))
{
$current = preg_replace('#\['.$current_tag.'=("|\'|)(.*?)\\1\]\s*#i', '['.$current_tag.'=$2]', $current);
}
if (in_array($current_tag, array_keys($tags_limit_bbcode)))
$limit_bbcode = $tags_limit_bbcode[$current_tag];
$open_tags[] = $current_tag;
$open_args[] = $current_arg;
$opened_tag++;
$new_text .= $current;
continue;
}
}
// Check we closed all the tags we needed to
foreach ($tags_closed as $check)
{
if (in_array($check, $open_tags))
{
// We left an important tag open
$errors[] = sprintf($lang_common['BBCode error no closing tag'], $check);
return false;
}
}
if ($current_ignore)
{
// We left an ignore tag open
$errors[] = sprintf($lang_common['BBCode error no closing tag'], $current_ignore);
return false;
}
return $new_text;
}
//
// Preparse the contents of [list] bbcode
//
function preparse_list_tag($content, $type = '*', &$errors)
{
global $lang_common, $re_list;
if (strlen($type) != 1)
$type = '*';
if (strpos($content,'[list') !== false)
{
$content = preg_replace($re_list, 'preparse_list_tag(\'$2\', \'$1\', $errors)', $content);
}
$items = explode('[*]', str_replace('\"', '"', $content));
$content = '';
foreach ($items as $item)
{
if (pun_trim($item) != '')
$content .= '[*'."\0".']'.str_replace('[/*]', '', pun_trim($item)).'[/*'."\0".']'."\n";
}
return '[list='.$type.']'."\n".$content.'[/list]';
}
//
// Truncate URL if longer than 55 characters (add http:// or ftp:// if missing)
//
function handle_url_tag($url, $link = '', $bbcode = false)
{
global $pun_config, $lang_common, $pun_user;
$url = pun_trim($url);
$full_url = str_replace(array(' ', '\'', '`', '"'), array('%20', '', '', ''), $url);
if (strpos($url, 'www.') === 0) // If it starts with www, we add http://
$full_url = 'http://'.$full_url;
else if (strpos($url, 'ftp.') === 0) // Else if it starts with ftp, we add ftp://
$full_url = 'ftp://'.$full_url;
else if (!preg_match('#^([a-z0-9]{3,6})://#', $url)) // Else if it doesn't start with abcdef://, we add http://
$full_url = 'http://'.$full_url;
// Ok, not very pretty :-)
if ($bbcode)
{
if ($full_url == $link)
return '[url]'.$link.'[/url]';
else
return '[url='.$full_url.']'.$link.'[/url]';
}
else if ($pun_config['o_board_redirect'] == '' || (!$pun_user['is_guest'] && $pun_config['o_board_redirectg'] == '1') || preg_match('/'.$pun_config['o_board_redirect'].'/i',$full_url))
{
if ($link == '' || $link == $url)
{
$url = pun_htmlspecialchars_decode($url);
$link = utf8_strlen($url) > 55 ? utf8_substr($url, 0 , 39).' … '.utf8_substr($url, -10) : $url;
$link = pun_htmlspecialchars($link);
}
else
$link = stripslashes($link);
return '<a href="http://forum.ru/go.php?to='.$full_url.'" >'.$link.'</a>';
}
else
{
if ($link == '' || $link == $url)
{
$link = $lang_common['Link'];
}
else
$link = stripslashes($link);
return '<a href="re.php?u='.urlencode($full_url).'">'.$link.'</a>';
}
}
function handle_dhrg_tag($url, $link = '', $bbcode = false)
{
$url = pun_trim($url);
// Deal with [url][img]http://example.com/test.png[/img][/url]
if (preg_match('%<img src=\"(.*?)\"%', $url, $matches))
return handle_url_tag($matches[1], $url, $bbcode);
$full_url = str_replace(array(' ', '\'', '`', '"'), array('%20', '', '', ''), $url);
if (strpos($url, 'www.') === 0) // If it starts with www, we add http://
$full_url = 'http://'.$full_url;
else if (strpos($url, 'ftp.') === 0) // Else if it starts with ftp, we add ftp://
$full_url = 'ftp://'.$full_url;
else if (strpos($url, '/') === 0) // Allow for relative URLs that start with a slash
$full_url = get_base_url(true).$full_url;
else if (!preg_match('#^([a-z0-9]{3,6})://#', $url)) // Else if it doesn't start with abcdef://, we add http://
$full_url = 'http://'.$full_url;
// Ok, not very pretty :-)
if ($bbcode)
{
if ($full_url == $link)
return '[dhrg]'.$link.'[/dhrg]';
else
return '[dhrg='.$full_url.']'.$link.'[/dhrg]';
}
else
{
if ($link == '' || $link == $url)
{
$url = pun_htmlspecialchars_decode($url);
$link = utf8_strlen($url) > 55 ? utf8_substr($url, 0 , 39).' … '.utf8_substr($url, -10) : $url;
$link = pun_htmlspecialchars($link);
}
else
$link = stripslashes($link);
return '<a href="'.$full_url.'" >'.$link.'</a>';
}
}
//
// Turns an URL from the [img] tag into an <img> tag or a <a href...> tag
//
function handle_img_tag($url, $is_signature = false, $alt = null, $float = '')
{
global $lang_common, $pun_user;
if ($alt == null)
$alt = basename($url);
$img_tag = '<a href="'.$url.'"><'.$lang_common['Image link'].' - '.$alt.'></a>';
if ($is_signature && $pun_user['show_img_sig'] != '0')
$img_tag = '<img class="sigimage" src="'.$url.'" alt="'.$alt.'" />';
else if (!$is_signature && $pun_user['show_img'] != '0')
$img_tag = '<span class="postimg"><img src="'.$url.'" '.(($float != '') ? 'style="float: '.$float.'; clear: '.$float.'" ' : '').'alt="'.$alt.'" /></span>';
return $img_tag;
}
//
// Parse the contents of [list] bbcode
//
function handle_list_tag($content, $type = '*')
{
global $re_list;
if (strlen($type) != 1)
$type = '*';
if (strpos($content,'[list') !== false)
{
$content = preg_replace($re_list, 'handle_list_tag(\'$2\', \'$1\')', $content);
}
$content = preg_replace('#\s*\[\*\](.*?)\[/\*\]\s*#s', '<li><p>$1</p></li>', pun_trim($content));
if ($type == '*')
$content = '<ul>'.$content.'</ul>';
else
if ($type == 'a')
$content = '<ol class="alpha">'.$content.'</ol>';
else
$content = '<ol class="decimal">'.$content.'</ol>';
return '</p>'.$content.'<p>';
}
//
// ф-ия показывающая сколько прошло времени - Visman
//
function handle_time_tag($after_time)
{
global $lang_common;
if ($after_time == 0)
return '';
$content = array();
$merged_sec = $after_time % 60;
$merged_min = ($after_time/60) % 60;
$merged_hours = ($after_time/3600) % 24;
$merged_days = intval($after_time/86400);
if ($merged_days > 0)
$content[] = $merged_days.$lang_common['After time d'];
if ($merged_hours > 0)
$content[] = $merged_hours.$lang_common['After time H'];
if ($merged_min > 0)
$content[] = (($merged_min < 10) ? '0'.$merged_min : $merged_min).$lang_common['After time i'];
if ($merged_sec > 0)
$content[] = (($merged_sec < 10) ? '0'.$merged_sec : $merged_sec).$lang_common['After time s'];
return pun_linebreaks(pun_trim('<span style="color: #808080"><em>'.$lang_common['After time'].' '.implode(' ', $content).':</em></span>'."\n"));
}
//
// Convert BBCodes to their HTML equivalent
//
function do_bbcode($text, $is_signature = false)
{
global $lang_common, $pun_user, $pun_config, $re_list;
if (strpos($text, '[quote') !== false)
{
$text = preg_replace('#\[quote\]\s*#', '</p><div class="quotebox"><blockquote><div><p>', $text);
$text = preg_replace('#\[quote=("|&\#039;|"|\'|)(.*?)\\1\]#se', '"</p><div class=\"quotebox\"><cite>".str_replace(array(\'[\', \'\\"\'), array(\'[\', \'"\'), \'$2\')." ".$lang_common[\'wrote\']."</cite><blockquote><div><p>"', $text);
$text = preg_replace('#\s*\[\/quote\]#S', '</p></div></blockquote></div><p>', $text);
}
// *****
// Обрабатываем спойлер - Visman
if (strpos($text, '[spoiler]') !== false)
{
$text = str_replace('[spoiler]', "</p><div><div style=\"margin-bottom:2px\"><strong>".$lang_common['Hidden text']."</strong>: <input type=\"button\" value=\"".$lang_common['Show']."\" style=\"width:60px;font-size:10px;margin:0px;padding:0px;\" onClick=\"if (this.parentNode.parentNode.getElementsByTagName('div')[1].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].style.display = ''; this.innerText = ''; this.value = '".$lang_common['Hide']."'; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].style.display = 'none'; this.innerText = ''; this.value = '".$lang_common['Show']."'; }\"></div><div style=\"margin: 0px; padding: 6px; border: 1px inset; display: none;\"><p>", $text);
$text = str_replace('[/spoiler]', '</p></div></div><p>', $text);
}
// bbcode VIDEO
if (strpos($text, '[video]') !== false)
{
$text = preg_replace('#\[video\]http://www.youtube.com/watch\?v=([-_a-zA-Z0-9]+?)(&.*?)?\[/video\]#U',
'</p><div class="bbvideo"><p><a href="http://www.youtube.com/watch?v=$1">http://www.youtube.com/watch?v=$1</a></p>'.
'<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/$1"></param><embed src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" width="640" height="385"></embed></object>'.
'</div><p>', $text);
$text = preg_replace('#\[video\]http://rutube.ru/tracks/([0-9]+?).html\?v=([a-zA-Z0-9]+?)\[/video\]#U',
'</p><div class="bbvideo"><p><a href="http://rutube.ru/tracks/$1.html?v=$2">http://rutube.ru/tracks/$1.html?v=$2</a></p>'.
'<object width="640" height="385"><param name="movie" value="http://video.rutube.ru/$2"></param><param name="wmode" value="window"></param><param name="allowFullScreen" value="true"></param><embed src="http://video.rutube.ru/$2" type="application/x-shockwave-flash" wmode="window" width="640" height="385" allowFullScreen="true" ></embed></object>'.
'</div><p>', $text);
$text = preg_replace('#\[video\]http://vimeo.com/([0-9]+?)\[/video\]#U',
'</p><div class="bbvideo"><p><a href="http://vimeo.com/$1">http://vimeo.com/$1</a></p>'.
'<object width="640" height="385"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=$1&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=$1&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="640" height="385"></embed></object>'.
'</div><p>', $text);
$text = preg_replace('#\[video\]http://smotri.com/video/view/\?id=([a-zA-Z0-9]+?)\[/video\]#U',
'</p><div class="bbvideo"><p><a href="http://smotri.com/video/view/?id=$1">http://smotri.com/video/view/?id=$1</a></p>'.
'<object id="smotriComVideoPlayer" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="640" height="360"><param name="movie" value="http://pics.smotri.com/player.swf?file=$1&bufferTime=3&autoStart=false&str_lang=rus&xmlsource=http%3A%2F%2Fpics.smotri.com%2Fcskins%2Fblue%2Fskin_color.xml&xmldatasource=http%3A%2F%2Fpics.smotri.com%2Fskin_ng.xml" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="bgcolor" value="#ffffff" /><embed src="http://pics.smotri.com/player.swf?file=$1&bufferTime=3&autoStart=false&str_lang=rus&xmlsource=http%3A%2F%2Fpics.smotri.com%2Fcskins%2Fblue%2Fskin_color.xml&xmldatasource=http%3A%2F%2Fpics.smotri.com%2Fskin_ng.xml" quality="high" allowscriptaccess="always" allowfullscreen="true" wmode="opaque" width="640" height="360" type="application/x-shockwave-flash"></embed></object>'.
'</div><p>', $text);
}
// bbcode AUDIO
if (strpos($text, '[audio]') !== false)
{
$text = preg_replace('#\[audio\](http://[^\s<"]+?.mp3)\[/audio\]#U',
'</p><div class="bbvideo"><p><a href="$1">$1</a></p>'.
'<object type="application/x-shockwave-flash" data="swf/mp3player.swf" id="audioplayer1" height="24" width="290">'.
'<param name="movie" value="swf/mp3player.swf">'.
'<param name="FlashVars" value="playerID=audioplayer1&soundFile=$1">'.
'<param name="quality" value="high">'.
'<param name="menu" value="false">'.
'<param name="wmode" value="transparent">'.
'</object> </div><p>', $text);
// $text = preg_replace('#\[audio\]http://([-_a-zA-Z0-9]+?).zippyshare.com/v/([-_a-zA-Z0-9]+?)/file.html\[/audio\]#U',
// '</p><div class="bbvideo">'.
// '<script type="text/javascript">var zippywww="$1";var zippyfile="$2";var zippydown="ffffff";var zippyfront="000000";var zippyback="ffffff";var zippylight="000000";var zippywidth=350;var zippyauto=false;var zippyvol=80;</script><script type="text/javascript" src="http://api.zippyshare.com/api/embed.js"></script>'.
// '</div><p>', $text);
// $text = preg_replace('#\[audio\]http://([-_a-zA-Z0-9]+?).zippyshare.com/view.jsp.*?key=([-_a-zA-Z0-9]+?)(&.*?)*?\[/audio\]#U',
// '</p><div class="bbvideo">'.
// '<script type="text/javascript">var zippywww="$1";var zippyfile="$2";var zippydown="ffffff";var zippyfront="000000";var zippyback="ffffff";var zippylight="000000";var zippywidth=350;var zippyauto=false;var zippyvol=80;</script><script type="text/javascript" src="http://api.zippyshare.com/api/embed.js"></script>'.
// '</div><p>', $text);
}
// *****
if (!$is_signature)
{
$pattern[] = $re_list;
$replace[] = 'handle_list_tag(\'$2\', \'$1\')';
}
$pattern[] = '#\[b\](.*?)\[/b\]#ms';
$pattern[] = '#\[i\](.*?)\[/i\]#ms';
$pattern[] = '#\[u\](.*?)\[/u\]#ms';
$pattern[] = '#\[s\](.*?)\[/s\]#ms';
$pattern[] = '#\[del\](.*?)\[/del\]#ms';
$pattern[] = '#\[ins\](.*?)\[/ins\]#ms';
$pattern[] = '#\[em\](.*?)\[/em\]#ms';
$pattern[] = '#\[colou?r=([a-zA-Z]{3,20}|\#[0-9a-fA-F]{6}|\#[0-9a-fA-F]{3})](.*?)\[/colou?r\]#ms';
$pattern[] = '#\[h\](.*?)\[/h\]#ms';
// дополнительные ббкоды - Visman
$pattern[] = '#\[hr\]#';
$pattern[] = '#\[size=([0-9]*)](.*?)\[/size\]#s';
$pattern[] = '#\[after=([0-9]*)\]#e';
$pattern[] = '#\[right\](.*?)\[/right\]#ms';
$pattern[] = '#\[center\](.*?)\[/center\]#ms';
$pattern[] = '#\[justify\](.*?)\[/justify\]#ms';
$pattern[] = '#\[mono\](.*?)\[/mono\]#ms';
$replace[] = '<strong>$1</strong>';
$replace[] = '<em>$1</em>';
$replace[] = '<span class="bbu">$1</span>';
$replace[] = '<span class="bbs">$1</span>';
$replace[] = '<del>$1</del>';
$replace[] = '<ins>$1</ins>';
$replace[] = '<em>$1</em>';
$replace[] = '<span style="color: $1">$2</span>';
$replace[] = '</p><h5>$1</h5><p>';
// дополнительные ббкоды - Visman
$replace[] = '</p><hr /><p>';
$replace[] = '<span style="font-size: $1px">$2</span>';
$replace[] = 'handle_time_tag(\'$1\')';
$replace[] = '</p><p style="text-align: right">$1</p><p>';
$replace[] = '</p><p style="text-align: center">$1</p><p>';
$replace[] = '</p><p style="text-align: justify">$1</p><p>';
$replace[] = '<code>$1</code>';
if (($is_signature && $pun_config['p_sig_img_tag'] == '1') || (!$is_signature && $pun_config['p_message_img_tag'] == '1'))
{
$pattern[] = '#\[img\]((ht|f)tps?://)([^\s<"]*?)\[/img\]#e';
$pattern[] = '#\[img=([^\[]*?)\]((ht|f)tps?://)([^\s<"]*?)\[/img\]#e';
if ($is_signature)
{
$replace[] = 'handle_img_tag(\'$1$3\', true)';
$replace[] = 'handle_img_tag(\'$2$4\', true, \'$1\')';
}
else
{
$replace[] = 'handle_img_tag(\'$1$3\', false)';
$replace[] = 'handle_img_tag(\'$2$4\', false, \'$1\')';
$pattern[] = '#\[imgr\]((ht|f)tps?://)([^\s<"]*?)\[/imgr\]#e';
$pattern[] = '#\[imgr=([^\[]*?)\]((ht|f)tps?://)([^\s<"]*?)\[/imgr\]#e';
$pattern[] = '#\[imgl\]((ht|f)tps?://)([^\s<"]*?)\[/imgl\]#e';
$pattern[] = '#\[imgl=([^\[]*?)\]((ht|f)tps?://)([^\s<"]*?)\[/imgl\]#e';
$replace[] = 'handle_img_tag(\'$1$3\', false, null,\'right\')';
$replace[] = 'handle_img_tag(\'$2$4\', false, \'$1\', \'right\')';
$replace[] = 'handle_img_tag(\'$1$3\', false, null,\'left\')';
$replace[] = 'handle_img_tag(\'$2$4\', false, \'$1\', \'left\')';
}
}
$pattern[] = '#\[url\]([^\[]*?)\[/url\]#e';
$pattern[] = '#\[url=([^\[]+?)\](.*?)\[/url\]#e';
$pattern[] = '#\[dhrg=([^\[]+?)\](.*?)\[/dhrg\]#e';
$pattern[] = '#\[dhrg=([^\[]+?)\](.*?)\[/dhrg\]#e';
$pattern[] = '#\[email\]([^\[]*?)\[/email\]#';
$pattern[] = '#\[email=([^\[]+?)\](.*?)\[/email\]#';
$replace[] = 'handle_url_tag(\'$1\')';
$replace[] = 'handle_url_tag(\'$1\', \'$2\')';
$replace[] = 'handle_dhrg_tag(\'$1\')';
$replace[] = 'handle_dhrg_tag(\'$1\', \'$2\')';
$replace[] = '<a href="mailto:$1">$1</a>';
$replace[] = '<a href="mailto:$1">$2</a>';
// This thing takes a while! :)
$text = preg_replace($pattern, $replace, $text);
return $text;
}
//
// Make hyperlinks clickable
//
function do_clickable($text)
{
$text = ' '.$text;
$text = ucp_preg_replace('#(?<=[\s\]\)])(<)?(\[)?(\()?([\'"]?)(https?|ftp|news){1}://([\p{L}\p{N}\-]+\.([\p{L}\p{N}\-]+\.)*[\p{L}\p{N}]+(:[0-9]+)?(/[^\s\[]*[^\s.,?!\[;:-])?)\4(?(3)(\)))(?(2)(\]))(?(1)(>))(?![^\s]*\[/(?:url|img|imgl|imgr|video|audio)\])#uie', 'stripslashes(\'$1$2$3$4\').handle_url_tag(\'$5://$6\', \'$5://$6\', true).stripslashes(\'$4$10$11$12\')', $text);
$text = ucp_preg_replace('#(?<=[\s\]\)])(<)?(\[)?(\()?([\'"]?)(www|ftp)\.(([\p{L}\p{N}\-]+\.)*[\p{L}\p{N}]+(:[0-9]+)?(/[^\s\[]*[^\s.,?!\[;:-])?)\4(?(3)(\)))(?(2)(\]))(?(1)(>))(?![^\s]*\[/(?:url|img|imgl|imgr|video|audio)\])#uie', 'stripslashes(\'$1$2$3$4\').handle_url_tag(\'$5.$6\', \'$5.$6\', true).stripslashes(\'$4$10$11$12\')', $text);
return substr($text, 1);
}
//
// Convert a series of smilies to images
//
function do_smilies($text)
{
global $pun_config, $smilies;
$text = ' '.$text.' ';
foreach ($smilies as $smiley_text => $smiley_img)
{
if (strpos($text, $smiley_text) !== false)
$text = ucp_preg_replace('#(?<=[>\s])'.preg_quote($smiley_text, '#').'(?=[^\p{L}\p{N}])#um', '<img src="'.pun_htmlspecialchars(get_base_url(true).'/img/smilies/'.$smiley_img).'" alt="'.substr($smiley_img, 0, strrpos($smiley_img, '.')).'" />', $text);
}
return substr($text, 1, -1);
}
//
// Parse message text
//
function parse_message($text, $hide_smilies)
{
global $pun_config, $lang_common, $pun_user;
if ($pun_config['o_censoring'] == '1')
$text = censor_words($text);
// Convert applicable characters to HTML entities
$text = pun_htmlspecialchars($text);
// If the message contains a code tag we have to split it up (text within shouldn't be touched)
if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false)
{
list($inside, $outside) = split_text($text, '[code]', '[/code]', $errors);
$text = implode("\1", $outside);
}
if ($pun_config['p_message_bbcode'] == '1' && strpos($text, '[') !== false && strpos($text, ']') !== false)
$text = do_bbcode($text);
if ($pun_config['o_smilies'] == '1' && $pun_user['show_smilies'] == '1' && $hide_smilies == '0')
$text = do_smilies($text);
// Deal with newlines, tabs and multiple spaces
$pattern = array("\n", "\t", ' ', ' ');
$replace = array('<br />', '    ', '  ', '  ');
$text = str_replace($pattern, $replace, $text);
// If we split up the message before we have to concatenate it together again (code tags)
if (isset($inside))
{
$outside = explode("\1", $text);
$text = '';
$num_tokens = count($outside);
for ($i = 0; $i < $num_tokens; ++$i)
{
$text .= $outside[$i];
if (isset($inside[$i]))
// $text .= '</p><div class="codebox"><pre><code>'.pun_trim($inside[$i], "\n\r").'</code></pre></div><p>';
{
$num_lines = (substr_count($inside[$i], "\n"));
$text .= '</p><div class="codebox"><pre'.(($num_lines > 28) ? ' class="vscroll"' : '').'><code>'.pun_trim($inside[$i], "\n\r").'</code></pre></div><p>';
}
}
}
// Add paragraph tag around post, but make sure there are no empty paragraphs
$text = preg_replace('#<br />\s*?<br />((\s*<br />)*)#i', "</p>$1<p>", $text);
$text = str_replace('<p><br />', '<p>', $text);
$text = str_replace('<p></p>', '', '<p>'.$text.'</p>');
return $text;
}
//
// Parse signature text
//
function parse_signature($text)
{
global $pun_config, $lang_common, $pun_user;
if ($pun_config['o_censoring'] == '1')
$text = censor_words($text);
// Convert applicable characters to HTML entities
$text = pun_htmlspecialchars($text);
if ($pun_config['p_sig_bbcode'] == '1' && strpos($text, '[') !== false && strpos($text, ']') !== false)
$text = do_bbcode($text, true);
if ($pun_config['o_smilies_sig'] == '1' && $pun_user['show_smilies'] == '1')
$text = do_smilies($text);
// Deal with newlines, tabs and multiple spaces
$pattern = array("\n", "\t", ' ', ' ');
$replace = array('<br />', '    ', '  ', '  ');
$text = str_replace($pattern, $replace, $text);
// Add paragraph tag around post, but make sure there are no empty paragraphs
$text = preg_replace('#<br />\s*?<br />((\s*<br />)*)#i', "</p>$1<p>", $text);
$text = str_replace('<p><br />', '<p>', $text);
$text = str_replace('<p></p>', '', '<p>'.$text.'</p>');
return $text;
}
Файлы /viewtopic.php и /parser.php редактируем как для Fluxbb 1.5
Сделал фрилансер Wondersmith
Я потратился на этот код, в знак благодарности можете зарегистрироваться по моей партнёрской ссылке на сайт по продаже сео-ссылок с профилей форумов linkum.ru
Редактировался 47linux (2017-03-03 13:16:23)
Offline
Offline
Страницы 1