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

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