View file engine/func.php

File size: 15.59Kb
<?php
# Бесплатный фотообменник
# Coding by Kokunov Evgeniy (aka Default_mo)
# ICQ 9 466 366 
# http://free-one.ru
# [email protected]
//низ страниц
 

function foot()
{
	echo '<br/><a href="/">На главную</a><br/>';
	echo '<div class="foot">всякие тут счетчики и баннеры)</div>';
echo'</body></html>';
}
############################
function utf8_substr($str, $offset, $length = null)
{
#в начале пробуем найти стандартные функции
if (function_exists('iconv_substr')) return iconv_substr($str, $offset, $length, 'utf-8'); #(PHP 5)
if (function_exists('mb_substr')) return mb_substr($str, $offset, $length, 'utf-8'); #(PHP 4 >= 4.0.6, PHP 5)
#однократные паттерны повышают производительность!
preg_match_all('/(?>[\x09\x0A\x0D\x20-\x7E]           # ASCII
| [\xC2-\xDF][\x80-\xBF]            # non-overlong 2-byte
|  \xE0[\xA0-\xBF][\x80-\xBF]       # excluding overlongs
| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
|  \xED[\x80-\x9F][\x80-\xBF]       # excluding surrogates
|  \xF0[\x90-\xBF][\x80-\xBF]{2}    # planes 1-3
| [\xF1-\xF3][\x80-\xBF]{3}         # planes 4-15
|  \xF4[\x80-\x8F][\x80-\xBF]{2}    # plane 16
)
/xs', $str, $m);
if ($length !== null) $a = array_slice($m[0], $offset, $length);
else $a = array_slice($m[0], $offset);
return implode('', $a);
}
############################
function utf8_strlen($str)
{
if (function_exists('mb_strlen')) return mb_strlen($str, 'utf-8');
if (function_exists('iconv_strlen')) return iconv_strlen($str, 'utf-8');
#utf8_decode() converts characters that are not in ISO-8859-1 to '?', which, for the purpose of counting, is quite alright.
return strlen(utf8_decode($str));
}
############################ функция постраничной навигации ############################
function pages($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = TRUE,$wml_device=TRUE)
{
//global $sid;
$total_pages = ceil($num_items/$per_page);
if ( $total_pages == 1 ){
return '';
}
$on_page = floor($start_item / $per_page) + 1;
$page_string = '';
if ( $total_pages > 7 )
{

$init_page_max = ( $total_pages > 3 ) ? 3 : $total_pages;
for($i = 1; $i < $init_page_max + 1; $i++)
{

$page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="' . $base_url . "" .( $i - 1 ) * $per_page  . '">' . $i . '</a>';
if ( $i <  $init_page_max )
{
$page_string .= ", ";
}
}
if ( $total_pages > 3 )
{
if ( $on_page > 1  && $on_page < $total_pages )
{
$page_string .= ( $on_page > 5 ) ? ' ... ' : ', ';
$init_page_min = ( $on_page > 4 ) ? $on_page : 5;
$init_page_max = ( $on_page < $total_pages - 4 ) ? $on_page : $total_pages - 4;
for($i = $init_page_min - 1; $i < $init_page_max + 2; $i++)
{
$page_string .= ($i == $on_page) ? '<b>' . $i . '</b>' : '<a href="' . $base_url . "" .( $i - 1 ) * $per_page  . '">' . $i . '</a>';
if ( $i <  $init_page_max + 1 )
{
$page_string .= ', ';
}
}
$page_string .= ( $on_page < $total_pages - 4 ) ? ' ... ' : ', ';
}
else
{
$page_string .= ' ... ';
}

for($i = $total_pages - 2; $i < $total_pages + 1; $i++)
{
$page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>'  : '<a href="' . $base_url . "" .( $i - 1 ) * $per_page  . '">' . $i . '</a>';
if( $i <  $total_pages )
{
$page_string .= ", ";
}
}
}
}
else
{
for($i = 1; $i < $total_pages + 1; $i++)
{
$page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="'.$base_url."".($i-1)*$per_page.'">' . $i . '</a>';
if ( $i <  $total_pages )
{
$page_string .= ', ';
}
}
}
if ( $add_prevnext_text )
{
//else $page_string='След.&gt;&gt;<br/>'.$page_string;
if ( $on_page  > 1 )
{
$page_string='<a href="'.$base_url."".(($on_page-2)*$per_page).'">&lt;&lt;</a> '.$page_string;
}
/******/
/******/
if ( $on_page  < $total_pages )
{
$page_string='<a href="'.$base_url."".($on_page*$per_page).'">&gt;&gt;</a> '.$page_string;
}
//else $page_string='&lt;&lt;Пред.|'.$page_string;
}


//$page_string .='<br/>';
return $page_string;
}
############################ val_text ############################
function val_text($s)
{
$s= htmlspecialchars(stripslashes($s));
$s = str_replace ('$', '&#36;', $s);
$s=addslashes($s);
return $s;
}
############################ лалала ############################
function cyr($cyr_str)
{
global $rus;
return strtr($cyr_str,$rus);
}
############################ BB-коды ############################

