View file dl/system/functions.php

File size: 14.09Kb
<?php
#********************************** AgS MOD DOWNLOAD CENTR SEA *************************************#
#***************************************************************************************************#
#  /||||||||||||||| *********************  /||||||||||||||| *********************  /||||||||||||||| #
# | ||||||||||||||| ********************* | ||||||||||||||| ********************* | ||||||||||||||| #
# | |||||/////||||| ********************* | |||||/////////  ********************* | |||||/////////  #
# | |||||   | ||||| ****** E-MAIL ******* | |||||           ****** WAP/WEB ****** | |||||           #
# | |||||   | ||||| *** [email protected] *** | |||||           * http://ags.h2m.ru * | ||||||||||||||| #
# | |||||   | ||||| ********************* | ||||||||||||||| ********************* | ||||||||||||||| #
# | |||||   | ||||| ********************* | |||||/////||||| ********************* |///////////||||| #
# | ||||||||||||||| ****** SKYPE ******** | |||||   | ||||| ***** MOD AUTHOR ****           | ||||| #
# | |||||////|||||| ***** agrizz15 ****** | |||||   | ||||| ***** Agris Cišs ****  /||||||||||||||| #
# | |||||   | ||||| ********************* | ||||||||||||||| ********************* | ||||||||||||||| #
# |/////    |/////  ********************* |///////////////  ********************* |///////////////  #
#***************************************************************************************************#
#********************************* MOD by AgS in 2010 @ LATVIA *************************************#


/* Funkcija sintakses krāsošanai*/
function highlight_kods($code) {
	$code=strtr($code,array("&lt;"=>"<","&gt;"=>">","&amp;"=>"&","&#36;"=>"\$","&quot;"=>"\"","&#39;"=>"'","&#92;"=>"\\","&#37;"=>"%","<br>"=>"\r\n","&#94;"=>"^","&#58;"=>":"));
	$code=highlight_string($code,true);
	$code=strtr($code,array("\r\n"=>"<br>","<br />"=>"<br>","\$"=>"&#36;","'"=>"&#39;","\\"=>"&#92;","%"=>"&#37;","^"=>"&#94;",":"=>"&#58;")); //,""=>""
	$code='<div class=d>'.$code.'</div>';
return $code;}


/* Funkcija pārkodēšanai no WIN uz UTF */
function win_to_utf_ru($str) { 
	if (function_exists('mb_convert_encoding')) return mb_convert_encoding($str, 'utf-8', 'windows-1251');
	if (function_exists('iconv')) return iconv('windows-1251', 'utf-8', $str);
		$win1251utf8 = array( 
"\xC0"=>"А","\xC1"=>"Б","\xC2"=>"В","\xC3"=>"Г","\xC4"=>"Д","\xC5"=>"Е","\xA8"=>"Ё","\xC6"=>"Ж","\xC7"=>"З","\xC8"=>"И","\xC9"=>"Й","\xCA"=>"К","\xCB"=>"Л","\xCC"=>"М",
"\xCD"=>"Н","\xCE"=>"О","\xCF"=>"П","\xD0"=>"Р","\xD1"=>"С","\xD2"=>"Т","\xD3"=>"У","\xD4"=>"Ф","\xD5"=>"Х","\xD6"=>"Ц","\xD7"=>"Ч","\xD8"=>"Ш","\xD9"=>"Щ","\xDA"=>"Ъ",
"\xDB"=>"Ы","\xDC"=>"Ь","\xDD"=>"Э","\xDE"=>"Ю","\xDF"=>"Я","\xE0"=>"а","\xE1"=>"б","\xE2"=>"в","\xE3"=>"г","\xE4"=>"д","\xE5"=>"е","\xB8"=>"ё","\xE6"=>"ж","\xE7"=>"з",
"\xE8"=>"и","\xE9"=>"й","\xEA"=>"к","\xEB"=>"л","\xEC"=>"м","\xED"=>"н","\xEE"=>"о","\xEF"=>"п","\xF0"=>"р","\xF1"=>"с","\xF2"=>"т","\xF3"=>"у","\xF4"=>"ф","\xF5"=>"х",
"\xF6"=>"ц","\xF7"=>"ч","\xF8"=>"ш","\xF9"=>"щ","\xFA"=>"ъ","\xFB"=>"ы","\xFC"=>"ь","\xFD"=>"э","\xFE"=>"ю","\xFF"=>"я"); 

return strtr($str, $win1251utf8); 
}


/* Funkcija IP reāla noteikšanai */
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match("|^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$|", $_SERVER['HTTP_X_FORWARDED_FOR'])){
	$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];}
elseif(isset($_SERVER['HTTP_CLIENT_IP']) && preg_match("|^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$|", $_SERVER['HTTP_CLIENT_IP'])) {
	$ip = $_SERVER['HTTP_CLIENT_IP'];}
