Вход Регистрация
Файл: system/function.php
Строк: 283
<?php
//error_reporting(E_ALL);
/*
* Автор - Александр Каплин(TheALex, Саня)
* Все права принадлежат CreaWap.Ru

* Данный скрипт будет постоянно дополняться, поэтому фиксированного времени нет.
* Данный скрипт будет содержать в себе все функции которые будут использольваться на сайте
*/

//Инклюдим файл подключения с базой данных

include_once($_SERVER["DOCUMENT_ROOT"].'/system/db.php');
//инклюдим дополнения
include_once($_SERVER["DOCUMENT_ROOT"].'/system/extensions.php');

define('TIME'time());
function 
bb ($string
{     
global 
$db;         
        
$codes = array ( 
                
// ссылка 
                
'/[url=(.+)](.+)[/url]/is'        =>'<a href="1">2</a>'
                
'/[url](.+)[/url]/isU'             =>'<a href="1">1</a>'
                                
//Картинка
                                
'/[img](.+)[/img]/isU'             =>'<a href="1"><img src="1" style="max-width: 300px; max-height: 500px;"></a>'
                
// наклонный текст 
                
'/[i](.+)[/i]/isU'                => '<i>1</i>'
                
// жирный текст 
                
'/[b](.+)[/b]/isU'                => '<b>1</b>'
                
// подчеркнутый текст 
                
'/[u](.+)[/u]/isU'                => '<u>1</u>'
                
// мелкий текст 
                
'/[small](.+)[/small]/i'          => '<span style="font-size:10px;">1</span>'
                
// большой текст 
                
'/[big](.+)[/big]/i'              => '<span style="font-size:16px;">1</span>'
                
// красный 
                
'/[red](.+)[/red]/i'              => '<span style="color:red;">1</span>'
                
// зеленый 
                
'/[green](.+)[/green]/i'          => '<span style="color:green;">1</span>'
                
// синий 
                
'/[blue](.+)[/blue]/i'            => '<span style="color:blue;">1</span>'
                
// выделение кода 
                
'/[code](.+)[/code]/is'           => '<code>1</code>'
                
'/[quote](.*)[/quote]/is'             => '<div class="quote">1</div>'
                
'/[rating=([0-9.]{1,})](.*)[/rating]/ies'=> 'hide_rated ("1", "2")' 
        
); 
         

        
$string preg_replace (array_keys($codes), array_values ($codes), $string);
         


        
// badurl 
         
       /* $f = file ('./system/badmsg.txt');         
        $c = count($f);  
        if ($c!=0) { 
                for ($i = 0; $i < $c; $i++) { 
                        $l = trim ($f[ $i ]); 
                        if (!empty ($l)) { 
                                $string = preg_replace ('/' . $l . '/i', ' ??? ', $string);
                        } 
                } 
        } */
  
        // новая строка 
        
$string str_replace ("rn""<br/>"$string); 
        
$string str_replace ("[br]""<br/>"$string); 

        
// us{[int]} // вывод пользователя 
        
$string preg_replace_callback ('/us{(d*)}/''nick'$string); 
        
// file{[int]} // вывод файла 
        
$string preg_replace_callback ('/file{(d*)}/''fname'$string); 
        
// topic{[int]}
        
$string preg_replace_callback ('/topic{(d*)}/''tname'$string); 
        
// [php][string][/php] // выделение php кода 
        
$string preg_replace_callback ('/[php](.+)[/php]/i''highlight_code'$string); 
         
         
        
$sm $db->query("SELECT * FROM `smile`");
        while (
$smile $sm->fetch_assoc()) { 
                
$string str_replace($smile['name'], '<img src="/files/smile/'.$smile['file'].'">'$string);
        }
        
        
$as $db->query("SELECT * FROM `antispam`");
        while(
$sp $as->fetch_assoc()){
            
$string str_replace($sp['desc'], '<b><font color="red">[Спам.]</font></b>'$string);
        }

        
$am $db->query("SELECT * FROM `antimat`");
        while(
$m $am->fetch_assoc()){
            
$string str_replace($m['desc'], '<b><font color="red">[Мат.]</font></b>'$string);
        }

        return 
$string




function 
highlight_code($matches



        
// если callback функция 
        
if (is_array($matches)) { 
                
$code $matches[1]; 
        } 
        else { 
                
$code $matches
        } 
                 
        
// перепреобразование кода 
        
$code strtr ($code, array ( 
                
'&lt;'   => '<'
                
'&gt;'   => '>'
                
'&amp;'  => '&'
                
'&quot;' => '"'
                
'&#36;'  => '$'
                
'&#37;'  => '%',  
                
'&#39;'  => "'"
                
'&#92;'  => '\', 
                '
&#94;'  => '^', 
                
'&#96;'  => '`'
                
'&#124;' => '|' 
        
)); 
         
        
// новая строка 
        
$code strtr ($code, array ( 
                
"<br/>" => "rn"
                
"\"    => "" 
        )); 
         
        
$code = highlight_string($code, true); 

        return 
$code
     


function hide_rated(
$rating = 0, $matches

         
        global 
$user
         
        // если callback функция 
        if (is_array(
$matches)) { 
                
$string = $matches[1]
        } 
        else { 
                
$string = $matches
        } 
         
         
        if (
$user['rating']>=$rating) { 
                return 
$string
        } 
        else { 
                return '<div class="
error">Для просмотра этого блока необходимо набрать <b>' . $rating . '</b> рейтинга</div>'; 
        } 


function fname(
$idf){
    global 
$db;

     // если callback функция 
        if (is_array (
$idf)) { 
                
$id = $idf[1]
            } 
        else { 
                
$id = $idf
        } 

    
$id = abs(intval($id));
    if(
$db->query("SELECT `idFROM `zc_fileWHERE `id`='".$id."'")->num_rows==0){
        
$f = 'Удалён';
    }else{
        
$file = $db->query("SELECT `id`, `nameFROM `zc_fileWHERE `id`='".$id."'")->fetch_assoc();
        
$f = '<a href="/zc/file/'.$file['id'].'">'.$file['name'].'</a>';
    }
    return 
$f;
}

function tname(
$idf){
    global 
$db;
    //Если callback функция
    if(is_array(
$idf)){
        
$id = $idf[1];
    }else{
        
$id = $idf;
    }

    
$id = abs(intval($id));
    if(
$db->query("SELECT `idFROM `forum_topicWHERE `id`='".$id."'")->num_rows==0){
        
$t = 'Удалён';
    }else{
        
$topic = $db->query("SELECT `id`, `nameFROM `forum_topicWHERE `id`='".$id."'")->fetch_assoc();
        
$t = '<a href="/forum/topic/'.$topic['id'].'">'.$topic['name'].'</a>';
    }
    return 
$t;
}


//Функция вывода
function output(
$string){
    //Преобразуем html теги в html ущности
    
$string = htmlspecialchars($string);
    //bb code
    
$string = bb($string);
    //Вставляем html код разрыва строки перед каждым переводом строки
    
$string = nl2br($string);
    //Выводим строку
    return 
$string;
}

function guard(
$str)
{
    global 
$db;
    /*
$str = $db->real_escape_string($str);*/
    
$str=preg_replace('""', " ", $str);//вырезка битовой команды реверса строки
    
$str = trim($str);
    return 
$str;
    }

function times(
$time = NULL)
{
    if (!
$time)
        
$time = TIME;

    
$data = date('j.n.y', $time);
    if (
$data == date('j.n.y'))
        
$res = 'Сегодня в '.date('G:i', $time);
    elseif (
$data == date('j.n.y', TIME - 86400))
        
$res = 'Вчера в '.date('G:i', $time);
    elseif (
$data == date('j.n.y', TIME - 172800))
        
$res = 'Позавчера в '.date('G:i', $time);
    else
    {
        
$m = array(
            '0',
            'Января',
            'Февраля',
            'Марта',
            'Апреля',
            'Мая',
            'Июня',
            'Июля',
            'Августа',
            'Сентября',
            'Октября',
            'Ноября',
            'Декабря');

        
$res = date('j '.$m[date('n', $time)].' Y в G:i', $time);
        
$res = str_replace(date('Y'), '', $res);
    }
    return 
$res;
}

function gradient (
$string$from = '', $to = '') 

         
        
$string = iconv ('utf-8', 'windows-1251', $string); 
         
         
        // 
        
$to   = array ( 
                hexdec (
$to[0] . $to[1]),     // r 
                hexdec (
$to[2] . $to[3]),     // g 
                hexdec (
$to[4] . $to[5])      // b 
        ); 
         
         
        // 
        
$from = array ( 
                hexdec (
$from[0] . $from[1]), // r 
                hexdec (
$from[2] . $from[3]), // g 
                hexdec (
$from[4] . $from[5])  // b 
        ); 
         
        
$levels = strlen ($string); 


        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 ]); 
                        if (strlen(
$rgb[ $ii ]) < 2) { 
                                
$rgb[ $ii ] = '0' . $rgb[ $ii ]; 
                        } 
                } 
         
                
$out .= '<span style="color#' . $rgb[0] . $rgb[1] . $rgb[2] . '">' . $string[ $i - 1 ] . '</span>';
                 
        

         
        return 
iconv ('windows-1251''utf-8'$out); 
         



function 
nick($idf){
    global 
$db;
    global 
$design;

    
// если callback функция 
        
if (is_array ($idf)) { 
                
$id $idf[1]; 
            } 
        else { 
                
$id $idf
        } 

    
$id abs(intval($id));
    
$us $db->query("SELECT * FROM `users` WHERE `id`='".$id."'")->fetch_assoc();
    
$us['nick']=htmlspecialchars($us['nick']);
    if(
$us['level']==1){
        
$level ' <font color="green">[Мд.]</font>';
    }elseif(
$us['level']==2){
        
$level ' <font color="green">[Адм.]</font>';
    }elseif(
$us['level']==3){
        
$level ' <font color="green">[Ст. Адм.]</font>';
    }elseif(
$us['level']==4){
        
$level ' <font color="green">[Соз.]</font>';
    }
    if(
$us['scam']==1){
        
$scam ' <b><font color="red">[мошенник]</font></b>';
    }
    
$nick '<a href="/user/'.$us['id'].'">'.$us['nick'].'</a>'.$level.''.$scam;
    if(
$us['sex'] == 1){
        
//Если пользователь мужского рода
        
if($us['online']>=time()-300){
            
//если пользователь онлайн
            
$icon='<img src="/style/themes/'.$design['system_name'].'/images/icons/online/m_on.png">';
            if(!empty(
$us['icon'])){
                
$icon '<img src="/files/icon_nick/'.$us['icon'].'" width="18" height="18">';
            }
            }else{
            
//если пользователь оффлайн
            
$icon='<img src="/style/themes/'.$design['system_name'].'/images/icons/online/m_off.png">';
        }
    }else{
        
//Есди пользователь женского рода
        
if($us['online']>=time()-300){
            
//Если онлайн
            
$icon='<img src="/style/themes/'.$design['system_name'].'/images/icons/online/w_on.png">';
            if(!empty(
$us['icon'])){
                
$icon '<img src="/files/icon_nick/'.$us['icon'].'" width="18" height="18">';
            }
        }else{
            
//Если оффлайн
            
$icon='<img src="/style/themes/'.$design['system_name'].'/images/icons/online/w_off.png">';
        }
    }
    if(!empty(
$us['gradient1']) AND !empty($us['gradient2']) AND $us['gradienth']!=0){
        
$nick '<a href="/user/'.$us['id'].'"><b>'.gradient($us['nick'], $us['gradient1'], $us['gradient2']).'</b></a>'.$level.''.$scam;
    }
    if(
$db->query("SELECT * FROM `users` WHERE `id`='".$id."'")->num_rows == 0){
        
$nick 'Удален';
    }
    return 
$icon.' '.$nick;
}

function 
error($string){
    global 
$gen;
    
$string output($string);
    if(
$string==NULL){
        
$string 'Ошибочка вышла';
    }
    
?>
    <div class="error"><?=$string?></div>
    <?
    
include_once($_SERVER["DOCUMENT_ROOT"].'/style/foot.php');
    exit();
}

function 
success($string){
    
?>
    <div class="success"><?=$string?></div>
    <?
}

function 
mode($mode){
    global 
$user;
    if(
$mode == 'guest'){
        if(isset(
$user['id'])){
            
error('Данная страница доступна только авторизованным пользователям!');
        }
    }elseif(
$mode == 'user'){
        if(!isset(
$user['id'])){
            
error('Данная страница доступна для просмотра только авторизованным пользователям!');
        }
    }
}

function 
level($level){
    global 
$user;
    if(
$user['level']<$level){
        
error('У вас недостаточно прав для просмотра данной страницы!');
    }
}


function 
fsize($file)
{
    if (!
file_exists($file))
        return 
"Файл не найден";
    
$filesize filesize($file);
    
$size = array(
        
'б',
        
'Кб',
        
'Мб',
        
'Гб');
    if (
$filesize pow(10243))
    {
        
$n 3;
    } elseif (
$filesize pow(10242))
    {
        
$n 2;
    } elseif (
$filesize 1024)
    {
        
$n 1;
    } else
    {
        
$n 0;
    }
    
$filesize = ($filesize pow(1024$n));
    
$filesize round($filesize1);
    return 
$filesize.' '.$size[$n];
}

function 
file_force_download($file) {
    if (
file_exists($file)) {
        
// сбрасываем буфер вывода PHP, чтобы избежать переполнения памяти выделенной под скрипт
        // если этого не сделать файл будет читаться в память полностью!
        
if (ob_get_level()) {
            
ob_end_clean();
        }
        
// заставляем браузер показать окно сохранения файла
        
header('Content-Description: File Transfer');
        
header('Content-Type: application/octet-stream');
        
header('Content-Disposition: attachment; filename=' basename($file));
        
header('Content-Transfer-Encoding: binary');
        
header('Expires: 0');
        
header('Cache-Control: must-revalidate');
        
header('Pragma: public');
        
header('Content-Length: ' filesize($file));
        
// читаем файл и отправляем его пользователю
        
readfile($file);
        exit;
    }
}
include_once 
$_SERVER['DOCUMENT_ROOT'].'/system/class/nav.php';
?>
Онлайн: 1
Реклама