Просмотр файла inc.php

Размер файла: 3.99Kb
<?php
ob_start();

session_name('SESS');
session_start();

$db_host = 'localhost';
$db_bd = 'news';
$db_user = 'news';
$db_pass = 'news';

$db = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db($db_bd, $db);
mysql_query('SET names utf8',$db); 
$site = 'localhost/news/'; 

$back = '<div class="line"><a href="index.php">К новостям</a></div>';

function filtr($text,$skol=false){
$text=htmlentities(trim($text),ENT_QUOTES,'UTF-8');
$text=mysql_real_escape_string($text);
if(!empty($skol)){$text=mb_substr($text,0,$skol,'UTF-8');}
return $text;
}

function num($num){
return abs((int)$num);
}

function page($all,$hvost,$page,$total,$who){ 
$hvost.='&amp;'; 
echo '<div class="line2">Всего '.$who.': '.$all.'</div>'; 
if($page!=1){ 
echo '<a href="'.$hvost.'page='.($page-1).'">&lt;&lt;Пред.</a> ';
if($page!=$total){echo '|| ';} 
}
if($page<$total){ 
echo ' <a href="'.$hvost.'page='.($page+1).'">След.&gt;&gt;</a>';
}
$pp=$p2l=$p1l=$p1r=$p2r=$np=''; 
if($page<$total){ 
$p1r='<a href="'.$hvost.'page='.($page+1).'">'.($page+1).'</a>';
if($page+1!=$total and $total-4<$page){$p1r.=',';}
}
if($page+4<$total){
$p1r.=',<a href="'.$hvost.'page='.($page+2).'">'.($page+2).'</a>';
}
if($page-3>0){
$pp='<a href="'.$hvost.'page=1">1</a>';
if($page-4>0){
$pp.=',<a href="'.$hvost.'page=2">2</a>';
}
if($page-5>0){
$pp.=',<a href="'.$hvost.'page=3">3</a>';
}
if($page-6>0 and $page<8){
$pp.=',<a href="'.$hvost.'page=4">4</a>';
}
if($page>7){$pp.='...';}else{$pp.=',';}
}
if($page+2<$total){
$np='<a href="'.$hvost.'page='.$total.'">'.$total.'</a>';
}
if($page-2>0){
$p2l='<a href="'.$hvost.'page='.($page-2).'">'.($page-2).'</a>,';
}
if($page-1>0){
$p1l='<a href="'.$hvost.'page='.($page-1).'">'.($page-1).'</a>,';
}
if($total-3>$page){
if($page+3==$total-3){
$p2r=',<a href="'.$hvost.'page='.($total-3).'">'.($total-3).'</a>';
}
if($page+2<$total-4){$p2r.='...';}else{$p2r.=',';}
$p2r.='<a href="'.$hvost.'page='.($total-2).'">'.($total-2).'</a>,<a href="'.$hvost.'page='.($total-1).'">'.($total-1).'</a>,';
}elseif($page+1<$total){
$p2r='<a href="'.$hvost.'page='.($page+2).'">'.($page+2).'</a>';
if($page+2<$total){$p2r.=',';}
}
if($total!=1){
echo $pp.$p2l.$p1l.' <b>'.$page.'</b> '.$p1r.$p2r.$np;
}
}

function vizual($stext){
$stext = preg_replace('#\[b\](.*?)\[/b\]#si', '<b>\1</b>', $stext);
$stext = preg_replace('#\[i\](.*?)\[/i\]#si', '<i>\1</i>', $stext);
$stext = preg_replace('#\[u\](.*?)\[/u\]#si', '<u>\1</u>', $stext);
$stext=preg_replace('#\[red\](.*?)\[/red\]#si', '<font color="#FF0000">\1</font>', $stext);
$stext=preg_replace('#\[green\](.*?)\[/green\]#si', '<font color="green">\1</font>', $stext);
$stext=preg_replace('#\[black\](.*?)\[/black\]#si', '<font color="black">\1</font>', $stext);
$stext=preg_replace('#\[white\](.*?)\[/white\]#si', '<font color="white">\1</font>', $stext);
$stext=preg_replace('#\[yellow\](.*?)\[/yellow\]#si', '<font color="yellow">\1</font>', $stext);
$stext=preg_replace('#\[orange\](.*?)\[/orange\]#si', '<font color="orange">\1</font>', $stext);
$stext=preg_replace('#\[blue\](.*?)\[/blue\]#si', '<font color="blue">\1</font>', $stext);
$stext=preg_replace('#\[violet\](.*?)\[/violet\]#si', '<font color="violet">\1</font>', $stext);
$stext=preg_replace('#\[cit\](.*?)\[/cit\]#si', '<div class="cit">\1</div>', $stext);
$stext=ereg_replace("\r\n",'<br />',$stext);
return $stext;
}



$ip = filtr($_SERVER['REMOTE_ADDR']);
$ua = filtr($_SERVER['HTTP_USER_AGENT']);



if(isset($_REQUEST['page'])){$page=intval($_REQUEST['page']);}else{$page=1;}
if (isset($_GET['id'])){$id = num($_GET['id']);}else{$id = '';}
if (isset($_GET['do'])){$do = filtr($_GET['do']);}else{$do = '';}

$set = mysql_fetch_array(mysql_query("SELECT * FROM `set` WHERE id='1'"));



$admin = 0;
if (isset($_SESSION['pass'])){
$pass = filtr($_SESSION['pass']);
$s = mysql_result(mysql_query("SELECT password FROM `set` WHERE id='1'"),0);
if ($s == $pass){
$admin = 1;
}
}
















?>