- <?php
- defined('_WBLIB') or die('Restricted access');
-
- function nav($total,$page,$num,$url) { //view.php?id='.$id.'
- if ($page != 1) $pervpage = ' <a href= "'.$url.'page='. ($page - 1) .'"><<</a> ';
- // Проверяем нужны ли стрелки вперед
- if ($page != $total) $nextpage = ' <a href="'.$url.'page='. ($page + 1) .'">>></a>';
- if ($page - 4 > 0) $first = '<a href="'.$url.'page=1">1</a>...';
- if ($page + 4 <= $total) $last = '...<a href="'.$url.'page='.$total.'">'.$total.'</a>';
- // Находим две ближайшие станицы с обоих краев, если они есть
- if($page - 2 > 0) $page2left = ' <a href= "'.$url.'page='. ($page - 2) .'">'. ($page - 2) .'</a> ';
- if($page - 1 > 0) $page1left = '<a href= "'.$url.'page='. ($page - 1) .'">'. ($page - 1) .'</a> ';
- if($page + 2 <= $total) $page2right = ' <a href= "'.$url.'page='. ($page + 2) .'">'. ($page + 2) .'</a>';
- if($page + 1 <= $total) $page1right = ' <a href="'.$url.'page='. ($page + 1) .'">'. ($page + 1) .'</a>';
- echo '<div class="nav">'.$pervpage.$first.$page2left.$page1left.'['.$page.']'.$page1right.$page2right.$last.$nextpage.'</div>';
- }
-
- // Функция обработка тегов в тексте
- function tags($text = '') {
- $text = preg_replace(array('#\[code\](.*?)\[\/code\]#se'), array("''.highlight_code('$1').''"), str_replace("]\n", "]", $text));
- $text = preg_replace('#\[b\](.*?)\[/b\]#si', '<span style="font-weight: bold;">\1</span>', $text);
- $text = preg_replace('#\[i\](.*?)\[/i\]#si', '<span style="font-style:italic;">\1</span>', $text);
- $text = preg_replace('#\[u\](.*?)\[/u\]#si', '<span style="text-decoration:underline;">\1</span>', $text);
- $text = preg_replace('#\[s\](.*?)\[/s\]#si', '<span style="text-decoration: line-through;">\1</span>', $text);
- $text = preg_replace('#\[red\](.*?)\[/red\]#si', '<span style="color:red">\1</span>', $text);
- $text = preg_replace('#\[green\](.*?)\[/green\]#si', '<span style="color:green">\1</span>', $text);
- $text = preg_replace('#\[blue\](.*?)\[/blue\]#si', '<span style="color:blue">\1</span>', $text);
- $text = preg_replace_callback('~\\[url=(https?://.+?)\\](.+?)\\[/url\\]|(https?://(www.)?[0-9a-z\.-]+\.[0-9a-z]{2,6}[0-9a-zA-Z/\?\.\~&_=/%-:#]*)~', 'url_replace', $text);
- return $text;
- }
- // Функция парсинга ссылки
- function url_replace($s) {
- if (!isset ($s[3])) {
- return '<a href="' . $s[1] . '">' . $s[2] . '</a>';
- }
- else {
- return '<a href="' . $s[3] . '">' . $s[3] . '</a>';
- }
- }
- // Функция смайлов
- function smileys($text){
- $text = strtr($text, array(
- ':)'=>'<img src="smileys/1.gif" alt=":)"/>',
- ':('=>'<img src="smileys/2.gif" alt=":("/>',
- ':P'=>'<img src="smileys/3.gif" alt=":P"/>',
- ':D'=>'<img src="smileys/4.gif" alt=":D"/>',
- ));
- return $text;
- }
- // Преобразование числа в ip
- function int2ip($i) {
- $d[0]=(int)($i/256/256/256);
- $d[1]=(int)(($i-$d[0]*256*256*256)/256/256);
- $d[2]=(int)(($i-$d[0]*256*256*256-$d[1]*256*256)/256);
- $d[3]=$i-$d[0]*256*256*256-$d[1]*256*256-$d[2]*256;
- return "$d[0].$d[1].$d[2].$d[3]";
- }
- // Преобразование ip в число
- function ip2int($ip) {
- $a=explode(".",$ip);
- return $a[0]*256*256*256+$a[1]*256*256+$a[2]*256+$a[3];
- }
-
- // Получаем реальный ip-адрес пользователя
- function getip()
- {
- if (!empty($_SERVER['HTTP_CLIENT_IP']))
- {
- $ip=$_SERVER['HTTP_CLIENT_IP'];
- }
- elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
- {
- $ip=htmlspecialchars($_SERVER['HTTP_X_FORWARDED_FOR']);
- }
- else
- {
- $ip=$_SERVER['REMOTE_ADDR'];
- }
- return $ip;
- }
-
- // Подсветка php-кода
- function highlight_code($code)
- {
- $code = strtr($code, array('<br />' => '', '\\' => 'slash'));
- $code = html_entity_decode(trim($code), ENT_QUOTES, 'UTF-8');
- $code = substr($code, 0, 2) != "<?" ? $code = "<?php\n" . $code . "\n?>" : $code;
- $code = stripslashes($code);
- $code=highlight_string($code,true);
- $code = strtr($code, array('slash' => '\', ':' => ':', '[' => '['));
- return '<div class="code">'.$code.'</div>';
- }
-
- // формат файла
- function format($name) {
- $f1 = strrpos($name, ".");
- $f2 = substr($name, $f1 + 1, 999);
- $fname = strtolower($f2);
- return $fname;
- }
-
- // Анонс статьи
- function preview_desc ( $str, $length = 150 ) {
- if (strstr($str,'[code]')) return '';
- $result = substr ( stripslashes( $str ), 0, $length );
- while( true ) {
- if( $tmp = substr ( stripslashes( $str ), $length, 1 ) ) {
- if ( $tmp == ' ' ) break;
- $result .= $tmp;
- } else break;
- $length++;
- }
- return $result;
- }
-
- // Вырезание bb-кодов
- function notags($text = '') {
- $text = strtr($text, array('[green]' => '', '[/green]' => '', '[red]' => '', '[/red]' => '', '[blue]' => '', '[/blue]' => '', '[b]' => '', '[/b]' => '', '[i]' => '', '[/i]' => '', '[u]' => '', '[/u]' => '', '[s]' => '', '[/s]' => '',
- '[code]' => '', '[/code]' => ''));
- return $text;
- }
-
- ?>