/**
  * @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);
     }
 }
 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);
         }
     }
 }
Example #3
0
 /**
  * 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);
 }
Example #5
0
 /**
  * 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;
 }
Example #6
0
 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;
     }
 }
 /**
  * Copy Theme Available Extensions to a tmp directory
  * Used before theme update
  * @since 2.6.0
  * @return null|WP_Error
  */
 public function theme_available_extensions_copy()
 {
     /** @var WP_Filesystem_Base $wp_filesystem */
     global $wp_filesystem;
     if (!$wp_filesystem || is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
         return new WP_Error('fs_not_initialized', __('WP Filesystem is not initialized', 'fw'));
     }
     $wpfs_tmp_dir = FW_WP_Filesystem::real_path_to_filesystem_path($this->get_tmp_dir('/theme-ext'));
     if ($wp_filesystem->exists($wpfs_tmp_dir) && !$wp_filesystem->rmdir($wpfs_tmp_dir, true)) {
         return new WP_Error('tmp_dir_rm_fail', sprintf(__('Temporary directory cannot be removed: %s', 'fw'), $wpfs_tmp_dir));
     }
     if (!FW_WP_Filesystem::mkdir_recursive($wpfs_tmp_dir)) {
         return new WP_Error('tmp_dir_rm_fail', sprintf(__('Temporary directory cannot be created: %s', 'fw'), $wpfs_tmp_dir));
     }
     $available_extensions = $this->get_available_extensions();
     $installed_extensions = $this->get_installed_extensions(true);
     $base_dir = fw_get_template_customizations_directory('/extensions');
     foreach ($installed_extensions as $name => $ext) {
         if (!(isset($available_extensions[$name]) && isset($available_extensions[$name]['theme']) && $available_extensions[$name]['theme'])) {
             continue;
         }
         if (($rel_path = preg_replace('/^' . preg_quote($base_dir, '/') . '/', '', $ext['path'])) === $base_dir) {
             return new WP_Error('rel_path_failed', sprintf(__('Failed to extract relative directory from: %s', 'fw'), $ext['path']));
         }
         if (($wpfs_path = FW_WP_Filesystem::real_path_to_filesystem_path($ext['path'])) === false) {
             return new WP_Error('real_to_wpfs_filed', sprintf(__('Failed to extract relative directory from: %s', 'fw'), $ext['path']));
         }
         $wpfs_dest_dir = $wpfs_tmp_dir . $rel_path;
         if (!FW_WP_Filesystem::mkdir_recursive($wpfs_dest_dir)) {
             return new WP_Error('dest_dir_mk_fail', sprintf(__('Failed to create directory %s', 'fw'), $wpfs_dest_dir));
         }
         if (is_wp_error($copy_result = copy_dir($wpfs_path, $wpfs_dest_dir))) {
             /** @var WP_Error $copy_result */
             return new WP_Error('ext_copy_failed', sprintf(__('Failed to copy extension to %s', 'fw'), $wpfs_dest_dir));
         }
     }
 }
Example #8
0
<?php

if (!defined('FW')) {
    die('Forbidden');
}
/** @internal */
function _filter_disable_default_shortcodes($to_disable)
{
    $list = array('accordion', 'button', 'calendar', 'call_to_action', 'icon', 'media_video', 'media_image', 'icon_box', 'notification', 'widget_area', 'table', 'map', 'contact_form');
    return array_merge($to_disable, $list);
}
add_filter('fw_ext_shortcodes_disable_shortcodes', '_filter_disable_default_shortcodes');
if (is_admin()) {
    include fw_get_template_customizations_directory() . '/includes/option-types.php';
}
 /**
  * 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;
     }
 }