else {$ip = preg_replace("|[^0-9.]|", "", $_SERVER['REMOTE_ADDR']);}
	$ip=parbaude($ip);


/* Funkcija īstā pārlūka noteikšanai */
if (isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA'])) {
		$browsus = htmlspecialchars(stripslashes($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']));}
elseif(isset($_SERVER['HTTP_USER_AGENT'])) {
		$browsus=htmlspecialchars(stripslashes($_SERVER['HTTP_USER_AGENT']));} else {
		$browsus='Not_detected';}
		$brow=preg_replace('|http://|i','', $browsus);
		$brow=strtok($brow,'(');
		$brow=strtok($brow,' ');
		$brow=substr($brow,0,22);
		$brow=parbaude($brow);


/* Funkcija īsto zīmju pārsaukšanai */
function parbaude($message){ 
	$message=str_replace("|","I",$message); 
	$message=str_replace("||","I",$message);
	$message=htmlspecialchars($message);                  
	$message=str_replace("'","&#39;",$message);            
	$message=str_replace("\"","&#34;",$message);  
	$message=str_replace("\$","&#36;",$message);    
	$message=str_replace("$","&#36;",$message);          
	$message=str_replace("\\","&#92;", $message);                            
	$message=str_replace("`","", $message);  
	$message=str_replace("^","&#94;", $message);   
	$message=str_replace("%","&#37;", $message);  
	$message=str_replace(":","&#58;",$message);  
	$message=preg_replace("|&#58;|",":",$message,3); 
	$message=stripslashes(trim($message));               
return $message;
}


/* Funkcija smailu izvadei un ievietoānai */
function smaidinji($string){
	$dir = opendir (BASE."pic/smiles"); 
while ($file = readdir ($dir)) {
if (ereg ("\.gif$", $file)){
	$smfile[]=str_replace(".gif","",$file);}}
	closedir ($dir);
	rsort($smfile);
foreach($smfile as $smval){
	$string=str_replace(":$smval",'<img src="'.BASE.'pic/smiles/'.$smval.'.gif" alt="">',$string);}
return $string;  
}


/* Funkcija skaistam izmēram */
function izmers($file_size){
if($file_size >= 1073741824){
		$file_size = round($file_size / 1073741824 * 100) / 100 . sys_wgb;
	}elseif(
		$file_size >= 1048576){
		$file_size = round($file_size / 1048576 * 100) / 100 . sys_wmb;
	}elseif(
		$file_size >= 1024){
		$file_size = round($file_size / 1024 * 100) / 100 . sys_wkb;
	}else{
		$file_size = round($file_size) . sys_wb;}
return $file_size;
}

/* Kodē cookies informāciju*/
function cookies_kodesana($plain_data,$cookies_key){
	$key_length=0;
	$all_bin_chars="";
	$cipher_data="";
for($i=0;$i<strlen($plain_data);$i++){
	$p=substr($plain_data,$i,1); 
	$k=substr($cookies_key,$key_length,1); 
	$key_length++;
if($key_length>=strlen($cookies_key)){$key_length=0;}
	$dec_chars=ord($p)^ord($k);
	$dec_chars=$dec_chars + strlen($cookies_key);
	$bin_chars=decbin($dec_chars);
while(strlen($bin_chars)<8){$bin_chars="0".$bin_chars;}
	$all_bin_chars=$all_bin_chars.$bin_chars;
}	
	$m=0;

for($j=0;$j<strlen($all_bin_chars);$j=$j+4){
	$four_bit=substr($all_bin_chars,$j,4);  
	$four_bit_dec=bindec($four_bit);
	$decimal_value=$four_bit_dec * 4 + $m;  
	$base64_value=decimals_to_base64($decimal_value);
	$cipher_data=$cipher_data.$base64_value;
	$m++;
if($m>3){$m=0;}
}
return $cipher_data;
}


/* Funkcija kodēšanai pēc atslēgas */
function decimals_to_base64($str){
	$str=strtr($str,array("64"=>"=","63"=>"-","62"=>"+","61"=>"9","60"=>"8","59"=>"7","58"=>"6","57"=>"5","56"=>"4","55"=>"3","54"=>"2","53"=>"1","52"=>"0","51"=>"z","50"=>"y","49"=>"x","48"=>"w","47"=>"v","46"=>"u","45"=>"t","44"=>"s","43"=>"r","42"=>"q","41"=>"p","40"=>"o","39"=>"n","38"=>"m","37"=>"l","36"=>"k","35"=>"j","34"=>"i","33"=>"h","32"=>"g","31"=>"f","30"=>"e","29"=>"d","28"=>"c","27"=>"b","26"=>"a","25"=>"Z","24"=>"Y","23"=>"X","22"=>"W","21"=>"V","20"=>"U","19"=>"T","18"=>"S","17"=>"R","16"=>"Q","15"=>"P","14"=>"O","13"=>"N","12"=>"M","11"=>"L","10"=>"K","9"=>"J","8"=>"I","7"=>"H","6"=>"G","5"=>"F","4"=>"E","3"=>"D","2"=>"C","1"=>"B","0"=>"A")); 
return $str;
}


/* Atkodē cookies informāciju*/
function cookies_atkodesana($cipher_data,$cookies_key){
	$m=0;
	$all_bin_chars="";

for($i=0;$i<strlen($cipher_data);$i++){
	$c=substr($cipher_data,$i,1);     
	$decimal_value=base64_to_decimal($c);         
	$decimal_value=($decimal_value - $m) / 4;
	$four_bit=decbin($decimal_value);
while(strlen($four_bit)<4){$four_bit="0".$four_bit;}
	$all_bin_chars=$all_bin_chars.$four_bit;
	$m++;
if($m>3){$m=0;}}
	$key_length=0;
	$plain_data="";
for($j=0;$j<strlen($all_bin_chars);$j=$j+8){
	$c=substr($all_bin_chars,$j,8);
	$k=substr($cookies_key,$key_length,1);
	$dec_chars=bindec($c);
	$dec_chars=$dec_chars - strlen($cookies_key);
	$c=chr($dec_chars);
	$key_length++;
if($key_length>=strlen($cookies_key)){
	$key_length=0;}
	$dec_chars=ord($c)^ord($k);
	$p=chr($dec_chars);
	$plain_data=$plain_data.$p;
}
return $plain_data;
}


/* Analogs substr priekš UTF */
function utf_substr($str, $offset, $length = null){
	if (function_exists('mb_substr')) return mb_substr($str, $offset, $length, 'utf-8');
	if (function_exists('iconv_substr')) return iconv_substr($str, $offset, $length, 'utf-8');
		$str=utf_to_win($str);
		$str=substr($str,$offset,$length);
return win_to_utf_ru($str);
}


/* Kodējuma noteikšanas funkcija */
function ir_utf($str) {
	if (function_exists('mb_detect_encoding')){
	if(mb_detect_encoding($str) == "UTF-8") {return 1;} else { return 0;}}

	if(language=="LATVIAN"){
		$letters=array("ā","č","ē","ģ","ī","ķ","ļ","ņ","š","ū","ž");
	}elseif(language=="RUSSIAN"){
		$letters=array("а","б","в","г","д","е","ё","ж","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ч","ш","щ","ъ","ы","ь","э","ю","я");}else{
		$letters=array();}

foreach($letters as $letval){
if(strstr($str,$letval)){return 1; break;} else { return 0;}
}} 

/* Translista burtu bāzes */
if(language=="LATVIAN"){
	$trans1=array("AA","Aa","CH","Ch","EE","Ee","GJ","Gj","II","Ii","KJ","Kj","LJ","Lj","NJ","Nj","SH","Sh","UU","Uu","ZH","Zh","aa","ch","ee","gj","ii","kj","lj","nj","sh","uu","zh","!","_");
	$trans2=array("Ā","Ā","Č","Č","Ē","Ē","Ģ","Ģ","Ī","Ī","Ķ","Ķ","Ļ","Ļ","Ņ","Ņ","Š","Š","Ū","Ū","Ž","Ž","ā","č","ē","ģ","ī","ķ","ļ","ņ","š","ū","ž",""," ");
}elseif(language=="RUSSIAN"){
	$trans1=array("CSH","Csh","ZH","Zh","CH","Ch","SH","Sh","JO","Jo","JE","Je","JU","Ju","JA","Ja","csh","zh","ch","sh","jo","je","ju","ja","A","B","V","G","D","E","Z","I","J","K","L","M","N","O","P","R","S","T","U","F","H","C","&#39;","'","Y","a","b","v","g","d","e","z","i","j","k","l","m","n","o","p","r","s","t","u","f","h","c","&#39;","'","y","!","_");
	$trans2=array("Щ","Щ","Ж","Ж","Ч","Ч","Ш","Ш","Ё","Ё","Э","Э","Ю","Ю","Я","Я","щ","ж","ч","ш","ё","э","ю","я","А","Б","В","Г","Д","Е","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х","Ц","ь","ь","Ы","а","б","в","г","д","е","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ь","ь","ы",""," "); 
}else{
	$trans1=array("!","_");
	$trans2=array(""," "); }


/* Translēt uz LV, RU simboliem */
function trans($string){
	global $trans1, $trans2;
		$string=str_replace($trans1,$trans2,$string);
return $string;}


/* Translēt no LV, RU simoliem uz orģinālu */
function retrans($string){
	global $trans1, $trans2;
		$string=str_replace($trans2,$trans1,$string);
return $string;}


/* Aizvietot "_" ar " " */
function trans2($t){
return str_replace('_',' ',$t);
}


/* Kodu lasītājs ziņām ielādēs */
function bb_kods($text){
	$bbcode = array(
'/\[url\](.+)\[\/url\]/isU'=>'<a href="$1">$1</a>',
'/\[url=(.+)\](.+)\[\/url\]/isU'=>'<a href="$1">$2</a>',
'/\[i\](.+)\[\/i\]/isU'=>'<em>$1</em>',
'/\[b\](.+)\[\/b\]/isU'=>'<strong>$1</strong>',
'/\[u\](.+)\[\/u\]/isU'=>'<span style="text-decoration:underline">$1</span>',
'/\[big\](.+)\[\/big\]/isU'=>'<big>$1</big>',
'/\[small\](.+)\[\/small\]/isU'=>'<small>$1</small>',
'/\[code\](.+)\[\/code\]/isU'=>'<code>$1</code>',
'/\[red\](.+)\[\/red\]/isU'=>'<font color="#ff0000">$1</font>',
'/\[yellow\](.+)\[\/yellow\]/isU'=>'<font color="#ffff22">$1</font>',
'/\[green\](.+)\[\/green\]/isU'=>'<font color="#00bb00">$1</font>',
'/\[blue\](.+)\[\/blue\]/isU'=>'<font color="#0000bb">$1</font>',
'/\[wite\](.+)\[\/wite\]/isU'=>'<font color="#ffffff">$1</font>',
'/\[color=(.+)\](.+)\[\/color\]/isU'=>'<font color="$1">$2</font>'
);
return preg_replace(array_keys($bbcode),array_values($bbcode),$text);
}


/* Tīrīt MySQL daļu pie ievietošanas */
function tirit($txt){
return mysql_escape_string(trim(htmlspecialchars($txt)));
}


/* Izgriezham $k */
function griezt($txt,$k){
return mb_substr($txt, 0, $k);
}


/* Dzēst ārā nevajadzīgos simbolus */
function dzest($text){
	$text = str_replace('&','', $text);
	$text = str_replace('$','', $text);
	$text = str_replace('>','', $text);
	$text = str_replace('<','', $text);
	$text = str_replace('~','', $text);
	$text = str_replace('`','', $text);
	$text = str_replace('#','', $text);
	$text = str_replace('*','', $text);
	return $text;
}


/* Pārbaude ar ieguvi datiem */
function ir_numurs($txt,$name){
	global $mudaki, $_POST, $_GET, $_SESSION;
	if(isset($_POST[$name])) $txt = $_POST[$name];
	elseif (isset($_GET[$name])) $txt = $_GET[$name];
	elseif (isset($_SESSION[$name])) $txt = $_SESSION[$name];
	if ((!ctype_digit($txt) or $txt < 0) AND !empty($txt)) die($mudaki.'</body></html>');
	return;
}


/* Option izvēles funkcija, kura norada izvēlēto */
function izvele_option($value,$real){
if($value != $real){
return;}else{
return 'selected="selected"';
}}


/* Sakam sesiju */


function iegut_sesiju($name)
{
global $_GET, $_SESSION, $setup;
$d = $name;
if(!isset($_SESSION[$name])) {$_SESSION[$name] =  $setup[$name];}
if(isset($_GET[$name])) {$_SESSION[$name] = $_GET[$name];}
return $$name = $_SESSION[$d];
}




/* Atkodēšana pēc atslēgas */
function base64_to_decimal($str){
	$str=strtr($str,array("="=>"64","-"=>"63","+"=>"62","9"=>"61","8"=>"60","7"=>"59","6"=>"58","5"=>"57","4"=>"56","3"=>"55","2"=>"54","1"=>"53","0"=>"52","z"=>"51","y"=>"50","x"=>"49","w"=>"48","v"=>"47","u"=>"46","t"=>"45","s"=>"44","r"=>"43","q"=>"42","p"=>"41","o"=>"40","n"=>"39","m"=>"38","l"=>"37","k"=>"36","j"=>"35","i"=>"34","h"=>"33","g"=>"32","f"=>"31","e"=>"30","d"=>"29","c"=>"28","b"=>"27","a"=>"26","Z"=>"25","Y"=>"24","X"=>"23","W"=>"22","V"=>"21","U"=>"20","T"=>"19","S"=>"18","R"=>"17","Q"=>"16","P"=>"15","O"=>"14","N"=>"13","M"=>"12","L"=>"11","K"=>"10","J"=>"9","I"=>"8","H"=>"7","G"=>"6","F"=>"5","E"=>"4","D"=>"3","C"=>"2","B"=>"1","A"=>"0")); 
return $str;
}







?>