<?php
function data($time)
{
$month = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
$month_rus = array('Янв','Фев','Мар','Апр','Мая','Июн','Июл','Авг','Сент','Окт','Ноя','Дек');
$timep = date("j M Y :: H:i:s", $time);
$timep = str_replace($month,$month_rus,$timep);
return $timep;
}
function navigation($total,$page,$url)
{
if($page-1 > 0)
{
$left='<li class="prev"><a href="'.$url.''.($page-1).'"><span>‹</span></a></li>';
}
if($page+1 > 0 AND $page < $total)
{
$right = '<li class="next"><a href="'.$url.''.($page+1).'"><span>›</span></a></li>';
}
if($page-3 > 0)
{
$first='<li><a href="'.$url.'1">1</a></li>';
}
if($page-2 > 0)
{
$page2left='<li><a href="'.$url.''.($page-2).'">'.($page-2).'</a></li>';
}
if($page-1 > 0)
{
$page1left='<li><a href="'.$url.''.($page-1).'">'.($page-1).'</a></li>';
}
if($page+1 <= $total)
{
$page1right='<li><a href="'.$url.''.($page+1).'">'.($page + 1).'</a></li>';
}
if($page+2 <= $total)
{
$page2right='<li><a href="'.$url.''.($page+2).'">'.($page + 2).'</a></li>';
}
if($page+3 <= $total)
{
$page3right='<li><a href="'.$url.''.($total).'">'.($total).'</a></li>';
}
echo '<nav class="pages"><ul>'.$left.''.$first.$page2left.$page1left.'<li class="active"><a href="#">'.$page.'</a></li>'.$page1right.$page2right.$page3right.''.$right.'</ul></nav><!-- /.pages -->';
}
function wCache($content, $filename)
{
$fp = fopen('Cache/'.$filename, 'w');
fwrite($fp, $content);
fclose($fp);
}
function unreg()
{
global $user_data;
if($user_data)
{
echo '<div class="l1">Доступ только не авторизованным пользователям.</div>';
require_once('foot.php');
exit;
}
}
function reg()
{
global $user_data;
if(!$user_data)
{
echo '<div class="l1">Доступ только авторизованным пользователям.</div>';
require_once('foot.php');
exit;
}
}
function level($level)
{
global $user_data;
if($user_data AND $user_data['level'] < $level OR !$user_data)
{
echo '<div class="l1">Доступ только администратору.</div>';
require_once('foot.php');
exit;
}
}
function filter($text)
{
global $mysqli;
$text = htmlspecialchars($text);
$text = str_replace("\'", "'", $text);
$text = str_replace('\\', "\", $text);
$text = str_replace("|", "I", $text);
$text = str_replace("||", "I", $text);
$text = str_replace("/\\\$/", "$", $text);
$text = mysqli_real_escape_string($mysqli,$text);
return $text;
}
function password()
{
$s = str_split('aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789');
$pass = '';
for ($i = 0; $i <= 15; $i++)
{
$rand = mt_rand(5,25);
$pass .= $s[$rand];
}
return $pass;
}
function keyRand()
{
$s = str_split('aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789');
$key = '';
for ($i = 0; $i <= 45; $i++)
{
$rand = mt_rand(2,30);
$key .= $s[$rand];
}
return $key;
}
function mobile()
{
return true;
}
function proxy()
{
if(isset($_SERVER['HTTP_VIA']))
{
return true;
}
}
function cy($url)
{
$url = str_replace("www.", "", $url);
$ci_url = "http://bar-navig.yandex.ru/u?ver=2&show=32&url=http://www.".$url."/";
$ci_data = implode("", file("$ci_url"));
preg_match("/value=\"(.\d*)\"/", $ci_data, $ci);
if ($ci[1] == "")
{
return 0;
}
else
{
return $ci[1];
}
}
function compression()
{
if(preg_match('#gzip#iU',$_SERVER['HTTP_ACCEPT_ENCODING']))
{
return 1;
}
else
{
return 0;
}
}
function bbCodes($text) /*некоторая часть с JohnCms 4.3.0*/
{
$search = array(
'#\[b](.+?)\[/b]#is', // Жирный
'#\[i](.+?)\[/i]#is', // Курсив
'#\[red](.+?)\[/red]#is', // Красный
'#\[green](.+?)\[/green]#is', // Зеленый
'#\[blue](.+?)\[/blue]#is' // Синий
);
$replace = array(
'<span style="font-weight: bold">$1</span>', // Жирный
'<span style="font-style:italic">$1</span>', // Курсив
'<span style="color:red">$1</span>', // Красный
'<span style="color:green">$1</span>', // Зеленый
'<span style="color:blue">$1</span>' // Синий
);
return preg_replace($search, $replace, $text);
}
function StrToNum($Str, $Check, $Magic)
{
$Int32Unit = 4294967296;
$length = strlen($Str);
for ($i = 0; $i < $length; $i++) {
$Check *= $Magic;
if ($Check >= $Int32Unit) {
$Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));
$Check = ($Check < -2147483648) ? ($Check + $Int32Unit) : $Check;
}
$Check += ord($Str{$i});
}
return $Check;
}
function HashURL($String)
{
$Check1 = StrToNum($String, 0x1505, 0x21);
$Check2 = StrToNum($String, 0, 0x1003F);
$Check1 >>= 2;
$Check1 = (($Check1 >> 4) & 0x3FFFFC0 ) | ($Check1 & 0x3F);
$Check1 = (($Check1 >> 4) & 0x3FFC00 ) | ($Check1 & 0x3FF);
$Check1 = (($Check1 >> 4) & 0x3C000 ) | ($Check1 & 0x3FFF);
$T1 = (((($Check1 & 0x3C0) << 4) | ($Check1 & 0x3C)) <<2 ) | ($Check2 &
0xF0F );
$T2 = (((($Check1 & 0xFFFFC000) << 4) | ($Check1 & 0x3C00)) << 0xA) |
($Check2 & 0xF0F0000 );
return ($T1 | $T2);
}
function CheckHash($Hashnum)
{
$CheckByte = 0;
$Flag = 0;
$HashStr = sprintf('%u', $Hashnum) ;
$length = strlen($HashStr);
for ($i = $length - 1; $i >= 0; $i --) {
$Re = $HashStr{$i};
if (1 === ($Flag % 2)) {
$Re += $Re;
$Re = (int)($Re / 10) + ($Re % 10);
}
$CheckByte += $Re;
$Flag ++;
}
$CheckByte %= 10;
if (0 !== $CheckByte) {
$CheckByte = 10 - $CheckByte;
if (1 === ($Flag % 2) ) {
if (1 === ($CheckByte % 2)) {
$CheckByte += 9;
}
$CheckByte >>= 1;
}
}
return '7'.$CheckByte.$HashStr;
}
function getPageRank($aUrl)
{
$url = 'info:'.$aUrl;
$ch = CheckHash(HashURL($aUrl));
$pr = implode("", file("http://toolbarqueries.google.com/tbr?client=navclient-auto&ch=$ch&features=Rank&q=$url&num=100&filter=0"));
$pr_str = explode(":",$pr);
return $pr_str[2];
}
require_once 'class/Mobile_Detect.php';
function layoutTypes()
{
return array('classic', 'mobile', 'tablet');
}
function initLayoutType()
{
if (!class_exists('Mobile_Detect'))
return 'classic';
$detect = new Mobile_Detect;
$isMobile = $detect->isMobile();
$isTablet = $detect->isTablet();
$layoutTypes = layoutTypes();
$referer = isset($_SERVER['HTTP_REFERER']) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : $_SERVER["HTTP_HOST"];
if (isset($_GET['layoutType']))
$layoutType = trim($_GET['layoutType']);
else {
if (empty($_SESSION['layoutType']))
$layoutType = ($isMobile ? ($isTablet ? 'tablet' : 'mobile') : 'classic');
else
$layoutType = $_SESSION['layoutType'];
}
// Fallback. If everything fails choose classic layout.
if (!in_array($layoutType, $layoutTypes))
$layoutType = 'classic';
// Store the layout type for future use.
$_SESSION['layoutType'] = $layoutType;
return $layoutType;
}
// Let's roll. Call this function!
$layoutType = initLayoutType();
function SwitchType()
{
global $layoutType;
$arr = array('Web', 'Wap', 'Pda');
//$arr = array(1 => 'classic', 'mo'=>'mobile', 'tab'=>'tablet');
foreach (layoutTypes() as $key => $val) {
if ($layoutType == $val)
echo '<span style="color: #FF7B0F;">'.strtoupper($arr[$key]).'</span>';
else
echo ' <a href="?layoutType=' . $val . '">' . strtoupper($arr[$key]) . '</a> ';
//echo ' <a href="' . $val . '">' . strtoupper($arr[$key]) . '</a> ';
}
return false;
}