Revision | 5c886a60262eac17b2c646d6b071098ad9bffd57 (tree) |
---|---|
Zeit | 2015-01-20 01:44:49 |
Autor | umorigu <umorigu@gmai...> |
Commiter | umorigu |
Remove create_function function for stability
@@ -124,34 +124,51 @@ function catbody($title, $page, $body) | ||
124 | 124 | arsort($keys, SORT_NUMERIC); |
125 | 125 | $keys = get_search_words(array_keys($keys), TRUE); |
126 | 126 | $id = 0; |
127 | + $patterns = ''; | |
127 | 128 | foreach ($keys as $key=>$pattern) { |
128 | - $s_key = htmlsc($key); | |
129 | - $pattern = '/' . | |
130 | - '<textarea[^>]*>.*?<\/textarea>' . // Ignore textareas | |
131 | - '|' . '<[^>]*>' . // Ignore tags | |
132 | - '|' . '&[^;]+;' . // Ignore entities | |
133 | - '|' . '(' . $pattern . ')' . // $matches[1]: Regex for a search word | |
134 | - '/sS'; | |
135 | - $decorate_Nth_word = create_function( | |
136 | - '$matches', | |
137 | - 'return (isset($matches[1])) ? ' . | |
138 | - '\'<strong class="word' . | |
139 | - $id . | |
140 | - '">\' . $matches[1] . \'</strong>\' : ' . | |
141 | - '$matches[0];' | |
142 | - ); | |
143 | - $body = preg_replace_callback($pattern, $decorate_Nth_word, $body); | |
144 | - $notes = preg_replace_callback($pattern, $decorate_Nth_word, $notes); | |
145 | - ++$id; | |
129 | + if (strlen($patterns) > 0) { | |
130 | + $pattern .= '|'; | |
131 | + } | |
132 | + $patterns = '(' . $pattern . ')'; | |
146 | 133 | } |
134 | + $pattern = '/' . | |
135 | + '<textarea[^>]*>.*?<\/textarea>' . // Ignore textareas | |
136 | + '|' . '<[^>]*>' . // Ignore tags | |
137 | + '|' . '&[^;]+;' . // Ignore entities | |
138 | + '|' . '(' . $patterns . ')' . // $matches[1]: Regex for a search word | |
139 | + '/sS'; | |
140 | + $body = preg_replace_callback($pattern, '_decorate_Nth_word', $body); | |
141 | + $notes = preg_replace_callback($pattern, '_decorate_Nth_word', $notes); | |
142 | + $s_key = htmlsc($key); | |
143 | + $pattern = '/' . | |
144 | + '<textarea[^>]*>.*?<\/textarea>' . // Ignore textareas | |
145 | + '|' . '<[^>]*>' . // Ignore tags | |
146 | + '|' . '&[^;]+;' . // Ignore entities | |
147 | + '|' . '(' . $pattern . ')' . // $matches[1]: Regex for a search word | |
148 | + '/sS'; | |
149 | + $body = preg_replace_callback($pattern, '_decorate_Nth_word', $body); | |
150 | + $notes = preg_replace_callback($pattern, '_decorate_Nth_word', $notes); | |
147 | 151 | } |
148 | - | |
149 | 152 | // Compat: 'HTML convert time' without time about MenuBar and skin |
150 | 153 | $taketime = elapsedtime(); |
151 | 154 | |
152 | 155 | require(SKIN_FILE); |
153 | 156 | } |
154 | 157 | |
158 | +function _decorate_Nth_word($matches) | |
159 | +{ | |
160 | + $index = 0; | |
161 | + for ($i = 2; $i < count($matches); $i++) { | |
162 | + if (isset($matches[$i])) { | |
163 | + $index = $i; | |
164 | + } | |
165 | + } | |
166 | + return (isset($matches[1])) ? | |
167 | + '<strong class="word' | |
168 | + . $index . | |
169 | + '>' . $matches[0] . '</strong>' : $matches[0]; | |
170 | +} | |
171 | + | |
155 | 172 | // Show 'edit' form |
156 | 173 | function edit_form($page, $postdata, $digest = FALSE, $b_template = TRUE) |
157 | 174 | { |
@@ -164,7 +181,7 @@ function edit_form($page, $postdata, $digest = FALSE, $b_template = TRUE) | ||
164 | 181 | if ($digest === FALSE) $digest = md5(join('', get_source($page))); |
165 | 182 | |
166 | 183 | $refer = $template = ''; |
167 | - | |
184 | + | |
168 | 185 | // Add plugin |
169 | 186 | $addtag = $add_top = ''; |
170 | 187 | if(isset($vars['add'])) { |