HEX
Server: Apache/2.4.59 (Debian)
System: Linux skycube.cz 4.19.0-25-amd64 #1 SMP Debian 4.19.289-2 (2023-08-08) x86_64
User: ilya (534)
PHP: 7.3.31-1~deb10u7
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: /var/www/ilya/data/www/korunka.ru/includes/functions.php
<?

#————————————————————> CMS Termit <———————————————————————#
#                                                         #
#                Author: Ilya Rudomilov                   #
#                                                         #
#                E-mail: ilya@grafix.ru                   #
#              URL: http://ilya.grafix.ru                 #
#                     ICQ: 206255213                      #
#                                                         #
#—————————————> GrafiX Design — (c) 2005 <————————————————#

function cache_write($dir,$filename,$content) {

	$dir_target = "cache/";
	
	foreach($dir as $dir_once) {
		$dir_target .= $dir_once."/";
		if(!is_dir($dir_target))
			mkdir($dir_target);
	}
	//print $dir_target.$filename;
	
	@unlink($dir_target.$filename);
	
	$handle = fopen($dir_target.$filename,"x+");
	fwrite($handle,$content);
	fclose($handle);

}
function cache_check($dir,$filename,$expire) {

	$dir_target = "cache/";

	foreach($dir as $dir_once) {
		$dir_target .= $dir_once."/";
	}

	if (file_exists($dir_target.$filename))
		if((time()-filemtime($dir_target.$filename))<$expire) {

			return true;
			}
	return false;


}

function cache_read($dir,$filename) {

	$dir_target = "cache/";

	foreach($dir as $dir_once) {
		$dir_target .= $dir_once."/";
	}
	if(filesize($dir_target.$filename)>0) {
		$handle = fopen($dir_target.$filename, "r");
		if(!($handle))
			return false;
		$contents = fread($handle, filesize($dir_target.$filename));
		fclose($handle);
	
		return $contents;
	}
	else
		return "";

}

function cache_delete($dir,$filename) {

	$dir_target = "cache/";

	foreach($dir as $dir_once) {
		$dir_target .= $dir_once."/";
	}
	
	if(file_exists($dir_target.$filename)) {
		unlink($dir_target.$filename);
	}
	else
		return false;
}

function mysql_fetch_array($data) {
	return mysqli_fetch_array($data);
}

function mysql_num_rows($data) {
	return mysqli_num_rows($data);
}

function query($query) {
// ********* Выполнение запроса к базе MySQL *************
global $global_vars;

//timestats_start("sql");
$result = mysqli_query($global_vars['db_connection'],$query) or error("1107");

//$result = mysql_query($query,$global_vars['db_connection']) or print($query);
//timestats_stop("sql");

return $result;
}

function get_images($dir) {
$handle=opendir($dir);
$files = array();
while(false !== ($files[] = readdir($handle)));
sort($files);
closedir($handle);
return $files;
}

function mail_send($recipient,$subject,$message) {
// ********* Отправка email *************
global $global_vars;

$headers = "X-Sender: <".SITE_EMAIL.">\n";
$headers .= "X-Mailer: CMS Termit 1.8\n";
$headers .= "X-Priority: 3 (Normal)\n";
$headers .= "From: <".SITE_EMAIL.">\n";
$headers .= "Reply-To: <".SITE_EMAIL.">\n";
$headers .= "MIME-Version: 1.0\n";

$result = query("SELECT `mail_charset` FROM `languages` WHERE `code`='".$global_vars['lang']."' LIMIT 1;");
$result = mysql_fetch_array($result);

$message = @join("",@file("./skin/".$global_vars['lang']."/"."mails/".$message.".txt"));

$headers .= "Content-Type: text/plain; charset=".$result[0]."\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "MIME-Version: 1.0\n";

@mail($recipient,$subject,$message,$headers);
}

function utf8($text) {
// ********* Перекодирование текста из win1251 в UTF-8 *************
$text = iconv("windows-1251","UTF-8",$text);

return $text;
}