function BBcode($str)
{
$str = preg_replace("#\[link=(.*?)\](.*?)\[/link\]#si", "<a href=\"\\1\">\\2</a>", $str);
$str = preg_replace("#\[url=(.*?)\](.*?)\[/url\]#si", "<a href=\"\\1\">\\2</a>", $str);
$str = preg_replace("#\[red\](.*?)\[/red\]#si", "<span style=\"color: red\">\\1</span>", $str);
$str = preg_replace("#\[blue\](.*?)\[/blue\]#si", "<span style=\"color: blue\">\\1</span>", $str);
$str = preg_replace("#\[black\](.*?)\[/black\]#si", "<span style=\"color: black\">\\1</span>", $str);
$str = preg_replace("#\[white\](.*?)\[/white\]#si", "<span style=\"color: white\">\\1</span>", $str);
$str = preg_replace("#\[green\](.*?)\[/green\]#si", "<span style=\"color: green\">\\1</span>", $str);
$str = preg_replace("#\[orange\](.*?)\[/orange\]#si", "<span style=\"color: orange\">\\1</span>", $str);
$str = preg_replace("#\[pink\](.*?)\[/pink\]#si", "<span style=\"color: pink\">\\1</span>", $str);
$str = preg_replace("#\[gray\](.*?)\[/gray\]#si", "<span style=\"color: gray\">\\1</span>", $str);
$str = preg_replace("#\[big\](.*?)\[/big\]#si", "<span style=\"font-size: 20px\">\\1</span>", $str);
$str = preg_replace("#\[small\](.*?)\[/small\]#si", "<span style=\"font-size: 8px\">\\1</span>", $str);
$str = preg_replace("#\[cod\](.*?)\[/cod\]#si", "<div class=\"d\"><span style=\"color: #000000\">\\1</span></div>", $str);
$str = preg_replace("#\[b\](.*?)\[/b\]#si", "<b>\\1</b>", $str);
$str = preg_replace("#\[u\](.*?)\[/u\]#si", "<u>\\1</u>", $str);
$str = preg_replace("#\[i\](.*?)\[/i\]#si", "<i>\\1</i>", $str);
$str = preg_replace("#\[li\](.*?)\[/li\]#si", "<ul><li>\\1</li></ul>", $str);
$str = preg_replace("#\[strike\](.*?)\[/strike\]#si", "<strike>\\1</strike>", $str);
return nl2br($str);
}
function BBcode_forum($str)
{
$str = preg_replace("#\[link=(.*?)\](.*?)\[/link\]#si", "<a href=\"\\1\">\\2</a>", $str);
$str = preg_replace("#\[cod\](.*?)\[/cod\]#si", "<div class=\"d\"><span style=\"color: #000000\">\\1</span></div>", $str);
$str = preg_replace("#\[quote\](.*?)\[/quote\]#si", "<div class=\"link\"><span style=\"color: #000000\">\\1</span></div>", $str);
$str = preg_replace("#\[url=(.*?)\](.*?)\[/url\]#si", "<a href=\"\\1\">\\2</a>", $str);
$str = preg_replace("#\[red\](.*?)\[/red\]#si", "<span style=\"color: red\">\\1</span>", $str);
$str = preg_replace("#\[blue\](.*?)\[/blue\]#si", "<span style=\"color: blue\">\\1</span>", $str);
$str = preg_replace("#\[black\](.*?)\[/black\]#si", "<span style=\"color: black\">\\1</span>", $str);
$str = preg_replace("#\[green\](.*?)\[/green\]#si", "<span style=\"color: green\">\\1</span>", $str);
$str = preg_replace("#\[orange\](.*?)\[/orange\]#si", "<span style=\"color: orange\">\\1</span>", $str);
$str = preg_replace("#\[pink\](.*?)\[/pink\]#si", "<span style=\"color: pink\">\\1</span>", $str);
$str = preg_replace("#\[gray\](.*?)\[/gray\]#si", "<span style=\"color: gray\">\\1</span>", $str);
$str = preg_replace("#\[small\](.*?)\[/small\]#si", "<span style=\"font-size: 8px\">\\1</span>", $str);
$str = preg_replace("#\[b\](.*?)\[/b\]#si", "<b>\\1</b>", $str);
$str = preg_replace("#\[u\](.*?)\[/u\]#si", "<u>\\1</u>", $str);
$str = preg_replace("#\[i\](.*?)\[/i\]#si", "<i>\\1</i>", $str);
$str = preg_replace("#\[strike\](.*?)\[/strike\]#si", "<strike>\\1</strike>", $str);
return nl2br($str);
}
############################ check ############################
function check($string, $symbols = "") //этой функцией будем проверять наличие в логине левых символов/одновременно обоих алфавитов/киррилицы в пароле
{
//Основные символы
$symbols .= "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789-._";
$string = strtr($string, $symbols, str_repeat(" ", strlen($symbols)));
$string = trim($string);
if(empty($string))
{
return true;
}
else
{
return false;
}
}
########################## translit ############################
function translit($replytext)
{
$trans1=array("W","w","Q","q","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("Ш","ш","Ь","ь","Щ","Щ","Ж","Ж","Ч","Ч","Ш","Ш","Ё","Ё","Э","Э","Ю","Ю","Я","Я","щ","ж","ч","ш","ё","э","ю","я","А","Б","В","Г","Д","Е","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х","Ц","ь","ь","Ы","а","б","в","г","д","е","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ь","ь","ы");
$replytext=str_replace($trans1,$trans2,$replytext);
$replytext=str_replace("\н","\n",$replytext);
$replytext=str_replace("&лт;","&lt;",$replytext);
$replytext=str_replace("&гт;","&gt;",$replytext);
return $replytext;
}
function atranslit($replytext)
{
$trans1=array("Ш","ш","Ь","ь","Щ","Щ","Ж","Ж","Ч","Ч","Ш","Ш","Ё","Ё","Э","Э","Ю","Ю","Я","Я","щ","ж","ч","ш","ё","э","ю","я","А","Б","В","Г","Д","Е","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х","Ц","ь","ь","Ы","а","б","в","г","д","е","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ь","ь","ы");
$trans2=array("W","w","Q","q","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");
$replytext=str_replace($trans1,$trans2,$replytext);
return $replytext;
}
########################## упрощенные знаки к новостям ############################
function hot_signs($str)
{
$game_url = 'http://zik';
$str = preg_replace("#\+#si", "<b>+</b>", $str);
//$str = preg_replace("#\-#si", "<b>-</b>", $str);
$str = preg_replace("#fix forum#si", "<b>fix forum</b>", $str);
$str = preg_replace("#fix game#si", "<b>fix game</b>", $str);
$str = preg_replace("#fix all#si", "<b>fix all</b>", $str);
$str = preg_replace("#fix#si", "<b>fix</b>", $str);
$str = preg_replace("#урл#si", "".$game_url."", $str);
return $str;
}
#######################################################3
function navigation($url, $current_page, $all_pages) {
$center = $current_page;
$left1 = 1;
$left2 = 2;
$left3 = $current_page - 2;
$left4 = $current_page - 1;
$right1 = $current_page + 1;
$right2 = $current_page + 2;
$right3 = $all_pages - 1;
$right4 = $all_pages;

$_left1 = ( $left1 == $center || $left1 <= 0 ) ? null : '<a href="'.$url.'page=1">1</a> ';
$_left2 = ( $left2 == $center || $left2 > $center ) ? null : '<a href="'.$url.'page=2">2</a> ';
$_left3 = ( $left3 < 1 || $left3 == $center || $left3 == $left2 || $left3 == $left1 ) ? null
: '<a href="'.$url.'page='.$left3.'">'.$left3.'</a> ';
$_left4 = ( $left4 < 1 || $left4 == $center || $left4 == $left2 || $left4 == $left1 || $left4 == $right1 ) ? null
: '<a href="'.$url.'page='.$left4.'">'.$left4.'</a> ';

$_right4 = ( $right4 == $center || $right4 <= 0 ) ? null : ' <a href="'.$url.'page='.$all_pages.'">'.$all_pages.'</a>';
$_right3 = ( $right3 == $center || $right3 < $center ) ? null : ' <a href="'.$url.'page='.$right3.'">'.$right3.'</a>';
$_right2 = ( $right2 > $all_pages || $right2 == $center || $right2 == $right3 || $right2 == $right4 ) ? null
: ' <a href="'.$url.'page='.$right2.'">'.$right2.'</a>';
$_right1 = ( $right1 > $all_pages || $right1 == $center || $right1 == $right3 || $right1 == $right4 || $right1 == $left4 ) ? null
: ' <a href="'.$url.'page='.$right1.'">'.$right1.'</a>';

$left_interval = !empty($_left2) && !empty($_left3) ? '..' : null;
$right_interval = !empty($_right2) && !empty($_right3) ? '..' : null;

$page_back = $current_page > 1
? '<a href="'.$url.'page='.($current_page - 1).'">&lt;&lt;</a> '
: '<span style="color: gray">&lt;&lt;</span> ';
$page_forward = $current_page < $all_pages
? ' <a href="'.$url.'page='.($current_page + 1).'">&gt;&gt;</a><br />'
: ' <span style="color: gray">&gt;&gt;</span>';

echo $page_back.$_left1.$_left2.$left_interval.$_left3.$_left4.$center.$_right1.$_right2.$right_interval.$_right3.$_right4.$page_forward;

# вот такая кухня)) ^_^
}
#######################################################
function formatsize($file_size)
{
if($file_size >= 1073741824)
{
$file_size = round($file_size / 1073741824 * 100) / 100 . " Gb";
}
elseif($file_size >= 1048576)
{
$file_size = round($file_size / 1048576 * 100) / 100 . " Mb";
}
elseif($file_size >= 1024)
{
$file_size = round($file_size / 1024 * 100) / 100 . " Kb";
}
else
{
$file_size = round($file_size) . " b";
}
return $file_size;
}
############################ none ############################
function ResizeImage($image_from,$image_to, $fitwidth=100,$fitheight=105,$quality=75) {
global $php_inc;
$os=$originalsize=getimagesize($image_from);
// если фотка JPEG или размеры, до которых надо уменьшить - ничего не делать
if($originalsize[2]!=2 && $originalsize[2]!=3 && $originalsize[2]!=6 && ($originalsize[2]<9
or $originalsize[2]>12)) {
return false;
}
if($originalsize[0]>$fitwidth or $originalsize[1]>$fitheight) {
$h=getimagesize($image_from);
if(($h[0]/$fitwidth)>($h[1]/$fitheight))
{
$fitheight=$h[1]*$fitwidth/$h[0];
}else{
$fitwidth=$h[0]*$fitheight/$h[1];
}
if($os[2]==2 or ($os[2]>=9 && $os[2]<=12))$i = ImageCreateFromJPEG($image_from);
if($os[2]==3)$i=ImageCreateFromPng($image_from);
$o = ImageCreateTrueColor($fitwidth, $fitheight);
imagecopyresampled($o, $i, 0, 0, 0, 0, $fitwidth, $fitheight, $h[0], $h[1]);
imagejpeg($o, $image_to, $quality);
chmod($image_to,0777);
imagedestroy($o);
imagedestroy($i);
return 2;
}
if($originalsize[0]<=$fitwidth && $originalsize[1]<=$fitheight) {
$i = ImageCreateFromJPEG($image_from);
imagejpeg($i, $image_to, $quality);
chmod($image_to,0777);
return 1;
}
}
##################################################################

function imageresize($outfile,$infile,$neww,$newh,$quality) {

    $im=imagecreatefromjpeg($infile);
    $im1=imagecreatetruecolor($neww,$newh);
    imagecopyresampled($im1,$im,0,0,0,0,$neww,$newh,imagesx($im),imagesy($im));

    imagejpeg($im1,$outfile,$quality);
    imagedestroy($im);
    imagedestroy($im1);
    }

##################################################################

/*-----------------------------------------------------------------------------------------------------------------------------*/

# обрезалка многа букаф
function cut_text($text) {
 $z=0; $bc='';
 $rez=substr($text, 0, 2);
 for ($i=2; $i<strlen($text); $i+=2) {
  $c=substr($text, $i, 2);
  if ($bc==$c) $z++;
   else $z=1;
  if ($z<6) $rez.=$c;
  $bc=$c;
 }
 return $rez;
}

/*-----------------------------------------------------------------------------------------------------------------------------*/













?>