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

833 lines 25.8 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)
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 add_action('plugins_loaded', array($this, 'load_textdomain'));
81
82 add_filter('widget_text', 'do_shortcode');
83 add_shortcode('maxbutton', array($this, 'shortcode'));
84
85 add_action("mb-footer", array($this, 'do_footer'),10,3);
86 add_action("wp_footer", array($this, "footer"));
87
88 add_filter('plugin_action_links', array($this, "plugin_action_links"), 10, 2);
89 add_filter('plugin_row_meta', array($this, 'plugin_row_meta'), 10, 2);
90
91 if( is_admin())
92 {
93 add_action('admin_enqueue_scripts', array($this,'add_admin_styles'));
94 add_action('admin_enqueue_scripts', array($this,'add_admin_scripts'));
95 add_action('admin_enqueue_scripts', array(maxUtils::namespaceit('maxUtils'), 'fixFAConflict'),999);
96
97 add_action('admin_init', array($this,'register_settings' ));
98
99 add_action('admin_init', array(maxUtils::namespaceit('maxAdmin'), 'do_review_notice')); // Ask for review
100 add_action('admin_init', array(maxUtils::namespaceit('maxInstall'),'check_database'));
101
102 add_action('admin_menu', array($this, 'admin_menu'));
103 add_action('admin_footer', array($this, "footer"));
104 add_filter("admin_footer_text",array($this, "admin_footer_text"));
105
106 // errors in user space. No internal error but user output friendly issues
107 add_action("mb/editor/display_notices", array($this,"display_notices"), 99);
108 add_action("mb/collection/display_notices", array($this,"display_notices"), 99);
109 add_action('mb/header/display_notices', array($this, 'display_notices'), 99);
110
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") );
115
116 //add_action("wp_ajax_set_review_notice_status", array($this, "setReviewNoticeStatus"));
117 add_action('wp_ajax_mb_button_action', array(maxUtils::namespaceit('maxButtons'), "ajax_action"));
118
119 add_action('wp_ajax_maxajax', array(maxUtils::namespaceit('maxUtils'), 'ajax_action'));
120
121 add_action('admin_init', array($this,'init_wp_editor_options') );
122 }
123
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 // front scripts
129 add_action('wp_enqueue_scripts', array($this, 'front_scripts'));
130 //add_action('wp_enqueue_scripts', array(maxUtils::namespaceit('maxUtils'), 'fixFAConflict'),999);
131
132 $this->setMainClasses(); // struct for override functionality
133
134 // The second the blocks are being loaded, check dbase integrity
135 add_action("mb_blockclassesloaded", array($this, "check_database"));
136
137 // setup page hooks and shortcode
138 add_shortcode('maxcollection', array($this, 'collection_shortcode'));
139
140 }
141
142 public static function getInstance()
143 {
144 return self::$instance;
145 }
146
147 public function setMainClasses()
148 {
149 $classes = array(
150 "button" => "maxButton",
151 "buttons" => "maxButtons",
152 "block" => "maxBlock",
153 "admin" => "maxButtonsAdmin",
154 "install" => "maxInstall",
155 "groups" => "maxGroups",
156 "pack" => "maxPack",
157 );
158
159 $this->mainClasses = $classes;
160 }
161
162 // from block loader action. Checks if all parts of the table are there, or panic if not.
163 public function check_database($blocks)
164 {
165 maxUtils::addTime("Check database");
166
167 $sql = "SELECT id,name,status,cache, created ";
168 foreach ($blocks as $block => $class)
169 {
170 $sql .= ", $block";
171 }
172 $sql .= " from " . maxUtils::get_table_name() . " limit 1";
173
174 global $wpdb;
175 $wpdb->hide_errors();
176 $result = $wpdb->get_results($sql);
177
178 // check this query for errors. If there is an error, one or more database fields are missing. Fix that.
179 if (isset($wpdb->last_error) && $wpdb->last_error != '')
180 {
181
182 $install = $this->getClass("install");
183 $install::create_database_table();
184 $install::migrate();
185 }
186
187 maxUtils::addTime("End check database");
188 }
189
190 public function getClass($class)
191 {
192
193 if (isset($this->mainClasses[$class]))
194 {
195 $load_class = maxUtils::namespaceit($this->mainClasses[$class]);
196 if (method_exists($load_class,'getInstance'))
197 {
198 return $load_class::getInstance();
199 }
200 return new $load_class;
201 }
202 }
203
204 /* Load the plugin textdomain */
205 public function load_textdomain()
206 {
207 // see: http://geertdedeckere.be/article/loading-wordpress-language-files-the-right-way
208 $domain = 'maxbuttons';
209 // The "plugin_locale" filter is also used in load_plugin_textdomain()
210 $locale = apply_filters('plugin_locale', get_locale(), $domain);
211
212 load_textdomain($domain, WP_LANG_DIR.'/maxbuttons/'.$domain.'-'.$locale.'.mo');
213 $res = load_plugin_textdomain('maxbuttons', false, $this->plugin_name . '/languages/');
214
215 }
216
217
218 /** WP Settings framework. Registers settings used on maxbuttons-settings.php page */
219 public function register_settings()
220 {
221 register_setting( 'maxbuttons_settings', 'maxbuttons_user_level' );
222 register_setting( 'maxbuttons_settings', 'maxbuttons_noshowtinymce' );
223 register_setting( 'maxbuttons_settings', 'maxbuttons_minify' );
224 register_setting( 'maxbuttons_settings', 'maxbuttons_hidedescription' );
225 register_setting( 'maxbuttons_settings', 'maxbuttons_forcefa') ;
226 register_setting( 'maxbuttons_settings', 'maxbuttons_borderbox');
227 register_setting( 'maxbuttons_settings', 'maxbuttons_protocol');
228 }
229
230 protected function checkbox_option($options)
231 {
232 if (! isset($options["maxbuttons_minify"]))
233 $options["maxbuttons_minify"] = 0;
234
235 return $options;
236
237 }
238
239
240 /** Returns the full path of the plugin installation directory */
241 public static function get_plugin_path()
242 {
243 return plugin_dir_path(MAXBUTTONS_ROOT_FILE);
244 }
245
246 /** Returns the full URL of the plugin installation path */
247 public static function get_plugin_url()
248 {
249 $url = plugin_dir_url(MAXBUTTONS_ROOT_FILE);
250 return $url;
251 }
252
253 /** Returns the current installed version */
254 public function get_installed_version()
255 {
256 return $this->installed_version;
257 }
258
259 /** Installs and adds the main menu and the submenu items */
260 function admin_menu() {
261 $maxbuttons_capabilities = get_option('maxbuttons_user_level');
262 if(!$maxbuttons_capabilities) {
263 $maxbuttons_capabilities = 'manage_options';
264 settings_fields( 'maxbuttons_settings' );
265 update_option('maxbuttons_user_level', $maxbuttons_capabilities);
266 }
267 $admin_pages = array();
268
269 $page_title = __('MaxButtons: Buttons', 'maxbuttons');
270 $menu_title = __('MaxButtons', 'maxbuttons');
271 $capability = $maxbuttons_capabilities;
272 $admin_capability = 'manage_options';
273 $menu_slug = 'maxbuttons-controller';
274 $function = array($this, 'load_admin_page');
275 $icon_url = $this->plugin_url . 'images/mb-peach-icon.png';
276 $submenu_function = array($this, 'load_admin_page');
277
278 add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, 81);
279
280 // We add this submenu page with the same slug as the parent to ensure we don't get duplicates
281 $sub_menu_title = __('Buttons', 'maxbuttons');
282 $menu_slug = 'maxbuttons-controller';
283 $admin_pages[] = add_submenu_page($menu_slug, $page_title, $sub_menu_title, $capability, $menu_slug, $function);
284
285 // Now add the submenu page for the Add New page
286 $submenu_page_title = __('MaxButtons: Add/Edit Button', 'maxbuttons');
287 $submenu_title = __('Add New', 'maxbuttons');
288 $submenu_slug = 'maxbuttons-button';
289
290 //$submenu_function = 'maxbuttons_button';
291 $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function);
292
293 // Now add the submenu page for the Go Pro page
294 $submenu_page_title = __('MaxButtons: Upgrade to Pro', 'maxbuttons');
295 $submenu_title = __('Upgrade to Pro', 'maxbuttons');
296 $submenu_slug = 'maxbuttons-pro';
297 //$submenu_function = 'maxbuttons_pro';
298 $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function);
299
300 // Now add the submenu page for the Settings page
301 $submenu_page_title = __('MaxButtons: Settings', 'maxbuttons');
302 $submenu_title = __('Settings', 'maxbuttons');
303 $submenu_slug = 'maxbuttons-settings';
304 //$submenu_function = 'maxbuttons_settings';
305 $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $admin_capability, $submenu_slug, $submenu_function);
306
307 // Now add the submenu page for the Support page
308 $submenu_page_title = __('MaxButtons: Support', 'maxbuttons');
309 $submenu_title = __('Support', 'maxbuttons');
310 $submenu_slug = 'maxbuttons-support';
311 //$submenu_function = 'maxbuttons_support';
312 $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $admin_capability, $submenu_slug, $submenu_function);
313
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 }
321 }
322
323 function load_admin_page()
324 {
325 $page = sanitize_text_field($_GET["page"]);
326
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 switch($page)
343 {
344 case "maxbuttons-button":
345 $controller = new editorController();
346 break;
347 case "maxbuttons-support":
348 $controller = new supportController();
349 break;
350 case "maxbuttons-settings":
351 $controller = new settingsController();
352 break;
353 case "maxbuttons-pro":
354 case "social-share":
355 $controller = new upgradeController();
356 break;
357 default:
358 $controller = new listController();
359 break;
360 }
361 //$pagepath = $this->plugin_path . $pagepath;
362 $controller->setPage($page);
363 $controller->view();
364 // include(apply_filters("mb-load-admin-page-$page", $pagepath));
365 }
366
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
416 }
417
418
419 function add_admin_styles($hook) {
420 // only hook in maxbuttons realm.
421 if ( strpos($hook,'maxbuttons') === false && $hook != 'post.php' && $hook != 'post-new.php' )
422 {
423 if (! isset($_GET['fl_builder'])) // exception for beaver builder
424 return;
425 }
426
427 $version = MAXBUTTONS_VERSION_NUM;
428 //$this->load_library('fontawesome');
429
430 wp_enqueue_style('wp-color-picker');
431
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 }
445
446 /** Add Admin scripts
447 *
448 * Uses WP hook for Admin scripts to add needed js.
449 */
450 function add_admin_scripts($hook) {
451 // only hook in maxbuttons realm.
452 if ( strpos($hook,'maxbuttons') === false ) //&& $hook != 'post.php' && $hook != 'post-new.php'
453 return;
454
455 $version = MAXBUTTONS_VERSION_NUM;
456
457 $js_url = trailingslashit($this->plugin_url . 'js');
458 if (! $this->debug_mode)
459 $js_url .= 'min/';
460
461 wp_enqueue_script('jquery-ui-draggable');
462 wp_enqueue_script('wplink');
463
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);
465
466 wp_localize_script('maxbutton-admin', 'maxadmin_settings', array(
467 'homeurl' => home_url(),
468 ));
469
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);
471
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 );
477
478 wp_enqueue_style('editor-buttons'); // style for WP-link
479
480
481 $this->load_ajax_script();
482 $this->load_modal_script();
483 }
484
485 /** Load the Modal Script
486 * The modal script is the generic solution for all popups within the plugin.
487 */
488 public function load_modal_script()
489 {
490 $version = MAXBUTTONS_VERSION_NUM;
491 $js_url = trailingslashit($this->plugin_url . 'js');
492 if (! $this->debug_mode)
493 $js_url .= 'min/';
494
495 wp_register_script('maxbuttons-modal', $js_url . 'maxmodal.js', array('jquery','jquery-ui-draggable'), $version, true);
496 // translations of controls and other elements that can be used in maxmodal
497 $translations = array(
498 'yes' => __("Yes","maxbuttons"),
499 'no' => __("No","maxbuttons"),
500 'ok' => __("OK","maxbuttons"),
501 'cancel' => __("Cancel","maxbuttons"),
502 );
503 wp_localize_script('maxbuttons-modal', 'modaltext', $translations);
504 wp_enqueue_script('maxbuttons-modal');
505
506 wp_enqueue_style('maxbuttons-maxmodal', $this->plugin_url . 'assets/css/maxmodal.css', array(), $version);
507
508 }
509
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 /** Load Media Buttons Script
534 *
535 * Useful for integrations that don't implement the media button but uses the media button JS for loading the button picker
536 *
537 */
538 public function load_media_script()
539 {
540 $version = MAXBUTTONS_VERSION_NUM;
541
542 $js_url = trailingslashit($this->plugin_url . 'js');
543 if (! $this->debug_mode)
544 $js_url .= 'min/';
545
546 wp_register_script('mb-media-button', $js_url . 'media_button.js', array('jquery', 'maxbuttons-modal', 'maxbuttons-ajax'), $version, true);
547
548 $this->load_modal_script();
549 $this->load_ajax_script();
550
551 wp_add_inline_script( 'maxbuttons-modal', '$ = jQuery;' );
552
553 $translations = array(
554 'insert' => __('Insert Button into Editor', 'maxbuttons'),
555 'use' => __('Use this Button', 'maxbuttons'),
556 'loading' => __("Loading your buttons","maxbuttons"),
557 'select' => __('Click on a button from the list below to place the button shortcode in the editor.', 'maxbuttons'),
558 'cancel' => __('Cancel', 'maxbuttons'),
559 'windowtitle' => __("Select a MaxButton","maxbuttons"),
560 'icon' => $this->plugin_url . 'images/mb-peach-32.png',
561 'ajax_url' => admin_url( 'admin-ajax.php' ),
562 'short_url_label' => __('Button URL', 'maxbuttons'),
563 'short_text_label' => __('Button Text', 'maxbuttons'),
564 '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'),
565 'short_add_button' => __('Add to Editor', 'maxbuttons'),
566 );
567
568 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 }
575
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;
584
585 // Media buttons
586 add_action('media_buttons', array($this,'media_button'), 20);
587
588 add_filter('mce_buttons', array($this, 'tinymce_button'));
589 add_filter('mce_external_plugins', array($this, 'add_tinymce_button'));
590
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 */
600
601 }
602
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;
625 }
626
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 /** Scripts run on front-end
651 * Load font-awesome, and limited javascript for the front-end. This is being kept extremely limited for performance reasons.
652 */
653 public function front_scripts()
654 {
655 $version = MAXBUTTONS_VERSION_NUM;
656
657 // load backend script on front in Beaver Builder
658 if (isset($_GET['fl_builder']))
659 {
660 $this->add_admin_styles('maxbuttons');
661 }
662
663 /*wp_enqueue_script('maxbuttons-front', $this->plugin_url . 'js/min/front.js', array('jquery'), $version);
664 $local = array();
665 $local["ajaxurl"] = admin_url( 'admin-ajax.php' ); */
666
667 //wp_localize_script('maxbuttons-front', 'mb_ajax', $local);
668 }
669
670 /** Extra text to display in admin footer */
671 function admin_footer_text($text)
672 {
673 if (! isset($_GET["page"]))
674 return $text;
675
676 if ( strpos($_GET["page"],'maxbuttons') === false)
677 return $text;
678 $text = '';
679
680 $text .= sprintf("If you like MaxButtons please give us a %s�
681
682
683
684
685 %s rating!",
686 "<a href='https://wordpress.org/support/view/plugin-reviews/maxbuttons#postform' target='_blank'>",
687 "</a>") ;
688 return $text;
689
690 }
691
692 /** Function for maxbuttons shortcode */
693 function shortcode($atts)
694 {
695 $button = $this->getClass("button");
696 return $button->shortcode($atts);
697 }
698
699 /** Function for collection shortcode [deprecated] **/
700 public function collection_shortcode($atts, $content = null)
701 {
702 return false; // no more. silent fail.
703
704 }
705
706
707 function plugin_action_links($links, $file) {
708
709 if ($file == plugin_basename(dirname(MAXBUTTONS_ROOT_FILE) . '/maxbuttons.php')) {
710 $label = __('Buttons', 'maxbuttons');
711 $dashboard_link = '<a href="' . admin_url() . 'admin.php?page=maxbuttons-controller&action=list">' . $label . '</a>';
712 array_unshift($links, $dashboard_link);
713 }
714
715 return $links;
716 }
717
718
719 function plugin_row_meta($links, $file) {
720 if ($file == plugin_basename(dirname(__FILE__) . '/maxbuttons.php')) {
721 $links[] = sprintf(__('%sUpgrade to Pro Version%s', 'maxbuttons'), '<a href="http://maxbuttons.com/?ref=mbfree" target="_blank">', '</a>');
722 }
723
724 return $links;
725 }
726
727
728 function do_footer($id, $code, $type = "css")
729 {
730 $this->footer[$type][$id] = $code;
731 }
732
733
734 /** Output footer styles and scripts
735 *
736 * Outputs loaded styles, and scripts to the footer for display. Email_off is to prevent cloudfare from 'obfuscating' the minified CSS
737 * No optimize prevent autoptimize from mutilating the already optimized CSS.
738 */
739 function footer()
740 {
741 if(count($this->footer) == 0) return; // nothing
742
743 $button_ids = array();
744 $use_file = get_option('maxbuttons_usecssfile', false);
745
746 foreach ($this->footer as $type => $part)
747 {
748 if ($type == 'css' && $use_file) // use file output to a CSS filebased output, don't put it inline.
749 {
750 foreach($part as $id => $statements)
751 {
752 if (is_numeric($id))
753 $button_ids[] = $id;
754 else
755 echo "nonum $id";
756 }
757 continue;
758 }
759
760 // add tag
761 if ($type == 'css')
762 {
763 echo "<!--noptimize--><!--email_off--><style type='text/css'>";
764 }
765
766 foreach ($part as $id => $statements)
767 {
768 if (strlen($statements) > 0) // prevent whitespace
769 echo $statements . "\n";
770 }
771
772 if ($type == 'css')
773 {
774 echo "</style><!--/email_off--><!--/noptimize-->\n";
775 }
776 }
777
778 if (is_array($button_ids) && count($button_ids) > 0 && $use_file)
779 {
780 wp_enqueue_style('maxbuttons-front', admin_url('admin-ajax.php').'?action=maxbuttons_front_css&id=' . implode(',',array_unique($button_ids)) );
781 }
782 }
783
784 /* Add a notice
785
786 The added notice will be displayed to the user in WordPress format.
787 @see display_notices
788
789 @param $type string message | notice | error | fatal
790 @param $message string User understandable message
791
792 */
793 public static function add_notice($type, $message)
794 {
795 self::$notices[] = array("type" => $type,
796 "message" => $message
797 );
798
799 }
800
801 /* Display all notices
802
803 Then notices added by @see add_notice will be displayed. This function is called by an action hook
804
805 @param $echo echo the results or silently return.
806 @return string|null If not written to screen via echo, the HTML output will be returned
807 */
808 public function display_notices($echo = true)
809 {
810
811 if ($echo === '') $echo = true;
812 $notices = self::$notices;
813 $output = '';
814 if (count($notices) == 0)
815 return;
816
817 foreach($notices as $index => $notice)
818 {
819 $type = $notice["type"];
820 $message = $notice["message"];
821 $output .= "<div class='mb-message $type'> ";
822 $output .= $message ;
823 $output .= "</div>";
824 }
825
826 self::$notices = array(); // empty notices to prevent double display
827
828 if ($echo) echo $output;
829 else return $output;
830 }
831
832 } // class
833