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