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 -104 7.116.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,19 +302,20 @@
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
319 -//echo "<PRE>"; print_r($css); echo "</PRE>";
320 318 $this->button_css = $css;
321 319
322 320 $css = $this->getCSSParser()->parse($this->button_css);
323 321 $css = apply_filters('mb/button/compiledcss', $css, $mode); // the final result.
@@ -364,9 +362,8 @@
364 362 $name = $this->name;
365 363 // non-latin breaks CSS / ID's - so move to latin.
366 364 $name = maxUtils::translit($name);
367 365 $name = sanitize_title($name);
368 - $name = str_replace('%', '', $name);
369 366
370 367 $classes = array("maxbutton-" . $this->id,
371 368 "maxbutton");
372 369
@@ -373,8 +370,9 @@
373 370
374 371 if ($name != '')
375 372 $classes[] = "maxbutton-" . $name;
376 373
374 + $classes = apply_filters('mb-mainclasses', $classes);
377 375 $classes = implode(' ', $classes);
378 376
379 377 $domObj = new simple_html_dom();
380 378 $domObj->load('<a class="' . $classes . '"></a>');
@@ -398,24 +396,14 @@
398 396 {
399 397 foreach($this->blocks as $block)
400 398 {
401 399 $block->admin_fields();
402 - $block->display_fields();
400 +
403 401 }
404 402 //do_action('mb-admin-fields' );
405 403
406 404 }
407 405
408 - protected function post_parse_button($domObj, $mode)
409 - {
410 - foreach($this->blocks as $block)
411 - {
412 - $domObj = $block->post_parse_button($domObj, $mode);
413 - $domObj->load($domObj->save());
414 - }
415 -
416 - }
417 -
418 406 /* Display the button */
419 407 public function display($args = array() )
420 408 {
421 409 maxUtils::startTime('button-display-'. $this->id);
@@ -453,9 +441,9 @@
453 441 $compile = false;
454 442 break;
455 443 case "editor":
456 444 $preview = true;
457 - $compile = true;
445 + $compile = true;
458 446 // editor is both compile and preview.
459 447 break;
460 448 break;
461 449 case "normal":
@@ -465,10 +453,13 @@
465 453 }
466 454
467 455
468 456 // Apply filters for general data override
457 +
469 458 $this->data = apply_filters('mb/button/data_before_display', $this->data, $mode, array('preview' => $preview, 'compile' => $compile) ); // hooks
470 459
460 +
461 +
471 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.
472 463 $compile = true;
473 464
474 465 }
@@ -481,21 +472,14 @@
481 472 {
482 473 $block->set($this->data);
483 474 }
484 475
485 - // create the button
486 476 $domObj = $this->parse_button($mode);
487 477
488 - // create CSS
489 478 maxUtils::startTime('button-parse-css-'. $this->id);
490 479 $this->parse_css($mode, $compile);
491 480 maxUtils::endTime('button-parse-css-'. $this->id);
492 481
493 -
494 - // operation after creating CSS model. Mainly adding extra classes
495 - $this->post_parse_button($domObj, $mode);
496 -
497 -
498 482 if (! $preview) // no js on previews
499 483 $this->parse_js($mode);
500 484
501 485 if ($preview) // mark it preview
@@ -522,9 +506,8 @@
522 506 }
523 507 elseif ($this->load_css == 'footer')
524 508 {
525 509 $css = $this->display_css(false, false);
526 -
527 510 do_action('mb-footer',$this->id, $css);
528 511
529 512 if (! $preview)
530 513 {
@@ -541,8 +524,9 @@
541 524 elseif ($this->load_css == 'element') // not possible to load both normal and hover to an element.
542 525 {
543 526 $domObj->find('a',0)->class .= ' normal';
544 527 $domObj = $this->cssParser->outputInline($domObj);
528 + //$this->get_element_css($domObj, 'normal');
545 529 }
546 530
547 531
548 532 $output .= $domObj->save();
@@ -569,9 +553,11 @@
569 553 foreach($this->blocks as $block)
570 554 {
571 555 $map = $block->map_fields($map);
572 556 }
557 + //$map = apply_filters("mb-field-map",$map);
573 558
559 +
574 560 echo "<script language='javascript'>";
575 561 echo "var buttonFieldMap = '" . json_encode($map) . "';" ;
576 562 echo "</script>";
577 563
@@ -672,8 +658,9 @@
672 658 */
673 659 public function save($post, $savedb = true)
674 660 {
675 661 $post = stripslashes_deep($post); // don't multiply slashes please.
662 + //$data = apply_filters('mb-save-fields',$this->data, $post);
676 663 $data = $this->data;
677 664
678 665 foreach($this->blocks as $block)
679 666 {
@@ -729,9 +716,8 @@
729 716 $return = $id;
730 717
731 718 }
732 719
733 - do_action('mb/button/save', $id);
734 720
735 721 if ($result === false)
736 722 {
737 723 $error = "Database error " . $wpdb->last_error;
@@ -761,9 +747,9 @@
761 747 global $wpdb;
762 748
763 749 if ($this->id > 0)
764 750 {
765 - $fields = array("cache" => $css, 'updated' => $this->updated); // try not to update timestamp on recache.
751 + $fields = array("cache" => $css);
766 752 $where = array('id' => $this->id);
767 753 $where_format = array('%d');
768 754 $wpdb->update(maxUtils::get_table_name(), $fields, $where, null, $where_format);
769 755 $return = true;
@@ -775,9 +761,9 @@
775 761 // Resets all of the button caches.
776 762 public function reset_cache()
777 763 {
778 764 global $wpdb;
779 - $fields = array("cache" => null, 'updated' => 'updated');
765 + $fields = array("cache" => null);
780 766 $where = array(1 => 1);
781 767 //$where_format = array('%d');
782 768 $sql = "UPDATE " . maxUtils::get_table_name() . " SET cache = NULL ";
783 769 $wpdb->query($sql);
@@ -792,32 +778,32 @@
792 778 @param $atts array Shortcode Atts
793 779 @return string HTML presentation of button
794 780
795 781 */
796 - public function shortcode($button_atts)
782 + public function shortcode($atts)
797 783 {
798 - $atts = shortcode_atts(array(
799 - 'id' => null,
800 - 'name' => null,
801 - 'text' => null,
802 - 'url' => null,
803 - 'linktitle' => null,
804 - 'window' => null,
805 - 'nofollow' => null,
806 - 'nocache' => null,
807 - 'extraclass' => null,
784 + extract(shortcode_atts(array(
785 + 'id' => '',
786 + 'name' => '',
787 + 'text' => '',
788 + 'url' => '',
789 + 'linktitle' => '',
790 + 'window' => '',
791 + 'nofollow' => '',
792 + 'nocache' => false,
808 793 'style' => 'footer',
794 + 'exclude' => ''
809 795
810 - ), $button_atts, 'maxbutton');
796 + ), $atts));
811 797
812 - $button_id = $atts['id'];
813 - $button_name = $atts['name'];
798 + $button_id = $id;
799 + $button_name = $name;
814 800
815 - if (! is_null($button_id) && $button_id > 0)
801 + if ($button_id > 0)
816 802 $result = $this->set($button_id);
817 - elseif (! is_null($button_name))
803 + elseif ($button_name != '')
818 804 $result = $this->set(0, $button_name);
819 - else return; // no button id or name given
805 + else return; // no button id / name
820 806
821 807 /* Shortcode cache control
822 808
823 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!
@@ -823,60 +809,67 @@
823 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!
824 810
825 811 @param boolean $nocache True / False
826 812 */
827 - $compile = apply_filters("mb/shortcode/nocache", $atts['nocache'] );
813 + $compile = apply_filters("mb/shortcode/nocache", $nocache);
828 814
829 815 if (! $result)
830 - return; // button doesn't exist
816 + return; // shortcode doesn't exist
831 817
832 818 // If we're not in the admin and the button is in the trash, just return nothing
833 - if (!is_admin() && $this->status == 'trash') {
834 - 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 + }
835 831 }
836 832
837 833 // Override shortcode options comparing to default button data.
838 - //$overrides = false;
839 -
840 - if (! is_null($atts['text']) && $atts['text'] !== '')
834 + $overrides = false;
835 + if ($text != '')
841 836 {
842 - $this->data["text"]["text"] = $atts['text'];
837 + $this->data["text"]["text"] = $text;
838 + $overrides = true;
843 839 }
840 + if ($url != '')
841 + {
844 842
845 - 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')
846 848 {
847 - $this->data["basic"]["url"] = $atts['url'];
849 + $this->data["basic"]["new_window"] = 1;
850 + $overrides = true;
848 851 }
849 -
850 - if (! is_null($atts['window']) )
852 + elseif ($window != '' && $window == 'same')
851 853 {
852 - if ($atts['window'] == 'new' )
853 - $this->data["basic"]["new_window"] = 1;
854 - elseif ($atts['window'] == 'same')
855 - $this->data["basic"]["new_window"] = 0;
854 + $this->data["basic"]["new_window"] = 0;
855 + $overrides = true;
856 856 }
857 857
858 - if (! is_null($atts['nofollow']) )
858 + if ($nofollow != '' && $nofollow == 'true')
859 859 {
860 - if ($atts['nofollow'] == 'true')
861 - $this->data["basic"]["nofollow"] = 1;
862 - elseif ($atts['nofollow'] == 'false')
863 - $this->data["basic"]["nofollow"] = 0;
860 + $this->data["basic"]["nofollow"] = 1;
861 + $overrides = true;
864 862 }
865 863
866 - if (! is_null($atts['linktitle']) )
864 + if ($linktitle != '')
867 865 {
868 - $this->data['basic']['link_title'] = $atts['linktitle'];
866 + $this->data['basic']['link_title'] = $linktitle;
867 + $overrides = true;
869 868 }
870 869
871 - if (! is_null($atts['extraclass']))
870 + switch($style)
872 871 {
873 -
874 - $this->data['advanced']['extra_classes'] .= ' ' . $atts['extraclass'];
875 - }
876 -
877 - switch($atts['style'])
878 - {
879 872 case "inline":
880 873 $load_css = 'inline';
881 874 break;
882 875 default:
@@ -884,11 +877,22 @@
884 877 break;
885 878 }
886 879
887 880 // allow for more flexible changes and data manipulation.
888 - $this->data = $this->shortcode_overrides($this->data, $button_atts);
881 + $data = $this->data;
882 + $this->data = $this->shortcode_overrides($this->data, $atts);
889 883 $this->data = apply_filters('mb/shortcode/data', $this->data, $atts);
890 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 +*/
891 895 // if there are no reasons not to display; display
892 896 $args = array("echo" => false,
893 897 "load_css" => $load_css,
894 898 "compile" => $compile,
@@ -893,8 +897,9 @@
893 897 "load_css" => $load_css,
894 898 "compile" => $compile,
895 899 );
896 900 $args = apply_filters('mb_shortcode_display_args', $args);
901 +
897 902
898 903 $output = $this->display($args);
899 904
900 905 return $output;