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

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