Файл: 4mast/profmas.ru/includes/PDO_func.php
Строк: 294
<?php
// The do
$do = ( isset( $_GET[ 'do' ] ) AND !empty( $_GET[ 'do' ] ) ) ? addslashes( htmlspecialchars( $_GET[ 'do' ] ) ) : false;
//The end
//The error
$error = ( isset( $error ) AND !empty( $error ) ) ? htmlspecialchars( $error ) : false;
//The end
//The id
$id = ( isset( $_GET[ 'id' ] ) AND is_numeric( $_GET[ 'id' ] ) ) ? (int) abs( $_GET[ 'id' ] ) : TRUE;
//The end
/* функция вывода текста */
function tag( $text ) {
$text = bb( br( esc( links( smiles( $text ) ) ) ) );
return $text;
}
function esc( $text, $br = NULL ) {
if ( $br != NULL )
for ( $i = 0; $i <= 31; $i++ )
$text = str_replace( chr( $i ), NULL, $text );
else {
for ( $i = 0; $i < 10; $i++ )
$text = str_replace( chr( $i ), NULL, $text );
for ( $i = 11; $i < 20; $i++ )
$text = str_replace( chr( $i ), NULL, $text );
for ( $i = 21; $i <= 31; $i++ )
$text = str_replace( chr( $i ), NULL, $text );
}
return $text;
}
function sizef ($size)
{
if ($size >= 1048576000) {
$out = round (($size / 1073741824), 2) . ' Гб';
} elseif ($size >= 1024000) {
$out = round(($size / 1048576), 2) . ' Мб';
} elseif ($size >= 1000) {
$out = round(($size / 1024), 2) . ' Кб';
} else {
$out = round ($size) . ' б';
}
return $out;
}
/* функция копирайта */
function copy_img($img)
{
$copy_path = $_SERVER['DOCUMENT_ROOT'] . '/copy.png';
if (isset($copy_path) && $copy_path != null && $copy = @imagecreatefromstring(file_get_contents($copy_path)))
{
$img_x = imagesx($img);
$img_y = imagesy($img);
$copy_x = imagesx($copy);
$copy_y = imagesy($copy);
$w = intval(min($img_x / 2.5, $copy_x, 128));
$h = intval(min($img_y / 2.5, $copy_y, 64));
$x_ratio = $w / $copy_x;
$y_ratio = $h / $copy_y;
if (($copy_x <= $w) && ($img_y <= $h))
{
$dstW = $copy_x;
$dstH = $copy_y;
}
elseif (($x_ratio * $copy_y) < $h)
{
$dstH = ceil($x_ratio * $copy_y);
$dstW = $w;
}
else
{
$dstW = ceil($y_ratio * $copy_x);
$dstH = $h;
}
imagecopyresampled($img, $copy, $img_x - $dstW, $img_y - $dstH, 0, 0, $dstW, $dstH, $copy_x, $copy_y);
}
return $img;
}
/* функция переноса */
function br( $msg, $br = '<br />' ) {
$msg = preg_replace( "((<br( ?/?)>)|n|r)", $br, $msg );
return $msg;
}
/* функция вывода смайла */
function smiles( $text ) {
$smiles = DB::$dbs->query( "SELECT * FROM `smiles`" );
while ( $a = $smiles->fetch() ) {
$text = str_replace( $a[ 'name' ], '<img src="/images/smiles/' . $a[ 'file' ] . '" alt="' . $a[ 'name' ] . '"/>', $text );
}
return $text;
}
function hi( $us ) {
if ( date( "H" ) <= 4 || date( "H" ) >= 23 )
$re = 'Доброй ночи, <b><a href="/us' . $us[ 'id' ] . '">' . $us[ 'nick' ] . '</a></b>';
if ( date( "H" ) >= 5 && date( "H" ) <= 10 )
$re = 'Доброе утро, <b><a href="/us' . $us[ 'id' ] . '">' . $us[ 'nick' ] . '</a></b>';
if ( date( "H" ) >= 11 && date( "H" ) <= 17 )
$re = 'Добрый день, <b><a href="/us' . $us[ 'id' ] . '">' . $us[ 'nick' ] . '</a></b>';
if ( date( "H" ) >= 18 && date( "H" ) <= 22 )
$re = 'Добрый вечер, <b><a href="/us' . $us[ 'id' ] . '">' . $us[ 'nick' ] . '</a></b>';
return $re;
}
/* вывод ника */
function Nick( $matches ) {
global $dbs;
$out = null;
if ( is_array( $matches ) ) {
$id = $matches[ 1 ];
} else {
$id = $matches;
}
$query = DB::$dbs->query( "SELECT `id`,`nick`,`sex`,`last`,`mosh`,`level`,`nickcolor1`,`nickcolor2`,`icon` FROM `us` WHERE (`id`='" . $id . "')" );
if ( $query->rowCount() != 0 ) {
$u = $query->fetch();
if ( $u[ 'icon' ] != NULL ) {
$icon = 'n/' . $u[ 'icon' ];
} else {
$icon = '/' . ( $u[ 'sex' ] == 'Муж' ? 'mon' : 'jon' ) . '.png';
}
$out .= '<a href="/us' . $u['id'] . '"><img src="/files/ico'.($u['last'] > time()-3600 ? $icon : '/mof.png').'" alt="*" style="width:16px;height:16px;"/> <b>' . ( isset( $u[ 'nickcolor1' ], $u[ 'nickcolor2' ] ) ? gradient( $u[ 'nick' ], $u[ 'nickcolor1' ], $u[ 'nickcolor2' ] ) : $u[ 'nick' ] ) . '</b></a>';
if ( $u[ 'mosh' ] != 0 ) {
$out .= ' <font color="green">[<font color="red"><b>мошенник</b></font>]</font>';
}
if ( $u[ 'level' ] > 0 ) {
$br = null;
if ( $u[ 'level' ] > 5 )
$level = 'Соз' . $br;
else if ( $u[ 'level' ] == 4 )
$level = 'Зам' . $br;
else if ( $u[ 'level' ] == 3 )
$level = 'Ст. Адм' . $br;
else if ( $u[ 'level' ] == 2 )
$level = 'Адм' . $br;
else if ( $u[ 'level' ] == 1 )
$level = 'Мд' . $br;
else
$level = null;
$out .= ' <font color="green">[<b id="level">' . $level . '</b>]</font>';
}
} else {
$out = '<img src="/files/ico/mon.png" alt="*" style="width:18px;height:18px;"/><b>Гость</a></b>';
}
return $out;
}
/* конец ника */
function slova( $str, $msg1, $msg2, $msg3 ) {
$str = (int) $str;
$str1 = abs( $str ) % 100;
$str2 = $str % 10;
if ( $str1 > 10 && $str1 < 20 )
return $str . ' ' . $msg3;
if ( $str2 > 1 && $str2 < 5 )
return $str . ' ' . $msg2;
if ( $str2 == 1 )
return $str . ' ' . $msg1;
return $str . ' ' . $msg3;
}
/* Функция подсветки кода */
function highlight_code( $code ) {
if ( is_array( $code ) )
$code = $code[ 1 ];
$code = strtr( $code, array(
'<' => '<',
'>' => '>',
'&' => '&',
'"' => '"',
'$' => '$',
'%' => '%',
''' => "'",
'\' => '\',
'^' => '^',
'`' => '`',
'|' => '|',
'<br />' => "rn"
) );
$code = highlight_string( $code, true );
$code = strtr( $code, array(
"rn" => '<br />',
'://' => '://',
'$' => '$',
"'" => ''',
'%' => '%',
'\' => '\',
'`' => '`',
'^' => '^',
'|' => '|'
) );
return '<div class="info">' . $code . '</div>';
}
/* Генерация пароля */
function gen( $var ) {
return substr( str_shuffle( '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ), 0, $var );
}
/* вывод Должности
function us_level( $us = NULL, $br = null ) {
$ul = DB::$dbs->query( "SELECT `id`,`level` FROM `us` WHERE `id` = ?", array(
$us
) )->fetch();
if ( $ul[ 'id' ] == 434 )
$level = 'Создатель Jis.su' . $br;
else if ( $ul[ 'level' ] > 5 )
$level = 'Создатель' . $br;
else if ( $ul[ 'level' ] == 4 )
$level = 'Заместитель' . $br;
else if ( $ul[ 'level' ] == 3 )
$level = 'Старший администратор' . $br;
else if ( $ul[ 'level' ] == 2 )
$level = 'Администратор' . $br;
else if ( $ul[ 'level' ] == 1 )
$level = 'Модератор' . $br;
else
$level = null;
return '<b id="level">' . $level . '</b>';
}
*/
/* вывод файла */
function fname( $matches ) {
if ( is_array( $matches ) ) {
$id = $matches[ 1 ];
} else {
$id = $matches;
}
$query = DB::$dbs->query( "SELECT * FROM `down_files` WHERE (`dop`='da') AND (`id`='" . $id . "')" );
$out = '';
if ( $query->rowCount() != 0 ) {
$f = $query->fetch();
$ext = substr( $f[ 'filename' ], strrpos( $f[ 'filename' ], '.' ) + 1 );
$out .= '<img src="/images/mime/' . strtolower( $ext ) . '.png" alt="*"/> ';
$out .= '<a href="/downloads/file' . $f[ 'id' ] . '">' . $f[ 'name' ] . '</a> ';
} else {
$out .= 'Файл удален.';
}
return $out;
}
/*размер файл */
function ssizef( $size ) {
if ( $size >= 1048576000 ) {
$out = round( ( $size / 1073741824 ), 2 ) . ' Гб';
} elseif ( $size >= 1024000 ) {
$out = round( ( $size / 1048576 ), 2 ) . ' Мб';
} elseif ( $size >= 1000 ) {
$out = round( ( $size / 1024 ), 2 ) . ' Кб';
} else {
$out = round( $size ) . ' б';
}
return $out;
}
/* вывод ссылки */
function links( $msg ) {
$msg = preg_replace_callback( '~[url=([a-z]+://[^ rnt`'"]+)](.*?)[/url]~iu', 'links_preg1', $msg );
$msg = preg_replace_callback( '~(^|s)([a-z]+://([^ rnt`'"]+))(s|$)~iu', 'links_preg2', $msg );
return $msg;
}
function links_preg1( $arr ) {
global $set;
if ( preg_match( '#^http://' . $_SERVER[ 'HTTP_HOST' ] . '#', $arr[ 1 ] ) ) {
return '<a href="/pages/away.php?url=' . $arr[ 1 ] . '">' . $arr[ 2 ] . '</a>';
} else {
return '<a href="/pages/away.php?url=' . $arr[ 1 ] . '">' . $arr[ 2 ] . '</a>';
}
}
function links_preg2( $arr ) {
global $set;
if ( preg_match( '#^http://' . $_SERVER[ 'HTTP_HOST' ] . '#', $arr[ 2 ] ) ) {
return $arr[ 1 ] . '<a href="/pages/away.php?url=' . $arr[ 2 ] . '">' . $arr[ 2 ] . '</a>' . $arr[ 4 ];
} else {
return $arr[ 1 ] . '<a href="/pages/away.php?url=' . $arr[ 2 ] . '">' . $arr[ 2 ] . '</a>' . $arr[ 4 ];
}
}
//The gradient
function gradient( $string, $from = '', $to = '' ) {
$out = null;
$string = iconv( 'utf-8', 'windows-1251', $string );
//
$to = array(
hexdec( $to[ 0 ] . $to[ 1 ] ), // r
hexdec( $to[ 2 ] . $to[ 3 ] ), // g
hexdec( $to[ 4 ] . $to[ 5 ] ) // b
);
//
$from = array(
hexdec( $from[ 0 ] . $from[ 1 ] ), // r
hexdec( $from[ 2 ] . $from[ 3 ] ), // g
hexdec( $from[ 4 ] . $from[ 5 ] ) // b
);
$levels = strlen( $string );
for ( $i = 1; $i <= $levels; $i++ ) {
for ( $ii = 0; $ii < 3; $ii++ ) {
$tmp[ $ii ] = $from[ $ii ] - $to[ $ii ];
$tmp[ $ii ] = floor( $tmp[ $ii ] / $levels );
$rgb[ $ii ] = $from[ $ii ] - ( $tmp[ $ii ] * $i );
if ( $rgb[ $ii ] > 255 ) {
$rgb[ $ii ] = 255;
}
$rgb[ $ii ] = dechex( $rgb[ $ii ] );
if ( strlen( $rgb[ $ii ] ) < 2 ) {
$rgb[ $ii ] = '0' . $rgb[ $ii ];
}
}
$out .= '<span style="color: #' . $rgb[ 0 ] . $rgb[ 1 ] . $rgb[ 2 ] . '">' . $string[ $i - 1 ] . '</span>';
}
return iconv( 'windows-1251', 'utf-8', $out );
}
//The end
//The nosmile
function nosmiles( $var ) {
$string = preg_replace( '|<img src="/images/smile/(.*?).(w+)" alt="smile"/>|', ':$1', $var );
return $string;
}
/* бб коды */
function bb( $var ) {
$var = preg_replace( '#[code](.*?)[/code]#si', "highlight('$1')", $var );
$var = preg_replace( '#[b](.*?)[/b]#si', '<span style="font-weight: bold;">1</span>', $var );
$var = preg_replace( '#[i](.*?)[/i]#si', '<span style="font-style:italic;">1</span>', $var );
$var = preg_replace( '#[u](.*?)[/u]#si', '<span style="text-decoration:underline;">1</span>', $var );
$var = preg_replace( '#[small](.*?)[/small]#si', '<small>1</small>', $var );
$var = preg_replace( '#[marq](.*?)[/marq]#si', '<marquee>1</marquee>', $var );
$var = preg_replace( '#[del](.*?)[/del]#si', '<del>1</del>', $var );
$var = preg_replace( '#[big](.*?)[/big]#si', '<big>1</big>', $var );
$var = preg_replace( '#[img](.*?)[/img]#si', '<a href="$1"> <img src="$1" alt="" style="max-width:250px;"/></a>', $var );
$var = preg_replace( '#[code](.+)[/code]#si', '<div class="cit" style="display:none;"><code>1</code></div>', $var );
$var = preg_replace( '#[php](.+)[/php]#si', '<div class="cit" style="display:none;"><code>1</code></div>', $var );
$var = preg_replace( '#[dou](.*?)[/dou]#si', '<span style="border:3px double black;">1</span>', $var );
$var = preg_replace( '#[center](.*?)[/center]#si', '<center>1</center>', $var );
$var = preg_replace( '#[right](.*?)[/right]#si', '<div align=right>1</div>', $var );
$var = preg_replace( '#[red](.*?)[/red]#si', '<span style="color:red">1</span>', $var );
$var = preg_replace( '#[t](.*?)[/t]#si', '<input name="text" type="text" value="1">', $var );
$var = preg_replace( '#[green](.*?)[/green]#si', '<span style="color:green">1</span>', $var );
$var = preg_replace( '#[blue](.*?)[/blue]#si', '<span style="color:blue">1</span>', $var );
$var = preg_replace( '#[cit](.*?)[/cit]#si', '<div class="cit"><b style="color:green">Цитата:</b><br/>" 1 "</div>', $var );
$var = preg_replace( '#[url=(.*?)](.*?)[/url]#sui', '<a href="1">2</a>', $var );
$var = preg_replace( '#[url](.*?)[/url]#sui', '<a href="1">1</a>', $var );
$var = preg_replace_callback( '/file{(d*)}/', 'fname', $var );
$var = preg_replace_callback( '/us{(d*)}/', 'Nick', $var );
$var = str_replace( "[br]", "<br/>", $var );
$query = DB::$dbs->query( "SELECT `id`,`name`,`filename` FROM `smile`" );
while ( $smile = $query->fetch() ) {
$var = str_replace( $smile[ 'name' ], '<img src="/images/smile/' . $smile[ 'filename' ] . '" alt="smile"/>', $var );
}
return $var;
}
function endi( $count, $msg = array( ) ) {
$count = (int) $count;
$max = $count % 100;
$min = $count % 10;
if ( $max > 10 && $max < 20 ) {
return $count . ' ' . $msg[ 2 ];
}
if ( $min > 1 && $min < 5 ) {
return $count . ' ' . $msg[ 1 ];
}
if ( $min == 1 ) {
return $count . ' ' . $msg[ 0 ];
}
return $count . ' ' . $msg[ 2 ];
}
//The passgen
function passgen( $count = 8 ) {
$symbols = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
$out = '';
for ( $i = 0; $i < $count; $i++ ) {
$out .= $symbols[ mt_rand( 0, 61 ) ];
}
return $out;
}
/* дата */
function datef( $time ) {
$out = null;
$t = time();
if ( ( $t - $time ) <= 60 ) {
$out .= endi( ( time() - $time ), array(
'секунду',
'секунды',
'секунд'
) );
$out .= ' назад';
} elseif ( ( $t - $time ) <= 3600 ) {
$out .= endi( ( ( $t - $time ) / 60 ), array(
'минуту',
'минуты',
'минут'
) );
$out .= ' назад';
} else {
$timesp = date( "j M Y в H:i", $time );
$timesp = str_replace( date( "j M Y", $t ), 'Сегодня', $timesp );
$timesp = str_replace( date( "j M Y", strtotime( "-1 day" ) ), 'Вчера', $timesp );
$timesp = strtr( $timesp, array(
'Jan' => 'Янв',
'Feb' => 'Фев',
'Mar' => 'Мар',
'May' => 'Мая',
'Apr' => 'Апр',
'Jun' => 'Июня',
'Jul' => 'Июля',
'Aug' => 'Авг',
'Sep' => 'Сен',
'Oct' => 'Окт',
'Nov' => 'Ноя',
'Dec' => 'Дек'
) );
$out .= $timesp;
}
return $out;
}
/* время */
function timef( $time ) {
$days = floor( $time / 86400 );
$hours = floor( ( $time / 3600 ) - ( $days * 24 ) );
$minutes = floor( ( $time - ( $hours * 3600 ) - ( $days * 86400 ) ) / 60 );
$seconds = floor( $time - ( ( $minutes * 60 ) + ( $hours * 3600 ) + ( $days * 86400 ) ) );
if ( $days != 0 ) {
$out .= endi( $days, array(
'день',
'дня',
'дней'
) );
if ( $hours != 0 || $minutes != 0 || $seconds != 0 ) {
$out .= ', ';
}
}
if ( $hours != 0 ) {
$out .= endi( $hours, array(
'час',
'часа',
'часов'
) );
if ( $minutes != 0 || $seconds != 0 ) {
$out .= ', ';
}
}
if ( $minutes != 0 ) {
$out .= endi( $minutes, array(
'минуту',
'минуты',
'минут'
) );
if ( $seconds != 0 ) {
$out .= ', ';
}
}
if ( $seconds != 0 ) {
$out .= endi( $seconds, array(
'секунду',
'секунды',
'секунд'
) );
}
return $out;
}
/* пагинация */
$page = ( isset( $_GET[ 'page' ] ) AND is_numeric( $_GET[ 'page' ] ) ) ? (int) abs( $_GET[ 'page' ] ) : 1;
function Page( $next = '?' ) {
global $page, $pages;
echo '<style type="text/css">
.str { text-align:center;}
</style>';
$pervpage = null;
$page2left = null;
$page1left = null;
$page1right = null;
$page2right = null;
$nextpage = null;
if ( $page != 1 )
$pervpage = '<a class="pages" href="' . $next . '/page1">< </a> ';
if ( $page != $pages )
$nextpage = ' <a class="pages" href="' . $next . '/page' . $pages . '">></a>';
if ( $page - 2 > 0 )
$page2left = ' <a class="pages" href="' . $next . '/page' . ( $page - 2 ) . '">' . ( $page - 2 ) . '</a> ';
if ( $page - 1 > 0 )
$page1left = '<a class="pages" href="' . $next . '/page' . ( $page - 1 ) . '">' . ( $page - 1 ) . '</a> ';
if ( $page + 2 <= $pages )
$page2right = ' <a class="pages" href="' . $next . '/page' . ( $page + 2 ) . '">' . ( $page + 2 ) . '</a>';
if ( $page + 1 <= $pages )
$page1right = ' <a class="pages" href="' . $next . '/page' . ( $page + 1 ) . '">' . ( $page + 1 ) . '</a>';
echo '<div class="str">' . $pervpage . $page2left . $page1left . '<div class="page">' . $page . '</div>' . $page1right . $page2right . $nextpage . '</div>';
}
?>