Файл: system/inc/functions.php
Строк: 514
<?php
function display_error($content) {
echo "<div class="error">{$content}</div>n";
}
function go($link) {
header('location: '.$link);
exit;
}
function cget($var) {
return htmlspecialchars(trim($var));
}
function dlext($ext){
if(preg_match('/gif|png|jpg|jpeg|bmp|ico|tiff/i', $ext))
{
return img('image.png');
}
elseif(preg_match('/mp3|mid|aac|midi|amr|wav|m4u/i', $ext))
{
return img('music.png');
}
elseif(preg_match('/mp4|avi|3gp|wmv/i', $ext))
{
return img('video.png');
}
elseif(preg_match('/apk|apt/i', $ext))
{
return img('android.png');
}
elseif(preg_match('/ipa|jar|jad|exe|deb|sis|sisx/i', $ext))
{
return img('application.png');
}
elseif(preg_match('/zip|rar|cab|tar|gz|bz|7z/i', $ext))
{
return img('box.png');
}
else
{
return img('topic.png');
}
}
function import_lib($lib_name)
{
if(file_exists(SYS.'/libs/'.$lib_name.'.php'))
{
require_once(SYS.'/libs/'.$lib_name.'.php');
}
else
{
echo 'Library has not exists';
}
}
function rtime($var) {
require_once(SYS.'/classes/lang.php');
global $lang;
if ($var == NULL) {
$var = time();
}
$real_time = date('d.m.Y '.$lang->word('time_in').' H:i', $var);
$date = date('d.m.Y', $var);
$time = date('H:i', $var);
if ($date == date('d.m.Y')) {
$real_time = date(''.$lang->word('today').' '.$lang->word('time_in').' H:i', $var);
}
if ($date == date('d.m.Y', time()-60*60*24)) {
$real_time = date(''.$lang->word('yesterday').' '.$lang->word('time_in').' H:i', $var);
}
return $real_time;
}
function escape($var)
{
return input($var);
}
function input($var) {
global $db;
return htmlspecialchars(substr($db->quote(trim($var)), 1, -1), ENT_QUOTES);
}
function output($var) {
return smiles(tags(antiMat(nl2br($var))));
}
function crypto($var) {
return md5(base64_encode($var) .'_PerfCMS_');
}
//функция антимат
function antiMat($var)
{
$var = strtr($var, array("mostop.net" => "MoSTOP.NeT", "http://mostop.net" => "MoSTOP.NeT"));
return $var;
}
function highlight($code)
{
$code = strtr($code, array (
'<br />' => '',
'\' => 'slash'
));
$code = html_entity_decode($code, ENT_QUOTES, 'UTF-8');
$code = stripslashes($code);
if(!strpos($code,"<?") && substr($code,0,2)!="<?") {
$code="<?phpn".trim($code)."n?>";
}
$code = trim($code);
$code = highlight_string($code,true);
$code = strtr($code, array (
'slash' => '\',
':' => ':',
'[' => '[',
' ' => ' '
));
return '<div class="code">'.$code.'</div>';
}
function tags($var){
global $system;
$var = preg_replace(array ('#[code](.*?)[/code]#se'), array ("''.highlight('$1').''"), str_replace("]n", "]", $var));
if($system['bb_b'] == 'on') { $var = preg_replace('/[b](.+)[/b]/isU', '<b>$1</b>', $var); }
if($system['bb_u'] == 'on') { $var = preg_replace('/[u](.+)[/u]/isU', '<span style="text-decoration:underline;">$1</span>', $var); }
if($system['bb_s'] == 'on') { $var = preg_replace('/[s](.+)[/s]/isU', '<s>$1</s>', $var); }
if($system['bb_i'] == 'on') { $var = preg_replace('/[i](.+)[/i]/isU', '<i>$1</i>', $var); }
if($system['bb_big'] == 'on') { $var = preg_replace('/[big](.+)[/big]/isU', '<span style="font-size:large;">$1</span>', $var); }
if($system['bb_small'] == 'on') { $var = preg_replace('/[small](.+)[/small]/isU', '<span style="font-size:small;">$1</span>', $var); }
if($system['bb_red'] == 'on') { $var = preg_replace('/[red](.+)[/red]/isU', '<span style="color:#ff0000;">$1</span>', $var); }
if($system['bb_yellow'] == 'on') { $var = preg_replace('/[yellow](.+)[/yellow]/isU', '<span style="color:#ffff22;">$1</span>', $var); }
if($system['bb_green'] == 'on') { $var = preg_replace('/[green](.+)[/green]/isU', '<span style="color:#00bb00;">$1</span>', $var); }
if($system['bb_blue'] == 'on') { $var = preg_replace('/[blue](.+)[/blue]/isU', '<span style="color:#0000bb;">$1</span>', $var); }
if($system['bb_color'] == 'on') { $var = preg_replace('/[color=(.+)](.+)[/color]/isU', '<span style="color:$1;">$2</span>', $var); }
if($system['bb_quote'] == 'on') { $var = preg_replace('/[quote](.+)[/quote]/isU', '<div class="quote">$1</div>', $var); }
if($system['bb_size'] == 'on') { $var = preg_replace('/[size=([0-11]+)](.+)[/size]/isU', '<span style="font-size:$1px;">$2</span>', $var); }
$var = preg_replace_callback("~\[url=(https?://.+?)\](.+?)\[/url\]|(https?://([a-zA-Zа-яА-Я0-9./-#?_!=&;]*))~", 'link_parser', $var);
$var = preg_replace("/([a-z0-9.-_]*)@([a-z0-9.-]*).([a-z]*)b/i", '<a href="mailto:$1@$2.$3">$1@$2.$3</a>', $var);
return $var;
}
function link_parser($link_info)
{
if(!$link_info[3])
{
return '<a target="_blank" href="'.$link_info[1].'">'.$link_info[2].'</a>';
}
else
{
return '<a target="_blank" href="'.$link_info[3].'">'.$link_info[3].'</a>';
}
}
function smiles($var) {
$var = str_replace(':)', '<img src="/template/smiles/smile.gif" alt="smile" />', $var);
$var = str_replace(':(', '<img src="/template/smiles/sad.gif" alt="smile" />', $var);
$var = str_replace(';(', '<img src="/template/smiles/cray.gif" alt="smile" />', $var);
$var = str_replace(':D', '<img src="/template/smiles/biggrin.gif" alt="smile" />', $var);
$var = str_replace(':P', '<img src="/template/smiles/blum.gif" alt="smile" />', $var);
$var = str_replace(':bad:', '<img src="/template/smiles/bad.gif" alt="smile" />', $var);
$var = str_replace('8)', '<img src="/template/smiles/cool.gif" alt="smile" />', $var);
$var = str_replace(':happy:', '<img src="/template/smiles/happy.gif" alt="smile" />', $var);
$var = str_replace('%)', '<img src="/template/smiles/wacko.gif" alt="smile" />', $var);
$var = str_replace('%P', '<img src="/template/smiles/wacko1.gif" alt="smile" />', $var);
$var = str_replace(':music:', '<img src="/template/smiles/music.gif" alt="smile" />', $var);
$var = str_replace(':@', '<img src="/template/smiles/yahoo.gif" alt="smile" />', $var);
$var = str_replace(':crazy:', '<img src="/template/smiles/crazy.gif" alt="smile" />', $var);
$var = str_replace('xD', '<img src="/template/smiles/sarcastic.gif" alt="smile" />', $var);
$var = str_replace(':diablo:', '<img src="/template/smiles/diablo.gif" alt="smile" />', $var);
$var = str_replace(':lol:', '<img src="/template/smiles/lol.gif" alt="smile" />', $var);
$var = str_replace(':rofl:', '<img src="/template/smiles/rofl.gif" alt="smile" />', $var);
$var = str_replace(':blush:', '<img src="/template/smiles/blush.gif" alt="smile" />', $var);
$var = str_replace(':bye:', '<img src="/template/smiles/bye2.gif" alt="smile" />', $var);
$var = str_replace(':hi:', '<img src="/template/smiles/hi.gif" alt="smile" />', $var);
$var = str_replace(':dance:', '<img src="/template/smiles/dance.gif" alt="smile" />', $var);
$var = str_replace(':dash:', '<img src="/template/smiles/dash2.gif" alt="smile" />', $var);
$var = str_replace(':beer:', '<img src="/template/smiles/drinks.gif" alt="smile" />', $var);
$var = str_replace(':gamer:', '<img src="/template/smiles/gamer.gif" alt="smile" />', $var);
$var = str_replace(':angel:', '<img src="/template/smiles/girl_angel.gif" alt="smile" />', $var);
$var = str_replace(':heart:', '<img src="/template/smiles/heart.gif" alt="smile" />', $var);
$var = str_replace(':good:', '<img src="/template/smiles/good.gif" alt="smile" />', $var);
$var = str_replace(':hang:', '<img src="/template/smiles/hang1.gif" alt="smile" />', $var);
$var = str_replace(':ireful:', '<img src="/template/smiles/ireful.gif" alt="smile" />', $var);
$var = str_replace(':mad:', '<img src="/template/smiles/mad.gif" alt="smile" />', $var);
$var = str_replace(':mail:', '<img src="/template/smiles/mail1.gif" alt="smile" />', $var);
$var = str_replace(':love:', '<img src="/template/smiles/man_in_love.gif" alt="smile" />', $var);
$var = str_replace(':mocking:', '<img src="/template/smiles/mocking.gif" alt="smile" />', $var);
$var = str_replace(':no:', '<img src="/template/smiles/nea.gif" alt="smile" />', $var);
$var = str_replace(':pardon:', '<img src="/template/smiles/pardon.gif" alt="smile" />', $var);
$var = str_replace(':head:', '<img src="/template/smiles/head.gif" alt="smile" />', $var);
$var = str_replace('o_O', '<img src="/template/smiles/shok.gif" alt="smile" />', $var);
$var = str_replace(':sorry:', '<img src="/template/smiles/sorry.gif" alt="smile" />', $var);
$var = str_replace(':unknown:', '<img src="/template/smiles/unknown.gif" alt="smile" />', $var);
$var = str_replace(':yes:', '<img src="/template/smiles/yes.gif" alt="smile" />', $var);
$var = str_replace(':kiss:', '<img src="/template/smiles/kiss.gif" alt="smile" />', $var);
$var = str_replace(':kiss2:', '<img src="/template/smiles/kiss2.gif" alt="smile" />', $var);
return $var;
}
function browser_type() {
$useragent = $_SERVER['HTTP_USER_AGENT'];
if(preg_match('/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|msie|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)/|plucker|pocket|psp|symbian|treo|up.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|/(k|l|u)|50|54|e-|e/|-[a-w])|libw|lynx|m1-w|m3ga|m50/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(-|2|g)|yas-|your|zeto|zte-/i',substr($useragent,0,4)))
{
return 'wap';
}
else {
return 'web';
}
}
function subtok($string,$chr,$pos,$len = NULL) {
return implode($chr,array_slice(explode($chr,$string),$pos,$len));
}
function browser($agent) {
if(empty($agent)) { $agent = $_SERVER['HTTP_USER_AGENT']; }
if (stripos($agent, 'Avant Browser') !== false) {
return 'Avant Browser';
} elseif (stripos($agent, 'Acoo Browser') !== false) {
return 'Acoo Browser';
} elseif (stripos($agent, 'MyIE2') !== false) {
return 'MyIE2';
} elseif (preg_match('|Iron/([0-9a-z.]*)|i', $agent, $pocket)) {
return 'SRWare Iron ' . subtok($pocket[1], '.', 0, 2);
} elseif (preg_match('|Chrome/([0-9a-z.]*)|i', $agent, $pocket)) {
return 'Chrome ' . subtok($pocket[1], '.', 0, 3);
} elseif (preg_match('#(Maxthon|NetCaptor)( [0-9a-z.]*)?#i', $agent, $pocket)) {
return $pocket[1] . $pocket[2];
} elseif (stripos($agent, 'Safari') !== false && preg_match('|Version/([0-9]{1,2}.[0-9]{1,2})|i', $agent, $pocket)) {
return 'Safari ' . subtok($pocket[1], '.', 0, 3);
} elseif (preg_match('#(NetFront|K-Meleon|Netscape|Galeon|Epiphany|Konqueror|Safari|Opera Mini|Opera Mobile/Opera Mobi)/([0-9a-z.]*)#i', $agent, $pocket)) {
return $pocket[1] . ' ' . subtok($pocket[2], '.', 0, 2);
} elseif (stripos($agent, 'Opera') !== false && preg_match('|Version/([0-9]{1,2}.[0-9]{1,2})|i', $agent, $pocket)) {
return 'Opera ' . $pocket[1];
} elseif (preg_match('|Opera[/ ]([0-9a-z.]*)|i', $agent, $pocket)) {
return 'Opera ' . subtok($pocket[1], '.', 0, 2);
} elseif (preg_match('|Orca/([ 0-9a-z.]*)|i', $agent, $pocket)) {
return 'Orca ' . subtok($pocket[1], '.', 0, 2);
} elseif (preg_match('#(SeaMonkey|Firefox|GranParadiso|Minefield|Shiretoko)/([0-9a-z.]*)#i', $agent, $pocket)) {
return $pocket[1] . ' ' . subtok($pocket[2], '.', 0, 3);
} elseif (preg_match('|rv:([0-9a-z.]*)|i', $agent, $pocket) && strpos($agent, 'Mozilla/') !== false) {
return 'Mozilla ' . subtok($pocket[1], '.', 0, 2);
} elseif (preg_match('|Lynx/([0-9a-z.]*)|i', $agent, $pocket)) {
return 'Lynx ' . subtok($pocket[1], '.', 0, 2);
} elseif (preg_match('|MSIE ([0-9a-z.]*)|i', $agent, $pocket)) {
return 'IE ' . subtok($pocket[1], '.', 0, 2);
} elseif (preg_match('|Googlebot/([0-9a-z.]*)|i', $agent, $pocket)) {
return 'Google Bot ' . subtok($pocket[1], '/', 0, 2);
} elseif (preg_match('|Yandex|i', $agent)) {
return 'Yandex Bot ';
} elseif (preg_match('|Nokia([0-9a-z.-_]*)|i', $agent, $pocket)) {
return 'Nokia '.$pocket[1];
} else {
$agent = preg_replace('|http://|i', '', $agent);
$agent = strtok($agent, '/ ');
$agent = substr($agent, 0, 22);
$agent = subtok($agent, '.', 0, 2);
if (!empty($agent)) {
return $agent;
}
}
return 'Unknown';
}
function gradient($text,$from='',$to='', $mode="hex")
{
if($mode=="hex")
{
$to = hexdec($to[0].$to[1]).",".hexdec($to[2].$to[3]).",".hexdec($to[4].$to[5]);
$from= hexdec($from[0].$from[1]).",".hexdec($from[2].$from[3]).",".hexdec($from[4].$from[5]);
}
if( empty($text) )
return '';
else
$levels=strlen($text);
if (empty($from))
$from = array(0,0,255);
else
$from = explode(",", $from);
if (empty($to))
$to = array(255,0,0);
else
$to = explode(",", $to);
$output = "";
for ($i=1;$i<=$levels;$i++)
{
for ($ii=0;$ii<3;$ii++)
{
$tmp[$ii] = $from[$ii] - $to[$ii];
$tmp[$ii] = floor($tmp[$ii] / $levels);
$rgb[$ii] = $from[$ii] - ($tmp[$ii] * $i);
if ($rgb[$ii] > 255) $rgb[$ii] = 255;
$rgb[$ii] = dechex($rgb[$ii]);
$rgb[$ii] = strtoupper($rgb[$ii]);
if (strlen($rgb[$ii]) < 2) $rgb[$ii] = "0$rgb[$ii]";
}
$output .= ''.$rgb[0].$rgb[1].$rgb[2].'' == '000000' ? '' . mb_substr($text, ($i-1), 1) . '' : "<font color="#".$rgb[0].$rgb[1].$rgb[2]."">" . mb_substr($text, ($i-1), 1) ."</font>";
}
return $output;
}
function avatar_mini($user_nick) {
if(file_exists(ROOT .'/files/avatars/'. cyrlat($user_nick) .'.png')) {
return '<img src="/files/avatars/'. cyrlat($user_nick) .'.png" width="36" height="36" alt="'. $user_nick .'" />';
}
else {
return '<img src="/files/preview/no_photo.png" width="36" height="36" alt="No photo" />';
}
}
function img($name) {
return '<img src="/template/icons/'. $name .'" alt="Icon" /> ';
}
function nick($user_id)
{
global $db;
$user_id = abs(intval($user_id));
if($db->query("SELECT * FROM `users` WHERE `id` = '". $user_id ."'")->rowCount() == 1)
{
$us = $db->query("SELECT * FROM `users` WHERE `id` = '". $user_id ."'")->fetch();
if($us['status'] != NULL && $us['time'] > (time()-600))
{
$on = '<font color="green">['.$us['status'].']</font>';
}
elseif($us['time'] > (time()-600))
{
$on = img('on.png');
}
else
{
$on = img('off.png');
}
if (!empty($us['color1']) or !empty($us['color2'])) {
$gr = '<b>';
$gr2 = '</b>';
}
if (!empty($us['color_nick'])) {
$c1 = $us['color_nick'];
$c2 = $us['color_nick'];
} else {
$c1 = $us['color1'];
$c2 = $us['color2'];
}
if($us['vip'] == 1)
{
$vip = 'vip_';
} else {
$vip = '';
}
if($us['id'] == 2)
{
return avatar_mini($us['nick']) .' '.img($vip.$us['gender'].'_system.png').' <a href="/user/'. $us['id'] .'/">'.$gr.gradient($us['nick'], $c1, $c2). $gr2.'</a> '. $on;
}
else if($us['level'] > 4)
{
return avatar_mini($us['nick']) .' '.img($vip.$us['gender'].'_admin.png').' <a href="/user/'. $us['id'] .'/">'.$gr.gradient($us['nick'], $c1, $c2). $gr2.'</a> '. $on;
}
else
{
return avatar_mini($us['nick']) .' '.img($vip.$us['gender'].'.png').' <a href="/user/'. $us['id'] .'/">'.$gr.gradient($us['nick'], $c1, $c2). $gr2.'</a> '. $on;
}
}
else
{
return 'Пользователь не существует';
}
}
function tnick($user_id) {
global $db;
$user_id = abs(intval($user_id));
if($db->query("SELECT * FROM `users` WHERE `id` = '". $user_id ."'")->rowCount() == 1) {
$us = $db->query("SELECT * FROM `users` WHERE `id` = '". $user_id ."'")->fetch();
return $us['nick'];
} else {
return 'Пользователь не существует';
}
}
function avatar($user_nick) {
if(file_exists(ROOT .'/files/avatars/'. cyrlat($user_nick) .'.png')) {
return '<img src="/files/avatars/'. cyrlat($user_nick) .'.png" alt="'. $user_nick .'" /><br/>';
}
else {
return '<img src="/files/preview/no_photo.png" alt="No photo" /><br/>';
}
}
function cyrlat($cyr_str) {
$tr = array(
"Ґ"=>"G","Ё"=>"YO","Є"=>"E","Ї"=>"YI","І"=>"I",
"і"=>"i","ґ"=>"g","ё"=>"yo","№"=>"","є"=>"e",
"ї"=>"yi","А"=>"A","Б"=>"B","В"=>"V","Г"=>"G",
"Д"=>"D","Е"=>"E","Ж"=>"ZH","З"=>"Z","И"=>"I",
"Й"=>"Y","К"=>"K","Л"=>"L","М"=>"M","Н"=>"N",
"О"=>"O","П"=>"P","Р"=>"R","С"=>"S","Т"=>"T",
"У"=>"U","Ф"=>"F","Х"=>"H","Ц"=>"TS","Ч"=>"CH",
"Ш"=>"SH","Щ"=>"SCH","Ъ"=>"'","Ы"=>"YI","Ь"=>"",
"Э"=>"E","Ю"=>"YU","Я"=>"YA","а"=>"a","б"=>"b",
"в"=>"v","г"=>"g","д"=>"d","е"=>"e","ж"=>"zh",
"з"=>"z","и"=>"i","й"=>"y","к"=>"k","л"=>"l",
"м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r",
"с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"h",
"ц"=>"ts","ч"=>"ch","ш"=>"sh","щ"=>"sch","ъ"=>"",
"ы"=>"yi","ь"=>"","э"=>"e","ю"=>"yu","я"=>"ya",
" "=>"_", "_"=>"_", "~"=>"_", "`" => "", "!"=>"",
"@"=>"_", "#"=>"", "$"=>"", "%"=>"", "^"=>"",
"&"=>"", "*"=>"", "("=>"", ")"=>"", "+"=>"_",
"\"=>"", "="=>"_", ";"=>"", ":"=>"", "?"=>"",
"<"=>"", ">"=>"",","=>"", "."=>"", "'"=>'', '/' => '_'
);
return strtolower(strtr($cyr_str,$tr));
}
function size($var) {
if ($var >= 1073741824) return round($var/1073741824, 2) .' Gb';
else if ($var >= 1048576) return round($var/1048576, 2) .' Mb';
elseif($var >= 1024) return round($var/1024, 2) .' Kb';
else return round($var) .' b';
}
function user_level($user_id) {
global $db;
global $lang;
$user_id = abs(intval($user_id));
if($db->query("SELECT * FROM `users` WHERE `id` = '$user_id'")->rowCount() == 1)
{
$level = $db->query("SELECT level FROM `users` WHERE `id` = '$user_id'")->fetchColumn();
if($level == 1) {
return $lang->word('usermod');
} elseif($level == 2) {
return $lang->word('chatmod');
} elseif($level == 3) {
return $lang->word('forummod');
} elseif($level == 4) {
return $lang->word('sharemod');
} elseif($level == 5) {
return $lang->word('super_moder');
} elseif($level == 6) {
return $lang->word('administrator');
} elseif($level == 7) {
return $lang->word('super_admin');
} else {
return 'Undefined';
}
} else {
return 'User not exists';
}
}
function level($level) {
global $lang;
if($level == 1) {
return $lang->word('usermod');;
} elseif($level == 2) {
return $lang->word('chatmod');
} elseif($level == 3) {
return $lang->word('forummod');
} elseif($level == 4) {
return $lang->word('sharemod');
} elseif($level == 5) {
return $lang->word('super_moder');
} elseif($level == 6) {
return $lang->word('administrator');
} elseif($level == 7) {
return $lang->word('super_admin');
} else {
return 'Undefined';
}
}
function title() {
global $title;
global $system;
if(!empty($title)) { return ''.$title.''; } else { return 'Page of PerfCMS'; }
}
function user_panel() {
global $lang;
global $user;
return (isset($user) ? '<a href="/user/panel/">'. $lang->word('user_panel') .'</a> | <a href="/exit/">'. $lang->word('sign_out') .'</a>' : '<a href="/sign_in/">'. $lang->word('sign_in') .'</a> | <a href="/sign_up/">'. $lang->word('sign_up') .'</a>') . ($user['level'] >= 6 ? ' | <a href="/padmin/">'. $lang->word('admin_panel').'</a>' : NULL);
}
function rrmdir($dir) {
if (is_dir($dir)) {
$files = scandir($dir);
foreach ($files as $file)
if ($file != "." && $file != "..") rrmdir("$dir/$file");
rmdir($dir);
}
else if (file_exists($dir)) unlink($dir);
}
function route_filter($route)
{
$route = escape(htmlentities(strip_tags(trim(($route)))));
return $route;
}
function rez_text( $text, $symbols = 100)
{
$symbols = (int)$symbols;
if( strlen( $text) <= $symbols)
return $text;
$pos = strpos( $text, ' ', $symbols);
return substr( $text, 0, (int)$pos);
}