Просмотр файла gb/incl/func.php

Размер файла: 5.2Kb
<?
/*
GB(v1.0) by Viktor
icq:357332321
site: http://yarap.ru
http://xwab.ru/forum/profile656
[incl/func.php]
*/
$path='./';
function name($name, $br=0)
	{
	$name = preg_replace('| +|', ' ', $name);
	$name = str_replace("\t", "", $name);
	$name = htmlspecialchars(trim($name));
	$name = str_replace("'", "&#039;", $name);
	$name = str_replace("\\", "", $name);
	$name = utf_to_html($name);
	if($br==1)$name = preg_replace('/([\r\n]){2,}/',"<br/>",$name); else $name = preg_replace('/([\r\n]){2,}/',"",$name);
	return $name;
	}
function user_ip()
	{
	if (!empty($_SERVER['HTTP_CLIENT_IP']))
		$ip=$_SERVER['HTTP_CLIENT_IP'];
	elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
		$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
	else
		$ip=$_SERVER['REMOTE_ADDR'];
	return $ip;
	}
function phpbb_realpath($path)
	{//phpbb
	//global $template, $path;
	return (!@function_exists('realpath') || !@realpath($path.'incl/func.php')) ? $path : @realpath($path);
	}
function sql($sql)
	{
	$res=query($sql);
	$sql = row($res);
	return $sql;
	}
// sql
function query($sql)
	{
	$res=mysql_query($sql) or die($sql.'<br />'.mysql_error());
	return $res;
	}
function row($sql)
	{
	$res=mysql_fetch_array($sql);
	return $res;
	}
// end sql
function utf_to_html($s)
	{
	if (function_exists('mb_convert_encoding'))
		return mb_convert_encoding($s, 'HTML-ENTITIES', 'UTF-8');
	$ololo = '';
	for($i=0,$len=strlen($s); $i<$len; $i++)
		{  
		$c = $s[$i];
		$x = ord($c);
		if ($x < 0x80)
			{
			$ololo .= $c;
			continue;
			}
		elseif (($x & 0xC0) == 0xC0)
			{
			$n = 1;
			while ( ($x & (0x40 >> $n)) > 0) $n++;
			$code = $x & (0x3F >> $n);
			for ($k=1; $k<=$n; $k++)
				{
				$y = ord($s[$i+$k]) & 0x3F;
				$code = ($code << 6) + $y;
				}
			$i += $n;
			$ololo .= '&x'.dechex($code).';';
			}
		else
			$ololo .= 'xm...';
		}
	return $ololo;
	}
function append_sid($url)
	{
	return $url;
	}
function data($data)
	{
	global $l;
	$mes=array($l[40], $l[41], $l[42], $l[43], $l[44], $l[45], $l[46], $l[47], $l[48], $l[49], $l[50], $l[51]);
	$m=date("m", $data) . PHP_EOL;
	$b=date("H:i ".intval(date("d", $data)), $data) . PHP_EOL;
	$g = date(" Y", $data) . PHP_EOL;
	if(intval($g)==intval(date(" Y", time()))) $g = '';
	$data = $b.' '.$mes[intval($m)-1].$g;
	return $data;
	}
function pagin($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = TRUE)
{// pizdanul s phpbb-wap v7
	global $l;
	$lang['Previous'] = $l[67];
	$lang['Next'] = $l[68];

	$total_pages = ceil($num_items/$per_page);

	if ( $total_pages == 1 )
	{
		return '';
	}

	$on_page = floor($start_item / $per_page) + 1;

	$page_string = '';
		if ( $on_page == 1 )
		{
			$page_string = $l[67].' | <a href="' . append_sid($base_url . "&amp;start=" . ( $on_page * $per_page ) ) . '">' . $l[68] . '</a><br/>';
		}
		if ( $on_page == $total_pages )
		{
			$page_string = '<a href="' . append_sid($base_url . "&amp;start=" . ( ( $on_page - 2 ) * $per_page ) ) . '">'.$l[67].'</a> | '.$l[68].'<br/>';
		}
	if ( $total_pages > 10 )
	{
		$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="' . append_sid($base_url . "&amp;start=" . ( ( $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="' . append_sid($base_url . "&amp;start=" . ( ( $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="' . append_sid($base_url . "&amp;start=" . ( ( $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="' . append_sid($base_url . "&amp;start=" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>';
			if ( $i <  $total_pages )
			{
				$page_string .= ',';
			}
		}
	}

	if ( $add_prevnext_text )
	{
		if ( $on_page > 1  && $on_page < $total_pages )
		{
			$page_string = '<a href="' . append_sid($base_url . "&amp;start=" . ( ( $on_page - 2 ) * $per_page ) ) . '">' . $l[67] . '</a> | <a href="' . append_sid($base_url . "&amp;start=" . ( $on_page * $per_page ) ) . '">' . $l[68] . '</a><br/>' . $page_string;
		}

		if ( $on_page < $total_pages )
		{
			$page_string .= '';
		}
	}

	$page_string = $page_string;

	return $page_string;
}
?>