예제 #1
0
 /**
  * Locate a theme file, giving priority to top themes in the stack
  *
  * If first argument is a ICE_Map instance, it is expected to be
  * a map of theme directives whose values are relative path prefixes.
  *
  * @param ICE_Map $prefix_map Optional map of directives which define path prefixes
  * @param string $file_names,... The file names that make up the RELATIVE path to the theme root
  * @return string|false
  */
 public function locate_file()
 {
     // get all args
     $file_names = func_get_args();
     // no prefix map by default
     $prefix_map = null;
     // prefixes map?
     if (!empty($file_names)) {
         if ($file_names[0] instanceof ICE_Map) {
             $prefix_map = array_shift($file_names);
         }
     }
     // still have something?
     if (empty($file_names)) {
         return false;
     }
     // loop through theme stack
     foreach ($this->theme_stack() as $theme) {
         // is theme in current loop compiled?
         if (true === $this->themes_compiled->contains($theme)) {
             // yep, skip it
             continue;
         }
         // build path to stackfile
         $stack_file = $this->theme_dir($theme);
         // inject prefix?
         if ($prefix_map && $prefix_map->contains($theme)) {
             $stack_file .= '/' . $prefix_map->item_at($theme)->get_value();
         }
         // append requested path
         $stack_file .= '/' . implode('/', $file_names);
         // does stack file exist?
         if (ICE_Files::cache($stack_file)->is_readable()) {
             return $stack_file;
         }
     }
     return false;
 }
예제 #2
0
 /**
  * Find first matching extension file in the path stack
  *
  * @param string|array $ext
  * @param string $file
  * @return string|boolean
  */
 public final function locate_file($ext, $file)
 {
     // handle strings
     if (is_string($ext)) {
         // if ext has path delim, use as is
         if (strpos($ext, self::PATH_DELIM)) {
             $ext_path = $ext;
         } elseif (class_exists($ext)) {
             // get class parts array
             $ext = $this->loaded->item_at($ext);
         }
     }
     // handle arrays
     if (is_array($ext)) {
         $ext_path = implode(self::PATH_DELIM, $ext);
     }
     // loop path stack top down
     foreach ($this->paths->to_array(true) as $basepath) {
         // build up path
         $path = $basepath . '/' . $ext_path . '/' . $file;
         // does file exist at path?
         if (ICE_Files::cache($path)->is_readable()) {
             // found one!
             return $path;
         }
     }
     return false;
 }
예제 #3
0
 /**
  * Inject static code/markup
  *
  * @return string
  */
 public function export()
 {
     // the code that will be returned
     $code = null;
     // handle callbacks
     if ($this->has_callbacks()) {
         // loop em
         foreach ($this->callbacks as $callback) {
             // execute callback with myself as only argument
             call_user_func($callback, $this);
         }
     }
     // have any files?
     if ($this->files_export->count()) {
         // loop through all files
         foreach ($this->files_export as $file) {
             // resolve file path
             if (path_is_absolute($file)) {
                 // its absolute already, which is good
                 $filename = $file;
             } else {
                 // relative path, need to locate it
                 $filename = $this->component()->locate_file($file);
             }
             // only import each file once!
             if (self::$files_imported->contains($filename)) {
                 // already imported that one
                 continue;
             } else {
                 // push it on to imported stack
                 self::$files_imported->push($filename);
             }
             // inject helpful comment ;)
             //$code .= '/*+++ import source: ' . $filename . ' */' . PHP_EOL;
             // make sure file actually exists
             if (ICE_Files::cache($filename)->is_readable()) {
                 // get entire contents of file
                 $code .= $this->get_file_contents($filename) . PHP_EOL;
                 // success
                 //$code .= '/*--- import complete! */' . PHP_EOL . PHP_EOL;
             } else {
                 //$code .= '/*!!! import failed! */' . PHP_EOL . PHP_EOL;
             }
         }
     }
     // handle strings
     if ($this->has_strings()) {
         //$code .= '/*--- importing strings */' . PHP_EOL;
         $code .= implode(PHP_EOL, $this->strings->to_array()) . str_repeat(PHP_EOL, 2);
         //$code .= '/*!!! importing strings complete */' . PHP_EOL;
     }
     // all done
     return $code;
 }
예제 #4
0
 /**
  * Remove the export file
  *
  * @return boolean
  */
 private function remove()
 {
     if (ICE_Files::cache($this->path)->is_writable()) {
         return unlink($this->path);
     }
 }