function bb($txt) {
// ********* Конвертация bb-кодов *************
$txt = preg_replace( "#\[b\](.+?)\[/b\]#is", "<b>\\1</b>", $txt );
$txt = preg_replace( "#\[i\](.+?)\[/i\]#is", "<i>\\1</i>", $txt );
$txt = preg_replace( "#\[u\](.+?)\[/u\]#is", "<u>\\1</u>", $txt );
$txt = preg_replace( "#\[s\](.+?)\[/s\]#is", "<s>\\1</s>", $txt );
$txt = preg_replace( "#\(c\)#i"     , "&copy;" , $txt );
$txt = preg_replace( "#\(tm\)#i"    , "&#153;" , $txt );
$txt = preg_replace( "#\(r\)#i"     , "&reg;"  , $txt );
$txt = preg_replace( "#\[email\](\S+?)\[/email\]#i"                                                                , "<a href='mailto:\\1'>\\1</a>", $txt );
$txt = preg_replace( "#\[email\s*=\s*\&quot\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\&quot\;\s*\](.*?)\[\/email\]#i"  , "<a href='mailto:\\1'>\\2</a>", $txt );
$txt = preg_replace( "#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i"                       , "<a href='mailto:\\1'>\\2</a>", $txt );
$txt = preg_replace( "/\n/", "<br>", $txt );
$txt = preg_replace("/&amp;#([0-9]+);/s", "&#\\1;", $txt );

$txt = preg_replace( "#\[url\](\S+?)\[/url\]#ie", "regex_build_url(array('html' => '\\1', 'show' => '\\1'))", $txt );
$txt = preg_replace( "#\[url\s*=\s*\&quot\;\s*(\S+?)\s*\&quot\;\s*\](.*?)\[\/url\]#ie" , "regex_build_url(array('html' => '\\1', 'show' => '\\2'))", $txt );
$txt = preg_replace( "#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#ie", "regex_build_url(array('html' => '\\1', 'show' => '\\2'))", $txt );

return $txt;
}

        function regex_build_url($url=array()) {

                $skip_it = 0;

                // Make sure the last character isn't punctuation.. if it is, remove it and add it to the
                // end array

                if ( preg_match( "/([\.,\?]|&#33;)$/", $url['html'], $match) )
                {
                        $url['end'] .= $match[1];
                        $url['html'] = preg_replace( "/([\.,\?]|&#33;)$/", "", $url['html'] );
                        $url['show'] = preg_replace( "/([\.,\?]|&#33;)$/", "", $url['show'] );
                }

                // Make sure it's not being used in a closing code/quote/html or sql block

                if (preg_match( "/\[\/(html|quote|code|sql)/i", $url['html']) )
                {
                        return $url['html'];
                }

                // clean up the ampersands
                $url['html'] = preg_replace( "/&amp;/" , "&" , $url['html'] );

                // Make sure we don't have a JS link
                $url['html'] = preg_replace( "/javascript:/i", "java script&#58; ", $url['html'] );

                // Do we have http:// at the front?

                if ( ! preg_match("#^(http|news|https|ftp|aim)://#", $url['html'] ) )
                {
                        $url['html'] = 'http://'.$url['html'];
                }

                //-------------------------
                // Tidy up the viewable URL
                //-------------------------

                if (preg_match( "/^<img src/i", $url['show'] )) $skip_it = 1;

                $url['show'] = preg_replace( "/&amp;/" , "&" , $url['show'] );
                $url['show'] = preg_replace( "/javascript:/i", "javascript&#58; ", $url['show'] );

                if ( (strlen($url['show']) -58 ) < 3 )  $skip_it = 1;

                // Make sure it's a "proper" url

                if (!preg_match( "/^(http|ftp|https|news):\/\//i", $url['show'] )) $skip_it = 1;

                $show     = $url['show'];

                if ($skip_it != 1) {
                        $stripped = preg_replace( "#^(http|ftp|https|news)://(\S+)$#i", "\\2", $url['show'] );
                        $uri_type = preg_replace( "#^(http|ftp|https|news)://(\S+)$#i", "\\1", $url['show'] );

                        $show = $uri_type.'://'.substr( $stripped , 0, 35 ).'...'.substr( $stripped , -15   );
                }

                return $url['st'] . "<a href='".$url['html']."' target='_blank'>".$show."</a>" . $url['end'];

        }


function convert_date($sql_date) {
// ********* Перевод даты в удобочитаемую форму день.мес *************
list($sql_date,$time)=split(" ",$sql_date);
list($year,$mon,$day)=split("-",$sql_date);
$convert_date=$day.".".$mon.".".substr($year,2,2);

return $convert_date;
}

function date2stamp($datetime) {
// ****** Конвертация SQL-datetime в SQL-timestamp **********

list($date,$time)=split(" ",$datetime);
list($hour,$mins,$sec) = split(":",$date);
list($year,$mon,$day) = split("-",$date);

$timestamp = mktime($hour,$mins,$sec,$mon,$day,$year);

return $timestamp;
}

function human_date($sql_date) {
// ********* Перевод даты в удобочитаемую форму "день месяц" *************
list($date,$time)=split(" ",$sql_date);
list($year,$mon,$day)=split("-",$date);

switch ($day_w)
        {
        case "0": $day_w = "воскресенье"; break;
        case "1": $day_w = "понедельник"; break;
        case "2": $day_w = "вторник"; break;
        case "3": $day_w = "среда"; break;
        case "4": $day_w = "четверг"; break;
        case "5": $day_w = "пятница"; break;
        case "6": $day_w = "суббота"; break;
        }

switch($mon)
       {
       case 1: $mon="января"; break;
       case 2: $mon="февраля"; break;
       case 3: $mon="марта"; break;
       case 4: $mon="апреля"; break;
       case 5: $mon="мая"; break;
       case 6: $mon="июня"; break;
       case 7: $mon="июля"; break;
       case 8: $mon="августа"; break;
       case 9: $mon="сентября"; break;
       case 10: $mon="октября"; break;
       case 11: $mon="ноября"; break;
       case 12: $mon="декабря"; break;
       default: $mon="";
       }

if (substr($day,0,1)=="0") $day=substr($day,1,1); //Убираем ноль в начале дня, если он есть

$convert_date=$day." ".$mon;
return $convert_date;
}

function text_replace($text) {
// *************** Перевод HTML'я в текст *******************

$search = array ("'<script[^>]*?>.*?</script>'si",  // Strip out javascript
                 "'<[\/\!]*?[^<>]*?>'si",  // Strip out html tags
                 "'([\r\n])[\s]+'",  // Strip out white space
                 "'&(quot|#34);'i",  // Replace html entities
                 "'&(amp|#38);'i",
                 "'&(lt|#60);'i",
                 "'&(gt|#62);'i",
                 "'&(nbsp|#160);'i",
                 "'&(iexcl|#161);'i",
                 "'&(cent|#162);'i",
                 "'&(pound|#163);'i",
                 "'&(copy|#169);'i",
                 "'&#(\d+);'e");  // evaluate as php

$replace = array ("",
                  "",
                  "\\1",
                  "\"",
                  "&",
                  "<",
                  ">",
                  " ",
                  chr(161),
                  chr(162),
                  chr(163),
                  chr(169),
                  "chr(\\1)");

$text = preg_replace ($search, $replace, $text);

return $text;

}


?>