View file system/xcms_func.php

File size: 19.67Kb
<?php
function smiles($text){
	$text = str_replace('.0.','<img src="/files/images/smiles/0.png">',$text);
	$text = str_replace('.1.','<img src="/files/images/smiles/1.png">',$text);
	$text = str_replace('.2.','<img src="/files/images/smiles/2.png">',$text);
	$text = str_replace('.3.','<img src="/files/images/smiles/3.png">',$text);
	$text = str_replace('.4.','<img src="/files/images/smiles/4.png">',$text);
	$text = str_replace('.5.','<img src="/files/images/smiles/5.png">',$text);
	$text = str_replace('.6.','<img src="/files/images/smiles/6.png">',$text);
	$text = str_replace('.7.','<img src="/files/images/smiles/7.png">',$text);
	$text = str_replace('.8.','<img src="/files/images/smiles/8.png">',$text);
	$text = str_replace('.9.','<img src="/files/images/smiles/9.png">',$text);
	$text = str_replace('.!!.','<img src="/files/images/smiles/10.png">',$text);
	$text = str_replace('.1?.','<img src="/files/images/smiles/11.png">',$text);
	$text = str_replace('.ok.','<img src="/files/images/smiles/12.png">',$text);
	$text = str_replace('.hlop.','<img src="/files/images/smiles/13.png">',$text);
	$text = str_replace('.cool.','<img src="/files/images/smiles/14.png">',$text);
	$text = str_replace('.dog.','<img src="/files/images/smiles/15.png">',$text);
	$text = str_replace('.rus.','<img src="/files/images/smiles/16.png">',$text);
	$text = str_replace('.eng.','<img src="/files/images/smiles/17.png">',$text);
	$text = str_replace('.ukr.','<img src="/files/images/smiles/18.png">',$text);
	$text = str_replace('.diamond.','<img src="/files/images/smiles/19.png">',$text);
	$text = str_replace('.hearth1.','<img src="/files/images/smiles/20.png">',$text);
	$text = str_replace('.hearth2.','<img src="/files/images/smiles/21.png">',$text);
	$text = str_replace('.hearth3.','<img src="/files/images/smiles/22.png">',$text);
	$text = str_replace('.hearth4.','<img src="/files/images/smiles/23.png">',$text);
	$text = str_replace('.hearth5.','<img src="/files/images/smiles/24.png">',$text);
	$text = str_replace('.hearth6.','<img src="/files/images/smiles/25.png">',$text);
	$text = str_replace('.pou.','<img src="/files/images/smiles/26.png">',$text);
	$text = str_replace('.money.','<img src="/files/images/smiles/27.png">',$text);
	$text = str_replace('.+18.','<img src="/files/images/smiles/28.png">',$text);
	$text = str_replace('.refresh1.','<img src="/files/images/smiles/29.png">',$text);
	$text = str_replace('.refresh2.','<img src="/files/images/smiles/30.png">',$text);
	$text = str_replace(':)','<img src="/files/images/smiles/31.png">',$text);
	$text = str_replace('.love.','<img src="/files/images/smiles/32.png">',$text);
	$text = str_replace(':*','<img src="/files/images/smiles/33.png">',$text);
	$text = str_replace('.haha.','<img src="/files/images/smiles/34.png">',$text);
	$text = str_replace('.8D.','<img src="/files/images/smiles/35.png">',$text);
	$text = str_replace('X)','<img src="/files/images/smiles/36.png">',$text);
	$text = str_replace(':D','<img src="/files/images/smiles/37.png">',$text);
	$text = str_replace('.angel.','<img src="/files/images/smiles/38.png">',$text);
	$text = str_replace(';)','<img src="/files/images/smiles/39.png">',$text);
	$text = str_replace(':|','<img src="/files/images/smiles/40.png">',$text);
	$text = str_replace('.hm.','<img src="/files/images/smiles/41.png">',$text);
	$text = str_replace(':-/','<img src="/files/images/smiles/42.png">',$text);
	$text = str_replace('.zloj.','<img src="/files/images/smiles/43.png">',$text);
	$text = str_replace(';(','<img src="/files/images/smiles/44.png">',$text);
	$text = str_replace(':O','<img src="/files/images/smiles/45.png">',$text);
	$text = str_replace('.smushen.','<img src="/files/images/smiles/46.png">',$text);
	$text = str_replace('.zzz.','<img src="/files/images/smiles/47.png">',$text);
	$text = str_replace('.kiss.','<img src="/files/images/smiles/48.png">',$text);
	$text = str_replace('.otstoi.','<img src="/files/images/smiles/49.png">',$text);
	return $text;
}
/* Определение размера */
function formatsize($file_size){
	if($file_size >= 1073741824){$file_size = round($file_size / 1073741824 * 100) / 100 . " Гб";}
	elseif($file_size >= 1048576){$file_size = round($file_size / 1048576 * 100) / 100 . " Мб";}
	elseif($file_size >= 1024){$file_size = round($file_size / 1024 * 100) / 100 . " Кб";}
	else{$file_size = round($file_size) . " байт";}
	return $file_size;
}
/* BB КОДЫ */
function bb_code($text){
	$text = preg_replace('|\[b](.+)\[\/b]|','<b>$1</b>',$text);
	$text = preg_replace('|\[i](.+)\[\/i]|','<i>$1</i>',$text);
	$text = preg_replace('|\[u](.+)\[\/u]|','<u>$1</u>',$text);
	$text = preg_replace('|\[big](.+)\[\/big]|','<big>$1</big>',$text);
	$text = preg_replace('|\[small](.+)\[\/small]|','<small>$1</small>',$text);
	$text = preg_replace('|\[del](.+)\[\/del]|','<del>$1</del>',$text);
	$text = preg_replace('|\[quote](.+)\[\/quote]|','<div class="ads">$1</div>',$text);
	$text = preg_replace('#\[url\=http://(.*)\](.*)\[/url\]#Ui','<a href="http://'.$_SERVER['HTTP_HOST'].'/go?url=http://\\1" target="_blank">\\2</a>',$text);//для ссылок
	$text = preg_replace('|\[img](.+)\[\/img]|','<a href="$1"><img src="$1" alt="" style="height:150px;"/></a>',$text);
	$text = preg_replace('|\[color=red](.+)\[\/color]|','<font color="#dc143c">$1</font>',$text);
	$text = preg_replace('|\[music](.+)\[\/music]|','<object type="application/x-shockwave-flash" data="/ump3player.swf" height="67" width="380">
	<param name="wmode" value="transparent" /><param name="allowFullScreen" value="true" />
	<param name="allowScriptAccess" value="always" /><param name="movie" value="http://'.$_SERVER['HTTP_HOST'].'/ump3player.swf" />
	<param name="FlashVars" value="way=$1&swf=http://'.$_SERVER['HTTP_HOST'].'/ump3player.swf&w=380&h=67&&autoplay=0&q=&skin=grey&volume=100&comment=" />
	</object>',$text);
	$text = preg_replace("/(^|[\n ])([\w]*?)((www|ftp)\.[^ \,\"\t\n\r<]*)/is", "$1$2<a href=\"http://$3\" >$3</a>", $text);
	$text = preg_replace("/(^|[\n ])([\w]*?)((ht|f)tp(s)?:\/\/[\w]+[^ \,\"\n\r\t<]*)/is", "$1$2<a href=\"$3\" >$3</a>", $text);
	/* ХЕШ ТЕГИ */
    $text = preg_replace("/@(\w+)/", '<a href="http://'.$_SERVER['HTTP_HOST'].'/profile$1" target="_blank">profile$1</a>', $text);
    $text = preg_replace("/\#(\w+)/", '<a href="'.$_SERVER['HTTP_HOST'].'/tag/$1" target="_blank">#$1</a>',$text);
	return $text;
}
/* Функция безопасного шифрования в MD5 */
function pass($text){return md5(md5('VKSELL').md5(md5($text)));}
/* Функция постраничной навигации */
function page($k_page=1){ // Выдает текущую страницу
	$page=1;
	if (isset($_GET['page'])){
	if ($_GET['page']=='end')$page=intval($k_page);elseif(is_numeric($_GET['page'])) $page=intval($_GET['page']);}
	if ($page<1)$page=1;
	if ($page>$k_page)$page=$k_page;
	return $page;
}
function k_page($k_post=0,$k_p_str=10){ // Высчитывает количество страниц
	if ($k_post!=0){$v_pages=ceil($k_post/$k_p_str);return $v_pages;}
	else return 1;
}
function str($link='?',$k_page=1,$page=1){ // Вывод номеров страниц (только на первый взгляд кажется сложно ;))
	if ($page<1)$page=1;
	echo'<div class="pages">';
	if($page!=1)echo'<a href="'.$link.'page='.($page-1).'"><span style="float:left;">Пред.</span></a>';else echo'<span style="float:left;">Пред.</span>';
	if($k_page>1 and $page!=$k_page)echo'<span style="float:right;"><a href="'.$link.'page='.($page+1).'">След.</a></span>';else echo'<span style="float:right;">След.</span>';
	echo'</div>';
	echo "<div class=\"pages\">Страница:\n";
	if ($page!=1)echo "<a href=\"".$link."page=1\">1</a>";else echo "<b>1</b>";
	for ($ot=-3; $ot<=3; $ot++){
	if ($page+$ot>1 && $page+$ot<$k_page){
	if ($ot==-3 && $page+$ot>2)echo " ..";
	if ($ot!=0)echo " <a href=\"".$link."page=".($page+$ot)."\">".($page+$ot)."</a>";else echo " <b>".($page+$ot)."</b>";
	if ($ot==3 && $page+$ot<$k_page-1)echo " ..";}}
	if ($page!=$k_page)echo " <a href=\"".$link."page=end\">$k_page</a>";elseif ($k_page>1)echo " <b>$k_page</b>";
	echo "</div>\n";
}
/* Функция отображения времени */
function clock($time){
	$timep= date("j M Y в H:i:s", $time);
	$time_p[0]=date("j n Y", $time);
	$time_p[1]=date("H:i", $time);
	if ($time_p[0]==date("j n Y", time()))$timep=$time_p['1'];
	if ($time_p[0]==date("j n Y", time()-86400))$timep='Вчера, '.$time_p['1'];
	$months_eng = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
	$months_rus = array('Января','Февраля','Марта','Апреля','Мая','Июня','Июля','Августа','Сентября','Октября','Ноября','Декабря');
	$timep = str_replace($months_eng,$months_rus,$timep);
	return $timep;
}
//generates
function passgen($k_simb=8, $types=3) {
	$password="";
	$small="abcdefghijklmnopqrstuvwxyz";
	$large="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	$numbers="1234567890";
	mt_srand((double)microtime()*1000000);
	for ($i=0; $i<$k_simb; $i++) {
		$type=mt_rand(1,min($types,3));
		switch ($type) {
			case 3:$password.=$large[mt_rand(0,25)];break;
			case 2:$password.=$small[mt_rand(0,25)];break;
			case 1:$password.=$numbers[mt_rand(0,9)];break;
		}
	}
	return $password;
}
$passgen=&passgen();

function checkin($str){
	if (function_exists('iconv')) {$str = iconv("UTF-8", "UTF-8", $str);}
	$str = preg_replace('/[^\P{C}\n]+/u', '', $str);
	return trim($str);
}
function protect1($str){
	$str = htmlentities(trim($str), ENT_QUOTES, 'UTF-8');
	$str = checkin($str);
	$str = htmlspecialchars($str);
	return $str;
}
function protect2($text){
	$text = strip_tags($text);
	$text = htmlspecialchars($text);
	$text = mysql_escape_string($text);
	return $text;
}
function protect($text){
	$text = trim(htmlspecialchars(($text)));
	return $text;
}
function back($text){echo'<div class="pages" style="text-align:center;"><a href="'.$text.'" style="display:block;">Назад</a></div>';return;}
function sizer($text){$text=round(filesize($text)/1000).' Кб';return $text;}
function size2($text)  {
    if ($text >= 1000000000000) {
        $text = round($text / 1099511627776, 1);
        $text = 'Тб';
    }  elseif ($text >= 1000000000) {
        $text = round($text / 1073741824, 1);
        $text ='Гб';
    } elseif ($text >= 1000000) {
        $text = round($text / 1048576, 1);
        $unit = 'Мб';
    } elseif ($text >= 1000) {
        $text = round($text / 1024, 1);
        $unit = 'Кб';
    } else {
        $unit = 'б';
        return number_format($text).' '.$unit;
    }
    return number_format($text, 1).' '.$unit;
}
function lvl($sozd, $text){
	if($text==1)$text='<span style="color:blue;">[Мод]</span> ';
	elseif($text==2)$text='<span style="color:blue;">[Мод]</span> ';
	elseif($text==3)$text='<span style="color:blue;">[Мод]</span> ';
	elseif($text==4)$text='<span style="color:blue;">[Мод]</span> ';
	elseif($text==5)$text='<span style="color:blue;">[Адм]</span> ';
	elseif($text==6)$text='<span style="color:blue;">[Ст.Адм]</span> ';
	elseif($text==0)$text='';
	if($sozd==1)$text='<span style="color:red;"><b>[Созд]</b></span> ';
	return $text;
}
function utf8_strrev($str){ // Для подсказки в загадках(обратное слово в utf8)
    preg_match_all('/./us', $str, $ar);
    return implode(array_reverse($ar[0]));
}
function detect_mobile_device(){ // Класс определения устройства
	if(stristr(@$_SERVER['HTTP_USER_AGENT'],'windows')&&!stristr(@$_SERVER['HTTP_USER_AGENT'],'windows ce')) return false;
	if(preg_match('/up.browser|up. link |windows ce|iemobile|mini|mmp|symbian|midp|wap|phone|pocket|mobile|pda|psp/i',
	@$_SERVER['HTTP_USER_AGENT'])) return true;
	if(isset($_SERVER['HTTP_ACCEPT'])&&(stristr($_SERVER['HTTP_ACCEPT'],'text/vnd.wap.wml')||
	stristr($_SERVER['HTTP_ACCEPT'],'application/vnd.wap.xhtml xml'))) return true;
	if(isset($_SERVER['HTTP_X_WAP_PROFILE'])||isset($_SERVER['HTTP_PROFILE'])||
	isset($_SERVER['X-OperaMini-Features'])||isset($_SERVER['UA-pixels'])) return true;
	$a = array ('acs-','alav','alca','amoi','audi','aste','avan','benq','bird','blac',
	'bla z','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
	'ipaq','java', 'jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
	'maui','maxo','midp','mi ts','mmef','mobi','mot-','moto','mwbp','nec-',
	'newt','noki','opwv','palm','pana' ,'pant','pdxg','phil','play','pluc',
	'port','prox','qtek','qwap','sage','sams','s any','sch-','sec-','send',
	'seri','sgh-','shar','sie-','siem','smal','smar','sony ','sph-','symb',
	't-mo','teli','tim-','tosh','tsm-','upg1','upsi','vk-v','voda',' w3c ',
	'wap-','wapa','wapi','wapp','wapr','webc','winw','winw','xda','xda-');
	if(isset($a[ substr (@$_SERVER['HTTP_USER_AGENT'],0,4)]))
	return true;
}
function smile_panel(){
	?>
	<div id="hide1">
	<a onclick="replaceSelectedText(document.getElementById('text'),' .0.');"><?=smiles('.0.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .1.');"><?=smiles('.1.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .2.');"><?=smiles('.2.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .3.');"><?=smiles('.3.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .4.');"><?=smiles('.4.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .5.');"><?=smiles('.5.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .6.');"><?=smiles('.6.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .7.');"><?=smiles('.7.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .8.');"><?=smiles('.8.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .9.');"><?=smiles('.9.')?></a><br />
	<a onclick="replaceSelectedText(document.getElementById('text'),' .!!.');"><?=smiles('.!!.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .1?.');"><?=smiles('.1?.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .ok.');"><?=smiles('.ok.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .hlop.');"><?=smiles('.hlop.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .cool.');"><?=smiles('.cool.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .dog.');"><?=smiles('.dog.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .rus.');"><?=smiles('.rus.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .eng.');"><?=smiles('.eng.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .ukr.');"><?=smiles('.ukr.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .diamond.');"><?=smiles('.diamond.')?></a><br />
	<a onclick="replaceSelectedText(document.getElementById('text'),' .hearth1.');"><?=smiles('.hearth1.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .hearth2.');"><?=smiles('.hearth2.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .hearth3.');"><?=smiles('.hearth3.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .hearth4.');"><?=smiles('.hearth4.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .hearth5.');"><?=smiles('.hearth5.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .hearth6.');"><?=smiles('.hearth6.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .pou.');"><?=smiles('.pou.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .money.');"><?=smiles('.money.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .+18.');"><?=smiles('.+18.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .refresh1.');"><?=smiles('.refresh1.')?></a><br />
	<a onclick="replaceSelectedText(document.getElementById('text'),' .refresh2.');"><?=smiles('.refresh2.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' :)');"><?=smiles(':)')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .love.');"><?=smiles('.love.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' :*');"><?=smiles(':*')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .haha.');"><?=smiles('.haha.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .8D.');"><?=smiles('.8D.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' X)');"><?=smiles('X)')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' :D');"><?=smiles(':D')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .angel.');"><?=smiles('.angel.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' ;)');"><?=smiles(';)')?></a><br />
	<a onclick="replaceSelectedText(document.getElementById('text'),' :|');"><?=smiles(':|')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .hm.');"><?=smiles('.hm.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' :-/');"><?=smiles(':-/')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .zloj.');"><?=smiles('.zloj.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' ;(');"><?=smiles(';(')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' :O');"><?=smiles(':O')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .smushen.');"><?=smiles('.smushen.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .zzz.');"><?=smiles('.zzz.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .kiss.');"><?=smiles('.kiss.')?></a>
	<a onclick="replaceSelectedText(document.getElementById('text'),' .otstoi.');"><?=smiles('.otstoi.')?></a>
	</div>
	<?php
}
function fast_smile(){
	?>
	<script language="JavaScript">
		function replaceSelectedText(obj,cbFunc){obj.focus();
		if (document.selection){
			var s = document.selection.createRange(); 
			s.text=cbFunc;
			s.select();
			return true;
		}else if (typeof(obj.selectionStart)=="number"){
			var start = obj.selectionStart;
			var end = obj.selectionEnd;
			var rs = cbFunc;
			obj.value = obj.value.substr(0,start)+rs+obj.value.substr(end);
			obj.setSelectionRange(end,end);
			return true;
		}return false;}
	</script>
	<?php
}
function avatar($text){$text='<img src="/files/avatar/'.$text.'" alt="" style="float:left;margin-right:5px;width:28px;height:28px;"/>';return $text;}
function avatar_group_small($text){$text='<img src="/files/avatar_group/'.$text.'" alt="" style="float:left;margin-right:5px;width:28px;height:28px;"/>';return $text;}
function avatar_group($text){$text='<img src="/files/avatar_group/'.$text.'" alt="" style="float:right;height:58px;"/>';return $text;}
function image($text){$text='<img src="/files/images/'.$text.'" alt="" style="float:left;margin-right:5px;width:28px;height:28px;"/>';return $text;}
function right($text){$text='<span style="float:right;">'.$text.'</span>';return $text;}
function on($visit){if($visit>(time()-90)){$out=' <img src="/files/images/on.png" alt="*" style="width:10px;height:10px;"/>';}else{$out='';} return $out;}
function pic($text,$size1,$size2){$text='<img src="'.$text.'" alt="*" style="width:'.$size1.'px;height:'.$size2.'px;margin-right:5px;"/>';return $text;}
function picleft($text,$size1,$size2){$text='<img src="'.$text.'" alt="*" style="width:'.$size1.'px;height:'.$size2.'px;margin-right:5px;float:left;"/>';return $text;}
?>