Просмотр файла engine/classes/text.class.php

Размер файла: 4.21Kb
  1. <?php
  2.  
  3. Class text
  4. {
  5. static function output($str, $set = array('html' => true, 'bbcode' => true, 'smiles' => true, 'br' => true))
  6. {
  7. if ($set['html'])
  8. $str = htmlspecialchars($str);
  9.  
  10. if ($set['bbcode'])
  11. {
  12. //$tmp_str = $str;
  13. $str = self::bbcode($str);
  14. }
  15.  
  16. if ($set['smiles'])// && $tmp_str == $str)
  17. $str = self::smiles($str);
  18.  
  19. if ($set['br'])
  20. {
  21. $str = nl2br($str);
  22. }
  23.  
  24. /**
  25. * Антиспам. Разрешается использовать только в SecWind
  26. */
  27.  
  28. if (file_exists(H . 'engine/files/data/antispam.db'))
  29. {
  30. $antispam = unserialize(file_get_contents(H . 'engine/files/data/antispam.db'));
  31. $str = str_replace(array_keys($antispam), array_values($antispam), $str);
  32. }
  33.  
  34. return $str;
  35. }
  36.  
  37. static function size_data($size = 0)
  38. {
  39. $size_ed = 'б';
  40. if ($size >= 1024)
  41. {
  42. $size = round($size / 1024, 2);
  43. $size_ed = 'Кб';
  44. }
  45. if ($size >= 1024)
  46. {
  47. $size = round($size / 1024, 2);
  48. $size_ed = 'Мб';
  49. }
  50.  
  51. if ($size >= 1024)
  52. {
  53. $size = round($size / 1024, 2);
  54. $size_ed = 'Гб';
  55. }
  56. return $size . ' ' . $size_ed;
  57. }
  58.  
  59. static function smiles($msg)
  60. {
  61. static $cache = array();
  62. if (empty($cache))
  63. {
  64. global $sql;
  65. $query = mysqli_query($sql->db, 'SELECT * FROM `smiles` WHERE `type` = "smile"');
  66. if ($sql->num_rows())
  67. {
  68. while($smiles = $sql->fetch($query)){
  69. $cache[$smiles['symbol']] = '<img src="/style/smiles/'.$smiles['name'].'.gif"/>';
  70. }
  71. }
  72. }
  73. return strtr($msg, $cache);
  74. }
  75.  
  76. static function passgen($len = 12)
  77. {
  78. $password = '';
  79. $small = 'abcdefghijklmnopqrstuvwxyz';
  80. $large = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  81. $numbers = '1234567890';
  82. for ($i = 0; $i < $len; $i++)
  83. {
  84. switch (mt_rand(1, 3))
  85. {
  86. case 3 :
  87. $password .= $large [mt_rand(0, 25)];
  88. break;
  89. case 2 :
  90. $password .= $small [mt_rand(0, 25)];
  91. break;
  92. case 1 :
  93. $password .= $numbers [mt_rand(0, 9)];
  94. break;
  95. }
  96. }
  97. return $password;
  98. }
  99.  
  100. static function antimat($str, $user)
  101. {
  102. include_once H.'engine/functions/censure.php';
  103. if ($censure = censure($str))
  104. {
  105. return $censure;
  106. }
  107. else
  108. return false;
  109. }
  110.  
  111. static function bbcode($text)
  112. {
  113. $search = array(
  114. '#\[b](.+?)\[/b]#i',
  115. '#\[i](.+?)\[/i]#i',
  116. '#\[u](.+?)\[/u]#i',
  117. '#\[del](.+?)\[/del]#i',
  118. '#\[color=(green|lime|red|blue|yellow|purple|gold|black|silver|gray|white)\](.+?)\[/color]#i',
  119. '#\[quote](.+?)\[quote]#i');
  120.  
  121. $replace = array(
  122. '<span style="font-weight: bold">$1</span>',
  123. '<span style="font-style:italic">$1</span>',
  124. '<span style="text-decoration:underline">$1</span>',
  125. '<span style="text-decoration:line-through">$1</span>',
  126. '<span style="color:$1">$2</span>',
  127. '<div class="quote">$2</div>');
  128.  
  129. $text = preg_replace($search, $replace, $text);
  130. $text = preg_replace_callback('#\[url=([-a-z0-9._~:\/?\#@!$&\'()*+,;=%]+)](.+?)\[\/url]#i',
  131. create_function('$match', 'return "<a href=\'$match[1]\' title=\'".htmlspecialchars($match[2])."\'>".strip_tags($match[2])."</a>";'), $text);
  132.  
  133. // [img=img link]title[/img]
  134. //$text = preg_replace('/\[img=([-a-z0-9._~:\/?#@!$&\'()*+,;=%]+)](.+?)\[\/img\]/si', '<img src="\1" alt="\2" title="\2" />', $text);
  135.  
  136. return $text; preg_replace($search, $replace, $text);
  137. }
  138. }