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
maxbuttons / classes / maxbuttons-class.php

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

741 lines 23.4 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
10 protected $installed_version = 0;
11 protected $plugin_name;
12 protected $plugin_url;
13 protected $plugin_path;
14 protected $debug_mode = false;
15 protected $footer = array();
16
17 protected static $notices = array();
18
19 protected $mainClasses = array();
20
21 protected static $instance;
22
23 /* Class constructor
24 Add hooks and actions used by this plugin. Sets plugin environment information
25 */
26 function __construct()
27 {
28 maxUtils::timeInit(); // benchmark timer init.
29
30 $this->plugin_url = self::get_plugin_url(); //plugins_url() . '/' . $this->plugin_name;
31 $this->plugin_path = self::get_plugin_path(); //plugin_dir_path($rootfile);
32 $this->plugin_name = trim(basename($this->plugin_path), '/');
33
34 $this->installed_version = get_option(MAXBUTTONS_VERSION_KEY);
35
36 if ( defined('MAXBUTTONS_DEBUG') && MAXBUTTONS_DEBUG)
37 $this->debug_mode = true;
38
39 add_action('plugins_loaded', array($this, 'load_textdomain'));
40
41 add_filter('widget_text', 'do_shortcode');
42 add_shortcode('maxbutton', array($this, 'shortcode'));
43
44 add_action("mb-footer", array($this, 'do_footer'),10,3);
45 add_action("wp_footer", array($this, "footer"));
46
47 // Media buttons
48 add_action('media_buttons', array($this,'media_button'));
49
50 add_filter('plugin_action_links', array($this, "plugin_action_links"), 10, 2);
51 add_filter('plugin_row_meta', array($this, 'plugin_row_meta'), 10, 2);
52
53 if( is_admin())
54 {
55 add_action('admin_enqueue_scripts', array($this,'add_admin_styles'));
56 add_action('admin_enqueue_scripts', array($this,'add_admin_scripts'));
57 add_action('admin_enqueue_scripts', array(maxUtils::namespaceit('maxUtils'), 'fixFAConflict'),999);
58
59 add_action('admin_init', array($this,'register_settings' ));
60
61 add_action('admin_init', array($this, 'do_review_notice')); // Ask for review
62 add_action('admin_init', array(maxUtils::namespaceit('maxInstall'),'check_database'));
63
64 add_action('admin_menu', array($this, 'admin_menu'));
65 add_action('admin_footer', array($this, "footer"));
66 add_filter("admin_footer_text",array($this, "admin_footer_text"));
67
68 // errors in user space. No internal error but user output friendly issues
69 add_action("mb/editor/display_notices", array($this,"display_notices"), 99);
70 add_action("mb/collection/display_notices", array($this,"display_notices"), 99);
71 add_action('mb/header/display_notices', array($this, 'display_notices'), 99);
72
73 add_action("wp_ajax_getAjaxButtons", array(maxUtils::namespaceit('maxButtonsAdmin'), 'getAjaxButtons'));
74 add_action("wp_ajax_set_review_notice_status", array($this, "setReviewNoticeStatus"));
75
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
79 add_action('wp_ajax_mb_button_action', array(maxUtils::namespaceit('maxButtons'), "ajax_action"));
80
81 add_action('wp_ajax_maxajax', array(maxUtils::namespaceit('maxUtils'), 'ajax_action'));
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"));
86
87 // front scripts
88 add_action('wp_enqueue_scripts', array($this, 'front_scripts'));
89 add_action('wp_enqueue_scripts', array(maxUtils::namespaceit('maxUtils'), 'fixFAConflict'),999);
90
91 $this->setMainClasses(); // struct for override functionality
92
93 // The second the blocks are being loaded, check dbase integrity
94 add_action("mb_blockclassesloaded", array($this, "check_database"));
95
96 // setup page hooks and shortcode
97 add_shortcode('maxcollection', array($this, 'collection_shortcode'));
98 if (! is_admin())
99 $hook_bool = maxCollections::setupHooks(); // setup the hooks to insert collections
100
101 self::$instance = $this;
102 maxIntegrations::init(); // fire the integrations.
103 }
104
105 public static function getInstance()
106 {
107 return self::$instance;
108 }
109
110 public function setMainClasses()
111 {
112 $classes = array(
113 "button" => "maxButton",
114 "buttons" => "maxButtons",
115 "block" => "maxBlock",
116 "admin" => "maxButtonsAdmin",
117 "install" => "maxInstall",
118 "groups" => "maxGroups",
119 "collections" => "maxCollections",
120 "collection" => "maxCollection",
121 "pack" => "maxPack",
122
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 // 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
286 }
287
288 function load_admin_page($page)
289 {
290 $page = sanitize_text_field($_GET["page"]);
291
292 switch($page)
293 {
294 case "maxbuttons-button":
295 $pagepath = "includes/maxbuttons-button.php";
296 break;
297 case "maxbuttons-support":
298 $pagepath = "includes/maxbuttons-support.php";
299 break;
300 case "maxbuttons-settings":
301 $pagepath = "includes/maxbuttons-settings.php";
302 break;
303 case "maxbuttons-pro":
304 $pagepath = "includes/maxbuttons-pro.php";
305 break;
306 case "maxbuttons-collections":
307 $pagepath = "includes/maxbuttons-collections.php";
308 break;
309 default:
310 $pagepath = "includes/maxbuttons-controller.php";
311 break;
312 }
313 $pagepath = $this->plugin_path . $pagepath;
314
315 include(apply_filters("mb-load-admin-page-$page", $pagepath));
316 }
317
318
319 function add_admin_styles($hook) {
320 // only hook in maxbuttons realm.
321 if ( strpos($hook,'maxbuttons') === false && $hook != 'post.php' && $hook != 'post-new.php' )
322 {
323 if (! isset($_GET['fl_builder'])) // exception for beaver builder
324 return;
325 }
326
327 $version = MAXBUTTONS_VERSION_NUM;
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
336 wp_enqueue_style('wp-color-picker');
337 wp_enqueue_style('maxbuttons-css', $this->plugin_url . 'assets/css/style.css', array(), $version);
338
339 }
340
341 /** Add Admin scripts
342 *
343 * Uses WP hook for Admin scripts to add needed js.
344 */
345 function add_admin_scripts($hook) {
346 // only hook in maxbuttons realm.
347 if ( strpos($hook,'maxbuttons') === false ) //&& $hook != 'post.php' && $hook != 'post-new.php'
348 return;
349
350 $version = MAXBUTTONS_VERSION_NUM;
351
352 $js_url = trailingslashit($this->plugin_url . 'js');
353 if (! $this->debug_mode)
354 $js_url .= 'min/';
355
356
357 wp_enqueue_script('jquery-ui-draggable');
358
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 );
363
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 ));
371
372 wp_enqueue_script('maxbuttons-ajax');
373
374 wp_register_script('maxcollections', $js_url . 'maxcollections.js',
375 array('jquery', 'maxbutton-admin', 'jquery-ui-sortable'),$version, true );
376
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);
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'),
385
386 );
387 wp_localize_script('maxcollections', 'maxcol_wp', $local);
388
389 $this->load_modal_script();
390
391 wp_enqueue_script('maxcollections');
392 }
393
394 /** Load the Modal Script
395 * The modal script is the generic solution for all popups within the plugin.
396 */
397 public function load_modal_script()
398 {
399 $version = MAXBUTTONS_VERSION_NUM;
400 $js_url = trailingslashit($this->plugin_url . 'js');
401 if (! $this->debug_mode)
402 $js_url .= 'min/';
403
404 wp_register_script('maxbuttons-modal', $js_url . 'maxmodal.js', array('jquery','jquery-ui-draggable'), $version, true);
405 // translations of controls and other elements that can be used in maxmodal
406 $translations = array(
407 'yes' => __("Yes","maxbuttons"),
408 'no' => __("No","maxbuttons"),
409 'ok' => __("OK","maxbuttons"),
410 'cancel' => __("Cancel","maxbuttons"),
411 );
412 wp_localize_script('maxbuttons-modal', 'modaltext', $translations);
413 wp_enqueue_script('maxbuttons-modal');
414
415 }
416
417 /** Load Media Buttons Script
418 *
419 * Useful for integrations that don't implement the media button but uses the media button JS for loading the button picker
420 *
421 */
422 public function load_media_script()
423 {
424 $version = MAXBUTTONS_VERSION_NUM;
425
426 $js_url = trailingslashit($this->plugin_url . 'js');
427 if (! $this->debug_mode)
428 $js_url .= 'min/';
429
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 }
436
437 wp_enqueue_script('mb-media-button', $js_url . 'maxbuttons_media_button.js', array('jquery', 'maxbuttons-modal'), $version, true);
438 $this->load_modal_script();
439
440 $translations = array(
441 'insert' => __('Insert Button into Editor', 'maxbuttons'),
442 'loading' => __("Loading your buttons","maxbuttons"),
443 'select' => __('Click on a button from the list below to place the button shortcode in the editor.', 'maxbuttons'),
444 'cancel' => __('Cancel', 'maxbuttons'),
445 'windowtitle' => __("Select a MaxButton","maxbuttons"),
446 'icon' => $this->plugin_url . 'images/mb-peach-32.png',
447 'ajax_url' => admin_url( 'admin-ajax.php' ),
448 'short_url_label' => __('Button URL', 'maxbuttons'),
449 'short_text_label' => __('Button Text', 'maxbuttons'),
450 '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'),
451 'short_add_button' => __('Add to Editor', 'maxbuttons'),
452 );
453
454 wp_localize_script('mb-media-button','mbtrans', $translations);
455 }
456
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 = '';
463
464 // options
465 if (get_option('maxbuttons_noshowtinymce') == 1) return;
466
467 $this->load_media_script();
468
469 // Only run in post/page creation and edit screens
470
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>';
475
476 echo $output;
477 }
478
479 /** Scripts run on front-end
480 * Load font-awesome, and limited javascript for the front-end. This is being kept extremely limited for performance reasons.
481 */
482 public function front_scripts()
483 {
484 $version = MAXBUTTONS_VERSION_NUM;
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
493 // load backend script on front in Beaver Builder
494 if (isset($_GET['fl_builder']))
495 {
496 $this->add_admin_styles('maxbuttons');
497 }
498
499 wp_enqueue_script('maxbuttons-front', $this->plugin_url . 'js/min/front.js', array('jquery'), $version);
500 $local = array();
501 $local["ajaxurl"] = admin_url( 'admin-ajax.php' );
502
503 wp_localize_script('maxbuttons-front', 'mb_ajax', $local);
504 }
505
506 /** Extra text to display in admin footer */
507 function admin_footer_text($text)
508 {
509 if (! isset($_GET["page"]))
510 return $text;
511
512 if ( strpos($_GET["page"],'maxbuttons') === false)
513 return $text;
514 $text = '';
515
516 $text .= sprintf("If you like MaxButtons please give us a %s�
517
518
519
520
521 %s rating!",
522 "<a href='https://wordpress.org/support/view/plugin-reviews/maxbuttons#postform' target='_blank'>",
523 "</a>") ;
524 return $text;
525
526 }
527
528
529 function shortcode($atts)
530 {
531 $button = $this->getClass("button");
532 return $button->shortcode($atts);
533 }
534
535 public function collection_shortcode($atts, $content = null)
536 {
537 $atts = shortcode_atts(array(
538 "id" => 0,
539 "name" => '',
540 "nocache" => false, // these are button options.
541 "mode" => "normal",
542 "style" => "footer",
543 ),
544
545 $atts);
546
547 $id = intval($atts["id"]);
548 $name = sanitize_text_field($atts["name"]);
549
550 if ($id > 0)
551 $collection = maxCollections::getCollectionByID($id);
552 elseif ($atts["name"] != '')
553 $collection = maxCollections::getCollectionByName($name);
554
555
556 if ($collection)
557 return $collection->shortcode($atts,$content);
558
559 }
560
561
562 function plugin_action_links($links, $file) {
563
564 if ($file == plugin_basename(dirname(MAXBUTTONS_ROOT_FILE) . '/maxbuttons.php')) {
565 $label = __('Buttons', 'maxbuttons');
566 $dashboard_link = '<a href="' . admin_url() . 'admin.php?page=maxbuttons-controller&action=list">' . $label . '</a>';
567 array_unshift($links, $dashboard_link);
568 }
569
570 return $links;
571 }
572
573
574 function plugin_row_meta($links, $file) {
575 if ($file == plugin_basename(dirname(__FILE__) . '/maxbuttons.php')) {
576 $links[] = sprintf(__('%sUpgrade to Pro Version%s', 'maxbuttons'), '<a href="http://maxbuttons.com/?ref=mbfree" target="_blank">', '</a>');
577 }
578
579 return $links;
580 }
581
582
583 function do_footer($id, $code, $type = "css")
584 {
585
586 $this->footer[$type][$id] = $code;
587
588 }
589 function footer()
590 {
591 if(count($this->footer) == 0) return; // nothing
592
593 foreach ($this->footer as $type => $part)
594 {
595 // add tag
596 if ($type == 'css')
597 {
598 echo "<!--email_off--><style type='text/css'>";
599 }
600 foreach ($part as $id => $statements)
601 {
602 if (strlen($statements) > 0) // prevent whitespace
603 echo $statements . "\n";
604 }
605 if ($type == 'css')
606 {
607 echo "</style><!--/email_off-->\n";
608 }
609 }
610
611 }
612
613 public function do_review_notice () {
614
615 $current_user_id = get_current_user_id();
616 $version = MAXBUTTONS_VERSION_NUM;
617
618 $review = get_user_meta( $current_user_id, 'maxbuttons_review_notice' , true );
619
620 if ($review == '')
621 {
622 //$created = get_option("MBFREE_CREATED");
623 $show = time() + (7* DAY_IN_SECONDS);
624 update_user_meta($current_user_id, 'maxbuttons_review_notice', $show);
625 return;
626 }
627
628
629 $display_review = false;
630
631 if ($review == 'off')
632 { return; // no show
633
634 }
635 elseif (is_numeric($review))
636 {
637 $now = time();
638
639 if ($now > $review)
640 {
641 $display_review = true;
642
643 }
644 }
645
646 // load style / script. It's seperated since it should show everywhere in admin.
647 if ($display_review)
648 {
649 add_action( 'admin_notices', array( maxUtils::namespaceit('maxAdmin'), 'mb_review_notice'));
650 wp_enqueue_style('maxbuttons-review-notice', $this->plugin_url . 'assets/css/review_notice.css', array(), $version);
651 wp_enqueue_script('maxbuttons-review-notice', $this->plugin_url . 'js/min/review-notice.js', array('jquery'), $version);
652
653 $local = array();
654 $local["ajaxurl"] = admin_url( 'admin-ajax.php' );
655 wp_localize_script('maxbuttons-review-notice', 'mb_ajax_review', $local);
656 }
657
658 }
659
660 public function setReviewNoticeStatus()
661 {
662 $status = isset($_POST["status"]) ? sanitize_text_field($_POST["status"]) : '';
663 $current_user_id = get_current_user_id();
664
665 $updated = false;
666
667 if ($status == 'off')
668 {
669 $updated = true;
670 update_user_meta($current_user_id, 'maxbuttons_review_notice', 'off');
671
672 }
673 if ($status == 'later')
674 {
675 $updated = true;
676 $later = time() + (14 * DAY_IN_SECONDS );
677
678 update_user_meta($current_user_id, 'maxbuttons_review_notice', $later);
679 }
680 if ($status == 'reviewoffer-dismiss') // different ad!
681 {
682 $updated = true;
683 update_user_meta($current_user_id, 'maxbuttons_review_offer', 'off');
684
685 }
686
687 echo json_encode(array("updated" => $updated)) ;
688
689 exit();
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