private static function load_from_extensions_recursive($extensions) { /* * Loop each extension * if it has a shortcodes folder load the shortcodes from it * if an extension has subextensions then recursion */ foreach ($extensions as $ext_name => $children) { $extension = fw()->extensions->get($ext_name); $rel_path = $extension->get_rel_path(); // framework $fw_path = fw_get_framework_directory('/extensions' . $rel_path . '/shortcodes'); if (file_exists($fw_path)) { self::load_from_shortcodes_folder(array('path' => $fw_path, 'uri' => fw_get_framework_directory_uri('/extensions' . $rel_path . '/shortcodes'))); } // parent theme framework-customizations $parent_fws_path = fw_get_template_customizations_directory('/extensions' . $rel_path . '/shortcodes'); if (file_exists($parent_fws_path)) { self::load_from_shortcodes_folder(array('path' => $parent_fws_path, 'uri' => fw_get_template_customizations_directory_uri('/extensions' . $rel_path . '/shortcodes'))); } // child theme framework-customizations if (is_child_theme()) { $child_fws_path = fw_get_stylesheet_customizations_directory('/extensions' . $rel_path . '/shortcodes'); if (file_exists($child_fws_path)) { self::load_from_shortcodes_folder(array('path' => $child_fws_path, 'uri' => fw_get_stylesheet_customizations_directory_uri('/extensions' . $rel_path . '/shortcodes'))); } } if (!empty($children)) { self::load_from_extensions_recursive($children); } } }
/** * @param FW_Extension $extension */ private static function load_extension_shortcodes($extension) { $ext_name = $extension->get_name(); if (version_compare(fw()->manifest->get_version(), '2.2', '<')) { $ext_rel_path = $extension->get_rel_path(); if ($extension->get_declared_source() === 'framework') { self::load_folder_shortcodes($ext_name, array('path' => $extension->get_declared_path('/shortcodes'), 'uri' => $extension->get_declared_URI('/shortcodes')), array('paths' => array(fw_get_stylesheet_customizations_directory('/extensions' . $ext_rel_path . '/shortcodes'), fw_get_template_customizations_directory('/extensions' . $ext_rel_path . '/shortcodes')), 'uris' => array(fw_get_stylesheet_customizations_directory_uri('/extensions' . $ext_rel_path . '/shortcodes'), fw_get_template_customizations_directory_uri('/extensions' . $ext_rel_path . '/shortcodes')))); self::load_folder_shortcodes($ext_name, array('path' => fw_get_template_customizations_directory('/extensions' . $ext_rel_path . '/shortcodes'), 'uri' => fw_get_template_customizations_directory_uri('/extensions' . $ext_rel_path . '/shortcodes')), array('paths' => array(fw_get_stylesheet_customizations_directory('/extensions' . $ext_rel_path . '/shortcodes')), 'uris' => array(fw_get_stylesheet_customizations_directory_uri('/extensions' . $ext_rel_path . '/shortcodes')))); self::load_folder_shortcodes($ext_name, array('path' => fw_get_stylesheet_customizations_directory('/extensions' . $ext_rel_path . '/shortcodes'), 'uri' => fw_get_stylesheet_customizations_directory_uri('/extensions' . $ext_rel_path . '/shortcodes'))); } elseif ($extension->get_declared_source() === 'parent') { self::load_folder_shortcodes($ext_name, array('path' => $extension->get_declared_path('/shortcodes'), 'uri' => $extension->get_declared_URI('/shortcodes')), array('paths' => array(fw_get_stylesheet_customizations_directory('/extensions' . $ext_rel_path . '/shortcodes')), 'uris' => array(fw_get_stylesheet_customizations_directory_uri('/extensions' . $ext_rel_path . '/shortcodes')))); self::load_folder_shortcodes($ext_name, array('path' => fw_get_stylesheet_customizations_directory('/extensions' . $ext_rel_path . '/shortcodes'), 'uri' => fw_get_stylesheet_customizations_directory_uri('/extensions' . $ext_rel_path . '/shortcodes'))); } else { self::load_folder_shortcodes($ext_name, array('path' => $extension->get_declared_path('/shortcodes'), 'uri' => $extension->get_declared_URI('/shortcodes'))); } } else { $customizations_locations = array('paths' => array(), 'uris' => array()); foreach ($extension->get_customizations_locations() as $path => $uri) { $customizations_locations['paths'][] = $path . '/shortcodes'; $customizations_locations['uris'][] = $uri . '/shortcodes'; } $path = $extension->get_path('/shortcodes'); $uri = $extension->get_uri('/shortcodes'); do { if (empty($customizations_locations['paths'])) { $customizations_locations = array(); } self::load_folder_shortcodes($ext_name, array('path' => $path, 'uri' => $uri), $customizations_locations); if ($customizations_locations) { $path = array_pop($customizations_locations['paths']); $uri = array_pop($customizations_locations['uris']); } } while ($customizations_locations); } }
/** * Search relative path in: child theme -> parent theme -> framework extensions directory and return URI * * @param string $rel_path '/<extension>/path_to_dir' or '/<extension>/extensions/<another_extension>/path_to_file.php' * @param bool $search_in_framework * @param bool $search_in_parent_theme * @param bool $search_in_child_theme * @return false|string URI or false if not found */ public function locate_path_URI($rel_path, $search_in_framework = true, $search_in_parent_theme = true, $search_in_child_theme = true) { if ($search_in_child_theme && is_child_theme()) { if (file_exists(fw_get_stylesheet_customizations_directory('/extensions' . $rel_path))) { return fw_get_stylesheet_customizations_directory_uri('/extensions' . $rel_path); } } if ($search_in_parent_theme) { if (file_exists(fw_get_template_customizations_directory('/extensions' . $rel_path))) { return fw_get_template_customizations_directory_uri('/extensions' . $rel_path); } } if ($search_in_framework) { if (file_exists(fw_get_framework_directory('/extensions' . $rel_path))) { return fw_get_framework_directory_uri('/extensions' . $rel_path); } } return false; }
public function get_locations() { $cache_key = 'fw_extensions_locations'; try { return FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { /** * { '/hello/world/extensions' => 'https://hello.com/world/extensions' } */ $custom_locations = apply_filters('fw_extensions_locations', array()); $customizations_locations = array(); if (is_child_theme()) { $customizations_locations[fw_get_stylesheet_customizations_directory('/extensions')] = fw_get_stylesheet_customizations_directory_uri('/extensions'); } $customizations_locations[fw_get_template_customizations_directory('/extensions')] = fw_get_template_customizations_directory_uri('/extensions'); $customizations_locations += $custom_locations; $locations = array(); $locations[fw_get_framework_directory('/extensions')] = array('path' => fw_get_framework_directory('/extensions'), 'uri' => fw_get_framework_directory_uri('/extensions'), 'customizations_locations' => $customizations_locations, 'is' => array('framework' => true, 'custom' => false, 'theme' => false)); foreach ($custom_locations as $path => $uri) { unset($customizations_locations[$path]); $locations[$path] = array('path' => $path, 'uri' => $uri, 'customizations_locations' => $customizations_locations, 'is' => array('framework' => false, 'custom' => true, 'theme' => false)); } array_pop($customizations_locations); $locations[fw_get_template_customizations_directory('/extensions')] = array('path' => fw_get_template_customizations_directory('/extensions'), 'uri' => fw_get_template_customizations_directory_uri('/extensions'), 'customizations_locations' => $customizations_locations, 'is' => array('framework' => false, 'custom' => false, 'theme' => true)); if (is_child_theme()) { array_pop($customizations_locations); $locations[fw_get_stylesheet_customizations_directory('/extensions')] = array('path' => fw_get_stylesheet_customizations_directory('/extensions'), 'uri' => fw_get_stylesheet_customizations_directory_uri('/extensions'), 'customizations_locations' => $customizations_locations, 'is' => array('framework' => false, 'custom' => false, 'theme' => true)); } FW_Cache::set($cache_key, $locations); return $locations; } }