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

Размер файла: 2.36Kb
  1. <?
  2. defined('WBCAT') or die('Restricted access');
  3. // Функция обработка тегов в тексте
  4. function tags($text = '') {
  5. $text = preg_replace('#\[b\](.*?)\[/b\]#si', '<span style="font-weight: bold;">\1</span>', $text);
  6. $text = preg_replace('#\[i\](.*?)\[/i\]#si', '<span style="font-style:italic;">\1</span>', $text);
  7. $text = preg_replace('#\[u\](.*?)\[/u\]#si', '<span style="text-decoration:underline;">\1</span>', $text);
  8. $text = preg_replace('#\[s\](.*?)\[/s\]#si', '<span style="text-decoration: line-through;">\1</span>', $text);
  9. $text = preg_replace('#\[red\](.*?)\[/red\]#si', '<span style="color:red">\1</span>', $text);
  10. $text = preg_replace('#\[green\](.*?)\[/green\]#si', '<span style="color:green">\1</span>', $text);
  11. $text = preg_replace('#\[blue\](.*?)\[/blue\]#si', '<span style="color:blue">\1</span>', $text);
  12. $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);
  13. return $text;
  14. }
  15. // Функция парсинга ссылки
  16. function url_replace($s) {
  17. if (!isset ($s[3])) {
  18. return '<a href="' . $s[1] . '">' . $s[2] . '</a>';
  19. }
  20. else {
  21. return '<a href="' . $s[3] . '">' . $s[3] . '</a>';
  22. }
  23. }
  24. // Функция смайлов
  25. function smileys($text){
  26. $text = strtr($text, array(
  27. ':)'=>'<img src="smileys/1.gif" alt=":)"/>',
  28. ':('=>'<img src="smileys/2.gif" alt=":("/>',
  29. ':P'=>'<img src="smileys/3.gif" alt=":P"/>',
  30. ':D'=>'<img src="smileys/4.gif" alt=":D"/>',
  31. ));
  32. return $text;
  33. }
  34. // Преобразование числа в ip
  35. function int2ip($i) {
  36. $d[0]=(int)($i/256/256/256);
  37. $d[1]=(int)(($i-$d[0]*256*256*256)/256/256);
  38. $d[2]=(int)(($i-$d[0]*256*256*256-$d[1]*256*256)/256);
  39. $d[3]=$i-$d[0]*256*256*256-$d[1]*256*256-$d[2]*256;
  40. return "$d[0].$d[1].$d[2].$d[3]";
  41. }
  42. // Преобразование ip в число
  43. function ip2int($ip) {
  44. $a=explode(".",$ip);
  45. return $a[0]*256*256*256+$a[1]*256*256+$a[2]*256+$a[3];
  46. }
  47.  
  48. // Получаем реальный ip-адрес пользователя
  49. function getip()
  50. {
  51. if (!empty($_SERVER['HTTP_CLIENT_IP']))
  52. {
  53. $ip=$_SERVER['HTTP_CLIENT_IP'];
  54. }
  55. elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
  56. {
  57. $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
  58. }
  59. else
  60. {
  61. $ip=$_SERVER['REMOTE_ADDR'];
  62. }
  63. return $ip;
  64. }
  65.  
  66.  
  67.  
  68. ?>