PluginProbe
MaxButtons – Create buttons / 6.28
MaxButtons – Create buttons v6.28
6.23 6.24 6.25 6.26 6.26.1 6.27 6.28 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.1.1 7.1.2 7.1.3 7.10 7.11 7.13 7.13.1 7.13.2 7.13.3 All 100 releases
← All changes | classes/maxCSSParser.php +277 -260 6.236.28 View file →
@@ -1,14 +1,14 @@
1 1 <?php
2 2 namespace MaxButtons;
3 3 defined('ABSPATH') or die('No direct access permitted');
4 4 /* Class to Parse CSS. Load as array with diffent pseudo-types,
5 - ability to add nested and new root blocks
5 + ability to add nested and new root blocks
6 6 parses via scss
7 7 ability to use complicated css stuff via scss mixins parsing like gradient
8 - auto-discovery for -unit field types to set units (like px, or %)
8 + auto-discovery for -unit field types to set units (like px, or %)
9 9 auto-discovery of fields via domobj.
10 -
10 +
11 11 */
12 12
13 13 use \Exception as Exception;
14 14
@@ -13,247 +13,262 @@
13 13 use \Exception as Exception;
14 14
15 15 class maxCSSParser
16 16 {
17 - protected $struct = array();
17 + protected $struct = array();
18 18 protected $domObj = '';
19 - protected $pseudo = array("hover","active","responsive");
20 -
21 - protected $data;
19 + protected $pseudo = array("hover","active","responsive");
20 +
21 + protected $data;
22 22 protected $output_css;
23 -
23 +
24 24 protected $inline = array();
25 25 protected $responsive = array();
26 -
27 - public $anchor_class = '.maxbutton'; // used for matching buttons in parse_part
28 -
26 +
27 + public $anchor_class = '.maxbutton'; // used for matching buttons in parse_part
28 +
29 29 // settings
30 30 protected $elements_ignore_zero = array(
31 31 'text-shadow-left',
32 - 'text_shadow-top',
32 + 'text_shadow-top',
33 33 'text-shadow-width',
34 34 'box-shadow-offset-left',
35 - 'box-shadow-offset-top',
35 + 'box-shadow-offset-top',
36 36 'box-shadow-width',
37 - 'box-shadow-spread',
38 - ); // items to ignore if value is zero, otherwise they become unremovable ( where 0 is still something on display)
39 -
37 + 'box-shadow-spread',
38 + ); // items to ignore if value is zero, otherwise they become unremovable ( where 0 is still something on display)
39 +
40 40 protected $important = false;
41 -
41 +
42 42 // log possible problems and incidents for debugging;
43 43 protected $parse_log = array();
44 -
44 +
45 45 function __construct()
46 46 {
47 - //$root[] = array("a" => array("hover","active","responsive"));
47 + //$root[] = array("a" => array("hover","active","responsive"));
48 48
49 49 }
50 -
50 +
51 51 function loadDom($domObj)
52 - {
52 + {
53 53 $this->domObj = $domObj;
54 54
55 55 $root = $domObj->find(0,0);
56 - $struct[$root->tag] = array();
57 -
56 + $struct[$root->tag] = array();
57 +
58 58 $children = $root->children();
59 -
60 - if (count($children) > 0)
59 +
60 + if (count($children) > 0)
61 61 $struct[$root->tag] = $this->loadRecursive(array(), $children);
62 -
62 +
63 +
63 64 $this->struct = $struct;
64 65
65 66
66 67 }
67 -
68 +
68 69 function loadRecursive($struct, $children)
69 70 {
70 71 foreach($children as $domChild)
71 72 {
72 73
73 - $class = $domChild->class;
74 - $class = str_replace(" ",".", $class); // combine seperate classes
75 -
76 - $struct[$class]["tag"] = $domChild->tag;
77 -
78 - $child_children = $domChild->children();
74 + $class = $domChild->class;
75 + $class = str_replace(" ",".", $class); // combine seperate classes
76 + $struct[$class]["tag"] = $domChild->tag;
79 77
80 - if (count($child_children) > 0)
78 + $child_children = $domChild->children();
79 +
80 + if (count($child_children) > 0)
81 81 {
82 -
82 +
83 83 $struct[$class]["children"] = $this->loadRecursive(array(), $child_children);
84 84 }
85 85 }
86 -
86 +
87 87 return $struct;
88 88 }
89 -
90 -
89 +
90 +
91 91 function parse($data)
92 - {
93 - $this->clear();
94 -
95 - $struct = $this->struct;
92 + {
93 + $this->clear();
96 94
97 - $this->data = $data;
95 + $struct = $this->struct;
98 96
99 -
97 + $this->data = $data;
98 +
99 +
100 100 if (isset($data["settings"])) // room for settings in parser
101 101 {
102 102 $settings = $data["settings"];
103 - $this->important = (isset($settings["important"])) ? $settings["important"] : false;
104 -
105 - unset($this->data["settings"]);
103 + $this->important = (isset($settings["important"])) ? $settings["important"] : false;
104 +
105 + unset($this->data["settings"]);
106 106 }
107 107
108 - $elements = array_shift($struct); // first element is a 'stub' root.
108 + $elements = array_shift($struct); // first element is a 'stub' root.
109 109
110 110 if ( is_null($elements) )
111 - return;
111 + return;
112 112
113 +
113 114 foreach($elements as $el => $el_data)
114 115 {
115 116
116 - $this->parse_part($el,$el_data);
117 + $this->parse_part($el,$el_data);
117 118 }
118 119
119 120
120 121 $this->parse_responsive();
121 -
122 +
122 123 maxUtils::startTime('compile CSS');
123 124 $css = $this->compile($this->output_css);
125 +
124 126 maxUtils::endTime('compile CSS');
125 127
126 128
127 129 return $css;
128 -
130 +
129 131 }
130 -
131 - // reset output values.
132 - protected function clear()
132 +
133 + // reset output values.
134 + protected function clear()
133 135 {
134 - $this->data = '';
135 - $this->output_css = '';
136 + $this->data = '';
137 + $this->output_css = '';
136 138 $this->inline = array();
137 139 //$this->struct = array();
138 140 $this->responsive = array();
139 -
141 +
140 142 }
141 -
143 +
142 144 protected function compile($css)
143 145 {
144 146 $scss = new \Leafo\ScssPhp\Compiler();
145 147 $scss->setImportPaths(MB()->get_plugin_path() . "assets/scss");
146 -
147 - $minify = get_option("maxbuttons_minify", 1);
148 +
149 + $minify = get_option("maxbuttons_minify", 1);
148 150 if ($minify == 1)
149 151 $scss->setFormatter('\Leafo\ScssPhp\Formatter\Compressed');
150 -
152 +
151 153 $compile = " @import '_mixins.scss'; " . $css;
152 154 //maxUtils::addTime("CSSParser: Compile start ");
153 -
155 +
154 156 try
155 157 {
156 158 $css = $scss->compile($compile);
157 - } catch (Exception $e) {
158 -
159 - $css = $this->output_css;
160 - }
159 + } catch (Exception $e) {
161 160
161 + $css = $this->output_css;
162 + }
163 +
162 164 //maxUtils::addTime("CSSParser: Compile end ");
163 165
164 166 return $css;
165 167 }
166 -
168 +
167 169 function parse_part($element, $el_data, $el_add = '')
168 170 {
169 171 maxUtils::addTime("CSSParser: Parse $element ");
170 -
171 - $tag = $el_data["tag"];
172 +
173 +
174 + $tag = $el_data["tag"];
172 175 $element_data = $this->findData($this->data, $element);
173 -
174 - // not using scss selectors here since there is trouble w/ the :pseudo selector, which should be put on the maxbutton / a tag.
176 +
177 + // not using scss selectors here since there is trouble w/ the :pseudo selector, which should be put on the maxbutton / a tag.
175 178 if ($element != '')
176 179 { $el_add .= " ." . $element;
177 -
180 +
178 181 }
179 -
180 - if (isset($element_data["responsive"]))
182 +
183 + if (isset($element_data["responsive"]))
181 184 {
182 185 $responsive = $element_data["responsive"]; // doing that at the end
183 - unset($element_data["responsive"]);
186 + unset($element_data["responsive"]);
184 187
185 188 $this->responsive[$el_add] = $responsive;
186 189 }
187 -
190 +
188 191 foreach($element_data as $pseudo => $values)
189 192 {
190 -
191 - if ($pseudo != 'normal')
193 +
194 + if ($pseudo != 'normal')
192 195 {
193 - // select the maxbutton case, ending with either space or next class -dot.
196 + // select the maxbutton case, ending with either space or next class -dot.
194 197 // Anchor class in default situation should be .maxbutton
195 - $anchor_class = $this->anchor_class;
196 -
197 - $ps_selector = preg_replace('/' . $anchor_class . '$|' . $anchor_class . '([.| ])/i',"$anchor_class:$pseudo\$1",$el_add);
198 - $this->output_css .= " $ps_selector { ";
198 + $anchor_class = $this->anchor_class;
199 +
200 + $count = 0;
201 +
202 + /* If PS Selector replacement doesn't match anchor class selector this probably means the parse is done in a higher level
203 + e.g. container level, so no proper will be set. In case 0 count replacement, just put it on current */
204 + $ps_selector = preg_replace('/' . $anchor_class . '$|' . $anchor_class . '([.| ])/i',"$anchor_class:$pseudo\$1",$el_add, -1, $count);
205 +
206 +
207 + if ($count === 0)
208 + {
209 + $ps_selector = $el_add . ":" . $pseudo;
210 + }
211 +
212 +
213 + $this->output_css .= " $ps_selector { ";
199 214 }
200 215 else {
201 216 $this->output_css .= " $el_add { ";
202 217 }
203 -
218 +
204 219 $values = $this->doMixins($values);
205 220
206 221 foreach($values as $cssTag => $cssVal)
207 222 {
208 -
223 +
209 224 $statement = $this->parse_cssline($values, $cssTag,$cssVal); ///"$cssTag $css_sep $cssVal$unit$css_end ";
210 225
211 226 if ($statement)
212 227 {
213 228 $this->output_css .= $statement ;
214 -
229 +
215 230 if (! isset($this->inline[$pseudo][$element])) $this->inline[$pseudo][$element] = '';
216 231 $this->inline[$pseudo][$element] .= $statement;
217 - }
232 + }
218 233 }
219 234
220 - $this->output_css .= " } ";
235 + $this->output_css .= " } ";
221 236 }
222 - if (isset($el_data["children"]))
237 + if (isset($el_data["children"]))
223 238 {
224 239 foreach($el_data["children"] as $child_id => $child_data)
225 240 {
226 -
241 +
227 242 $this->parse_part($child_id, $child_data, $el_add);
228 243 }
229 244 }
230 245
231 246 }
232 -
247 +
233 248 function parse_cssline($values, $cssTag, $cssVal, $css_end = ';')
234 249 {
235 250
236 251 // unit check - two ways; either unitable items is first or unit declaration.
237 - if (isset($values[$cssTag . "_unit"]))
252 + if (isset($values[$cssTag . "_unit"]))
238 253 {
239 - $unit = $values[$cssTag . "_unit"];
254 + $unit = $values[$cssTag . "_unit"];
240 255 }
241 256 elseif(strpos($cssTag, "_unit") !== false)
242 257 {
243 - return false; // no print, should be found under first def.
258 + return false; // no print, should be found under first def.
244 259 }
245 260 else $unit = '';
246 -
247 261
248 - $important = ($this->is_important()) ? " !important" : "";
249 - $important = ($cssTag == '@include') ? "" : $important; // mixin's problem, no checking here.
250 -
262 +
263 + $important = ($this->is_important()) ? " !important" : "";
264 + $important = ($cssTag == '@include') ? "" : $important; // mixin's problem, no checking here.
265 +
251 266 $css_sep = ($cssTag == '@include') ? $css_sep = '' : ':';
252 -
267 +
253 268 if ($cssVal == 0 && in_array($cssTag, $this->elements_ignore_zero))
254 - return false;
255 -
269 + return false;
270 +
256 271 if($cssVal !== '' && $cssTag !== '')
257 272 {
258 273 $statement = "$cssTag $css_sep $cssVal$unit$important$css_end ";
259 274 return $statement;
@@ -258,119 +273,119 @@
258 273 $statement = "$cssTag $css_sep $cssVal$unit$important$css_end ";
259 274 return $statement;
260 275 }
261 276 return false;
262 -
277 +
263 278 }
264 -
279 +
265 280 function parse_responsive()
266 281 {
267 282
268 - $responsive = $this->responsive;
269 - if (! is_array($responsive) || count($responsive) == 0)
270 - return;
283 + $responsive = $this->responsive;
284 + if (! is_array($responsive) || count($responsive) == 0)
285 + return;
271 286
272 287 $media_queries = maxUtils::get_media_query(2); // query names
273 -
274 - $output = '';
275 -
276 - $query_array = array();
277 288
289 + $output = '';
278 290
291 + $query_array = array();
292 +
293 +
279 294 foreach($responsive as $element => $queries)
280 295 {
281 296 foreach($queries as $query => $qdata)
282 297 foreach($qdata as $index => $data)
283 298 {{
284 - $query_array[$query][$index][$element] = $data;
285 -
299 + $query_array[$query][$index][$element] = $data;
300 +
286 301 }}
287 302 }
288 -
289 303
290 -
304 +
305 +
291 306 foreach($query_array as $query => $vdata):
292 307
293 - if ($query == 'custom')
308 + if ($query == 'custom')
294 309 {
295 310
296 - // first discover the custom size properties.
311 + // first discover the custom size properties.
297 312 foreach($vdata as $index => $data):
298 313 foreach($data as $element => $values):
299 314
300 - if (isset($values["custom_maxwidth"]) || isset($values["custom_minwidth"]) )
315 + if (isset($values["custom_maxwidth"]) || isset($values["custom_minwidth"]) )
301 316 {
302 -
317 +
303 318 $minwidth = (isset($values["custom_minwidth"])) ? intval($values["custom_minwidth"]) : -1;
304 - $maxwidth = (isset($values["custom_maxwidth"])) ? intval($values["custom_maxwidth"]) : -1;
305 -
306 -
307 - unset($vdata[$index][$element]["custom_minwidth"]);
319 + $maxwidth = (isset($values["custom_maxwidth"])) ? intval($values["custom_maxwidth"]) : -1;
320 +
321 +
322 + unset($vdata[$index][$element]["custom_minwidth"]);
308 323 unset($vdata[$index][$element]["custom_maxwidth"]);
309 -
310 -
311 - // make it always an integer
312 - if ($minwidth == '') $minwidth = 0;
313 - if ($maxwidth == '') $maxwidth = 0;
314 -
315 - // if minwidth is not set and maxwidth zero or not set - ignore since it would result in an empty media line.
316 - //if ($minwidth <= 0 && $maxwidth <= 0)
324 +
325 +
326 + // make it always an integer
327 + if ($minwidth == '') $minwidth = 0;
328 + if ($maxwidth == '') $maxwidth = 0;
329 +
330 + // if minwidth is not set and maxwidth zero or not set - ignore since it would result in an empty media line.
331 + //if ($minwidth <= 0 && $maxwidth <= 0)
317 332 //{
318 333 //continue;
319 334 //}
320 -
321 - if ($minwidth > 0 && $maxwidth > 0)
322 - $qdef = "only screen and (min-width: $minwidth" . "px) and (max-width: $maxwidth" . "px)";
323 - if ($minwidth >= 0 && $maxwidth <= 0)
324 - $qdef = "only screen and (min-width: $minwidth" . "px) ";
325 - if ($minwidth <= 0 && $maxwidth > 0)
326 - $qdef = "only screen and (max-width: $maxwidth" . "px) ";
327 -
335 +
336 + if ($minwidth > 0 && $maxwidth > 0)
337 + $qdef = "only screen and (min-width: $minwidth" . "px) and (max-width: $maxwidth" . "px)";
338 + if ($minwidth >= 0 && $maxwidth <= 0)
339 + $qdef = "only screen and (min-width: $minwidth" . "px) ";
340 + if ($minwidth <= 0 && $maxwidth > 0)
341 + $qdef = "only screen and (max-width: $maxwidth" . "px) ";
342 +
328 343 //break;
329 344
330 - }
331 - endforeach; //foreach data
332 -
333 - // The problem is that every 'custom' query needs to run with a different qdef unlike other queries.
334 -
345 + }
346 + endforeach; //foreach data
347 +
348 + // The problem is that every 'custom' query needs to run with a different qdef unlike other queries.
349 +
335 350 $qdata = array($vdata[$index]);
336 -
337 - $output = $this->parse_responsive_definition($output, $qdef, $qdata);
338 - endforeach; // foreach vdata
351 +
352 + $output = $this->parse_responsive_definition($output, $qdef, $qdata);
353 + endforeach; // foreach vdata
339 354 }
340 355 else
341 356 {
342 -
343 - $qdef = $media_queries[$query];
357 +
358 + $qdef = $media_queries[$query];
344 359 $output = $this->parse_responsive_definition($output, $qdef, $vdata);
345 360 }
346 361
347 362 endforeach;
348 -
349 -
363 +
364 +
350 365 $this->output_css .= $output;
351 366 }
352 -
367 +
353 368 protected function parse_responsive_definition($output, $qdef, $vdata)
354 369 {
355 -
370 +
356 371 if (! isset($qdef) || $qdef == '') {
357 -
358 - return; // no definition.
372 +
373 + return; // no definition.
359 374 }
360 375
361 -
362 - $output .= "@media ". $qdef . " { ";
363 376
364 -
377 + $output .= "@media ". $qdef . " { ";
378 +
379 +
365 380 foreach($vdata as $index => $data)
366 381 {
367 -
382 +
368 383 foreach($data as $element => $values) {
369 384 //foreach($vdat as $index => $values):
370 - $output .= $element . " { ";
385 + $output .= $element . " { ";
371 386 $css_end = ';';
372 -
387 +
373 388 // same as parse part, maybe merge in future
374 389 foreach($values as $cssTag => $cssVal)
375 390 {
376 391 // unit check - two ways; either unitable items is first or unit declaration.
@@ -376,60 +391,62 @@
376 391 // unit check - two ways; either unitable items is first or unit declaration.
377 392 $statement = $this->parse_cssline($values, $cssTag,$cssVal);
378 393 if($statement)
379 394 $output .= $statement;
380 -
395 +
381 396 }
382 397
383 - $output .= " } ";
398 + $output .= " } ";
384 399 // endforeach;
385 400 }
386 401
387 -
402 +
388 403 }
389 - $output .= " } ";
390 -
391 - //endforeach;
392 -
404 + $output .= " } ";
405 +
406 + //endforeach;
407 +
393 408 return $output;
394 409 }
395 -
410 +
396 411 private function is_important()
397 412 {
398 413
399 414 if ($this->important == 1)
400 415 return true;
401 - else
416 + else
402 417 return false;
403 418 }
404 -
419 +
405 420 function findData($data, $el)
406 421 {
407 - $classes = explode(".", $el);
422 + $classes = explode(".", $el);
408 423
409 - foreach($data as $part => $values)
424 + foreach($data as $part => $values)
410 425 {
411 426 if (in_array($part, $classes))
427 + {
412 428 return $data[$part];
429 + }
413 430 }
414 431 return array();
415 432 }
416 -
433 +
417 434 function doMixins($values)
418 435 {
419 436 $mixins = array("gradient", "box-shadow", "text-shadow");
420 -
421 - foreach($mixins as $mixin)
437 +
438 + foreach($mixins as $mixin)
422 439 {
423 440
424 441 $results = preg_grep("/^$mixin/i",array_keys($values) );
425 - if (count($results) === 0)
426 - continue; // no mixins.
427 -
442 + if (count($results) === 0)
443 + continue; // no mixins.
444 +
428 445 $mixin_array = array();
429 446 foreach($results as $result)
430 447 {
431 - $mixin_array[$result] = $values[$result];
448 + $mixin_array[$result] = $values[$result];
432 449 }
433 450
434 451 if (count($mixin_array) > 0)
435 452 {
@@ -434,156 +451,156 @@
434 451 if (count($mixin_array) > 0)
435 452 {
436 453 switch($mixin)
437 454 {
438 - case "gradient":
455 + case "gradient":
439 456 $values = $this->mixin_gradient($mixin_array, $values);
440 -
457 +
441 458 break;
442 - case "box-shadow":
459 + case "box-shadow":
443 460 $values = $this->mixin_boxshadow($mixin_array, $values);
444 - break;
445 - case "text-shadow":
461 + break;
462 + case "text-shadow":
446 463 $values = $this->mixin_textshadow($mixin_array, $values);
447 464 break;
448 465 }
449 466 }
450 467
451 -
452 - }
468 +
469 + }
453 470 return $values;
454 471 }
455 -
472 +
456 473 function mixin_gradient($results, $values)
457 474 {
458 475
459 476 $start = isset($results["gradient-start-color"]) ? $results["gradient-start-color"] : '';
460 - $end = isset( $results["gradient-end-color"] ) ? $results["gradient-end-color"] : '';
461 - $start_opacity = isset( $results["gradient-start-opacity"] ) ? $results["gradient-start-opacity"] : '';
462 - $end_opacity = isset( $results["gradient-end-opacity"] ) ? $results["gradient-end-opacity"] : '';
463 - $stop = (isset( $results["gradient-stop"]) && $results["gradient-stop"] != '') ? $results["gradient-stop"] . "%" : '45%';
477 + $end = isset( $results["gradient-end-color"] ) ? $results["gradient-end-color"] : '';
478 + $start_opacity = isset( $results["gradient-start-opacity"] ) ? $results["gradient-start-opacity"] : '';
479 + $end_opacity = isset( $results["gradient-end-opacity"] ) ? $results["gradient-end-opacity"] : '';
480 + $stop = (isset( $results["gradient-stop"]) && $results["gradient-stop"] != '') ? $results["gradient-stop"] . "%" : '45%';
464 481 // default to use ( old situation )
465 482 $use_gradient = (isset($results['gradient-use-gradient']) && $results['gradient-use-gradient'] != '') ? $results['gradient-use-gradient'] : 1;
466 -
483 +
467 484 $start = maxUtils::hex2rgba($start, $start_opacity);
468 - $end = maxUtils::hex2rgba($end, $end_opacity);
469 -
485 + $end = maxUtils::hex2rgba($end, $end_opacity);
486 +
470 487 $important = ($this->is_important()) ? "!important" : "";
471 - //$values = $this->add_include($values, "linear-gradient($start,$end,$stop,$important)");
488 + //$values = $this->add_include($values, "linear-gradient($start,$end,$stop,$important)");
472 489
473 490 if ($use_gradient == 1)
474 491 {
475 - $values = $this->add_include($values, "linear-gradient($start,$end,$stop,$important)");
492 + $values = $this->add_include($values, "linear-gradient($start,$end,$stop,$important)");
476 493 }
477 494 else {
478 - $values['background-color'] = $start;
495 + $values['background-color'] = $start;
479 496 }
480 497
481 - // remove the non-css keys from the value array ( field names )
498 + // remove the non-css keys from the value array ( field names )
482 499 $values = array_diff_key($values, $results);
483 500
484 501 return $values;
485 -
502 +
486 503 }
487 -
504 +
488 505 function mixin_boxshadow($results, $values)
489 506 {
490 - $width = $results["box-shadow-width"];
491 - $left = $results["box-shadow-offset-left"];
492 - $top = $results["box-shadow-offset-top"];
493 - $spread = isset($results['box-shadow-spread']) ? $results['box-shadow-spread'] : 0;
494 - $color = isset($results["box-shadow-color"]) ? $results["box-shadow-color"] : '';
495 -
496 - $important = ($this->is_important()) ? "!important" : "";
497 -
498 - if ($width == 0 && $left == 0 && $top == 0)
499 - return $values;
500 -
501 - $values = $this->add_include($values, "box-shadow($left, $top, $width, $color,$spread, false, $important) ");
507 + $width = isset($results["box-shadow-width"]) ? $results["box-shadow-width"] : 0;
508 + $left = isset($results["box-shadow-offset-left"]) ? $results["box-shadow-offset-left"] : 0;
509 + $top = isset($results["box-shadow-offset-top"]) ? $results["box-shadow-offset-top"] : 0;
510 + $spread = isset($results['box-shadow-spread']) ? $results['box-shadow-spread'] : 0;
511 + $color = isset($results["box-shadow-color"]) ? $results["box-shadow-color"] : '';
512 +
513 + $important = ($this->is_important()) ? "!important" : "";
514 +
515 + if ($width == 0 && $left == 0 && $top == 0)
516 + return $values;
517 +
518 + $values = $this->add_include($values, "box-shadow($left, $top, $width, $color,$spread, false, $important) ");
502 519 $values = array_diff_key($values, $results);
503 520
504 - return $values;
521 + return $values;
505 522 }
506 -
523 +
507 524 function mixin_textshadow($results, $values)
508 525 {
509 - $width = isset($results["text-shadow-width"]) ? $results["text-shadow-width"] : 0;
510 - $left = isset($results["text-shadow-left"]) ? $results["text-shadow-left"] : 0;
511 - $top = isset($results["text-shadow-top"]) ? $results["text-shadow-top"] : 0;
512 - $color = isset($results["text-shadow-color"]) ? $results["text-shadow-color"] : '';
513 - $important = ($this->is_important()) ? "!important" : "";
514 -
515 - if ($width == 0 && $left == 0 && $top == 0)
526 + $width = isset($results["text-shadow-width"]) ? $results["text-shadow-width"] : 0;
527 + $left = isset($results["text-shadow-left"]) ? $results["text-shadow-left"] : 0;
528 + $top = isset($results["text-shadow-top"]) ? $results["text-shadow-top"] : 0;
529 + $color = isset($results["text-shadow-color"]) ? $results["text-shadow-color"] : '';
530 + $important = ($this->is_important()) ? "!important" : "";
531 +
532 + if ($width == 0 && $left == 0 && $top == 0)
516 533 {
517 534 $values = array_diff_key($values, $results); // remove them from the values, prevent incorrect output.
518 - return $values;
535 + return $values;
519 536 }
520 -
521 - $values = $this->add_include($values, "text-shadow ($left,$top,$width,$color $important)");
522 -
537 +
538 + $values = $this->add_include($values, "text-shadow ($left,$top,$width,$color $important)");
539 +
523 540 $values = array_diff_key($values, $results);
524 -
541 +
525 542 return $values;
526 543 }
527 -
544 +
528 545 private function add_include($values, $include)
529 546 {
530 - if (isset($values["@include"]))
531 - $values["@include"] .= "; @include " . $include;
547 + if (isset($values["@include"]))
548 + $values["@include"] .= "; @include " . $include;
532 549 else
533 - $values["@include"] = $include;
534 - return $values;
550 + $values["@include"] = $include;
551 + return $values;
535 552 }
536 -
553 +
537 554 function outputInline($domObj, $pseudo = 'normal')
538 555 {
539 556 $domObj = $domObj->load($domObj->save());
540 -
557 +
541 558 $inline = $this->inline;
542 -
543 - // ISSUE #43 Sometimes this breaks
544 - if (! isset($inline[$pseudo]))
559 +
560 + // ISSUE #43 Sometimes this breaks
561 + if (! isset($inline[$pseudo]))
545 562 return $domObj;
546 563
547 564 $elements = array_keys($inline[$pseudo]);
548 565 if ($pseudo != 'normal') // gather all elements
549 566 $elements = array_merge($elements, array_keys($inline["normal"]));
550 -
567 +
551 568 foreach($elements as $element )
552 569 {
553 - $styles = isset($inline[$pseudo][$element]) ? $inline[$pseudo][$element] : '';
554 -
570 + $styles = isset($inline[$pseudo][$element]) ? $inline[$pseudo][$element] : '';
571 +
555 572 if ($pseudo != 'normal') // parse all possible missing styles from pseudo el.
556 - $normstyle = $this->compile($inline['normal'][$element]);
557 -
558 - $normstyle = '';
573 + $normstyle = $this->compile($inline['normal'][$element]);
574 +
575 + $normstyle = '';
559 576 if ($pseudo != 'normal') // parse all possible missing styles from pseudo el.
560 - $normstyle = $this->compile($inline['normal'][$element]);
561 -
577 + $normstyle = $this->compile($inline['normal'][$element]);
578 +
562 579 maxUtils::addTime("CSSParser: Parse inline done");
563 -
580 +
564 581 $styles = $normstyle . $this->compile($styles);
565 -
566 - $element = trim(str_replace("."," ", $element)); // molten css class, seperator.
567 -
582 +
583 + $element = trim(str_replace("."," ", $element)); // molten css class, seperator.
584 +
568 585 $el = $domObj->find('[class*="' . $element . '"]', 0);
569 - if (is_null($el)) echo "NULL";
586 +
570 587 $el->style = $styles;
571 -
588 +
572 589 }
573 -
590 +
574 591 return $domObj;
575 -
576 - }
577 -
578 - function output()
592 +
593 + }
594 +
595 + function output()
579 596 {
580 -
581 -
597 +
598 +
582 599 }
583 -
600 +
584 601 }
585 602
586 -class compileException extends Exception {
603 +class compileException extends Exception {
587 604 protected $code = -1;
588 605
589 606 }