PluginProbe ʕ •ᴥ•ʔ
Products Compare for WooCommerce / 3.5
Products Compare for WooCommerce v3.5
3.6.2.8 3.6.2.7 trunk 1.0.1 1.0.10 1.0.10.1 1.0.11 1.0.11.1 1.0.12 1.0.13 1.0.13.1 1.0.2 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 3.5 3.5.0.1 3.5.0.2 3.5.1 3.5.1.1 3.5.1.2 3.5.1.3 3.5.1.4 3.5.1.5 3.5.1.6 3.5.1.7 3.5.2 3.5.2.1 3.5.2.2 3.5.2.3 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7 3.5.7.1 3.5.7.2 3.5.7.3 3.5.7.4 3.5.7.5 3.5.7.6 3.5.7.7 3.5.7.8 3.5.7.9 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.6.2.1 3.6.2.2 3.6.2.3 3.6.2.4 3.6.2.5 3.6.2.6
products-compare-for-woocommerce / berocket / framework.php
products-compare-for-woocommerce / berocket Last commit date
assets 7 years ago includes 7 years ago languages 7 years ago libraries 7 years ago templates 7 years ago framework.php 7 years ago framework_version.php 7 years ago
framework.php
1044 lines
1 <?php
2 if( ! class_exists( 'BeRocket_Framework' ) && ! function_exists('BeRocket_Framework_load_newest') ) {
3 function BeRocket_Framework_load_newest() {
4 $active_plugins = get_option('active_plugins');
5 $framework_version = '0';
6 $framework_dir = false;
7 foreach($active_plugins as $active_plugin) {
8 $version_file = plugin_dir_path(WP_PLUGIN_DIR . '/' . $active_plugin) . 'berocket/framework_version.php';
9 if( file_exists($version_file) ) {
10 include_once($version_file);
11 }
12 }
13 if( ! empty($framework_version) && ! empty($framework_dir) ) {
14 include_once($framework_dir . '/framework.php');
15 }
16 }
17 BeRocket_Framework_load_newest();
18 }
19 if( ! class_exists( 'BeRocket_Framework' ) ) {
20 if( ! defined('BeRocket_framework_file') ) {
21 define( "BeRocket_framework_file", __FILE__ );
22 }
23 if( ! defined('BeRocket_framework_dir') ) {
24 define( "BeRocket_framework_dir", __DIR__ );
25 }
26 require_once( plugin_dir_path( __FILE__ ) . 'includes/functions.php');
27 require_once( plugin_dir_path( __FILE__ ) . 'includes/updater.php');
28 require_once( plugin_dir_path( __FILE__ ) . 'includes/widget.php');
29 require_once( plugin_dir_path( __FILE__ ) . 'includes/admin_notices.php');
30 require_once( plugin_dir_path( __FILE__ ) . 'includes/custom_post.php');
31 require_once( plugin_dir_path( __FILE__ ) . 'includes/conditions.php');
32 require_once( plugin_dir_path( __FILE__ ) . 'includes/plugin-variation.php');
33 require_once( plugin_dir_path( __FILE__ ) . 'includes/libraries.php');
34 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
35 load_plugin_textdomain('BeRocket_domain', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/');
36 class BeRocket_Framework {
37 public static $framework_version = '2.5';
38 public static $settings_name = '';
39 public $addons;
40 public $libraries;
41 private $post;
42 private $cc;
43 protected static $instance;
44 protected $plugin_version_capability = 0;
45 protected $framework_data = array(
46 'fontawesome_frontend' => false,
47 );
48 protected $active_libraries = array();
49 protected $global_settings = array(
50 'fontawesome_frontend_disable',
51 'fontawesome_frontend_version',
52 );
53 public $check_lib = null;
54 protected $check_init_array = array();
55 public static function getInstance()
56 {
57 if (null === static::$instance)
58 {
59 static::$instance = new static();
60 }
61 return static::$instance;
62 }
63
64 function __construct( $child ) {
65 if (null === static::$instance)
66 {
67 static::$instance = $child;
68 }
69 $this->include_once_files();
70 $this->cc = $child; // Child Class object
71 do_action('BeRocket_framework_init_plugin', $this->cc->info);
72 $this->plugin_version_capability = apply_filters('brfr_plugin_version_capability_'.$this->cc->info['plugin_name'], $this->plugin_version_capability, $this);
73 if( $this->plugin_version_capability == 15 ) {
74 $is_active_plugin = get_transient( 'berocket_framework_plugin_is_active_'.$this->info['id'] );
75 if( $is_active_plugin === false || is_admin() ) {
76 $active_plugin = get_option( 'berocket_key_activated_plugins' );
77 $active_site_plugin = get_site_option( 'berocket_key_activated_plugins' );
78 if ( ! is_array( $active_plugin ) ) {
79 $active_plugin = array();
80 }
81 if ( ! is_array( $active_site_plugin ) ) {
82 $active_site_plugin = array();
83 }
84 $is_active_plugin = ( empty( $active_plugin[ $this->info['id'] ] ) && empty( $active_site_plugin[ $this->info['id'] ] ) ) ? 0 : 20;
85 set_transient( 'berocket_framework_plugin_is_active_'.$this->info['id'], $is_active_plugin, 7200 );
86 }
87 $this->plugin_version_capability = $is_active_plugin;
88 }
89 $this->defaults = apply_filters('brfr_plugin_defaults_value_'.$this->cc->info['plugin_name'], $this->defaults, $this);
90
91 register_activation_hook( $this->cc->info[ 'plugin_file' ], array( $this->cc, 'activation' ) );
92 register_uninstall_hook( $this->cc->info[ 'plugin_file' ], array( get_class( $this->cc ), 'deactivation' ) );
93 add_filter( 'BeRocket_updater_add_plugin', array( $this->cc, 'updater_info' ) );
94 add_filter( 'berocket_admin_notices_rate_stars_plugins', array( $this, 'rate_stars_plugins' ) );
95
96 if ( $this->cc->init_validation() ) {
97 add_action( 'init', array( $this->cc, 'init' ) );
98 add_action( 'wp_head', array( $this->cc, 'set_styles' ) );
99 add_action( 'admin_init', array( $this->cc, 'admin_init' ) );
100 add_action( 'admin_menu', array( $this->cc, 'admin_menu' ) );
101 add_action( 'admin_enqueue_scripts', array( $this->cc, 'admin_enqueue_scripts' ) );
102
103 add_action( 'wp_ajax_br_' . $this->cc->info[ 'plugin_name' ] . '_settings_save', array(
104 $this->cc,
105 'save_settings'
106 ) );
107 add_filter( 'plugin_row_meta', array( $this->cc, 'plugin_row_meta' ), 10, 2 );
108 add_filter( 'is_berocket_settings_page', array( $this->cc, 'is_settings_page' ) );
109
110 $plugin_base_slug = plugin_basename( $this->cc->info[ 'plugin_file' ] );
111 add_filter( 'plugin_action_links_' . $plugin_base_slug, array( $this->cc, 'plugin_action_links' ) );
112
113 add_action( 'plugins_loaded', array( $this->cc, 'plugins_loaded' ) );
114 add_action( 'sanitize_comment_cookies', array( $this->cc, 'sanitize_comment_cookies' ) );
115 add_action ( 'install_plugins_pre_plugin-information', array( $this->cc, 'install_plugins_pre_plugin_information' ), 1 );
116 if( empty($this->plugin_version_capability) || $this->plugin_version_capability < 10 ) {
117 add_filter('berocket_admin_notices_subscribe_plugins', array($this, 'admin_notices_subscribe_plugins'));
118 }
119 $this->libraries = new BeRocket_framework_libraries($this->active_libraries, $this->info, $this->values, $this->get_option());
120 add_filter('BeRocket_admin_init_user_capabilities', array($this, 'init_user_capabilities'));
121 }
122 do_action($this->info[ 'plugin_name' ].'_framework_construct', $this->cc);
123 add_filter('brfr_get_plugin_version_capability_'.$this->cc->info['plugin_name'], array($this, 'get_plugin_version_capability'));
124 }
125 public function include_once_files() {
126 foreach (glob($this->info['plugin_dir'] . "/includes/*.php") as $filename)
127 {
128 include_once($filename);
129 }
130 }
131 public function init_check_lib() {
132 if( empty($this->check_lib) ) {
133 include_once('libraries/check_init.php');
134 $this->check_lib = new BeRocket_framework_check_init_lib($this->check_init_array);
135 }
136 }
137 public function get_plugin_version_capability($version) {
138 return $this->plugin_version_capability;
139 }
140 public function admin_notices_subscribe_plugins($plugins) {
141 $plugins[] = $this->info['id'];
142 return $plugins;
143 }
144 public function install_plugins_pre_plugin_information() {
145 wp_print_styles('font-awesome');
146 }
147 public function init_validation() {
148 $this->init_check_lib();
149 return $this->check_lib->check();
150 }
151
152 public function plugins_loaded() {
153 if( ! empty($_POST[ $this->cc->values[ 'settings_name' ] ]) ) {
154 $this->post = berocket_sanitize_array($_POST[ $this->cc->values[ 'settings_name' ] ]);
155 }
156 }
157
158 public function sanitize_comment_cookies() {
159 if( ! empty($this->post) ) {
160 $_POST[ $this->cc->values[ 'settings_name' ] ] = $this->post;
161 }
162 }
163
164 /**
165 * Get plugin data from BeRocket
166 *
167 * @return array
168 */
169 public function get_product_data_berocket() {
170 $products = get_transient($this->info[ 'plugin_name' ] . '_paid_info');
171 if( $products === FALSE ) {
172 $response = wp_remote_post('https://berocket.com/main/get_product_data/'.$this->info['id'], array(
173 'method' => 'POST',
174 'timeout' => 15,
175 'redirection' => 5,
176 'blocking' => true,
177 'sslverify' => false
178 ));
179 if( ! is_wp_error($response) ) {
180 $out = wp_remote_retrieve_body($response);
181 if( !empty($out) && json_decode($out) ) {
182 $products = json_decode($out, true);
183 set_transient($this->info[ 'plugin_name' ] . '_paid_info', $products, WEEK_IN_SECONDS);
184 } else {
185 set_transient($this->info[ 'plugin_name' ] . '_paid_info', '', DAY_IN_SECONDS);
186 }
187 } else {
188 set_transient($this->info[ 'plugin_name' ] . '_paid_info', '', DAY_IN_SECONDS);
189 }
190 }
191 return $products;
192 }
193
194 public function clear_product_data_transient() {
195 delete_transient($this->info[ 'plugin_name' ] . '_paid_info');
196 }
197
198 /**
199 * Function set default settings to database
200 *
201 * @return void
202 */
203 public function activation() {
204 add_option( $this->cc->values[ 'settings_name' ], $this->sanitize_option( $this->cc->defaults ) );
205 do_action('brfr_activate_' . $this->cc->info[ 'plugin_name' ]);
206 }
207
208 /**
209 * Function remove settings from database
210 *
211 * @return void
212 */
213 public static function deactivation() {
214 if( ! empty(static::$settings_name) ) {
215 do_action('brfr_deactivate_' . static::$settings_name);
216 delete_option( static::$settings_name );
217 }
218 }
219
220 /**
221 * Filter for BeRocket updater
222 */
223 public function updater_info( $plugins ) {
224 $option = $this->get_option();
225 $info = get_plugin_data( $this->cc->info[ 'plugin_file' ] );
226
227 $this->cc->info[ 'key' ] = ( isset($option[ 'plugin_key' ]) ? $option[ 'plugin_key' ] : '' );
228 $this->cc->info[ 'slug' ] = basename( $this->cc->info[ 'plugin_dir' ] );
229 $this->cc->info[ 'plugin' ] = plugin_basename( $this->cc->info[ 'plugin_file' ] );
230 $this->cc->info[ 'name' ] = $info[ 'Name' ];
231 $this->cc->info[ 'version_capability' ] = $this->plugin_version_capability;
232 if( ! empty($this->cc->values['free_slug']) ) {
233 $this->cc->info[ 'free_slug' ] = $this->cc->values['free_slug'];
234 }
235
236 $plugins[] = $this->cc->info;
237
238 return $plugins;
239 }
240
241 public function rate_stars_plugins($plugins) {
242 if( $this->plugin_version_capability < 10 ) {
243 $plugin = array(
244 'id' => $this->info['id'],
245 'name' => $this->info['name'],
246 'free_slug' => $this->values['free_slug'],
247 );
248 $plugins[$this->info['id']] = $plugin;
249 }
250 return $plugins;
251 }
252
253 /**
254 * Action links on the Plugins page
255 */
256 public function plugin_action_links( $links ) {
257 $action_links = array(
258 'settings' => '<a href="' . admin_url( 'admin.php?page=' . $this->cc->values[ 'option_page' ] ) .
259 '" title="' . __( 'View Plugin Settings', 'BeRocket_domain' ) . '">' .
260 __( 'Settings', 'BeRocket_domain' ) . '</a>',
261 );
262
263 return apply_filters('brfr_action_link_' . $this->cc->info[ 'plugin_name' ], array_merge( $action_links, $links ));
264 }
265
266 /**
267 * Meta links on the Plugins page
268 */
269 public function plugin_row_meta( $links, $file ) {
270 $plugin_base_slug = plugin_basename( $this->cc->info[ 'plugin_file' ] );
271 if ( $file == $plugin_base_slug ) {
272 $row_meta = array(
273 'docs' => '<a href="https://berocket.com/docs/plugin/' .
274 $this->cc->values[ 'premium_slug' ] . '" title="' .
275 __( 'View Plugin Documentation', 'BeRocket_domain' ) .
276 '" target="_blank">' . __( 'Docs', 'BeRocket_domain' ) . '</a>',
277 );
278 if( ! empty($this->plugin_version_capability) && $this->plugin_version_capability > 10 ) {
279 $row_meta['premium'] = '<a href="https://berocket.com/support/product/' . $this->cc->values[ 'premium_slug' ] .
280 '" title="' . __( 'View Premium Support Page', 'BeRocket_domain' ) .
281 '" target="_blank">' . __( 'Premium Support', 'BeRocket_domain' ) . '</a>';
282 } else {
283 $row_meta['premium'] = '<a href="https://berocket.com/product/' . $this->cc->values[ 'premium_slug' ] .
284 '" title="' . __( 'View Premium Version Page', 'BeRocket_domain' ) .
285 '" target="_blank">' . __( 'Premium Version', 'BeRocket_domain' ) . '</a>';
286 }
287
288 $links = array_merge( $links, $row_meta );
289 $links = apply_filters('brfr_plugin_row_meta_' . $this->cc->info[ 'plugin_name' ], $links, $file, $this);
290 }
291
292 return $links;
293 }
294
295 /**
296 * Initialize
297 */
298 public function init() {
299 $global_option = $this->get_global_option();
300 wp_enqueue_script( "jquery" );
301 if( is_admin() ) {
302 $this->register_font_awesome('fa5live');
303 } elseif( ! empty($this->framework_data['fontawesome_frontend']) ) {
304 $this->enqueue_fontawesome();
305 }
306
307 wp_add_inline_script(
308 $this->cc->info['plugin_name'] . "_execute_func",
309 ";
310 (function ($){
311 $(document).ready( function () {
312 " . $this->cc->info['plugin_name'] . "_execute_func( the_" . $this->cc->info['plugin_name'] . "_js_data.script.js_page_load );
313 });
314 })(jQuery);
315
316 function " . $this->cc->info['plugin_name'] . "_execute_func ( func ) {
317 if( the_" . $this->cc->info['plugin_name'] . "_js_data.script != 'undefined'
318 && the_" . $this->cc->info['plugin_name'] . "_js_data.script != null
319 && typeof func != 'undefined'
320 && func.length > 0 ) {
321 try {
322 eval( func );
323 } catch(err) {
324 alert('You have some incorrect JavaScript code (" . $this->cc->info['norm_name'] . ")');
325 }
326 }"
327 );
328 if ( function_exists('icl_object_id') ) {
329 include_once('libraries/wpml_compatibility.php');
330 }
331 }
332
333 public function enqueue_fontawesome($force = false) {
334 $global_option = $this->get_global_option();
335 if( empty($global_option['fontawesome_frontend_disable']) ) {
336 if( br_get_value_from_array($global_option, 'fontawesome_frontend_version') == 'fontawesome5' ) {
337 $this->register_font_awesome('fa5');
338 wp_enqueue_style( 'font-awesome-5' );
339 } else {
340 $this->register_font_awesome('fa4');
341 wp_enqueue_style( 'font-awesome' );
342 }
343 } else {
344 if( br_get_value_from_array($global_option, 'fontawesome_frontend_version') == 'fontawesome5' ) {
345 $this->register_font_awesome('fa5c');
346 wp_enqueue_style( 'font-awesome-5-compat' );
347 }
348 }
349 }
350
351 /**
352 * Function set styles in wp_head WordPress action
353 *
354 * @return void
355 */
356 public function set_styles() {
357 $options = $this->get_option();
358 echo '<style>' . $options[ 'custom_css' ] . '</style>';
359 }
360
361 /**
362 * Function adding styles/scripts and settings to admin_init WordPress action
363 *
364 * @access public
365 *
366 * @return void
367 */
368 public function admin_init() {
369 add_action('upgrader_process_complete', array($this, 'clear_product_data_transient'));
370 if( is_admin() ) {
371 $this->plugin_version_check();
372 }
373 if( isset($this->plugin_version_capability) && $this->plugin_version_capability <= 5 ) {
374 berocket_admin_notices::generate_subscribe_notice();
375 if( empty($this->feature_list) || ! is_array($this->feature_list) || ! count($this->feature_list) ) {
376 $products_info = $this->get_product_data_berocket();
377 if( is_array($products_info) && isset($products_info['difference']) && is_array($products_info['difference']) ) {
378 $this->feature_list = $products_info['difference'];
379 }
380 }
381 }
382 require_once( plugin_dir_path( __FILE__ ) . 'includes/settings_fields.php');
383 wp_register_script(
384 'berocket_framework_admin',
385 plugins_url( 'assets/js/admin.js', __FILE__ ),
386 array( 'jquery' ),
387 $this->cc->info[ 'version' ]
388 );
389
390 wp_register_style(
391 'berocket_framework_admin_style',
392 plugins_url( 'assets/css/admin.css', __FILE__ ),
393 "",
394 $this->cc->info[ 'version' ]
395 );
396
397 wp_register_style(
398 'berocket_framework_global_admin_style',
399 plugins_url( 'assets/css/global-admin.css', __FILE__ ),
400 "",
401 $this->cc->info[ 'version' ]
402 );
403
404 wp_register_script(
405 'berocket_widget-colorpicker',
406 plugins_url( 'assets/js/colpick.js', __FILE__ ),
407 array( 'jquery' )
408 );
409
410 wp_register_style(
411 'berocket_widget-colorpicker-style',
412 plugins_url( 'assets/css/colpick.css', __FILE__ )
413 );
414
415 wp_register_style(
416 'berocket_font_awesome',
417 plugins_url( 'assets/css/font-awesome.min.css', __FILE__ )
418 );
419 wp_localize_script( 'berocket_framework_admin', 'berocket_framework_admin', array(
420 'security' => wp_create_nonce("search-products")
421 ) );
422 if( ! empty($_GET['page']) && $_GET['page'] == $this->cc->values[ 'option_page' ] ) {
423 if( function_exists('wp_enqueue_code_editor') ) {
424 wp_enqueue_code_editor(
425 array(
426 'type' => 'css',
427 ) );
428 }
429 wp_enqueue_script( 'berocket_framework_admin' );
430
431 wp_enqueue_style( 'berocket_framework_admin_style' );
432
433 wp_enqueue_script( 'berocket_widget-colorpicker' );
434
435 wp_enqueue_style( 'berocket_widget-colorpicker-style' );
436
437 wp_enqueue_style( 'berocket_font_awesome' );
438 }
439
440 wp_enqueue_style( 'berocket_framework_global_admin_style' );
441
442 add_filter('option_page_capability_'.$this->cc->values[ 'option_page' ], array($this, 'option_page_capability'));
443 }
444
445 public function option_page_capability($capability = '') {
446 return 'manage_berocket';
447 }
448
449 /**
450 * Function add options button to admin panel if there are 3+ plugins from BeRocket and return false
451 * Other way it return true asking main function to add own options page
452 *
453 * @access public
454 *
455 * @return boolean
456 */
457 public function admin_menu() {
458 register_setting($this->cc->values[ 'option_page' ], $this->cc->values[ 'settings_name' ], array($this->cc, 'save_settings_callback'));
459 if ( method_exists( 'BeRocket_updater', 'get_plugin_count' ) ) {
460 add_submenu_page(
461 'berocket_account',
462 $this->cc->info[ 'norm_name' ] . ' ' . __( 'Settings', 'BeRocket_domain' ),
463 $this->cc->info[ 'norm_name' ],
464 $this->option_page_capability(),
465 $this->cc->values[ 'option_page' ],
466 array(
467 $this->cc,
468 'option_form'
469 )
470 );
471
472 return false;
473 }
474
475 return true;
476 }
477
478 /**
479 * Function add options form to settings page
480 *
481 * @return void
482 */
483 public function option_form() {
484 include __DIR__ . "/templates/settings.php";
485 }
486 public function admin_settings( $tabs_info = array(), $data = array() ) {
487 $setup_style = func_get_args();
488 $setup_style = (empty($setup_style[2]) || ! is_array($setup_style[2]) ? array() : $setup_style[2]);
489 $setup_style['settings_url'] = admin_url( 'admin.php?page=' . $this->cc->values[ 'option_page' ] );
490 $this->display_admin_settings($tabs_info, $data, $setup_style);
491 }
492
493 /**
494 * Function generate settings page
495 *
496 * @var $data - array with settings data, page will be build using this
497 *
498 * @return string
499 */
500 public function display_admin_settings( $tabs_info = array(), $data = array(), $setup_style = array() ) {
501 $plugin_info = get_plugin_data( $this->cc->info[ 'plugin_file' ] );
502 global $wp;
503 $settings_url = add_query_arg( NULL, NULL );
504 $settings_url = esc_url_raw($settings_url);
505 $def_setup_style = array(
506 'settings_url' => $settings_url,
507 'use_filters_hook' => true,
508 'hide_header' => false,
509 'hide_header_links' => false,
510 'hide_save_button' => false,
511 'hide_form' => false,
512 'hide_additional_blocks' => false,
513 'header_name' => "{$this->cc->info['norm_name']} by BeRocket",
514 'header_description' => str_replace( ' By BeRocket.', '', strip_tags( $plugin_info['Description'] ) ),
515 'settings_name' => $this->cc->values['settings_name'],
516 'options' => $this->get_option(),
517 'name_for_filters' => $this->cc->info[ 'plugin_name' ]
518 );
519 $setup_style = array_merge($def_setup_style, $setup_style);
520 if( $setup_style['use_filters_hook'] ) {
521 $tabs_info = apply_filters('brfr_tabs_info_' . $setup_style['name_for_filters'], $tabs_info);
522 $data = apply_filters('brfr_data_' . $setup_style['name_for_filters'], $data);
523 }
524 if ( isset($data) and is_array($data) and count( $data ) ) {
525 $page_menu = '';
526 $is_first = true;
527 $title = '';
528 $options = $setup_style['options'];
529
530 $selected_tab = false;
531 if( ! empty($_GET['tab']) ) {
532 foreach ( $tabs_info as $tab_name => $tab_info ) {
533 if( sanitize_title( $tab_name ) == $_GET['tab'] ) {
534 $selected_tab = true;
535 }
536 }
537 }
538
539 foreach ( $tabs_info as $tab_name => $tab_info ) {
540 if( isset($tab_info['name']) ) {
541 $display_name = $tab_info['name'];
542 } else {
543 $display_name = $tab_name;
544 }
545 $page_menu .= '<li>';
546
547 $page_menu .= '<a href="' . ( empty($tab_info['link']) ? add_query_arg('tab', sanitize_title( $tab_name ), $setup_style['settings_url']) : $tab_info['link'] ) .
548 '" class="' . ( empty($tab_info['priority']) ? 'default' : $tab_info['priority'] ) .
549 ( empty($tab_info['link']) ? '' : ' redirect_link' ) .
550 ( $selected_tab ? ( sanitize_title( $tab_name ) == $_GET['tab'] ? ' active' : '' ) : ( $is_first ? ' active' : '' ) ) .
551 '" data-block="' . ( empty($tab_info['link']) ? 'berocket_framework_menu_' . sanitize_title( $tab_name ) : 'redirect_link' ) . '">';
552 if ( $tab_info['icon'] ) {
553 $page_menu .= '<span class="fa fa-' . $tab_info['icon'] . '"></span>';
554 }
555 $page_menu .= $display_name . '</a>';
556
557 $page_menu .= '</li>';
558
559 if ( ($selected_tab && sanitize_title( $tab_name ) == $_GET['tab'] ) || ( ! $selected_tab && $is_first ) ) {
560 if ( $tab_info['icon'] ) {
561 $title .= '<span class="fa fa-' . $tab_info['icon'] . '"></span>';
562 }
563 $title .= $display_name;
564 }
565
566 $is_first = false;
567 }
568 if( ! $setup_style['hide_save_button'] ) {
569 $page_menu .= '<li class="berocket_framework_sidebar_save_button"><input type="submit" class="button-primary button" value="' . __( 'Save Changes', 'BeRocket_domain' ) . '" /></li>';
570 }
571 if( $setup_style['use_filters_hook'] ) {
572 $page_menu = apply_filters('brfr_page_menu_' . $setup_style['name_for_filters'], $page_menu, $tabs_info);
573 }
574
575 $is_first = true;
576 $page_content = '';
577
578 foreach ( $data as $tab_name => $tab_content ) {
579 $page_content .= '<div class="nav-block berocket_framework_menu_' . sanitize_title( $tab_name ) . '-block ' . ( $selected_tab ? ( sanitize_title( $tab_name ) == $_GET['tab'] ? ' nav-block-active' : '' ) : ( $is_first ? ' nav-block-active' : '' ) ) . '">';
580 $page_content .= '<table class="framework-form-table berocket_framework_menu_' . sanitize_title( $tab_name ) . '">';
581
582 if ( isset($tab_content) and is_array($tab_content) and count( $tab_content ) ) {
583 foreach ( $tab_content as $item ) {
584 $class = $extra = '';
585
586 if ( isset($item['class']) && trim( $item['class'] ) ) {
587 $class = " class='" . trim( $item['class'] ) . "'";
588 }
589
590 if ( isset($item['extra']) && trim( $item['extra'] ) ) {
591 $extra = " " . trim( $item['extra'] );
592 }
593
594 $item['tr_class'] = (empty($item['tr_class']) ? '' : ' class="'.$item['tr_class'].'"');
595 $page_content .= "<tr".$item['tr_class'].">";
596
597 if ( empty($item['section']) or $item['section'] == 'field' ) {
598 $item['td_class'] = (empty($item['td_class']) ? '' : ' class="'.$item['td_class'].'"');
599 $page_content .= '<th scope="row">' . $item['label'] .'</th><td'.$item['td_class'].'>';
600
601 $field_items = array();
602 if( isset($item['items']) && is_array($item['items']) ) {
603 $field_items = $item['items'];
604 } else {
605 $field_items[] = $item;
606 }
607 $item_i = 0;
608 foreach( $field_items as $item_key => $field_item ) {
609 $class = $extra = $item_content = '';
610 if ( isset($field_item['class']) && trim( $field_item['class'] ) ) {
611 $class = " class='" . trim( $field_item['class'] ) . "'";
612 }
613
614 if ( isset($field_item['extra']) && trim( $field_item['extra'] ) ) {
615 $extra = " " . trim( $field_item['extra'] );
616 }
617 if( isset($option_values) ) {
618 unset($option_values);
619 }
620 if( empty($field_item['custom_name']) && ! empty($field_item['name']) ) {
621 if( is_array($field_item['name']) ) {
622 $option_values = $options;
623 $option_deault_values = $this->cc->defaults;
624 foreach($field_item['name'] as $field_names) {
625 if( isset($option_values) && isset($field_names) && $field_names !== '' && isset($option_values[$field_names]) ) {
626 $option_values = $option_values[$field_names];
627 } else {
628 unset($option_values);
629 }
630 if( isset($option_values) && isset($field_names) && $field_names !== '' && isset($option_deault_values[$field_names]) ) {
631 $option_deault_values = $option_deault_values[$field_names];
632 } else {
633 unset($option_deault_values);
634 }
635 }
636 } elseif( isset($options[ $field_item['name'] ]) ) {
637 $option_values = $options[ $field_item['name'] ];
638 if( isset($this->cc->defaults[ $field_item['name'] ]) ) {
639 $option_deault_values = $this->cc->defaults[ $field_item['name'] ];
640 }
641 }
642 }
643 if( ! isset($option_values) ) {
644 $option_values = NULL;
645 }
646 if( ! isset($option_deault_values) ) {
647 $option_deault_values = NULL;
648 }
649 if ( $field_item['type'] != 'checkbox' and isset( $option_values ) ) {
650 $value = $option_values;
651 } else {
652 $value = $field_item['value'];
653 }
654 if( $item_i > 0 ) {
655 $page_content .= '<span class="br_line_delimiter"></span> ';
656 }
657 $field_item['label_for'] = ( isset($field_item['label_for']) ? $field_item['label_for'] : '' );
658 $field_item['label_be_for'] = ( isset($field_item['label_be_for']) ? $field_item['label_be_for'] : '' );
659
660 $field_name = (
661 empty($field_item['custom_name']) ?
662 (
663 empty($field_item['name']) ?
664 $setup_style['settings_name'] . '[]' :
665 (
666 is_array($field_item['name']) ?
667 $setup_style['settings_name'] . '[' . implode('][', $field_item['name']) . ']' :
668 $setup_style['settings_name'] . '[' . $field_item['name'] . ']'
669 )
670 ) :
671 $field_item['custom_name']
672 );
673 if( empty($field_item['type']) ) {
674 $field_item['type'] = 'text';
675 }
676 $item_filtered_content = apply_filters('berocket_framework_item_content_'.$field_item['type'], '', $field_item, $field_name, $value, $class, $extra, $option_values, $option_deault_values);
677 if( empty($item_filtered_content) ) {
678 $item_content .= "<td class='error'>Unsupported field type!</td>";
679 } else {
680 $item_content .= $item_filtered_content;
681 }
682 if( $setup_style['use_filters_hook'] ) {
683 $item_content = apply_filters('brfr_fields_html_' . $setup_style['name_for_filters'], $item_content, $field_name, $value, $field_item);
684 }
685 $page_content .= $item_content;
686 $item_i++;
687 }
688
689 $page_content .= '</td>';
690 } elseif ( $item['section'] == 'header' ) {
691 $page_content .= "
692 <th colspan='2'>
693 <h{$item['type']}" . $class . $extra . ">{$item['label']}</h{$item['type']}>
694 </th>";
695 } elseif ( $item['section'] == 'license' ) {
696 $page_content .= '
697 <th scope="row">' . __('Plugin key', 'BeRocket_domain') .'</th>
698 <td><div class="license-block">
699 <input id="berocket_product_key" size="50" name="' . $setup_style['settings_name'] . '[plugin_key]"
700 type="text" value="' . $options['plugin_key'] . '"/>
701 <input class="berocket_test_account_product button-secondary" data-id="' . $this->cc->info['id'] . '" type="button" value="Test"/>
702 <br />
703 <span style="color:#666666;margin-left:2px;">' . __('Key for plugin from BeRocket.com', 'BeRocket_domain') . '</span>
704 <br />
705 <div class="berocket_test_result"></div>
706 </div></td>';
707 } elseif ( method_exists( $this->cc, 'section_' . $item['section'] ) ) {
708 $section_filter = $this->cc->{'section_' . $item['section']}( $item, $options );
709 if( $setup_style['use_filters_hook'] ) {
710 $section_filter = apply_filters('brfr_' . $setup_style['name_for_filters'] . '_' . $item['section'], $section_filter, $item, $options, $setup_style['settings_name']);
711 }
712 $page_content .= $section_filter;
713 } else {
714 $section_filter = apply_filters('brfr_' . $setup_style['name_for_filters'] . '_' . $item['section'], '', $item, $options, $setup_style['settings_name']);
715 if( ! empty($section_filter) ) {
716 $page_content .= $section_filter;
717 } else {
718 $page_content .= "<th colspan='2' class='error'>Not supported section type `{$item['section']}`!</th>";
719 }
720 }
721
722 $page_content .= "</tr>";
723 }
724 }
725
726 $page_content .= '</table>';
727 $page_content .= '</div>';
728
729 $is_first = false;
730 }
731
732 if( $setup_style['use_filters_hook'] ) {
733 $page_content = apply_filters('brfr_page_content_' . $setup_style['name_for_filters'], $page_content, $data);
734 }
735
736 if( ! $setup_style['hide_header'] ) {
737 echo "
738 <header>
739 <div class='br_logo_white'>
740 <a href='https://berocket.com/products/' title='BeRocket' target='_blank'><img src='" . ( plugins_url( 'assets/images/br_logo_white.png', __FILE__ ) ) . "' /></a>
741 </div>
742 <nav class='premium'>";
743 if( ! $setup_style['hide_header_links'] ) {
744 $header_links = array(
745 'documentation' => array(
746 'text' => "<i class='fa fa-book'></i>",
747 'link' => apply_filters('brfr_docs_link_' . $setup_style['name_for_filters'], "https://berocket.com/docs/plugin/{$this->cc->values['premium_slug']}" )
748 )
749 );
750 if( ! empty($this->plugin_version_capability) && $this->plugin_version_capability > 5 ) {
751 $header_links['support'] = array(
752 'text' => "<i class='fa fa-support'></i>",
753 'link' => apply_filters('brfr_support_link_' . $setup_style['name_for_filters'], "https://berocket.com/support/product/{$this->cc->values['premium_slug']}" )
754 );
755 } elseif( ! empty($this->cc->values['free_slug']) ) {
756 $header_links['support'] = array(
757 'text' => "<i class='fa fa-support'></i>",
758 'link' => apply_filters('brfr_support_link_' . $setup_style['name_for_filters'], "https://wordpress.org/support/plugin/{$this->cc->values['free_slug']}" )
759 );
760 }
761 $header_links = apply_filters('brfr_header_links_' . $setup_style['name_for_filters'], $header_links);
762 foreach($header_links as $header_link_title => $header_link) {
763 echo "<a href='" . $header_link['link'] . "' title='" . $header_link_title . "' target='_blank'>" . $header_link['text'] . "</a>";
764 }
765 }
766 echo "</nav>
767 <div class='br_plugin_name'>
768 <h1>{$setup_style['header_name']}</h1>
769 <h3>
770 {$setup_style['header_description']}
771 </h3>
772 </div>
773 </header>
774 ";
775 }
776 echo '<div class="body">';
777 echo '<ul class="side">';
778 echo $page_menu;
779 echo '</ul>';
780 echo '<div class="content">';
781 echo "<div class='title'>{$title}</div>";
782 if( ! $setup_style['hide_form'] ) {
783 echo '<form data-plugin="' . $this->cc->info['plugin_name'] . '" class="br_framework_submit_form ' . $this->cc->info['plugin_name'] . '_submit_form ' . ( ( isset($this->plugin_version_capability) && $this->plugin_version_capability <= 5 ) ? 'show_premium' : '' ) .
784 '" method="post" action="options.php">';
785 settings_fields( $_GET['page'] );
786 }
787 echo $page_content;
788 echo '<div class="clear-both"></div>';
789 if( ! $setup_style['hide_save_button'] ) {
790 echo '<input type="submit" class="berocket_framework_default_save_button button-primary button" value="' . __( 'Save Changes', 'BeRocket_domain' ) . '" />';
791 echo '<div class="br_save_error"></div>';
792 }
793 if( ! $setup_style['hide_form'] ) {
794 echo '</form>';
795 }
796 if( ! $setup_style['hide_additional_blocks'] ) {
797 require_once( plugin_dir_path( __FILE__ ) . 'templates/premium.php');
798 }
799 echo '</div>';
800 echo '<div class="clear-both"></div>';
801 echo '</div>';
802 }
803 }
804
805 /**
806 * Load template from theme | plugin
807 *
808 * @access public
809 *
810 * @param string $name template name
811 *
812 * @return void
813 */
814 public function br_get_template_part( $name = '' ) {
815 $template = '';
816
817 // Look in your_child_theme/woocommerce-%PLUGINNAME%/name.php
818 if ( $name ) {
819 $template = locate_template( "woocommerce-" . $this->cc->info[ 'plugin_name' ] . "/{$name}.php" );
820 }
821
822 // Get default slug-name.php
823 if ( ! $template && $name && file_exists( $this->cc->info[ 'templates' ] . "{$name}.php" ) ) {
824 $template = $this->cc->info[ 'templates' ] . "{$name}.php";
825 }
826
827 // Allow 3rd party plugin filter template file from their plugin
828 $template = apply_filters( $this->cc->info[ 'plugin_name' ] . '_get_template_part', $template, $name );
829
830 if ( $template ) {
831 load_template( $template, false );
832 }
833 }
834
835 /**
836 * Load admin file-upload scripts and styles
837 *
838 * @access public
839 *
840 * @return void
841 */
842 public static function admin_enqueue_scripts() {
843 if ( function_exists( 'wp_enqueue_media' ) ) {
844 wp_enqueue_media();
845 } else {
846 wp_enqueue_style( 'thickbox' );
847 wp_enqueue_script( 'media-upload' );
848 wp_enqueue_script( 'thickbox' );
849 }
850 }
851 public function save_settings_callback($settings) {
852 if ( isset( $settings ) ) {
853 $settings = $this->sanitize_option( $settings );
854 if( count($this->global_settings) ) {
855 $global_options = $this->get_global_option();
856 foreach($this->global_settings as $global_setting) {
857 if( isset($settings[$global_setting]) ) {
858 $global_options[$global_setting] = $settings[$global_setting];
859 }
860 }
861 $this->save_global_option($global_options);
862 }
863 }
864 return $settings;
865 }
866
867 /**
868 * Checking if we are on Settings page
869 *
870 * @access public
871 *
872 * @return boolean
873 */
874 public function check_screen() {
875 $screen = get_current_screen();
876 if ( $screen->id == 'woocommerce_page_br-' . $this->cc->info[ 'plugin_name' ] ) {
877 return true;
878 }
879
880 return false;
881 }
882
883 /**
884 * Sanitize option function
885 *
886 * @access public
887 *
888 * @return mixed
889 */
890 public function sanitize_option( $input ) {
891 $new_input = $this->recursive_array_set( $this->cc->defaults, $input );
892 return apply_filters('brfr_sanitize_option_' . $this->cc->info[ 'plugin_name' ], $new_input, $input, $this->cc->defaults);
893 }
894
895 /**
896 * Settings correct values for the array. If it exist in the input it will be used
897 * if not - default will be used
898 *
899 * @access public
900 *
901 * @return mixed
902 */
903 public static function recursive_array_set( $default, $options ) {
904 $result = array();
905
906 foreach ( $default as $key => $value ) {
907 if ( array_key_exists( $key, $options ) ) {
908 if ( is_array( $value ) ) {
909 if ( is_array( $options[ $key ] ) ) {
910 $result[ $key ] = self::recursive_array_set( $value, $options[ $key ] );
911 } else {
912 $result[ $key ] = self::recursive_array_set( $value, array() );
913 }
914 } else {
915 $result[ $key ] = $options[ $key ];
916 }
917 } else {
918 if ( is_array( $value ) ) {
919 $result[ $key ] = self::recursive_array_set( $value, array() );
920 } else {
921 $result[ $key ] = '';
922 }
923 }
924 }
925
926 foreach ( $options as $key => $value ) {
927 if ( ! array_key_exists( $key, $result ) ) {
928 $result[ $key ] = $value;
929 }
930 }
931
932 return $result;
933 }
934
935 /**
936 * Getting plugin option values
937 *
938 * @access public
939 *
940 * @return mixed
941 */
942 public function get_option() {
943 if ( ! function_exists('icl_object_id') ) {
944 $options = wp_cache_get( $this->cc->values[ 'settings_name' ], 'berocket_framework_option' );
945 }
946 if( empty($options) ) {
947 $options = get_option( $this->cc->values[ 'settings_name' ] );
948
949 if ( ! empty($options) && is_array( $options ) ) {
950 $options = array_merge( $this->cc->defaults, $options );
951 } else {
952 $options = $this->cc->defaults;
953 }
954 $options = apply_filters('brfr_get_option_cache_' . $this->cc->info[ 'plugin_name' ], $options, $this->cc->defaults);
955 wp_cache_set( $this->cc->values[ 'settings_name' ], $options, 'berocket_framework_option', 600 );
956 }
957 $global_options = $this->get_global_option();
958 if( count($this->global_settings) ) {
959 foreach($this->global_settings as $global_setting) {
960 if( isset($global_options[$global_setting]) ) {
961 $options[$global_setting] = $global_options[$global_setting];
962 }
963 }
964 }
965
966 $options = apply_filters('brfr_get_option_' . $this->cc->info[ 'plugin_name' ], $options, $this->cc->defaults);
967
968 return $options;
969 }
970 public function get_global_option() {
971 $option = get_option('berocket_framework_option_global');
972 if( ! is_array($option) ) {
973 $option = array();
974 }
975 return $option;
976 }
977 public function save_global_option($option) {
978 $option = update_option('berocket_framework_option_global', $option);
979 return $option;
980 }
981 public function is_settings_page($settings_page) {
982 if( ! empty($_GET['page']) && $_GET['page'] == $this->cc->values[ 'option_page' ] ) {
983 $settings_page = true;
984 }
985 return $settings_page;
986 }
987
988 public static function register_font_awesome($type = 'all') {
989 if( $type == 'all' || $type == 'fa4' ) {
990 wp_register_style( 'font-awesome', plugins_url( 'assets/css/font-awesome.min.css', __FILE__ ) );
991 }
992 if( $type == 'all' || $type == 'fa5' ) {
993 wp_register_style( 'font-awesome-5', plugins_url( 'assets/css/fontawesome5.min.css', __FILE__ ) );
994 }
995 if( $type == 'all' || $type == 'fa5c' ) {
996 wp_register_style( 'font-awesome-5-compat', plugins_url( 'assets/css/fontawesome4-compat.min.css', __FILE__ ) );
997 }
998 if( $type == 'fa5live' ) {
999 add_action('admin_footer', array(__CLASS__, 'fa5live'));
1000 add_action('wp_footer', array(__CLASS__, 'fa5live'));
1001 wp_enqueue_style( 'font-awesome-5-compat', plugins_url( 'assets/css/fontawesome4-compat.min.css', __FILE__ ) );
1002 }
1003 }
1004 public static function fa5live() {
1005 echo '<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">';
1006 }
1007 public function plugin_version_check() {
1008 $plugins = get_option('BeRocket_Framework_plugins_version_check');
1009 if( empty($plugins) || ! is_array($plugins) ) {
1010 $plugins = array();
1011 }
1012 if( ! isset($plugins[$this->info['plugin_name']]) ) {
1013 $plugins[$this->info['plugin_name']] = '0';
1014 }
1015 if( $this->info['version'] != $plugins[$this->info['plugin_name']] ) {
1016 $this->update_version($plugins[$this->info['plugin_name']], $this->info['version']);
1017 $plugins[$this->info['plugin_name']] = $this->info['version'];
1018 }
1019 update_option('BeRocket_Framework_plugins_version_check', $plugins);
1020 }
1021 public function update_version($previous, $current) {
1022
1023 }
1024 public function init_user_capabilities($user_caps) {
1025 $user_caps[] = $this->option_page_capability();
1026 return $user_caps;
1027 }
1028 }
1029 add_action('admin_init', 'BeRocket_admin_init_user_capabilities');
1030 function BeRocket_admin_init_user_capabilities() {
1031 global $wp_roles;
1032 $role_names = $wp_roles->get_names();
1033 $berocket_roles = apply_filters('BeRocket_admin_init_user_capabilities', array('manage_berocket', 'manage_berocket_account'));
1034 foreach($role_names as $role_name => $role_text) {
1035 $role_object = get_role( $role_name );
1036 if( $role_object->has_cap( 'manage_options' ) ) {
1037 foreach($berocket_roles as $berocket_role) {
1038 $role_object->add_cap( $berocket_role );
1039 }
1040 }
1041 }
1042 }
1043 }
1044