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); } }
/** * Return config key value, or entire config array * Config array is merged from child configs * @param string|null $key Multi key format accepted: 'a/b/c' * @param mixed $default_value * @return mixed|null */ public final function get_config($key = null, $default_value = null) { $cache_key = self::$cache_key . '/config'; try { $config = FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { $config = array('settings_form_ajax_submit' => true, 'settings_form_side_tabs' => false); if (file_exists(fw_get_template_customizations_directory('/theme/config.php'))) { $variables = fw_get_variables_from_file(fw_get_template_customizations_directory('/theme/config.php'), array('cfg' => null)); if (!empty($variables['cfg'])) { $config = array_merge($config, $variables['cfg']); unset($variables); } } if (is_child_theme() && file_exists(fw_get_stylesheet_customizations_directory('/theme/config.php'))) { $variables = fw_get_variables_from_file(fw_get_stylesheet_customizations_directory('/theme/config.php'), array('cfg' => null)); if (!empty($variables['cfg'])) { $config = array_merge($config, $variables['cfg']); unset($variables); } } unset($path); FW_Cache::set($cache_key, $config); } return $key === null ? $config : fw_akg($key, $config, $default_value); }
/** * Return config key value, or entire config array * Config array is merged from child configs * @param string|null $key Multi key format accepted: 'a/b/c' * @return mixed|null */ public final function get_config($key = null) { $cache_key = $this->get_cache_key() . '/config'; try { $config = FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { list($search_in_framework, $search_in_parent_theme, $search_in_child_theme) = $this->correct_search_in_locations(true, true, true); $rel_path = $this->get_rel_path() . '/config.php'; $config = array(); $paths = array(); if ($search_in_framework) { $paths[] = fw_get_framework_directory('/extensions' . $rel_path); } if ($search_in_parent_theme) { $paths[] = fw_get_template_customizations_directory('/extensions' . $rel_path); } if ($search_in_child_theme) { $paths[] = fw_get_stylesheet_customizations_directory('/extensions' . $rel_path); } foreach ($paths as $path) { if (file_exists($path)) { $variables = fw_get_variables_from_file($path, array('cfg' => null)); if (!empty($variables['cfg'])) { $config = array_merge($config, $variables['cfg']); unset($variables); } } } unset($path); FW_Cache::set($cache_key, $config); } return $key === null ? $config : fw_akg($key, $config); }
/** * 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; } }
/** * Scan all directories for extensions * * @param bool $reset_cache * * @return array */ private function get_installed_extensions($reset_cache = false) { $cache_key = $this->get_cache_key('installed_extensions'); if ($reset_cache) { FW_Cache::del($cache_key); } try { return FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { $search_paths = array('framework' => fw_get_framework_directory('/extensions'), 'parent' => fw_get_template_customizations_directory('/extensions')); if (is_child_theme()) { $search_paths['child'] = fw_get_stylesheet_customizations_directory('/extensions'); } $extensions = array(); foreach ($search_paths as $source => $path) { $this->read_extensions($source, $path, $extensions); } FW_Cache::set($cache_key, $extensions); return $extensions; } }