PluginProbe ʕ •ᴥ•ʔ
Products Compare for WooCommerce / 3.6.2.8
Products Compare for WooCommerce v3.6.2.8
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 1 month ago includes 1 month ago languages 1 month ago libraries 1 month ago sale 1 month ago templates 1 month ago framework.php 1 month ago framework_version.php 1 month ago
framework.php
1361 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/utm.php');
30 require_once( plugin_dir_path( __FILE__ ) . 'includes/admin_notices.php');
31 require_once( plugin_dir_path( __FILE__ ) . 'includes/information_notices.php');
32 require_once( plugin_dir_path( __FILE__ ) . 'includes/custom_post.php');
33 require_once( plugin_dir_path( __FILE__ ) . 'includes/conditions.php');
34 require_once( plugin_dir_path( __FILE__ ) . 'includes/plugin-variation.php');
35 require_once( plugin_dir_path( __FILE__ ) . 'includes/libraries.php');
36 require_once( plugin_dir_path( __FILE__ ) . 'includes/eng_engine/controller.php');
37 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
38 load_plugin_textdomain('BeRocket_domain', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/');
39 class BeRocket_Framework {
40 public static $framework_version = '3.0.5.2';
41 public $plugin_framework_version = '3.0.5.2';
42 public $licenses_current = array('free');
43 public static $settings_name = '';
44 public $addons;
45 public $defaults = array();
46 public $default;
47 public $values = array();
48 public $feature_list = array();
49 public $libraries;
50 public $info;
51 public $import_export = false;
52 public $import_export_posts = false;
53 protected $disable_settings_for_admin = array();
54 private $post;
55 private $cc;
56 protected static $instance;
57 protected $plugin_version_capability = 0;
58 protected $framework_data = array(
59 'fontawesome_frontend' => false,
60 );
61 protected $active_libraries = array();
62 public $check_lib = null;
63 protected $check_init_array = array();
64 public static function getInstance()
65 {
66 if (null === static::$instance)
67 {
68 static::$instance = new static();
69 }
70 return static::$instance;
71 }
72
73 function __construct( $child ) {
74 if (null === static::$instance)
75 {
76 static::$instance = $child;
77 }
78 $this->include_once_files();
79 $this->cc = $child; // Child Class object
80 do_action('BeRocket_framework_init_plugin', $this->cc->info);
81 $this->plugin_version_capability = apply_filters('brfr_plugin_version_capability_'.$this->cc->info['plugin_name'], $this->plugin_version_capability, $this);
82 $this->licenses_current = apply_filters('brfr_plugin_licenses_current_'.$this->cc->info['plugin_name'], $this->licenses_current, $this);
83 add_filter('brfr_plugin_get_licenses_current_' . $this->cc->info['plugin_name'], array( $this, 'get_licenses_current' ) );
84 add_filter('brfr_plugin_get_licenses_current_id_' . $this->cc->info['id'], array( $this, 'get_licenses_current' ) );
85 add_filter('brfr_plugin_get_licenses_current_latest_' . $this->cc->info['plugin_name'], array( $this, 'get_licenses_latest' ) );
86 add_filter('brfr_plugin_get_instance_' . $this->cc->info['plugin_name'], array( $this, 'getInstance_hook' ) );
87 add_filter('plugins_list', array( $this, 'modify_license_type' ), 10, 1 );
88 if( $this->plugin_version_capability == 15 && is_admin() ) {
89 $is_active_plugin = get_transient( 'berocket_framework_plugin_is_active_'.$this->info['id'] );
90 if( $is_active_plugin === false || is_admin() ) {
91 $active_plugin = get_option( 'berocket_key_activated_plugins' );
92 $active_site_plugin = get_site_option( 'berocket_key_activated_plugins' );
93 if ( ! is_array( $active_plugin ) ) {
94 $active_plugin = array();
95 }
96 if ( ! is_array( $active_site_plugin ) ) {
97 $active_site_plugin = array();
98 }
99 $is_active_plugin = ( empty( $active_plugin[ $this->info['id'] ] ) && empty( $active_site_plugin[ $this->info['id'] ] ) ) ? 3 : 17;
100 set_transient( 'berocket_framework_plugin_is_active_'.$this->info['id'], $is_active_plugin, 7200 );
101 }
102 $this->plugin_version_capability = $is_active_plugin;
103 }
104 $this->defaults = apply_filters('brfr_plugin_defaults_value_'.$this->cc->info['plugin_name'], $this->defaults, $this);
105
106 register_activation_hook( $this->cc->info[ 'plugin_file' ], array( $this->cc, 'activation' ) );
107 register_uninstall_hook( $this->cc->info[ 'plugin_file' ], array( get_class( $this->cc ), 'deactivation' ) );
108 add_filter( 'BeRocket_updater_add_plugin', array( $this->cc, 'updater_info' ) );
109 add_filter( 'berocket_admin_notices_rate_stars_plugins', array( $this, 'rate_stars_plugins' ) );
110 add_action( 'init', array($this, 'init_translation'), 1 );
111
112 if ( $this->cc->init_validation() ) {
113 add_action( 'init', array( $this->cc, 'init' ) );
114 add_action( 'wp_head', array( $this->cc, 'set_styles' ) );
115 add_action( 'wp_footer', array( $this->cc, 'set_scripts' ), 9000 );
116 add_action( 'admin_init', array( $this->cc, 'admin_init' ) );
117 add_action( 'admin_menu', array( $this->cc, 'admin_menu' ) );
118 add_action( 'admin_enqueue_scripts', array( $this->cc, 'admin_enqueue_scripts' ) );
119 add_action( 'berocket_enqueue_media', array( $this, 'wp_enqueue_media' ) );
120
121 add_action( 'wp_ajax_br_' . $this->cc->info[ 'plugin_name' ] . '_settings_save', array(
122 $this->cc,
123 'save_settings'
124 ) );
125 add_filter( 'plugin_row_meta', array( $this->cc, 'plugin_row_meta' ), 10, 2 );
126 add_filter( 'is_berocket_settings_page', array( $this->cc, 'is_settings_page' ) );
127
128 $plugin_base_slug = plugin_basename( $this->cc->info[ 'plugin_file' ] );
129 add_filter( 'plugin_action_links_' . $plugin_base_slug, array( $this->cc, 'plugin_action_links' ) );
130
131 add_action( 'plugins_loaded', array( $this->cc, 'plugins_loaded' ) );
132 add_action( 'sanitize_comment_cookies', array( $this->cc, 'sanitize_comment_cookies' ) );
133 add_action ( 'install_plugins_pre_plugin-information', array( $this->cc, 'install_plugins_pre_plugin_information' ), 1 );
134 if( empty($this->plugin_version_capability) || $this->plugin_version_capability < 10 ) {
135 add_filter('berocket_admin_notices_subscribe_plugins', array($this, 'admin_notices_subscribe_plugins'));
136 }
137 $this->libraries = new BeRocket_framework_libraries($this->active_libraries, $this->info, $this->values, $this->get_option());
138 add_filter('BeRocket_admin_init_user_capabilities', array($this, 'init_user_capabilities'));
139 add_filter('berocket_sanitize_array_predefine', array($this, 'sanitize_array_predefine'), 10, 4);
140 add_filter('berocket_sanitize_array_kses', array($this, 'sanitize_array_kses'), 10, 4);
141 add_filter('brfr_menu_item_remove_'.$this->info['plugin_name'], array($this, 'menu_item_remove'), 10, 3);
142 //CHECK OLD FRAMEWORK
143 add_filter('berocket_sanitize_array_kses', array($this, 'disable_for_old_plugins'), 10, 4);
144 $framework_version_current = self::$framework_version;
145 $framework_version = $framework_version_current;
146 include($this->info['plugin_dir']."/berocket/framework_version.php");
147 $this->plugin_framework_version = $framework_version_current;
148 if( $this->plugin_version_capability < 10 ) {
149 if( file_exists(plugin_dir_path( __FILE__ ) . 'sale/sale.php') ) {
150 include_once( plugin_dir_path( __FILE__ ) . 'sale/sale.php');
151 }
152 }
153 add_action( 'before_woocommerce_init', array($this, 'hpos_compatible'));
154 }
155 do_action($this->info[ 'plugin_name' ].'_framework_construct', $this->cc);
156 add_filter('brfr_get_plugin_version_capability_'.$this->cc->info['plugin_name'], array($this, 'get_plugin_version_capability'));
157 }
158 public function init_translation() {}
159 public function getInstance_hook($instance) {
160 return $this->cc::getInstance();
161 }
162 public function include_once_files() {
163 foreach (glob($this->info['plugin_dir'] . "/includes/*.php") as $filename)
164 {
165 include_once($filename);
166 }
167 $global_option = self::get_global_option();
168 if( ! is_admin() && br_get_value_from_array($global_option, 'disable_admin_bar_panel') != 'disable' ) {
169 include_once('includes/admin/admin_bar.php');
170 }
171 }
172 public function init_check_lib() {
173 if( empty($this->check_lib) ) {
174 include_once('libraries/check_init.php');
175 $this->check_lib = new BeRocket_framework_check_init_lib($this->check_init_array);
176 }
177 }
178 public function get_licenses_current() {
179 return $this->licenses_current;
180 }
181 public function get_licenses_latest() {
182 return end($this->licenses_current);
183 }
184 public function modify_license_type($plugins_list) {
185 $plugin_base = plugin_basename( $this->cc->info[ 'plugin_file' ] );
186 $license_latest = apply_filters('brfr_plugin_get_licenses_current_latest_' . $this->cc->info['plugin_name'], 'free');
187 foreach($plugins_list as $type => $plugins) {
188 if( isset($plugins[$plugin_base]) && is_array($plugins[$plugin_base]) && ! empty($plugins[$plugin_base]['Version']) ) {
189 $plugins_list[$type][$plugin_base]['Version'] .= '(' . $license_latest . ')';
190 }
191 }
192 return $plugins_list;
193 }
194 public function get_plugin_version_capability($version) {
195 return $this->plugin_version_capability;
196 }
197 public function admin_notices_subscribe_plugins($plugins) {
198 $plugins[] = $this->info['id'];
199 return $plugins;
200 }
201 public function install_plugins_pre_plugin_information() {
202 wp_print_styles('font-awesome');
203 }
204 public function init_validation() {
205 $this->init_check_lib();
206 return $this->check_lib->check();
207 }
208
209 public function plugins_loaded() {
210 if( ! empty($_POST[ $this->cc->values[ 'settings_name' ] ]) ) {
211 $previous_options = $this->get_option();
212 $this->post = berocket_sanitize_array($_POST[ $this->cc->values[ 'settings_name' ] ], array($this->cc->values[ 'settings_name' ]), $previous_options);
213 }
214 }
215
216 public function sanitize_comment_cookies() {
217 if( ! empty($this->post) ) {
218 if( ! empty($_POST[ $this->cc->values[ 'settings_name' ] ]['addons']) ) {
219 $this->post['addons'] = $_POST[ $this->cc->values[ 'settings_name' ] ]['addons'];
220 }
221 if( ! empty($_POST[ $this->cc->values[ 'settings_name' ] ]['template']) ) {
222 $this->post['template'] = $_POST[ $this->cc->values[ 'settings_name' ] ]['template'];
223 }
224 $_POST[ $this->cc->values[ 'settings_name' ] ] = $this->post;
225 }
226 }
227
228 /**
229 * Get plugin data from BeRocket
230 *
231 * @return array
232 */
233 public static function get_product_data_berocket($plugin_id) {
234 $products = get_transient('berocket_plugin_paid_info');
235 if( $products === FALSE ) {
236 $response = wp_remote_post('https://apicdn.berocket.com/plugins_data', array(
237 'method' => 'GET',
238 'timeout' => 15,
239 'redirection' => 5,
240 'blocking' => true,
241 'sslverify' => false
242 ));
243 if( ! is_wp_error($response) ) {
244 $out = wp_remote_retrieve_body($response);
245 if( !empty($out) && json_decode($out) ) {
246 $products = json_decode($out, true);
247 set_transient('berocket_plugin_paid_info', $products, DAY_IN_SECONDS);
248 } else {
249 set_transient('berocket_plugin_paid_info', '', HOUR_IN_SECONDS);
250 }
251 } else {
252 set_transient('berocket_plugin_paid_info', '', HOUR_IN_SECONDS);
253 }
254 }
255 if( $plugin_id == 'all' ) {
256 return $products;
257 }
258 $product_return = '';
259 if( is_array($products) ) {
260 foreach($products as $product) {
261 if( ! empty($product['id']) && $product['id'] == $plugin_id ) {
262 $product_return = $product;
263 break;
264 }
265 }
266 }
267 return $product_return;
268 }
269
270 public function clear_product_data_transient() {
271 delete_transient($this->info[ 'plugin_name' ] . '_paid_info');
272 }
273
274 /**
275 * Function set default settings to database
276 *
277 * @return void
278 */
279 public function activation() {
280 add_option( $this->cc->values[ 'settings_name' ], $this->sanitize_option( $this->cc->defaults ) );
281 do_action('brfr_activate_' . $this->cc->info[ 'plugin_name' ]);
282 }
283
284 /**
285 * Function remove settings from database
286 *
287 * @return void
288 */
289 public static function deactivation() {
290 if( ! empty(static::$settings_name) ) {
291 do_action('brfr_deactivate_' . static::$settings_name);
292 delete_option( static::$settings_name );
293 }
294 }
295
296 /**
297 * Filter for BeRocket updater
298 */
299 public function updater_info( $plugins ) {
300 $option = $this->get_option();
301 $info = get_plugin_data( $this->cc->info[ 'plugin_file' ] );
302
303 $this->cc->info[ 'key' ] = ( isset($option[ 'plugin_key' ]) ? $option[ 'plugin_key' ] : '' );
304 $this->cc->info[ 'slug' ] = basename( $this->cc->info[ 'plugin_dir' ] );
305 $this->cc->info[ 'plugin' ] = plugin_basename( $this->cc->info[ 'plugin_file' ] );
306 $this->cc->info[ 'name' ] = $info[ 'Name' ];
307 $this->cc->info[ 'version_capability' ] = $this->plugin_version_capability;
308 if( ! empty($this->cc->values['free_slug']) ) {
309 $this->cc->info[ 'free_slug' ] = $this->cc->values['free_slug'];
310 }
311
312 $plugins[] = $this->cc->info;
313
314 return $plugins;
315 }
316
317 public function rate_stars_plugins($plugins) {
318 if( $this->plugin_version_capability < 10 ) {
319 $plugin = array(
320 'id' => $this->info['id'],
321 'name' => $this->info['name'],
322 'plugin_name' => $this->info['plugin_name'],
323 'free_slug' => $this->values['free_slug'],
324 );
325 $plugins[$this->info['id']] = $plugin;
326 }
327 return $plugins;
328 }
329
330 /**
331 * Action links on the Plugins page
332 */
333 public function plugin_action_links( $links ) {
334 $action_links = array(
335 'settings' => '<a href="' . admin_url( 'admin.php?page=' . $this->cc->values[ 'option_page' ] ) .
336 '" title="' . __( 'View Plugin Settings', 'BeRocket_domain' ) . '">' .
337 __( 'Settings', 'BeRocket_domain' ) . '</a>',
338 );
339
340 return apply_filters('brfr_action_link_' . $this->cc->info[ 'plugin_name' ], array_merge( $action_links, $links ));
341 }
342
343 /**
344 * Meta links on the Plugins page
345 */
346 public function plugin_row_meta( $links, $file ) {
347 $plugin_base_slug = plugin_basename( $this->cc->info[ 'plugin_file' ] );
348 if ( $file == $plugin_base_slug ) {
349 $meta_data = '?utm_source=plugin&utm_medium=plugins_page&utm_campaign=upgrade&utm_term='.($this->info['plugin_sku'] ?? $this->info['plugin_name']);
350 $row_meta = array(
351 'docs' => '<a href="https://docs.berocket.com/plugin/' .
352 $this->cc->values[ 'premium_slug' ] . $meta_data . '" title="' .
353 __( 'View Plugin Documentation', 'BeRocket_domain' ) .
354 '" target="_blank">' . __( 'Docs', 'BeRocket_domain' ) . '</a>',
355 );
356 if( ! empty($this->plugin_version_capability) && $this->plugin_version_capability == 3 ) {
357 if( ! empty($this->cc->values[ 'free_slug' ]) ) {
358 $row_meta['support'] = '<a href="https://wordpress.org/support/plugin/' . $this->cc->values[ 'free_slug' ] .
359 '/' . $meta_data . '" title="' . __( 'View Support Page', 'BeRocket_domain' ) .
360 '" target="_blank">' . __( 'Support', 'BeRocket_domain' ) . '</a>';
361 }
362 } elseif( ! empty($this->plugin_version_capability) && $this->plugin_version_capability > 10 ) {
363 $row_meta['premium'] = '<a href="https://berocket.com/support/support-' . $this->cc->values[ 'premium_slug' ] .
364 '" title="' . __( 'View Premium Support Page', 'BeRocket_domain' ) .
365 '" target="_blank">' . __( 'Premium Support', 'BeRocket_domain' ) . '</a>';
366 } else {
367 $row_meta['premium'] = '<a href="https://berocket.com/' . $this->cc->values[ 'premium_slug' ] . $meta_data .
368 '" title="' . __( 'View Premium Version Page', 'BeRocket_domain' ) .
369 '" target="_blank">' . __( 'Premium Version', 'BeRocket_domain' ) . '</a>';
370 }
371
372 $links = array_merge( $links, $row_meta );
373 $links = apply_filters('brfr_plugin_row_meta_' . $this->cc->info[ 'plugin_name' ], $links, $file, $this);
374 }
375
376 return $links;
377 }
378
379 /**
380 * Initialize
381 */
382 public function init() {
383 $global_option = self::get_global_option();
384 wp_enqueue_script( "jquery" );
385 if( is_admin() ) {
386 $this->register_font_awesome('fa5live');
387 include_once('includes/admin/import_export.php');
388 } else {
389 if ( ! empty($global_option['framework_products_per_page']) && intval($global_option['framework_products_per_page']) > 0 ) {
390 add_filter( 'loop_shop_per_page', array($this, 'framework_products_per_page_set'), 999999999 );
391 }
392 if( ! empty($this->framework_data['fontawesome_frontend']) ) {
393 $this->enqueue_fontawesome();
394 }
395 }
396
397 wp_add_inline_script(
398 $this->cc->info['plugin_name'] . "_execute_func",
399 ";
400 (function ($){
401 $(document).ready( function () {
402 " . $this->cc->info['plugin_name'] . "_execute_func( the_" . $this->cc->info['plugin_name'] . "_js_data.script.js_page_load );
403 });
404 })(jQuery);
405
406 function " . $this->cc->info['plugin_name'] . "_execute_func ( func ) {
407 if( the_" . $this->cc->info['plugin_name'] . "_js_data.script != 'undefined'
408 && the_" . $this->cc->info['plugin_name'] . "_js_data.script != null
409 && typeof func != 'undefined'
410 && func.length > 0 ) {
411 try {
412 eval( func );
413 } catch(err) {
414 alert('You have some incorrect JavaScript code (" . $this->cc->info['norm_name'] . ")');
415 }
416 }"
417 );
418 if ( function_exists('icl_object_id') ) {
419 include_once('libraries/wpml_compatibility.php');
420 }
421 }
422
423 public function enqueue_fontawesome($force = false) {
424 $global_option = self::get_global_option();
425 if( empty($global_option['fontawesome_frontend_disable']) ) {
426 if( br_get_value_from_array($global_option, 'fontawesome_frontend_version') == 'fontawesome5' ) {
427 $this->register_font_awesome('fa5');
428 wp_enqueue_style( 'font-awesome-5' );
429 } else {
430 $this->register_font_awesome('fa4');
431 wp_enqueue_style( 'font-awesome' );
432 }
433 } else {
434 if( br_get_value_from_array($global_option, 'fontawesome_frontend_version') == 'fontawesome5' ) {
435 $this->register_font_awesome('fa5c');
436 wp_enqueue_style( 'font-awesome-5-compat' );
437 }
438 }
439 }
440 public function framework_products_per_page_set() {
441 $global_option = self::get_global_option();
442 return intval($global_option['framework_products_per_page']);
443 }
444
445 /**
446 * Function set styles in wp_head WordPress action
447 *
448 * @return void
449 */
450 public function set_styles() {
451 $options = $this->get_option();
452 if( ! empty($options[ 'custom_css' ]) ) {
453 $previous_options = $this->get_option();
454 $custom_css = berocket_sanitize_array($options[ 'custom_css' ], array($this->cc->values[ 'settings_name' ]), $previous_options);
455 echo '<style>' . $custom_css . '</style>';
456 }
457 }
458 public function set_scripts() {
459 $options = $this->get_option();
460 $javascript = br_get_value_from_array($options, array('javascript'));
461 $is_admin = current_user_can($this->option_page_capability());
462 if(is_array($javascript)) {
463 $html = '';
464 foreach($javascript as $trigger => $script) {
465 $script = trim($script);
466 if( ! empty($script) ) {
467 $function_name = strtolower($this->info['plugin_name'] . '_' . $trigger);
468 $function_name = preg_replace("/[^a-z0-9_\s-]/", "", $function_name);
469 $function_name = 'brjst_' . preg_replace("/[\s_-]+/", "_", $function_name);
470 $html .= 'function '.$function_name.'(){try{'.$script.'}catch(err){';
471 if( $is_admin ) {
472 $html .= 'alert("You have some incorrect custom JavaScript code (Plugin: '.$this->info['full_name'].', Trigger: '.$trigger.')");';
473 $html .= 'console.log(err);';
474 }
475 $html .= '}};';
476 if( $trigger == 'load' ) {
477 $html .='jQuery(document).ready('.$function_name.');';
478 } else {
479 $html .='jQuery(document).on("'.$trigger.'", '.$function_name.');';
480 }
481 }
482 }
483 $html = trim($html);
484 if( ! empty($html) ) {
485 echo '<script>', $html, '</script>';
486 }
487 }
488 }
489
490 /**
491 * Function adding styles/scripts and settings to admin_init WordPress action
492 *
493 * @access public
494 *
495 * @return void
496 */
497 public function admin_init() {
498 add_action('upgrader_process_complete', array($this, 'clear_product_data_transient'));
499 if( is_admin() ) {
500 $this->plugin_version_check();
501 }
502 if( isset($this->plugin_version_capability) && $this->plugin_version_capability <= 5 ) {
503 berocket_admin_notices::generate_subscribe_notice();
504 if( empty($this->feature_list) || ! is_array($this->feature_list) || ! count($this->feature_list) ) {
505 $products_info = $this->get_product_data_berocket($this->info['id']);
506 if( is_array($products_info) && isset($products_info['difference']) && is_array($products_info['difference']) ) {
507 $this->feature_list = $products_info['difference'];
508 }
509 }
510 }
511 require_once( plugin_dir_path( __FILE__ ) . 'includes/settings_fields.php');
512 wp_register_script(
513 'berocket_framework_admin',
514 plugins_url( 'assets/js/admin.js', __FILE__ ),
515 array( 'jquery' ),
516 BeRocket_Framework::$framework_version
517 );
518 wp_localize_script(
519 'berocket_framework_admin',
520 'berocket_framework_admin_text',
521 array(
522 'wizard_next' => __('Next', 'BeRocket_domain'),
523 'wizard_close' => __('Close', 'BeRocket_domain'),
524 )
525 );
526
527 wp_register_style(
528 'berocket_framework_admin_style',
529 plugins_url( 'assets/css/admin.css', __FILE__ ),
530 "",
531 BeRocket_Framework::$framework_version
532 );
533
534 wp_register_style(
535 'berocket_framework_global_admin_style',
536 plugins_url( 'assets/css/global-admin.css', __FILE__ ),
537 "",
538 BeRocket_Framework::$framework_version
539 );
540
541 wp_register_script(
542 'berocket_widget-colorpicker',
543 plugins_url( 'assets/js/colpick.js', __FILE__ ),
544 array( 'jquery' ),
545 BeRocket_Framework::$framework_version
546 );
547
548 wp_register_style(
549 'berocket_widget-colorpicker-style',
550 plugins_url( 'assets/css/colpick.css', __FILE__ ),
551 "",
552 BeRocket_Framework::$framework_version
553 );
554
555 wp_register_style(
556 'berocket_font_awesome',
557 plugins_url( 'assets/css/font-awesome.min.css', __FILE__ )
558 );
559 wp_localize_script( 'berocket_framework_admin', 'berocket_framework_admin', array(
560 'security' => wp_create_nonce("search-products")
561 ) );
562 if( ! empty($_GET['page']) && $_GET['page'] == $this->cc->values[ 'option_page' ] ) {
563 if( function_exists('wp_enqueue_code_editor') ) {
564 wp_enqueue_code_editor(
565 array(
566 'type' => 'css',
567 ) );
568 }
569 wp_enqueue_script( 'berocket_framework_admin' );
570
571 wp_enqueue_style( 'berocket_framework_admin_style' );
572
573 wp_enqueue_script( 'berocket_widget-colorpicker' );
574
575 wp_enqueue_style( 'berocket_widget-colorpicker-style' );
576
577 wp_enqueue_style( 'berocket_font_awesome' );
578 }
579
580 wp_enqueue_style( 'berocket_framework_global_admin_style' );
581
582 add_filter('option_page_capability_'.$this->cc->values[ 'option_page' ], array($this, 'option_page_capability'));
583 }
584
585 public function option_page_capability($capability = '') {
586 return 'manage_berocket';
587 }
588
589 /**
590 * Function add options button to admin panel if there are 3+ plugins from BeRocket and return false
591 * Other way it return true asking main function to add own options page
592 *
593 * @access public
594 *
595 * @return boolean
596 */
597 public function admin_menu() {
598 register_setting($this->cc->values[ 'option_page' ], $this->cc->values[ 'settings_name' ], array($this->cc, 'save_settings_callback'));
599 if ( method_exists( 'BeRocket_updater', 'get_plugin_count' ) ) {
600 add_submenu_page(
601 'berocket_account',
602 $this->cc->info[ 'norm_name' ] . ' ' . __( 'Settings', 'BeRocket_domain' ),
603 $this->cc->info[ 'norm_name' ],
604 $this->option_page_capability(),
605 $this->cc->values[ 'option_page' ],
606 array(
607 $this->cc,
608 'option_form'
609 )
610 );
611
612 return false;
613 }
614
615 return true;
616 }
617
618 /**
619 * Function add options form to settings page
620 *
621 * @return void
622 */
623 public function option_form() {
624 include __DIR__ . "/templates/settings.php";
625 }
626 public function admin_settings( $tabs_info = array(), $data = array() ) {
627 $setup_style = func_get_args();
628 $setup_style = (empty($setup_style[2]) || ! is_array($setup_style[2]) ? array() : $setup_style[2]);
629 $setup_style['settings_url'] = admin_url( 'admin.php?page=' . $this->cc->values[ 'option_page' ] );
630 $this->display_admin_settings($tabs_info, $data, $setup_style);
631 }
632
633 /**
634 * Function generate settings page
635 *
636 * @var $data - array with settings data, page will be build using this
637 *
638 * @return string
639 */
640 public function display_admin_settings( $tabs_info = array(), $data = array(), $setup_style = array() ) {
641 $plugin_info = get_plugin_data( $this->cc->info[ 'plugin_file' ] );
642 global $wp;
643 $settings_url = add_query_arg( NULL, NULL );
644 $settings_url = esc_url_raw($settings_url);
645 $def_setup_style = array(
646 'settings_url' => $settings_url,
647 'use_filters_hook' => true,
648 'hide_header' => false,
649 'hide_header_links' => false,
650 'hide_save_button' => false,
651 'hide_form' => false,
652 'hide_additional_blocks' => false,
653 'header_name' => "{$this->cc->info['norm_name']} by BeRocket",
654 'header_description' => str_replace( ' By BeRocket.', '', strip_tags( $plugin_info['Description'] ) ),
655 'settings_name' => $this->cc->values['settings_name'],
656 'options' => $this->get_option(),
657 'name_for_filters' => $this->cc->info[ 'plugin_name' ]
658 );
659 $setup_style = array_merge($def_setup_style, $setup_style);
660 if( $setup_style['use_filters_hook'] ) {
661 $tabs_info = apply_filters('brfr_tabs_info_' . $setup_style['name_for_filters'], $tabs_info);
662 $data = apply_filters('brfr_data_' . $setup_style['name_for_filters'], $data);
663 }
664 if ( isset($data) and is_array($data) and count( $data ) ) {
665 $page_menu = '';
666 $is_first = true;
667 $title = '';
668 $options = $setup_style['options'];
669
670 $selected_tab = false;
671 if( ! empty($_GET['tab']) ) {
672 foreach ( $tabs_info as $tab_name => $tab_info ) {
673 if( sanitize_title( $tab_name ) == $_GET['tab'] ) {
674 $selected_tab = true;
675 }
676 }
677 }
678
679 foreach ( $tabs_info as $tab_name => $tab_info ) {
680 if( isset($tab_info['name']) ) {
681 $display_name = $tab_info['name'];
682 } else {
683 $display_name = $tab_name;
684 }
685 $page_menu .= '<li>';
686
687 $page_menu .= '<a href="' . ( empty($tab_info['link']) ? add_query_arg('tab', sanitize_title( $tab_name ), $setup_style['settings_url']) : $tab_info['link'] ) .
688 '" class="' . ( empty($tab_info['priority']) ? 'default' : $tab_info['priority'] ) .
689 ( empty($tab_info['link']) ? '' : ' redirect_link' ) .
690 ( $selected_tab ? ( sanitize_title( $tab_name ) == $_GET['tab'] ? ' active' : '' ) : ( $is_first ? ' active' : '' ) ) .
691 '" data-block="' . ( empty($tab_info['link']) ? 'berocket_framework_menu_' . sanitize_title( $tab_name ) : 'redirect_link' ) . '">';
692 if ( $tab_info['icon'] ) {
693 $page_menu .= '<span class="fa fa-' . $tab_info['icon'] . '"></span>';
694 }
695 $page_menu .= $display_name . '</a>';
696
697 $page_menu .= '</li>';
698
699 if ( ($selected_tab && sanitize_title( $tab_name ) == $_GET['tab'] ) || ( ! $selected_tab && $is_first ) ) {
700 if ( $tab_info['icon'] ) {
701 $title .= '<span class="fa fa-' . $tab_info['icon'] . '"></span>';
702 }
703 $title .= $display_name;
704 }
705
706 $is_first = false;
707 }
708 $title = apply_filters('brfr_settings_tab_title', $title);
709 if( ! $setup_style['hide_save_button'] ) {
710 $page_menu .= '<li class="berocket_framework_sidebar_save_button"><input type="submit" class="button-primary button" value="' . __( 'Save Changes', 'BeRocket_domain' ) . '" /></li>';
711 }
712 if( $setup_style['use_filters_hook'] ) {
713 $page_menu = apply_filters('brfr_page_menu_' . $setup_style['name_for_filters'], $page_menu, $tabs_info);
714 }
715
716 $is_first = true;
717 $page_content = '';
718
719 foreach ( $data as $tab_name => $tab_content ) {
720 $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' : '' ) ) . '">';
721 $page_content .= '<table class="framework-form-table berocket_framework_menu_' . sanitize_title( $tab_name ) . '">';
722
723 if ( isset($tab_content) and is_array($tab_content) and count( $tab_content ) ) {
724 foreach ( $tab_content as $item ) {
725 $item = apply_filters('brfr_menu_item_remove_'.$this->info['plugin_name'], $item, $tab_name, $tab_content);
726 if( empty($item) ) continue;
727 $class = $extra = '';
728
729 if ( isset($item['class']) && trim( $item['class'] ) ) {
730 $class = " class='" . trim( $item['class'] ) . "'";
731 }
732
733 if ( isset($item['extra']) && trim( $item['extra'] ) ) {
734 $extra = " " . trim( $item['extra'] );
735 }
736
737 $item['tr_class'] = (empty($item['tr_class']) ? '' : ' class="'.$item['tr_class'].'"');
738
739 // hook for ee
740 if ( ! empty( $item['items'] ) ) {
741 if ( ! empty( $item['items'][1] ) and
742 ! empty( $item['items'][1]['type'] ) and
743 'selectbox' == $item['items'][1]['type']
744 ) {
745 $hook_name = $item['items'][0]['name'];
746 if ( $hook_name )
747 $page_content = apply_filters( 'brfr_' . $this->info['plugin_name'] . '_settings_item_'
748 . $hook_name . '_before', $page_content, $item['items'][0],
749 $tab_name, $tab_content );
750 } else {
751 foreach ( $item['items'] as $hook_name => $temp_item_items ) {
752 $page_content = apply_filters( 'brfr_' . $this->info['plugin_name'] . '_settings_item_'
753 . $hook_name . '_before', $page_content, $temp_item_items,
754 $tab_name, $tab_content );
755 }
756 }
757 } elseif ( ! empty( $item['name'] ) or ! empty( $item['section'] ) ) {
758 if ( empty( $item['name'] ) ) {
759 $tmp_filter_name = $item['section'];
760 } else {
761 $tmp_filter_name = ( is_array( $item['name'] ) ? implode( '_', $item['name'] ) : $item['name'] );
762 }
763 $page_content = apply_filters('brfr_' . $this->info['plugin_name'] . '_settings_item_' .
764 $tmp_filter_name
765 . '_before', $page_content, $item, $tab_name, $tab_content);
766 }
767
768 $page_content .= "<tr".$item['tr_class'].">";
769
770 if ( empty($item['section']) or $item['section'] == 'field' ) {
771 $item['td_class'] = (empty($item['td_class']) ? '' : ' class="'.$item['td_class'].'"');
772 $page_content .= '<th scope="row">' . $item['label'] .'</th><td'.$item['td_class'].'><div class="br_field">';
773
774 if( ! empty($item['text_before']) ) {
775 $page_content .= $item['text_before'];
776 }
777
778 $field_items = array();
779 if( isset($item['items']) && is_array($item['items']) ) {
780 $field_items = $item['items'];
781 } else {
782 $field_items[] = $item;
783 }
784 $item_i = 0;
785 foreach( $field_items as $item_key => $field_item ) {
786 // hook for ee
787 if ( $item_key ) {
788 $page_content = apply_filters( 'brfr_' . $this->info['plugin_name'] . '_settings_item_' . $item_key . '_inline_before', $page_content, $field_item, $tab_name, $tab_content );
789 }
790
791 $class = $extra = $item_content = '';
792 if ( isset($field_item['class']) && trim( $field_item['class'] ) ) {
793 $class = " class='" . trim( $field_item['class'] ) . "'";
794 }
795
796 if ( isset($field_item['extra']) && trim( $field_item['extra'] ) ) {
797 $extra = " " . trim( $field_item['extra'] );
798 }
799 if( isset($option_values) ) {
800 unset($option_values);
801 }
802 if( empty($field_item['custom_name']) && ! empty($field_item['name']) ) {
803 if( is_array($field_item['name']) ) {
804 $option_values = $options;
805 $option_deault_values = $this->cc->defaults;
806 foreach($field_item['name'] as $field_names) {
807 if( isset($option_values) && isset($field_names) && $field_names !== '' && isset($option_values[$field_names]) ) {
808 $option_values = $option_values[$field_names];
809 } else {
810 unset($option_values);
811 }
812 if( isset($option_values) && isset($field_names) && $field_names !== '' && isset($option_deault_values[$field_names]) ) {
813 $option_deault_values = $option_deault_values[$field_names];
814 } else {
815 unset($option_deault_values);
816 }
817 }
818 } elseif( isset($options[ $field_item['name'] ]) ) {
819 $option_values = $options[ $field_item['name'] ];
820 if( isset($this->cc->defaults[ $field_item['name'] ]) ) {
821 $option_deault_values = $this->cc->defaults[ $field_item['name'] ];
822 }
823 }
824 }
825 if( ! isset($option_values) ) {
826 $option_values = NULL;
827 }
828 if( ! isset($option_deault_values) ) {
829 $option_deault_values = NULL;
830 }
831 if ( $field_item['type'] != 'checkbox' and isset( $option_values ) ) {
832 $value = $option_values;
833 } else {
834 $value = $field_item['value'];
835 }
836 if( $item_i > 0 ) {
837 $page_content .= '<span class="br_line_delimiter"></span> ';
838 }
839 $field_item['label_for'] = ( isset($field_item['label_for']) ? $field_item['label_for'] : '' );
840 $field_item['label_be_for'] = ( isset($field_item['label_be_for']) ? $field_item['label_be_for'] : '' );
841
842 $field_name = (
843 empty($field_item['custom_name']) ?
844 (
845 empty($field_item['name']) ?
846 $setup_style['settings_name'] . '[]' :
847 (
848 is_array($field_item['name']) ?
849 $setup_style['settings_name'] . '[' . implode('][', $field_item['name']) . ']' :
850 $setup_style['settings_name'] . '[' . $field_item['name'] . ']'
851 )
852 ) :
853 $field_item['custom_name']
854 );
855 if( empty($field_item['type']) ) {
856 $field_item['type'] = 'text';
857 }
858 $item_filtered_content = apply_filters('berocket_framework_item_content_'.$field_item['type'], '', $field_item, $field_name, $value, $class, $extra, $option_values, $option_deault_values);
859 if( empty($item_filtered_content) ) {
860 $item_content .= "<td class='error'>Unsupported field type!</td>";
861 } else {
862 $item_content .= $item_filtered_content;
863 }
864 if( $setup_style['use_filters_hook'] ) {
865 $item_content = apply_filters('brfr_fields_html_' . $setup_style['name_for_filters'], $item_content, $field_name, $value, $field_item);
866 }
867 $page_content .= $item_content;
868
869 // hook for ee
870 if ( $item_key ) {
871 $page_content = apply_filters( 'brfr_' . $this->info['plugin_name'] . '_settings_item_' . $item_key . '_inline_after', $page_content, $field_item, $tab_name, $tab_content );
872 }
873
874 $item_i++;
875 }
876
877 if( ! empty($item['text_after']) ) {
878 $page_content .= $item['text_after'];
879 }
880
881 $page_content .= '</div></td>';
882 } elseif ( $item['section'] == 'header' ) {
883 $page_content .= "
884 <th colspan='2'>
885 <h{$item['type']}" . $class . $extra . ">{$item['label']}</h{$item['type']}>
886 </th>";
887 } elseif ( $item['section'] == 'license' ) {
888 $page_content .= '
889 <th scope="row">' . __('Plugin key', 'BeRocket_domain') .'</th>
890 <td><div class="license-block">
891 <input id="berocket_product_key" size="50" name="' . $setup_style['settings_name'] . '[plugin_key]"
892 type="text" value="' . $options['plugin_key'] . '"/>
893 <input class="berocket_test_account_product button-secondary" data-id="' . $this->cc->info['id'] . '" type="button" value="Test"/>
894 <br />
895 <span style="color:#666666;margin-left:2px;">' . __('Key for plugin from BeRocket.com', 'BeRocket_domain') . '</span>
896 <br />
897 <div class="berocket_test_result"></div>
898 </div></td>';
899 } elseif ( method_exists( $this->cc, 'section_' . $item['section'] ) ) {
900 //$page_content = apply_filters( 'brfr_' . $this->info['plugin_name'] . '_settings_item_' . $item['section'] . '_before', $page_content, $item, $tab_name, $tab_content );
901 $section_filter = $this->cc->{'section_' . $item['section']}( $item, $options );
902 if( $setup_style['use_filters_hook'] ) {
903 $section_filter = apply_filters('brfr_' . $setup_style['name_for_filters'] . '_' . $item['section'], $section_filter, $item, $options, $setup_style['settings_name']);
904 }
905 $page_content .= $section_filter;
906
907 //$page_content = apply_filters( 'brfr_' . $this->info['plugin_name'] . '_settings_item_' . $item['section'] . '_after', $page_content, $item, $tab_name, $tab_content );
908 } else {
909 //$page_content = apply_filters( 'brfr_' . $this->info['plugin_name'] . '_settings_item_' . $item['section'] . '_before', $page_content, $item, $tab_name, $tab_content );
910
911 $section_filter = apply_filters('brfr_' . $setup_style['name_for_filters'] . '_' . $item['section'], '', $item, $options, $setup_style['settings_name']);
912 if( ! empty($section_filter) ) {
913 $page_content .= $section_filter;
914 } else {
915 $page_content .= "<th colspan='2' class='error'>Not supported section type `{$item['section']}`!</th>";
916 }
917
918 //$page_content = apply_filters( 'brfr_' . $this->info['plugin_name'] . '_settings_item_' . $item['section'] . '_after', $page_content, $item, $tab_name, $tab_content );
919 }
920
921 $page_content .= "</tr>";
922
923 // hook for ee
924 if ( ! empty( $item['items'] ) ) {
925 if ( ! empty( $item['items'][1] ) and
926 ! empty( $item['items'][1]['type'] ) and
927 'selectbox' == $item['items'][1]['type']
928 ) {
929 $hook_name = $item['items'][0]['name'];
930 if ( $hook_name )
931 $page_content = apply_filters( 'brfr_' . $this->info['plugin_name'] . '_settings_item_'
932 . $hook_name . '_after', $page_content, $item['items'][0],
933 $tab_name, $tab_content );
934 } else {
935 foreach ( $item['items'] as $hook_name => $temp_item_items ) {
936 $page_content = apply_filters( 'brfr_' . $this->info['plugin_name'] . '_settings_item_'
937 . $hook_name . '_after', $page_content, $temp_item_items,
938 $tab_name, $tab_content );
939 }
940 }
941 } elseif ( ! empty( $item['name'] ) or ! empty( $item['section'] ) ) {
942 if ( empty( $item['name'] ) ) {
943 $tmp_filter_name = $item['section'];
944 } else {
945 $tmp_filter_name = ( is_array( $item['name'] ) ? implode( '_', $item['name'] ) : $item['name'] );
946 }
947 $page_content = apply_filters('brfr_' . $this->info['plugin_name'] . '_settings_item_' .
948 $tmp_filter_name
949 . '_after', $page_content, $item, $tab_name, $tab_content);
950 }
951 }
952 }
953
954 $page_content .= '</table>';
955 $page_content .= '</div>';
956
957 $is_first = false;
958 }
959
960 if( $setup_style['use_filters_hook'] ) {
961 $page_content = apply_filters('brfr_page_content_' . $setup_style['name_for_filters'], $page_content, $data);
962 }
963
964 if( ! $setup_style['hide_header'] ) {
965 $meta_data = '?utm_source=plugin&utm_medium=settings&utm_campaign=upgrade&utm_content=header&utm_term='.($this->info['plugin_sku'] ?? $this->info['plugin_name']);
966 echo "
967 <style>.notice:not(.berocket_admin_notice){display:none!important;}</style>
968 <header>
969 <div class='br_logo_white'>
970 <a href='https://berocket.com/plugins/{$meta_data}' title='BeRocket' target='_blank'><img src='" . ( plugins_url( 'assets/images/br_logo_white.webp', __FILE__ ) ) . "' /></a>
971 </div>
972 <nav class='premium'>";
973 if( ! $setup_style['hide_header_links'] ) {
974 $header_links = array(
975 'documentation' => array(
976 'text' => "<i class='fa fa-book'></i>",
977 'link' => apply_filters('brfr_docs_link_' . $setup_style['name_for_filters'],
978 "https://docs.berocket.com/plugin/{$this->cc->values['premium_slug']}" )
979 )
980 );
981 if( ! empty($this->plugin_version_capability) && $this->plugin_version_capability > 10 ) {
982 $header_links['support'] = array(
983 'text' => "<i class='fa fa-support'></i>",
984 'link' => apply_filters('brfr_support_link_' . $setup_style['name_for_filters'],
985 "https://berocket.com/support/support-{$this->cc->values['premium_slug']}{$meta_data}" )
986 );
987 } elseif( ! empty($this->cc->values['free_slug']) ) {
988 $header_links['support'] = array(
989 'text' => "<i class='fa fa-support'></i>",
990 'link' => apply_filters('brfr_support_link_' . $setup_style['name_for_filters'],
991 "https://wordpress.org/support/plugin/{$this->cc->values['free_slug']}{$meta_data}" )
992 );
993 }
994 $header_links = apply_filters('brfr_header_links_' . $setup_style['name_for_filters'], $header_links);
995 foreach($header_links as $header_link_title => $header_link) {
996 echo "<a href='" . $header_link['link'] . "' title='" . $header_link_title . "' target='_blank'>" . $header_link['text'] . "</a>";
997 }
998 }
999 echo "</nav>
1000 <div class='br_plugin_name'>
1001 <h1>{$setup_style['header_name']}</h1>
1002 <h3>
1003 {$setup_style['header_description']}
1004 </h3>
1005 </div>
1006 </header>
1007 ";
1008 }
1009 echo '<div class="body">';
1010 echo '<ul class="side">';
1011 echo $page_menu;
1012 echo '</ul>';
1013 echo '<div class="content">';
1014 echo "<div class='title'>{$title}</div>";
1015 if( ! $setup_style['hide_form'] ) {
1016 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' : '' ) .
1017 '" method="post" action="options.php">';
1018 settings_fields( $_GET['page'] );
1019 }
1020 echo $page_content;
1021 echo '<div class="clear-both"></div>';
1022 if( ! $setup_style['hide_save_button'] ) {
1023 echo '<input type="submit" class="berocket_framework_default_save_button button-primary button" value="' . __( 'Save Changes', 'BeRocket_domain' ) . '" />';
1024 echo '<div class="br_save_error"></div>';
1025 }
1026 if( ! $setup_style['hide_form'] ) {
1027 echo '</form>';
1028 }
1029 if( ! $setup_style['hide_additional_blocks'] ) {
1030 if ( file_exists( $this->info['plugin_dir'] . '/templates/premium.php' ) ) {
1031 require_once( $this->info['plugin_dir'] . '/templates/premium.php' );
1032 } else {
1033 require_once( plugin_dir_path( __FILE__ ) . 'templates/premium.php');
1034 }
1035 }
1036 echo '</div>';
1037 echo '<div class="clear-both"></div>';
1038 echo '</div>';
1039 }
1040 }
1041
1042 /**
1043 * Load template from theme | plugin
1044 *
1045 * @access public
1046 *
1047 * @param string $name template name
1048 *
1049 * @return void
1050 */
1051 public function br_get_template_part( $name = '' ) {
1052 $template = '';
1053
1054 // Look in your_child_theme/woocommerce-%PLUGINNAME%/name.php
1055 if ( $name ) {
1056 $template = locate_template( "woocommerce-" . $this->cc->info[ 'plugin_name' ] . "/{$name}.php" );
1057 }
1058
1059 // Get default slug-name.php
1060 if ( ! $template && $name && file_exists( $this->cc->info[ 'templates' ] . "{$name}.php" ) ) {
1061 $template = $this->cc->info[ 'templates' ] . "{$name}.php";
1062 }
1063
1064 // Allow 3rd party plugin filter template file from their plugin
1065 $template = apply_filters( $this->cc->info[ 'plugin_name' ] . '_get_template_part', $template, $name );
1066
1067 if ( $template ) {
1068 load_template( $template, false );
1069 }
1070 }
1071
1072 /**
1073 * Load admin file-upload scripts and styles
1074 *
1075 * @access public
1076 *
1077 * @return void
1078 */
1079 public static function admin_enqueue_scripts() {}
1080 public static function wp_enqueue_media () {
1081 if ( function_exists( 'wp_enqueue_media' ) ) {
1082 wp_enqueue_media();
1083 } else {
1084 wp_enqueue_style( 'thickbox' );
1085 wp_enqueue_script( 'media-upload' );
1086 wp_enqueue_script( 'thickbox' );
1087 }
1088 }
1089 public function save_settings_callback($settings) {
1090 if ( isset( $settings ) ) {
1091 $settings = $this->sanitize_option( $settings );
1092 }
1093 return $settings;
1094 }
1095
1096 /**
1097 * Checking if we are on Settings page
1098 *
1099 * @access public
1100 *
1101 * @return boolean
1102 */
1103 public function check_screen() {
1104 $screen = get_current_screen();
1105 if ( $screen->id == 'woocommerce_page_br-' . $this->cc->info[ 'plugin_name' ] ) {
1106 return true;
1107 }
1108
1109 return false;
1110 }
1111
1112 /**
1113 * Sanitize option function
1114 *
1115 * @access public
1116 *
1117 * @return mixed
1118 */
1119 public function sanitize_option( $input ) {
1120 $previous_options = $this->get_option();
1121 $new_input = $this->recursive_array_set( $this->cc->defaults, $input );
1122 $new_input = berocket_sanitize_array($new_input, array($this->cc->values[ 'settings_name' ]), $previous_options);
1123 wp_cache_delete( $this->cc->values[ 'settings_name' ], 'berocket_framework_option' );
1124 return apply_filters('brfr_sanitize_option_' . $this->cc->info[ 'plugin_name' ], $new_input, $input, $this->cc->defaults);
1125 }
1126
1127 /**
1128 * Settings correct values for the array. If it exist in the input it will be used
1129 * if not - default will be used
1130 *
1131 * @access public
1132 *
1133 * @return mixed
1134 */
1135 public static function recursive_array_set( $default, $options ) {
1136 $result = array();
1137
1138 foreach ( $default as $key => $value ) {
1139 if ( array_key_exists( $key, $options ) ) {
1140 if ( is_array( $value ) ) {
1141 if ( is_array( $options[ $key ] ) ) {
1142 $result[ $key ] = self::recursive_array_set( $value, $options[ $key ] );
1143 } else {
1144 $result[ $key ] = self::recursive_array_set( $value, array() );
1145 }
1146 } else {
1147 $result[ $key ] = $options[ $key ];
1148 }
1149 } else {
1150 if ( is_array( $value ) ) {
1151 $result[ $key ] = self::recursive_array_set( $value, array() );
1152 } else {
1153 $result[ $key ] = '';
1154 }
1155 }
1156 }
1157
1158 foreach ( $options as $key => $value ) {
1159 if ( ! array_key_exists( $key, $result ) ) {
1160 $result[ $key ] = $value;
1161 }
1162 }
1163
1164 return $result;
1165 }
1166
1167 /**
1168 * Getting plugin option values
1169 *
1170 * @access public
1171 *
1172 * @return mixed
1173 */
1174 public function get_option() {
1175 if ( ! function_exists('icl_object_id') ) {
1176 $options = wp_cache_get( $this->cc->values[ 'settings_name' ], 'berocket_framework_option' );
1177 }
1178 if( empty($options) ) {
1179 $options = get_option( $this->cc->values[ 'settings_name' ] );
1180
1181 if ( ! empty($options) && is_array( $options ) ) {
1182 $options = array_merge( $this->cc->defaults, $options );
1183 } else {
1184 $options = $this->cc->defaults;
1185 }
1186 $options = apply_filters('brfr_get_option_cache_' . $this->cc->info[ 'plugin_name' ], $options, $this->cc->defaults);
1187 wp_cache_set( $this->cc->values[ 'settings_name' ], $options, 'berocket_framework_option', 600 );
1188 }
1189
1190 $options = apply_filters('brfr_get_option_' . $this->cc->info[ 'plugin_name' ], $options, $this->cc->defaults);
1191
1192 return $options;
1193 }
1194 public static function get_global_option($site = false) {
1195 $option_func = $site ? 'get_site_option' : 'get_option';
1196 $new_option = $option_func( 'BeRocket_account_option' );
1197 if( ! is_array($new_option) ) {
1198 $new_option = array();
1199 }
1200 if( empty($new_option['fontawesome_frontend_version']) ) {
1201 $option = $option_func('berocket_framework_option_global');
1202 if( is_array($option) ) {
1203 $new_option = array_merge($new_option, $option);
1204 }
1205 }
1206 return $new_option;
1207 }
1208 public static function save_global_option($option, $site = false) {
1209 $option_func = $site ? 'update_site_option' : 'update_option';
1210 $option = $option_func('BeRocket_account_option', $option);
1211 return $option;
1212 }
1213 public function is_settings_page($settings_page) {
1214 if( ! empty($_GET['page']) && $_GET['page'] == $this->cc->values[ 'option_page' ] ) {
1215 $settings_page = true;
1216 }
1217 return $settings_page;
1218 }
1219
1220 public static function register_font_awesome($type = 'all') {
1221 if( $type == 'all' || $type == 'fa4' ) {
1222 wp_register_style( 'font-awesome', plugins_url( 'assets/css/font-awesome.min.css', __FILE__ ) );
1223 }
1224 if( $type == 'all' || $type == 'fa5' ) {
1225 wp_register_style( 'font-awesome-5', plugins_url( 'assets/css/fontawesome5.min.css', __FILE__ ) );
1226 }
1227 if( $type == 'all' || $type == 'fa5c' ) {
1228 wp_register_style( 'font-awesome-5-compat', plugins_url( 'assets/css/fontawesome4-compat.min.css', __FILE__ ) );
1229 }
1230 if( $type == 'fa5live' ) {
1231 add_action('admin_footer', array(__CLASS__, 'fa5live'));
1232 add_action('wp_footer', array(__CLASS__, 'fa5live'));
1233 wp_enqueue_style( 'font-awesome-5-compat', plugins_url( 'assets/css/fontawesome4-compat.min.css', __FILE__ ) );
1234 }
1235 }
1236 public static function fa5live() {
1237 echo '<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">';
1238 }
1239 public function plugin_version_check() {
1240 $plugins = get_option('BeRocket_Framework_plugins_version_check');
1241 if( empty($plugins) || ! is_array($plugins) ) {
1242 $plugins = array();
1243 }
1244 if( ! isset($plugins[$this->info['plugin_name']]) ) {
1245 $plugins[$this->info['plugin_name']] = '0';
1246 }
1247 if( $this->info['version'] != $plugins[$this->info['plugin_name']] ) {
1248 $this->update_version($plugins[$this->info['plugin_name']], $this->info['version']);
1249 $plugins[$this->info['plugin_name']] = $this->info['version'];
1250 }
1251 update_option('BeRocket_Framework_plugins_version_check', $plugins);
1252 }
1253 public function update_version($previous, $current) {
1254
1255 }
1256 public function init_user_capabilities($user_caps) {
1257 $user_caps[] = $this->option_page_capability();
1258 return $user_caps;
1259 }
1260 //disable fields for not admin
1261 function sanitize_array_predefine($value, $array, $option_name, $previous_settings) {
1262 if( ! is_super_admin() && $this->search_disabled_settings($option_name) ) {
1263 array_shift($option_name);
1264 $value = br_get_value_from_array($previous_settings, $option_name);
1265 }
1266 return $value;
1267 }
1268 function sanitize_array_kses($apply, $array, $option_name, $previous_settings) {
1269 if( is_super_admin() && $this->search_disabled_settings($option_name) ) {
1270 $apply = false;
1271 }
1272 return $apply;
1273 }
1274 function menu_item_remove($item, $tab_name, $tab_content) {
1275 if ( is_array($item) && ( empty($item['section']) or $item['section'] == 'field' ) ) {
1276 $field_items = array();
1277 $single = false;
1278 if( isset($item['items']) && is_array($item['items']) ) {
1279 $field_items = $item['items'];
1280 } else {
1281 $field_items[] = $item;
1282 $single = true;
1283 }
1284 $new_field_name = array();
1285 foreach($field_items as $field_name => $field_item) {
1286 $option_name = $field_item['name'];
1287 if( ! is_array($option_name) ) {
1288 $option_name = array($option_name);
1289 }
1290 array_unshift($option_name, $this->values[ 'settings_name' ]);
1291 if( ! is_super_admin() && $this->search_disabled_settings($option_name) ) {
1292 $field_item['disabled'] = true;
1293 $field_item['admin_disabled'] = true;
1294 }
1295 $new_field_name[$field_name] = $field_item;
1296
1297 }
1298 if( count($new_field_name) > 0 ) {
1299 if( $single ) {
1300 $item = array_pop($new_field_name);
1301 } else {
1302 $item['items'] = $new_field_name;
1303 }
1304 } else {
1305 $item = false;
1306 }
1307 } elseif( ! empty($item['name']) ) {
1308 $option_name = $item['name'];
1309 if( ! is_array($option_name) ) {
1310 $option_name = array($option_name);
1311 }
1312 array_unshift($option_name, $this->values[ 'settings_name' ]);
1313 if( ! is_super_admin() &&$this->search_disabled_settings($option_name) ) {
1314 $item = false;
1315 }
1316 }
1317 return $item;
1318 }
1319 function search_disabled_settings($option_name) {
1320 $disable = false;
1321 if( is_array($this->disable_settings_for_admin) && count($this->disable_settings_for_admin) > 0 ) {
1322 foreach($this->disable_settings_for_admin as $search_option_name) {
1323 array_unshift($search_option_name, $this->values[ 'settings_name' ]);
1324 if(berocket_check_array_same($option_name, $search_option_name) ) {
1325 $disable = true;
1326 }
1327 }
1328 }
1329 return $disable;
1330 }
1331 function disable_for_old_plugins($apply, $array, $option_name, $previous_settings) {
1332 if( is_array($option_name) && count($option_name) > 0 ) {
1333 $base_name = array_shift($option_name);
1334 if( $base_name === $this->values[ 'settings_name' ] && version_compare($this->plugin_framework_version, '2.7', '<') ) {
1335 $apply = false;
1336 }
1337 }
1338 return $apply;
1339 }
1340 function hpos_compatible() {
1341 if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
1342 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', $this->info['plugin_file'], ( ! empty($this->values['hpos_comp']) ) );
1343 }
1344 }
1345 }
1346 add_action('admin_init', 'BeRocket_admin_init_user_capabilities');
1347 function BeRocket_admin_init_user_capabilities() {
1348 global $wp_roles;
1349 $role_names = $wp_roles->get_names();
1350 $berocket_roles = apply_filters('BeRocket_admin_init_user_capabilities', array('manage_berocket', 'manage_berocket_account'));
1351 foreach($role_names as $role_name => $role_text) {
1352 $role_object = get_role( $role_name );
1353 if( $role_object->has_cap( 'manage_options' ) || $role_name == 'administrator' ) {
1354 foreach($berocket_roles as $berocket_role) {
1355 $role_object->add_cap( $berocket_role );
1356 }
1357 }
1358 }
1359 }
1360 }
1361