@@ -54,6 +54,9 @@ discard block |
||
54 | 54 | $this->logs[] = array('class' => $tret, 'info' => $str, 'data' => $data); |
55 | 55 | } |
56 | 56 | |
57 | + /** |
|
58 | + * @param string $data |
|
59 | + */ |
|
57 | 60 | protected function error($info, $data = null) |
58 | 61 | { |
59 | 62 | $this->errors[] = array('class' => '', 'info' => $info, 'data' => $data); |
@@ -154,7 +157,7 @@ discard block |
||
154 | 157 | * Добавление защищенного блока |
155 | 158 | * |
156 | 159 | * @param string $tag тэг, который должен быть защищён |
157 | - * @return void |
|
160 | + * @return boolean |
|
158 | 161 | */ |
159 | 162 | public function add_safe_tag($tag) |
160 | 163 | { |
@@ -170,8 +173,9 @@ discard block |
||
170 | 173 | * |
171 | 174 | * @param string $open начало блока |
172 | 175 | * @param string $close конец защищенного блока |
173 | - * @param bool $quoted специальные символы в начале и конце блока экранированы |
|
174 | - * @return void |
|
176 | + * @param bool $quoted специальные символы в начале и конце блока экранированы |
|
177 | + * @param string $id |
|
178 | + * @return boolean |
|
175 | 179 | */ |
176 | 180 | public function add_safe_block($id, $open, $close, $quoted = false) |
177 | 181 | { |
@@ -197,8 +201,8 @@ discard block |
||
197 | 201 | /** |
198 | 202 | * Сохранение содержимого защищенных блоков |
199 | 203 | * |
200 | - * @param string $text |
|
201 | - * @param bool $safe если true, то содержимое блоков будет сохранено, иначе - раскодировано. |
|
204 | + * @param string $text |
|
205 | + * @param boolean $way |
|
202 | 206 | * @return string |
203 | 207 | */ |
204 | 208 | public function safe_blocks($text, $way, $show = true) |
@@ -307,7 +311,7 @@ discard block |
||
307 | 311 | * |
308 | 312 | * @param mixed $class - имя класса трета, или сам объект |
309 | 313 | * @param string $altname - альтернативное имя, если хотим например иметь два одинаоковых терта в обработке |
310 | - * @return unknown |
|
314 | + * @return boolean |
|
311 | 315 | */ |
312 | 316 | public function add_tret($class, $altname = false) |
313 | 317 | { |
@@ -592,7 +596,6 @@ discard block |
||
592 | 596 | * Установить настройку |
593 | 597 | * |
594 | 598 | * @param mixed $selector |
595 | - * @param string $setting |
|
596 | 599 | * @param mixed $value |
597 | 600 | */ |
598 | 601 | protected function doset($selector, $key, $value) |
@@ -103,130 +103,130 @@ discard block |
||
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
106 | - * Добавление защищенного блока |
|
107 | - * |
|
108 | - * <code> |
|
109 | - * Jare_Typograph_Tool::addCustomBlocks('<span>', '</span>'); |
|
110 | - * Jare_Typograph_Tool::addCustomBlocks('\<nobr\>', '\<\/span\>', true); |
|
111 | - * </code> |
|
112 | - * |
|
113 | - * @param string $id идентификатор |
|
114 | - * @param string $open начало блока |
|
115 | - * @param string $close конец защищенного блока |
|
116 | - * @param string $tag тэг |
|
117 | - * @return void |
|
118 | - */ |
|
119 | - private function _add_safe_block($id, $open, $close, $tag) |
|
120 | - { |
|
121 | - $this->_safe_blocks[] = array( |
|
122 | - 'id' => $id, |
|
123 | - 'tag' => $tag, |
|
124 | - 'open' => $open, |
|
125 | - 'close' => $close, |
|
126 | - ); |
|
127 | - } |
|
106 | + * Добавление защищенного блока |
|
107 | + * |
|
108 | + * <code> |
|
109 | + * Jare_Typograph_Tool::addCustomBlocks('<span>', '</span>'); |
|
110 | + * Jare_Typograph_Tool::addCustomBlocks('\<nobr\>', '\<\/span\>', true); |
|
111 | + * </code> |
|
112 | + * |
|
113 | + * @param string $id идентификатор |
|
114 | + * @param string $open начало блока |
|
115 | + * @param string $close конец защищенного блока |
|
116 | + * @param string $tag тэг |
|
117 | + * @return void |
|
118 | + */ |
|
119 | + private function _add_safe_block($id, $open, $close, $tag) |
|
120 | + { |
|
121 | + $this->_safe_blocks[] = array( |
|
122 | + 'id' => $id, |
|
123 | + 'tag' => $tag, |
|
124 | + 'open' => $open, |
|
125 | + 'close' => $close, |
|
126 | + ); |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * Список защищенных блоков |
|
131 | - * |
|
132 | - * @return array |
|
133 | - */ |
|
134 | - public function get_all_safe_blocks() |
|
135 | - { |
|
136 | - return $this->_safe_blocks; |
|
137 | - } |
|
129 | + /** |
|
130 | + * Список защищенных блоков |
|
131 | + * |
|
132 | + * @return array |
|
133 | + */ |
|
134 | + public function get_all_safe_blocks() |
|
135 | + { |
|
136 | + return $this->_safe_blocks; |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * Удаленного блока по его номеру ключа |
|
141 | - * |
|
142 | - * @param string $id идентифиактор защищённого блока |
|
143 | - * @return void |
|
144 | - */ |
|
145 | - public function remove_safe_block($id) |
|
146 | - { |
|
147 | - foreach($this->_safe_blocks as $k => $block) { |
|
148 | - if($block['id']==$id) unset($this->_safe_blocks[$k]); |
|
149 | - } |
|
150 | - } |
|
139 | + /** |
|
140 | + * Удаленного блока по его номеру ключа |
|
141 | + * |
|
142 | + * @param string $id идентифиактор защищённого блока |
|
143 | + * @return void |
|
144 | + */ |
|
145 | + public function remove_safe_block($id) |
|
146 | + { |
|
147 | + foreach($this->_safe_blocks as $k => $block) { |
|
148 | + if($block['id']==$id) unset($this->_safe_blocks[$k]); |
|
149 | + } |
|
150 | + } |
|
151 | 151 | |
152 | 152 | |
153 | - /** |
|
154 | - * Добавление защищенного блока |
|
155 | - * |
|
156 | - * @param string $tag тэг, который должен быть защищён |
|
157 | - * @return void |
|
158 | - */ |
|
159 | - public function add_safe_tag($tag) |
|
160 | - { |
|
161 | - $open = preg_quote("<", '/'). $tag."[^>]*?" . preg_quote(">", '/'); |
|
162 | - $close = preg_quote("</$tag>", '/'); |
|
163 | - $this->_add_safe_block($tag, $open, $close, $tag); |
|
164 | - return true; |
|
165 | - } |
|
153 | + /** |
|
154 | + * Добавление защищенного блока |
|
155 | + * |
|
156 | + * @param string $tag тэг, который должен быть защищён |
|
157 | + * @return void |
|
158 | + */ |
|
159 | + public function add_safe_tag($tag) |
|
160 | + { |
|
161 | + $open = preg_quote("<", '/'). $tag."[^>]*?" . preg_quote(">", '/'); |
|
162 | + $close = preg_quote("</$tag>", '/'); |
|
163 | + $this->_add_safe_block($tag, $open, $close, $tag); |
|
164 | + return true; |
|
165 | + } |
|
166 | 166 | |
167 | 167 | |
168 | - /** |
|
169 | - * Добавление защищенного блока |
|
170 | - * |
|
171 | - * @param string $open начало блока |
|
172 | - * @param string $close конец защищенного блока |
|
173 | - * @param bool $quoted специальные символы в начале и конце блока экранированы |
|
174 | - * @return void |
|
175 | - */ |
|
176 | - public function add_safe_block($id, $open, $close, $quoted = false) |
|
177 | - { |
|
178 | - $open = trim($open); |
|
179 | - $close = trim($close); |
|
168 | + /** |
|
169 | + * Добавление защищенного блока |
|
170 | + * |
|
171 | + * @param string $open начало блока |
|
172 | + * @param string $close конец защищенного блока |
|
173 | + * @param bool $quoted специальные символы в начале и конце блока экранированы |
|
174 | + * @return void |
|
175 | + */ |
|
176 | + public function add_safe_block($id, $open, $close, $quoted = false) |
|
177 | + { |
|
178 | + $open = trim($open); |
|
179 | + $close = trim($close); |
|
180 | 180 | |
181 | - if (empty($open) || empty($close)) |
|
182 | - { |
|
183 | - return false; |
|
184 | - } |
|
181 | + if (empty($open) || empty($close)) |
|
182 | + { |
|
183 | + return false; |
|
184 | + } |
|
185 | 185 | |
186 | - if (false === $quoted) |
|
187 | - { |
|
188 | - $open = preg_quote($open, '/'); |
|
189 | - $close = preg_quote($close, '/'); |
|
190 | - } |
|
186 | + if (false === $quoted) |
|
187 | + { |
|
188 | + $open = preg_quote($open, '/'); |
|
189 | + $close = preg_quote($close, '/'); |
|
190 | + } |
|
191 | 191 | |
192 | - $this->_add_safe_block($id, $open, $close, ""); |
|
193 | - return true; |
|
194 | - } |
|
192 | + $this->_add_safe_block($id, $open, $close, ""); |
|
193 | + return true; |
|
194 | + } |
|
195 | 195 | |
196 | 196 | |
197 | - /** |
|
198 | - * Сохранение содержимого защищенных блоков |
|
199 | - * |
|
200 | - * @param string $text |
|
201 | - * @param bool $safe если true, то содержимое блоков будет сохранено, иначе - раскодировано. |
|
202 | - * @return string |
|
203 | - */ |
|
204 | - public function safe_blocks($text, $way, $show = true) |
|
205 | - { |
|
206 | - if (count($this->_safe_blocks)) |
|
207 | - { |
|
208 | - $safeType = true === $way ? "\Fenrizbes\TypographBundle\EMT\EMTLib::encrypt_tag(\$m[2])" : "stripslashes(\Fenrizbes\TypographBundle\EMT\EMTLib::decrypt_tag(\$m[2]))"; |
|
209 | - $safeblocks = true === $way ? $this->_safe_blocks : array_reverse($this->_safe_blocks); |
|
210 | - foreach ($safeblocks as $block) |
|
211 | - { |
|
212 | - $text = preg_replace_callback("/({$block['open']})(.+?)({$block['close']})/s", create_function('$m','return $m[1].'.$safeType . '.$m[3];') , $text); |
|
213 | - } |
|
214 | - } |
|
197 | + /** |
|
198 | + * Сохранение содержимого защищенных блоков |
|
199 | + * |
|
200 | + * @param string $text |
|
201 | + * @param bool $safe если true, то содержимое блоков будет сохранено, иначе - раскодировано. |
|
202 | + * @return string |
|
203 | + */ |
|
204 | + public function safe_blocks($text, $way, $show = true) |
|
205 | + { |
|
206 | + if (count($this->_safe_blocks)) |
|
207 | + { |
|
208 | + $safeType = true === $way ? "\Fenrizbes\TypographBundle\EMT\EMTLib::encrypt_tag(\$m[2])" : "stripslashes(\Fenrizbes\TypographBundle\EMT\EMTLib::decrypt_tag(\$m[2]))"; |
|
209 | + $safeblocks = true === $way ? $this->_safe_blocks : array_reverse($this->_safe_blocks); |
|
210 | + foreach ($safeblocks as $block) |
|
211 | + { |
|
212 | + $text = preg_replace_callback("/({$block['open']})(.+?)({$block['close']})/s", create_function('$m','return $m[1].'.$safeType . '.$m[3];') , $text); |
|
213 | + } |
|
214 | + } |
|
215 | 215 | |
216 | - return $text; |
|
217 | - } |
|
216 | + return $text; |
|
217 | + } |
|
218 | 218 | |
219 | 219 | |
220 | - /** |
|
221 | - * Декодирование блоков, которые были скрыты в момент типографирования |
|
222 | - * |
|
223 | - * @param string $text |
|
224 | - * @return string |
|
225 | - */ |
|
226 | - public function decode_internal_blocks($text) |
|
227 | - { |
|
220 | + /** |
|
221 | + * Декодирование блоков, которые были скрыты в момент типографирования |
|
222 | + * |
|
223 | + * @param string $text |
|
224 | + * @return string |
|
225 | + */ |
|
226 | + public function decode_internal_blocks($text) |
|
227 | + { |
|
228 | 228 | return EMTLib::decode_internal_blocks($text); |
229 | - } |
|
229 | + } |
|
230 | 230 | |
231 | 231 | |
232 | 232 | private function create_object($tret) |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | * |
308 | 308 | * @param mixed $class - имя класса трета, или сам объект |
309 | 309 | * @param string $altname - альтернативное имя, если хотим например иметь два одинаоковых терта в обработке |
310 | - * @return unknown |
|
310 | + * @return unknown |
|
311 | 311 | */ |
312 | 312 | public function add_tret($class, $altname = false) |
313 | 313 | { |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | |
450 | 450 | if($this->is_on('dounicode')) |
451 | 451 | { |
452 | - EMTLib::convert_html_entities_to_unicode($this->_text); |
|
452 | + EMTLib::convert_html_entities_to_unicode($this->_text); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | $this->_text = EMTLib::safe_tag_chars($this->_text, false); |
@@ -612,8 +612,8 @@ discard block |
||
612 | 612 | $rule_pattern = implode(".", $pa); |
613 | 613 | } |
614 | 614 | } |
615 | - EMTLib::_process_selector_pattern($tret_pattern); |
|
616 | - EMTLib::_process_selector_pattern($rule_pattern); |
|
615 | + EMTLib::_process_selector_pattern($tret_pattern); |
|
616 | + EMTLib::_process_selector_pattern($rule_pattern); |
|
617 | 617 | if($selector == "*") $this->settings[$key] = $value; |
618 | 618 | |
619 | 619 | foreach ($this->trets as $tret) |
@@ -24,9 +24,9 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $trets = array() ; |
|
28 | - protected $trets_index = array() ; |
|
29 | - protected $tret_objects = array() ; |
|
27 | + protected $trets = array(); |
|
28 | + protected $trets_index = array(); |
|
29 | + protected $tret_objects = array(); |
|
30 | 30 | |
31 | 31 | public $ok = false; |
32 | 32 | public $debug_enabled = false; |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | protected function log($str, $data = null) |
47 | 47 | { |
48 | - if(!$this->logging) return; |
|
48 | + if (!$this->logging) return; |
|
49 | 49 | $this->logs[] = array('class' => '', 'info' => $str, 'data' => $data); |
50 | 50 | } |
51 | 51 | |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | protected function error($info, $data = null) |
58 | 58 | { |
59 | 59 | $this->errors[] = array('class' => '', 'info' => $info, 'data' => $data); |
60 | - $this->log("ERROR $info", $data ); |
|
60 | + $this->log("ERROR $info", $data); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | protected function tret_error($tret, $info, $data = null) |
@@ -67,10 +67,10 @@ discard block |
||
67 | 67 | |
68 | 68 | protected function debug($class, $place, &$after_text, $after_text_raw = "") |
69 | 69 | { |
70 | - if(!$this->debug_enabled) return; |
|
70 | + if (!$this->debug_enabled) return; |
|
71 | 71 | $this->debug_info[] = array( |
72 | - 'tret' => $class == $this ? false: true, |
|
73 | - 'class' => is_object($class)? get_class($class) : $class, |
|
72 | + 'tret' => $class == $this ? false : true, |
|
73 | + 'class' => is_object($class) ? get_class($class) : $class, |
|
74 | 74 | 'place' => $place, |
75 | 75 | 'text' => $after_text, |
76 | 76 | 'text_raw' => $after_text_raw, |
@@ -144,8 +144,8 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public function remove_safe_block($id) |
146 | 146 | { |
147 | - foreach($this->_safe_blocks as $k => $block) { |
|
148 | - if($block['id']==$id) unset($this->_safe_blocks[$k]); |
|
147 | + foreach ($this->_safe_blocks as $k => $block) { |
|
148 | + if ($block['id'] == $id) unset($this->_safe_blocks[$k]); |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public function add_safe_tag($tag) |
160 | 160 | { |
161 | - $open = preg_quote("<", '/'). $tag."[^>]*?" . preg_quote(">", '/'); |
|
161 | + $open = preg_quote("<", '/').$tag."[^>]*?".preg_quote(">", '/'); |
|
162 | 162 | $close = preg_quote("</$tag>", '/'); |
163 | 163 | $this->_add_safe_block($tag, $open, $close, $tag); |
164 | 164 | return true; |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | $safeblocks = true === $way ? $this->_safe_blocks : array_reverse($this->_safe_blocks); |
210 | 210 | foreach ($safeblocks as $block) |
211 | 211 | { |
212 | - $text = preg_replace_callback("/({$block['open']})(.+?)({$block['close']})/s", create_function('$m','return $m[1].'.$safeType . '.$m[3];') , $text); |
|
212 | + $text = preg_replace_callback("/({$block['open']})(.+?)({$block['close']})/s", create_function('$m', 'return $m[1].'.$safeType.'.$m[3];'), $text); |
|
213 | 213 | } |
214 | 214 | } |
215 | 215 | |
@@ -232,20 +232,20 @@ discard block |
||
232 | 232 | private function create_object($tret) |
233 | 233 | { |
234 | 234 | // если класса нету, попытаемся его прогрузить, например, если стандартный |
235 | - if(!class_exists($tret)) |
|
235 | + if (!class_exists($tret)) |
|
236 | 236 | { |
237 | - if(preg_match("/^EMTTret([a-zA-Z0-9_]+)$/",$tret, $m)) |
|
237 | + if (preg_match("/^EMTTret([a-zA-Z0-9_]+)$/", $tret, $m)) |
|
238 | 238 | { |
239 | 239 | $tname = $m[1]; |
240 | - $fname = str_replace("_"," ",$tname); |
|
240 | + $fname = str_replace("_", " ", $tname); |
|
241 | 241 | $fname = ucwords($fname); |
242 | - $fname = str_replace(" ",".",$fname); |
|
242 | + $fname = str_replace(" ", ".", $fname); |
|
243 | 243 | //if(file_exists("EMT.Tret.".$fname.".php")) |
244 | 244 | { |
245 | 245 | } |
246 | 246 | } |
247 | 247 | } |
248 | - if(!class_exists($tret)) |
|
248 | + if (!class_exists($tret)) |
|
249 | 249 | { |
250 | 250 | $this->error("Класс $tret не найден. Пожалуйста, подргузите нужный файл."); |
251 | 251 | return null; |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | |
260 | 260 | private function get_short_tret($tretname) |
261 | 261 | { |
262 | - if(preg_match("/^EMTTret([a-zA-Z0-9_]+)$/",$tretname, $m)) |
|
262 | + if (preg_match("/^EMTTret([a-zA-Z0-9_]+)$/", $tretname, $m)) |
|
263 | 263 | { |
264 | 264 | return $m[1]; |
265 | 265 | } |
@@ -268,15 +268,15 @@ discard block |
||
268 | 268 | |
269 | 269 | private function _init() |
270 | 270 | { |
271 | - foreach($this->trets as $tret) |
|
271 | + foreach ($this->trets as $tret) |
|
272 | 272 | { |
273 | - if(isset($this->tret_objects[$tret])) continue; |
|
273 | + if (isset($this->tret_objects[$tret])) continue; |
|
274 | 274 | $obj = $this->create_object($tret); |
275 | - if($obj == null) continue; |
|
275 | + if ($obj == null) continue; |
|
276 | 276 | $this->tret_objects[$tret] = $obj; |
277 | 277 | } |
278 | 278 | |
279 | - if(!$this->inited) |
|
279 | + if (!$this->inited) |
|
280 | 280 | { |
281 | 281 | $this->add_safe_tag('pre'); |
282 | 282 | $this->add_safe_tag('script'); |
@@ -311,9 +311,9 @@ discard block |
||
311 | 311 | */ |
312 | 312 | public function add_tret($class, $altname = false) |
313 | 313 | { |
314 | - if(is_object($class)) |
|
314 | + if (is_object($class)) |
|
315 | 315 | { |
316 | - if(!is_a($class, "EMTTret")) |
|
316 | + if (!is_a($class, "EMTTret")) |
|
317 | 317 | { |
318 | 318 | $this->error("You are adding Tret that doesn't inherit base class EMTTret", get_class($class)); |
319 | 319 | return false; |
@@ -325,10 +325,10 @@ discard block |
||
325 | 325 | $this->trets[] = ($altname ? $altname : get_class($class)); |
326 | 326 | return true; |
327 | 327 | } |
328 | - if(is_string($class)) |
|
328 | + if (is_string($class)) |
|
329 | 329 | { |
330 | 330 | $obj = $this->create_object($class); |
331 | - if($obj === null) |
|
331 | + if ($obj === null) |
|
332 | 332 | return false; |
333 | 333 | $this->tret_objects[($altname ? $altname : $class)] = $obj; |
334 | 334 | $this->trets[] = ($altname ? $altname : $class); |
@@ -345,15 +345,15 @@ discard block |
||
345 | 345 | */ |
346 | 346 | public function get_tret($name) |
347 | 347 | { |
348 | - if(isset($this->tret_objects[$name])) return $this->tret_objects[$name]; |
|
349 | - foreach($this->trets as $tret) |
|
348 | + if (isset($this->tret_objects[$name])) return $this->tret_objects[$name]; |
|
349 | + foreach ($this->trets as $tret) |
|
350 | 350 | { |
351 | - if($tret == $name) |
|
351 | + if ($tret == $name) |
|
352 | 352 | { |
353 | 353 | $this->_init(); |
354 | 354 | return $this->tret_objects[$name]; |
355 | 355 | } |
356 | - if($this->get_short_tret($tret) == $name) |
|
356 | + if ($this->get_short_tret($tret) == $name) |
|
357 | 357 | { |
358 | 358 | $this->_init(); |
359 | 359 | return $this->tret_objects[$tret]; |
@@ -387,8 +387,8 @@ discard block |
||
387 | 387 | $this->_init(); |
388 | 388 | |
389 | 389 | $atrets = $this->trets; |
390 | - if(is_string($trets)) $atrets = array($trets); |
|
391 | - elseif(is_array($trets)) $atrets = $trets; |
|
390 | + if (is_string($trets)) $atrets = array($trets); |
|
391 | + elseif (is_array($trets)) $atrets = $trets; |
|
392 | 392 | |
393 | 393 | $this->debug($this, 'init', $this->_text); |
394 | 394 | |
@@ -404,15 +404,15 @@ discard block |
||
404 | 404 | foreach ($atrets as $tret) |
405 | 405 | { |
406 | 406 | // если установлен режим разметки тэгов то выставим его |
407 | - if($this->use_layout_set) |
|
407 | + if ($this->use_layout_set) |
|
408 | 408 | $this->tret_objects[$tret]->set_tag_layout_ifnotset($this->use_layout); |
409 | 409 | |
410 | - if($this->class_layout_prefix) |
|
410 | + if ($this->class_layout_prefix) |
|
411 | 411 | $this->tret_objects[$tret]->set_class_layout_prefix($this->class_layout_prefix); |
412 | 412 | |
413 | 413 | // влючаем, если нужно |
414 | - if($this->debug_enabled) $this->tret_objects[$tret]->debug_on(); |
|
415 | - if($this->logging) $this->tret_objects[$tret]->logging = true; |
|
414 | + if ($this->debug_enabled) $this->tret_objects[$tret]->debug_on(); |
|
415 | + if ($this->logging) $this->tret_objects[$tret]->logging = true; |
|
416 | 416 | |
417 | 417 | // применяем трэт |
418 | 418 | //$this->tret_objects[$tret]->set_text(&$this->_text); |
@@ -420,19 +420,19 @@ discard block |
||
420 | 420 | $this->tret_objects[$tret]->apply(); |
421 | 421 | |
422 | 422 | // соберём ошибки если таковые есть |
423 | - if(count($this->tret_objects[$tret]->errors)>0) |
|
424 | - foreach($this->tret_objects[$tret]->errors as $err ) |
|
423 | + if (count($this->tret_objects[$tret]->errors)>0) |
|
424 | + foreach ($this->tret_objects[$tret]->errors as $err) |
|
425 | 425 | $this->tret_error($tret, $err['info'], $err['data']); |
426 | 426 | |
427 | 427 | // логгирование |
428 | - if($this->logging) |
|
429 | - if(count($this->tret_objects[$tret]->logs)>0) |
|
430 | - foreach($this->tret_objects[$tret]->logs as $log ) |
|
428 | + if ($this->logging) |
|
429 | + if (count($this->tret_objects[$tret]->logs)>0) |
|
430 | + foreach ($this->tret_objects[$tret]->logs as $log) |
|
431 | 431 | $this->tret_log($tret, $log['info'], $log['data']); |
432 | 432 | |
433 | 433 | // отладка |
434 | - if($this->debug_enabled) |
|
435 | - foreach($this->tret_objects[$tret]->debug_info as $di) |
|
434 | + if ($this->debug_enabled) |
|
435 | + foreach ($this->tret_objects[$tret]->debug_info as $di) |
|
436 | 436 | { |
437 | 437 | $unsafetext = $di['text']; |
438 | 438 | $unsafetext = EMTLib::safe_tag_chars($unsafetext, false); |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | $this->_text = $this->decode_internal_blocks($this->_text); |
448 | 448 | $this->debug($this, 'decode_internal_blocks', $this->_text); |
449 | 449 | |
450 | - if($this->is_on('dounicode')) |
|
450 | + if ($this->is_on('dounicode')) |
|
451 | 451 | { |
452 | 452 | EMTLib::convert_html_entities_to_unicode($this->_text); |
453 | 453 | } |
@@ -458,14 +458,14 @@ discard block |
||
458 | 458 | $this->_text = $this->safe_blocks($this->_text, false); |
459 | 459 | $this->debug($this, 'unsafe_blocks', $this->_text); |
460 | 460 | |
461 | - if(!$this->disable_notg_replace) |
|
461 | + if (!$this->disable_notg_replace) |
|
462 | 462 | { |
463 | 463 | $repl = array('<span class="_notg_start"></span>', '<span class="_notg_end"></span>'); |
464 | - if($this->remove_notg) $repl = ""; |
|
465 | - $this->_text = str_replace( array('<notg>','</notg>'), $repl , $this->_text); |
|
464 | + if ($this->remove_notg) $repl = ""; |
|
465 | + $this->_text = str_replace(array('<notg>', '</notg>'), $repl, $this->_text); |
|
466 | 466 | } |
467 | 467 | $this->_text = trim($this->_text); |
468 | - $this->ok = (count($this->errors)==0); |
|
468 | + $this->ok = (count($this->errors) == 0); |
|
469 | 469 | return $this->_text; |
470 | 470 | } |
471 | 471 | |
@@ -483,18 +483,18 @@ discard block |
||
483 | 483 | $res = array(); |
484 | 484 | foreach ($this->trets as $tret) |
485 | 485 | { |
486 | - $arr =$this->tret_objects[$tret]->classes; |
|
487 | - if(!is_array($arr)) continue; |
|
488 | - foreach($arr as $classname => $str) |
|
486 | + $arr = $this->tret_objects[$tret]->classes; |
|
487 | + if (!is_array($arr)) continue; |
|
488 | + foreach ($arr as $classname => $str) |
|
489 | 489 | { |
490 | - if(($compact) && (!$str)) continue; |
|
491 | - $clsname = ($this->class_layout_prefix ? $this->class_layout_prefix : "" ).(isset($this->tret_objects[$tret]->class_names[$classname]) ? $this->tret_objects[$tret]->class_names[$classname] :$classname); |
|
490 | + if (($compact) && (!$str)) continue; |
|
491 | + $clsname = ($this->class_layout_prefix ? $this->class_layout_prefix : "").(isset($this->tret_objects[$tret]->class_names[$classname]) ? $this->tret_objects[$tret]->class_names[$classname] : $classname); |
|
492 | 492 | $res[$clsname] = $str; |
493 | 493 | } |
494 | 494 | } |
495 | - if($list) return $res; |
|
495 | + if ($list) return $res; |
|
496 | 496 | $str = ""; |
497 | - foreach($res as $k => $v) |
|
497 | + foreach ($res as $k => $v) |
|
498 | 498 | { |
499 | 499 | $str .= ".$k { $v }\n"; |
500 | 500 | } |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | * |
525 | 525 | * @param string|bool $prefix если true то префикс 'emt_', иначе то, что передали |
526 | 526 | */ |
527 | - public function set_class_layout_prefix($prefix ) |
|
527 | + public function set_class_layout_prefix($prefix) |
|
528 | 528 | { |
529 | 529 | $this->class_layout_prefix = $prefix === true ? "emt_" : $prefix; |
530 | 530 | } |
@@ -542,33 +542,33 @@ discard block |
||
542 | 542 | */ |
543 | 543 | public function set_enable_map($map, $disable = false, $strict = true) |
544 | 544 | { |
545 | - if(!is_array($map)) return; |
|
545 | + if (!is_array($map)) return; |
|
546 | 546 | $trets = array(); |
547 | - foreach($map as $tret => $list) |
|
547 | + foreach ($map as $tret => $list) |
|
548 | 548 | { |
549 | 549 | $tretx = $this->get_tret($tret); |
550 | - if(!$tretx) |
|
550 | + if (!$tretx) |
|
551 | 551 | { |
552 | 552 | $this->log("Трэт $tret не найден при применении карты включаемых правил"); |
553 | 553 | continue; |
554 | 554 | } |
555 | 555 | $trets[] = $tretx; |
556 | 556 | |
557 | - if($list === true) // все |
|
557 | + if ($list === true) // все |
|
558 | 558 | { |
559 | - $tretx->activate(array(), !$disable , true); |
|
560 | - } elseif(is_string($list)) { |
|
561 | - $tretx->activate(array($list), $disable , $strict); |
|
562 | - } elseif(is_array($list)) { |
|
563 | - $tretx->activate($list, $disable , $strict); |
|
559 | + $tretx->activate(array(), !$disable, true); |
|
560 | + } elseif (is_string($list)) { |
|
561 | + $tretx->activate(array($list), $disable, $strict); |
|
562 | + } elseif (is_array($list)) { |
|
563 | + $tretx->activate($list, $disable, $strict); |
|
564 | 564 | } |
565 | 565 | } |
566 | - if($strict) |
|
566 | + if ($strict) |
|
567 | 567 | { |
568 | - foreach($this->trets as $tret) |
|
568 | + foreach ($this->trets as $tret) |
|
569 | 569 | { |
570 | - if(in_array($this->tret_objects[$tret], $trets)) continue; |
|
571 | - $this->tret_objects[$tret]->activate(array(), $disable , true); |
|
570 | + if (in_array($this->tret_objects[$tret], $trets)) continue; |
|
571 | + $this->tret_objects[$tret]->activate(array(), $disable, true); |
|
572 | 572 | } |
573 | 573 | } |
574 | 574 | |
@@ -582,9 +582,9 @@ discard block |
||
582 | 582 | */ |
583 | 583 | public function is_on($key) |
584 | 584 | { |
585 | - if(!isset($this->settings[$key])) return false; |
|
585 | + if (!isset($this->settings[$key])) return false; |
|
586 | 586 | $kk = $this->settings[$key]; |
587 | - return ((strtolower($kk)=="on") || ($kk === "1") || ($kk === true) || ($kk === 1)); |
|
587 | + return ((strtolower($kk) == "on") || ($kk === "1") || ($kk === true) || ($kk === 1)); |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | |
@@ -600,9 +600,9 @@ discard block |
||
600 | 600 | $tret_pattern = false; |
601 | 601 | $rule_pattern = false; |
602 | 602 | //if(($selector === false) || ($selector === null) || ($selector === false) || ($selector === "*")) $type = 0; |
603 | - if(is_string($selector)) |
|
603 | + if (is_string($selector)) |
|
604 | 604 | { |
605 | - if(strpos($selector,".")===false) |
|
605 | + if (strpos($selector, ".") === false) |
|
606 | 606 | { |
607 | 607 | $tret_pattern = $selector; |
608 | 608 | } else { |
@@ -614,29 +614,29 @@ discard block |
||
614 | 614 | } |
615 | 615 | EMTLib::_process_selector_pattern($tret_pattern); |
616 | 616 | EMTLib::_process_selector_pattern($rule_pattern); |
617 | - if($selector == "*") $this->settings[$key] = $value; |
|
617 | + if ($selector == "*") $this->settings[$key] = $value; |
|
618 | 618 | |
619 | 619 | foreach ($this->trets as $tret) |
620 | 620 | { |
621 | 621 | $t1 = $this->get_short_tret($tret); |
622 | - if(!EMTLib::_test_pattern($tret_pattern, $t1)) if(!EMTLib::_test_pattern($tret_pattern, $tret)) continue; |
|
622 | + if (!EMTLib::_test_pattern($tret_pattern, $t1)) if (!EMTLib::_test_pattern($tret_pattern, $tret)) continue; |
|
623 | 623 | $tret_obj = $this->get_tret($tret); |
624 | - if($key == "active") |
|
624 | + if ($key == "active") |
|
625 | 625 | { |
626 | - foreach($tret_obj->rules as $rulename => $v) |
|
626 | + foreach ($tret_obj->rules as $rulename => $v) |
|
627 | 627 | { |
628 | - if(!EMTLib::_test_pattern($rule_pattern, $rulename)) continue; |
|
629 | - if((strtolower($value) === "on") || ($value===1) || ($value === true) || ($value=="1")) $tret_obj->enable_rule($rulename); |
|
630 | - if((strtolower($value) === "off") || ($value===0) || ($value === false) || ($value=="0")) $tret_obj->disable_rule($rulename); |
|
628 | + if (!EMTLib::_test_pattern($rule_pattern, $rulename)) continue; |
|
629 | + if ((strtolower($value) === "on") || ($value === 1) || ($value === true) || ($value == "1")) $tret_obj->enable_rule($rulename); |
|
630 | + if ((strtolower($value) === "off") || ($value === 0) || ($value === false) || ($value == "0")) $tret_obj->disable_rule($rulename); |
|
631 | 631 | } |
632 | 632 | } else { |
633 | - if($rule_pattern===false) |
|
633 | + if ($rule_pattern === false) |
|
634 | 634 | { |
635 | 635 | $tret_obj->set($key, $value); |
636 | 636 | } else { |
637 | - foreach($tret_obj->rules as $rulename => $v) |
|
637 | + foreach ($tret_obj->rules as $rulename => $v) |
|
638 | 638 | { |
639 | - if(!EMTLib::_test_pattern($rule_pattern, $rulename)) continue; |
|
639 | + if (!EMTLib::_test_pattern($rule_pattern, $rulename)) continue; |
|
640 | 640 | $tret_obj->set_rule($rulename, $key, $value); |
641 | 641 | } |
642 | 642 | } |
@@ -658,18 +658,18 @@ discard block |
||
658 | 658 | * @param mixed $key |
659 | 659 | * @param mixed $value |
660 | 660 | */ |
661 | - public function set($selector, $key , $value = false) |
|
661 | + public function set($selector, $key, $value = false) |
|
662 | 662 | { |
663 | - if(is_array($selector)) |
|
663 | + if (is_array($selector)) |
|
664 | 664 | { |
665 | - foreach($selector as $val) $this->set($val, $key, $value); |
|
665 | + foreach ($selector as $val) $this->set($val, $key, $value); |
|
666 | 666 | return; |
667 | 667 | } |
668 | - if(is_array($key)) |
|
668 | + if (is_array($key)) |
|
669 | 669 | { |
670 | - foreach($key as $x => $y) |
|
670 | + foreach ($key as $x => $y) |
|
671 | 671 | { |
672 | - if(is_array($value)) |
|
672 | + if (is_array($value)) |
|
673 | 673 | { |
674 | 674 | $kk = $y; |
675 | 675 | $vv = $value[$x]; |
@@ -712,11 +712,11 @@ discard block |
||
712 | 712 | */ |
713 | 713 | public function setup($setupmap) |
714 | 714 | { |
715 | - if(!is_array($setupmap)) return; |
|
715 | + if (!is_array($setupmap)) return; |
|
716 | 716 | |
717 | - if(isset($setupmap['map']) || isset($setupmap['maps'])) |
|
717 | + if (isset($setupmap['map']) || isset($setupmap['maps'])) |
|
718 | 718 | { |
719 | - if(isset($setupmap['map'])) |
|
719 | + if (isset($setupmap['map'])) |
|
720 | 720 | { |
721 | 721 | $ret['map'] = $test['params']['map']; |
722 | 722 | $ret['disable'] = $test['params']['map_disable']; |
@@ -726,12 +726,11 @@ discard block |
||
726 | 726 | unset($setupmap['map_disable']); |
727 | 727 | unset($setupmap['map_strict']); |
728 | 728 | } |
729 | - if(is_array($setupmap['maps'])) |
|
729 | + if (is_array($setupmap['maps'])) |
|
730 | 730 | { |
731 | - foreach($setupmap['maps'] as $map) |
|
731 | + foreach ($setupmap['maps'] as $map) |
|
732 | 732 | { |
733 | - $this->set_enable_map |
|
734 | - ($map['map'], |
|
733 | + $this->set_enable_map($map['map'], |
|
735 | 734 | isset($map['disable']) ? $map['disable'] : false, |
736 | 735 | isset($map['strict']) ? $map['strict'] : false |
737 | 736 | ); |
@@ -741,7 +740,7 @@ discard block |
||
741 | 740 | } |
742 | 741 | |
743 | 742 | |
744 | - foreach($setupmap as $k => $v) $this->do_setup($k , $v); |
|
743 | + foreach ($setupmap as $k => $v) $this->do_setup($k, $v); |
|
745 | 744 | } |
746 | 745 | |
747 | 746 |
@@ -45,7 +45,9 @@ discard block |
||
45 | 45 | |
46 | 46 | protected function log($str, $data = null) |
47 | 47 | { |
48 | - if(!$this->logging) return; |
|
48 | + if(!$this->logging) { |
|
49 | + return; |
|
50 | + } |
|
49 | 51 | $this->logs[] = array('class' => '', 'info' => $str, 'data' => $data); |
50 | 52 | } |
51 | 53 | |
@@ -67,7 +69,9 @@ discard block |
||
67 | 69 | |
68 | 70 | protected function debug($class, $place, &$after_text, $after_text_raw = "") |
69 | 71 | { |
70 | - if(!$this->debug_enabled) return; |
|
72 | + if(!$this->debug_enabled) { |
|
73 | + return; |
|
74 | + } |
|
71 | 75 | $this->debug_info[] = array( |
72 | 76 | 'tret' => $class == $this ? false: true, |
73 | 77 | 'class' => is_object($class)? get_class($class) : $class, |
@@ -145,7 +149,9 @@ discard block |
||
145 | 149 | public function remove_safe_block($id) |
146 | 150 | { |
147 | 151 | foreach($this->_safe_blocks as $k => $block) { |
148 | - if($block['id']==$id) unset($this->_safe_blocks[$k]); |
|
152 | + if($block['id']==$id) { |
|
153 | + unset($this->_safe_blocks[$k]); |
|
154 | + } |
|
149 | 155 | } |
150 | 156 | } |
151 | 157 | |
@@ -270,9 +276,13 @@ discard block |
||
270 | 276 | { |
271 | 277 | foreach($this->trets as $tret) |
272 | 278 | { |
273 | - if(isset($this->tret_objects[$tret])) continue; |
|
279 | + if(isset($this->tret_objects[$tret])) { |
|
280 | + continue; |
|
281 | + } |
|
274 | 282 | $obj = $this->create_object($tret); |
275 | - if($obj == null) continue; |
|
283 | + if($obj == null) { |
|
284 | + continue; |
|
285 | + } |
|
276 | 286 | $this->tret_objects[$tret] = $obj; |
277 | 287 | } |
278 | 288 | |
@@ -328,8 +338,9 @@ discard block |
||
328 | 338 | if(is_string($class)) |
329 | 339 | { |
330 | 340 | $obj = $this->create_object($class); |
331 | - if($obj === null) |
|
332 | - return false; |
|
341 | + if($obj === null) { |
|
342 | + return false; |
|
343 | + } |
|
333 | 344 | $this->tret_objects[($altname ? $altname : $class)] = $obj; |
334 | 345 | $this->trets[] = ($altname ? $altname : $class); |
335 | 346 | return true; |
@@ -345,7 +356,9 @@ discard block |
||
345 | 356 | */ |
346 | 357 | public function get_tret($name) |
347 | 358 | { |
348 | - if(isset($this->tret_objects[$name])) return $this->tret_objects[$name]; |
|
359 | + if(isset($this->tret_objects[$name])) { |
|
360 | + return $this->tret_objects[$name]; |
|
361 | + } |
|
349 | 362 | foreach($this->trets as $tret) |
350 | 363 | { |
351 | 364 | if($tret == $name) |
@@ -387,8 +400,11 @@ discard block |
||
387 | 400 | $this->_init(); |
388 | 401 | |
389 | 402 | $atrets = $this->trets; |
390 | - if(is_string($trets)) $atrets = array($trets); |
|
391 | - elseif(is_array($trets)) $atrets = $trets; |
|
403 | + if(is_string($trets)) { |
|
404 | + $atrets = array($trets); |
|
405 | + } elseif(is_array($trets)) { |
|
406 | + $atrets = $trets; |
|
407 | + } |
|
392 | 408 | |
393 | 409 | $this->debug($this, 'init', $this->_text); |
394 | 410 | |
@@ -404,15 +420,21 @@ discard block |
||
404 | 420 | foreach ($atrets as $tret) |
405 | 421 | { |
406 | 422 | // если установлен режим разметки тэгов то выставим его |
407 | - if($this->use_layout_set) |
|
408 | - $this->tret_objects[$tret]->set_tag_layout_ifnotset($this->use_layout); |
|
423 | + if($this->use_layout_set) { |
|
424 | + $this->tret_objects[$tret]->set_tag_layout_ifnotset($this->use_layout); |
|
425 | + } |
|
409 | 426 | |
410 | - if($this->class_layout_prefix) |
|
411 | - $this->tret_objects[$tret]->set_class_layout_prefix($this->class_layout_prefix); |
|
427 | + if($this->class_layout_prefix) { |
|
428 | + $this->tret_objects[$tret]->set_class_layout_prefix($this->class_layout_prefix); |
|
429 | + } |
|
412 | 430 | |
413 | 431 | // влючаем, если нужно |
414 | - if($this->debug_enabled) $this->tret_objects[$tret]->debug_on(); |
|
415 | - if($this->logging) $this->tret_objects[$tret]->logging = true; |
|
432 | + if($this->debug_enabled) { |
|
433 | + $this->tret_objects[$tret]->debug_on(); |
|
434 | + } |
|
435 | + if($this->logging) { |
|
436 | + $this->tret_objects[$tret]->logging = true; |
|
437 | + } |
|
416 | 438 | |
417 | 439 | // применяем трэт |
418 | 440 | //$this->tret_objects[$tret]->set_text(&$this->_text); |
@@ -420,21 +442,24 @@ discard block |
||
420 | 442 | $this->tret_objects[$tret]->apply(); |
421 | 443 | |
422 | 444 | // соберём ошибки если таковые есть |
423 | - if(count($this->tret_objects[$tret]->errors)>0) |
|
424 | - foreach($this->tret_objects[$tret]->errors as $err ) |
|
445 | + if(count($this->tret_objects[$tret]->errors)>0) { |
|
446 | + foreach($this->tret_objects[$tret]->errors as $err ) |
|
425 | 447 | $this->tret_error($tret, $err['info'], $err['data']); |
448 | + } |
|
426 | 449 | |
427 | 450 | // логгирование |
428 | - if($this->logging) |
|
429 | - if(count($this->tret_objects[$tret]->logs)>0) |
|
451 | + if($this->logging) { |
|
452 | + if(count($this->tret_objects[$tret]->logs)>0) |
|
430 | 453 | foreach($this->tret_objects[$tret]->logs as $log ) |
431 | - $this->tret_log($tret, $log['info'], $log['data']); |
|
454 | + $this->tret_log($tret, $log['info'], $log['data']); |
|
455 | + } |
|
432 | 456 | |
433 | 457 | // отладка |
434 | - if($this->debug_enabled) |
|
435 | - foreach($this->tret_objects[$tret]->debug_info as $di) |
|
458 | + if($this->debug_enabled) { |
|
459 | + foreach($this->tret_objects[$tret]->debug_info as $di) |
|
436 | 460 | { |
437 | 461 | $unsafetext = $di['text']; |
462 | + } |
|
438 | 463 | $unsafetext = EMTLib::safe_tag_chars($unsafetext, false); |
439 | 464 | $unsafetext = $this->safe_blocks($unsafetext, false); |
440 | 465 | $this->debug($tret, $di['place'], $unsafetext, $di['text']); |
@@ -461,7 +486,9 @@ discard block |
||
461 | 486 | if(!$this->disable_notg_replace) |
462 | 487 | { |
463 | 488 | $repl = array('<span class="_notg_start"></span>', '<span class="_notg_end"></span>'); |
464 | - if($this->remove_notg) $repl = ""; |
|
489 | + if($this->remove_notg) { |
|
490 | + $repl = ""; |
|
491 | + } |
|
465 | 492 | $this->_text = str_replace( array('<notg>','</notg>'), $repl , $this->_text); |
466 | 493 | } |
467 | 494 | $this->_text = trim($this->_text); |
@@ -484,15 +511,21 @@ discard block |
||
484 | 511 | foreach ($this->trets as $tret) |
485 | 512 | { |
486 | 513 | $arr =$this->tret_objects[$tret]->classes; |
487 | - if(!is_array($arr)) continue; |
|
514 | + if(!is_array($arr)) { |
|
515 | + continue; |
|
516 | + } |
|
488 | 517 | foreach($arr as $classname => $str) |
489 | 518 | { |
490 | - if(($compact) && (!$str)) continue; |
|
519 | + if(($compact) && (!$str)) { |
|
520 | + continue; |
|
521 | + } |
|
491 | 522 | $clsname = ($this->class_layout_prefix ? $this->class_layout_prefix : "" ).(isset($this->tret_objects[$tret]->class_names[$classname]) ? $this->tret_objects[$tret]->class_names[$classname] :$classname); |
492 | 523 | $res[$clsname] = $str; |
493 | 524 | } |
494 | 525 | } |
495 | - if($list) return $res; |
|
526 | + if($list) { |
|
527 | + return $res; |
|
528 | + } |
|
496 | 529 | $str = ""; |
497 | 530 | foreach($res as $k => $v) |
498 | 531 | { |
@@ -542,7 +575,9 @@ discard block |
||
542 | 575 | */ |
543 | 576 | public function set_enable_map($map, $disable = false, $strict = true) |
544 | 577 | { |
545 | - if(!is_array($map)) return; |
|
578 | + if(!is_array($map)) { |
|
579 | + return; |
|
580 | + } |
|
546 | 581 | $trets = array(); |
547 | 582 | foreach($map as $tret => $list) |
548 | 583 | { |
@@ -554,9 +589,11 @@ discard block |
||
554 | 589 | } |
555 | 590 | $trets[] = $tretx; |
556 | 591 | |
557 | - if($list === true) // все |
|
592 | + if($list === true) { |
|
593 | + // все |
|
558 | 594 | { |
559 | 595 | $tretx->activate(array(), !$disable , true); |
596 | + } |
|
560 | 597 | } elseif(is_string($list)) { |
561 | 598 | $tretx->activate(array($list), $disable , $strict); |
562 | 599 | } elseif(is_array($list)) { |
@@ -567,7 +604,9 @@ discard block |
||
567 | 604 | { |
568 | 605 | foreach($this->trets as $tret) |
569 | 606 | { |
570 | - if(in_array($this->tret_objects[$tret], $trets)) continue; |
|
607 | + if(in_array($this->tret_objects[$tret], $trets)) { |
|
608 | + continue; |
|
609 | + } |
|
571 | 610 | $this->tret_objects[$tret]->activate(array(), $disable , true); |
572 | 611 | } |
573 | 612 | } |
@@ -582,7 +621,9 @@ discard block |
||
582 | 621 | */ |
583 | 622 | public function is_on($key) |
584 | 623 | { |
585 | - if(!isset($this->settings[$key])) return false; |
|
624 | + if(!isset($this->settings[$key])) { |
|
625 | + return false; |
|
626 | + } |
|
586 | 627 | $kk = $this->settings[$key]; |
587 | 628 | return ((strtolower($kk)=="on") || ($kk === "1") || ($kk === true) || ($kk === 1)); |
588 | 629 | } |
@@ -614,20 +655,30 @@ discard block |
||
614 | 655 | } |
615 | 656 | EMTLib::_process_selector_pattern($tret_pattern); |
616 | 657 | EMTLib::_process_selector_pattern($rule_pattern); |
617 | - if($selector == "*") $this->settings[$key] = $value; |
|
658 | + if($selector == "*") { |
|
659 | + $this->settings[$key] = $value; |
|
660 | + } |
|
618 | 661 | |
619 | 662 | foreach ($this->trets as $tret) |
620 | 663 | { |
621 | 664 | $t1 = $this->get_short_tret($tret); |
622 | - if(!EMTLib::_test_pattern($tret_pattern, $t1)) if(!EMTLib::_test_pattern($tret_pattern, $tret)) continue; |
|
665 | + if(!EMTLib::_test_pattern($tret_pattern, $t1)) { |
|
666 | + if(!EMTLib::_test_pattern($tret_pattern, $tret)) continue; |
|
667 | + } |
|
623 | 668 | $tret_obj = $this->get_tret($tret); |
624 | 669 | if($key == "active") |
625 | 670 | { |
626 | 671 | foreach($tret_obj->rules as $rulename => $v) |
627 | 672 | { |
628 | - if(!EMTLib::_test_pattern($rule_pattern, $rulename)) continue; |
|
629 | - if((strtolower($value) === "on") || ($value===1) || ($value === true) || ($value=="1")) $tret_obj->enable_rule($rulename); |
|
630 | - if((strtolower($value) === "off") || ($value===0) || ($value === false) || ($value=="0")) $tret_obj->disable_rule($rulename); |
|
673 | + if(!EMTLib::_test_pattern($rule_pattern, $rulename)) { |
|
674 | + continue; |
|
675 | + } |
|
676 | + if((strtolower($value) === "on") || ($value===1) || ($value === true) || ($value=="1")) { |
|
677 | + $tret_obj->enable_rule($rulename); |
|
678 | + } |
|
679 | + if((strtolower($value) === "off") || ($value===0) || ($value === false) || ($value=="0")) { |
|
680 | + $tret_obj->disable_rule($rulename); |
|
681 | + } |
|
631 | 682 | } |
632 | 683 | } else { |
633 | 684 | if($rule_pattern===false) |
@@ -636,7 +687,9 @@ discard block |
||
636 | 687 | } else { |
637 | 688 | foreach($tret_obj->rules as $rulename => $v) |
638 | 689 | { |
639 | - if(!EMTLib::_test_pattern($rule_pattern, $rulename)) continue; |
|
690 | + if(!EMTLib::_test_pattern($rule_pattern, $rulename)) { |
|
691 | + continue; |
|
692 | + } |
|
640 | 693 | $tret_obj->set_rule($rulename, $key, $value); |
641 | 694 | } |
642 | 695 | } |
@@ -662,7 +715,9 @@ discard block |
||
662 | 715 | { |
663 | 716 | if(is_array($selector)) |
664 | 717 | { |
665 | - foreach($selector as $val) $this->set($val, $key, $value); |
|
718 | + foreach($selector as $val) { |
|
719 | + $this->set($val, $key, $value); |
|
720 | + } |
|
666 | 721 | return; |
667 | 722 | } |
668 | 723 | if(is_array($key)) |
@@ -712,7 +767,9 @@ discard block |
||
712 | 767 | */ |
713 | 768 | public function setup($setupmap) |
714 | 769 | { |
715 | - if(!is_array($setupmap)) return; |
|
770 | + if(!is_array($setupmap)) { |
|
771 | + return; |
|
772 | + } |
|
716 | 773 | |
717 | 774 | if(isset($setupmap['map']) || isset($setupmap['maps'])) |
718 | 775 | { |
@@ -741,7 +798,9 @@ discard block |
||
741 | 798 | } |
742 | 799 | |
743 | 800 | |
744 | - foreach($setupmap as $k => $v) $this->do_setup($k , $v); |
|
801 | + foreach($setupmap as $k => $v) { |
|
802 | + $this->do_setup($k , $v); |
|
803 | + } |
|
745 | 804 | } |
746 | 805 | |
747 | 806 |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @author somebody? |
82 | 82 | * @param int $c код символа в кодировке UTF-8 (например, 0x00AB) |
83 | - * @return bool|string |
|
83 | + * @return string|false |
|
84 | 84 | */ |
85 | 85 | public static function _getUnicodeChar($c) |
86 | 86 | { |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @param string $text |
120 | 120 | * @param mixed $mode |
121 | - * @return string|bool |
|
121 | + * @return false|string |
|
122 | 122 | */ |
123 | 123 | public static function clear_special_chars($text, $mode = null) |
124 | 124 | { |
@@ -199,8 +199,8 @@ discard block |
||
199 | 199 | * Тег 'a' кодируется со специальным префиксом для дальнейшей |
200 | 200 | * возможности выносить за него кавычки. |
201 | 201 | * |
202 | - * @param string $text |
|
203 | - * @param bool $safe |
|
202 | + * @param string $text |
|
203 | + * @param boolean $way |
|
204 | 204 | * @return string |
205 | 205 | */ |
206 | 206 | public static function safe_tag_chars($text, $way) |
@@ -322,6 +322,9 @@ discard block |
||
322 | 322 | |
323 | 323 | |
324 | 324 | |
325 | + /** |
|
326 | + * @param string[] $needle |
|
327 | + */ |
|
325 | 328 | public static function strpos_ex(&$haystack, $needle, $offset = null) |
326 | 329 | { |
327 | 330 | if(is_array($needle)) |
@@ -668,6 +671,10 @@ discard block |
||
668 | 671 | , $text); |
669 | 672 | } |
670 | 673 | |
674 | + /** |
|
675 | + * @param string $haystack |
|
676 | + * @param string $needle |
|
677 | + */ |
|
671 | 678 | public static function rstrpos ($haystack, $needle, $offset = 0){ |
672 | 679 | |
673 | 680 | if(trim($haystack) != "" && trim($needle) != "" && $offset <= mb_strlen($haystack)) |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | '1/2' => array('html' => array('½', '½'), |
44 | 44 | 'utf8' => array(0x00BD)), |
45 | 45 | '1/4' => array('html' => array('¼', '¼'), |
46 | - 'utf8' => array(0x00BC)), |
|
46 | + 'utf8' => array(0x00BC)), |
|
47 | 47 | '3/4' => array('html' => array('¾', '¾'), |
48 | 48 | 'utf8' => array(0x00BE)), |
49 | 49 | '+-' => array('html' => array('±', '±'), |
@@ -55,13 +55,13 @@ discard block |
||
55 | 55 | '(r)' => array('html' => array('®', '®'), |
56 | 56 | 'utf8' => array(0x00AE)), |
57 | 57 | '(c)' => array('html' => array('©', '©'), |
58 | - 'utf8' => array(0x00A9)), |
|
58 | + 'utf8' => array(0x00A9)), |
|
59 | 59 | '§' => array('html' => array('§', '§'), |
60 | - 'utf8' => array(0x00A7)), |
|
60 | + 'utf8' => array(0x00A7)), |
|
61 | 61 | '`' => array('html' => array('́')), |
62 | 62 | '\'' => array('html' => array('’', '’')), |
63 | 63 | 'x' => array('html' => array('×', '×'), |
64 | - 'utf8' => array('×') /* какой же у него может быть код? */), |
|
64 | + 'utf8' => array('×') /* какой же у него может быть код? */), |
|
65 | 65 | |
66 | 66 | ); |
67 | 67 | |
@@ -76,32 +76,32 @@ discard block |
||
76 | 76 | |
77 | 77 | |
78 | 78 | /** |
79 | - * Костыли для работы с символами UTF-8 |
|
80 | - * |
|
81 | - * @author somebody? |
|
82 | - * @param int $c код символа в кодировке UTF-8 (например, 0x00AB) |
|
83 | - * @return bool|string |
|
84 | - */ |
|
85 | - public static function _getUnicodeChar($c) |
|
86 | - { |
|
87 | - if ($c <= 0x7F) { |
|
88 | - return chr($c); |
|
89 | - } else if ($c <= 0x7FF) { |
|
90 | - return chr(0xC0 | $c >> 6) |
|
91 | - . chr(0x80 | $c & 0x3F); |
|
92 | - } else if ($c <= 0xFFFF) { |
|
93 | - return chr(0xE0 | $c >> 12) |
|
94 | - . chr(0x80 | $c >> 6 & 0x3F) |
|
95 | - . chr(0x80 | $c & 0x3F); |
|
96 | - } else if ($c <= 0x10FFFF) { |
|
97 | - return chr(0xF0 | $c >> 18) |
|
98 | - . chr(0x80 | $c >> 12 & 0x3F) |
|
99 | - . chr(0x80 | $c >> 6 & 0x3F) |
|
100 | - . chr(0x80 | $c & 0x3F); |
|
101 | - } else { |
|
102 | - return false; |
|
103 | - } |
|
104 | - } |
|
79 | + * Костыли для работы с символами UTF-8 |
|
80 | + * |
|
81 | + * @author somebody? |
|
82 | + * @param int $c код символа в кодировке UTF-8 (например, 0x00AB) |
|
83 | + * @return bool|string |
|
84 | + */ |
|
85 | + public static function _getUnicodeChar($c) |
|
86 | + { |
|
87 | + if ($c <= 0x7F) { |
|
88 | + return chr($c); |
|
89 | + } else if ($c <= 0x7FF) { |
|
90 | + return chr(0xC0 | $c >> 6) |
|
91 | + . chr(0x80 | $c & 0x3F); |
|
92 | + } else if ($c <= 0xFFFF) { |
|
93 | + return chr(0xE0 | $c >> 12) |
|
94 | + . chr(0x80 | $c >> 6 & 0x3F) |
|
95 | + . chr(0x80 | $c & 0x3F); |
|
96 | + } else if ($c <= 0x10FFFF) { |
|
97 | + return chr(0xF0 | $c >> 18) |
|
98 | + . chr(0x80 | $c >> 12 & 0x3F) |
|
99 | + . chr(0x80 | $c >> 6 & 0x3F) |
|
100 | + . chr(0x80 | $c & 0x3F); |
|
101 | + } else { |
|
102 | + return false; |
|
103 | + } |
|
104 | + } |
|
105 | 105 | |
106 | 106 | |
107 | 107 | /** |
@@ -194,71 +194,71 @@ discard block |
||
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
197 | - * Сохраняем содержимое тегов HTML |
|
198 | - * |
|
199 | - * Тег 'a' кодируется со специальным префиксом для дальнейшей |
|
200 | - * возможности выносить за него кавычки. |
|
201 | - * |
|
202 | - * @param string $text |
|
203 | - * @param bool $safe |
|
204 | - * @return string |
|
205 | - */ |
|
206 | - public static function safe_tag_chars($text, $way) |
|
207 | - { |
|
208 | - if ($way) |
|
209 | - $text = preg_replace_callback('/(\<\/?)(.+?)(\>)/s', create_function('$m','return $m[1].( substr(trim($m[2]), 0, 1) === "a" ? "%%___" : "" ) . \Fenrizbes\TypographBundle\EMT\EMTLib::encrypt_tag(trim($m[2])) . $m[3];'), $text); |
|
210 | - else |
|
211 | - $text = preg_replace_callback('/(\<\/?)(.+?)(\>)/s', create_function('$m','return $m[1].( substr(trim($m[2]), 0, 3) === "%%___" ? \Fenrizbes\TypographBundle\EMT\EMTLib::decrypt_tag(substr(trim($m[2]), 4)) : \Fenrizbes\TypographBundle\EMT\EMTLib::decrypt_tag(trim($m[2])) ) . $m[3];'), $text); |
|
212 | - return $text; |
|
213 | - } |
|
197 | + * Сохраняем содержимое тегов HTML |
|
198 | + * |
|
199 | + * Тег 'a' кодируется со специальным префиксом для дальнейшей |
|
200 | + * возможности выносить за него кавычки. |
|
201 | + * |
|
202 | + * @param string $text |
|
203 | + * @param bool $safe |
|
204 | + * @return string |
|
205 | + */ |
|
206 | + public static function safe_tag_chars($text, $way) |
|
207 | + { |
|
208 | + if ($way) |
|
209 | + $text = preg_replace_callback('/(\<\/?)(.+?)(\>)/s', create_function('$m','return $m[1].( substr(trim($m[2]), 0, 1) === "a" ? "%%___" : "" ) . \Fenrizbes\TypographBundle\EMT\EMTLib::encrypt_tag(trim($m[2])) . $m[3];'), $text); |
|
210 | + else |
|
211 | + $text = preg_replace_callback('/(\<\/?)(.+?)(\>)/s', create_function('$m','return $m[1].( substr(trim($m[2]), 0, 3) === "%%___" ? \Fenrizbes\TypographBundle\EMT\EMTLib::decrypt_tag(substr(trim($m[2]), 4)) : \Fenrizbes\TypographBundle\EMT\EMTLib::decrypt_tag(trim($m[2])) ) . $m[3];'), $text); |
|
212 | + return $text; |
|
213 | + } |
|
214 | 214 | |
215 | 215 | |
216 | - /** |
|
217 | - * Декодриует спец блоки |
|
218 | - * |
|
219 | - * @param string $text |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - public static function decode_internal_blocks($text) |
|
223 | - { |
|
224 | - $text = preg_replace_callback('/'.EMTLib::INTERNAL_BLOCK_OPEN.'([a-zA-Z0-9\/=]+?)'.EMTLib::INTERNAL_BLOCK_CLOSE.'/s', create_function('$m','return \Fenrizbes\TypographBundle\EMT\EMTLib::decrypt_tag($m[1]);'), $text); |
|
225 | - return $text; |
|
226 | - } |
|
216 | + /** |
|
217 | + * Декодриует спец блоки |
|
218 | + * |
|
219 | + * @param string $text |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + public static function decode_internal_blocks($text) |
|
223 | + { |
|
224 | + $text = preg_replace_callback('/'.EMTLib::INTERNAL_BLOCK_OPEN.'([a-zA-Z0-9\/=]+?)'.EMTLib::INTERNAL_BLOCK_CLOSE.'/s', create_function('$m','return \Fenrizbes\TypographBundle\EMT\EMTLib::decrypt_tag($m[1]);'), $text); |
|
225 | + return $text; |
|
226 | + } |
|
227 | 227 | |
228 | - /** |
|
229 | - * Кодирует спец блок |
|
230 | - * |
|
231 | - * @param string $text |
|
232 | - * @return string |
|
233 | - */ |
|
234 | - public static function iblock($text) |
|
235 | - { |
|
236 | - return EMTLib::INTERNAL_BLOCK_OPEN. EMTLib::encrypt_tag($text).EMTLib::INTERNAL_BLOCK_CLOSE; |
|
237 | - } |
|
228 | + /** |
|
229 | + * Кодирует спец блок |
|
230 | + * |
|
231 | + * @param string $text |
|
232 | + * @return string |
|
233 | + */ |
|
234 | + public static function iblock($text) |
|
235 | + { |
|
236 | + return EMTLib::INTERNAL_BLOCK_OPEN. EMTLib::encrypt_tag($text).EMTLib::INTERNAL_BLOCK_CLOSE; |
|
237 | + } |
|
238 | 238 | |
239 | 239 | |
240 | - /** |
|
241 | - * Создание тега с защищенным содержимым |
|
242 | - * |
|
243 | - * @param string $content текст, который будет обрамлен тегом |
|
244 | - * @param string $tag тэг |
|
245 | - * @param array $attribute список атрибутов, где ключ - имя атрибута, а значение - само значение данного атрибута |
|
246 | - * @return string |
|
247 | - */ |
|
248 | - public static function build_safe_tag($content, $tag = 'span', $attribute = array(), $layout = EMTLib::LAYOUT_STYLE ) |
|
249 | - { |
|
250 | - $htmlTag = $tag; |
|
240 | + /** |
|
241 | + * Создание тега с защищенным содержимым |
|
242 | + * |
|
243 | + * @param string $content текст, который будет обрамлен тегом |
|
244 | + * @param string $tag тэг |
|
245 | + * @param array $attribute список атрибутов, где ключ - имя атрибута, а значение - само значение данного атрибута |
|
246 | + * @return string |
|
247 | + */ |
|
248 | + public static function build_safe_tag($content, $tag = 'span', $attribute = array(), $layout = EMTLib::LAYOUT_STYLE ) |
|
249 | + { |
|
250 | + $htmlTag = $tag; |
|
251 | 251 | |
252 | - if (self::$_typographSpecificTagId) |
|
253 | - { |
|
254 | - if(!isset($attribute['id'])) |
|
255 | - { |
|
256 | - $attribute['id'] = 'emt-2' . mt_rand(1000,9999); |
|
257 | - } |
|
258 | - } |
|
252 | + if (self::$_typographSpecificTagId) |
|
253 | + { |
|
254 | + if(!isset($attribute['id'])) |
|
255 | + { |
|
256 | + $attribute['id'] = 'emt-2' . mt_rand(1000,9999); |
|
257 | + } |
|
258 | + } |
|
259 | 259 | |
260 | 260 | $classname = ""; |
261 | - if (count($attribute)) |
|
261 | + if (count($attribute)) |
|
262 | 262 | { |
263 | 263 | |
264 | 264 | if($layout & EMTLib::LAYOUT_STYLE) |
@@ -291,66 +291,66 @@ discard block |
||
291 | 291 | } |
292 | 292 | |
293 | 293 | if( ($layout & EMTLib::LAYOUT_CLASS ) && $classname) { |
294 | - $htmlTag .= " class=\"$classname\""; |
|
295 | - } |
|
294 | + $htmlTag .= " class=\"$classname\""; |
|
295 | + } |
|
296 | 296 | |
297 | 297 | return "<" . self::encrypt_tag($htmlTag) . ">$content</" . self::encrypt_tag($tag) . ">"; |
298 | - } |
|
298 | + } |
|
299 | 299 | |
300 | - /** |
|
301 | - * Метод, осуществляющий кодирование (сохранение) информации |
|
302 | - * с целью невозможности типографировать ее |
|
303 | - * |
|
304 | - * @param string $text |
|
305 | - * @return string |
|
306 | - */ |
|
307 | - public static function encrypt_tag($text) |
|
308 | - { |
|
309 | - return base64_encode($text)."="; |
|
310 | - } |
|
300 | + /** |
|
301 | + * Метод, осуществляющий кодирование (сохранение) информации |
|
302 | + * с целью невозможности типографировать ее |
|
303 | + * |
|
304 | + * @param string $text |
|
305 | + * @return string |
|
306 | + */ |
|
307 | + public static function encrypt_tag($text) |
|
308 | + { |
|
309 | + return base64_encode($text)."="; |
|
310 | + } |
|
311 | 311 | |
312 | - /** |
|
313 | - * Метод, осуществляющий декодирование информации |
|
314 | - * |
|
315 | - * @param string $text |
|
316 | - * @return string |
|
317 | - */ |
|
318 | - public static function decrypt_tag($text) |
|
319 | - { |
|
320 | - return base64_decode(substr($text,0,-1)); |
|
321 | - } |
|
312 | + /** |
|
313 | + * Метод, осуществляющий декодирование информации |
|
314 | + * |
|
315 | + * @param string $text |
|
316 | + * @return string |
|
317 | + */ |
|
318 | + public static function decrypt_tag($text) |
|
319 | + { |
|
320 | + return base64_decode(substr($text,0,-1)); |
|
321 | + } |
|
322 | 322 | |
323 | 323 | |
324 | 324 | |
325 | - public static function strpos_ex(&$haystack, $needle, $offset = null) |
|
326 | - { |
|
327 | - if(is_array($needle)) |
|
328 | - { |
|
329 | - $m = false; |
|
330 | - $w = false; |
|
331 | - foreach($needle as $n) |
|
332 | - { |
|
333 | - $p = strpos($haystack, $n , $offset); |
|
334 | - if($p===false) continue; |
|
335 | - if($m === false) |
|
336 | - { |
|
337 | - $m = $p; |
|
338 | - $w = $n; |
|
339 | - continue; |
|
340 | - } |
|
341 | - if($p < $m) |
|
342 | - { |
|
343 | - $m = $p; |
|
344 | - $w = $n; |
|
345 | - } |
|
346 | - } |
|
347 | - if($m === false) return false; |
|
348 | - return array('pos' => $m, 'str' => $w); |
|
349 | - } |
|
350 | - return strpos($haystack, $needle, $offset); |
|
351 | - } |
|
325 | + public static function strpos_ex(&$haystack, $needle, $offset = null) |
|
326 | + { |
|
327 | + if(is_array($needle)) |
|
328 | + { |
|
329 | + $m = false; |
|
330 | + $w = false; |
|
331 | + foreach($needle as $n) |
|
332 | + { |
|
333 | + $p = strpos($haystack, $n , $offset); |
|
334 | + if($p===false) continue; |
|
335 | + if($m === false) |
|
336 | + { |
|
337 | + $m = $p; |
|
338 | + $w = $n; |
|
339 | + continue; |
|
340 | + } |
|
341 | + if($p < $m) |
|
342 | + { |
|
343 | + $m = $p; |
|
344 | + $w = $n; |
|
345 | + } |
|
346 | + } |
|
347 | + if($m === false) return false; |
|
348 | + return array('pos' => $m, 'str' => $w); |
|
349 | + } |
|
350 | + return strpos($haystack, $needle, $offset); |
|
351 | + } |
|
352 | 352 | |
353 | - public static function _process_selector_pattern(&$pattern) |
|
353 | + public static function _process_selector_pattern(&$pattern) |
|
354 | 354 | { |
355 | 355 | if($pattern===false) return; |
356 | 356 | $pattern = preg_quote($pattern , '/'); |
@@ -363,8 +363,8 @@ discard block |
||
363 | 363 | return preg_match($pattern, $text); |
364 | 364 | } |
365 | 365 | |
366 | - public static function strtolower($string) |
|
367 | - { |
|
366 | + public static function strtolower($string) |
|
367 | + { |
|
368 | 368 | $convert_to = array( |
369 | 369 | "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", |
370 | 370 | "v", "w", "x", "y", "z", "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï", |
@@ -670,28 +670,28 @@ discard block |
||
670 | 670 | |
671 | 671 | public static function rstrpos ($haystack, $needle, $offset = 0){ |
672 | 672 | |
673 | - if(trim($haystack) != "" && trim($needle) != "" && $offset <= mb_strlen($haystack)) |
|
674 | - { |
|
675 | - $last_pos = $offset; |
|
676 | - $found = false; |
|
677 | - while(($curr_pos = mb_strpos($haystack, $needle, $last_pos)) !== false) |
|
678 | - { |
|
679 | - $found = true; |
|
680 | - $last_pos = $curr_pos + 1; |
|
681 | - } |
|
682 | - if($found) |
|
683 | - { |
|
684 | - return $last_pos - 1; |
|
685 | - } |
|
686 | - else |
|
687 | - { |
|
688 | - return false; |
|
689 | - } |
|
690 | - } |
|
691 | - else |
|
692 | - { |
|
693 | - return false; |
|
694 | - } |
|
673 | + if(trim($haystack) != "" && trim($needle) != "" && $offset <= mb_strlen($haystack)) |
|
674 | + { |
|
675 | + $last_pos = $offset; |
|
676 | + $found = false; |
|
677 | + while(($curr_pos = mb_strpos($haystack, $needle, $last_pos)) !== false) |
|
678 | + { |
|
679 | + $found = true; |
|
680 | + $last_pos = $curr_pos + 1; |
|
681 | + } |
|
682 | + if($found) |
|
683 | + { |
|
684 | + return $last_pos - 1; |
|
685 | + } |
|
686 | + else |
|
687 | + { |
|
688 | + return false; |
|
689 | + } |
|
690 | + } |
|
691 | + else |
|
692 | + { |
|
693 | + return false; |
|
694 | + } |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | public static function ifop($cond, $true, $false) { |
@@ -84,16 +84,16 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public static function _getUnicodeChar($c) |
86 | 86 | { |
87 | - if ($c <= 0x7F) { |
|
87 | + if ($c<=0x7F) { |
|
88 | 88 | return chr($c); |
89 | - } else if ($c <= 0x7FF) { |
|
89 | + } else if ($c<=0x7FF) { |
|
90 | 90 | return chr(0xC0 | $c >> 6) |
91 | 91 | . chr(0x80 | $c & 0x3F); |
92 | - } else if ($c <= 0xFFFF) { |
|
92 | + } else if ($c<=0xFFFF) { |
|
93 | 93 | return chr(0xE0 | $c >> 12) |
94 | 94 | . chr(0x80 | $c >> 6 & 0x3F) |
95 | 95 | . chr(0x80 | $c & 0x3F); |
96 | - } else if ($c <= 0x10FFFF) { |
|
96 | + } else if ($c<=0x10FFFF) { |
|
97 | 97 | return chr(0xF0 | $c >> 18) |
98 | 98 | . chr(0x80 | $c >> 12 & 0x3F) |
99 | 99 | . chr(0x80 | $c >> 6 & 0x3F) |
@@ -122,12 +122,12 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public static function clear_special_chars($text, $mode = null) |
124 | 124 | { |
125 | - if(is_string($mode)) $mode = array($mode); |
|
126 | - if(is_null($mode)) $mode = array('utf8', 'html'); |
|
127 | - if(!is_array($mode)) return false; |
|
125 | + if (is_string($mode)) $mode = array($mode); |
|
126 | + if (is_null($mode)) $mode = array('utf8', 'html'); |
|
127 | + if (!is_array($mode)) return false; |
|
128 | 128 | $moder = array(); |
129 | - foreach($mode as $mod) if(in_array($mod, array('utf8','html'))) $moder[] = $mod; |
|
130 | - if(count($moder)==0) return false; |
|
129 | + foreach ($mode as $mod) if (in_array($mod, array('utf8', 'html'))) $moder[] = $mod; |
|
130 | + if (count($moder) == 0) return false; |
|
131 | 131 | |
132 | 132 | foreach (self::$_charsTable as $char => $vals) |
133 | 133 | { |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | } |
144 | 144 | if ('html' === $type) |
145 | 145 | { |
146 | - if(preg_match("/<[a-z]+>/i",$v)) |
|
146 | + if (preg_match("/<[a-z]+>/i", $v)) |
|
147 | 147 | { |
148 | 148 | $v = self::safe_tag_chars($v, true); |
149 | 149 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | $ignore = implode('', $tags); |
189 | 189 | } |
190 | 190 | } |
191 | - $text = preg_replace(array('/\<br\s*\/?>/i', '/\<\/p\>\s*\<p\>/'), array("\n","\n\n"), $text); |
|
191 | + $text = preg_replace(array('/\<br\s*\/?>/i', '/\<\/p\>\s*\<p\>/'), array("\n", "\n\n"), $text); |
|
192 | 192 | $text = strip_tags($text, $ignore); |
193 | 193 | return $text; |
194 | 194 | } |
@@ -206,9 +206,9 @@ discard block |
||
206 | 206 | public static function safe_tag_chars($text, $way) |
207 | 207 | { |
208 | 208 | if ($way) |
209 | - $text = preg_replace_callback('/(\<\/?)(.+?)(\>)/s', create_function('$m','return $m[1].( substr(trim($m[2]), 0, 1) === "a" ? "%%___" : "" ) . \Fenrizbes\TypographBundle\EMT\EMTLib::encrypt_tag(trim($m[2])) . $m[3];'), $text); |
|
209 | + $text = preg_replace_callback('/(\<\/?)(.+?)(\>)/s', create_function('$m', 'return $m[1].( substr(trim($m[2]), 0, 1) === "a" ? "%%___" : "" ) . \Fenrizbes\TypographBundle\EMT\EMTLib::encrypt_tag(trim($m[2])) . $m[3];'), $text); |
|
210 | 210 | else |
211 | - $text = preg_replace_callback('/(\<\/?)(.+?)(\>)/s', create_function('$m','return $m[1].( substr(trim($m[2]), 0, 3) === "%%___" ? \Fenrizbes\TypographBundle\EMT\EMTLib::decrypt_tag(substr(trim($m[2]), 4)) : \Fenrizbes\TypographBundle\EMT\EMTLib::decrypt_tag(trim($m[2])) ) . $m[3];'), $text); |
|
211 | + $text = preg_replace_callback('/(\<\/?)(.+?)(\>)/s', create_function('$m', 'return $m[1].( substr(trim($m[2]), 0, 3) === "%%___" ? \Fenrizbes\TypographBundle\EMT\EMTLib::decrypt_tag(substr(trim($m[2]), 4)) : \Fenrizbes\TypographBundle\EMT\EMTLib::decrypt_tag(trim($m[2])) ) . $m[3];'), $text); |
|
212 | 212 | return $text; |
213 | 213 | } |
214 | 214 | |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | */ |
222 | 222 | public static function decode_internal_blocks($text) |
223 | 223 | { |
224 | - $text = preg_replace_callback('/'.EMTLib::INTERNAL_BLOCK_OPEN.'([a-zA-Z0-9\/=]+?)'.EMTLib::INTERNAL_BLOCK_CLOSE.'/s', create_function('$m','return \Fenrizbes\TypographBundle\EMT\EMTLib::decrypt_tag($m[1]);'), $text); |
|
224 | + $text = preg_replace_callback('/'.EMTLib::INTERNAL_BLOCK_OPEN.'([a-zA-Z0-9\/=]+?)'.EMTLib::INTERNAL_BLOCK_CLOSE.'/s', create_function('$m', 'return \Fenrizbes\TypographBundle\EMT\EMTLib::decrypt_tag($m[1]);'), $text); |
|
225 | 225 | return $text; |
226 | 226 | } |
227 | 227 | |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | */ |
234 | 234 | public static function iblock($text) |
235 | 235 | { |
236 | - return EMTLib::INTERNAL_BLOCK_OPEN. EMTLib::encrypt_tag($text).EMTLib::INTERNAL_BLOCK_CLOSE; |
|
236 | + return EMTLib::INTERNAL_BLOCK_OPEN.EMTLib::encrypt_tag($text).EMTLib::INTERNAL_BLOCK_CLOSE; |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | |
@@ -245,15 +245,15 @@ discard block |
||
245 | 245 | * @param array $attribute список атрибутов, где ключ - имя атрибута, а значение - само значение данного атрибута |
246 | 246 | * @return string |
247 | 247 | */ |
248 | - public static function build_safe_tag($content, $tag = 'span', $attribute = array(), $layout = EMTLib::LAYOUT_STYLE ) |
|
248 | + public static function build_safe_tag($content, $tag = 'span', $attribute = array(), $layout = EMTLib::LAYOUT_STYLE) |
|
249 | 249 | { |
250 | 250 | $htmlTag = $tag; |
251 | 251 | |
252 | 252 | if (self::$_typographSpecificTagId) |
253 | 253 | { |
254 | - if(!isset($attribute['id'])) |
|
254 | + if (!isset($attribute['id'])) |
|
255 | 255 | { |
256 | - $attribute['id'] = 'emt-2' . mt_rand(1000,9999); |
|
256 | + $attribute['id'] = 'emt-2'.mt_rand(1000, 9999); |
|
257 | 257 | } |
258 | 258 | } |
259 | 259 | |
@@ -261,14 +261,14 @@ discard block |
||
261 | 261 | if (count($attribute)) |
262 | 262 | { |
263 | 263 | |
264 | - if($layout & EMTLib::LAYOUT_STYLE) |
|
264 | + if ($layout & EMTLib::LAYOUT_STYLE) |
|
265 | 265 | { |
266 | - if(isset($attribute['__style']) && $attribute['__style']) |
|
266 | + if (isset($attribute['__style']) && $attribute['__style']) |
|
267 | 267 | { |
268 | - if(isset($attribute['style']) && $attribute['style']) |
|
268 | + if (isset($attribute['style']) && $attribute['style']) |
|
269 | 269 | { |
270 | 270 | $st = trim($attribute['style']); |
271 | - if(mb_substr($st, -1) != ";") $st .= ";"; |
|
271 | + if (mb_substr($st, -1) != ";") $st .= ";"; |
|
272 | 272 | $st .= $attribute['__style']; |
273 | 273 | $attribute['style'] = $st; |
274 | 274 | } else { |
@@ -280,8 +280,8 @@ discard block |
||
280 | 280 | } |
281 | 281 | foreach ($attribute as $attr => $value) |
282 | 282 | { |
283 | - if($attr == "__style") continue; |
|
284 | - if($attr == "class") { |
|
283 | + if ($attr == "__style") continue; |
|
284 | + if ($attr == "class") { |
|
285 | 285 | $classname = "$value"; |
286 | 286 | continue; |
287 | 287 | } |
@@ -290,11 +290,11 @@ discard block |
||
290 | 290 | |
291 | 291 | } |
292 | 292 | |
293 | - if( ($layout & EMTLib::LAYOUT_CLASS ) && $classname) { |
|
293 | + if (($layout & EMTLib::LAYOUT_CLASS) && $classname) { |
|
294 | 294 | $htmlTag .= " class=\"$classname\""; |
295 | 295 | } |
296 | 296 | |
297 | - return "<" . self::encrypt_tag($htmlTag) . ">$content</" . self::encrypt_tag($tag) . ">"; |
|
297 | + return "<".self::encrypt_tag($htmlTag).">$content</".self::encrypt_tag($tag).">"; |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | /** |
@@ -317,34 +317,34 @@ discard block |
||
317 | 317 | */ |
318 | 318 | public static function decrypt_tag($text) |
319 | 319 | { |
320 | - return base64_decode(substr($text,0,-1)); |
|
320 | + return base64_decode(substr($text, 0, -1)); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | |
324 | 324 | |
325 | 325 | public static function strpos_ex(&$haystack, $needle, $offset = null) |
326 | 326 | { |
327 | - if(is_array($needle)) |
|
327 | + if (is_array($needle)) |
|
328 | 328 | { |
329 | 329 | $m = false; |
330 | 330 | $w = false; |
331 | - foreach($needle as $n) |
|
331 | + foreach ($needle as $n) |
|
332 | 332 | { |
333 | - $p = strpos($haystack, $n , $offset); |
|
334 | - if($p===false) continue; |
|
335 | - if($m === false) |
|
333 | + $p = strpos($haystack, $n, $offset); |
|
334 | + if ($p === false) continue; |
|
335 | + if ($m === false) |
|
336 | 336 | { |
337 | 337 | $m = $p; |
338 | 338 | $w = $n; |
339 | 339 | continue; |
340 | 340 | } |
341 | - if($p < $m) |
|
341 | + if ($p<$m) |
|
342 | 342 | { |
343 | 343 | $m = $p; |
344 | 344 | $w = $n; |
345 | 345 | } |
346 | 346 | } |
347 | - if($m === false) return false; |
|
347 | + if ($m === false) return false; |
|
348 | 348 | return array('pos' => $m, 'str' => $w); |
349 | 349 | } |
350 | 350 | return strpos($haystack, $needle, $offset); |
@@ -352,14 +352,14 @@ discard block |
||
352 | 352 | |
353 | 353 | public static function _process_selector_pattern(&$pattern) |
354 | 354 | { |
355 | - if($pattern===false) return; |
|
356 | - $pattern = preg_quote($pattern , '/'); |
|
355 | + if ($pattern === false) return; |
|
356 | + $pattern = preg_quote($pattern, '/'); |
|
357 | 357 | $pattern = str_replace("\\*", "[a-z0-9_\-]*", $pattern); |
358 | 358 | $pattern = "/".$pattern."/i"; |
359 | 359 | } |
360 | 360 | public static function _test_pattern($pattern, $text) |
361 | 361 | { |
362 | - if($pattern === false) return true; |
|
362 | + if ($pattern === false) return true; |
|
363 | 363 | return preg_match($pattern, $text); |
364 | 364 | } |
365 | 365 | |
@@ -646,7 +646,7 @@ discard block |
||
646 | 646 | */ |
647 | 647 | public static function html_char_entity_to_unicode($entity) |
648 | 648 | { |
649 | - if(isset(self::$html4_char_ents[$entity])) return self::_getUnicodeChar(self::$html4_char_ents[$entity]); |
|
649 | + if (isset(self::$html4_char_ents[$entity])) return self::_getUnicodeChar(self::$html4_char_ents[$entity]); |
|
650 | 650 | return false; |
651 | 651 | } |
652 | 652 | |
@@ -668,20 +668,20 @@ discard block |
||
668 | 668 | , $text); |
669 | 669 | } |
670 | 670 | |
671 | - public static function rstrpos ($haystack, $needle, $offset = 0){ |
|
671 | + public static function rstrpos($haystack, $needle, $offset = 0) { |
|
672 | 672 | |
673 | - if(trim($haystack) != "" && trim($needle) != "" && $offset <= mb_strlen($haystack)) |
|
673 | + if (trim($haystack) != "" && trim($needle) != "" && $offset<=mb_strlen($haystack)) |
|
674 | 674 | { |
675 | 675 | $last_pos = $offset; |
676 | 676 | $found = false; |
677 | - while(($curr_pos = mb_strpos($haystack, $needle, $last_pos)) !== false) |
|
677 | + while (($curr_pos = mb_strpos($haystack, $needle, $last_pos)) !== false) |
|
678 | 678 | { |
679 | 679 | $found = true; |
680 | - $last_pos = $curr_pos + 1; |
|
680 | + $last_pos = $curr_pos+1; |
|
681 | 681 | } |
682 | - if($found) |
|
682 | + if ($found) |
|
683 | 683 | { |
684 | - return $last_pos - 1; |
|
684 | + return $last_pos-1; |
|
685 | 685 | } |
686 | 686 | else |
687 | 687 | { |
@@ -122,12 +122,22 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public static function clear_special_chars($text, $mode = null) |
124 | 124 | { |
125 | - if(is_string($mode)) $mode = array($mode); |
|
126 | - if(is_null($mode)) $mode = array('utf8', 'html'); |
|
127 | - if(!is_array($mode)) return false; |
|
125 | + if(is_string($mode)) { |
|
126 | + $mode = array($mode); |
|
127 | + } |
|
128 | + if(is_null($mode)) { |
|
129 | + $mode = array('utf8', 'html'); |
|
130 | + } |
|
131 | + if(!is_array($mode)) { |
|
132 | + return false; |
|
133 | + } |
|
128 | 134 | $moder = array(); |
129 | - foreach($mode as $mod) if(in_array($mod, array('utf8','html'))) $moder[] = $mod; |
|
130 | - if(count($moder)==0) return false; |
|
135 | + foreach($mode as $mod) { |
|
136 | + if(in_array($mod, array('utf8','html'))) $moder[] = $mod; |
|
137 | + } |
|
138 | + if(count($moder)==0) { |
|
139 | + return false; |
|
140 | + } |
|
131 | 141 | |
132 | 142 | foreach (self::$_charsTable as $char => $vals) |
133 | 143 | { |
@@ -181,8 +191,12 @@ discard block |
||
181 | 191 | $tags = array(); |
182 | 192 | foreach ($allowableTag as $tag) |
183 | 193 | { |
184 | - if ('<' !== substr($tag, 0, 1) || '>' !== substr($tag, -1, 1)) continue; |
|
185 | - if ('/' === substr($tag, 1, 1)) continue; |
|
194 | + if ('<' !== substr($tag, 0, 1) || '>' !== substr($tag, -1, 1)) { |
|
195 | + continue; |
|
196 | + } |
|
197 | + if ('/' === substr($tag, 1, 1)) { |
|
198 | + continue; |
|
199 | + } |
|
186 | 200 | $tags [] = $tag; |
187 | 201 | } |
188 | 202 | $ignore = implode('', $tags); |
@@ -205,10 +219,11 @@ discard block |
||
205 | 219 | */ |
206 | 220 | public static function safe_tag_chars($text, $way) |
207 | 221 | { |
208 | - if ($way) |
|
209 | - $text = preg_replace_callback('/(\<\/?)(.+?)(\>)/s', create_function('$m','return $m[1].( substr(trim($m[2]), 0, 1) === "a" ? "%%___" : "" ) . \Fenrizbes\TypographBundle\EMT\EMTLib::encrypt_tag(trim($m[2])) . $m[3];'), $text); |
|
210 | - else |
|
211 | - $text = preg_replace_callback('/(\<\/?)(.+?)(\>)/s', create_function('$m','return $m[1].( substr(trim($m[2]), 0, 3) === "%%___" ? \Fenrizbes\TypographBundle\EMT\EMTLib::decrypt_tag(substr(trim($m[2]), 4)) : \Fenrizbes\TypographBundle\EMT\EMTLib::decrypt_tag(trim($m[2])) ) . $m[3];'), $text); |
|
222 | + if ($way) { |
|
223 | + $text = preg_replace_callback('/(\<\/?)(.+?)(\>)/s', create_function('$m','return $m[1].( substr(trim($m[2]), 0, 1) === "a" ? "%%___" : "" ) . \Fenrizbes\TypographBundle\EMT\EMTLib::encrypt_tag(trim($m[2])) . $m[3];'), $text); |
|
224 | + } else { |
|
225 | + $text = preg_replace_callback('/(\<\/?)(.+?)(\>)/s', create_function('$m','return $m[1].( substr(trim($m[2]), 0, 3) === "%%___" ? \Fenrizbes\TypographBundle\EMT\EMTLib::decrypt_tag(substr(trim($m[2]), 4)) : \Fenrizbes\TypographBundle\EMT\EMTLib::decrypt_tag(trim($m[2])) ) . $m[3];'), $text); |
|
226 | + } |
|
212 | 227 | return $text; |
213 | 228 | } |
214 | 229 | |
@@ -268,7 +283,9 @@ discard block |
||
268 | 283 | if(isset($attribute['style']) && $attribute['style']) |
269 | 284 | { |
270 | 285 | $st = trim($attribute['style']); |
271 | - if(mb_substr($st, -1) != ";") $st .= ";"; |
|
286 | + if(mb_substr($st, -1) != ";") { |
|
287 | + $st .= ";"; |
|
288 | + } |
|
272 | 289 | $st .= $attribute['__style']; |
273 | 290 | $attribute['style'] = $st; |
274 | 291 | } else { |
@@ -280,7 +297,9 @@ discard block |
||
280 | 297 | } |
281 | 298 | foreach ($attribute as $attr => $value) |
282 | 299 | { |
283 | - if($attr == "__style") continue; |
|
300 | + if($attr == "__style") { |
|
301 | + continue; |
|
302 | + } |
|
284 | 303 | if($attr == "class") { |
285 | 304 | $classname = "$value"; |
286 | 305 | continue; |
@@ -331,7 +350,9 @@ discard block |
||
331 | 350 | foreach($needle as $n) |
332 | 351 | { |
333 | 352 | $p = strpos($haystack, $n , $offset); |
334 | - if($p===false) continue; |
|
353 | + if($p===false) { |
|
354 | + continue; |
|
355 | + } |
|
335 | 356 | if($m === false) |
336 | 357 | { |
337 | 358 | $m = $p; |
@@ -344,7 +365,9 @@ discard block |
||
344 | 365 | $w = $n; |
345 | 366 | } |
346 | 367 | } |
347 | - if($m === false) return false; |
|
368 | + if($m === false) { |
|
369 | + return false; |
|
370 | + } |
|
348 | 371 | return array('pos' => $m, 'str' => $w); |
349 | 372 | } |
350 | 373 | return strpos($haystack, $needle, $offset); |
@@ -352,14 +375,18 @@ discard block |
||
352 | 375 | |
353 | 376 | public static function _process_selector_pattern(&$pattern) |
354 | 377 | { |
355 | - if($pattern===false) return; |
|
378 | + if($pattern===false) { |
|
379 | + return; |
|
380 | + } |
|
356 | 381 | $pattern = preg_quote($pattern , '/'); |
357 | 382 | $pattern = str_replace("\\*", "[a-z0-9_\-]*", $pattern); |
358 | 383 | $pattern = "/".$pattern."/i"; |
359 | 384 | } |
360 | 385 | public static function _test_pattern($pattern, $text) |
361 | 386 | { |
362 | - if($pattern === false) return true; |
|
387 | + if($pattern === false) { |
|
388 | + return true; |
|
389 | + } |
|
363 | 390 | return preg_match($pattern, $text); |
364 | 391 | } |
365 | 392 | |
@@ -646,7 +673,9 @@ discard block |
||
646 | 673 | */ |
647 | 674 | public static function html_char_entity_to_unicode($entity) |
648 | 675 | { |
649 | - if(isset(self::$html4_char_ents[$entity])) return self::_getUnicodeChar(self::$html4_char_ents[$entity]); |
|
676 | + if(isset(self::$html4_char_ents[$entity])) { |
|
677 | + return self::_getUnicodeChar(self::$html4_char_ents[$entity]); |
|
678 | + } |
|
650 | 679 | return false; |
651 | 680 | } |
652 | 681 | |
@@ -682,13 +711,11 @@ discard block |
||
682 | 711 | if($found) |
683 | 712 | { |
684 | 713 | return $last_pos - 1; |
685 | - } |
|
686 | - else |
|
714 | + } else |
|
687 | 715 | { |
688 | 716 | return false; |
689 | 717 | } |
690 | - } |
|
691 | - else |
|
718 | + } else |
|
692 | 719 | { |
693 | 720 | return false; |
694 | 721 | } |
@@ -70,6 +70,9 @@ discard block |
||
70 | 70 | $this->logs[] = array('info' => $str, 'data' => $data); |
71 | 71 | } |
72 | 72 | |
73 | + /** |
|
74 | + * @param string $info |
|
75 | + */ |
|
73 | 76 | private function error($info, $data = null) |
74 | 77 | { |
75 | 78 | $this->errors[] = array('info' => $info, 'data' => $data); |
@@ -91,7 +94,6 @@ discard block |
||
91 | 94 | * EMTLib::LAYOUT_STYLE - с помощью стилей |
92 | 95 | * EMTLib::LAYOUT_CLASS - с помощью классов |
93 | 96 | * |
94 | - * @param int $kind |
|
95 | 97 | */ |
96 | 98 | public function set_tag_layout_ifnotset($layout) |
97 | 99 | { |
@@ -105,7 +107,6 @@ discard block |
||
105 | 107 | * EMTLib::LAYOUT_CLASS - с помощью классов |
106 | 108 | * EMTLib::LAYOUT_STYLE|EMTLib::LAYOUT_CLASS - оба метода |
107 | 109 | * |
108 | - * @param int $kind |
|
109 | 110 | */ |
110 | 111 | public function set_tag_layout($layout = EMTLib::LAYOUT_STYLE) |
111 | 112 | { |
@@ -292,6 +293,10 @@ discard block |
||
292 | 293 | } |
293 | 294 | |
294 | 295 | |
296 | + /** |
|
297 | + * @param string $pattern |
|
298 | + * @param string $replacement |
|
299 | + */ |
|
295 | 300 | protected function preg_replace_e($pattern, $replacement, $text) |
296 | 301 | { |
297 | 302 | $chr = substr($pattern,0,1); |
@@ -437,7 +442,7 @@ discard block |
||
437 | 442 | * Получить строковое значение настройки |
438 | 443 | * |
439 | 444 | * @param unknown_type $key |
440 | - * @return unknown |
|
445 | + * @return string |
|
441 | 446 | */ |
442 | 447 | public function ss($key) |
443 | 448 | { |
@@ -494,7 +499,6 @@ discard block |
||
494 | 499 | /** |
495 | 500 | * Применить к тексту |
496 | 501 | * |
497 | - * @param string $text - текст к которому применить |
|
498 | 502 | * @param mixed $list - список правил, null - все правила |
499 | 503 | * @return string |
500 | 504 | */ |
@@ -59,9 +59,9 @@ |
||
59 | 59 | * Типы кавычек |
60 | 60 | */ |
61 | 61 | const QUOTE_FIRS_OPEN = '«'; |
62 | - const QUOTE_FIRS_CLOSE = '»'; |
|
63 | - const QUOTE_CRAWSE_OPEN = '„'; |
|
64 | - const QUOTE_CRAWSE_CLOSE = '“'; |
|
62 | + const QUOTE_FIRS_CLOSE = '»'; |
|
63 | + const QUOTE_CRAWSE_OPEN = '„'; |
|
64 | + const QUOTE_CRAWSE_CLOSE = '“'; |
|
65 | 65 | |
66 | 66 | |
67 | 67 | private function log($str, $data = null) |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | |
30 | 30 | private $disabled = array(); |
31 | 31 | private $enabled = array(); |
32 | - protected $_text= ''; |
|
32 | + protected $_text = ''; |
|
33 | 33 | public $logging = false; |
34 | 34 | public $logs = false; |
35 | 35 | public $errors = false; |
@@ -66,19 +66,19 @@ discard block |
||
66 | 66 | |
67 | 67 | private function log($str, $data = null) |
68 | 68 | { |
69 | - if(!$this->logging) return; |
|
69 | + if (!$this->logging) return; |
|
70 | 70 | $this->logs[] = array('info' => $str, 'data' => $data); |
71 | 71 | } |
72 | 72 | |
73 | 73 | private function error($info, $data = null) |
74 | 74 | { |
75 | 75 | $this->errors[] = array('info' => $info, 'data' => $data); |
76 | - $this->log('ERROR: '. $info , $data); |
|
76 | + $this->log('ERROR: '.$info, $data); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | public function debug($place, &$after_text) |
80 | 80 | { |
81 | - if(!$this->debug_enabled) return; |
|
81 | + if (!$this->debug_enabled) return; |
|
82 | 82 | $this->debug_info[] = array( |
83 | 83 | 'place' => $place, |
84 | 84 | 'text' => $after_text, |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function set_tag_layout_ifnotset($layout) |
97 | 97 | { |
98 | - if($this->use_layout_set) return; |
|
98 | + if ($this->use_layout_set) return; |
|
99 | 99 | $this->use_layout = $layout; |
100 | 100 | } |
101 | 101 | |
@@ -132,29 +132,29 @@ discard block |
||
132 | 132 | |
133 | 133 | private function getmethod($name) |
134 | 134 | { |
135 | - if(!$name) return false; |
|
136 | - if(!method_exists($this, $name)) return false; |
|
135 | + if (!$name) return false; |
|
136 | + if (!method_exists($this, $name)) return false; |
|
137 | 137 | return array($this, $name); |
138 | 138 | } |
139 | 139 | |
140 | 140 | private function _pre_parse() |
141 | 141 | { |
142 | 142 | $this->pre_parse(); |
143 | - foreach($this->rules as $rule) |
|
143 | + foreach ($this->rules as $rule) |
|
144 | 144 | { |
145 | - if(!isset($rule['init'])) continue; |
|
145 | + if (!isset($rule['init'])) continue; |
|
146 | 146 | $m = $this->getmethod($rule['init']); |
147 | - if(!$m) continue; |
|
147 | + if (!$m) continue; |
|
148 | 148 | call_user_func($m); |
149 | 149 | } |
150 | 150 | } |
151 | 151 | private function _post_parse() |
152 | 152 | { |
153 | - foreach($this->rules as $rule) |
|
153 | + foreach ($this->rules as $rule) |
|
154 | 154 | { |
155 | - if(!isset($rule['deinit'])) continue; |
|
155 | + if (!isset($rule['deinit'])) continue; |
|
156 | 156 | $m = $this->getmethod($rule['deinit']); |
157 | - if(!$m) continue; |
|
157 | + if (!$m) continue; |
|
158 | 158 | call_user_func($m); |
159 | 159 | } |
160 | 160 | $this->post_parse(); |
@@ -162,8 +162,8 @@ discard block |
||
162 | 162 | |
163 | 163 | private function rule_order_sort($a, $b) |
164 | 164 | { |
165 | - if($a['order'] == $b['order']) return 0; |
|
166 | - if($a['order'] < $b['order']) return -1; |
|
165 | + if ($a['order'] == $b['order']) return 0; |
|
166 | + if ($a['order']<$b['order']) return -1; |
|
167 | 167 | return 1; |
168 | 168 | } |
169 | 169 | |
@@ -172,23 +172,23 @@ discard block |
||
172 | 172 | $name = $rule['id']; |
173 | 173 | //$this->log("Правило $name", "Применяем правило"); |
174 | 174 | $disabled = (isset($this->disabled[$rule['id']]) && $this->disabled[$rule['id']]) || ((isset($rule['disabled']) && $rule['disabled']) && !(isset($this->enabled[$rule['id']]) && $this->enabled[$rule['id']])); |
175 | - if($disabled) |
|
175 | + if ($disabled) |
|
176 | 176 | { |
177 | - $this->log("Правило $name", "Правило отключено" . ((isset($rule['disabled']) && $rule['disabled'])? " (по умолчанию)" : "")); |
|
177 | + $this->log("Правило $name", "Правило отключено".((isset($rule['disabled']) && $rule['disabled']) ? " (по умолчанию)" : "")); |
|
178 | 178 | return; |
179 | 179 | } |
180 | - if(isset($rule['function']) && $rule['function']) |
|
180 | + if (isset($rule['function']) && $rule['function']) |
|
181 | 181 | { |
182 | - if(!(isset($rule['pattern']) && $rule['pattern'])) |
|
182 | + if (!(isset($rule['pattern']) && $rule['pattern'])) |
|
183 | 183 | { |
184 | - if(method_exists($this, $rule['function'])) |
|
184 | + if (method_exists($this, $rule['function'])) |
|
185 | 185 | { |
186 | 186 | $this->log("Правило $name", "Используется метод ".$rule['function']." в правиле"); |
187 | 187 | |
188 | 188 | call_user_func(array($this, $rule['function'])); |
189 | 189 | return; |
190 | 190 | } |
191 | - if(function_exists($rule['function'])) |
|
191 | + if (function_exists($rule['function'])) |
|
192 | 192 | { |
193 | 193 | $this->log("Правило $name", "Используется функция ".$rule['function']." в правиле"); |
194 | 194 | |
@@ -196,38 +196,38 @@ discard block |
||
196 | 196 | return; |
197 | 197 | } |
198 | 198 | |
199 | - $this->error('Функция '.$rule['function'].' из правила '.$rule['id']. " не найдена"); |
|
200 | - return ; |
|
199 | + $this->error('Функция '.$rule['function'].' из правила '.$rule['id']." не найдена"); |
|
200 | + return; |
|
201 | 201 | } else { |
202 | - if(preg_match("/^[a-z_0-9]+$/i", $rule['function'])) |
|
202 | + if (preg_match("/^[a-z_0-9]+$/i", $rule['function'])) |
|
203 | 203 | { |
204 | - if(method_exists($this, $rule['function'])) |
|
204 | + if (method_exists($this, $rule['function'])) |
|
205 | 205 | { |
206 | 206 | $this->log("Правило $name", "Замена с использованием preg_replace_callback с методом ".$rule['function'].""); |
207 | 207 | |
208 | 208 | $this->_text = preg_replace_callback($rule['pattern'], array($this, $rule['function']), $this->_text); |
209 | 209 | return; |
210 | 210 | } |
211 | - if(function_exists($rule['function'])) |
|
211 | + if (function_exists($rule['function'])) |
|
212 | 212 | { |
213 | 213 | $this->log("Правило $name", "Замена с использованием preg_replace_callback с функцией ".$rule['function'].""); |
214 | 214 | |
215 | 215 | $this->_text = preg_replace_callback($rule['pattern'], $rule['function'], $this->_text); |
216 | 216 | return; |
217 | 217 | } |
218 | - $this->error('Функция '.$rule['function'].' из правила '.$rule['id']. " не найдена"); |
|
218 | + $this->error('Функция '.$rule['function'].' из правила '.$rule['id']." не найдена"); |
|
219 | 219 | } else { |
220 | - $this->_text = preg_replace_callback($rule['pattern'], create_function('$m', $rule['function']), $this->_text); |
|
220 | + $this->_text = preg_replace_callback($rule['pattern'], create_function('$m', $rule['function']), $this->_text); |
|
221 | 221 | $this->log('Замена с использованием preg_replace_callback с инлайн функцией из правила '.$rule['id']); |
222 | 222 | return; |
223 | 223 | } |
224 | - return ; |
|
224 | + return; |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | |
228 | - if(isset($rule['simple_replace']) && $rule['simple_replace']) |
|
228 | + if (isset($rule['simple_replace']) && $rule['simple_replace']) |
|
229 | 229 | { |
230 | - if(isset($rule['case_sensitive']) && $rule['case_sensitive']) |
|
230 | + if (isset($rule['case_sensitive']) && $rule['case_sensitive']) |
|
231 | 231 | { |
232 | 232 | $this->log("Правило $name", "Простая замена с использованием str_replace"); |
233 | 233 | $this->_text = str_replace($rule['pattern'], $rule['replacement'], $this->_text); |
@@ -239,53 +239,53 @@ discard block |
||
239 | 239 | } |
240 | 240 | |
241 | 241 | $pattern = $rule['pattern']; |
242 | - if(is_string($pattern)) $pattern = array($pattern); |
|
242 | + if (is_string($pattern)) $pattern = array($pattern); |
|
243 | 243 | $eval = false; |
244 | - foreach($pattern as $patt) |
|
244 | + foreach ($pattern as $patt) |
|
245 | 245 | { |
246 | - $chr = substr($patt,0,1); |
|
246 | + $chr = substr($patt, 0, 1); |
|
247 | 247 | $preg_arr = explode($chr, $patt); |
248 | - if(strpos($preg_arr[count($preg_arr)-1], "e")!==false) |
|
248 | + if (strpos($preg_arr[count($preg_arr)-1], "e") !== false) |
|
249 | 249 | { |
250 | 250 | $eval = true; |
251 | 251 | break; |
252 | 252 | } |
253 | 253 | } |
254 | - if(!$eval) |
|
254 | + if (!$eval) |
|
255 | 255 | { |
256 | 256 | $this->log("Правило $name", "Замена с использованием preg_replace"); |
257 | 257 | |
258 | 258 | do { |
259 | 259 | $this->_text = preg_replace($rule['pattern'], $rule['replacement'], $this->_text); |
260 | - if(!(isset($rule['cycled']) && $rule['cycled'])) break; |
|
261 | - } while(preg_match($rule['pattern'], $this->_text)); |
|
260 | + if (!(isset($rule['cycled']) && $rule['cycled'])) break; |
|
261 | + } while (preg_match($rule['pattern'], $this->_text)); |
|
262 | 262 | |
263 | 263 | return; |
264 | 264 | } |
265 | 265 | |
266 | 266 | $this->log("Правило $name", "Замена с использованием preg_replace_callback вместо eval"); |
267 | 267 | $k = 0; |
268 | - foreach($pattern as $patt) |
|
268 | + foreach ($pattern as $patt) |
|
269 | 269 | { |
270 | 270 | $repl = is_string($rule['replacement']) ? $rule['replacement'] : $rule['replacement'][$k]; |
271 | 271 | |
272 | - $chr = substr($patt,0,1); |
|
272 | + $chr = substr($patt, 0, 1); |
|
273 | 273 | $preg_arr = explode($chr, $patt); |
274 | - if(strpos($preg_arr[count($preg_arr)-1], "e")!==false) // eval система |
|
274 | + if (strpos($preg_arr[count($preg_arr)-1], "e") !== false) // eval система |
|
275 | 275 | { |
276 | - $preg_arr[count($preg_arr)-1] = str_replace("e","",$preg_arr[count($preg_arr)-1]); |
|
276 | + $preg_arr[count($preg_arr)-1] = str_replace("e", "", $preg_arr[count($preg_arr)-1]); |
|
277 | 277 | $patt = implode($chr, $preg_arr); |
278 | 278 | $this->thereplacement = $repl; |
279 | 279 | do { |
280 | 280 | $this->_text = preg_replace_callback($patt, array($this, "thereplcallback"), $this->_text); |
281 | - if(!(isset($rule['cycled']) && $rule['cycled'])) break; |
|
282 | - } while(preg_match($patt, $this->_text)); |
|
281 | + if (!(isset($rule['cycled']) && $rule['cycled'])) break; |
|
282 | + } while (preg_match($patt, $this->_text)); |
|
283 | 283 | |
284 | 284 | } else { |
285 | 285 | do { |
286 | 286 | $this->_text = preg_replace($patt, $repl, $this->_text); |
287 | - if(!(isset($rule['cycled']) && $rule['cycled'])) break; |
|
288 | - } while(preg_match($patt, $this->_text)); |
|
287 | + if (!(isset($rule['cycled']) && $rule['cycled'])) break; |
|
288 | + } while (preg_match($patt, $this->_text)); |
|
289 | 289 | } |
290 | 290 | $k++; |
291 | 291 | } |
@@ -294,10 +294,10 @@ discard block |
||
294 | 294 | |
295 | 295 | protected function preg_replace_e($pattern, $replacement, $text) |
296 | 296 | { |
297 | - $chr = substr($pattern,0,1); |
|
297 | + $chr = substr($pattern, 0, 1); |
|
298 | 298 | $preg_arr = explode($chr, $pattern); |
299 | - if(strpos($preg_arr[count($preg_arr)-1], "e")===false) return preg_replace($pattern, $replacement, $text); |
|
300 | - $preg_arr[count($preg_arr)-1] = str_replace("e","",$preg_arr[count($preg_arr)-1]); |
|
299 | + if (strpos($preg_arr[count($preg_arr)-1], "e") === false) return preg_replace($pattern, $replacement, $text); |
|
300 | + $preg_arr[count($preg_arr)-1] = str_replace("e", "", $preg_arr[count($preg_arr)-1]); |
|
301 | 301 | $patt = implode($chr, $preg_arr); |
302 | 302 | $this->thereplacement = $replacement; |
303 | 303 | return preg_replace_callback($patt, array($this, "thereplcallback"), $text); |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | private function thereplcallback($m) |
308 | 308 | { |
309 | 309 | $x = ""; |
310 | - eval('$x = '.($this->thereplacement?$this->thereplacement:'""').';'); |
|
310 | + eval('$x = '.($this->thereplacement ? $this->thereplacement : '""').';'); |
|
311 | 311 | return $x; |
312 | 312 | } |
313 | 313 | |
@@ -316,19 +316,19 @@ discard block |
||
316 | 316 | $this->errors = array(); |
317 | 317 | $this->_pre_parse(); |
318 | 318 | |
319 | - $this->log("Применяется набор правил", implode(",",$list)); |
|
319 | + $this->log("Применяется набор правил", implode(",", $list)); |
|
320 | 320 | |
321 | 321 | $rulelist = array(); |
322 | - foreach($list as $k) |
|
322 | + foreach ($list as $k) |
|
323 | 323 | { |
324 | 324 | $rule = $this->rules[$k]; |
325 | 325 | $rule['id'] = $k; |
326 | - $rule['order'] = isset($rule['order'])? $rule['order'] : 5 ; |
|
326 | + $rule['order'] = isset($rule['order']) ? $rule['order'] : 5; |
|
327 | 327 | $rulelist[] = $rule; |
328 | 328 | } |
329 | 329 | //usort($rulelist, array($this, "rule_order_sort")); |
330 | 330 | |
331 | - foreach($rulelist as $rule) |
|
331 | + foreach ($rulelist as $rule) |
|
332 | 332 | { |
333 | 333 | $this->apply_rule($rule); |
334 | 334 | $this->debug($rule['id'], $this->_text); |
@@ -349,30 +349,30 @@ discard block |
||
349 | 349 | */ |
350 | 350 | protected function tag($content, $tag = 'span', $attribute = array()) |
351 | 351 | { |
352 | - if(isset($attribute['class'])) |
|
352 | + if (isset($attribute['class'])) |
|
353 | 353 | { |
354 | 354 | $classname = $attribute['class']; |
355 | - if($classname == "nowrap") |
|
355 | + if ($classname == "nowrap") |
|
356 | 356 | { |
357 | - if(!$this->is_on('nowrap')) |
|
357 | + if (!$this->is_on('nowrap')) |
|
358 | 358 | { |
359 | 359 | $tag = "nobr"; |
360 | 360 | $attribute = array(); |
361 | 361 | $classname = ""; |
362 | 362 | } |
363 | 363 | } |
364 | - if(isset($this->classes[$classname])) |
|
364 | + if (isset($this->classes[$classname])) |
|
365 | 365 | { |
366 | 366 | $style_inline = $this->classes[$classname]; |
367 | - if($style_inline) $attribute['__style'] = $style_inline; |
|
367 | + if ($style_inline) $attribute['__style'] = $style_inline; |
|
368 | 368 | } |
369 | - $classname = (isset($this->class_names[$classname]) ? $this->class_names[$classname] :$classname); |
|
370 | - $classname = ($this->class_layout_prefix ? $this->class_layout_prefix : "" ).$classname; |
|
369 | + $classname = (isset($this->class_names[$classname]) ? $this->class_names[$classname] : $classname); |
|
370 | + $classname = ($this->class_layout_prefix ? $this->class_layout_prefix : "").$classname; |
|
371 | 371 | $attribute['class'] = $classname; |
372 | 372 | } |
373 | 373 | |
374 | 374 | return EMTLib::build_safe_tag($content, $tag, $attribute, |
375 | - $this->use_layout === false? EMTLib::LAYOUT_STYLE : $this->use_layout ); |
|
375 | + $this->use_layout === false ? EMTLib::LAYOUT_STYLE : $this->use_layout); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | |
@@ -428,9 +428,9 @@ discard block |
||
428 | 428 | */ |
429 | 429 | public function is_on($key) |
430 | 430 | { |
431 | - if(!isset($this->settings[$key])) return false; |
|
431 | + if (!isset($this->settings[$key])) return false; |
|
432 | 432 | $kk = $this->settings[$key]; |
433 | - return ((strtolower($kk)=="on") || ($kk === "1") || ($kk === true) || ($kk === 1)); |
|
433 | + return ((strtolower($kk) == "on") || ($kk === "1") || ($kk === true) || ($kk === 1)); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | /** |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | */ |
442 | 442 | public function ss($key) |
443 | 443 | { |
444 | - if(!isset($this->settings[$key])) return ""; |
|
444 | + if (!isset($this->settings[$key])) return ""; |
|
445 | 445 | return strval($this->settings[$key]); |
446 | 446 | } |
447 | 447 | |
@@ -464,21 +464,21 @@ discard block |
||
464 | 464 | * @param boolean $disable выкллючить их или включить |
465 | 465 | * @param boolean $strict строго, т.е. те которые не в списку будут тоже обработаны |
466 | 466 | */ |
467 | - public function activate($list,$disable =false, $strict = true) |
|
467 | + public function activate($list, $disable = false, $strict = true) |
|
468 | 468 | { |
469 | - if(!is_array($list)) return ; |
|
469 | + if (!is_array($list)) return; |
|
470 | 470 | |
471 | - foreach($list as $rulename) |
|
471 | + foreach ($list as $rulename) |
|
472 | 472 | { |
473 | - if($disable) $this->disable_rule($rulename); else $this->enable_rule($rulename); |
|
473 | + if ($disable) $this->disable_rule($rulename); else $this->enable_rule($rulename); |
|
474 | 474 | } |
475 | 475 | |
476 | - if($strict) |
|
476 | + if ($strict) |
|
477 | 477 | { |
478 | - foreach($this->rules as $rulename => $v) |
|
478 | + foreach ($this->rules as $rulename => $v) |
|
479 | 479 | { |
480 | - if(in_array($rulename, $list)) continue; |
|
481 | - if(!$disable) $this->disable_rule($rulename); else $this->enable_rule($rulename); |
|
480 | + if (in_array($rulename, $list)) continue; |
|
481 | + if (!$disable) $this->disable_rule($rulename); else $this->enable_rule($rulename); |
|
482 | 482 | } |
483 | 483 | } |
484 | 484 | } |
@@ -500,8 +500,8 @@ discard block |
||
500 | 500 | */ |
501 | 501 | public function apply($list = null) |
502 | 502 | { |
503 | - if(is_string($list)) $rlist = array($list); |
|
504 | - elseif(is_array($list)) $rlist = $list; |
|
503 | + if (is_string($list)) $rlist = array($list); |
|
504 | + elseif (is_array($list)) $rlist = $list; |
|
505 | 505 | else $rlist = array_keys($this->rules); |
506 | 506 | $this->_apply($rlist); |
507 | 507 | return $this->_text; |
@@ -66,7 +66,9 @@ discard block |
||
66 | 66 | |
67 | 67 | private function log($str, $data = null) |
68 | 68 | { |
69 | - if(!$this->logging) return; |
|
69 | + if(!$this->logging) { |
|
70 | + return; |
|
71 | + } |
|
70 | 72 | $this->logs[] = array('info' => $str, 'data' => $data); |
71 | 73 | } |
72 | 74 | |
@@ -78,7 +80,9 @@ discard block |
||
78 | 80 | |
79 | 81 | public function debug($place, &$after_text) |
80 | 82 | { |
81 | - if(!$this->debug_enabled) return; |
|
83 | + if(!$this->debug_enabled) { |
|
84 | + return; |
|
85 | + } |
|
82 | 86 | $this->debug_info[] = array( |
83 | 87 | 'place' => $place, |
84 | 88 | 'text' => $after_text, |
@@ -95,7 +99,9 @@ discard block |
||
95 | 99 | */ |
96 | 100 | public function set_tag_layout_ifnotset($layout) |
97 | 101 | { |
98 | - if($this->use_layout_set) return; |
|
102 | + if($this->use_layout_set) { |
|
103 | + return; |
|
104 | + } |
|
99 | 105 | $this->use_layout = $layout; |
100 | 106 | } |
101 | 107 | |
@@ -132,8 +138,12 @@ discard block |
||
132 | 138 | |
133 | 139 | private function getmethod($name) |
134 | 140 | { |
135 | - if(!$name) return false; |
|
136 | - if(!method_exists($this, $name)) return false; |
|
141 | + if(!$name) { |
|
142 | + return false; |
|
143 | + } |
|
144 | + if(!method_exists($this, $name)) { |
|
145 | + return false; |
|
146 | + } |
|
137 | 147 | return array($this, $name); |
138 | 148 | } |
139 | 149 | |
@@ -142,9 +152,13 @@ discard block |
||
142 | 152 | $this->pre_parse(); |
143 | 153 | foreach($this->rules as $rule) |
144 | 154 | { |
145 | - if(!isset($rule['init'])) continue; |
|
155 | + if(!isset($rule['init'])) { |
|
156 | + continue; |
|
157 | + } |
|
146 | 158 | $m = $this->getmethod($rule['init']); |
147 | - if(!$m) continue; |
|
159 | + if(!$m) { |
|
160 | + continue; |
|
161 | + } |
|
148 | 162 | call_user_func($m); |
149 | 163 | } |
150 | 164 | } |
@@ -152,9 +166,13 @@ discard block |
||
152 | 166 | { |
153 | 167 | foreach($this->rules as $rule) |
154 | 168 | { |
155 | - if(!isset($rule['deinit'])) continue; |
|
169 | + if(!isset($rule['deinit'])) { |
|
170 | + continue; |
|
171 | + } |
|
156 | 172 | $m = $this->getmethod($rule['deinit']); |
157 | - if(!$m) continue; |
|
173 | + if(!$m) { |
|
174 | + continue; |
|
175 | + } |
|
158 | 176 | call_user_func($m); |
159 | 177 | } |
160 | 178 | $this->post_parse(); |
@@ -162,8 +180,12 @@ discard block |
||
162 | 180 | |
163 | 181 | private function rule_order_sort($a, $b) |
164 | 182 | { |
165 | - if($a['order'] == $b['order']) return 0; |
|
166 | - if($a['order'] < $b['order']) return -1; |
|
183 | + if($a['order'] == $b['order']) { |
|
184 | + return 0; |
|
185 | + } |
|
186 | + if($a['order'] < $b['order']) { |
|
187 | + return -1; |
|
188 | + } |
|
167 | 189 | return 1; |
168 | 190 | } |
169 | 191 | |
@@ -239,7 +261,9 @@ discard block |
||
239 | 261 | } |
240 | 262 | |
241 | 263 | $pattern = $rule['pattern']; |
242 | - if(is_string($pattern)) $pattern = array($pattern); |
|
264 | + if(is_string($pattern)) { |
|
265 | + $pattern = array($pattern); |
|
266 | + } |
|
243 | 267 | $eval = false; |
244 | 268 | foreach($pattern as $patt) |
245 | 269 | { |
@@ -257,7 +281,9 @@ discard block |
||
257 | 281 | |
258 | 282 | do { |
259 | 283 | $this->_text = preg_replace($rule['pattern'], $rule['replacement'], $this->_text); |
260 | - if(!(isset($rule['cycled']) && $rule['cycled'])) break; |
|
284 | + if(!(isset($rule['cycled']) && $rule['cycled'])) { |
|
285 | + break; |
|
286 | + } |
|
261 | 287 | } while(preg_match($rule['pattern'], $this->_text)); |
262 | 288 | |
263 | 289 | return; |
@@ -271,20 +297,26 @@ discard block |
||
271 | 297 | |
272 | 298 | $chr = substr($patt,0,1); |
273 | 299 | $preg_arr = explode($chr, $patt); |
274 | - if(strpos($preg_arr[count($preg_arr)-1], "e")!==false) // eval система |
|
300 | + if(strpos($preg_arr[count($preg_arr)-1], "e")!==false) { |
|
301 | + // eval система |
|
275 | 302 | { |
276 | 303 | $preg_arr[count($preg_arr)-1] = str_replace("e","",$preg_arr[count($preg_arr)-1]); |
304 | + } |
|
277 | 305 | $patt = implode($chr, $preg_arr); |
278 | 306 | $this->thereplacement = $repl; |
279 | 307 | do { |
280 | 308 | $this->_text = preg_replace_callback($patt, array($this, "thereplcallback"), $this->_text); |
281 | - if(!(isset($rule['cycled']) && $rule['cycled'])) break; |
|
309 | + if(!(isset($rule['cycled']) && $rule['cycled'])) { |
|
310 | + break; |
|
311 | + } |
|
282 | 312 | } while(preg_match($patt, $this->_text)); |
283 | 313 | |
284 | 314 | } else { |
285 | 315 | do { |
286 | 316 | $this->_text = preg_replace($patt, $repl, $this->_text); |
287 | - if(!(isset($rule['cycled']) && $rule['cycled'])) break; |
|
317 | + if(!(isset($rule['cycled']) && $rule['cycled'])) { |
|
318 | + break; |
|
319 | + } |
|
288 | 320 | } while(preg_match($patt, $this->_text)); |
289 | 321 | } |
290 | 322 | $k++; |
@@ -296,7 +328,9 @@ discard block |
||
296 | 328 | { |
297 | 329 | $chr = substr($pattern,0,1); |
298 | 330 | $preg_arr = explode($chr, $pattern); |
299 | - if(strpos($preg_arr[count($preg_arr)-1], "e")===false) return preg_replace($pattern, $replacement, $text); |
|
331 | + if(strpos($preg_arr[count($preg_arr)-1], "e")===false) { |
|
332 | + return preg_replace($pattern, $replacement, $text); |
|
333 | + } |
|
300 | 334 | $preg_arr[count($preg_arr)-1] = str_replace("e","",$preg_arr[count($preg_arr)-1]); |
301 | 335 | $patt = implode($chr, $preg_arr); |
302 | 336 | $this->thereplacement = $replacement; |
@@ -364,7 +398,9 @@ discard block |
||
364 | 398 | if(isset($this->classes[$classname])) |
365 | 399 | { |
366 | 400 | $style_inline = $this->classes[$classname]; |
367 | - if($style_inline) $attribute['__style'] = $style_inline; |
|
401 | + if($style_inline) { |
|
402 | + $attribute['__style'] = $style_inline; |
|
403 | + } |
|
368 | 404 | } |
369 | 405 | $classname = (isset($this->class_names[$classname]) ? $this->class_names[$classname] :$classname); |
370 | 406 | $classname = ($this->class_layout_prefix ? $this->class_layout_prefix : "" ).$classname; |
@@ -428,7 +464,9 @@ discard block |
||
428 | 464 | */ |
429 | 465 | public function is_on($key) |
430 | 466 | { |
431 | - if(!isset($this->settings[$key])) return false; |
|
467 | + if(!isset($this->settings[$key])) { |
|
468 | + return false; |
|
469 | + } |
|
432 | 470 | $kk = $this->settings[$key]; |
433 | 471 | return ((strtolower($kk)=="on") || ($kk === "1") || ($kk === true) || ($kk === 1)); |
434 | 472 | } |
@@ -441,7 +479,9 @@ discard block |
||
441 | 479 | */ |
442 | 480 | public function ss($key) |
443 | 481 | { |
444 | - if(!isset($this->settings[$key])) return ""; |
|
482 | + if(!isset($this->settings[$key])) { |
|
483 | + return ""; |
|
484 | + } |
|
445 | 485 | return strval($this->settings[$key]); |
446 | 486 | } |
447 | 487 | |
@@ -466,19 +506,31 @@ discard block |
||
466 | 506 | */ |
467 | 507 | public function activate($list,$disable =false, $strict = true) |
468 | 508 | { |
469 | - if(!is_array($list)) return ; |
|
509 | + if(!is_array($list)) { |
|
510 | + return ; |
|
511 | + } |
|
470 | 512 | |
471 | 513 | foreach($list as $rulename) |
472 | 514 | { |
473 | - if($disable) $this->disable_rule($rulename); else $this->enable_rule($rulename); |
|
515 | + if($disable) { |
|
516 | + $this->disable_rule($rulename); |
|
517 | + } else { |
|
518 | + $this->enable_rule($rulename); |
|
519 | + } |
|
474 | 520 | } |
475 | 521 | |
476 | 522 | if($strict) |
477 | 523 | { |
478 | 524 | foreach($this->rules as $rulename => $v) |
479 | 525 | { |
480 | - if(in_array($rulename, $list)) continue; |
|
481 | - if(!$disable) $this->disable_rule($rulename); else $this->enable_rule($rulename); |
|
526 | + if(in_array($rulename, $list)) { |
|
527 | + continue; |
|
528 | + } |
|
529 | + if(!$disable) { |
|
530 | + $this->disable_rule($rulename); |
|
531 | + } else { |
|
532 | + $this->enable_rule($rulename); |
|
533 | + } |
|
482 | 534 | } |
483 | 535 | } |
484 | 536 | } |
@@ -500,9 +552,13 @@ discard block |
||
500 | 552 | */ |
501 | 553 | public function apply($list = null) |
502 | 554 | { |
503 | - if(is_string($list)) $rlist = array($list); |
|
504 | - elseif(is_array($list)) $rlist = $list; |
|
505 | - else $rlist = array_keys($this->rules); |
|
555 | + if(is_string($list)) { |
|
556 | + $rlist = array($list); |
|
557 | + } elseif(is_array($list)) { |
|
558 | + $rlist = $list; |
|
559 | + } else { |
|
560 | + $rlist = array_keys($this->rules); |
|
561 | + } |
|
506 | 562 | $this->_apply($rlist); |
507 | 563 | return $this->_text; |
508 | 564 | } |
@@ -62,6 +62,7 @@ |
||
62 | 62 | /** |
63 | 63 | * Расстановка защищенных тегов параграфа (<p>...</p>) и переноса строки |
64 | 64 | * |
65 | + * @param string $text |
|
65 | 66 | * @return void |
66 | 67 | */ |
67 | 68 | protected function do_paragraphs($text) { |
@@ -59,7 +59,7 @@ |
||
59 | 59 | |
60 | 60 | ); |
61 | 61 | |
62 | - /** |
|
62 | + /** |
|
63 | 63 | * Расстановка защищенных тегов параграфа (<p>...</p>) и переноса строки |
64 | 64 | * |
65 | 65 | * @return void |
@@ -65,15 +65,15 @@ discard block |
||
65 | 65 | * @return void |
66 | 66 | */ |
67 | 67 | protected function do_paragraphs($text) { |
68 | - $text = str_replace("\r\n","\n",$text); |
|
69 | - $text = str_replace("\r","\n",$text); |
|
70 | - $text = '<' . self::BASE64_PARAGRAPH_TAG . '>' . trim($text) . '</' . self::BASE64_PARAGRAPH_TAG . '>'; |
|
68 | + $text = str_replace("\r\n", "\n", $text); |
|
69 | + $text = str_replace("\r", "\n", $text); |
|
70 | + $text = '<'.self::BASE64_PARAGRAPH_TAG.'>'.trim($text).'</'.self::BASE64_PARAGRAPH_TAG.'>'; |
|
71 | 71 | //$text = $this->preg_replace_e('/([\040\t]+)?(\n|\r){2,}/e', '"</" . self::BASE64_PARAGRAPH_TAG . "><" .self::BASE64_PARAGRAPH_TAG . ">"', $text); |
72 | 72 | //$text = $this->preg_replace_e('/([\040\t]+)?(\n){2,}/e', '"</" . self::BASE64_PARAGRAPH_TAG . "><" .self::BASE64_PARAGRAPH_TAG . ">"', $text); |
73 | 73 | $text = $this->preg_replace_e('/([\040\t]+)?(\n)+([\040\t]*)(\n)+/e', '$m[1]."</" . self::BASE64_PARAGRAPH_TAG . ">".\Fenrizbes\TypographBundle\EMT\EMTLib::iblock($m[2].$m[3])."<" .self::BASE64_PARAGRAPH_TAG . ">"', $text); |
74 | 74 | //$text = $this->preg_replace_e('/([\040\t]+)?(\n)+([\040\t]*)(\n)+/e', '"</" . self::BASE64_PARAGRAPH_TAG . ">"."<" .self::BASE64_PARAGRAPH_TAG . ">"', $text); |
75 | 75 | //может от открвающего до закрывающего ?! |
76 | - $text = preg_replace('/\<' . self::BASE64_PARAGRAPH_TAG . '\>('.EMTLib::INTERNAL_BLOCK_OPEN.'[a-zA-Z0-9\/=]+?'.EMTLib::INTERNAL_BLOCK_CLOSE.')?\<\/' . self::BASE64_PARAGRAPH_TAG . '\>/s', "", $text); |
|
76 | + $text = preg_replace('/\<'.self::BASE64_PARAGRAPH_TAG.'\>('.EMTLib::INTERNAL_BLOCK_OPEN.'[a-zA-Z0-9\/=]+?'.EMTLib::INTERNAL_BLOCK_CLOSE.')?\<\/'.self::BASE64_PARAGRAPH_TAG.'\>/s', "", $text); |
|
77 | 77 | return $text; |
78 | 78 | } |
79 | 79 | |
@@ -84,16 +84,16 @@ discard block |
||
84 | 84 | */ |
85 | 85 | protected function build_paragraphs() |
86 | 86 | { |
87 | - $r = mb_strpos($this->_text, '<' . self::BASE64_PARAGRAPH_TAG . '>' ); |
|
88 | - $p = EMTLib::rstrpos($this->_text, '</' . self::BASE64_PARAGRAPH_TAG . '>' ) ; |
|
89 | - if(($r!== false) && ($p !== false)) { |
|
87 | + $r = mb_strpos($this->_text, '<'.self::BASE64_PARAGRAPH_TAG.'>'); |
|
88 | + $p = EMTLib::rstrpos($this->_text, '</'.self::BASE64_PARAGRAPH_TAG.'>'); |
|
89 | + if (($r !== false) && ($p !== false)) { |
|
90 | 90 | |
91 | - $beg = mb_substr($this->_text,0,$r); |
|
92 | - $end = mb_substr($this->_text,$p+mb_strlen('</' . self::BASE64_PARAGRAPH_TAG . '>')); |
|
91 | + $beg = mb_substr($this->_text, 0, $r); |
|
92 | + $end = mb_substr($this->_text, $p+mb_strlen('</'.self::BASE64_PARAGRAPH_TAG.'>')); |
|
93 | 93 | $this->_text = |
94 | - (trim($beg) ? $this->do_paragraphs($beg). "\n":"") .'<' . self::BASE64_PARAGRAPH_TAG . '>'. |
|
95 | - mb_substr($this->_text,$r + mb_strlen('<' . self::BASE64_PARAGRAPH_TAG . '>'),$p -($r + mb_strlen('<' . self::BASE64_PARAGRAPH_TAG . '>')) ).'</' . self::BASE64_PARAGRAPH_TAG . '>'. |
|
96 | - (trim($end) ? "\n".$this->do_paragraphs($end) :"") ; |
|
94 | + (trim($beg) ? $this->do_paragraphs($beg)."\n" : "").'<'.self::BASE64_PARAGRAPH_TAG.'>'. |
|
95 | + mb_substr($this->_text, $r+mb_strlen('<'.self::BASE64_PARAGRAPH_TAG.'>'), $p-($r+mb_strlen('<'.self::BASE64_PARAGRAPH_TAG.'>'))).'</'.self::BASE64_PARAGRAPH_TAG.'>'. |
|
96 | + (trim($end) ? "\n".$this->do_paragraphs($end) : ""); |
|
97 | 97 | } else { |
98 | 98 | $this->_text = $this->do_paragraphs($this->_text); |
99 | 99 | } |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | */ |
107 | 107 | protected function build_brs() |
108 | 108 | { |
109 | - $this->_text = $this->preg_replace_e('/(\<\/' . self::BASE64_PARAGRAPH_TAG . '\>)([\r\n \t]+)(\<' . self::BASE64_PARAGRAPH_TAG . '\>)/mse', '$m[1].\Fenrizbes\TypographBundle\EMT\EMTLib::iblock($m[2]).$m[3]', $this->_text); |
|
109 | + $this->_text = $this->preg_replace_e('/(\<\/'.self::BASE64_PARAGRAPH_TAG.'\>)([\r\n \t]+)(\<'.self::BASE64_PARAGRAPH_TAG.'\>)/mse', '$m[1].\Fenrizbes\TypographBundle\EMT\EMTLib::iblock($m[2]).$m[3]', $this->_text); |
|
110 | 110 | |
111 | - if (!preg_match('/\<' . self::BASE64_BREAKLINE_TAG . '\>/', $this->_text)) { |
|
112 | - $this->_text = str_replace("\r\n","\n",$this->_text); |
|
113 | - $this->_text = str_replace("\r","\n",$this->_text); |
|
111 | + if (!preg_match('/\<'.self::BASE64_BREAKLINE_TAG.'\>/', $this->_text)) { |
|
112 | + $this->_text = str_replace("\r\n", "\n", $this->_text); |
|
113 | + $this->_text = str_replace("\r", "\n", $this->_text); |
|
114 | 114 | //$this->_text = $this->preg_replace_e('/(\n|\r)/e', '"<" . self::BASE64_BREAKLINE_TAG . ">"', $this->_text); |
115 | 115 | $this->_text = $this->preg_replace_e('/(\n)/e', '"<" . self::BASE64_BREAKLINE_TAG . ">\n"', $this->_text); |
116 | 116 | } |
@@ -7,23 +7,23 @@ |
||
7 | 7 | |
8 | 8 | class TypographService |
9 | 9 | { |
10 | - protected $configs; |
|
10 | + protected $configs; |
|
11 | 11 | |
12 | - public function __construct($configs) |
|
13 | - { |
|
14 | - $this->configs = $configs; |
|
15 | - } |
|
12 | + public function __construct($configs) |
|
13 | + { |
|
14 | + $this->configs = $configs; |
|
15 | + } |
|
16 | 16 | |
17 | - public function apply($string, $config = null) |
|
18 | - { |
|
19 | - if (is_null($config)) { |
|
20 | - $config = 'default'; |
|
21 | - } |
|
17 | + public function apply($string, $config = null) |
|
18 | + { |
|
19 | + if (is_null($config)) { |
|
20 | + $config = 'default'; |
|
21 | + } |
|
22 | 22 | |
23 | - if (!isset($this->configs[$config])) { |
|
24 | - throw new InvalidConfigurationException('Typograph\'s config "'. $config .'" doesn\'t exist'); |
|
25 | - } |
|
23 | + if (!isset($this->configs[$config])) { |
|
24 | + throw new InvalidConfigurationException('Typograph\'s config "'. $config .'" doesn\'t exist'); |
|
25 | + } |
|
26 | 26 | |
27 | - return EMTypograph::fast_apply($string, $this->configs[$config]); |
|
28 | - } |
|
27 | + return EMTypograph::fast_apply($string, $this->configs[$config]); |
|
28 | + } |
|
29 | 29 | } |
30 | 30 | \ No newline at end of file |
@@ -21,7 +21,7 @@ |
||
21 | 21 | } |
22 | 22 | |
23 | 23 | if (!isset($this->configs[$config])) { |
24 | - throw new InvalidConfigurationException('Typograph\'s config "'. $config .'" doesn\'t exist'); |
|
24 | + throw new InvalidConfigurationException('Typograph\'s config "'.$config.'" doesn\'t exist'); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | return EMTypograph::fast_apply($string, $this->configs[$config]); |
@@ -112,7 +112,7 @@ |
||
112 | 112 | |
113 | 113 | foreach ($triad as $value) { |
114 | 114 | $value = (int) $value; |
115 | - if ($value > 255) { |
|
115 | + if ($value>255) { |
|
116 | 116 | $addTag = false; |
117 | 117 | break; |
118 | 118 | } |
@@ -53,7 +53,7 @@ |
||
53 | 53 | 'math_chars' => array( |
54 | 54 | 'description' => 'Математические знаки больше/меньше/плюс минус/неравно', |
55 | 55 | 'pattern' => array('/!=/', '/\<=/', '/([^=]|^)\>=/', '/~=/', '/\+-/'), |
56 | - 'replacement' => array('≠', '≤', '\1≥', '≅', '±' ) |
|
56 | + 'replacement' => array('≠', '≤', '\1≥', '≅', '±') |
|
57 | 57 | ), |
58 | 58 | /* |
59 | 59 | 'split_number_to_triads' => array( |
@@ -83,7 +83,7 @@ |
||
83 | 83 | 'arrows_symbols' => array( |
84 | 84 | 'description' => 'Замена стрелок вправо-влево на html коды', |
85 | 85 | 'pattern' => array('/(\s|\>|\ \;|^)\-\>($|\s|\ \;|\<)/', '/(\s|\>|\ \;|^|;)\<\-(\s|\ \;|$)/', '/→/u', '/←/u'), |
86 | - 'replacement' => array('\1→\2', '\1←\2', '→', '←' ) |
|
86 | + 'replacement' => array('\1→\2', '\1←\2', '→', '←') |
|
87 | 87 | ), |
88 | 88 | ); |
89 | 89 | } |
90 | 90 | \ No newline at end of file |
@@ -76,7 +76,7 @@ |
||
76 | 76 | protected function oaquote_extra() |
77 | 77 | { |
78 | 78 | $this->_text = $this->preg_replace_e( |
79 | - '/(<' .self::BASE64_PARAGRAPH_TAG . '>)([\040\t]+)?(\«\;)/e', |
|
79 | + '/(<'.self::BASE64_PARAGRAPH_TAG.'>)([\040\t]+)?(\«\;)/e', |
|
80 | 80 | '$m[1] . $this->tag($m[3], "span", array("class"=>"oa_oquote_nl"))', |
81 | 81 | $this->_text); |
82 | 82 | } |