PluginProbe
MaxButtons – Create buttons / 7.11
MaxButtons – Create buttons v7.11
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.11, at classes/maxbuttons-class.php

751 lines 24.0 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
356 wp_enqueue_style('maxbuttons-css');
357
358 wp_register_style('mb-alpha-color', $this->plugin_url . 'assets/libraries/alpha-color/alpha-color-picker.css', array(), $version);
359
360 wp_enqueue_style('mb-alpha-color');
361
362 }
363
364 /** Add Admin scripts
365 *
366 * Uses WP hook for Admin scripts to add needed js.
367 */
368 function add_admin_scripts($hook) {
369 // only hook in maxbuttons realm.
370 if ( strpos($hook,'maxbuttons') === false ) //&& $hook != 'post.php' && $hook != 'post-new.php'
371 return;
372
373 $version = MAXBUTTONS_VERSION_NUM;
374
375 $js_url = trailingslashit($this->plugin_url . 'js');
376 if (! $this->debug_mode)
377 $js_url .= 'min/';
378
379 wp_enqueue_script('jquery-ui-draggable');
380 wp_enqueue_script('wplink');
381
382 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', 'maxbutton-alpha-picker', 'underscore', 'maxbuttons-ajax', 'wplink'),$version, true);
383
384 wp_localize_script('maxbutton-admin', 'maxadmin_settings', array(
385 'homeurl' => home_url(),
386 ));
387
388 wp_register_script('maxbutton-alpha-picker', $this->plugin_url . 'assets/libraries/alpha-color/alpha-color-picker.js', array('jquery', 'wp-color-picker'), $version, true);
389
390 wp_enqueue_script('maxbutton-alpha-picker');
391 wp_enqueue_script('maxbutton-admin');
392 wp_enqueue_script('maxbutton-js-init', $js_url . 'init.js', array('maxbutton-admin'),$version, true);
393 wp_enqueue_script('maxbuttons-tabs', $js_url . 'maxtabs.js', array('jquery') ,$version, true);
394 wp_enqueue_script('maxbuttons-responsive', $js_url . 'responsive.js', array('jquery'), $version, true );
395
396 wp_enqueue_style('editor-buttons'); // style for WP-link
397
398
399 $this->load_ajax_script();
400 $this->load_modal_script();
401 }
402
403 /** Load the Modal Script
404 * The modal script is the generic solution for all popups within the plugin.
405 */
406 public function load_modal_script()
407 {
408 $version = MAXBUTTONS_VERSION_NUM;
409 $js_url = trailingslashit($this->plugin_url . 'js');
410 if (! $this->debug_mode)
411 $js_url .= 'min/';
412
413 wp_register_script('maxbuttons-modal', $js_url . 'maxmodal.js', array('jquery','jquery-ui-draggable'), $version, true);
414 // translations of controls and other elements that can be used in maxmodal
415 $translations = array(
416 'yes' => __("Yes","maxbuttons"),
417 'no' => __("No","maxbuttons"),
418 'ok' => __("OK","maxbuttons"),
419 'cancel' => __("Cancel","maxbuttons"),
420 );
421 wp_localize_script('maxbuttons-modal', 'modaltext', $translations);
422 wp_enqueue_script('maxbuttons-modal');
423
424 wp_enqueue_style('maxbuttons-maxmodal', $this->plugin_url . 'assets/css/maxmodal.css', array(), $version);
425
426 }
427
428 /** Load MaxAjax services
429 *
430 * MaxButtons Ajax Library.
431 */
432 public function load_ajax_script()
433 {
434 $version = MAXBUTTONS_VERSION_NUM;
435 $js_url = trailingslashit($this->plugin_url . 'js');
436 if (! $this->debug_mode)
437 $js_url .= 'min/';
438
439 wp_register_script('maxbuttons-ajax', $js_url . 'maxajax.js', array('jquery'), $version, true);
440 wp_localize_script('maxbuttons-ajax', 'maxajax',
441 array(
442 'ajax_url' => admin_url( 'admin-ajax.php' ),
443 'ajax_action' => 'maxajax',
444 'nonce' => wp_create_nonce('maxajax'),
445 'leave_page' => __("You have unsaved data, are you sure you want to leave the page?","maxbuttons"),
446 ));
447
448 wp_enqueue_script('maxbuttons-ajax');
449 }
450
451 /** Load Media Buttons Script
452 *
453 * Useful for integrations that don't implement the media button but uses the media button JS for loading the button picker
454 *
455 */
456 public function load_media_script()
457 {
458 $version = MAXBUTTONS_VERSION_NUM;
459
460 $js_url = trailingslashit($this->plugin_url . 'js');
461 if (! $this->debug_mode)
462 $js_url .= 'min/';
463
464 wp_register_script('mb-media-button', $js_url . 'media_button.js', array('jquery', 'maxbuttons-modal', 'maxbuttons-ajax'), $version, true);
465
466 $this->load_modal_script();
467 $this->load_ajax_script();
468
469 wp_add_inline_script( 'maxbuttons-modal', '$ = jQuery;' );
470
471 $translations = array(
472 'insert' => __('Insert Button into Editor', 'maxbuttons'),
473 'use' => __('Use this Button', 'maxbuttons'),
474 'loading' => __("Loading your buttons","maxbuttons"),
475 'select' => __('Click on a button from the list below to place the button shortcode in the editor.', 'maxbuttons'),
476 'cancel' => __('Cancel', 'maxbuttons'),
477 'windowtitle' => __("Select a MaxButton","maxbuttons"),
478 'icon' => $this->plugin_url . 'images/mb-peach-32.png',
479 'ajax_url' => admin_url( 'admin-ajax.php' ),
480 'short_url_label' => __('Button URL', 'maxbuttons'),
481 'short_text_label' => __('Button Text', 'maxbuttons'),
482 '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'),
483 'short_add_button' => __('Add to Editor', 'maxbuttons'),
484 );
485
486 wp_localize_script('mb-media-button','mbtrans', $translations);
487 wp_enqueue_script('mb-media-button');
488
489 wp_enqueue_style('maxbuttons-media-button', $this->plugin_url . 'assets/css/media_button.css', array(), $version);
490
491
492 }
493
494 /** Inits the options for WP editor, like tinymce and other buttons **/
495 public function init_wp_editor_options()
496 {
497 /*if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
498 return;
499 } */
500 // option
501 if (get_option('maxbuttons_noshowtinymce') == 1) return;
502
503 // Media buttons
504 add_action('media_buttons', array($this,'media_button'), 20);
505
506 add_filter('mce_buttons', array($this, 'tinymce_button'));
507 add_filter('mce_external_plugins', array($this, 'add_tinymce_button'));
508
509 /* add_action('before_wp_tiny_mce', function($settings) {
510 $icon_url = MB()->get_plugin_url() . 'images/mb-peach-32.png';
511 echo "<script type='text/javascript'>
512 var maxButtonsTinyMCE = {
513 'icon': '$icon_url'
514 };
515 </script>";
516 });
517 */
518
519 }
520
521 /** Load Media Button in WP editor
522 *
523 * The 'add button' interface in WP post and page editor to simplify adding buttons. Loads button plus required Javascript.
524 */
525 function media_button($editor_id) {
526 $output = '';
527
528 $this->load_media_script();
529
530 // Only run in post/page creation and edit screens
531
532 $title = __('Add Button', 'maxbuttons');
533 $icon = $this->plugin_url . 'images/mb-peach-icon.png';
534 //$nonce = wp_create_nonce('maxajax');
535 $img = '<span class="wp-media-buttons-icon" style="background-image: url(' . $icon . '); width: 16px; height: 16px; margin-top: 1px;"></span>';
536 //$img = '';
537 $output = '<button id="maxbutton-add-button" type="button" class="button maxbutton_media_button" onclick="var mm = new window.maxFoundry.maxMedia();
538 mm.init();
539 mm.openModal();"
540 title="' . $title . '" style="padding-left: .4em;" data-editor=' . $editor_id . '>' . $img . ' ' . $title . '</button>';
541
542 echo $output;
543 }
544
545 public function tinymce_button($buttons)
546 {
547
548 $buttons[] = 'maxbutton';
549 return $buttons;
550 }
551
552 public function add_tinymce_button($plugin_array)
553 {
554 $js_url = trailingslashit($this->plugin_url . 'js');
555 if (! $this->debug_mode)
556 $js_url .= 'min/';
557
558 $this->load_media_script(); // enqueue button handler
559
560
561 $plugin_array['maxButtons_tinymce'] = $js_url . 'tinymce.js' ;
562 return $plugin_array;
563
564 }
565
566
567
568 /** Scripts run on front-end
569 * Load font-awesome, and limited javascript for the front-end. This is being kept extremely limited for performance reasons.
570 */
571 public function front_scripts()
572 {
573 $version = MAXBUTTONS_VERSION_NUM;
574
575 // load backend script on front in Beaver Builder
576 if (isset($_GET['fl_builder']))
577 {
578 $this->add_admin_styles('maxbuttons');
579 }
580
581 /*wp_enqueue_script('maxbuttons-front', $this->plugin_url . 'js/min/front.js', array('jquery'), $version);
582 $local = array();
583 $local["ajaxurl"] = admin_url( 'admin-ajax.php' ); */
584
585 //wp_localize_script('maxbuttons-front', 'mb_ajax', $local);
586 }
587
588 /** Extra text to display in admin footer */
589 function admin_footer_text($text)
590 {
591 if (! isset($_GET["page"]))
592 return $text;
593
594 if ( strpos($_GET["page"],'maxbuttons') === false)
595 return $text;
596 $text = '';
597
598 $text .= sprintf("If you like MaxButtons please give us a %s�
599
600
601
602
603 %s rating!",
604 "<a href='https://wordpress.org/support/view/plugin-reviews/maxbuttons#postform' target='_blank'>",
605 "</a>") ;
606 return $text;
607
608 }
609
610 /** Function for maxbuttons shortcode */
611 function shortcode($atts)
612 {
613 $button = $this->getClass("button");
614 return $button->shortcode($atts);
615 }
616
617 /** Function for collection shortcode [deprecated] **/
618 public function collection_shortcode($atts, $content = null)
619 {
620 return false; // no more. silent fail.
621
622 }
623
624
625 function plugin_action_links($links, $file) {
626
627 if ($file == plugin_basename(dirname(MAXBUTTONS_ROOT_FILE) . '/maxbuttons.php')) {
628 $label = __('Buttons', 'maxbuttons');
629 $dashboard_link = '<a href="' . admin_url() . 'admin.php?page=maxbuttons-controller&action=list">' . $label . '</a>';
630 array_unshift($links, $dashboard_link);
631 }
632
633 return $links;
634 }
635
636
637 function plugin_row_meta($links, $file) {
638 if ($file == plugin_basename(dirname(__FILE__) . '/maxbuttons.php')) {
639 $links[] = sprintf(__('%sUpgrade to Pro Version%s', 'maxbuttons'), '<a href="http://maxbuttons.com/?ref=mbfree" target="_blank">', '</a>');
640 }
641
642 return $links;
643 }
644
645
646 function do_footer($id, $code, $type = "css")
647 {
648 $this->footer[$type][$id] = $code;
649 }
650
651
652 /** Output footer styles and scripts
653 *
654 * Outputs loaded styles, and scripts to the footer for display. Email_off is to prevent cloudfare from 'obfuscating' the minified CSS
655 * No optimize prevent autoptimize from mutilating the already optimized CSS.
656 */
657 function footer()
658 {
659 if(count($this->footer) == 0) return; // nothing
660
661 $button_ids = array();
662 $use_file = get_option('maxbuttons_usecssfile', false);
663
664 foreach ($this->footer as $type => $part)
665 {
666 if ($type == 'css' && $use_file) // use file output to a CSS filebased output, don't put it inline.
667 {
668 foreach($part as $id => $statements)
669 {
670 if (is_numeric($id))
671 $button_ids[] = $id;
672 else
673 echo "nonum $id";
674 }
675 continue;
676 }
677
678 // add tag
679 if ($type == 'css')
680 {
681 echo "<!--noptimize--><!--email_off--><style type='text/css'>";
682 }
683
684 foreach ($part as $id => $statements)
685 {
686 if (strlen($statements) > 0) // prevent whitespace
687 echo $statements . "\n";
688 }
689
690 if ($type == 'css')
691 {
692 echo "</style><!--/email_off--><!--/noptimize-->\n";
693 }
694 }
695
696 if (is_array($button_ids) && count($button_ids) > 0 && $use_file)
697 {
698 wp_enqueue_style('maxbuttons-front', admin_url('admin-ajax.php').'?action=maxbuttons_front_css&id=' . implode(',',array_unique($button_ids)) );
699 }
700 }
701
702 /* Add a notice
703
704 The added notice will be displayed to the user in WordPress format.
705 @see display_notices
706
707 @param $type string message | notice | error | fatal
708 @param $message string User understandable message
709
710 */
711 public static function add_notice($type, $message)
712 {
713 self::$notices[] = array("type" => $type,
714 "message" => $message
715 );
716
717 }
718
719 /* Display all notices
720
721 Then notices added by @see add_notice will be displayed. This function is called by an action hook
722
723 @param $echo echo the results or silently return.
724 @return string|null If not written to screen via echo, the HTML output will be returned
725 */
726 public function display_notices($echo = true)
727 {
728
729 if ($echo === '') $echo = true;
730 $notices = self::$notices;
731 $output = '';
732 if (count($notices) == 0)
733 return;
734
735 foreach($notices as $index => $notice)
736 {
737 $type = $notice["type"];
738 $message = $notice["message"];
739 $output .= "<div class='mb-message $type'> ";
740 $output .= $message ;
741 $output .= "</div>";
742 }
743
744 self::$notices = array(); // empty notices to prevent double display
745
746 if ($echo) echo $output;
747 else return $output;
748 }
749
750 } // class
751