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

Размер файла: 4.99Kb
  1. <?php
  2. defined('_WBLIB') or die('Restricted access');
  3.  
  4. function nav($total,$page,$num,$url) { //view.php?id='.$id.'
  5. if ($page != 1) $pervpage = ' <a href= "'.$url.'page='. ($page - 1) .'">&lt;&lt;</a> ';
  6. // Проверяем нужны ли стрелки вперед
  7. if ($page != $total) $nextpage = ' <a href="'.$url.'page='. ($page + 1) .'">&gt;&gt;</a>';
  8. if ($page - 4 > 0) $first = '<a href="'.$url.'page=1">1</a>...';
  9. if ($page + 4 <= $total) $last = '...<a href="'.$url.'page='.$total.'">'.$total.'</a>';
  10. // Находим две ближайшие станицы с обоих краев, если они есть
  11. if($page - 2 > 0) $page2left = ' <a href= "'.$url.'page='. ($page - 2) .'">'. ($page - 2) .'</a> ';
  12. if($page - 1 > 0) $page1left = '<a href= "'.$url.'page='. ($page - 1) .'">'. ($page - 1) .'</a> ';
  13. if($page + 2 <= $total) $page2right = ' <a href= "'.$url.'page='. ($page + 2) .'">'. ($page + 2) .'</a>';
  14. if($page + 1 <= $total) $page1right = ' <a href="'.$url.'page='. ($page + 1) .'">'. ($page + 1) .'</a>';
  15. echo '<div class="nav">'.$pervpage.$first.$page2left.$page1left.'['.$page.']'.$page1right.$page2right.$last.$nextpage.'</div>';
  16. }
  17.  
  18. // Функция обработка тегов в тексте
  19. function tags($text = '') {
  20. $text = preg_replace(array('#\[code\](.*?)\[\/code\]#se'), array("''.highlight_code('$1').''"), str_replace("]\n", "]", $text));
  21. $text = preg_replace('#\[b\](.*?)\[/b\]#si', '<span style="font-weight: bold;">\1</span>', $text);
  22. $text = preg_replace('#\[i\](.*?)\[/i\]#si', '<span style="font-style:italic;">\1</span>', $text);
  23. $text = preg_replace('#\[u\](.*?)\[/u\]#si', '<span style="text-decoration:underline;">\1</span>', $text);
  24. $text = preg_replace('#\[s\](.*?)\[/s\]#si', '<span style="text-decoration: line-through;">\1</span>', $text);
  25. $text = preg_replace('#\[red\](.*?)\[/red\]#si', '<span style="color:red">\1</span>', $text);
  26. $text = preg_replace('#\[green\](.*?)\[/green\]#si', '<span style="color:green">\1</span>', $text);
  27. $text = preg_replace('#\[blue\](.*?)\[/blue\]#si', '<span style="color:blue">\1</span>', $text);
  28. $text = preg_replace_callback('~\\[url=(https?://.+?)\\](.+?)\\[/url\\]|(https?://(www.)?[0-9a-z\.-]+\.[0-9a-z]{2,6}[0-9a-zA-Z/\?\.\~&amp;_=/%-:#]*)~', 'url_replace', $text);
  29. return $text;
  30. }
  31. // Функция парсинга ссылки
  32. function url_replace($s) {
  33. if (!isset ($s[3])) {
  34. return '<a href="' . $s[1] . '">' . $s[2] . '</a>';
  35. }
  36. else {
  37. return '<a href="' . $s[3] . '">' . $s[3] . '</a>';
  38. }
  39. }
  40. // Функция смайлов
  41. function smileys($text){
  42. $text = strtr($text, array(
  43. ':)'=>'<img src="smileys/1.gif" alt=":)"/>',
  44. ':('=>'<img src="smileys/2.gif" alt=":("/>',
  45. ':P'=>'<img src="smileys/3.gif" alt=":P"/>',
  46. ':D'=>'<img src="smileys/4.gif" alt=":D"/>',
  47. ));
  48. return $text;
  49. }
  50. // Преобразование числа в ip
  51. function int2ip($i) {
  52. $d[0]=(int)($i/256/256/256);
  53. $d[1]=(int)(($i-$d[0]*256*256*256)/256/256);
  54. $d[2]=(int)(($i-$d[0]*256*256*256-$d[1]*256*256)/256);
  55. $d[3]=$i-$d[0]*256*256*256-$d[1]*256*256-$d[2]*256;
  56. return "$d[0].$d[1].$d[2].$d[3]";
  57. }
  58. // Преобразование ip в число
  59. function ip2int($ip) {
  60. $a=explode(".",$ip);
  61. return $a[0]*256*256*256+$a[1]*256*256+$a[2]*256+$a[3];
  62. }
  63.  
  64. // Получаем реальный ip-адрес пользователя
  65. function getip()
  66. {
  67. if (!empty($_SERVER['HTTP_CLIENT_IP']))
  68. {
  69. $ip=$_SERVER['HTTP_CLIENT_IP'];
  70. }
  71. elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
  72. {
  73. $ip=htmlspecialchars($_SERVER['HTTP_X_FORWARDED_FOR']);
  74. }
  75. else
  76. {
  77. $ip=$_SERVER['REMOTE_ADDR'];
  78. }
  79. return $ip;
  80. }
  81.  
  82. // Подсветка php-кода
  83. function highlight_code($code)
  84. {
  85. $code = strtr($code, array('<br />' => '', '\\' => 'slash'));
  86. $code = html_entity_decode(trim($code), ENT_QUOTES, 'UTF-8');
  87. $code = substr($code, 0, 2) != "<?" ? $code = "<?php\n" . $code . "\n?>" : $code;
  88. $code = stripslashes($code);
  89. $code=highlight_string($code,true);
  90. $code = strtr($code, array('slash' => '&#92;', ':' => '&#58;', '[' => '&#91;'));
  91. return '<div class="code">'.$code.'</div>';
  92. }
  93.  
  94. // формат файла
  95. function format($name) {
  96. $f1 = strrpos($name, ".");
  97. $f2 = substr($name, $f1 + 1, 999);
  98. $fname = strtolower($f2);
  99. return $fname;
  100. }
  101.  
  102. // Анонс статьи
  103. function preview_desc ( $str, $length = 150 ) {
  104. if (strstr($str,'[code]')) return '';
  105. $result = substr ( stripslashes( $str ), 0, $length );
  106. while( true ) {
  107. if( $tmp = substr ( stripslashes( $str ), $length, 1 ) ) {
  108. if ( $tmp == ' ' ) break;
  109. $result .= $tmp;
  110. } else break;
  111. $length++;
  112. }
  113. return $result;
  114. }
  115.  
  116. // Вырезание bb-кодов
  117. function notags($text = '') {
  118. $text = strtr($text, array('[green]' => '', '[/green]' => '', '[red]' => '', '[/red]' => '', '[blue]' => '', '[/blue]' => '', '[b]' => '', '[/b]' => '', '[i]' => '', '[/i]' => '', '[u]' => '', '[/u]' => '', '[s]' => '', '[/s]' => '',
  119. '[code]' => '', '[/code]' => ''));
  120. return $text;
  121. }
  122.  
  123. ?>