Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ##############################
- ##### ПОДКЛЮЧЕНИЕ К БАЗЕ #####
- ##############################
- $mc = mysql_connect('localhost', 'root', '') or die('Невозможно подключиться к MySQL');
- mysql_query('SET NAMES `utf8`', $mc);
- mysql_select_db('nigga', $mc) or die('Указаная таблица не найдена');
- ##################
- ##### СЕССИИ #####
- ##################
- session_start();
- ob_start();
- ######################
- ##### ФИЛЬТРАЦИИ #####
- ######################
- function text($m){
- $m = htmlspecialchars($m);
- $m = mysql_escape_string($m);
- return $m;
- } /* Фильтрует текст */
- function num($m){
- $m = intval($m);
- $m = abs($m);
- return $m;
- } /* Фильтрует цифры */
- ################
- ##### КУКИ #####
- ################
- if (isset($_COOKIE['login']) and isset($_COOKIE['password'])) {
- $login = text($_COOKIE['login']);
- $password = text($_COOKIE['password']);
- $dbs = mysql_query("SELECT * FROM `users` WHERE `login` = '".$login."' and `password` = '".$password."' LIMIT 1");
- $user = mysql_fetch_assoc($dbs);
- if (isset($user['id'])) {
- if ($user['login'] != $login or $user['password'] != $password) {
- setcookie('login', '', time() - 86400*31);
- setcookie('password', '', time() - 86400*31);
- }
- }
- $users = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `login` = '".$login."' and `password`='".$password."' LIMIT 1"));
- if(isset($user['id']) && $users['login']!=$login or $users['password']!=$password) {
- setcookie('login', '', time() - 86400*31);
- setcookie('password', '', time() - 86400*31);
- }
- }
- $myLogin = $user['login'];
- $myID = $user['id'];
- ###################
- ##### ФУНКЦИИ #####
- ###################
- function msg($sms){
- echo '<div class="dashed"> '.$sms.' </div>';
- }
- function battleMSG($sms){
- echo '
- <table class="block" width="100%">
- <tr valign="bottom">
- <td width="38px" style="padding: 0px 7px 0px 0px">
- <img src="/img/info.png" width="38px" alt="*" />
- </td>
- <td class="battleMSG">
- '.$sms.'
- </td>
- </td>
- </table>
- ';
- }
- function tl($tl){
- $d=3600*24;
- $day=floor($tl/$d);
- $tl=$tl-($d*$day);
- $hour=floor($tl/3600);
- $tl=$tl-(3600*$hour);
- $minute=floor($tl/60);
- $tl=$tl-(60*$minute);
- $second=floor($tl);
- $dayt="".($day>0?"$day д. ":null)."";
- $hourt="".($hour>0?"$hour ч. ":null)."";
- $minutet="".($minute>0?"$minute м. ":null)."";
- $secondt="".($second>0?"$second с. ":null)."";
- if($day>0){
- $minutet=NULL;
- $secondt=NULL;
- }
- if($hour>0 && $day==0){
- $secondt=NULL;
- $dayt=NULL;
- }
- return "$dayt$hourt$minutet$secondt";
- } /* Вывод оставшегося времени */
- function vremja($time=NULL){
- if ($time == NULL)$time = time();
- $timep="".date("j M Y в H:i", $time)."";
- $time_p[0]=date("j n Y", $time);
- $time_p[1]=date("H:i", $time);
- if ($time_p[0] == date("j n Y"))$timep = date("H:i:s", $time);
- if ($time_p[0] == date("j n Y", time()-60*60*24))$timep = "Вчера в $time_p[1]";
- $timep=str_replace("Jan","Января",$timep);
- $timep=str_replace("Feb","Февраля",$timep);
- $timep=str_replace("Mar","Марта",$timep);
- $timep=str_replace("May","Мая",$timep);
- $timep=str_replace("Apr","Апреля",$timep);
- $timep=str_replace("Jun","Июня",$timep);
- $timep=str_replace("Jul","Июля",$timep);
- $timep=str_replace("Aug","Августа",$timep);
- $timep=str_replace("Sep","Сентября",$timep);
- $timep=str_replace("Oct","Октября",$timep);
- $timep=str_replace("Nov","Ноября",$timep);
- $timep=str_replace("Dec","Декабря",$timep);
- return $timep;
- } /* Вывод времени */
- function noauth(){
- global $user;
- if(isset($user['id'])) header('Location: /main');
- }
- function auth(){
- global $user;
- if(!isset($user['id'])) header('Location: /');
- }
- function access($access = 0){
- global $user;
- if($user['access'] < $access) header('Location: /main');
- }
- function error($txt){
- echo '<div class="title"> Ошибка </div>';
- echo '<div class="alert center"> '.text($txt).' </div>';
- include_once 'foot.php';
- exit();
- }
- function errored($txt){
- echo '<div class="alert center"> '.text($txt).' </div>';
- }
- function page($k_page=1){ // Выдает текущую страницу
- $page=1;
- if (isset($_GET['page'])){
- if ($_GET['page']=='end')$page=intval($k_page);elseif(is_numeric($_GET['page'])) $page=intval($_GET['page']);}
- if ($page<1)$page=1;
- if ($page>$k_page)$page=$k_page;
- return $page;}
- function k_page($k_post=0,$k_p_str=10){ // Высчитывает количество страниц
- if ($k_post!=0){$v_pages=ceil($k_post/$k_p_str);return $v_pages;}
- else return 1;}
- function str($link='?',$k_page=1,$page=1){ // Вывод номеров страниц (только на первый взгляд кажется сложно ;))
- if ($page<1)$page=1;
- echo "<div class=\"str\">\n";
- if ($page!=1)echo "<span class='pag'><a href=\"".$link."page=".($page-1)."\" title='Предыдущая страница (№".($page-1).")'><Сюда</a></span> ";else echo "<span class='pag'><Сюда</span>";
- echo " | ";
- if ($page!=$k_page)echo " <span class='pag'><a href=\"".$link."page=".($page+1)."\" title='Следующая страница (№".($page+1).")'>Туда></a></span>";else echo "<span class='pag'>Туда></span>";
- echo "<br />\n";
- if ($page!=1)echo "<span class='pag'><a href=\"".$link."page=1\" title='Первая страница'><<</a></span> | ";
- if ($page!=1)echo "<span class='pag'><a href=\"".$link."page=1\" title='Страница №1'>1</a></span>";else echo "<span class='pag'>1</span>";
- for ($ot=-3; $ot<=3; $ot++){
- if ($page+$ot>1 && $page+$ot<$k_page){
- if ($ot==-3 && $page+$ot>2)echo " | ..";
- if ($ot!=0)echo " | <span class='pag'><a href=\"".$link."page=".($page+$ot)."\" title='Страница №".($page+$ot)."'>".($page+$ot)."</a></span>";else echo " | <span class='pag'> ".($page+$ot)."</span>";
- if ($ot==3 && $page+$ot<$k_page-1)echo " | ..";}}
- if ($page!=$k_page)echo " | <span class='pag'><a href=\"".$link."page=end\" title='Страница №$k_page'>$k_page</a></span>";elseif ($k_page>1)echo " | < <span class='pag'>$k_page</span>";
- if ($page!=$k_page)echo " | <span class='pag'><a href=\"".$link."page=end\" title='Последняя страница'> >></a></span>";
- echo "</div>\n";
- } /* Навигация */
- function translite($str)
- {
- $ok = array(
- "А"=>"a","Б"=>"b","В"=>"v","Г"=>"g",
- "Д"=>"d","Е"=>"e","Ж"=>"j","З"=>"z","И"=>"i",
- "Й"=>"y","К"=>"k","Л"=>"l","М"=>"m","Н"=>"n",
- "О"=>"o","П"=>"p","Р"=>"r","С"=>"s","Т"=>"t",
- "У"=>"u","Ф"=>"f","Х"=>"h","Ц"=>"ts","Ч"=>"ch",
- "Ш"=>"sh","Щ"=>"sch","Ъ"=>"","Ы"=>"yi","Ь"=>"",
- "Э"=>"e","Ю"=>"yu","Я"=>"ya","а"=>"a","б"=>"b",
- "в"=>"v","г"=>"g","д"=>"d","е"=>"e","ж"=>"j",
- "з"=>"z","и"=>"i","й"=>"y","к"=>"k","л"=>"l",
- "м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r",
- "с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"h",
- "ц"=>"ts","ч"=>"ch","ш"=>"sh","щ"=>"sch","ъ"=>"y",
- "ы"=>"yi","ь"=>"","э"=>"e","ю"=>"yu","я"=>"ya",
- " -"=> "", ","=> "", " "=> "-", "."=> "", "/"=> "_",
- "-"=> ""
- );
- return strtr($str,$ok);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement