1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Xmf;
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26: class Utilities
27: {
28:
29: 30: 31: 32: 33: 34: 35: 36:
37: public static function purifyText($text, $keyword = false)
38: {
39: $myts = \Xoops\Core\Text\Sanitizer::getInstance();
40: $text = str_replace(' ', ' ', $text);
41: $text = str_replace('<br />', ' ', $text);
42: $text = str_replace('<br/>', ' ', $text);
43: $text = str_replace('<br', ' ', $text);
44: $text = strip_tags($text);
45: $text = html_entity_decode($text);
46: $text = $myts->undoHtmlSpecialChars($text);
47: $text = str_replace(')', ' ', $text);
48: $text = str_replace('(', ' ', $text);
49: $text = str_replace(':', ' ', $text);
50: $text = str_replace('&euro', ' euro ', $text);
51: $text = str_replace('&hellip', '...', $text);
52: $text = str_replace('&rsquo', ' ', $text);
53: $text = str_replace('!', ' ', $text);
54: $text = str_replace('?', ' ', $text);
55: $text = str_replace('"', ' ', $text);
56: $text = str_replace('-', ' ', $text);
57: $text = str_replace('\n', ' ', $text);
58: $text = str_replace('―', ' ', $text);
59:
60: if ($keyword) {
61: $text = str_replace('.', ' ', $text);
62: $text = str_replace(',', ' ', $text);
63: $text = str_replace('\'', ' ', $text);
64: }
65: $text = str_replace(';', ' ', $text);
66:
67: return $text;
68: }
69:
70: 71: 72: 73: 74: 75: 76: 77: 78:
79: public static function html2text($document)
80: {
81: $search = array ("'<script[^>]*?>.*?</script>'si",
82: "'<img.*?/>'si",
83: "'<[\/\!]*?[^<>]*?>'si",
84: "'([\r\n])[\s]+'",
85: "'&(quot|#34);'i",
86: "'&(amp|#38);'i",
87: "'&(lt|#60);'i",
88: "'&(gt|#62);'i",
89: "'&(nbsp|#160);'i",
90: "'&(iexcl|#161);'i",
91: "'&(cent|#162);'i",
92: "'&(pound|#163);'i",
93: "'&(copy|#169);'i");
94:
95: $replace = array ("",
96: "",
97: "",
98: "\\1",
99: "\"",
100: "&",
101: "<",
102: ">",
103: " ",
104: chr(161),
105: chr(162),
106: chr(163),
107: chr(169));
108:
109: $text = preg_replace($search, $replace, $document);
110:
111: preg_replace_callback(
112: '/&#(\d+);/',
113: function ($matches) {
114: return chr($matches[1]);
115: },
116: $document
117: );
118:
119: return $text;
120: }
121: }
122: