Размер файла: 5.44Kb
<?php
Class text
{
static function output($str, $set = array('html' => true, 'links' => true, 'bbcode' => true, 'smiles' => true, 'br' => true))
{
if ($set['html'])
$str = htmlspecialchars($str);
if ($set['links'])
$str = self::links($str);
if ($set['bbcode'])
{
$tmp_str = $str;
$str = self::bbcode($str);
}
if ($set['smiles'] && $tmp_str == $str)
$str = self::smiles($str);
if ($set['br'])
{
$str = nl2br($str);
}
/**
* Антиспам. Разрешается использовать только в SecWind
*/
if (file_exists(H . 'engine/files/data/antispam.db'))
{
$antispam = unserialize(file_get_contents(H . 'engine/files/data/antispam.db'));
$str = str_replace(array_keys($antispam), array_values($antispam), $str);
}
return $str; //esc($str);
}
static function size_data($size = 0)
{
$size_ed = 'б';
if ($size >= 1024)
{
$size = round($size / 1024, 2);
$size_ed = 'Кб';
}
if ($size >= 1024)
{
$size = round($size / 1024, 2);
$size_ed = 'Мб';
}
if ($size >= 1024)
{
$size = round($size / 1024, 2);
$size_ed = 'Гб';
}
return $size . ' ' . $size_ed;
}
static function smiles($msg){return $msg;}
static function passgen($len = 12)
{
$password = '';
$small = 'abcdefghijklmnopqrstuvwxyz';
$large = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$numbers = '1234567890';
for ($i = 0; $i < $len; $i++)
{
switch (mt_rand(1, 3))
{
case 3 :
$password .= $large [mt_rand(0, 25)];
break;
case 2 :
$password .= $small [mt_rand(0, 25)];
break;
case 1 :
$password .= $numbers [mt_rand(0, 9)];
break;
}
}
return $password;
}
static function antimat($str, $user)
{
include_once H.'engine/functions/censure.php';
if ($censure = censure($str))
{
return $censure;
}
else
return false;
}
static function bbcode($msg)
{
$bbcode=array();/*
if ($set['bb_i'])$bbcode['/\[i\](.+)\[\/i\]/isU']='<em>$1</em>';
if ($set['bb_b'])$bbcode['/\[b\](.+)\[\/b\]/isU']='<strong>$1</strong>';
if ($set['bb_u'])$bbcode['/\[u\](.+)\[\/u\]/isU']='<span style="text-decoration:underline;">$1</span>';
if ($set['bb_big'])$bbcode['/\[big\](.+)\[\/big\]/isU']='<span style="font-size:large;">$1</span>';
if ($set['bb_small'])$bbcode['/\[small\](.+)\[\/small\]/isU']='<span style="font-size:small;">$1</span>';
if ($set['bb_red'])$bbcode['/\[red\](.+)\[\/red\]/isU']='<span style="color:#ff0000;">$1</span>';
if ($set['bb_yellow'])$bbcode['/\[yellow\](.+)\[\/yellow\]/isU']='<span style="color:#ffff22;">$1</span>';
if ($set['bb_green'])$bbcode['/\[green\](.+)\[\/green\]/isU']='<span style="color:#00bb00;">$1</span>';
if ($set['bb_blue'])$bbcode['/\[blue\](.+)\[\/blue\]/isU']='<span style="color:#0000bb;">$1</span>';
if ($set['bb_white'])$bbcode['/\[white\](.+)\[\/white\]/isU']='<span style="color:#ffffff;">$1</span>';
if ($set['bb_size'])$bbcode['/\[size=([0-9]+)\](.+)\[\/size\]/isU']='<span style="font-size:$1px;">$2</span>';
if (count($bbcode))$msg= preg_replace(array_keys($bbcode), array_values($bbcode), $msg);
if ($set['bb_code']){
$msg=preg_replace_callback('#<\?(.*?)\?>#sui', 'bbcodehightlight', $msg);
$msg=preg_replace('#\[code\](.*?)\[/code\]#si', '\1', $msg);
}*/
return $msg;
}
static function img_preg($arr)
{
return '<img src="http://'.$_SERVER['HTTP_HOST'].'/go.php?go='.base64_encode(html_entity_decode($arr[1])).'" alt="img" />';
}
static function links_preg1($arr)
{
global $set;
if (preg_match('#^http://'.preg_quote($_SERVER['HTTP_HOST']).'#',$arr[1]) || !preg_match('#://#',$arr[1]))
return '<a href="'.$arr[1].'">'.$arr[2].'</a>';
else
return '<a'.($set['web']?' target="_blank"':null).' href="http://'.$_SERVER['HTTP_HOST'].'/go.php?go='.base64_encode(html_entity_decode($arr[1])).'">'.$arr[2].'</a>';
}
static function links_preg2($arr)
{
global $set;
if (preg_match('#^http://'.preg_quote($_SERVER['HTTP_HOST']).'#',$arr[2]))
return $arr[1].'<a href="'.$arr[2].'">'.$arr[2].'</a>'.$arr[4];
else
return $arr[1].'<a'.($set['web']?' target="_blank"':null).' href="http://'.$_SERVER['HTTP_HOST'].'/go.php?go='.base64_encode(html_entity_decode($arr[2])).'">'.$arr[2].'</a>'.$arr[4];
}
static function links($msg)
{
return $msg;
global $set;
if ($set['bb_img'])$msg=preg_replace_callback('/\[img\](.+)\[\/img\]/isU', 'text::img_preg', $msg);
if ($set['bb_url'])$msg=preg_replace_callback('/\[url=(.+)\](.+)\[\/url\]/isU', 'text::links_preg1', $msg);
if ($set['bb_http'])$msg=preg_replace_callback('~(^|\s)([a-z]+://([^ \r\n\t`\'"]+))(\s|$)~iu', 'text::links_preg2', $msg);
return $msg;
}
}