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 +21 -61 7.13.16.28 View file →
@@ -20,11 +20,8 @@
20 20
21 21 protected $data;
22 22 protected $output_css;
23 23
24 - protected $has_compile_error = false;
25 - protected $compile_error;
26 -
27 24 protected $inline = array();
28 25 protected $responsive = array();
29 26
30 27 public $anchor_class = '.maxbutton'; // used for matching buttons in parse_part
@@ -47,9 +44,9 @@
47 44
48 45 function __construct()
49 46 {
50 47 //$root[] = array("a" => array("hover","active","responsive"));
51 - MB()->load_library('scss');
48 +
52 49 }
53 50
54 51 function loadDom($domObj)
55 52 {
@@ -63,16 +60,8 @@
63 60 if (count($children) > 0)
64 61 $struct[$root->tag] = $this->loadRecursive(array(), $children);
65 62
66 63
67 - // find the full and complete statement class defining maxbutton. This is needed for proper parsing on parse_part.
68 - $anchor_element = $root->find('.maxbutton', 0);
69 - if (! is_null($anchor_element))
70 - {
71 - $anchor_class = str_replace(' ', '.', $anchor_element->class);
72 - $this->anchor_class = $anchor_class;
73 - }
74 -
75 64 $this->struct = $struct;
76 65
77 66
78 67 }
@@ -82,9 +71,8 @@
82 71 foreach($children as $domChild)
83 72 {
84 73
85 74 $class = $domChild->class;
86 -
87 75 $class = str_replace(" ",".", $class); // combine seperate classes
88 76 $struct[$class]["tag"] = $domChild->tag;
89 77
90 78 $child_children = $domChild->children();
@@ -107,8 +95,9 @@
107 95 $struct = $this->struct;
108 96
109 97 $this->data = $data;
110 98
99 +
111 100 if (isset($data["settings"])) // room for settings in parser
112 101 {
113 102 $settings = $data["settings"];
114 103 $this->important = (isset($settings["important"])) ? $settings["important"] : false;
@@ -146,22 +135,21 @@
146 135 {
147 136 $this->data = '';
148 137 $this->output_css = '';
149 138 $this->inline = array();
139 + //$this->struct = array();
150 140 $this->responsive = array();
141 +
151 142 }
152 143
153 - public function compile($css)
144 + protected function compile($css)
154 145 {
155 146 $scss = new \Leafo\ScssPhp\Compiler();
156 147 $scss->setImportPaths(MB()->get_plugin_path() . "assets/scss");
157 148
158 149 $minify = get_option("maxbuttons_minify", 1);
159 -
160 150 if ($minify == 1)
161 - {
162 - $scss->setFormatter('\Leafo\ScssPhp\Formatter\Crunched');
163 - }
151 + $scss->setFormatter('\Leafo\ScssPhp\Formatter\Compressed');
164 152
165 153 $compile = " @import '_mixins.scss'; " . $css;
166 154 //maxUtils::addTime("CSSParser: Compile start ");
167 155
@@ -167,28 +155,18 @@
167 155
168 156 try
169 157 {
170 158 $css = $scss->compile($compile);
171 - } catch (\Exception $e) {
172 - $this->has_compile_error = true;
173 - $this->compile_error = $e;
159 + } catch (Exception $e) {
160 +
174 161 $css = $this->output_css;
175 162 }
176 163
177 164 //maxUtils::addTime("CSSParser: Compile end ");
165 +
178 166 return $css;
179 167 }
180 168
181 - function get_compile_errors()
182 - {
183 - if ($this->has_compile_error)
184 - {
185 - return $this->compile_error;
186 - }
187 - return false;
188 - }
189 -
190 - /** Element is the current element that being parsed. El_add is the parent element that should be put before the subpart */
191 169 function parse_part($element, $el_data, $el_add = '')
192 170 {
193 171 maxUtils::addTime("CSSParser: Parse $element ");
194 172
@@ -264,9 +242,8 @@
264 242 $this->parse_part($child_id, $child_data, $el_add);
265 243 }
266 244 }
267 245
268 -
269 246 }
270 247
271 248 function parse_cssline($values, $cssTag, $cssVal, $css_end = ';')
272 249 {
@@ -455,9 +432,9 @@
455 432 }
456 433
457 434 function doMixins($values)
458 435 {
459 - $mixins = array("gradient", "box-shadow", "text-shadow", "keyframes");
436 + $mixins = array("gradient", "box-shadow", "text-shadow");
460 437
461 438 foreach($mixins as $mixin)
462 439 {
463 440
@@ -476,8 +453,9 @@
476 453 switch($mixin)
477 454 {
478 455 case "gradient":
479 456 $values = $this->mixin_gradient($mixin_array, $values);
457 +
480 458 break;
481 459 case "box-shadow":
482 460 $values = $this->mixin_boxshadow($mixin_array, $values);
483 461 break;
@@ -483,11 +461,8 @@
483 461 break;
484 462 case "text-shadow":
485 463 $values = $this->mixin_textshadow($mixin_array, $values);
486 464 break;
487 - case 'keyframes':
488 - $values = $this->mixin_keyframes($mixin_array, $values);
489 - break;
490 465 }
491 466 }
492 467
493 468
@@ -494,23 +469,8 @@
494 469 }
495 470 return $values;
496 471 }
497 472
498 - /** Parse the keyframes. Not a real mixin */
499 - function mixin_keyframes($results, $values)
500 - {
501 - $keyframes_name = isset($results['keyframes-name']) ? $results['keyframes-name'] : false;
502 - $keyframes = isset($results['keyframes']) ? $results['keyframes'] : false;
503 -
504 - $key_output = ' @keyframes ' . $keyframes_name . ' { '.
505 - $keyframes . '}';
506 -
507 - $this->output_css = $key_output . $this->output_css;
508 -
509 - $values = array_diff_key($values, $results);
510 - return $values;
511 - }
512 -
513 473 function mixin_gradient($results, $values)
514 474 {
515 475
516 476 $start = isset($results["gradient-start-color"]) ? $results["gradient-start-color"] : '';
@@ -547,23 +507,18 @@
547 507 $width = isset($results["box-shadow-width"]) ? $results["box-shadow-width"] : 0;
548 508 $left = isset($results["box-shadow-offset-left"]) ? $results["box-shadow-offset-left"] : 0;
549 509 $top = isset($results["box-shadow-offset-top"]) ? $results["box-shadow-offset-top"] : 0;
550 510 $spread = isset($results['box-shadow-spread']) ? $results['box-shadow-spread'] : 0;
551 - $color = isset($results["box-shadow-color"]) ? $results["box-shadow-color"] : "rgba(0,0,0,0)";
511 + $color = isset($results["box-shadow-color"]) ? $results["box-shadow-color"] : '';
552 512
553 513 $important = ($this->is_important()) ? "!important" : "";
554 514
555 - $values = array_diff_key($values, $results); // always remove these fields from CSS since they are not valid.
556 -
557 - if ($width == 0 && $left == 0 && $top == 0 && $spread == 0)
558 - {
559 - $values['box-shadow'] = 'none'; // if no box-shadow, prevent it in total
515 + if ($width == 0 && $left == 0 && $top == 0)
560 516 return $values;
561 - }
562 517
563 518 $values = $this->add_include($values, "box-shadow($left, $top, $width, $color,$spread, false, $important) ");
519 + $values = array_diff_key($values, $results);
564 520
565 -
566 521 return $values;
567 522 }
568 523
569 524 function mixin_textshadow($results, $values)
@@ -570,9 +525,9 @@
570 525 {
571 526 $width = isset($results["text-shadow-width"]) ? $results["text-shadow-width"] : 0;
572 527 $left = isset($results["text-shadow-left"]) ? $results["text-shadow-left"] : 0;
573 528 $top = isset($results["text-shadow-top"]) ? $results["text-shadow-top"] : 0;
574 - $color = isset($results["text-shadow-color"]) ? $results["text-shadow-color"] : rgba(0,0,0,0);
529 + $color = isset($results["text-shadow-color"]) ? $results["text-shadow-color"] : '';
575 530 $important = ($this->is_important()) ? "!important" : "";
576 531
577 532 if ($width == 0 && $left == 0 && $top == 0)
578 533 {
@@ -580,8 +535,9 @@
580 535 return $values;
581 536 }
582 537
583 538 $values = $this->add_include($values, "text-shadow ($left,$top,$width,$color $important)");
539 +
584 540 $values = array_diff_key($values, $results);
585 541
586 542 return $values;
587 543 }
@@ -600,9 +556,8 @@
600 556 $domObj = $domObj->load($domObj->save());
601 557
602 558 $inline = $this->inline;
603 559
604 -
605 560 // ISSUE #43 Sometimes this breaks
606 561 if (! isset($inline[$pseudo]))
607 562 return $domObj;
608 563
@@ -636,8 +591,13 @@
636 591 return $domObj;
637 592
638 593 }
639 594
595 + function output()
596 + {
597 +
598 +
599 + }
640 600
641 601 }
642 602
643 603 class compileException extends Exception {