false, ); protected $active_libraries = array(); protected $global_settings = array( 'fontawesome_frontend_disable', 'fontawesome_frontend_version', ); public $check_lib = null; protected $check_init_array = array(); public static function getInstance() { if (null === static::$instance) { static::$instance = new static(); } return static::$instance; } function __construct( $child ) { if (null === static::$instance) { static::$instance = $child; } $this->include_once_files(); $this->cc = $child; // Child Class object do_action('BeRocket_framework_init_plugin', $this->cc->info); $this->plugin_version_capability = apply_filters('brfr_plugin_version_capability_'.$this->cc->info['plugin_name'], $this->plugin_version_capability, $this); $this->defaults = apply_filters('brfr_plugin_defaults_value_'.$this->cc->info['plugin_name'], $this->defaults, $this); register_activation_hook( $this->cc->info[ 'plugin_file' ], array( $this->cc, 'activation' ) ); register_uninstall_hook( $this->cc->info[ 'plugin_file' ], array( get_class( $this->cc ), 'deactivation' ) ); add_filter( 'BeRocket_updater_add_plugin', array( $this->cc, 'updater_info' ) ); add_filter( 'berocket_admin_notices_rate_stars_plugins', array( $this, 'rate_stars_plugins' ) ); if ( $this->cc->init_validation() ) { add_action( 'init', array( $this->cc, 'init' ) ); add_action( 'wp_head', array( $this->cc, 'set_styles' ) ); add_action( 'admin_init', array( $this->cc, 'admin_init' ) ); add_action( 'admin_menu', array( $this->cc, 'admin_menu' ) ); add_action( 'admin_enqueue_scripts', array( $this->cc, 'admin_enqueue_scripts' ) ); add_action( 'wp_ajax_br_' . $this->cc->info[ 'plugin_name' ] . '_settings_save', array( $this->cc, 'save_settings' ) ); add_filter( 'plugin_row_meta', array( $this->cc, 'plugin_row_meta' ), 10, 2 ); add_filter( 'is_berocket_settings_page', array( $this->cc, 'is_settings_page' ) ); $plugin_base_slug = plugin_basename( $this->cc->info[ 'plugin_file' ] ); add_filter( 'plugin_action_links_' . $plugin_base_slug, array( $this->cc, 'plugin_action_links' ) ); add_action( 'plugins_loaded', array( $this->cc, 'plugins_loaded' ) ); add_action( 'sanitize_comment_cookies', array( $this->cc, 'sanitize_comment_cookies' ) ); add_action ( 'install_plugins_pre_plugin-information', array( $this->cc, 'install_plugins_pre_plugin_information' ), 1 ); if( empty($this->plugin_version_capability) || $this->plugin_version_capability < 10 ) { add_filter('berocket_admin_notices_subscribe_plugins', array($this, 'admin_notices_subscribe_plugins')); } $this->libraries = new BeRocket_framework_libraries($this->active_libraries, $this->info, $this->values, $this->get_option()); } do_action($this->info[ 'plugin_name' ].'_framework_construct', $this->cc); add_filter('brfr_get_plugin_version_capability_'.$this->cc->info['plugin_name'], array($this, 'get_plugin_version_capability')); } public function include_once_files() { foreach (glob($this->info['plugin_dir'] . "/includes/*.php") as $filename) { include_once($filename); } } public function init_check_lib() { if( empty($this->check_lib) ) { include_once('libraries/check_init.php'); $this->check_lib = new BeRocket_framework_check_init_lib($this->check_init_array); } } public function get_plugin_version_capability($version) { return $this->plugin_version_capability; } public function admin_notices_subscribe_plugins($plugins) { $plugins[] = $this->info['id']; return $plugins; } public function install_plugins_pre_plugin_information() { wp_print_styles('font-awesome'); } public function init_validation() { $this->init_check_lib(); return $this->check_lib->check(); } public function plugins_loaded() { if( ! empty($_POST[ $this->cc->values[ 'settings_name' ] ]) ) { $this->post = berocket_sanitize_array($_POST[ $this->cc->values[ 'settings_name' ] ]); } } public function sanitize_comment_cookies() { if( ! empty($this->post) ) { $_POST[ $this->cc->values[ 'settings_name' ] ] = $this->post; } } /** * Get plugin data from BeRocket * * @return array */ public function get_product_data_berocket() { $products = get_transient($this->info[ 'plugin_name' ] . '_paid_info'); if( $products === FALSE ) { $response = wp_remote_post('https://berocket.com/main/get_product_data/'.$this->info['id'], array( 'method' => 'POST', 'timeout' => 15, 'redirection' => 5, 'blocking' => true, 'sslverify' => false )); if( ! is_wp_error($response) ) { $out = wp_remote_retrieve_body($response); if( !empty($out) && json_decode($out) ) { $products = json_decode($out, true); set_transient($this->info[ 'plugin_name' ] . '_paid_info', $products, WEEK_IN_SECONDS); } else { set_transient($this->info[ 'plugin_name' ] . '_paid_info', '', DAY_IN_SECONDS); } } else { set_transient($this->info[ 'plugin_name' ] . '_paid_info', '', DAY_IN_SECONDS); } } return $products; } /** * Function set default settings to database * * @return void */ public function activation() { add_option( $this->cc->values[ 'settings_name' ], self::sanitize_option( $this->cc->defaults ) ); do_action('brfr_activate_' . $this->cc->info[ 'plugin_name' ]); } /** * Function remove settings from database * * @return void */ public static function deactivation() { if( ! empty(static::$settings_name) ) { do_action('brfr_deactivate_' . static::$settings_name); delete_option( static::$settings_name ); } } /** * Filter for BeRocket updater */ public function updater_info( $plugins ) { $option = $this->get_option(); $info = get_plugin_data( $this->cc->info[ 'plugin_file' ] ); $this->cc->info[ 'key' ] = ( isset($option[ 'plugin_key' ]) ? $option[ 'plugin_key' ] : '' ); $this->cc->info[ 'slug' ] = basename( $this->cc->info[ 'plugin_dir' ] ); $this->cc->info[ 'plugin' ] = plugin_basename( $this->cc->info[ 'plugin_file' ] ); $this->cc->info[ 'name' ] = $info[ 'Name' ]; $this->cc->info[ 'version_capability' ] = $this->plugin_version_capability; if( ! empty($this->cc->values['free_slug']) ) { $this->cc->info[ 'free_slug' ] = $this->cc->values['free_slug']; } $plugins[] = $this->cc->info; return $plugins; } public function rate_stars_plugins($plugins) { if( $this->plugin_version_capability < 10 ) { $plugin = array( 'id' => $this->info['id'], 'name' => $this->info['name'], 'free_slug' => $this->values['free_slug'], ); $plugins[$this->info['id']] = $plugin; } return $plugins; } /** * Action links on the Plugins page */ public function plugin_action_links( $links ) { $action_links = array( 'settings' => '' . __( 'Settings', 'BeRocket_domain' ) . '', ); return apply_filters('brfr_action_link_' . $this->cc->info[ 'plugin_name' ], array_merge( $action_links, $links )); } /** * Meta links on the Plugins page */ public function plugin_row_meta( $links, $file ) { $plugin_base_slug = plugin_basename( $this->cc->info[ 'plugin_file' ] ); if ( $file == $plugin_base_slug ) { $row_meta = array( 'docs' => '' . __( 'Docs', 'BeRocket_domain' ) . '', ); if( ! empty($this->plugin_version_capability) && $this->plugin_version_capability > 10 ) { $row_meta['premium'] = '' . __( 'Premium Support', 'BeRocket_domain' ) . ''; } else { $row_meta['premium'] = '' . __( 'Premium Version', 'BeRocket_domain' ) . ''; } $links = array_merge( $links, $row_meta ); $links = apply_filters('brfr_plugin_row_meta_' . $this->cc->info[ 'plugin_name' ], $links, $file, $this); } return $links; } /** * Initialize */ public function init() { $global_option = $this->get_global_option(); wp_enqueue_script( "jquery" ); if( is_admin() ) { self::register_font_awesome(); wp_enqueue_style( 'font-awesome' ); } elseif( ! empty($this->framework_data['fontawesome_frontend']) ) { $this->enqueue_fontawesome(); } wp_add_inline_script( $this->cc->info['plugin_name'] . "_execute_func", "; (function ($){ $(document).ready( function () { " . $this->cc->info['plugin_name'] . "_execute_func( the_" . $this->cc->info['plugin_name'] . "_js_data.script.js_page_load ); }); })(jQuery); function " . $this->cc->info['plugin_name'] . "_execute_func ( func ) { if( the_" . $this->cc->info['plugin_name'] . "_js_data.script != 'undefined' && the_" . $this->cc->info['plugin_name'] . "_js_data.script != null && typeof func != 'undefined' && func.length > 0 ) { try { eval( func ); } catch(err) { alert('You have some incorrect JavaScript code (" . $this->cc->info['norm_name'] . ")'); } }" ); if ( function_exists('icl_object_id') ) { include_once('libraries/wpml_compatibility.php'); } } public function enqueue_fontawesome($force = false) { $global_option = $this->get_global_option(); if( empty($global_option['fontawesome_frontend_disable']) ) { if( br_get_value_from_array($global_option, 'fontawesome_frontend_version') == 'fontawesome5' ) { self::register_font_awesome('fa5'); wp_enqueue_style( 'font-awesome-5' ); } else { self::register_font_awesome('fa4'); wp_enqueue_style( 'font-awesome' ); } } else { if( br_get_value_from_array($global_option, 'fontawesome_frontend_version') == 'fontawesome5' ) { self::register_font_awesome('fa5c'); wp_enqueue_style( 'font-awesome-5-compat' ); } } } /** * Function set styles in wp_head WordPress action * * @return void */ public function set_styles() { $options = $this->get_option(); echo ''; } /** * Function adding styles/scripts and settings to admin_init WordPress action * * @access public * * @return void */ public function admin_init() { if( is_admin() ) { $this->plugin_version_check(); } if( isset($this->plugin_version_capability) && $this->plugin_version_capability <= 5 ) { berocket_admin_notices::generate_subscribe_notice(); if( empty($this->feature_list) || ! is_array($this->feature_list) || ! count($this->feature_list) ) { $products_info = $this->get_product_data_berocket(); if( is_array($products_info) && isset($products_info['difference']) && is_array($products_info['difference']) ) { $this->feature_list = $products_info['difference']; } } } require_once( plugin_dir_path( __FILE__ ) . 'includes/settings_fields.php'); wp_register_script( 'berocket_framework_admin', plugins_url( 'assets/js/admin.js', __FILE__ ), array( 'jquery' ), $this->cc->info[ 'version' ] ); wp_register_style( 'berocket_framework_admin_style', plugins_url( 'assets/css/admin.css', __FILE__ ), "", $this->cc->info[ 'version' ] ); wp_register_style( 'berocket_framework_global_admin_style', plugins_url( 'assets/css/global-admin.css', __FILE__ ), "", $this->cc->info[ 'version' ] ); wp_register_script( 'berocket_widget-colorpicker', plugins_url( 'assets/js/colpick.js', __FILE__ ), array( 'jquery' ) ); wp_register_style( 'berocket_widget-colorpicker-style', plugins_url( 'assets/css/colpick.css', __FILE__ ) ); wp_register_style( 'berocket_font_awesome', plugins_url( 'assets/css/font-awesome.min.css', __FILE__ ) ); wp_localize_script( 'berocket_framework_admin', 'berocket_framework_admin', array( 'security' => wp_create_nonce("search-products") ) ); if( ! empty($_GET['page']) && $_GET['page'] == $this->cc->values[ 'option_page' ] ) { if( function_exists('wp_enqueue_code_editor') ) { wp_enqueue_code_editor( array( 'type' => 'css', ) ); } wp_enqueue_script( 'berocket_framework_admin' ); wp_enqueue_style( 'berocket_framework_admin_style' ); wp_enqueue_script( 'berocket_widget-colorpicker' ); wp_enqueue_style( 'berocket_widget-colorpicker-style' ); wp_enqueue_style( 'berocket_font_awesome' ); } wp_enqueue_style( 'berocket_framework_global_admin_style' ); add_filter('option_page_capability_'.$this->cc->values[ 'option_page' ], array($this, 'option_page_capability')); } public function option_page_capability($capability = '') { return 'manage_woocommerce'; } /** * Function add options button to admin panel if there are 3+ plugins from BeRocket and return false * Other way it return true asking main function to add own options page * * @access public * * @return boolean */ public function admin_menu() { register_setting($this->cc->values[ 'option_page' ], $this->cc->values[ 'settings_name' ], array($this->cc, 'save_settings_callback')); if ( method_exists( 'BeRocket_updater', 'get_plugin_count' ) ) { add_submenu_page( 'berocket_account', $this->cc->info[ 'norm_name' ] . ' ' . __( 'Settings', 'BeRocket_domain' ), $this->cc->info[ 'norm_name' ], $this->option_page_capability(), $this->cc->values[ 'option_page' ], array( $this->cc, 'option_form' ) ); return false; } return true; } /** * Function add options form to settings page * * @return void */ public function option_form() { include __DIR__ . "/templates/settings.php"; } public function admin_settings( $tabs_info = array(), $data = array() ) { $setup_style = func_get_args(); $setup_style = (empty($setup_style[2]) || ! is_array($setup_style[2]) ? array() : $setup_style[2]); $setup_style['settings_url'] = admin_url( 'admin.php?page=' . $this->cc->values[ 'option_page' ] ); $this->display_admin_settings($tabs_info, $data, $setup_style); } /** * Function generate settings page * * @var $data - array with settings data, page will be build using this * * @return string */ public function display_admin_settings( $tabs_info = array(), $data = array(), $setup_style = array() ) { $plugin_info = get_plugin_data( $this->cc->info[ 'plugin_file' ] ); global $wp; $settings_url = add_query_arg( NULL, NULL ); $settings_url = esc_url_raw($settings_url); $def_setup_style = array( 'settings_url' => $settings_url, 'use_filters_hook' => true, 'hide_header' => false, 'hide_header_links' => false, 'hide_save_button' => false, 'hide_form' => false, 'hide_additional_blocks' => false, 'header_name' => "{$this->cc->info['norm_name']} by BeRocket", 'header_description' => str_replace( ' By BeRocket.', '', strip_tags( $plugin_info['Description'] ) ), 'settings_name' => $this->cc->values['settings_name'], 'options' => $this->get_option(), 'name_for_filters' => $this->cc->info[ 'plugin_name' ] ); $setup_style = array_merge($def_setup_style, $setup_style); if( $setup_style['use_filters_hook'] ) { $tabs_info = apply_filters('brfr_tabs_info_' . $setup_style['name_for_filters'], $tabs_info); $data = apply_filters('brfr_data_' . $setup_style['name_for_filters'], $data); } if ( isset($data) and is_array($data) and count( $data ) ) { $page_menu = ''; $is_first = true; $title = ''; $options = $setup_style['options']; $selected_tab = false; if( ! empty($_GET['tab']) ) { foreach ( $tabs_info as $tab_name => $tab_info ) { if( sanitize_title( $tab_name ) == $_GET['tab'] ) { $selected_tab = true; } } } foreach ( $tabs_info as $tab_name => $tab_info ) { $page_menu .= '
  • '; $page_menu .= ''; if ( $tab_info['icon'] ) { $page_menu .= ''; } $page_menu .= $tab_name . ''; $page_menu .= '
  • '; if ( ($selected_tab && sanitize_title( $tab_name ) == $_GET['tab'] ) || ( ! $selected_tab && $is_first ) ) { if ( $tab_info['icon'] ) { $title .= ''; } $title .= $tab_name; } $is_first = false; } if( ! $setup_style['hide_save_button'] ) { $page_menu .= '
  • '; } if( $setup_style['use_filters_hook'] ) { $page_menu = apply_filters('brfr_page_menu_' . $setup_style['name_for_filters'], $page_menu, $tabs_info); } $is_first = true; $page_content = ''; foreach ( $data as $tab_name => $tab_content ) { $page_content .= ''; $is_first = false; } if( $setup_style['use_filters_hook'] ) { $page_content = apply_filters('brfr_page_content_' . $setup_style['name_for_filters'], $page_content, $data); } if( ! $setup_style['hide_header'] ) { echo "

    {$setup_style['header_name']}

    {$setup_style['header_description']}

    "; } echo '
    '; echo ''; echo '
    '; echo "
    {$title}
    "; if( ! $setup_style['hide_form'] ) { echo '
    '; settings_fields( $_GET['page'] ); } echo $page_content; echo '
    '; if( ! $setup_style['hide_save_button'] ) { echo ''; echo '
    '; } if( ! $setup_style['hide_form'] ) { echo '
    '; } if( ! $setup_style['hide_additional_blocks'] ) { require_once( plugin_dir_path( __FILE__ ) . 'templates/premium.php'); } echo '
    '; echo '
    '; echo '
    '; } } /** * Load template from theme | plugin * * @access public * * @param string $name template name * * @return void */ public function br_get_template_part( $name = '' ) { $template = ''; // Look in your_child_theme/woocommerce-%PLUGINNAME%/name.php if ( $name ) { $template = locate_template( "woocommerce-" . $this->cc->info[ 'plugin_name' ] . "/{$name}.php" ); } // Get default slug-name.php if ( ! $template && $name && file_exists( $this->cc->info[ 'templates' ] . "{$name}.php" ) ) { $template = $this->cc->info[ 'templates' ] . "{$name}.php"; } // Allow 3rd party plugin filter template file from their plugin $template = apply_filters( $this->cc->info[ 'plugin_name' ] . '_get_template_part', $template, $name ); if ( $template ) { load_template( $template, false ); } } /** * Load admin file-upload scripts and styles * * @access public * * @return void */ public static function admin_enqueue_scripts() { if ( function_exists( 'wp_enqueue_media' ) ) { wp_enqueue_media(); } else { wp_enqueue_style( 'thickbox' ); wp_enqueue_script( 'media-upload' ); wp_enqueue_script( 'thickbox' ); } } public function save_settings_callback($settings) { if ( isset( $settings ) ) { $settings = self::sanitize_option( $settings ); if( count($this->global_settings) ) { $global_options = $this->get_global_option(); foreach($this->global_settings as $global_setting) { if( isset($settings[$global_setting]) ) { $global_options[$global_setting] = $settings[$global_setting]; } } $this->save_global_option($global_options); } } return $settings; } /** * Checking if we are on Settings page * * @access public * * @return boolean */ public function check_screen() { $screen = get_current_screen(); if ( $screen->id == 'woocommerce_page_br-' . $this->cc->info[ 'plugin_name' ] ) { return true; } return false; } /** * Sanitize option function * * @access public * * @return mixed */ public function sanitize_option( $input ) { $new_input = self::recursive_array_set( $this->cc->defaults, $input ); return apply_filters('brfr_sanitize_option_' . $this->cc->info[ 'plugin_name' ], $new_input, $input, $this->cc->defaults); } /** * Settings correct values for the array. If it exist in the input it will be used * if not - default will be used * * @access public * * @return mixed */ public static function recursive_array_set( $default, $options ) { $result = array(); foreach ( $default as $key => $value ) { if ( array_key_exists( $key, $options ) ) { if ( is_array( $value ) ) { if ( is_array( $options[ $key ] ) ) { $result[ $key ] = self::recursive_array_set( $value, $options[ $key ] ); } else { $result[ $key ] = self::recursive_array_set( $value, array() ); } } else { $result[ $key ] = $options[ $key ]; } } else { if ( is_array( $value ) ) { $result[ $key ] = self::recursive_array_set( $value, array() ); } else { $result[ $key ] = ''; } } } foreach ( $options as $key => $value ) { if ( ! array_key_exists( $key, $result ) ) { $result[ $key ] = $value; } } return $result; } /** * Getting plugin option values * * @access public * * @return mixed */ public function get_option() { if ( ! function_exists('icl_object_id') ) { $options = wp_cache_get( $this->cc->values[ 'settings_name' ], 'berocket_framework_option' ); } if( empty($options) ) { $options = get_option( $this->cc->values[ 'settings_name' ] ); if ( ! empty($options) && is_array( $options ) ) { $options = array_merge( $this->cc->defaults, $options ); } else { $options = $this->cc->defaults; } $options = apply_filters('brfr_get_option_cache_' . $this->cc->info[ 'plugin_name' ], $options, $this->cc->defaults); wp_cache_set( $this->cc->values[ 'settings_name' ], $options, 'berocket_framework_option', 600 ); } $global_options = $this->get_global_option(); if( count($this->global_settings) ) { foreach($this->global_settings as $global_setting) { if( isset($global_options[$global_setting]) ) { $options[$global_setting] = $global_options[$global_setting]; } } } $options = apply_filters('brfr_get_option_' . $this->cc->info[ 'plugin_name' ], $options, $this->cc->defaults); return $options; } public function get_global_option() { $option = get_option('berocket_framework_option_global'); if( ! is_array($option) ) { $option = array(); } return $option; } public function save_global_option($option) { $option = update_option('berocket_framework_option_global', $option); return $option; } public function is_settings_page($settings_page) { if( ! empty($_GET['page']) && $_GET['page'] == $this->cc->values[ 'option_page' ] ) { $settings_page = true; } return $settings_page; } public static function register_font_awesome($type = 'all') { if( $type == 'all' || $type == 'fa4' ) { wp_register_style( 'font-awesome', plugins_url( 'assets/css/font-awesome.min.css', __FILE__ ) ); } if( $type == 'all' || $type == 'fa5' ) { wp_register_style( 'font-awesome-5', plugins_url( 'assets/css/fontawesome5.min.css', __FILE__ ) ); } if( $type == 'all' || $type == 'fa5c' ) { wp_register_style( 'font-awesome-5-compat', plugins_url( 'assets/css/fontawesome4-compat.min.css', __FILE__ ) ); } } public function plugin_version_check() { $plugins = get_option('BeRocket_Framework_plugins_version_check'); if( empty($plugins) || ! is_array($plugins) ) { $plugins = array(); } if( ! isset($plugins[$this->info['plugin_name']]) ) { $plugins[$this->info['plugin_name']] = '0'; } if( $this->info['version'] != $plugins[$this->info['plugin_name']] ) { $this->update_version($plugins[$this->info['plugin_name']], $this->info['version']); $plugins[$this->info['plugin_name']] = $this->info['version']; } update_option('BeRocket_Framework_plugins_version_check', $plugins); } public function update_version($previous, $current) { } } }