Beispiel #1
0
 /**
  * Search relative path in: child theme -> parent "theme" directory and return full path
  * @param string $rel_path
  * @return false|string
  */
 public function locate_path($rel_path)
 {
     try {
         return FW_File_Cache::get($cache_key = 'core:theme:path:' . $rel_path);
     } catch (FW_File_Cache_Not_Found_Exception $e) {
         if (is_child_theme() && file_exists(fw_get_stylesheet_customizations_directory('/theme' . $rel_path))) {
             $path = fw_get_stylesheet_customizations_directory('/theme' . $rel_path);
         } elseif (file_exists(fw_get_template_customizations_directory('/theme' . $rel_path))) {
             $path = fw_get_template_customizations_directory('/theme' . $rel_path);
         } else {
             $path = false;
         }
         FW_File_Cache::set($cache_key, $path);
         return $path;
     }
 }
Beispiel #2
0
/**
 * Search relative path in child then in parent theme directory and return full path
 *
 * @param  string $rel_path '/some/path_to_dir' or '/some/path_to_file.php'
 * @return string URI
 */
function fw_locate_theme_path($rel_path)
{
    try {
        return FW_File_Cache::get($cache_key = 'theme-path:' . $rel_path);
    } catch (FW_File_Cache_Not_Found_Exception $e) {
        if (is_child_theme() && file_exists(get_stylesheet_directory() . $rel_path)) {
            $result = get_stylesheet_directory() . $rel_path;
        } elseif (file_exists(get_template_directory() . $rel_path)) {
            $result = get_template_directory() . $rel_path;
        } else {
            $result = false;
        }
        FW_File_Cache::set($cache_key, $result);
        return $result;
    }
}
Beispiel #3
0
 /**
  * Include all files from directory, from all extension's locations: framework, child, parent
  * @param string|FW_Extension $extension
  * @param string $dir_rel_path
  * @param bool $themeFirst
  *        false - [framework, parent, child]
  *        true  - [child, parent, framework]
  */
 private static function include_extension_directory_all_locations($extension, $dir_rel_path, $themeFirst = false)
 {
     if (is_string($extension)) {
         $extension = fw()->extensions->get($extension);
     }
     $paths = $extension->get_customizations_locations();
     $paths[$extension->get_path()] = $extension->get_uri();
     if (!$themeFirst) {
         $paths = array_reverse($paths);
     }
     foreach ($paths as $path => $uri) {
         try {
             $files = FW_File_Cache::get($cache_key = 'core:ext:glob:inc-all-php:' . $extension->get_name() . ':' . $path);
         } catch (FW_File_Cache_Not_Found_Exception $e) {
             $files = glob($path . $dir_rel_path . '/*.php');
             FW_File_Cache::set($cache_key, $files);
         }
         if ($files) {
             foreach ($files as $dir_file_path) {
                 fw_include_file_isolated($dir_file_path);
             }
         }
     }
 }
 /**
  * @internal
  */
 public static function _reset_blog_id()
 {
     self::$blog_id = null;
 }
 /**
  * @param string $rel_path E.g. '/static/js/scripts.js'
  * @return string URI E.g. 'http: //wordpress.com/.../extensions/<extension>/static/js/scripts.js'
  */
 public final function locate_URI($rel_path)
 {
     try {
         return FW_File_Cache::get($cache_key = 'ext:' . $this->get_name() . ':uri:' . $rel_path);
     } catch (FW_File_Cache_Not_Found_Exception $e) {
         $result = false;
         $locations = $this->customizations_locations;
         $locations[$this->get_path()] = $this->get_uri();
         foreach ($locations as $path => $uri) {
             if (file_exists($path . $rel_path)) {
                 $result = $uri . $rel_path;
                 break;
             }
         }
         FW_File_Cache::set($cache_key, $result);
         return $result;
     }
 }