Boss |
|
---|---|
Вот мой вариант парсера для ссылок.
Размещается в parser.php. В настройках включается дополнительно к основному парсеру.
function sed_custom_parse($text, $parse_bbcodes = TRUE, $parse_smilies = TRUE, $parse_newlines = TRUE)
{
if($parse_bbcodes)
{
// Коды. Высокоприоритетная обработка!
$text = preg_replace_callback('`\[code\](.+?)\[/code\]`mis', create_function('$input', 'return("<pre class=\"code\">".sed_bbcode_cdata($input[1])."</pre>");'), $text);
$text = preg_replace_callback('`\[highlight=([\w\-]+)\](.*?)\[/highlight\]`mis', create_function('$input', 'return("<div class=\"highlight\"><pre class=\"".$input[1]."\">".sed_bbcode_cdata($input[2])."</pre></div>");'), $text);
// Свои авто-ссылки.
$text = preg_replace('`(^|\s)http://(www.pctuner.ru|pctuner.ru)([^\s"\'\[]+)`mis', '$1<a href="http://www.pctuner.ru$3">http://www.pctuner.ru$3</a>', $text);
// Чужие авто-ссылки.
$text = preg_replace('`(^|\s)http://([^\s"\'\[]+)`mis', '$1<a href="http://www.pctuner.ru/go.php?url=$2" target="_blank">http://$2</a>', $text);
$text = preg_replace('`(^|\s)(https|ftp)://([^\s"\'\[]+)`mis', '$1<a href="http://www.pctuner.ru/go.php?url=$2://$3" target="_blank">$2://$3</a>', $text);
// Свои бб-ссылки.
$text = preg_replace('`\[url\]([^\s"\'\[]+)pctuner.ru([^\s"\'\[]+)\[/url\]`mis', '<a href="http://www.pctuner.ru$2">http://www.pctuner.ru$2</a>', $text);
$text = preg_replace('`\[url\]pctuner.ru([^\s"\'\[]+)\[/url\]`mis', '<a href="http://www.pctuner.ru$1">http://www.pctuner.ru$1</a>', $text);
$text = preg_replace('`\[url=([^\s"\'\[]+)pctuner.ru([^\s"\'\[]+)\](.+?)\[/url\]`mis', '<a href="http://www.pctuner.ru$2">$3</a>', $text);
$text = preg_replace('`\[url=pctuner.ru([^\s"\'\[]+)\](.+?)\[/url\]`mis', '<a href="http://www.pctuner.ru$1">$2</a>', $text);
// Чужие бб-ссылки.
$text = preg_replace('`\[url\]http://([^\s"\'\[]+)\[/url\]`mis', '<a href="http://www.pctuner.ru/go.php?url=$1" target="_blank">http://$1</a>', $text);
$text = preg_replace('`\[url\](https|ftp)://([^\s"\'\[]+)\[/url\]`mis', '<a href="http://www.pctuner.ru/go.php?url=$1://$2" target="_blank">$1://$2</a>', $text);
$text = preg_replace('`\[url\]([^\s"\'\[]+)\[/url\]`mis', '<a href="http://www.pctuner.ru/go.php?url=$1" target="_blank">$1</a>', $text);
$text = preg_replace('`\[url=http://([^\s"\'\[]+)\](.+?)\[/url\]`mis', '<a href="http://www.pctuner.ru/go.php?url=$1" target="_blank">$2</a>', $text);
$text = preg_replace('`\[url=(https|ftp)://([^\s"\'\[]+)\](.+?)\[/url\]`mis', '<a href="http://www.pctuner.ru/go.php?url=$1://$2" target="_blank">$3</a>', $text);
$text = preg_replace('`\[url=([^\s"\'\[]+)\](.+?)\[/url\]`mis', '<a href="http://www.pctuner.ru/go.php?url=$1" target="_blank">$2</a>', $text);
}
else
{
// Вырезка тегов.
$text = preg_replace("'\[img.*?/img\]'si", "", $text);
$text = preg_replace("'\[thumb.*?/thumb\]'si", "", $text);
$text = preg_replace("'[[^]]*?.*?]'si", "", $text);
}
return $text;
}
Добавлено 3 Минуты спустя: Что там за хрень еще вставилась после слов "Давно уже собираюсь."? Косяк похоже. |