Ejemplo n.º 1
0
 /**
  * Load extension from directory
  *
  * @param null|FW_Extension $parent
  * @param array $all_extensions_tree
  * @param FW_Extension[] $all_extensions
  * @param string $dir
  * @param string $URI
  * @var int $current_depth
  */
 private static function load_extensions($dir, &$parent, &$all_extensions_tree, &$all_extensions, $URI, $current_depth)
 {
     $dirs = glob($dir . '/*', GLOB_ONLYDIR);
     if (empty($dirs)) {
         return;
     }
     foreach ($dirs as $extension_dir) {
         $extension_name = basename($extension_dir);
         if (isset($all_extensions_tree[$extension_name])) {
             if ($all_extensions[$extension_name]->get_parent() !== $parent) {
                 // extension with the same name exists in another tree
                 trigger_error('Extension "' . $extension_name . '" already loaded', E_USER_ERROR);
             }
             // this is not original extension, it contains only settings, has no class
             self::load_extensions($extension_dir . '/extensions', $all_extensions[$extension_name], $all_extensions_tree[$extension_name], $all_extensions, $URI, $current_depth + 1);
         } else {
             $class_file_name = 'class-fw-extension-' . $extension_name . '.php';
             if (file_exists($extension_dir . '/' . $class_file_name)) {
                 $all_extensions_tree[$extension_name] = array();
                 self::$extension_to_all_tree[$extension_name] =& $all_extensions_tree[$extension_name];
                 require $extension_dir . '/' . $class_file_name;
                 $class_name = 'FW_Extension_' . fw_dirname_to_classname($extension_name);
                 $all_extensions[$extension_name] = new $class_name($parent, $extension_dir, self::$current_declaring_source, $URI, $current_depth);
                 if (!$all_extensions[$extension_name] instanceof FW_Extension) {
                     trigger_error('Extension "' . $extension_name . '" should extend FW_Extension class', E_USER_ERROR);
                 }
             } elseif (file_exists($extension_dir . '/manifest.php')) {
                 /**
                  * extension class does not exists, but exists manifest, create an instance of default class
                  */
                 $all_extensions_tree[$extension_name] = array();
                 self::$extension_to_all_tree[$extension_name] =& $all_extensions_tree[$extension_name];
                 $default_class_name = 'FW_Extension_Default';
                 // check if parent class defined custom Default class for it's children extensions
                 $parent_class_name = get_class($parent);
                 if (class_exists($parent_class_name . '_Default')) {
                     $default_class_name = $parent_class_name . '_Default';
                 }
                 $all_extensions[$extension_name] = new $default_class_name($parent, $extension_dir, self::$current_declaring_source, $URI, $current_depth);
             } else {
                 /**
                  * class or manifest does not exists, do not load this extension
                  * maybe it's a directory with configurations for a not existing extension
                  */
                 continue;
             }
             self::load_extensions($all_extensions[$extension_name]->get_declared_path() . '/extensions', $all_extensions[$extension_name], $all_extensions_tree[$extension_name], $all_extensions, $URI, $current_depth + 1);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @internal
  */
 public function _action_widgets_init()
 {
     $paths = array();
     if (FW_CT) {
         $paths[] = FW_CT_CUSTOM_DIR . '/theme/widgets';
     }
     $paths[] = FW_PT_CUSTOM_DIR . '/theme/widgets';
     $included_widgets = array();
     foreach ($paths as $path) {
         $dirs = glob($path . '/*', GLOB_ONLYDIR);
         if (!$dirs) {
             continue;
         }
         foreach ($dirs as $dir_path) {
             $dirname = basename($dir_path);
             if (isset($included_widgets[$dirname])) {
                 // this happens when a widget in child theme wants to overwrite the widget from parent theme
                 continue;
             } else {
                 $included_widgets[$dirname] = true;
             }
             fw_include_file_isolated($dir_path . '/class-fw-widget-' . $dirname . '.php');
             register_widget('FW_Widget_' . fw_dirname_to_classname($dirname));
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Load extension from directory
  *
  * @param array $data
  */
 private static function load_extensions($data)
 {
     if (false) {
         $data = array('rel_path' => '/extension', 'path' => '/path/to/extension', 'uri' => 'https://uri.to/extension', 'customizations_locations' => array('/path/to/parent/theme/customizations/extensions/ext/rel/path' => 'https://uri.to/customization/path', '/path/to/child/theme/customizations/extensions/ext/rel/path' => 'https://uri.to/customization/path'), 'all_extensions_tree' => array(), 'all_extensions' => array(), 'current_depth' => 1, 'parent' => '&$parent_extension_instance');
     }
     /**
      * Do not check all keys
      * if one not set, then sure others are not set (this is a private method)
      */
     if (!isset($data['all_extensions_tree'])) {
         $data['all_extensions_tree'] =& self::$all_extensions_tree;
         $data['all_extensions'] =& self::$all_extensions;
         $data['current_depth'] = 1;
         $data['rel_path'] = '';
         $data['parent'] = null;
     }
     $dirs = glob($data['path'] . '/*', GLOB_ONLYDIR);
     if (empty($dirs)) {
         return;
     }
     if ($data['current_depth'] > 1) {
         $customizations_locations = array();
         foreach ($data['customizations_locations'] as $customization_path => $customization_uri) {
             $customizations_locations[$customization_path . '/extensions'] = $customization_uri . '/extensions';
         }
         $data['customizations_locations'] = $customizations_locations;
     }
     foreach ($dirs as $extension_dir) {
         $extension_name = basename($extension_dir);
         $customizations_locations = array();
         foreach ($data['customizations_locations'] as $customization_path => $customization_uri) {
             $customizations_locations[$customization_path . '/' . $extension_name] = $customization_uri . '/' . $extension_name;
         }
         if (isset($data['all_extensions'][$extension_name])) {
             if ($data['all_extensions'][$extension_name]->get_parent() !== $data['parent']) {
                 // extension with the same name exists in another tree
                 trigger_error('Extension "' . $extension_name . '" is already defined ' . 'in "' . $data['all_extensions'][$extension_name]->get_declared_path() . '" ' . 'found again in "' . $extension_dir . '"', E_USER_ERROR);
             }
             // this is a directory with customizations for an extension
             self::load_extensions(array('rel_path' => $data['rel_path'] . '/' . $extension_name . '/extensions', 'path' => $data['path'] . '/' . $extension_name . '/extensions', 'uri' => $data['uri'] . '/' . $extension_name . '/extensions', 'customizations_locations' => $customizations_locations, 'all_extensions_tree' => &$data['all_extensions_tree'][$extension_name], 'all_extensions' => &$data['all_extensions'], 'current_depth' => $data['current_depth'] + 1, 'parent' => &$data['all_extensions'][$extension_name]));
         } else {
             $class_file_name = 'class-fw-extension-' . $extension_name . '.php';
             if (file_exists($extension_dir . '/manifest.php')) {
                 $data['all_extensions_tree'][$extension_name] = array();
                 self::$extension_to_all_tree[$extension_name] =& $data['all_extensions_tree'][$extension_name];
                 if (fw_include_file_isolated($extension_dir . '/' . $class_file_name)) {
                     $class_name = 'FW_Extension_' . fw_dirname_to_classname($extension_name);
                 } else {
                     $parent_class_name = get_class($data['parent']);
                     // check if parent extension has been defined custom Default class for its child extensions
                     if (class_exists($parent_class_name . '_Default')) {
                         $class_name = $parent_class_name . '_Default';
                     } else {
                         $class_name = 'FW_Extension_Default';
                     }
                 }
                 if (!is_subclass_of($class_name, 'FW_Extension')) {
                     trigger_error('Extension "' . $extension_name . '" must extend FW_Extension class', E_USER_ERROR);
                 }
                 $data['all_extensions'][$extension_name] = new $class_name(array('rel_path' => $data['rel_path'] . '/' . $extension_name, 'path' => $data['path'] . '/' . $extension_name, 'uri' => $data['uri'] . '/' . $extension_name, 'parent' => $data['parent'], 'depth' => $data['current_depth'], 'customizations_locations' => $customizations_locations));
             } else {
                 /**
                  * The manifest file does not exist, do not load this extension.
                  * Maybe it's a directory with configurations for a not existing extension.
                  */
                 continue;
             }
             self::load_extensions(array('rel_path' => $data['all_extensions'][$extension_name]->get_rel_path() . '/extensions', 'path' => $data['all_extensions'][$extension_name]->get_path() . '/extensions', 'uri' => $data['all_extensions'][$extension_name]->get_uri() . '/extensions', 'customizations_locations' => $customizations_locations, 'parent' => &$data['all_extensions'][$extension_name], 'all_extensions_tree' => &$data['all_extensions_tree'][$extension_name], 'all_extensions' => &$data['all_extensions'], 'current_depth' => $data['current_depth'] + 1));
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Load extension from directory
  *
  * @param null|FW_Extension $parent
  * @param array $all_extensions_tree
  * @param FW_Extension[] $all_extensions
  * @param string $dir
  * @param string $URI
  * @var int $current_depth
  */
 private static function load_extensions($dir, &$parent, &$all_extensions_tree, &$all_extensions, $URI, $current_depth)
 {
     $dirs = glob($dir . '/*', GLOB_ONLYDIR);
     if (empty($dirs)) {
         return;
     }
     foreach ($dirs as $extension_dir) {
         $extension_name = basename($extension_dir);
         if (isset($all_extensions[$extension_name])) {
             if ($all_extensions[$extension_name]->get_parent() !== $parent) {
                 // extension with the same name exists in another tree
                 trigger_error('Extension "' . $extension_name . '" is already defined ' . 'in "' . $all_extensions[$extension_name]->get_declared_path() . '" ' . 'found again in "' . $extension_dir . '"', E_USER_ERROR);
             }
             // this is a directory with customizations for an extension
             self::load_extensions($extension_dir . '/extensions', $all_extensions[$extension_name], $all_extensions_tree[$extension_name], $all_extensions, $URI, $current_depth + 1);
         } else {
             $class_file_name = 'class-fw-extension-' . $extension_name . '.php';
             if (file_exists($extension_dir . '/manifest.php')) {
                 $all_extensions_tree[$extension_name] = array();
                 self::$extension_to_all_tree[$extension_name] =& $all_extensions_tree[$extension_name];
                 if (file_exists($extension_dir . '/' . $class_file_name)) {
                     $class_name = 'FW_Extension_' . fw_dirname_to_classname($extension_name);
                     require $extension_dir . '/' . $class_file_name;
                 } else {
                     $parent_class_name = get_class($parent);
                     // check if parent extension has been defined custom Default class for its child extensions
                     if (class_exists($parent_class_name . '_Default')) {
                         $class_name = $parent_class_name . '_Default';
                     } else {
                         $class_name = 'FW_Extension_Default';
                     }
                 }
                 if (!is_subclass_of($class_name, 'FW_Extension')) {
                     trigger_error('Extension "' . $extension_name . '" must extend FW_Extension class', E_USER_ERROR);
                 }
                 $all_extensions[$extension_name] = new $class_name($parent, $extension_dir, self::$current_declaring_source, $URI, $current_depth);
             } else {
                 /**
                  * The manifest file does not exist, do not load this extension.
                  * Maybe it's a directory with configurations for a not existing extension.
                  */
                 continue;
             }
             self::load_extensions($all_extensions[$extension_name]->get_declared_path() . '/extensions', $all_extensions[$extension_name], $all_extensions_tree[$extension_name], $all_extensions, $URI, $current_depth + 1);
         }
     }
 }