/** * Enqueue assets for shortcodes * * @global type $Wr_Megamenu_By_Sc_Providers * * @param type $this_ : current shortcode object * @param type $extra : frontend_assets/ admin_assets * @param type $post_fix : _frontend/ '' */ public static function shortcode_enqueue_assets($this_, $extra, $post_fix = '') { $extra_js = isset($this_->config['exception']) && isset($this_->config['exception'][$extra]) && is_array($this_->config['exception'][$extra]); $assets = array_merge($extra_js ? $this_->config['exception'][$extra] : array(), array(str_replace('wr_', '', $this_->config['shortcode']) . $post_fix)); foreach ($assets as $asset) { if (!preg_match('/\\.(css|js)$/', $asset)) { WR_Megamenu_Init_Assets::load($asset); } else { global $Wr_Megamenu_By_Sc_Providers; if (empty($Wr_Megamenu_By_Sc_Providers)) { continue; } // load assets file in common assets directory of provider $default_assets = self::assets_default($this_, $asset); // if can't find the asset file, search in /assets folder of the shortcode if (!$default_assets) { // Get path of directory contains all shortcodes of provider $shortcode_dir = WR_Megamenu_Helpers_Shortcode::get_provider_info($this_->config['shortcode'], 'shortcode_dir'); if ($shortcode_dir == WR_MEGAMENU_LAYOUT_PATH) { // this is core PB $sc_path = WR_MEGAMENU_ELEMENT_PATH; $sc_uri = WR_MEGAMENU_ROOT_URL . basename($sc_path); } else { // Get directory of shortcodes of this provider $plugin_path = WR_Megamenu_Helpers_Shortcode::get_provider_info($this_->config['shortcode'], 'path'); $plugin_uri = WR_Megamenu_Helpers_Shortcode::get_provider_info($this_->config['shortcode'], 'uri'); $shortcode_dir_arr = (array) WR_Megamenu_Helpers_Shortcode::get_provider_info($this_->config['shortcode'], 'shortcode_dir'); $shortcode_dir = reset($shortcode_dir_arr); $sc_path = $plugin_path . basename($shortcode_dir); if (is_dir($sc_path)) { $sc_uri = $plugin_uri . basename($shortcode_dir); } else { $sc_path = $plugin_path; $sc_uri = $plugin_uri; } } $ext_regex = '/(_frontend)*\\.(js|css)$/'; if (preg_match($ext_regex, $asset)) { // load assets in directory of shortcodes $require_sc = preg_replace($ext_regex, '', $asset); self::assets_specific_shortcode($require_sc, $asset, $sc_path, $sc_uri); } else { // load js/css file in directory of current shortcode $exts = array('js', 'css'); foreach ($exts as $ext) { $require_sc = $this_->config['shortcode']; $file = $asset . ".{$ext}"; // if this asset is processed, leave it self::assets_check($file); // enqueue or add to cache file self::assets_specific_shortcode($require_sc, $file, $sc_path, $sc_uri); // store it as processed asset self::assets_check($file, true); } } } } } }