Файл: wapxl.ru/shaxty/classes/bbcode.php
Строк: 223
<?php
function url_replace($str) {
if (!isset($str[3])) {
$target = (strpos($str[1], $_SERVER['HTTP_HOST']) === false) ? ' target="_blank"' : '';
return '<a href="' . $str[1] . '"' . $target . ' class="href">' . $str[2] . '</a>';
} else {
$target = (strpos($str[3], $_SERVER['HTTP_HOST']) === false) ? ' target="_blank"' : '';
return '<a href="' . $str[3] . '"' . $target . ' class="href">' . $str[3] . '</a>';
}
}
function highlight_url($str)
{
if (!function_exists('process_url')) {
function process_url($url)
{
if (!isset($str[3])) {
$target = (strpos($str[1], $_SERVER['HTTP_HOST']) === false) ? ' target="_blank"' : '';
return '<a href="' . $str[1] . '"' . $target . '>' . $str[2] . '</a>';
} else {
$target = (strpos($str[3], $_SERVER['HTTP_HOST']) === false) ? ' target="_blank"' : '';
return '<a href="' . $str[3] . '"' . $target . '>' . $str[3] . '</a>';
}
}
}
return preg_replace_callback('~\[url=(https?://.+?)\](.+?)\[/url\]|(https?://(www.)?[0-9a-z.-]+.[0-9a-z]{2,6}[0-9a-zA-Z/?.~&_=/%-:#]*)~', 'process_url', $str);
}
function nosmiles($string) {
$string = preg_replace("#<img src="(.*?)" alt="" />#i", '', $string);
return $string;
}
function highlight($code) {
//$code = nosmiles($code);
$code = html_entity_decode(trim($code), ENT_QUOTES, 'UTF-8');
$code = strtr($code, array('<' => '<', '>' => '>', '&' => '&', '"' => '"', '$' => '$', '%' => '%', ''' => "'", '\' => '\', '^' => '^', '`' => '`', '|' => '|', '<br />' => "brbr"));
$code = highlight_string(stripslashes($code), true);
$code = strtr($code, array("brbr" => '<br />', '$' => '$', "'" => ''', '%' => '%', '\' => '\', '`' => '`', '^' => '^', '|' => '|'));
// <div class='quote'>
$code = '<br /><div class="phpcode">' . $code . '</div>';
return $code;
}
class bbcode extends core
{
/*
-----------------------------------------------------------------
Обработка тэгов и ссылок
-----------------------------------------------------------------
*/
public static function tags($str)
{
$str = self::bb_code($str);
$str = self::spoiler_bb($str);
// $str = self::highlight_url($str);
$str = self::smiles($str);
$str = self::img_bb($str);
$str = self::vip_bb($str);
return $str;
}
/*
-----------------------------------------------------------------
Удаление bbCode из текста
-----------------------------------------------------------------
*/
public static function notags($str = '')
{
$str = preg_replace('#[color=(.+?)](.+?)[/color]#si', '$2', $str);
$str = preg_replace('![bg=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z-]+)](.+?)[/bg]!is', '$2', $str);
$str = preg_replace('#[spoiler=(.+?)]#si', '$2', $str);
$replace = array(
'[spoiler]' => '',
'[/spoiler]' => '',
'[small]' => '',
'[/small]' => '',
'[big]' => '',
'[/big]' => '',
'[green]' => '',
'[/green]' => '',
'[red]' => '',
'[/red]' => '',
'[blue]' => '',
'[/blue]' => '',
'[b]' => '',
'[/b]' => '',
'[i]' => '',
'[/i]' => '',
'[u]' => '',
'[/u]' => '',
'[s]' => '',
'[/s]' => '',
'[q]' => '',
'[/q]' => '',
'[c]' => '',
'[/c]' => '',
'[*]' => '',
'[/*]' => ''
);
return strtr($str, $replace);
}
public static function bb_code($str = '') {
$str = preg_replace('#php-(.*?)#si', 'PHP функция: 1', $str);
$str = preg_replace(array ('#[code](.*?)[/code]#se'), array ("''.nosmiles(highlight('$1')).''"), str_replace("]n", "]", $str));
$str = preg_replace('#[b](.*?)[/b]#si', '<span style="font-weight: bold;">1</span>', $str);
$str = preg_replace('#[i](.*?)[/i]#si', '<span style="font-style:italic;">1</span>', $str);
$str = preg_replace('#[u](.*?)[/u]#si', '<span style="text-decoration:underline;">1</span>', $str);
$str = preg_replace('#[small](.*?)[/small]#si', '<small>1</small>', $str);
$str = preg_replace('#[del](.*?)[/del]#si', '<del>1</del>', $str);
$str = preg_replace('#[sup](.*?)[/sup]#si', '<sup>1</sup>', $str);
$str = preg_replace('#[sub](.*?)[/sub]#si', '<sub>1</sub>', $str);
$str = preg_replace('#[big](.*?)[/big]#si', '<big>1</big>', $str);
$str = preg_replace('#[s](.*?)[/s]#si', '<span style="text-decoration: line-through;">1</span>', $str);
$str = preg_replace('#[red](.*?)[/red]#si', '<span style="color:red">1</span>', $str);
$str = preg_replace('#[t](.*?)[/t]#si', '<input name="text" type="text" value="1">', $str);
$str = preg_replace('#[green](.*?)[/green]#si', '<span style="color:green">1</span>', $str);
$str = preg_replace('#[blue](.*?)[/blue]#si', '<span style="color:blue">1</span>', $str);
$str = preg_replace('#[q](.*?)[/q]#si', '<div>"1"</div>', $str);
$str = preg_replace('![color=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z-]+)](.+?)[/color]!is', '<span style="color:$1">$2</span>', $str);
$str = preg_replace('![bg=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z-]+)](.+?)[/bg]!is', '<span style="background-color:$1">$2</span>', $str);
$str = preg_replace_callback('~\[url=(http://.+?)\](.+?)\[/url\]|(http://(www.)?[0-9a-zа-яА-Я.-]+.[0-9a-zа-яА-Я]{2,6}[0-9a-zA-Zа-яА-Я/?.-~&;_=%:#]*)~', 'url_replace', $str);
/* $str = @eregi_replace("((http://))((([а-я0-9-]+(.[а-я0-9-]+)*(.[а-я;]{2,3}))|(([0-9]{1,3}.){3}([0-9]{1,3})))((/|?)[а-я0-9~#%&'_+=:;?.-]*)*)", "<a href="\0">\3</a>", $str);*/
$str = preg_replace("!((http://))((([а-я0-9-]+(.[а-я0-9-]+)*(.[а-я;]{2,3}))|(([0-9]{1,3}.){3}([0-9]{1,3})))((/|?)[а-я0-9~#%&'_+=:;?.-]*)*)!is", "<a href="\0" class="href">\3</a>", $str);
return $str;
}
private static function highlight_url($str)
{
if (!function_exists('process_url')) {
function process_url($url)
{
if (!isset($str[3])) {
$target = (strpos($str[1], $_SERVER['HTTP_HOST']) === false) ? ' target="_blank"' : '';
return '<a href="' . $str[1] . '"' . $target . '>' . $str[2] . '</a>';
} else {
$target = (strpos($str[3], $_SERVER['HTTP_HOST']) === false) ? ' target="_blank"' : '';
return '<a href="' . $str[3] . '"' . $target . '>' . $str[3] . '</a>';
}
}
}
return preg_replace_callback('~\[url=(https?://.+?)\](.+?)\[/url\]|(https?://(www.)?[0-9a-z.-]+.[0-9a-z]{2,6}[0-9a-zA-Z/?.~&_=/%-:#]*)~', 'process_url', $str);
}
public static function vip_bb($str){
/*
return preg_replace_callback('#[vip=(.+?)](.+?)[/vip]#si', function($vip) {
global $user, $set;
$vip[1] = intval($vip[1]);
// or core::$user['level']==9
if ($vip[1]==0 or ($vip[1]>0 and core::$user['postsf']>=$vip[1]) or level::dostup('privat')){
return '<span style="color:green">['.$vip[1].' постов]</span>'.$vip[2].'<span style="color:green">['.$vip[1].' постов]</span>';
}else{
return '[<b>Текст скрыт!</b> Чтобы увидеть его вам необходимо набрать <b>'.$vip[1].'</b> постов форума]';
}
}, $str); */ return $str;
}
public static function spoiler_bb($str){
$spoil = rand(0000,9999);
if(func::is_mobile()==0){
$str = preg_replace('#[spoiler](.*?)[/spoiler]#si', '<b>Спойлер</b> <span id="sp'.$spoil.'" style="line-height: 18px"><a href="#" onClick="spoiler('.$spoil.'); return false" class="href">(Отобразить)</a></span><div class="quote" id="spoiler'.$spoil.'" style="display: none">
$1
</div><br />', $str);
$str = preg_replace('#[spoiler=(.*?)](.*?)[/spoiler]#si', '<b>$1</b> <span id="sp'.$spoil.'" style="line-height: 18px"><a href="#" onClick="spoiler('.$spoil.'); return false" class="href">(Отобразить)</a></span><div class="quote" id="spoiler'.$spoil.'" style="display: none">
$2
</div><br />', $str);
}else{
$str = preg_replace('#[spoiler](.*?)[/spoiler]#si', '$1', $str);
$str = preg_replace('#[spoiler=(.*?)](.*?)[/spoiler]#si', '$2', $str);
}
return $str;
}
/*функция тега img*/
public static function img_bb($str){ /*
if (function_exists('curl_init')) {
return preg_replace_callback('#[img](.*?)[/img]#si', function($img) {
$img[1] = "http://".$img[1];
$curl = curl_init($img[1]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_exec($curl);
$mime = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
$size = curl_getinfo($curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
curl_close($curl);
if (!in_array($mime, array('image/png', 'image/jpeg', 'image/gif', 'image/x-png'))) {
return '[нет изображения]';
} else {
$sizs = GetImageSize($img[1]);
$razm = 800;
$width = $sizs[0];
$height = $sizs[1]; //.$width.'x'.$height.'|'.($size/1024)
if ($size <= 1024*500 and $sizs[0] <= 1000 and $sizs[1] <= 1000) {
return '<a href="'.$img[1].'"><img src="'.F.'pic2.php?file='.$img[1].'" alt="Нажмите для просмотра изображения" /></a>';
} else return '<a href="'.$img[1].'">[Изображение слишком большое]</a>';
}
}, $str);
} */ return $str;
}
public static function nosmiles($string) {
$string = preg_replace("#<img src="(.*?)" alt="" />#i", '', $string);
return $string;
}
public static function php_code($str = '') {
//$str = preg_replace(array ('#[code](.*?)[/code]#se'), array ("''.highlight('$1').''"), str_replace("]n", "]", $str));
$str = preg_replace('#[b](.*?)[/b]#si', '<span style="font-weight: bold;">1</span>', $str);
$str = preg_replace('#[i](.*?)[/i]#si', '<span style="font-style:italic;">1</span>', $str);
$str = preg_replace('#[u](.*?)[/u]#si', '<span style="text-decoration:underline;">1</span>', $str);
$str = preg_replace('#[small](.*?)[/small]#si', '<small>1</small>', $str);
$str = preg_replace('#[del](.*?)[/del]#si', '<del>1</del>', $str);
$str = preg_replace('#[s](.*?)[/s]#si', '<span style="text-decoration: line-through;">1</span>', $str);
$str = preg_replace('#[red](.*?)[/red]#si', '<span style="color:red">1</span>', $str);
$str = preg_replace('#[green](.*?)[/green]#si', '<span style="color:green">1</span>', $str);
$str = preg_replace('#[blue](.*?)[/blue]#si', '<span style="color:blue">1</span>', $str);
$str = preg_replace('#[q](.*?)[/q]#si', '<div class="citata">"1"</div>', $str);
$str = preg_replace_callback('~\[url=(http://.+?)\](.+?)\[/url\]|(http://(www.)?[0-9a-z.-]+.[0-9a-z]{2,6}[0-9a-zA-Z/?.-~&;_=%:#]*)~', 'url_replace', $str);
return $str;
}
public static function highlight($code) {
//$code = nosmiles($code);
$code = html_entity_decode(trim($code), ENT_QUOTES, 'UTF-8');
$code = strtr($code, array('<' => '<', '>' => '>', '&' => '&', '"' => '"', '$' => '$', '%' => '%', ''' => "'", '\' => '\', '^' => '^', '`' => '`', '|' => '|', '<br />' => "brbr"));
$code = highlight_string(stripslashes($code), true);
$code = strtr($code, array("brbr" => '<br />', '$' => '$', "'" => ''', '%' => '%', '\' => '\', '`' => '`', '^' => '^', '|' => '|'));
// <div class='quote'>
$code = '<br /><div class="phpcode">' . $code . '</div>';
return $code;
}
public static function smiles($str)
{
$f_smiles=file(H."smiles/smiles.txt");
for ($i=0;$i<count($f_smiles);$i++)
{
$str_sm=explode(' ',trim($f_smiles[$i]));
$str_sm2='';
for ($z=1;$z<count($str_sm);$z++)
{
if ($z>1){$str_sm2.=' ';}
$str_sm2.=$str_sm[$z];
}
$str_sm2=explode(',',$str_sm2);
for ($i2=0;$i2<count($str_sm2);$i2++)
{
$str_sm2[$i2]=stripcslashes(htmlspecialchars($str_sm2[$i2]));
$str=str_replace("$str_sm2[$i2]", "<img src="/smiles/$str_sm[0].gif" alt="" />", $str);
}
}
$f_smiles=file(H."smiles/smiles_mod.txt");
for ($i=0;$i<count($f_smiles);$i++)
{
$str_sm=explode(' ',trim($f_smiles[$i]));
$str_sm2='';
for ($z=1;$z<count($str_sm);$z++)
{
if ($z>1){$str_sm2.=' ';}
$str_sm2.=$str_sm[$z];
}
$str_sm2=explode(',',$str_sm2);
for ($i2=0;$i2<count($str_sm2);$i2++)
{
$str_sm2[$i2]=stripcslashes(htmlspecialchars($str_sm2[$i2]));
$str=str_replace("$str_sm2[$i2]", "<img src="/smiles/$str_sm[0].gif" alt="" />", $str);
}
}
return $str;
}
public static function url_replace($str) {
if (!isset($str[3])) {
$target = (strpos($str[1], $_SERVER['HTTP_HOST']) === false) ? ' target="_blank"' : '';
return '<a href="' . $str[1] . '"' . $target . ' class="href">' . $str[2] . '</a>';
} else {
$target = (strpos($str[3], $_SERVER['HTTP_HOST']) === false) ? ' target="_blank"' : '';
return '<a href="' . $str[3] . '"' . $target . ' class="href">' . $str[3] . '</a>';
}
}
public static function br($str,$br='<br />')
{
$str=eregi_replace("((<br( ?/?)>)|n|r)+","rn", $str);
return $str;
}
public static function php_functions($str){
/*return preg_replace_callback('#!(.*?)!#si', function($php) {
global $user, $set;
$php_func = core:: $db -> queryFetch("SELECT * FROM `php_functions` WHERE `func`=? LIMIT 1;", array($php[1]));
if (isset($php_func['msg']))return 'PHP функция <b>'.$php[1].'</b> <br /> '.nl2br($php_func['msg']).'';
else return $php[1];
}, $str); */ return $str;
}
}