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