<?php
function entity_decode($string)
{
$string = html_entity_decode(strip_tags($string));
$string = preg_replace("~�*([0-9a-f]+);~ei", "chr(hexdec(\"\\1\"))", $string);
$string = preg_replace("~�*([0-9]+);~e", "chr(\\1)", $string);
return $string;
}
function rus2uni($str, $isTo = true)
{
$arr = array("\xB8" => "ё", "\xA8" => "Ё");
$i = 192;
for(; $i < 256; ++$i )
{
$arr[chr($i)] = "".dechex($i - 176).";";
}
$str = preg_replace(array("@([а- ]) @i", "@([а- ])@i"), array("\$1 ", " \$1"), $str);
return strtr($str, $isTo ? $arr : array_flip($arr));
}
function switchfileerror($number)
{
global $lang;
switch($number)
{
case 1 :
return $lang['wrong_format'];
case 2 :
return $lang['fatal_copy'];
case 3 :
return $lang['wrong_size'];
case 4 :
return $lang['wrong_format_image'];
case 5 :
return $lang['wrong_format_file'];
}
}
function getfileextension($param)
{
$p = strrpos($param, ".");
return strtolower(substr($param, $p + 1, strlen($param)));
}
function deletefile($file = "")
{
global $config;
if(!empty($file))
{
if(@is_file($config['images_dir'].$file))
{
@unlink($config['images_dir'].$file);
return true;
}
return false;
}
return false;
}
function uploadfile($pic_tmp, $pic_to)
{
global $config;
if(!empty($pic_tmp))
{
$ext = strtoupper(getfileextension($pic_to));
$defname = rand(1, 10000000).rand(1, 100000).".".strtolower($ext);
$filename = $config['images_dir']."pricelist/".$defname;
if($ext == "XLS" || $ext == "DOC")
{
$ndefname = $defname;
while(is_file($filename))
{
$ndefname = rand(1000, 9999).$defname;
$filename = $config['images_dir']."pricelist/".$ndefname;
}
if(!copy($pic_tmp, $filename))
{
return 2;
}
$arr[0] = $ndefname;
return $arr;
}
return 5;
}
}
function uploadpicture($pic_tmp, $pic_to, $number = false)
{
global $config;
if(!empty($pic_tmp))
{
$size = getimagesize($pic_tmp);
if(!is_array($size))
{
return 1;
}
if($size[0] <= 2000 && $size[2] < 2000)
{
$defname = $pic_to;
$filename = $config['images_dir'].$defname;
$ndefname = $defname;
while(is_file($filename))
{
$ndefname = rand(1000, 9999).$defname;
$filename = $config['images_dir'].$ndefname;
}
if(!copy($pic_tmp, $filename))
{
return 2;
}
$dfname = $filename;
$ext = strtoupper(getfileextension($filename));
$pic = $ndefname;
if($ext == "JPG" || $ext == "PNG")
{
require_once($config['modules']['thumbnail']);
$thumb = new thumbnail($dfname);
$thumb->size($config['images_width'], $config['images_height']);
$thumb->quality = 100;
$thumb->output_format = $ext;
$thumb->jpeg_progressive = 1;
$thumb->process();
$filename = $config['images_dir']."middle_".$defname;
$ndefname = $defname;
while(is_file($filename))
{
$ndefname = rand(1000, 9999).$defname;
$filename = $config['images_dir']."middle_".$ndefname;
}
$thumbmiddle = $ndefname;
$thumb->save($filename);
unset($thumb);
}
else
{
$thumbmiddle = $ndefname;
copy($_FILES['image']['tmp_name'], $config['images_dir']."middle_".$defname);
return 4;
}
}
else
{
return 3;
}
}
else
{
$pic = "";
$thumbmiddle = "";
}
$arr[0] = $pic;
$arr[1] = $thumbmiddle;
return $arr;
}
function getnextday($day, $month, $year)
{
if(!checkdate($month, $day + 1, $year))
{
$mday = 1;
$mmonth = $month + 1;
$yyear = $year;
if(!checkdate($mmonth, $mday, $year))
{
$mmonth = 1;
$yyear = $year + 1;
}
}
else
{
$mday = $day + 1;
$mmonth = $month;
$yyear = $year;
}
$result['day'] = $mday;
$result['month'] = $mmonth;
$result['year'] = $yyear;
return $result;
}
function geturl($url, $postData = "")
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if(is_array($postData))
{
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
}
$response = curl_exec($ch);
if(curl_errno($ch))
{
return false;
}
return $response;
}
function deltree($path)
{
if(is_dir($path))
{
if(version_compare(PHP_VERSION, "5.0.0") < 0)
{
$entries = array();
if($handle = opendir($path))
{
while(false !==($file = readdir($handle)))
{
$entries[] = $file;
}
closedir($handle);
}
}
else
{
$entries = scandir($path);
if($entries === false)
{
$entries = array();
}
}
foreach($entries as $entry)
{
if(!($entry != ".") && !($entry != ".."))
{
deltree($path."/".$entry);
}
}
return rmdir($path);
}
return unlink($path);
}
function serial($str = "", $email = "")
{
global $settings;
$type = substr($str, 0, 3);
$len = substr($str, strlen($str) - 1, strlen($str)) + 4;
$str = substr($str, 3, strlen($str) - $len);
$search = array("wq", "re", "yt", "iu", "po", "sa", "fd", "hg", "kj", "lk");
$replace = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
switch($type)
{
case "1st" :
$serials = explode("@%", $str);
if(isset($serials[1]))
{
$host = "scriptoprofessional_".rethostex()."scripto_time";
if(md5($host).md5($host.$host).md5($host.$host.$host).md5($host.$host.$host.$host).md5($host.$host.$host.$host.$host).md5($host.$host.$host.$host.$host.$host) == $serials[1])
{
$time = str_replace($search, $replace, $serials[0]);
if(eregi("^[0-9]{1,}\$", $time))
{
if(time() <= $time)
{
$timestamp = $time - time();
if($timestamp / 86400 <= 2)
{
echo "Внимание! Действие лицензии Scripto catalog заканчиваетс ".date("d-m-Y", $time)."<br>";
}
return true;
}
return false;
}
return false;
}
return false;
}
return false;
case "1sn" :
$host = "scriptoprofessional_".rethostex()."scripto_notime";
if(md5($host).md5($host.$host).md5($host.$host.$host).md5($host.$host.$host.$host).md5($host.$host.$host.$host.$host).md5($host.$host.$host.$host.$host.$host) == $str)
{
return true;
}
return false;
case "unt" :
if(isset($settings['mailadmin']))
{
$mail = $settings['mailadmin'];
}
else
{
$mail = $email;
}
$serials = explode("@%", $str);
if(isset($serials[1]))
{
$host = "scriptoprofessional_".$mail."supernick";
if(md5($host).md5($host.$host).md5($host.$host.$host).md5($host.$host.$host.$host).md5($host.$host.$host.$host.$host).md5($host.$host.$host.$host.$host.$host) == $serials[1])
{
$time = str_replace($search, $replace, $serials[0]);
if(eregi("^[0-9]{1,}\$", $time))
{
if(time() <= $time)
{
$timestamp = $time - time();
if($timestamp / 86400 <= 2)
{
echo "Внимание! Действие лицензии Scripto catalog заканчиваетс ".date("d-m-Y", $time)."<br>";
}
return true;
}
return false;
}
return false;
}
return false;
}
return false;
case "unn" :
if(isset($settings['mailadmin']))
{
$mail = $settings['mailadmin'];
}
else
{
$mail = $email;
}
$host = "scriptoprofessional_".$mail."supernick_noptime";
if(md5($host).md5($host.$host).md5($host.$host.$host).md5($host.$host.$host.$host).md5($host.$host.$host.$host.$host).md5($host.$host.$host.$host.$host.$host) == $str)
{
return true;
}
return false;
}
}
function printtext($img, $font, $x, $y, $text, $color)
{
$fontwidth = imagefontwidth($font);
$fullwidth = strlen($text) * $fontwidth;
imagestring($img, $font, $x - strlen($text) * $fontwidth, $y, $text, $color);
}
function cmp($a, $b)
{
return strcmp($a['caption'], $b['caption']);
}
function cmp2($a, $b)
{
if($a['sort'] == $b['sort'])
{
return 0;
}
if($b['sort'] < $a['sort'])
{
return -1;
}
return 1;
}
function cmp3($a, $b)
{
return strcmp($a['name'], $b['name']);
}
function ftpdircopy($conn, $fromDir, $toDir, $chmod = 495, $verbose = false)
{
$errors = array();
$messages = array();
if(!$conn)
{
$errors[] = "wrong ftp connect";
}
if(!is_dir($fromDir))
{
$errors[] = "source ".$fromDir." is not a directory";
}
if(!empty($errors))
{
if($verbose)
{
foreach($errors as $err)
{
echo "<strong>Error</strong>: ".$err."<br />";
}
}
return false;
}
$exceptions = array(".", "..");
$handle = opendir($fromDir);
while(false !==($item = readdir($handle)))
{
if(!in_array($item, $exceptions))
{
$from = str_replace("//", "/", $fromDir."/".$item);
$to = str_replace("//", "/", $toDir."/".$item);
if(is_file($from))
{
if(@ftp_put($conn_id, $from, $to, FTP_ASCII))
{
ftp_chmod($conn, $to, $chmod);
$messages[] = "File copied from ".$from." to ".$to;
}
else
{
$errors[] = "cannot copy file from ".$from." to ".$to;
}
}
if(is_dir($from))
{
if(@ftp_mkdir($conn, $to))
{
ftp_chmod($conn, $to, $chmod);
$messages[] = "Directory created: ".$to;
}
else
{
$errors[] = "cannot create directory ".$to;
}
ftpdircopy($conn, $from, $to, $chmod, $verbose);
}
}
}
closedir($handle);
if($verbose)
{
foreach($errors as $err)
{
echo "<strong>Error</strong>: ".$err."<br />";
}
foreach($messages as $msg)
{
echo $msg."<br />";
}
}
return true;
}
function dircopy($fromDir, $toDir, $chmod = 495, $verbose = false)
{
$errors = array();
$messages = array();
if(!is_writable($toDir))
{
$errors[] = "target ".$toDir." is not writable";
}
if(!is_dir($toDir))
{
$errors[] = "target ".$toDir." is not a directory";
}
if(!is_dir($fromDir))
{
$errors[] = "source ".$fromDir." is not a directory";
}
if(!empty($errors))
{
if($verbose)
{
foreach($errors as $err)
{
echo "<strong>Error</strong>: ".$err."<br />";
}
}
return false;
}
$exceptions = array(".", "..");
$handle = opendir($fromDir);
while(false !==($item = readdir($handle)))
{
if(!in_array($item, $exceptions))
{
$from = str_replace("//", "/", $fromDir."/".$item);
$to = str_replace("//", "/", $toDir."/".$item);
if(is_file($from))
{
if(is_file($to))
{
unlink($to);
}
if(@copy($from, $to))
{
chmod($to, $chmod);
touch($to, filemtime($from));
$messages[] = "File copied from ".$from." to ".$to;
}
else
{
$errors[] = "cannot copy file from ".$from." to ".$to;
}
}
if(is_dir($from))
{
if(@mkdir($to))
{
chmod($to, $chmod);
$messages[] = "Directory created: ".$to;
}
else
{
$errors[] = "cannot create directory ".$to;
}
dircopy($from, $to, $chmod, $verbose);
}
}
}
closedir($handle);
if($verbose)
{
foreach($errors as $err)
{
echo "<strong>Error</strong>: ".$err."<br />";
}
foreach($messages as $msg)
{
echo $msg."<br />";
}
}
return true;
}
function get_all_urls($str)
{
$tag_name = "(?>(?i)[!a-z](?!--)[-:_a-z]*)";
$param_name = "(?>\"[^\"]*\"|'[^']*'|[^\"'](?:[^\\s>=/]+|/(?!>))*)";
$param_value = "(?>\"[^\"]*\"|'[^']*'|[^\"'\\s>](?:[^\\s>/]+|/(?!>))*)";
$param_pair = "(?>".$param_name."(?:\\s*=\\s*{$param_value}|(?!\\s*=)))";
$params = "(?>(?:\\s+".$param_pair.")*\\s*)";
$tag = "(?></?".$tag_nam."{$params}/?>)";
$comment = "(?>(?s)<!--.*?-->)";
$text = "(?>(?:[^<]+|(?!".$tag.")(?!{$comment})<)+)";
$html_element = "(?>".$text."|{$comment}|{$script}|{$style}|{$tag})";
$html_doc = "(?>(?s)^".$html_element."*\$)";
$tag_a = "^(?i)<a(?:\\s+".$param_name."(?<!href)(?:\\s*=\\s*{$param_value}|(?!\\s*=)))*\\s+href\\s*=\\s*({$param_value})";
preg_match_all("#".$html_element."#", $str, $matches);
$tmp = $matches[0];
$n = sizeof($tmp);
$urls = array();
$i = 0;
for(; $i < $n; ++$i )
{
if(preg_match("#".$tag_a."#", $tmp[$i], $matches))
{
$href = $matches[1];
if($href[0] == "'" || $href[0] == "\"")
{
$href = substr($href, 1, -1);
}
$urls[] = html_entity_decode($href, ENT_QUOTES);
}
}
return $urls;
}
function initializesmarty(&$smarty)
{
global $config;
require($config['modules']['smarty']);
$smarty = new smarty();
$smarty->compile_check = true;
$smarty->debugging = false;
$smarty->template_dir = $config['smarty']['templatedir'];
$smarty->compile_dir = $config['smarty']['compiledir'];
}
function fputcsv_ex($dataArray, $delimiter = ";", $enclosure = "")
{
$string = "";
foreach($dataArray as $line)
{
$writeDelimiter = FALSE;
foreach($line as $dataElement)
{
if($writeDelimiter)
{
$string .= $delimiter;
}
$string .= $enclosure.$dataElement.$enclosure;
$writeDelimiter = TRUE;
}
$string .= $delimiter.chr(13);
}
echo $string;
}
function ftpconnect($ftp_server, $ftp_user_name, $ftp_user_pass)
{
$conn_id = @ftp_connect($ftp_server);
$login_result = @ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if(!$conn_id && !$login_result)
{
exit("Unable connect to FTP using(host: ".$ftp_server.", login: {$ftp_user_name} , password: {$ftp_user_pass})");
}
ftp_pasv($conn_id, true);
return $conn_id;
}
function downloadfromftp($conn, $to, $from)
{
if(ftp_get($conn, $to, $from, FTP_BINARY))
{
return true;
}
exit("Невозможно скачать файл!");
}
function includeoneadmin()
{
global $config;
if(!empty($config['ftpserver']))
{
$conn = ftpconnect($config['ftpserver'], $config['ftplogin'], $config['ftppassword']);
if(is_file($config['base_tmp']))
{
$size1 = filesize($config['base_tmp']);
$size2 = ftp_size($conn, $config['ftppath']);
if($size1 != $size2)
{
downloadfromftp($conn, $config['base_tmp'], $config['ftppath']);
}
}
else
{
downloadfromftp($conn, $config['base_tmp'], $config['ftppath']);
}
ftp_close($conn);
}
}
function vote($id_link, $vote)
{
global $db;
global $config;
global $structure;
$objResponse = new xajaxresponse("windows-1251", true);
$link = $structure->getlinkbyid($id_link);
$ips = explode(";", $link['voters_ip']);
$ip = getip();
$do = false;
if(!is_array($ips))
{
$do = true;
}
else
{
$do = true;
if(in_array($ip, $ips))
{
$do = false;
}
}
$voters = 1;
if($vote < 1 || 5 < $vote)
{
$vote = 0;
$voters = 0;
}
if($do)
{
$voters_ip = $link['voters_ip'].$ip.";";
$db->query("update %LINKS% set vote=vote+".$vote.", voters=voters+1 ,`voters_ip`='{$voters_ip}' where id_link={$id_link}");
}
$objResponse->addassign("votes", "innerHTML", $config['vote']);
return $objResponse;
}
function votestat($id_stat, $vote)
{
global $db;
global $config;
$objResponse = new xajaxresponse("windows-1251", true);
$stat = $structure->getstatbyid($id_stat);
$ips = explode(";", $stat['voters_ip']);
$ip = getip();
$do = false;
if(!is_array($ips))
{
$do = true;
}
else
{
$do = true;
if(in_array($ip, $ips))
{
$do = false;
}
}
$voters = 1;
if($vote < 1 || 5 < $vote)
{
$vote = 0;
$voters = 0;
}
if($do)
{
$voters_ip = $stat['voters_ip'].$ip.";";
$db->query("update %STAT% set vote=vote+".$vote.", voters=voters+1,`voters_ip`='{$voters_ip}' where id_stat={$id_stat}");
}
$objResponse->addassign("votes", "innerHTML", $config['vote']);
return $objResponse;
}
function rethostex($host = false)
{
if(!$host)
{
$host = $_SERVER['HTTP_HOST'];
}
$host = str_replace("www.", "", $host);
if($host[strlen($host) - 1] == "/")
{
$host = substr($host, 0, strlen($host) - 1);
}
$host = str_replace("http://", "", $host);
$host = str_replace("/", "", $host);
$host = str_replace("\\", "", $host);
return $host;
}
function printinfile($newarr, $path, $ftpserver, $ftplogin, $ftppassword, $usenew = true)
{
global $config;
$is_ftp = false;
if(!empty($ftpserver))
{
$is_ftp = true;
$conn = ftpconnect($ftpserver, $ftplogin, $ftppassword);
if(!$conn)
{
return false;
}
downloadfromftp($conn, $config['base_tmp'], $path);
include($config['base_tmp']);
$file = fopen($config['base_tmp'], "w+");
}
else
{
if(is_file($path))
{
@include($path);
}
$file = fopen($path, "w");
}
fwrite($file, "<?\n");
if(isset($versionconfig))
{
foreach($versionconfig as $key => $item)
{
fwrite($file, "\$versionconfig[\"".$key."\"]=\"".$item."\";\n");
}
}
if($usenew && @is_array($baseconfig))
{
foreach($baseconfig as $key => $item)
{
foreach($item as $key2 => $item2)
{
fwrite($file, "\$baseconfig[\"".$key."\"][\"".$key2."\"]=\"".$item2."\";\n");
}
}
}
foreach($newarr as $key => $item)
{
foreach($item as $key2 => $item2)
{
fwrite($file, "\$baseconfig[\"".$key."\"][\"".$key2."\"]=\"".$item2."\";\n");
}
}
fwrite($file, "?>");
fclose($file);
if($is_ftp)
{
$file = fopen($config['base_tmp'], "r");
ftp_delete($conn, $path);
ftp_fput($conn, $path, $file, FTP_BINARY);
ftp_close($conn);
fclose($file);
}
}
function copyfiles($from, $to)
{
global $config;
if(!is_dir($to))
{
@mkdir($to);
}
chmod($to, 509);
if($handle = opendir($from))
{
$has_rand = false;
while(false !==($file = readdir($handle)))
{
if(!($file != ".") && !($file != ".."))
{
if(is_file($from."/".$file))
{
copy($from."/".$file, $to.$file);
}
else
{
copyfiles($from."/".$file, $to.$file);
}
}
}
}
}
function removemagicquotes($data)
{
if(get_magic_quotes_gpc())
{
$newdata = array();
foreach($data as $name => $value)
{
$name = stripslashes($name);
if(is_array($value))
{
$newdata[$name] = removemagicquotes($value);
}
else
{
$newdata[$name] = stripslashes($value);
}
}
return $newdata;
}
return $data;
}
function replaceonce($search, $replace, $content)
{
$pos = strpos($content, $search);
if($pos === false)
{
return $content;
}
return substr($content, 0, $pos).$replace.substr($content, $pos + strlen($search));
}
function cleararrsql($arr, $notArr = array())
{
foreach($arr as $item => $value)
{
if(!in_array($item, $notArr))
{
if(is_array($arr[$item]))
{
$arr[$item] = cleararrsql($value);
}
else
{
$arr[$item] = sql_quote($value);
}
}
}
return $arr;
}
function sql_quote($value)
{
if(get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
if(function_exists("mysql_real_escape_string"))
{
$value = mysql_real_escape_string($value);
return $value;
}
$value = addslashes($value);
return $value;
}
function xmail($from, $to, $subj, $text, $filename)
{
$f = fopen($filename, "rb");
$un = strtoupper(uniqid(time()));
$head = "From: ".$from."\n";
$head .= "To: ".$to."\n";
$head .= "Subject: ".$subj."\n";
$head .= "X-Mailer: PHPMail Tool\n";
$head .= "Reply-To: ".$from."\n";
$head .= "Mime-Version: 1.0\n";
$head .= "Content-Type:multipart/mixed;";
$head .= "boundary=\"----------".$un."\"\n\n";
$zag = "------------".$un."\nContent-Type:text/html;\n";
$zag .= "Content-Transfer-Encoding: 8bit\n\n".$text."\n\n";
$zag .= "------------".$un."\n";
$zag .= "Content-Type: application/octet-stream;";
$zag .= "name=\"".basename($filename)."\"\n";
$zag .= "Content-Transfer-Encoding:base64\n";
$zag .= "Content-Disposition:attachment;";
$zag .= "filename=\"".basename($filename)."\"\n\n";
$zag .= chunk_split(base64_encode(fread($f, filesize($filename))))."\n";
return mail($to."", $subj."", $zag, $head);
}
function removeshouting($string)
{
return $string;
}
function converthost($host)
{
$host = str_replace("www.", "", $host);
if($host[strlen($host) - 1] == "/")
{
$host = substr($host, 0, strlen($host) - 2);
}
return $host;
}
function rethost()
{
$host = $_SERVER['HTTP_HOST'];
$host = str_replace("www.", "", $host);
if($host[strlen($host) - 1] == "/")
{
$host = substr($host, 0, strlen($host) - 2);
}
return $host;
}
function finddomen($str)
{
global $config;
$str = strtolower($str);
if(strpos($str, $_SERVER['HTTP_HOST']) === false)
{
return false;
}
return true;
}
function getip()
{
global $REMOTE_ADDR;
global $HTTP_X_FORWARDED_FOR;
global $HTTP_X_FORWARDED;
global $HTTP_FORWARDED_FOR;
global $HTTP_FORWARDED;
global $HTTP_VIA;
global $HTTP_X_COMING_FROM;
global $HTTP_COMING_FROM;
global $HTTP_SERVER_VARS;
global $HTTP_ENV_VARS;
if(empty($REMOTE_ADDR))
{
if(!empty($_SERVER) || isset($_SERVER['REMOTE_ADDR']))
{
$REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];
}
else if(!empty($_ENV) || isset($_ENV['REMOTE_ADDR']))
{
$REMOTE_ADDR = $_ENV['REMOTE_ADDR'];
}
else if(!empty($HTTP_SERVER_VARS) || isset($HTTP_SERVER_VARS['REMOTE_ADDR']))
{
$REMOTE_ADDR = $HTTP_SERVER_VARS['REMOTE_ADDR'];
}
else if(!empty($HTTP_ENV_VARS) || isset($HTTP_ENV_VARS['REMOTE_ADDR']))
{
$REMOTE_ADDR = $HTTP_ENV_VARS['REMOTE_ADDR'];
}
else if(@getenv("REMOTE_ADDR"))
{
$REMOTE_ADDR = getenv("REMOTE_ADDR");
}
}
if(empty($HTTP_X_FORWARDED_FOR))
{
if(!empty($_SERVER) || isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$HTTP_X_FORWARDED_FOR = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else if(!empty($_ENV) || isset($_ENV['HTTP_X_FORWARDED_FOR']))
{
$HTTP_X_FORWARDED_FOR = $_ENV['HTTP_X_FORWARDED_FOR'];
}
else if(!empty($HTTP_SERVER_VARS) || isset($HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR']))
{
$HTTP_X_FORWARDED_FOR = $HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'];
}
else if(!empty($HTTP_ENV_VARS) || isset($HTTP_ENV_VARS['HTTP_X_FORWARDED_FOR']))
{
$HTTP_X_FORWARDED_FOR = $HTTP_ENV_VARS['HTTP_X_FORWARDED_FOR'];
}
else if(@getenv("HTTP_X_FORWARDED_FOR"))
{
$HTTP_X_FORWARDED_FOR = getenv("HTTP_X_FORWARDED_FOR");
}
}
if(empty($HTTP_X_FORWARDED))
{
if(!empty($_SERVER) || isset($_SERVER['HTTP_X_FORWARDED']))
{
$HTTP_X_FORWARDED = $_SERVER['HTTP_X_FORWARDED'];
}
else if(!empty($_ENV) || isset($_ENV['HTTP_X_FORWARDED']))
{
$HTTP_X_FORWARDED = $_ENV['HTTP_X_FORWARDED'];
}
else if(!empty($HTTP_SERVER_VARS) || isset($HTTP_SERVER_VARS['HTTP_X_FORWARDED']))
{
$HTTP_X_FORWARDED = $HTTP_SERVER_VARS['HTTP_X_FORWARDED'];
}
else if(!empty($HTTP_ENV_VARS) || isset($HTTP_ENV_VARS['HTTP_X_FORWARDED']))
{
$HTTP_X_FORWARDED = $HTTP_ENV_VARS['HTTP_X_FORWARDED'];
}
else if(@getenv("HTTP_X_FORWARDED"))
{
$HTTP_X_FORWARDED = getenv("HTTP_X_FORWARDED");
}
}
if(empty($HTTP_FORWARDED_FOR))
{
if(!empty($_SERVER) || isset($_SERVER['HTTP_FORWARDED_FOR']))
{
$HTTP_FORWARDED_FOR = $_SERVER['HTTP_FORWARDED_FOR'];
}
else if(!empty($_ENV) || isset($_ENV['HTTP_FORWARDED_FOR']))
{
$HTTP_FORWARDED_FOR = $_ENV['HTTP_FORWARDED_FOR'];
}
else if(!empty($HTTP_SERVER_VARS) || isset($HTTP_SERVER_VARS['HTTP_FORWARDED_FOR']))
{
$HTTP_FORWARDED_FOR = $HTTP_SERVER_VARS['HTTP_FORWARDED_FOR'];
}
else if(!empty($HTTP_ENV_VARS) || isset($HTTP_ENV_VARS['HTTP_FORWARDED_FOR']))
{
$HTTP_FORWARDED_FOR = $HTTP_ENV_VARS['HTTP_FORWARDED_FOR'];
}
else if(@getenv("HTTP_FORWARDED_FOR"))
{
$HTTP_FORWARDED_FOR = getenv("HTTP_FORWARDED_FOR");
}
}
if(empty($HTTP_FORWARDED))
{
if(!empty($_SERVER) || isset($_SERVER['HTTP_FORWARDED']))
{
$HTTP_FORWARDED = $_SERVER['HTTP_FORWARDED'];
}
else if(!empty($_ENV) || isset($_ENV['HTTP_FORWARDED']))
{
$HTTP_FORWARDED = $_ENV['HTTP_FORWARDED'];
}
else if(!empty($HTTP_SERVER_VARS) || isset($HTTP_SERVER_VARS['HTTP_FORWARDED']))
{
$HTTP_FORWARDED = $HTTP_SERVER_VARS['HTTP_FORWARDED'];
}
else if(!empty($HTTP_ENV_VARS) || isset($HTTP_ENV_VARS['HTTP_FORWARDED']))
{
$HTTP_FORWARDED = $HTTP_ENV_VARS['HTTP_FORWARDED'];
}
else if(@getenv("HTTP_FORWARDED"))
{
$HTTP_FORWARDED = getenv("HTTP_FORWARDED");
}
}
if(empty($HTTP_VIA))
{
if(!empty($_SERVER) || isset($_SERVER['HTTP_VIA']))
{
$HTTP_VIA = $_SERVER['HTTP_VIA'];
}
else if(!empty($_ENV) || isset($_ENV['HTTP_VIA']))
{
$HTTP_VIA = $_ENV['HTTP_VIA'];
}
else if(!empty($HTTP_SERVER_VARS) || isset($HTTP_SERVER_VARS['HTTP_VIA']))
{
$HTTP_VIA = $HTTP_SERVER_VARS['HTTP_VIA'];
}
else if(!empty($HTTP_ENV_VARS) || isset($HTTP_ENV_VARS['HTTP_VIA']))
{
$HTTP_VIA = $HTTP_ENV_VARS['HTTP_VIA'];
}
else if(@getenv("HTTP_VIA"))
{
$HTTP_VIA = getenv("HTTP_VIA");
}
}
if(empty($HTTP_X_COMING_FROM))
{
if(!empty($_SERVER) || isset($_SERVER['HTTP_X_COMING_FROM']))
{
$HTTP_X_COMING_FROM = $_SERVER['HTTP_X_COMING_FROM'];
}
else if(!empty($_ENV) || isset($_ENV['HTTP_X_COMING_FROM']))
{
$HTTP_X_COMING_FROM = $_ENV['HTTP_X_COMING_FROM'];
}
else if(!empty($HTTP_SERVER_VARS) || isset($HTTP_SERVER_VARS['HTTP_X_COMING_FROM']))
{
$HTTP_X_COMING_FROM = $HTTP_SERVER_VARS['HTTP_X_COMING_FROM'];
}
else if(!empty($HTTP_ENV_VARS) || isset($HTTP_ENV_VARS['HTTP_X_COMING_FROM']))
{
$HTTP_X_COMING_FROM = $HTTP_ENV_VARS['HTTP_X_COMING_FROM'];
}
else if(@getenv("HTTP_X_COMING_FROM"))
{
$HTTP_X_COMING_FROM = getenv("HTTP_X_COMING_FROM");
}
}
if(empty($HTTP_COMING_FROM))
{
if(!empty($_SERVER) || isset($_SERVER['HTTP_COMING_FROM']))
{
$HTTP_COMING_FROM = $_SERVER['HTTP_COMING_FROM'];
}
else if(!empty($_ENV) || isset($_ENV['HTTP_COMING_FROM']))
{
$HTTP_COMING_FROM = $_ENV['HTTP_COMING_FROM'];
}
else if(!empty($HTTP_COMING_FROM) || isset($HTTP_SERVER_VARS['HTTP_COMING_FROM']))
{
$HTTP_COMING_FROM = $HTTP_SERVER_VARS['HTTP_COMING_FROM'];
}
else if(!empty($HTTP_ENV_VARS) || isset($HTTP_ENV_VARS['HTTP_COMING_FROM']))
{
$HTTP_COMING_FROM = $HTTP_ENV_VARS['HTTP_COMING_FROM'];
}
else if(@getenv("HTTP_COMING_FROM"))
{
$HTTP_COMING_FROM = getenv("HTTP_COMING_FROM");
}
}
if(!empty($REMOTE_ADDR))
{
$direct_ip = $REMOTE_ADDR;
}
$proxy_ip = "";
if(!empty($HTTP_X_FORWARDED_FOR))
{
$proxy_ip = $HTTP_X_FORWARDED_FOR;
}
else if(!empty($HTTP_X_FORWARDED))
{
$proxy_ip = $HTTP_X_FORWARDED;
}
else if(!empty($HTTP_FORWARDED_FOR))
{
$proxy_ip = $HTTP_FORWARDED_FOR;
}
else if(!empty($HTTP_FORWARDED))
{
$proxy_ip = $HTTP_FORWARDED;
}
else if(!empty($HTTP_VIA))
{
$proxy_ip = $HTTP_VIA;
}
else if(!empty($HTTP_X_COMING_FROM))
{
$proxy_ip = $HTTP_X_COMING_FROM;
}
else if(!empty($HTTP_COMING_FROM))
{
$proxy_ip = $HTTP_COMING_FROM;
}
if(empty($proxy_ip))
{
return $direct_ip;
}
$is_ip = ereg("^([0-9]{1,3}\\.){3,3}[0-9]{1,3}", $proxy_ip, $regs);
if($is_ip && 0 < count($regs))
{
return $regs[0];
}
return FALSE;
}
function writestatistic()
{
global $rubric;
global $db;
global $config;
global $for_stat;
global $stat_warn;
require_once($config['modules']['browser']);
$browserSearch = array("ie6up", "ie5", "ie4", "gecko", "ns6up", "ns4", "nav", "safari", "opera");
net_useragent_detect::getuseragent();
$ip = getip();
if(!isset($for_stat))
{
$caption = $_SERVER['SCRIPT_URI'];
}
else
{
$caption = $for_stat;
}
$browser = net_useragent_detect::getbrowserstring();
if(!$browser)
{
$browser = $_SERVER['HTTP_USER_AGENT'];
}
if($browser == "Unknown")
{
$browser = $_SERVER['HTTP_USER_AGENT'];
}
$user_agent = $browser;
$referer = $_SERVER['HTTP_REFERER'];
if($referer == "")
{
$referer = "Пуста строка";
}
else if(finddomen($referer))
{
$referer = "С данного сайта";
}
$os = net_useragent_detect::getosstring();
if($stat_warn)
{
$stat_warn = 1;
}
else
{
$stat_warn = 0;
}
$db->query("insert into %STATISTIC% values(NULL,'".$ip."',NULL,'{$os}','{$user_agent}','{$caption}','{$referer}',{$stat_warn})");
}
function errorreporting($on)
{
if($on)
{
@ini_set(display_errors, On);
@ini_set(error_reporting, E_ALL);
}
else
{
@ini_set(display_errors, Off);
@ini_set(error_reporting, E_ALL);
}
}
function getleveldomain($url)
{
$domain = getdomain($url);
$l = strpos($domain, ".");
$level = 0;
while($l !== false)
{
++$level;
$l = strpos($domain, ".", $l + 1);
}
return $level + 1;
}
function getlasturl($url)
{
$host = getdomainex($url);
$url = str_replace("http://", "", $url);
$pos = strpos($url, "/");
if(0 < $pos)
{
$part = substr($url, $pos, strlen($url));
if(substr($part, strlen($part) - 1, strlen($part)) == "/")
{
$part = substr($part, 0, strlen($part) - 1);
}
return $host.$part;
}
return $host;
}
function getdomain($url)
{
preg_match("@^(?:http://)?([^/]+)@i", $url, $matches);
$host = $matches[1];
$host = strtolower(str_replace("www.", "", $host));
return "http://".$host;
}
function getdomainex($url)
{
preg_match("@^(?:http://)?([^/]+)@i", $url, $matches);
$host = $matches[1];
$level = getleveldomain($host);
return "http://".$host;
}
function auth2($login, $password, &$user)
{
global $settings;
global $db;
$res = $db->query("select * from %USERS%");
while($row = mysql_fetch_array($res))
{
if(!($login == $row['login']) && !($password == $row['password']))
{
continue;
}
$user = $row;
$user['password'] = false;
$user['access'] = "user";
return true;
}
$user = false;
return false;
}
function auth($login, $password, &$user)
{
global $settings;
if($login == $settings['login'] && $password == $settings['password'])
{
$user['access'] = "root";
$user['login'] = "login";
return true;
}
return false;
}
function getsettings()
{
global $db;
return mysql_fetch_array(@$db->query("select * from %SETTINGS% WHERE 1"));
}
function mailhtml($to, $from, $subject, $body)
{
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=windows-1251\n";
$headers .= "From: ".$from."\n";
$headers .= "Reply-To: ".$from."\n";
mail($to, $subject, $body, $headers);
}
if(!function_exists("memory_get_usage"))
{
function memory_get_usage()
{
if(substr(PHP_OS, 0, 3) == "WIN")
{
if(substr(PHP_OS, 0, 3) == "WIN")
{
$output = array();
exec("tasklist /FI \"PID eq ".getmypid()."\" /FO LIST", $output);
return preg_replace("/[\\D]/", "", $output[5]) * 1024;
}
}
else
{
$pid = getmypid();
exec("ps -eo%mem,rss,pid | grep ".$pid, $output);
$output = explode(" ", $output[0]);
return $output[1] * 1024;
}
}
}
if(!function_exists("htmlspecialchars_decode"))
{
function htmlspecialchars_decode($str, $quote_style = ENT_COMPAT)
{
return strtr($str, array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style)));
}
}
?>