$attr ) { add_submenu_page( $attr['parent_slug'], $attr['page_title'], $attr['menu_title'], 'manage_options', 'bsf-extensions-' . $attr['product_id'], 'bsf_extensions_callback' ); } } } } if(!function_exists('register_bsf_extension_page_network')) { function register_bsf_extension_page_network() { $themes = wp_get_themes(array('allowed' => 'network')); foreach( $themes as $theme ) { if ( $theme->Name == 'iMedica' ) { add_submenu_page( 'bsf-registration', __('iMedica Extensions','bsf'), __('iMedica Extensions','bsf'), 'manage_options', 'bsf-extensions-10395942', 'bsf_extensions_callback' ); break; } } $installer_menu = ''; $reg_menu = array(); $reg_menu = apply_filters( 'bsf_installer_menu', $reg_menu, $installer_menu ); if( is_array( $reg_menu ) ) { foreach ( $reg_menu as $installer => $attr ) { add_submenu_page( 'bsf-registration', $installer .' ' . $attr['page_title'], $installer .' ' . $attr['menu_title'], 'manage_options', 'bsf-extensions-' . $attr['product_id'], 'bsf_extensions_callback' ); } } } } if ( ! function_exists( 'bsf_extensions_callback' ) ) { function bsf_extensions_callback() { include_once 'plugin-installer/index.php'; } } if(!function_exists('bsf_extract_product_id')) { function bsf_extract_product_id($path) { $id = false; $file = rtrim($path,'/').'/admin/bsf.yml'; $file_fallback = rtrim($path,'/').'/bsf.yml'; if(is_file($file)) $file = $file; else if(is_file($file_fallback)) $file = $file_fallback; else return false; $filelines = file_get_contents($file); if(stripos($filelines,'ID:[') !== false) { preg_match_all("/ID:\[(.*?)\]/", $filelines, $matches); if(isset($matches[1])) { $id = (isset($matches[1][0])) ? $matches[1][0] : ''; } } return $id; } } add_action( 'admin_init', 'init_bsf_core' ); if(!function_exists('init_bsf_core')) { function init_bsf_core() { $plugins = get_plugins(); $themes = wp_get_themes(); $bsf_products = array(); foreach($plugins as $plugin => $plugin_data) { if(trim($plugin_data['Author']) === 'Brainstorm Force') { $plugin_data['type'] = 'plugin'; $plugin_data['template'] = $plugin; $plugin_data['path'] = dirname(realpath(WP_PLUGIN_DIR.'/'.$plugin)); $id = bsf_extract_product_id($plugin_data['path']); if($id !== false) $plugin_data['id'] = $id; // without readme.txt filename array_push($bsf_products, $plugin_data); } } foreach($themes as $theme => $theme_data) { $temp = array(); $theme_author = trim($theme_data->display('Author', FALSE)); if($theme_author === 'Brainstorm Force') { $temp['Name'] = $theme_data->get('Name'); $temp['ThemeURI'] = $theme_data->get('ThemeURI'); $temp['Description'] = $theme_data->get('Description'); $temp['Author'] = $theme_data->get('Author'); $temp['AuthorURI'] = $theme_data->get('AuthorURI'); $temp['Version'] = $theme_data->get('Version'); $temp['type'] = 'theme'; $temp['template'] = $theme; $temp['path'] = realpath(get_theme_root().'/'.$theme); $id = bsf_extract_product_id($temp['path']); if($id !== false) $temp['id'] = $id; // without readme.txt filename array_push($bsf_products, $temp); } } $brainstrom_products = ( get_option( 'brainstrom_products' ) ) ? get_option( 'brainstrom_products' ) : array(); if(!empty($bsf_products)) { foreach ($bsf_products as $key => $product) { if(!(isset($product['id'])) || $product['id'] === '') continue; if(isset($brainstrom_products[$product['type'].'s'][$product['id']])) $bsf_product_info = $brainstrom_products[$product['type'].'s'][$product['id']]; else $bsf_product_info = array(); $bsf_product_info['template'] = $product['template']; $bsf_product_info['type'] = $product['type']; $bsf_product_info['id'] = $product['id']; $brainstrom_products[$product['type'].'s'][$product['id']] = $bsf_product_info; } } update_option('brainstrom_products', $brainstrom_products); } } if(is_multisite()) { $brainstrom_products = (get_option('brainstrom_products')) ? get_option('brainstrom_products') : array(); if(!empty($brainstrom_products)) { $bsf_product_themes = (isset($brainstrom_products['themes'])) ? $brainstrom_products['themes'] : array(); if(!empty($bsf_product_themes)) { foreach ($bsf_product_themes as $id => $theme) { global $bsf_theme_template; $template = $theme['template']; $bsf_theme_template = $template; } } } } // assets add_action( 'admin_enqueue_scripts', 'register_bsf_core_admin_styles', 1 ); if(!function_exists('register_bsf_core_admin_styles')) { function register_bsf_core_admin_styles($hook) { //echo '--------------------------------------........'.$hook;die(); // bsf core style $hook_array = array( 'toplevel_page_bsf-registration', 'update-core.php', 'dashboard_page_bsf-registration', 'index_page_bsf-registration', 'admin_page_bsf-extensions', 'settings_page_bsf-registration' ); $hook_array = apply_filters('bsf_core_style_screens',$hook_array); if( in_array($hook, $hook_array) || strpos( $hook, 'bsf-extensions' ) !== false ){ // add function here global $bsf_core_path; $bsf_core_url = bsf_convert_core_path_to_relative($bsf_core_path); $path = $bsf_core_url.'/assets/css/style.css'; wp_register_style( 'bsf-core-admin', $path ); wp_enqueue_style( 'bsf-core-admin' ); } // frosty script $hook_frosty_array = array(); $hook_frosty_array = apply_filters('bsf_core_frosty_screens',$hook_frosty_array); if(in_array($hook, $hook_frosty_array)){ global $bsf_core_path; $bsf_core_url = bsf_convert_core_path_to_relative($bsf_core_path); $path = $bsf_core_url.'/assets/js/frosty.js'; $css_path = $bsf_core_url.'/assets/css/frosty.css'; wp_register_script( 'bsf-core-frosty', $path ); wp_enqueue_script( 'bsf-core-frosty' ); wp_register_style( 'bsf-core-frosty-style', $css_path ); wp_enqueue_style( 'bsf-core-frosty-style' ); } } } if(is_multisite()) { add_action('admin_print_scripts', 'print_bsf_styles'); if(!function_exists('print_bsf_styles')) { function print_bsf_styles() { global $bsf_core_path; $bsf_core_url = bsf_convert_core_path_to_relative($bsf_core_path); $path = $bsf_core_url.'/assets/fonts'; echo ""; } } } if ( ! function_exists( 'bsf_flush_bundled_products' ) ) { function bsf_flush_bundled_products() { $bsf_force_check_extensions = get_option( 'bsf_force_check_extensions', false ); if ( $bsf_force_check_extensions == true ) { delete_option( 'brainstrom_bundled_products' ); delete_site_transient( 'bsf_get_bundled_products' ); update_option( 'bsf_force_check_extensions', false ); } } } add_action( 'bsf_after_plugin_installer', 'bsf_flush_bundled_products' ); /** * Return extension installer page URL */ if ( ! function_exists( 'bsf_exension_installer_url' ) ) { function bsf_exension_installer_url( $priduct_id ) { if ( is_multisite() ) { return network_admin_url( 'admin.php?page=bsf-extensions-' . $priduct_id ); } else { return admin_url( 'admin.php?page=bsf-extensions-' . $priduct_id ); } } } /** * Return array of bundled plugins for a specific * * @since Graupi 1.9 */ if ( ! function_exists( 'bsf_bundled_plugins' ) ) { function bsf_bundled_plugins( $product_id = '' ) { $products = array(); $brainstrom_bundled_products = get_option( 'brainstrom_bundled_products', '' ); if ( $brainstrom_bundled_products !== '' ) { if ( array_key_exists( $product_id, $brainstrom_bundled_products ) ) { $products = $brainstrom_bundled_products[ $product_id ]; } } return $products; } } /** * Get product name from product ID * * @since Graupi 1.9 */ if ( ! function_exists( 'brainstrom_product_name' ) ) { function brainstrom_product_name( $product_id = '' ) { $product_name = ''; $brainstrom_products = get_option( 'brainstrom_products', '' ); foreach ( $brainstrom_products as $key => $value ) { foreach ( $value as $key => $product ) { if ( $product_id == $key ) { $product_name = $product['product_name']; } } } return $product_name; } } /** * Dismiss Extension installer nag * * @since Graupi 1.9 */ if ( ! function_exists( 'bsf_dismiss_extension_nag' ) ) { function bsf_dismiss_extension_nag() { if ( isset( $_GET['bsf-dismiss-notice'] ) ) { $product_id = $_GET['bsf-dismiss-notice']; update_user_meta( get_current_user_id(), $product_id . '-bsf_nag_dismiss', true ); } } } add_action( 'admin_head', 'bsf_dismiss_extension_nag' ); // For debugging uncomment line below and remove query var &bsf-dismiss-notice from url and nag will be restored. // delete_user_meta( get_current_user_id(), 'bsf-next-bsf_nag_dismiss'); /** * Generate's markup to generate notice to ask users to install required extensions. * * @since Graupi 1.9 */ if ( ! function_exists( 'bsf_extension_nag' ) ) { function bsf_extension_nag( $product_id = '' ) { $display_nag = get_user_meta( get_current_user_id(), $product_id . '-bsf_nag_dismiss', true ); if ( $display_nag === '1' ) { return; } $bsf_installed_plugins = ''; $bsf_not_installed_plugins = ''; $bsf_not_activated_plugins = ''; $installer = ''; $bsf_install = false; $bsf_activate = false; $bsf_bundled_products = bsf_bundled_plugins( $product_id ); $bsf_product_name = brainstrom_product_name( $product_id ); foreach ( $bsf_bundled_products as $key => $plugin ) { if ( ! isset( $plugin->id ) || $plugin->id == '' || ! isset( $plugin->must_have_extension ) || $plugin->must_have_extension == 'false' ) { continue; } $plugin_abs_path = WP_PLUGIN_DIR . '/' . $plugin->init; if ( is_file( $plugin_abs_path ) ) { if ( ! is_plugin_active( $plugin->init ) ) { $bsf_not_activated_plugins .= $bsf_bundled_products[ $key ]->name . ', '; } } else { $bsf_not_installed_plugins .= $bsf_bundled_products[ $key ]->name . ', '; } } $bsf_not_activated_plugins = rtrim( $bsf_not_activated_plugins, ", " ); $bsf_not_installed_plugins = rtrim( $bsf_not_installed_plugins, ", " ); if ( $bsf_not_activated_plugins !== '' || $bsf_not_installed_plugins !== '' ) { echo '

'; if ( $bsf_not_activated_plugins !== '' ) { echo '

'; echo $bsf_product_name . __( ' requires following plugins to be active : ', 'bsf' ); echo ""; echo $bsf_not_activated_plugins; echo ""; echo '

'; $bsf_activate = true; } if ( $bsf_not_installed_plugins !== '' ) { echo '

'; echo $bsf_product_name . __( ' requires following plugins to be installed and activated : ', 'bsf' ); echo ""; echo $bsf_not_installed_plugins; echo ""; echo '

'; $bsf_install = true; } if ( $bsf_activate == true ) { $installer .= '' . __( 'Begin activating plugins', 'bsf' ) . ' | '; } if ( $bsf_install == true ) { $installer .= '' . __( 'Begin installing plugins', 'bsf' ) . ' | '; } $installer .= '' . __( 'Dismiss This Notice', 'bsf' ) . ''; $installer = ltrim( $installer, '| ' ); echo '

'; echo rtrim( $installer, ' |' ); echo '

'; echo '

'; } } } /** * Check if bundled products data on site is from old version of graupi and force refresh the data if required. */ function bsf_check_correct_updater_data() { $brainstrom_bundled_products = get_option( 'brainstrom_bundled_products', array() ); $url = ''; foreach ( $brainstrom_bundled_products as $key => $value) { if ( is_object( $value ) || is_object( $brainstrom_bundled_products ) ) { if ( is_multisite() ) { $url = network_admin_url( 'admin.php?page=bsf-registration&remove-bundled-products', $scheme ); } else { $url = admin_url( 'index.php?page=bsf-registration&remove-bundled-products' ); } continue; } } // if page is reloaded once dont check agan, this may result in redirect loop if brainstorm products are not being updated. if ( $url !== '' && ! isset( $_GET['bsf-reload-page'] ) ) { echo ''; } } add_action( 'admin_init', 'bsf_check_correct_updater_data', 2 );