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/maxbuttons-class.php +225 -317 7.13.26.28 View file →
@@ -5,8 +5,9 @@
5 5 define('MAXBUTTONS_VERSION_KEY', 'maxbuttons_version');
6 6
7 7 class maxButtonsPlugin
8 8 {
9 +
9 10 protected $installed_version = 0;
10 11 protected $plugin_name;
11 12 protected $plugin_url;
12 13 protected $plugin_path;
@@ -18,19 +19,14 @@
18 19 protected $mainClasses = array();
19 20
20 21 protected static $instance;
21 22
22 - private $paths = array('classes', 'classes/controllers');
23 -
24 23 /* Class constructor
25 24 Add hooks and actions used by this plugin. Sets plugin environment information
26 25 */
27 - public function __construct()
26 + function __construct()
28 27 {
29 - $this->load(); // loads classes
30 -
31 28 maxUtils::timeInit(); // benchmark timer init.
32 - maxAdmin::init(); // helper class hook init
33 29
34 30 $this->plugin_url = self::get_plugin_url(); //plugins_url() . '/' . $this->plugin_name;
35 31 $this->plugin_path = self::get_plugin_path(); //plugin_dir_path($rootfile);
36 32 $this->plugin_name = trim(basename($this->plugin_path), '/');
@@ -39,45 +35,8 @@
39 35
40 36 if ( defined('MAXBUTTONS_DEBUG') && MAXBUTTONS_DEBUG)
41 37 $this->debug_mode = true;
42 38
43 - self::$instance = $this;
44 -
45 - $this->hooks();
46 -
47 - maxIntegrations::init(); // fire the integrations.
48 -
49 - // Core libraries.
50 - MB()->load_library('simplehtmldom');
51 - MB()->load_library('simple_template');
52 - }
53 -
54 - public function load()
55 - {
56 - $plugin_path = plugin_dir_path(MAXBUTTONS_ROOT_FILE);
57 - foreach($this->paths as $short_path)
58 - {
59 - $directory_path = realpath($plugin_path . $short_path);
60 -
61 - if ($directory_path !== false)
62 - {
63 - $it = new \DirectoryIterator($directory_path);
64 - foreach($it as $file)
65 - {
66 - $file_path = $file->getRealPath();
67 - if ($file->isFile() && pathinfo($file_path, PATHINFO_EXTENSION) == 'php')
68 - {
69 - require_once($file_path);
70 - }
71 - }
72 - }
73 - }
74 -
75 - }
76 -
77 - public function hooks()
78 - {
79 -
80 39 add_action('plugins_loaded', array($this, 'load_textdomain'));
81 40
82 41 add_filter('widget_text', 'do_shortcode');
83 42 add_shortcode('maxbutton', array($this, 'shortcode'));
@@ -84,8 +43,11 @@
84 43
85 44 add_action("mb-footer", array($this, 'do_footer'),10,3);
86 45 add_action("wp_footer", array($this, "footer"));
87 46
47 + // Media buttons
48 + add_action('media_buttons', array($this,'media_button'));
49 +
88 50 add_filter('plugin_action_links', array($this, "plugin_action_links"), 10, 2);
89 51 add_filter('plugin_row_meta', array($this, 'plugin_row_meta'), 10, 2);
90 52
91 53 if( is_admin())
@@ -95,9 +57,9 @@
95 57 add_action('admin_enqueue_scripts', array(maxUtils::namespaceit('maxUtils'), 'fixFAConflict'),999);
96 58
97 59 add_action('admin_init', array($this,'register_settings' ));
98 60
99 - add_action('admin_init', array(maxUtils::namespaceit('maxAdmin'), 'do_review_notice')); // Ask for review
61 + add_action('admin_init', array($this, 'do_review_notice')); // Ask for review
100 62 add_action('admin_init', array(maxUtils::namespaceit('maxInstall'),'check_database'));
101 63
102 64 add_action('admin_menu', array($this, 'admin_menu'));
103 65 add_action('admin_footer', array($this, "footer"));
@@ -107,28 +69,25 @@
107 69 add_action("mb/editor/display_notices", array($this,"display_notices"), 99);
108 70 add_action("mb/collection/display_notices", array($this,"display_notices"), 99);
109 71 add_action('mb/header/display_notices', array($this, 'display_notices'), 99);
110 72
111 - //add_action("wp_ajax_getAjaxButtons", array(maxUtils::namespaceit('maxButtonsAdmin'), 'getAjaxButtons'));
112 - add_action('maxbuttons/ajax/getAjaxButtons', array(maxUtils::namespaceit('maxButtonsAdmin'), 'getAjaxButtons') );
113 - add_action('maxbuttons/ajax/mediaShortcodeOptions', array(maxUtils::namespaceit('maxButtonsAdmin'), 'mediaShortcodeOptions'));
114 - add_action('maxbuttons/ajax/save_review_notice_status', array(maxUtils::namespaceit('maxAdmin'), "setReviewNoticeStatus") );
73 + add_action("wp_ajax_getAjaxButtons", array(maxUtils::namespaceit('maxButtonsAdmin'), 'getAjaxButtons'));
74 + add_action("wp_ajax_set_review_notice_status", array($this, "setReviewNoticeStatus"));
115 75
116 - //add_action("wp_ajax_set_review_notice_status", array($this, "setReviewNoticeStatus"));
76 + // Collection AJAX
77 + add_action("wp_ajax_collection-edit", array(maxUtils::namespaceit("maxCollections"), "ajax_save"));
78 + add_action('wp_ajax_mbpro_collection_block', array(maxUtils::namespaceit("maxCollections"), "ajax_action")); // all block level ajax stuff - for logged in users - backend
117 79 add_action('wp_ajax_mb_button_action', array(maxUtils::namespaceit('maxButtons'), "ajax_action"));
118 80
119 81 add_action('wp_ajax_maxajax', array(maxUtils::namespaceit('maxUtils'), 'ajax_action'));
120 -
121 - add_action('admin_init', array($this,'init_wp_editor_options') );
122 82 }
83 + // FRONT AJAX
84 + add_action('wp_ajax_mbpro_collection_block_front', array(maxUtils::namespaceit("maxCollections"), "ajax_action_front")); // front end for all users
85 + add_action('wp_ajax_nopriv_mbpro_collection_block_front', array(maxUtils::namespaceit("maxCollections"), "ajax_action_front"));
123 86
124 -
125 - add_action('wp_ajax_maxbuttons_front_css', array(maxUtils::namespaceit('maxButtons'), 'generate_css'));
126 - add_action('wp_ajax_nopriv_maxbuttons_front_css', array(maxUtils::namespaceit('maxButtons'), 'generate_css'));
127 -
128 87 // front scripts
129 88 add_action('wp_enqueue_scripts', array($this, 'front_scripts'));
130 - //add_action('wp_enqueue_scripts', array(maxUtils::namespaceit('maxUtils'), 'fixFAConflict'),999);
89 + add_action('wp_enqueue_scripts', array(maxUtils::namespaceit('maxUtils'), 'fixFAConflict'),999);
131 90
132 91 $this->setMainClasses(); // struct for override functionality
133 92
134 93 // The second the blocks are being loaded, check dbase integrity
@@ -135,9 +94,13 @@
135 94 add_action("mb_blockclassesloaded", array($this, "check_database"));
136 95
137 96 // setup page hooks and shortcode
138 97 add_shortcode('maxcollection', array($this, 'collection_shortcode'));
98 + if (! is_admin())
99 + $hook_bool = maxCollections::setupHooks(); // setup the hooks to insert collections
139 100
101 + self::$instance = $this;
102 + maxIntegrations::init(); // fire the integrations.
140 103 }
141 104
142 105 public static function getInstance()
143 106 {
@@ -152,9 +115,12 @@
152 115 "block" => "maxBlock",
153 116 "admin" => "maxButtonsAdmin",
154 117 "install" => "maxInstall",
155 118 "groups" => "maxGroups",
119 + "collections" => "maxCollections",
120 + "collection" => "maxCollection",
156 121 "pack" => "maxPack",
122 +
157 123 );
158 124
159 125 $this->mainClasses = $classes;
160 126 }
@@ -174,8 +140,9 @@
174 140 global $wpdb;
175 141 $wpdb->hide_errors();
176 142 $result = $wpdb->get_results($sql);
177 143
144 +
178 145 // check this query for errors. If there is an error, one or more database fields are missing. Fix that.
179 146 if (isset($wpdb->last_error) && $wpdb->last_error != '')
180 147 {
181 148
@@ -183,8 +150,9 @@
183 150 $install::create_database_table();
184 151 $install::migrate();
185 152 }
186 153
154 +
187 155 maxUtils::addTime("End check database");
188 156 }
189 157
190 158 public function getClass($class)
@@ -235,9 +203,8 @@
235 203 return $options;
236 204
237 205 }
238 206
239 -
240 207 /** Returns the full path of the plugin installation directory */
241 208 public static function get_plugin_path()
242 209 {
243 210 return plugin_dir_path(MAXBUTTONS_ROOT_FILE);
@@ -278,19 +245,18 @@
278 245 add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, 81);
279 246
280 247 // We add this submenu page with the same slug as the parent to ensure we don't get duplicates
281 248 $sub_menu_title = __('Buttons', 'maxbuttons');
282 - $menu_slug = 'maxbuttons-controller';
283 249 $admin_pages[] = add_submenu_page($menu_slug, $page_title, $sub_menu_title, $capability, $menu_slug, $function);
284 250
285 251 // Now add the submenu page for the Add New page
286 252 $submenu_page_title = __('MaxButtons: Add/Edit Button', 'maxbuttons');
287 253 $submenu_title = __('Add New', 'maxbuttons');
288 - $submenu_slug = 'maxbuttons-button';
289 -
254 + $submenu_slug = 'maxbuttons-controller&action=edit';
290 255 //$submenu_function = 'maxbuttons_button';
291 256 $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function);
292 257
258 +
293 259 // Now add the submenu page for the Go Pro page
294 260 $submenu_page_title = __('MaxButtons: Upgrade to Pro', 'maxbuttons');
295 261 $submenu_title = __('Upgrade to Pro', 'maxbuttons');
296 262 $submenu_slug = 'maxbuttons-pro';
@@ -310,110 +276,44 @@
310 276 $submenu_slug = 'maxbuttons-support';
311 277 //$submenu_function = 'maxbuttons_support';
312 278 $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $admin_capability, $submenu_slug, $submenu_function);
313 279
314 - if (! MaxInstall::hasAddon('socialshare'))
315 - {
316 - $submenu_page_title = __('MaxButtons: Share Buttons', 'maxbuttons');
317 - $submenu_title = __('Share Buttons', 'maxbuttons');
318 - $submenu_slug = 'social-share';
319 - $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function);
320 - }
280 + // Now add the submenu page for the Export page
281 + $submenu_page_title = __('MaxButtons: Share Buttons', 'maxbuttons');
282 + $submenu_title = __('Share Buttons', 'maxbuttons');
283 + $submenu_slug = 'maxbuttons-collections';
284 + $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function);
285 +
321 286 }
322 287
323 - function load_admin_page()
288 + function load_admin_page($page)
324 289 {
325 290 $page = sanitize_text_field($_GET["page"]);
326 291
327 - if ($page == 'maxbuttons-controller')
328 - {
329 - $action = isset($_GET['action']) ? sanitize_text_field($_GET['action']) : null;
330 - if (! is_null($action))
331 - {
332 - $page = 'maxbuttons-list'; // default;
333 -
334 - if ($action == 'button' || $action == 'edit')
335 - {
336 - $page = 'maxbuttons-button';
337 - }
338 -
339 - }
340 - }
341 -
342 292 switch($page)
343 293 {
344 294 case "maxbuttons-button":
345 - $controller = new editorController();
295 + $pagepath = "includes/maxbuttons-button.php";
346 296 break;
347 297 case "maxbuttons-support":
348 - $controller = new supportController();
298 + $pagepath = "includes/maxbuttons-support.php";
349 299 break;
350 300 case "maxbuttons-settings":
351 - $controller = new settingsController();
301 + $pagepath = "includes/maxbuttons-settings.php";
352 302 break;
353 303 case "maxbuttons-pro":
354 - case "social-share":
355 - $controller = new upgradeController();
304 + $pagepath = "includes/maxbuttons-pro.php";
356 305 break;
306 + case "maxbuttons-collections":
307 + $pagepath = "includes/maxbuttons-collections.php";
308 + break;
357 309 default:
358 - $controller = new listController();
310 + $pagepath = "includes/maxbuttons-controller.php";
359 311 break;
360 312 }
361 - //$pagepath = $this->plugin_path . $pagepath;
362 - $controller->setPage($page);
363 - $controller->view();
364 - // include(apply_filters("mb-load-admin-page-$page", $pagepath));
365 - }
313 + $pagepath = $this->plugin_path . $pagepath;
366 314
367 - /** Load a library. This can be a non-standard Javascript / CSS combination or external PHP scripting
368 - *
369 - * @param $libname String Known library name
370 - */
371 - public function load_library($libname)
372 - {
373 - $version = MAXBUTTONS_VERSION_NUM;
374 - $js_url = trailingslashit($this->plugin_url . 'js');
375 - if (! $this->debug_mode)
376 - $js_url .= 'min/';
377 -
378 - if ($libname == 'review_notice')
379 - {
380 - wp_register_style('maxbuttons-review-notice-css',$this->plugin_url . 'assets/css/review_notice.css', array(), $version);
381 - wp_register_script('maxbuttons-review-notice', $js_url . 'review-notice.js', array('jquery'), $version);
382 -
383 - $local = array();
384 - $local["ajaxurl"] = admin_url( 'admin-ajax.php' );
385 - $local['nonce'] = wp_create_nonce('maxajax');
386 - wp_localize_script('maxbuttons-review-notice', 'mb_ajax_review', $local);
387 -
388 - wp_enqueue_style('maxbuttons-review-notice-css');
389 - wp_enqueue_script('maxbuttons-review-notice');
390 - }
391 -
392 - if ($libname == 'scss')
393 - {
394 - // external libraries
395 - if ( version_compare(PHP_VERSION, '5.4', '<' ) )
396 - {
397 - require_once($this->get_plugin_path() . "assets/libraries/scssphp_legacy/scss.inc.php");
398 - }
399 - else
400 - {
401 - require_once($this->get_plugin_path() . "assets/libraries/scssphp/scss.inc.php");
402 - }
403 - }
404 -
405 - if ($libname == 'simple_template')
406 - {
407 - require_once($this->get_plugin_path() . "assets/libraries/simple-template/simple_template.php");
408 - }
409 -
410 - if ($libname == 'simplehtmldom')
411 - {
412 - if (! class_exists('simple_html_dom_node'))
413 - require_once($this->get_plugin_path() . "assets/libraries/simplehtmldom/simple_html_dom.php");
414 - }
415 -
315 + include(apply_filters("mb-load-admin-page-$page", $pagepath));
416 316 }
417 317
418 318
419 319 function add_admin_styles($hook) {
@@ -424,24 +324,19 @@
424 324 return;
425 325 }
426 326
427 327 $version = MAXBUTTONS_VERSION_NUM;
428 - //$this->load_library('fontawesome');
429 328
329 + $fa_url = apply_filters("mb_fa_url", $this->plugin_url . 'assets/libraries/font-awesome/css/font-awesome.min.css', array(), $version);
330 + if ($fa_url != false && $fa_url != '')
331 + {
332 + wp_register_style('mbpro-font-awesome', $fa_url, array(), $version);
333 + wp_enqueue_style('mbpro-font-awesome');
334 + }
335 +
430 336 wp_enqueue_style('wp-color-picker');
337 + wp_enqueue_style('maxbuttons-css', $this->plugin_url . 'assets/css/style.css', array(), $version);
431 338
432 - if (is_rtl())
433 - wp_register_style('maxbuttons-css', $this->plugin_url . 'assets/css/style.rtl.css', array(), $version);
434 - else
435 - wp_register_style('maxbuttons-css', $this->plugin_url . 'assets/css/style.css', array(), $version);
436 -
437 -
438 - wp_enqueue_style('maxbuttons-css');
439 -
440 - wp_register_style('mb-alpha-color', $this->plugin_url . 'assets/libraries/alpha-color/alpha-color-picker.css', array(), $version);
441 -
442 - wp_enqueue_style('mb-alpha-color');
443 -
444 339 }
445 340
446 341 /** Add Admin scripts
447 342 *
@@ -457,30 +352,44 @@
457 352 $js_url = trailingslashit($this->plugin_url . 'js');
458 353 if (! $this->debug_mode)
459 354 $js_url .= 'min/';
460 355
356 +
461 357 wp_enqueue_script('jquery-ui-draggable');
462 - wp_enqueue_script('wplink');
463 358
464 - 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);
359 + wp_enqueue_script('maxbutton-admin', $js_url . 'maxbuttons-admin.js', array('jquery', 'jquery-ui-draggable', 'maxbuttons-tabs','maxbuttons-modal', 'wp-color-picker', 'underscore'),$version, true);
360 + wp_enqueue_script('maxbutton-js-init', $js_url . 'init.js', array('maxbutton-admin','maxcollections','maxbuttons-modal'),$version, true);
361 + wp_enqueue_script('maxbuttons-tabs', $js_url . 'maxtabs.js', array('jquery'),$version, true);
362 + wp_enqueue_script('maxbuttons-responsive', $js_url . 'responsive.js', array('maxbutton-admin'), $version, true );
465 363
466 - wp_localize_script('maxbutton-admin', 'maxadmin_settings', array(
467 - 'homeurl' => home_url(),
468 - ));
364 + wp_register_script('maxbuttons-ajax', $js_url . 'maxajax.js', array('maxbutton-admin'), $version, true);
365 + wp_localize_script('maxbuttons-ajax', 'maxajax',
366 + array(
367 + 'ajax_url' => admin_url( 'admin-ajax.php' ),
368 + 'ajax_action' => 'maxajax',
369 + 'nonce' => wp_create_nonce('maxajax'),
370 + ));
469 371
470 - wp_register_script('maxbutton-alpha-picker', $this->plugin_url . 'assets/libraries/alpha-color/alpha-color-picker.js', array('jquery', 'wp-color-picker'), $version, true);
372 + wp_enqueue_script('maxbuttons-ajax');
471 373
472 - wp_enqueue_script('maxbutton-alpha-picker');
473 - wp_enqueue_script('maxbutton-admin');
474 - wp_enqueue_script('maxbutton-js-init', $js_url . 'init.js', array('maxbutton-admin'),$version, true);
475 - wp_enqueue_script('maxbuttons-tabs', $js_url . 'maxtabs.js', array('jquery') ,$version, true);
476 - wp_enqueue_script('maxbuttons-responsive', $js_url . 'responsive.js', array('jquery'), $version, true );
374 + wp_register_script('maxcollections', $js_url . 'maxcollections.js',
375 + array('jquery', 'maxbutton-admin', 'jquery-ui-sortable'),$version, true );
477 376
478 - wp_enqueue_style('editor-buttons'); // style for WP-link
377 + $local = array();
378 + $local["ajaxurl"] = admin_url( 'admin-ajax.php' );
379 + $local["maxurl"] = $this->plugin_url;
380 + wp_localize_script('maxbutton-admin', 'mb_ajax', $local);
479 381
382 + $local = array(
383 + "leave_page" => __("You have unsaved data, are you sure you want to leave the page?","maxbuttons"),
384 + 'picker_title' => __('Select your buttons','maxbuttons'),
480 385
481 - $this->load_ajax_script();
386 + );
387 + wp_localize_script('maxcollections', 'maxcol_wp', $local);
388 +
482 389 $this->load_modal_script();
390 +
391 + wp_enqueue_script('maxcollections');
483 392 }
484 393
485 394 /** Load the Modal Script
486 395 * The modal script is the generic solution for all popups within the plugin.
@@ -502,35 +411,10 @@
502 411 );
503 412 wp_localize_script('maxbuttons-modal', 'modaltext', $translations);
504 413 wp_enqueue_script('maxbuttons-modal');
505 414
506 - wp_enqueue_style('maxbuttons-maxmodal', $this->plugin_url . 'assets/css/maxmodal.css', array(), $version);
507 -
508 415 }
509 416
510 - /** Load MaxAjax services
511 - *
512 - * MaxButtons Ajax Library.
513 - */
514 - public function load_ajax_script()
515 - {
516 - $version = MAXBUTTONS_VERSION_NUM;
517 - $js_url = trailingslashit($this->plugin_url . 'js');
518 - if (! $this->debug_mode)
519 - $js_url .= 'min/';
520 -
521 - wp_register_script('maxbuttons-ajax', $js_url . 'maxajax.js', array('jquery'), $version, true);
522 - wp_localize_script('maxbuttons-ajax', 'maxajax',
523 - array(
524 - 'ajax_url' => admin_url( 'admin-ajax.php' ),
525 - 'ajax_action' => 'maxajax',
526 - 'nonce' => wp_create_nonce('maxajax'),
527 - 'leave_page' => __("You have unsaved data, are you sure you want to leave the page?","maxbuttons"),
528 - ));
529 -
530 - wp_enqueue_script('maxbuttons-ajax');
531 - }
532 -
533 417 /** Load Media Buttons Script
534 418 *
535 419 * Useful for integrations that don't implement the media button but uses the media button JS for loading the button picker
536 420 *
@@ -542,18 +426,20 @@
542 426 $js_url = trailingslashit($this->plugin_url . 'js');
543 427 if (! $this->debug_mode)
544 428 $js_url .= 'min/';
545 429
546 - wp_register_script('mb-media-button', $js_url . 'media_button.js', array('jquery', 'maxbuttons-modal', 'maxbuttons-ajax'), $version, true);
430 + $fa_url = apply_filters("mb_fa_url", $this->plugin_url . 'assets/libraries/font-awesome/css/font-awesome.min.css');
431 + if ($fa_url != false && $fa_url != '')
432 + {
433 + wp_register_style('mbpro-font-awesome', $fa_url, array(), $version);
434 + wp_enqueue_style('mbpro-font-awesome');
435 + }
547 436
437 + wp_enqueue_script('mb-media-button', $js_url . 'maxbuttons_media_button.js', array('jquery', 'maxbuttons-modal'), $version, true);
548 438 $this->load_modal_script();
549 - $this->load_ajax_script();
550 439
551 - wp_add_inline_script( 'maxbuttons-modal', '$ = jQuery;' );
552 -
553 440 $translations = array(
554 441 'insert' => __('Insert Button into Editor', 'maxbuttons'),
555 - 'use' => __('Use this Button', 'maxbuttons'),
556 442 'loading' => __("Loading your buttons","maxbuttons"),
557 443 'select' => __('Click on a button from the list below to place the button shortcode in the editor.', 'maxbuttons'),
558 444 'cancel' => __('Cancel', 'maxbuttons'),
559 445 'windowtitle' => __("Select a MaxButton","maxbuttons"),
@@ -565,89 +451,32 @@
565 451 'short_add_button' => __('Add to Editor', 'maxbuttons'),
566 452 );
567 453
568 454 wp_localize_script('mb-media-button','mbtrans', $translations);
569 - wp_enqueue_script('mb-media-button');
570 -
571 - wp_enqueue_style('maxbuttons-media-button', $this->plugin_url . 'assets/css/media_button.css', array(), $version);
572 -
573 -
574 455 }
575 456
576 - /** Inits the options for WP editor, like tinymce and other buttons **/
577 - public function init_wp_editor_options()
578 - {
579 - /*if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
580 - return;
581 - } */
582 - // option
583 - if (get_option('maxbuttons_noshowtinymce') == 1) return;
457 + /** Load Media Button in WP editor
458 + *
459 + * The 'add button' interface in WP post and page editor to simplify adding buttons. Loads button plus required Javascript.
460 + */
461 + function media_button($editor_id) {
462 + $output = '';
584 463
585 - // Media buttons
586 - add_action('media_buttons', array($this,'media_button'), 20);
464 + // options
465 + if (get_option('maxbuttons_noshowtinymce') == 1) return;
587 466
588 - add_filter('mce_buttons', array($this, 'tinymce_button'));
589 - add_filter('mce_external_plugins', array($this, 'add_tinymce_button'));
467 + $this->load_media_script();
590 468
591 - /* add_action('before_wp_tiny_mce', function($settings) {
592 - $icon_url = MB()->get_plugin_url() . 'images/mb-peach-32.png';
593 - echo "<script type='text/javascript'>
594 - var maxButtonsTinyMCE = {
595 - 'icon': '$icon_url'
596 - };
597 - </script>";
598 - });
599 -*/
469 + // Only run in post/page creation and edit screens
600 470
601 - }
471 + $title = __('Add Button', 'maxbuttons');
472 + $icon = $this->plugin_url . 'images/mb-peach-icon.png';
473 + $img = '<span class="wp-media-buttons-icon" style="background-image: url(' . $icon . '); width: 16px; height: 16px; margin-top: 1px;"></span>';
474 + $output = '<a href="javascript:void(0);" class="button maxbutton_media_button" data-callback="window.maxMedia.showShortcodeOptions" title="' . $title . '" style="padding-left: .4em;">' . $img . ' ' . $title . '</a>';
602 475
603 - /** Load Media Button in WP editor
604 - *
605 - * The 'add button' interface in WP post and page editor to simplify adding buttons. Loads button plus required Javascript.
606 - */
607 - function media_button($editor_id) {
608 - $output = '';
609 -
610 - $this->load_media_script();
611 -
612 - // Only run in post/page creation and edit screens
613 -
614 - $title = __('Add Button', 'maxbuttons');
615 - $icon = $this->plugin_url . 'images/mb-peach-icon.png';
616 - //$nonce = wp_create_nonce('maxajax');
617 - $img = '<span class="wp-media-buttons-icon" style="background-image: url(' . $icon . '); width: 16px; height: 16px; margin-top: 1px;"></span>';
618 - //$img = '';
619 - $output = '<button id="maxbutton-add-button" type="button" class="button maxbutton_media_button" onclick="var mm = new window.maxFoundry.maxMedia();
620 - mm.init();
621 - mm.openModal();"
622 - title="' . $title . '" style="padding-left: .4em;" data-editor=' . $editor_id . '>' . $img . ' ' . $title . '</button>';
623 -
624 - echo $output;
476 + echo $output;
625 477 }
626 478
627 - public function tinymce_button($buttons)
628 - {
629 -
630 - $buttons[] = 'maxbutton';
631 - return $buttons;
632 - }
633 -
634 - public function add_tinymce_button($plugin_array)
635 - {
636 - $js_url = trailingslashit($this->plugin_url . 'js');
637 - if (! $this->debug_mode)
638 - $js_url .= 'min/';
639 -
640 - $this->load_media_script(); // enqueue button handler
641 -
642 -
643 - $plugin_array['maxButtons_tinymce'] = $js_url . 'tinymce.js' ;
644 - return $plugin_array;
645 -
646 - }
647 -
648 -
649 -
650 479 /** Scripts run on front-end
651 480 * Load font-awesome, and limited javascript for the front-end. This is being kept extremely limited for performance reasons.
652 481 */
653 482 public function front_scripts()
@@ -653,8 +482,15 @@
653 482 public function front_scripts()
654 483 {
655 484 $version = MAXBUTTONS_VERSION_NUM;
656 485
486 + $fa_url = apply_filters("mb_fa_url", $this->plugin_url . 'assets/libraries/font-awesome/css/font-awesome.min.css');
487 + if ($fa_url != false && $fa_url != '')
488 + {
489 + wp_register_style('mbpro-font-awesome', $fa_url, array(), $version);
490 + wp_enqueue_style('mbpro-font-awesome');
491 + }
492 +
657 493 // load backend script on front in Beaver Builder
658 494 if (isset($_GET['fl_builder']))
659 495 {
660 496 $this->add_admin_styles('maxbuttons');
@@ -659,13 +495,13 @@
659 495 {
660 496 $this->add_admin_styles('maxbuttons');
661 497 }
662 498
663 - /*wp_enqueue_script('maxbuttons-front', $this->plugin_url . 'js/min/front.js', array('jquery'), $version);
499 + wp_enqueue_script('maxbuttons-front', $this->plugin_url . 'js/min/front.js', array('jquery'), $version);
664 500 $local = array();
665 - $local["ajaxurl"] = admin_url( 'admin-ajax.php' ); */
501 + $local["ajaxurl"] = admin_url( 'admin-ajax.php' );
666 502
667 - //wp_localize_script('maxbuttons-front', 'mb_ajax', $local);
503 + wp_localize_script('maxbuttons-front', 'mb_ajax', $local);
668 504 }
669 505
670 506 /** Extra text to display in admin footer */
671 507 function admin_footer_text($text)
@@ -683,9 +519,9 @@
683 519 return $text;
684 520
685 521 }
686 522
687 - /** Function for maxbuttons shortcode */
523 +
688 524 function shortcode($atts)
689 525 {
690 526 $button = $this->getClass("button");
691 527 return $button->shortcode($atts);
@@ -690,13 +526,32 @@
690 526 $button = $this->getClass("button");
691 527 return $button->shortcode($atts);
692 528 }
693 529
694 - /** Function for collection shortcode [deprecated] **/
695 530 public function collection_shortcode($atts, $content = null)
696 531 {
697 - return false; // no more. silent fail.
532 + $atts = shortcode_atts(array(
533 + "id" => 0,
534 + "name" => '',
535 + "nocache" => false, // these are button options.
536 + "mode" => "normal",
537 + "style" => "footer",
538 + ),
698 539
540 + $atts);
541 +
542 + $id = intval($atts["id"]);
543 + $name = sanitize_text_field($atts["name"]);
544 +
545 + if ($id > 0)
546 + $collection = maxCollections::getCollectionByID($id);
547 + elseif ($atts["name"] != '')
548 + $collection = maxCollections::getCollectionByName($name);
549 +
550 +
551 + if ($collection)
552 + return $collection->shortcode($atts,$content);
553 +
699 554 }
700 555
701 556
702 557 function plugin_action_links($links, $file) {
@@ -719,63 +574,116 @@
719 574 return $links;
720 575 }
721 576
722 577
723 - function do_footer($id, $code, $type = "css")
724 - {
725 - $this->footer[$type][$id] = $code;
726 - }
578 + function do_footer($id, $code, $type = "css")
579 + {
727 580
581 + $this->footer[$type][$id] = $code;
728 582
729 - /** Output footer styles and scripts
730 - *
731 - * Outputs loaded styles, and scripts to the footer for display. Email_off is to prevent cloudfare from 'obfuscating' the minified CSS
732 - * No optimize prevent autoptimize from mutilating the already optimized CSS.
733 - */
734 - function footer()
735 - {
736 - if(count($this->footer) == 0) return; // nothing
583 + }
584 + function footer()
585 + {
586 + if(count($this->footer) == 0) return; // nothing
737 587
738 - $button_ids = array();
739 - $use_file = get_option('maxbuttons_usecssfile', false);
740 -
741 - foreach ($this->footer as $type => $part)
742 - {
743 - if ($type == 'css' && $use_file) // use file output to a CSS filebased output, don't put it inline.
588 + foreach ($this->footer as $type => $part)
744 589 {
745 - foreach($part as $id => $statements)
590 + // add tag
591 + if ($type == 'css')
746 592 {
747 - if (is_numeric($id))
748 - $button_ids[] = $id;
749 - else
750 - echo "nonum $id";
593 + echo "<!--email_off--><style type='text/css'>";
751 594 }
752 - continue;
595 + foreach ($part as $id => $statements)
596 + {
597 + if (strlen($statements) > 0) // prevent whitespace
598 + echo $statements . "\n";
599 + }
600 + if ($type == 'css')
601 + {
602 + echo "</style><!--/email_off-->\n";
603 + }
753 604 }
754 605
755 - // add tag
756 - if ($type == 'css')
606 + }
607 +
608 + public function do_review_notice () {
609 +
610 + $current_user_id = get_current_user_id();
611 + $version = MAXBUTTONS_VERSION_NUM;
612 +
613 + $review = get_user_meta( $current_user_id, 'maxbuttons_review_notice' , true );
614 +
615 + if ($review == '')
616 + {
617 + //$created = get_option("MBFREE_CREATED");
618 + $show = time() + (7* DAY_IN_SECONDS);
619 + update_user_meta($current_user_id, 'maxbuttons_review_notice', $show);
620 + return;
621 + }
622 +
623 +
624 + $display_review = false;
625 +
626 + if ($review == 'off')
627 + { return; // no show
628 +
629 + }
630 + elseif (is_numeric($review))
631 + {
632 + $now = time();
633 +
634 + if ($now > $review)
635 + {
636 + $display_review = true;
637 +
638 + }
639 + }
640 +
641 + // load style / script. It's seperated since it should show everywhere in admin.
642 + if ($display_review)
643 + {
644 + add_action( 'admin_notices', array( maxUtils::namespaceit('maxAdmin'), 'mb_review_notice'));
645 + wp_enqueue_style('maxbuttons-review-notice', $this->plugin_url . 'assets/css/review_notice.css', array(), $version);
646 + wp_enqueue_script('maxbuttons-review-notice', $this->plugin_url . 'js/min/review-notice.js', array('jquery'), $version);
647 +
648 + $local = array();
649 + $local["ajaxurl"] = admin_url( 'admin-ajax.php' );
650 + wp_localize_script('maxbuttons-review-notice', 'mb_ajax_review', $local);
651 + }
652 +
653 + }
654 +
655 + public function setReviewNoticeStatus()
656 + {
657 + $status = isset($_POST["status"]) ? sanitize_text_field($_POST["status"]) : '';
658 + $current_user_id = get_current_user_id();
659 +
660 + $updated = false;
661 +
662 + if ($status == 'off')
757 663 {
758 - echo "<!--noptimize--><!--email_off--><style type='text/css'>";
664 + $updated = true;
665 + update_user_meta($current_user_id, 'maxbuttons_review_notice', 'off');
666 +
759 667 }
668 + if ($status == 'later')
669 + {
670 + $updated = true;
671 + $later = time() + (14 * DAY_IN_SECONDS );
760 672
761 - foreach ($part as $id => $statements)
762 - {
763 - if (strlen($statements) > 0) // prevent whitespace
764 - echo $statements . "\n";
765 - }
673 + update_user_meta($current_user_id, 'maxbuttons_review_notice', $later);
674 + }
675 + if ($status == 'reviewoffer-dismiss') // different ad!
676 + {
677 + $updated = true;
678 + update_user_meta($current_user_id, 'maxbuttons_review_offer', 'off');
766 679
767 - if ($type == 'css')
768 - {
769 - echo "</style><!--/email_off--><!--/noptimize-->\n";
770 680 }
771 - }
772 681
773 - if (is_array($button_ids) && count($button_ids) > 0 && $use_file)
774 - {
775 - wp_enqueue_style('maxbuttons-front', admin_url('admin-ajax.php').'?action=maxbuttons_front_css&id=' . implode(',',array_unique($button_ids)) );
682 + echo json_encode(array("updated" => $updated)) ;
683 +
684 + exit();
776 685 }
777 - }
778 686
779 687 /* Add a notice
780 688
781 689 The added notice will be displayed to the user in WordPress format.