PluginProbe
MaxButtons – Create buttons / 7.10
MaxButtons – Create buttons v7.10
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
maxbuttons / classes / maxbuttons-class.php

maxbuttons-class.php in MaxButtons – Create buttons 7.10, at classes/maxbuttons-class.php

741 lines 23.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace MaxButtons;
3 defined('ABSPATH') or die('No direct access permitted');
4
5 define('MAXBUTTONS_VERSION_KEY', 'maxbuttons_version');
6
7 class maxButtonsPlugin
8 {
9 protected $installed_version = 0;
10 protected $plugin_name;
11 protected $plugin_url;
12 protected $plugin_path;
13 protected $debug_mode = false;
14 protected $footer = array();
15
16 protected static $notices = array();
17
18 protected $mainClasses = array();
19
20 protected static $instance;
21
22 /* Class constructor
23 Add hooks and actions used by this plugin. Sets plugin environment information
24 */
25 function __construct()
26 {
27 maxUtils::timeInit(); // benchmark timer init.
28
29 $this->plugin_url = self::get_plugin_url(); //plugins_url() . '/' . $this->plugin_name;
30 $this->plugin_path = self::get_plugin_path(); //plugin_dir_path($rootfile);
31 $this->plugin_name = trim(basename($this->plugin_path), '/');
32
33 $this->installed_version = get_option(MAXBUTTONS_VERSION_KEY);
34
35 if ( defined('MAXBUTTONS_DEBUG') && MAXBUTTONS_DEBUG)
36 $this->debug_mode = true;
37
38 add_action('plugins_loaded', array($this, 'load_textdomain'));
39
40 add_filter('widget_text', 'do_shortcode');
41 add_shortcode('maxbutton', array($this, 'shortcode'));
42
43 add_action("mb-footer", array($this, 'do_footer'),10,3);
44 add_action("wp_footer", array($this, "footer"));
45
46 add_filter('plugin_action_links', array($this, "plugin_action_links"), 10, 2);
47 add_filter('plugin_row_meta', array($this, 'plugin_row_meta'), 10, 2);
48
49 if( is_admin())
50 {
51 add_action('admin_enqueue_scripts', array($this,'add_admin_styles'));
52 add_action('admin_enqueue_scripts', array($this,'add_admin_scripts'));
53 add_action('admin_enqueue_scripts', array(maxUtils::namespaceit('maxUtils'), 'fixFAConflict'),999);
54
55 add_action('admin_init', array($this,'register_settings' ));
56
57 add_action('admin_init', array(maxUtils::namespaceit('maxAdmin'), 'do_review_notice')); // Ask for review
58 add_action('admin_init', array(maxUtils::namespaceit('maxInstall'),'check_database'));
59
60 add_action('admin_menu', array($this, 'admin_menu'));
61 add_action('admin_footer', array($this, "footer"));
62 add_filter("admin_footer_text",array($this, "admin_footer_text"));
63
64 // errors in user space. No internal error but user output friendly issues
65 add_action("mb/editor/display_notices", array($this,"display_notices"), 99);
66 add_action("mb/collection/display_notices", array($this,"display_notices"), 99);
67 add_action('mb/header/display_notices', array($this, 'display_notices'), 99);
68
69 //add_action("wp_ajax_getAjaxButtons", array(maxUtils::namespaceit('maxButtonsAdmin'), 'getAjaxButtons'));
70 add_action('maxbuttons/ajax/getAjaxButtons', array(maxUtils::namespaceit('maxButtonsAdmin'), 'getAjaxButtons') );
71 add_action('maxbuttons/ajax/mediaShortcodeOptions', array(maxUtils::namespaceit('maxButtonsAdmin'), 'mediaShortcodeOptions'));
72 add_action('maxbuttons/ajax/save_review_notice_status', array(maxUtils::namespaceit('maxAdmin'), "setReviewNoticeStatus") );
73
74 //add_action("wp_ajax_set_review_notice_status", array($this, "setReviewNoticeStatus"));
75 add_action('wp_ajax_mb_button_action', array(maxUtils::namespaceit('maxButtons'), "ajax_action"));
76
77 add_action('wp_ajax_maxajax', array(maxUtils::namespaceit('maxUtils'), 'ajax_action'));
78
79 add_action('admin_init', array($this,'init_wp_editor_options') );
80 }
81
82
83 add_action('wp_ajax_maxbuttons_front_css', array(maxUtils::namespaceit('maxButtons'), 'generate_css'));
84 add_action('wp_ajax_nopriv_maxbuttons_front_css', array(maxUtils::namespaceit('maxButtons'), 'generate_css'));
85
86 // front scripts
87 add_action('wp_enqueue_scripts', array($this, 'front_scripts'));
88 //add_action('wp_enqueue_scripts', array(maxUtils::namespaceit('maxUtils'), 'fixFAConflict'),999);
89
90 $this->setMainClasses(); // struct for override functionality
91
92 // The second the blocks are being loaded, check dbase integrity
93 add_action("mb_blockclassesloaded", array($this, "check_database"));
94
95 // setup page hooks and shortcode
96 add_shortcode('maxcollection', array($this, 'collection_shortcode'));
97
98
99 self::$instance = $this;
100 maxIntegrations::init(); // fire the integrations.
101 }
102
103 public static function getInstance()
104 {
105 return self::$instance;
106 }
107
108 public function setMainClasses()
109 {
110 $classes = array(
111 "button" => "maxButton",
112 "buttons" => "maxButtons",
113 "block" => "maxBlock",
114 "admin" => "maxButtonsAdmin",
115 "install" => "maxInstall",
116 "groups" => "maxGroups",
117 "pack" => "maxPack",
118 );
119
120 $this->mainClasses = $classes;
121 }
122
123 // from block loader action. Checks if all parts of the table are there, or panic if not.
124 public function check_database($blocks)
125 {
126 maxUtils::addTime("Check database");
127
128 $sql = "SELECT id,name,status,cache, created ";
129 foreach ($blocks as $block => $class)
130 {
131 $sql .= ", $block";
132 }
133 $sql .= " from " . maxUtils::get_table_name() . " limit 1";
134
135 global $wpdb;
136 $wpdb->hide_errors();
137 $result = $wpdb->get_results($sql);
138
139 // check this query for errors. If there is an error, one or more database fields are missing. Fix that.
140 if (isset($wpdb->last_error) && $wpdb->last_error != '')
141 {
142
143 $install = $this->getClass("install");
144 $install::create_database_table();
145 $install::migrate();
146 }
147
148 maxUtils::addTime("End check database");
149 }
150
151 public function getClass($class)
152 {
153
154 if (isset($this->mainClasses[$class]))
155 {
156 $load_class = maxUtils::namespaceit($this->mainClasses[$class]);
157 if (method_exists($load_class,'getInstance'))
158 {
159 return $load_class::getInstance();
160 }
161 return new $load_class;
162 }
163 }
164
165 /* Load the plugin textdomain */
166 public function load_textdomain()
167 {
168 // see: http://geertdedeckere.be/article/loading-wordpress-language-files-the-right-way
169 $domain = 'maxbuttons';
170 // The "plugin_locale" filter is also used in load_plugin_textdomain()
171 $locale = apply_filters('plugin_locale', get_locale(), $domain);
172
173 load_textdomain($domain, WP_LANG_DIR.'/maxbuttons/'.$domain.'-'.$locale.'.mo');
174 $res = load_plugin_textdomain('maxbuttons', false, $this->plugin_name . '/languages/');
175
176 }
177
178
179 /** WP Settings framework. Registers settings used on maxbuttons-settings.php page */
180 public function register_settings()
181 {
182 register_setting( 'maxbuttons_settings', 'maxbuttons_user_level' );
183 register_setting( 'maxbuttons_settings', 'maxbuttons_noshowtinymce' );
184 register_setting( 'maxbuttons_settings', 'maxbuttons_minify' );
185 register_setting( 'maxbuttons_settings', 'maxbuttons_hidedescription' );
186 register_setting( 'maxbuttons_settings', 'maxbuttons_forcefa') ;
187 register_setting( 'maxbuttons_settings', 'maxbuttons_borderbox');
188 register_setting( 'maxbuttons_settings', 'maxbuttons_protocol');
189 }
190
191 protected function checkbox_option($options)
192 {
193 if (! isset($options["maxbuttons_minify"]))
194 $options["maxbuttons_minify"] = 0;
195
196 return $options;
197
198 }
199
200
201 /** Returns the full path of the plugin installation directory */
202 public static function get_plugin_path()
203 {
204 return plugin_dir_path(MAXBUTTONS_ROOT_FILE);
205 }
206
207 /** Returns the full URL of the plugin installation path */
208 public static function get_plugin_url()
209 {
210 $url = plugin_dir_url(MAXBUTTONS_ROOT_FILE);
211 return $url;
212 }
213
214 /** Returns the current installed version */
215 public function get_installed_version()
216 {
217 return $this->installed_version;
218 }
219
220 /** Installs and adds the main menu and the submenu items */
221 function admin_menu() {
222 $maxbuttons_capabilities = get_option('maxbuttons_user_level');
223 if(!$maxbuttons_capabilities) {
224 $maxbuttons_capabilities = 'manage_options';
225 settings_fields( 'maxbuttons_settings' );
226 update_option('maxbuttons_user_level', $maxbuttons_capabilities);
227 }
228 $admin_pages = array();
229
230 $page_title = __('MaxButtons: Buttons', 'maxbuttons');
231 $menu_title = __('MaxButtons', 'maxbuttons');
232 $capability = $maxbuttons_capabilities;
233 $admin_capability = 'manage_options';
234 $menu_slug = 'maxbuttons-controller';
235 $function = array($this, 'load_admin_page');
236 $icon_url = $this->plugin_url . 'images/mb-peach-icon.png';
237 $submenu_function = array($this, 'load_admin_page');
238
239 add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, 81);
240
241 // We add this submenu page with the same slug as the parent to ensure we don't get duplicates
242 $sub_menu_title = __('Buttons', 'maxbuttons');
243 $admin_pages[] = add_submenu_page($menu_slug, $page_title, $sub_menu_title, $capability, $menu_slug, $function);
244
245 // Now add the submenu page for the Add New page
246 $submenu_page_title = __('MaxButtons: Add/Edit Button', 'maxbuttons');
247 $submenu_title = __('Add New', 'maxbuttons');
248 $submenu_slug = 'maxbuttons-controller&action=edit';
249 //$submenu_function = 'maxbuttons_button';
250 $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function);
251
252
253 // Now add the submenu page for the Go Pro page
254 $submenu_page_title = __('MaxButtons: Upgrade to Pro', 'maxbuttons');
255 $submenu_title = __('Upgrade to Pro', 'maxbuttons');
256 $submenu_slug = 'maxbuttons-pro';
257 //$submenu_function = 'maxbuttons_pro';
258 $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function);
259
260 // Now add the submenu page for the Settings page
261 $submenu_page_title = __('MaxButtons: Settings', 'maxbuttons');
262 $submenu_title = __('Settings', 'maxbuttons');
263 $submenu_slug = 'maxbuttons-settings';
264 //$submenu_function = 'maxbuttons_settings';
265 $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $admin_capability, $submenu_slug, $submenu_function);
266
267 // Now add the submenu page for the Support page
268 $submenu_page_title = __('MaxButtons: Support', 'maxbuttons');
269 $submenu_title = __('Support', 'maxbuttons');
270 $submenu_slug = 'maxbuttons-support';
271 //$submenu_function = 'maxbuttons_support';
272 $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $admin_capability, $submenu_slug, $submenu_function);
273
274 if (! MaxInstall::hasAddon('socialshare'))
275 {
276 $submenu_page_title = __('MaxButtons: Share Buttons', 'maxbuttons');
277 $submenu_title = __('Share Buttons', 'maxbuttons');
278 $submenu_slug = 'maxbuttons-collections';
279 $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function);
280 }
281 }
282
283 function load_admin_page()
284 {
285 $page = sanitize_text_field($_GET["page"]);
286
287 switch($page)
288 {
289 case "maxbuttons-button":
290 $pagepath = "includes/maxbuttons-button.php";
291 break;
292 case "maxbuttons-support":
293 $pagepath = "includes/maxbuttons-support.php";
294 break;
295 case "maxbuttons-settings":
296 $pagepath = "includes/maxbuttons-settings.php";
297 break;
298 case "maxbuttons-pro":
299 $pagepath = "includes/maxbuttons-pro.php";
300 break;
301 case "maxbuttons-collections":
302 $pagepath = "includes/maxbuttons-collections.php";
303 break;
304 default:
305 $pagepath = "includes/maxbuttons-controller.php";
306 break;
307 }
308 $pagepath = $this->plugin_path . $pagepath;
309
310 include(apply_filters("mb-load-admin-page-$page", $pagepath));
311 }
312
313 public function load_library($libname)
314 {
315 $version = MAXBUTTONS_VERSION_NUM;
316 $js_url = trailingslashit($this->plugin_url . 'js');
317 if (! $this->debug_mode)
318 $js_url .= 'min/';
319
320 if ($libname == 'review_notice')
321 {
322 wp_register_style('maxbuttons-review-notice-css',$this->plugin_url . 'assets/css/review_notice.css', array(), $version);
323 wp_register_script('maxbuttons-review-notice', $js_url . 'review-notice.js', array('jquery'), $version);
324
325 $local = array();
326 $local["ajaxurl"] = admin_url( 'admin-ajax.php' );
327 $local['nonce'] = wp_create_nonce('maxajax');
328 wp_localize_script('maxbuttons-review-notice', 'mb_ajax_review', $local);
329
330 wp_enqueue_style('maxbuttons-review-notice-css');
331 wp_enqueue_script('maxbuttons-review-notice');
332 }
333
334 }
335
336
337 function add_admin_styles($hook) {
338 // only hook in maxbuttons realm.
339 if ( strpos($hook,'maxbuttons') === false && $hook != 'post.php' && $hook != 'post-new.php' )
340 {
341 if (! isset($_GET['fl_builder'])) // exception for beaver builder
342 return;
343 }
344
345 $version = MAXBUTTONS_VERSION_NUM;
346 //$this->load_library('fontawesome');
347
348 wp_enqueue_style('wp-color-picker');
349
350 if (is_rtl())
351 wp_register_style('maxbuttons-css', $this->plugin_url . 'assets/css/style.rtl.css', array(), $version);
352 else
353 wp_register_style('maxbuttons-css', $this->plugin_url . 'assets/css/style.css', array(), $version);
354
355 wp_enqueue_style('maxbuttons-css');
356
357 }
358
359 /** Add Admin scripts
360 *
361 * Uses WP hook for Admin scripts to add needed js.
362 */
363 function add_admin_scripts($hook) {
364 // only hook in maxbuttons realm.
365 if ( strpos($hook,'maxbuttons') === false ) //&& $hook != 'post.php' && $hook != 'post-new.php'
366 return;
367
368 $version = MAXBUTTONS_VERSION_NUM;
369
370 $js_url = trailingslashit($this->plugin_url . 'js');
371 if (! $this->debug_mode)
372 $js_url .= 'min/';
373
374 wp_enqueue_script('jquery-ui-draggable');
375 wp_enqueue_script('wplink');
376
377 wp_register_script('maxbutton-admin', $js_url . 'maxbuttons-admin.js', array('jquery', 'jquery-ui-draggable', 'maxbuttons-tabs','maxbuttons-modal', 'maxbuttons-tabs', 'maxbuttons-responsive', 'maxbuttons-ajax', 'wp-color-picker', 'underscore', 'maxbuttons-ajax', 'wplink'),$version, true);
378
379 wp_localize_script('maxbutton-admin', 'maxadmin_settings', array('homeurl' => home_url() ));
380
381 wp_enqueue_script('maxbutton-admin');
382 wp_enqueue_script('maxbutton-js-init', $js_url . 'init.js', array('maxbutton-admin'),$version, true);
383 wp_enqueue_script('maxbuttons-tabs', $js_url . 'maxtabs.js', array('jquery') ,$version, true);
384 wp_enqueue_script('maxbuttons-responsive', $js_url . 'responsive.js', array('jquery'), $version, true );
385
386 wp_enqueue_style('editor-buttons'); // style for WP-link
387
388
389 $this->load_ajax_script();
390 $this->load_modal_script();
391 }
392
393 /** Load the Modal Script
394 * The modal script is the generic solution for all popups within the plugin.
395 */
396 public function load_modal_script()
397 {
398 $version = MAXBUTTONS_VERSION_NUM;
399 $js_url = trailingslashit($this->plugin_url . 'js');
400 if (! $this->debug_mode)
401 $js_url .= 'min/';
402
403 wp_register_script('maxbuttons-modal', $js_url . 'maxmodal.js', array('jquery','jquery-ui-draggable'), $version, true);
404 // translations of controls and other elements that can be used in maxmodal
405 $translations = array(
406 'yes' => __("Yes","maxbuttons"),
407 'no' => __("No","maxbuttons"),
408 'ok' => __("OK","maxbuttons"),
409 'cancel' => __("Cancel","maxbuttons"),
410 );
411 wp_localize_script('maxbuttons-modal', 'modaltext', $translations);
412 wp_enqueue_script('maxbuttons-modal');
413
414 wp_enqueue_style('maxbuttons-maxmodal', $this->plugin_url . 'assets/css/maxmodal.css', array(), $version);
415
416 }
417
418 /** Load MaxAjax services
419 *
420 * MaxButtons Ajax Library.
421 */
422 public function load_ajax_script()
423 {
424 $version = MAXBUTTONS_VERSION_NUM;
425 $js_url = trailingslashit($this->plugin_url . 'js');
426 if (! $this->debug_mode)
427 $js_url .= 'min/';
428
429 wp_register_script('maxbuttons-ajax', $js_url . 'maxajax.js', array('jquery'), $version, true);
430 wp_localize_script('maxbuttons-ajax', 'maxajax',
431 array(
432 'ajax_url' => admin_url( 'admin-ajax.php' ),
433 'ajax_action' => 'maxajax',
434 'nonce' => wp_create_nonce('maxajax'),
435 'leave_page' => __("You have unsaved data, are you sure you want to leave the page?","maxbuttons"),
436 ));
437
438 wp_enqueue_script('maxbuttons-ajax');
439 }
440
441 /** Load Media Buttons Script
442 *
443 * Useful for integrations that don't implement the media button but uses the media button JS for loading the button picker
444 *
445 */
446 public function load_media_script()
447 {
448 $version = MAXBUTTONS_VERSION_NUM;
449
450 $js_url = trailingslashit($this->plugin_url . 'js');
451 if (! $this->debug_mode)
452 $js_url .= 'min/';
453
454 wp_register_script('mb-media-button', $js_url . 'media_button.js', array('jquery', 'maxbuttons-modal', 'maxbuttons-ajax'), $version, true);
455
456 $this->load_modal_script();
457 $this->load_ajax_script();
458
459 wp_add_inline_script( 'maxbuttons-modal', '$ = jQuery;' );
460
461 $translations = array(
462 'insert' => __('Insert Button into Editor', 'maxbuttons'),
463 'use' => __('Use this Button', 'maxbuttons'),
464 'loading' => __("Loading your buttons","maxbuttons"),
465 'select' => __('Click on a button from the list below to place the button shortcode in the editor.', 'maxbuttons'),
466 'cancel' => __('Cancel', 'maxbuttons'),
467 'windowtitle' => __("Select a MaxButton","maxbuttons"),
468 'icon' => $this->plugin_url . 'images/mb-peach-32.png',
469 'ajax_url' => admin_url( 'admin-ajax.php' ),
470 'short_url_label' => __('Button URL', 'maxbuttons'),
471 'short_text_label' => __('Button Text', 'maxbuttons'),
472 'short_options_explain' => __('If you want to change the URL or Text of the Button, enter the appropiate field. If you want to use the button values, just click Add to editor', 'maxbuttons'),
473 'short_add_button' => __('Add to Editor', 'maxbuttons'),
474 );
475
476 wp_localize_script('mb-media-button','mbtrans', $translations);
477 wp_enqueue_script('mb-media-button');
478
479 wp_enqueue_style('maxbuttons-media-button', $this->plugin_url . 'assets/css/media_button.css', array(), $version);
480
481
482 }
483
484 /** Inits the options for WP editor, like tinymce and other buttons **/
485 public function init_wp_editor_options()
486 {
487 /*if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
488 return;
489 } */
490 // option
491 if (get_option('maxbuttons_noshowtinymce') == 1) return;
492
493 // Media buttons
494 add_action('media_buttons', array($this,'media_button'), 20);
495
496 add_filter('mce_buttons', array($this, 'tinymce_button'));
497 add_filter('mce_external_plugins', array($this, 'add_tinymce_button'));
498
499 /* add_action('before_wp_tiny_mce', function($settings) {
500 $icon_url = MB()->get_plugin_url() . 'images/mb-peach-32.png';
501 echo "<script type='text/javascript'>
502 var maxButtonsTinyMCE = {
503 'icon': '$icon_url'
504 };
505 </script>";
506 });
507 */
508
509 }
510
511 /** Load Media Button in WP editor
512 *
513 * The 'add button' interface in WP post and page editor to simplify adding buttons. Loads button plus required Javascript.
514 */
515 function media_button($editor_id) {
516 $output = '';
517
518 $this->load_media_script();
519
520 // Only run in post/page creation and edit screens
521
522 $title = __('Add Button', 'maxbuttons');
523 $icon = $this->plugin_url . 'images/mb-peach-icon.png';
524 //$nonce = wp_create_nonce('maxajax');
525 $img = '<span class="wp-media-buttons-icon" style="background-image: url(' . $icon . '); width: 16px; height: 16px; margin-top: 1px;"></span>';
526 //$img = '';
527 $output = '<button id="maxbutton-add-button" type="button" class="button maxbutton_media_button" onclick="var mm = new window.maxFoundry.maxMedia();
528 mm.init();
529 mm.openModal();"
530 title="' . $title . '" style="padding-left: .4em;" data-editor=' . $editor_id . '>' . $img . ' ' . $title . '</button>';
531
532 echo $output;
533 }
534
535 public function tinymce_button($buttons)
536 {
537
538 $buttons[] = 'maxbutton';
539 return $buttons;
540 }
541
542 public function add_tinymce_button($plugin_array)
543 {
544 $js_url = trailingslashit($this->plugin_url . 'js');
545 if (! $this->debug_mode)
546 $js_url .= 'min/';
547
548 $this->load_media_script(); // enqueue button handler
549
550
551 $plugin_array['maxButtons_tinymce'] = $js_url . 'tinymce.js' ;
552 return $plugin_array;
553
554 }
555
556
557
558 /** Scripts run on front-end
559 * Load font-awesome, and limited javascript for the front-end. This is being kept extremely limited for performance reasons.
560 */
561 public function front_scripts()
562 {
563 $version = MAXBUTTONS_VERSION_NUM;
564
565 // load backend script on front in Beaver Builder
566 if (isset($_GET['fl_builder']))
567 {
568 $this->add_admin_styles('maxbuttons');
569 }
570
571 /*wp_enqueue_script('maxbuttons-front', $this->plugin_url . 'js/min/front.js', array('jquery'), $version);
572 $local = array();
573 $local["ajaxurl"] = admin_url( 'admin-ajax.php' ); */
574
575 //wp_localize_script('maxbuttons-front', 'mb_ajax', $local);
576 }
577
578 /** Extra text to display in admin footer */
579 function admin_footer_text($text)
580 {
581 if (! isset($_GET["page"]))
582 return $text;
583
584 if ( strpos($_GET["page"],'maxbuttons') === false)
585 return $text;
586 $text = '';
587
588 $text .= sprintf("If you like MaxButtons please give us a %s�
589
590
591
592
593 %s rating!",
594 "<a href='https://wordpress.org/support/view/plugin-reviews/maxbuttons#postform' target='_blank'>",
595 "</a>") ;
596 return $text;
597
598 }
599
600 /** Function for maxbuttons shortcode */
601 function shortcode($atts)
602 {
603 $button = $this->getClass("button");
604 return $button->shortcode($atts);
605 }
606
607 /** Function for collection shortcode [deprecated] **/
608 public function collection_shortcode($atts, $content = null)
609 {
610 return false; // no more. silent fail.
611
612 }
613
614
615 function plugin_action_links($links, $file) {
616
617 if ($file == plugin_basename(dirname(MAXBUTTONS_ROOT_FILE) . '/maxbuttons.php')) {
618 $label = __('Buttons', 'maxbuttons');
619 $dashboard_link = '<a href="' . admin_url() . 'admin.php?page=maxbuttons-controller&action=list">' . $label . '</a>';
620 array_unshift($links, $dashboard_link);
621 }
622
623 return $links;
624 }
625
626
627 function plugin_row_meta($links, $file) {
628 if ($file == plugin_basename(dirname(__FILE__) . '/maxbuttons.php')) {
629 $links[] = sprintf(__('%sUpgrade to Pro Version%s', 'maxbuttons'), '<a href="http://maxbuttons.com/?ref=mbfree" target="_blank">', '</a>');
630 }
631
632 return $links;
633 }
634
635
636 function do_footer($id, $code, $type = "css")
637 {
638 $this->footer[$type][$id] = $code;
639 }
640
641
642 /** Output footer styles and scripts
643 *
644 * Outputs loaded styles, and scripts to the footer for display. Email_off is to prevent cloudfare from 'obfuscating' the minified CSS
645 * No optimize prevent autoptimize from mutilating the already optimized CSS.
646 */
647 function footer()
648 {
649 if(count($this->footer) == 0) return; // nothing
650
651 $button_ids = array();
652 $use_file = get_option('maxbuttons_usecssfile', false);
653
654 foreach ($this->footer as $type => $part)
655 {
656 if ($type == 'css' && $use_file) // use file output to a CSS filebased output, don't put it inline.
657 {
658 foreach($part as $id => $statements)
659 {
660 if (is_numeric($id))
661 $button_ids[] = $id;
662 else
663 echo "nonum $id";
664 }
665 continue;
666 }
667
668 // add tag
669 if ($type == 'css')
670 {
671 echo "<!--noptimize--><!--email_off--><style type='text/css'>";
672 }
673
674 foreach ($part as $id => $statements)
675 {
676 if (strlen($statements) > 0) // prevent whitespace
677 echo $statements . "\n";
678 }
679
680 if ($type == 'css')
681 {
682 echo "</style><!--/email_off--><!--/noptimize-->\n";
683 }
684 }
685
686 if (is_array($button_ids) && count($button_ids) > 0 && $use_file)
687 {
688 wp_enqueue_style('maxbuttons-front', admin_url('admin-ajax.php').'?action=maxbuttons_front_css&id=' . implode(',',array_unique($button_ids)) );
689 }
690 }
691
692 /* Add a notice
693
694 The added notice will be displayed to the user in WordPress format.
695 @see display_notices
696
697 @param $type string message | notice | error | fatal
698 @param $message string User understandable message
699
700 */
701 public static function add_notice($type, $message)
702 {
703 self::$notices[] = array("type" => $type,
704 "message" => $message
705 );
706
707 }
708
709 /* Display all notices
710
711 Then notices added by @see add_notice will be displayed. This function is called by an action hook
712
713 @param $echo echo the results or silently return.
714 @return string|null If not written to screen via echo, the HTML output will be returned
715 */
716 public function display_notices($echo = true)
717 {
718
719 if ($echo === '') $echo = true;
720 $notices = self::$notices;
721 $output = '';
722 if (count($notices) == 0)
723 return;
724
725 foreach($notices as $index => $notice)
726 {
727 $type = $notice["type"];
728 $message = $notice["message"];
729 $output .= "<div class='mb-message $type'> ";
730 $output .= $message ;
731 $output .= "</div>";
732 }
733
734 self::$notices = array(); // empty notices to prevent double display
735
736 if ($echo) echo $output;
737 else return $output;
738 }
739
740 } // class
741