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/button.php +109 -101 7.106.28 View file →
@@ -15,9 +15,8 @@
15 15 protected $name = '';
16 16 protected $status = '';
17 17 protected $description = '';
18 18 protected $cache = '';
19 - protected $updated = 0;
20 19
21 20 protected $button_loaded = false;
22 21
23 22 protected $data = array();
@@ -46,9 +45,9 @@
46 45 // the parser
47 46
48 47 // get all files from blocks map
49 48
50 - // get all blocks classes, do init on the blocks. Init should not load anything big.
49 + // get all blocks via apply filters, do init. Init should not load anything big.
51 50 $this->loadBlockClasses();
52 51
53 52 }
54 53
@@ -60,8 +59,9 @@
60 59
61 60 // set blocks to the 'block name' that survived.
62 61 maxUtils::addTime("Load Block classes");
63 62
63 + //$classes = apply_filters("mb_blockclassesload", $classes);
64 64 $class_array = maxBlocks::getBlockClasses();
65 65 $classes = array_map(maxUtils::namespaceit('maxUtils::array_namespace'), $class_array );
66 66
67 67 foreach($classes as $block => $class)
@@ -70,10 +70,8 @@
70 70
71 71 $this->blocks[] = $block;
72 72 if (is_admin())
73 73 {
74 - // used for getValue() operators in the Admin Section
75 -
76 74 maxBlocks::add($block); // block collection.
77 75 }
78 76 }
79 77
@@ -78,8 +76,10 @@
78 76 }
79 77
80 78
81 79 $this->clear(); // init
80 + do_action("mb\blockclasses", $class_array);
81 +
82 82 }
83 83
84 84 /** Simple function to retrieve loaded blocks - * Used by install class */
85 85 public function getBlocks()
@@ -111,16 +111,12 @@
111 111 } else {
112 112 $row = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . maxUtils::get_table_name() . " WHERE id = %d and status ='%s'", $id, $status), ARRAY_A);
113 113 }
114 114
115 - if (! is_array($row)) // no db row results in null / false
115 + if (count($row) == 0)
116 116 {
117 117 return false;
118 118 }
119 - elseif (count($row) == 0)
120 - {
121 - return false;
122 - }
123 119
124 120 /* Take the id from the query, otherwise ( when button shortcode called by name ) id might not be present properly' */
125 121 $button_id = $row["id"];
126 122 maxButtons::buttonLoad(array("button_id" => $button_id)); // central registration
@@ -140,9 +136,8 @@
140 136 $this->button_css = array();
141 137 $this->button_js = array();
142 138 $this->data = array('id' => 0);
143 139 $this->data = $this->save(array(),false);
144 - $this->updated = 0;
145 140
146 141 $this->cache = '';
147 142 $this->button_loaded = false;
148 143
@@ -149,9 +144,9 @@
149 144 foreach($this->blocks as $block)
150 145 {
151 146 $block->set($this->data); // reset blocks
152 147 }
153 - maxBlocks::setData($this->data);
148 +
154 149 }
155 150
156 151 function setupData($data)
157 152 {
@@ -181,17 +176,16 @@
181 176 $this->data["id"] = $this->id; // needed for certain blocks, to be button aware.
182 177 $this->data["document_id"] = $this->document_id; // bound to JS and others.
183 178 $this->name = $data["name"];
184 179 $this->status = $data["status"];
185 - $this->updated = isset($data['updated']) ? $data['updated'] : 0;
186 180 $this->description = $this->data["basic"]["description"];
187 181
182 + //do_action('mb-data-load', $this->data);
188 183 foreach($this->blocks as $block)
189 184 {
190 185 $block->set($this->data);
191 186 }
192 187
193 -
194 188 maxBlocks::setData($this->data);
195 189
196 190
197 191 return true;
@@ -203,46 +197,36 @@
203 197 return $this->data;
204 198
205 199 }
206 200
207 - public function getID()
201 + function getID()
208 202 {
209 203 return $this->id;
210 204 }
211 -
212 - public function getDocumentID()
205 + function getDocumentID()
213 206 {
214 207 return $this->document_id;
215 208 }
216 - public function getName()
209 + function getName()
217 210 {
218 211 return $this->name;
219 212 }
220 -
221 - public function getDescription()
213 + function getDescription()
222 214 {
223 215 return $this->description;
224 216 }
225 217
226 - public function getStatus()
218 + function getStatus()
227 219 {
228 220 return $this->status;
229 221 }
230 222
231 - public function getUpdated($forDisplay = true)
223 + function getParsedCSS()
232 224 {
233 - if ($forDisplay)
234 - return date_i18n( get_option( 'date_format' ), strtotime($this->updated) );
235 - else
236 - return strtotime($this->updated);
237 - }
238 -
239 - public function getParsedCSS()
240 - {
241 225 return $this->parsed_css;
242 226 }
243 227
244 - public function getCSSArray()
228 + function getCSSArray()
245 229 {
246 230
247 231 return $this->button_css;
248 232 }
@@ -275,8 +259,21 @@
275 259
276 260 }
277 261 }
278 262
263 +
264 + /* Tell all blocks to reload the data
265 +
266 + This function will tell all loaded blocks to reload it's data. This is needed when data is changed after the initial button load.
267 +
268 + */
269 + function reloadData()
270 + {
271 + exit('reload Data - do not use');
272 + //do_action('mb-data-load', $this->data);
273 +
274 + }
275 +
279 276 /* Parse CSS from the elements
280 277
281 278 @param string $mode [normal,preview,editor] - The view needed.
282 279 @param string $forceCompile Recompile the CSS in any case
@@ -305,14 +302,16 @@
305 302 foreach($this->blocks as $block)
306 303 {
307 304 $css = $block->parse_css($css, $mode);
308 305 }
306 + //$css = apply_filters('mb-css-blocks', $css, $mode);
309 307
310 308 /* Filter the raw CSS array before compile
311 309
312 - This filters passes an array with all CSS elements before compile time. This should be CSS elements that can be understood by the CSS parser.
310 + This filters passes an array with all CSS element before compile time. This should be CSS elements that can be understood by the CSS parser.
313 311 @since 4.20
314 312 @param $css CSS Array - split by element and pseudo (normal/hover)
313 +
315 314 */
316 315
317 316 $css = apply_filters('mb/button/rawcss', $css, $mode);
318 317
@@ -363,9 +362,8 @@
363 362 $name = $this->name;
364 363 // non-latin breaks CSS / ID's - so move to latin.
365 364 $name = maxUtils::translit($name);
366 365 $name = sanitize_title($name);
367 - $name = str_replace('%', '', $name);
368 366
369 367 $classes = array("maxbutton-" . $this->id,
370 368 "maxbutton");
371 369
@@ -372,8 +370,9 @@
372 370
373 371 if ($name != '')
374 372 $classes[] = "maxbutton-" . $name;
375 373
374 + $classes = apply_filters('mb-mainclasses', $classes);
376 375 $classes = implode(' ', $classes);
377 376
378 377 $domObj = new simple_html_dom();
379 378 $domObj->load('<a class="' . $classes . '"></a>');
@@ -397,24 +396,14 @@
397 396 {
398 397 foreach($this->blocks as $block)
399 398 {
400 399 $block->admin_fields();
401 - $block->display_fields();
400 +
402 401 }
403 402 //do_action('mb-admin-fields' );
404 403
405 404 }
406 405
407 - protected function post_parse_button($domObj, $mode)
408 - {
409 - foreach($this->blocks as $block)
410 - {
411 - $domObj = $block->post_parse_button($domObj, $mode);
412 - $domObj->load($domObj->save());
413 - }
414 -
415 - }
416 -
417 406 /* Display the button */
418 407 public function display($args = array() )
419 408 {
420 409 maxUtils::startTime('button-display-'. $this->id);
@@ -452,9 +441,9 @@
452 441 $compile = false;
453 442 break;
454 443 case "editor":
455 444 $preview = true;
456 - $compile = true;
445 + $compile = true;
457 446 // editor is both compile and preview.
458 447 break;
459 448 break;
460 449 case "normal":
@@ -464,10 +453,13 @@
464 453 }
465 454
466 455
467 456 // Apply filters for general data override
457 +
468 458 $this->data = apply_filters('mb/button/data_before_display', $this->data, $mode, array('preview' => $preview, 'compile' => $compile) ); // hooks
469 459
460 +
461 +
470 462 if ( $this->load_css == "element" || $args["preview_part"] != "full" || $args["compile"] == true) { // if css output is on element, for to compile - otherwise inline styles will not be loaded.
471 463 $compile = true;
472 464
473 465 }
@@ -480,20 +472,14 @@
480 472 {
481 473 $block->set($this->data);
482 474 }
483 475
484 - // create the button
485 476 $domObj = $this->parse_button($mode);
486 477
487 - // create CSS
488 478 maxUtils::startTime('button-parse-css-'. $this->id);
489 479 $this->parse_css($mode, $compile);
490 480 maxUtils::endTime('button-parse-css-'. $this->id);
491 481
492 - // operation after creating CSS model. Mainly adding extra classes
493 - $this->post_parse_button($domObj, $mode);
494 -
495 -
496 482 if (! $preview) // no js on previews
497 483 $this->parse_js($mode);
498 484
499 485 if ($preview) // mark it preview
@@ -520,9 +506,8 @@
520 506 }
521 507 elseif ($this->load_css == 'footer')
522 508 {
523 509 $css = $this->display_css(false, false);
524 -
525 510 do_action('mb-footer',$this->id, $css);
526 511
527 512 if (! $preview)
528 513 {
@@ -539,8 +524,9 @@
539 524 elseif ($this->load_css == 'element') // not possible to load both normal and hover to an element.
540 525 {
541 526 $domObj->find('a',0)->class .= ' normal';
542 527 $domObj = $this->cssParser->outputInline($domObj);
528 + //$this->get_element_css($domObj, 'normal');
543 529 }
544 530
545 531
546 532 $output .= $domObj->save();
@@ -567,9 +553,11 @@
567 553 foreach($this->blocks as $block)
568 554 {
569 555 $map = $block->map_fields($map);
570 556 }
557 + //$map = apply_filters("mb-field-map",$map);
571 558
559 +
572 560 echo "<script language='javascript'>";
573 561 echo "var buttonFieldMap = '" . json_encode($map) . "';" ;
574 562 echo "</script>";
575 563
@@ -670,8 +658,9 @@
670 658 */
671 659 public function save($post, $savedb = true)
672 660 {
673 661 $post = stripslashes_deep($post); // don't multiply slashes please.
662 + //$data = apply_filters('mb-save-fields',$this->data, $post);
674 663 $data = $this->data;
675 664
676 665 foreach($this->blocks as $block)
677 666 {
@@ -758,9 +747,9 @@
758 747 global $wpdb;
759 748
760 749 if ($this->id > 0)
761 750 {
762 - $fields = array("cache" => $css, 'updated' => $this->updated); // try not to update timestamp on recache.
751 + $fields = array("cache" => $css);
763 752 $where = array('id' => $this->id);
764 753 $where_format = array('%d');
765 754 $wpdb->update(maxUtils::get_table_name(), $fields, $where, null, $where_format);
766 755 $return = true;
@@ -772,9 +761,9 @@
772 761 // Resets all of the button caches.
773 762 public function reset_cache()
774 763 {
775 764 global $wpdb;
776 - $fields = array("cache" => null, 'updated' => 'updated');
765 + $fields = array("cache" => null);
777 766 $where = array(1 => 1);
778 767 //$where_format = array('%d');
779 768 $sql = "UPDATE " . maxUtils::get_table_name() . " SET cache = NULL ";
780 769 $wpdb->query($sql);
@@ -789,32 +778,32 @@
789 778 @param $atts array Shortcode Atts
790 779 @return string HTML presentation of button
791 780
792 781 */
793 - public function shortcode($button_atts)
782 + public function shortcode($atts)
794 783 {
795 - $atts = shortcode_atts(array(
796 - 'id' => null,
797 - 'name' => null,
798 - 'text' => null,
799 - 'url' => null,
800 - 'linktitle' => null,
801 - 'window' => null,
802 - 'nofollow' => null,
803 - 'nocache' => null,
804 - 'extraclass' => null,
784 + extract(shortcode_atts(array(
785 + 'id' => '',
786 + 'name' => '',
787 + 'text' => '',
788 + 'url' => '',
789 + 'linktitle' => '',
790 + 'window' => '',
791 + 'nofollow' => '',
792 + 'nocache' => false,
805 793 'style' => 'footer',
794 + 'exclude' => ''
806 795
807 - ), $button_atts, 'maxbutton');
796 + ), $atts));
808 797
809 - $button_id = $atts['id'];
810 - $button_name = $atts['name'];
798 + $button_id = $id;
799 + $button_name = $name;
811 800
812 - if (! is_null($button_id) && $button_id > 0)
801 + if ($button_id > 0)
813 802 $result = $this->set($button_id);
814 - elseif (! is_null($button_name))
803 + elseif ($button_name != '')
815 804 $result = $this->set(0, $button_name);
816 - else return; // no button id or name given
805 + else return; // no button id / name
817 806
818 807 /* Shortcode cache control
819 808
820 809 If true the button CSS will be recompiled again. If false the plugin will check the cache for CSS declarations. Set to true if anything is interrupting the caching mechanism. Please note, recompiling causes some load times!
@@ -820,60 +809,67 @@
820 809 If true the button CSS will be recompiled again. If false the plugin will check the cache for CSS declarations. Set to true if anything is interrupting the caching mechanism. Please note, recompiling causes some load times!
821 810
822 811 @param boolean $nocache True / False
823 812 */
824 - $compile = apply_filters("mb/shortcode/nocache", $atts['nocache'] );
813 + $compile = apply_filters("mb/shortcode/nocache", $nocache);
825 814
826 815 if (! $result)
827 - return; // button doesn't exist
816 + return; // shortcode doesn't exist
828 817
829 818 // If we're not in the admin and the button is in the trash, just return nothing
830 - if (!is_admin() && $this->status == 'trash') {
831 - return;
819 + if (!is_admin() && $this->status == 'trash') {
820 + return '';
821 + }
822 + // Check to handle excludes
823 + if ("{$exclude}" != '') {
824 + global $post;
825 +
826 + // Don't render the button if excluded from the current post/page
827 + $exclude = explode(',', "{$exclude}");
828 + if (in_array($post->ID, $exclude)) {
829 + return '';
830 + }
832 831 }
833 832
834 833 // Override shortcode options comparing to default button data.
835 - //$overrides = false;
836 -
837 - if (! is_null($atts['text']) && $atts['text'] !== '')
834 + $overrides = false;
835 + if ($text != '')
838 836 {
839 - $this->data["text"]["text"] = $atts['text'];
837 + $this->data["text"]["text"] = $text;
838 + $overrides = true;
840 839 }
840 + if ($url != '')
841 + {
841 842
842 - if (! is_null($atts['url']) && $atts['url'] !== '')
843 + $this->data["basic"]["url"] = $url;
844 + //$compile = true; // css change forces recompile
845 + $overrides = true;
846 + }
847 + if ($window != '' && $window =='new')
843 848 {
844 - $this->data["basic"]["url"] = $atts['url'];
849 + $this->data["basic"]["new_window"] = 1;
850 + $overrides = true;
845 851 }
846 -
847 - if (! is_null($atts['window']) )
852 + elseif ($window != '' && $window == 'same')
848 853 {
849 - if ($atts['window'] == 'new' )
850 - $this->data["basic"]["new_window"] = 1;
851 - elseif ($atts['window'] == 'same')
852 - $this->data["basic"]["new_window"] = 0;
854 + $this->data["basic"]["new_window"] = 0;
855 + $overrides = true;
853 856 }
854 857
855 - if (! is_null($atts['nofollow']) )
858 + if ($nofollow != '' && $nofollow == 'true')
856 859 {
857 - if ($atts['nofollow'] == 'true')
858 - $this->data["basic"]["nofollow"] = 1;
859 - elseif ($atts['nofollow'] == 'false')
860 - $this->data["basic"]["nofollow"] = 0;
860 + $this->data["basic"]["nofollow"] = 1;
861 + $overrides = true;
861 862 }
862 863
863 - if (! is_null($atts['linktitle']) )
864 + if ($linktitle != '')
864 865 {
865 - $this->data['basic']['link_title'] = $atts['linktitle'];
866 + $this->data['basic']['link_title'] = $linktitle;
867 + $overrides = true;
866 868 }
867 869
868 - if (! is_null($atts['extraclass']))
870 + switch($style)
869 871 {
870 -
871 - $this->data['advanced']['extra_classes'] .= ' ' . $atts['extraclass'];
872 - }
873 -
874 - switch($atts['style'])
875 - {
876 872 case "inline":
877 873 $load_css = 'inline';
878 874 break;
879 875 default:
@@ -881,11 +877,22 @@
881 877 break;
882 878 }
883 879
884 880 // allow for more flexible changes and data manipulation.
885 - $this->data = $this->shortcode_overrides($this->data, $button_atts);
881 + $data = $this->data;
882 + $this->data = $this->shortcode_overrides($this->data, $atts);
886 883 $this->data = apply_filters('mb/shortcode/data', $this->data, $atts);
887 884
885 +/* if ($data !== $this->data)
886 + {
887 + $overrides = true;
888 + }
889 +*/
890 +/* if ($overrides)
891 + {
892 + do_action('mb-data-load', $this->data);
893 + }
894 +*/
888 895 // if there are no reasons not to display; display
889 896 $args = array("echo" => false,
890 897 "load_css" => $load_css,
891 898 "compile" => $compile,
@@ -890,8 +897,9 @@
890 897 "load_css" => $load_css,
891 898 "compile" => $compile,
892 899 );
893 900 $args = apply_filters('mb_shortcode_display_args', $args);
901 +
894 902
895 903 $output = $this->display($args);
896 904
897 905 return $output;