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

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