обработка ссылок в bbcode git-svn-id: https://torrentpier2.googlecode.com/svn/trunk@77 a8ac35ab-4ca4-ca47-4c2d-a49a94f06293
This commit is contained in:
nanosimbiot 2011-07-04 21:43:34 +00:00
commit 6f5104a9e5
3 changed files with 33 additions and 36 deletions

View file

@ -57,8 +57,8 @@ $bb_cfg['css_ver'] = 1;
// Increase number of revision after update
$bb_cfg['tp_version'] = '2.0.2';
$bb_cfg['tp_release_state'] = 'TP II r76';
$bb_cfg['tp_release_date'] = '04-07-2011';
$bb_cfg['tp_release_state'] = 'TP II r77';
$bb_cfg['tp_release_date'] = '05-07-2011';
$bb_cfg['board_disabled_msg'] = 'форум временно отключен'; // 'forums temporarily disabled'; // show this msg if board has been disabled via ON/OFF trigger
$bb_cfg['srv_overloaded_msg'] = "Извините, в данный момент сервер перегружен\nПопробуйте повторить запрос через несколько минут";

View file

@ -583,30 +583,25 @@ class bbcode
function init_replacements ()
{
$tpl = $this->tpl;
$url_exp = '[\w\#!$%&~/.\-;:=,?@а-яА-Я\[\]+]+?';
$img_url_exp = 'http://[^\s\?&;:=\#\"<>]+?\.(jpg|jpeg|gif|png)';
$email_exp = '[a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+';
$this->preg = array(
'#\[quote="(.+?)"\]#i' => $tpl['quote_username_open'],
'#\[spoiler="(.+?)"\]#i' => $tpl['spoiler_title_open'],
'#\[list=(a|A|i|I|1)\]#i' => '<ul type="$1">',
'#\[\*=(\d+)\]#i' => '<li value="$1">',
'#\[pre\](.*?)\[/pre\]#si' => '<pre class="post-pre">$1</pre>',
'#\[name=([a-zA-Z0-9_]+?)\]#i' => '<a name="$1"></a>',
'#\[url=\#([a-zA-Z0-9_]+?)\](.*?)\[/url\]#i' => '<a class="postLink-name" href="#$1">$2</a>',
'#\[color=([\#0-9a-zA-Z]+)\]#' => '<span style="color: $1;">',
'#\[size=([1-2]?[0-9])\]#i' => '<span style="font-size: $1px; line-height: normal;">',
'#\[align=(left|right|center|justify)\]#i' => '<span class="post-align" style="text-align: $1;">',
'#\[font="([\w\- \']+)"\]#i' => '<span style="font-family: $1;">',
"#\[img\]($img_url_exp)\[/img\]#i" => $tpl['img'],
"#\[img=(left|right)\]($img_url_exp)\[/img\]\s*#i" => $tpl['img_aligned'],
"#\[email\]($email_exp)\[/email\]#i" => '<a href="mailto:$1">$1</a>',
"#\[url\](https?://$url_exp)\[/url\]#i" => '<a href="$1" class="postLink">$1</a>',
"#\[url\](www\.$url_exp)\[/url\]#i" => '<a href="http://$1" class="postLink">$1</a>',
"#\[url=(https?://$url_exp)\]([^?\n\t].*?)\[/url\]#i" => '<a href="$1" class="postLink">$2</a>',
"#\[url=(www\.$url_exp)\]([^?\n\t].*?)\[/url\]#i" => '<a href="http://$1" class="postLink">$2</a>',
'#\[quote="(.+?)"\]#isu' => $tpl['quote_username_open'],
'#\[spoiler="(.+?)"\]#isu' => $tpl['spoiler_title_open'],
'#\[list=(a|A|i|I|1)\]#isu' => '<ul type="$1">',
'#\[\*=(\d+)\]#isu' => '<li value="$1">',
'#\[pre\](.*?)\[/pre\]#isu' => '<pre class="post-pre">$1</pre>',
'#\[name=([a-zA-Z0-9_]+?)\]#isu' => '<a name="$1"></a>',
'#\[url=\#([a-zA-Z0-9_]+?)\](.*?)\[/url\]#isu' => '<a class="postLink-name" href="#$1">$2</a>',
'#\[color=([\#0-9a-zA-Z]+)\]#isu' => '<span style="color: $1;">',
'#\[size=([1-2]?[0-9])\]#isu' => '<span style="font-size: $1px; line-height: normal;">',
'#\[align=(left|right|center|justify)\]#isu' => '<span class="post-align" style="text-align: $1;">',
'#\[font="([\w\- \']+)"\]#isu' => '<span style="font-family: $1;">',
"#\[img\]($img_url_exp)\[/img\]#isu" => $tpl['img'],
"#\[img=(left|right)\]($img_url_exp)\[/img\]\s*#isu" => $tpl['img_aligned'],
"#\[email\]($email_exp)\[/email\]#isu" => '<a href="mailto:$1">$1</a>',
);
$this->str = array(
@ -794,16 +789,13 @@ class bbcode
{
global $bb_cfg;
$url_regexp = "#
(?<![\"'=])
\b
(
(https?://|ftp://|www\.|ftp\.)
[\w\#!$%&~/.\-;:=?@а-яА-Я\[\]+]+
)
(?![\"']|\[/url|\[/img|</a)
(?=[,!]?\s|[\)<!])
#xiu";
$url_regexp = array();
$url_regexp[] = "#\[url\]([\w]+?://[\w\#!$%&~/.\-;:=,?@а-яА-Я\[\]+]+?)\[/url\]#isu";
$url_regexp[] = "#\[url\]((www|ftp)\.[\w\#!$%&~/.\-;:=,?@а-яА-Я\[\]+]+?)\[/url\]#isu";
$url_regexp[] = "#\[url=([\w]+?://[\w\#!$%&~/.\-;:=,?@а-яА-Я\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#isu";
$url_regexp[] = "#\[url=((www|ftp)\.[\w\#!$%&~/.\-;:=,?@а-яА-Я\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#isu";
$url_regexp[] = "#\[url=([\w]+?://[\w\#$%&~/.\-;:=,?@а-яА-Я\[\]+]*?(jpg|jpeg|gif|png))\]([^?\n\r\t].*?)\[/url\]#isu";
$url_regexp[] = "#(?<![\"'=])\b([https://|ftp://|www\.|ftp\.][\w\#!$%&~/.\-;:=,?@а-яА-Я\[\]+]+)(?![\"']|\[/url|\[/img|</a)(?=[,!]?\s|[\)<!])#xius";
// pad it with a space so we can match things at the start of the 1st line.
$ret = " $text ";
@ -829,7 +821,13 @@ class bbcode
$max_len = 70;
$href = $m[1];
$name = (strlen($href) > $max_len) ? substr($href, 0, $max_len - 19) .'...'. substr($href, -16) : $href;
$name = empty($m[2]) ? $href : $m[2];
if(mb_strlen($name, 'UTF-8'))
{
$anme = mb_substr($name, 0, $max_len - 19, 'UTF-8') .'...'. mb_substr($name, -16, 'UTF-8');
}
if(!preg_match("#{$bb_cfg['server_name']}#", $href))
{
require_once(INC_DIR .'class.idna_convert.php');

View file

@ -1469,22 +1469,21 @@ function get_user_id ($username)
function str_short ($text, $max_length, $space = ' ')
{
if ($max_length && strlen($text) > $max_length)
if ($max_length && mb_strlen($text, 'UTF-8') > $max_length)
{
$text = mb_substr($text, 0, $max_length);
$text = mb_substr($text, 0, $max_length, 'UTF-8');
if ($last_space_pos = $max_length - intval(strpos(strrev($text), $space)))
{
if ($last_space_pos > round($max_length * 3/4))
{
$last_space_pos--;
$text = mb_substr($text, 0, $last_space_pos);
$text = mb_substr($text, 0, $last_space_pos, 'UTF-8');
}
}
$text .= '...';
$text = preg_replace('!&#?(\w+)?;?(\w{1,5})?\.\.\.$!', '...', $text);
}
return $text;
}