예제 #1
0
 /**
  */
 public function load_field_options()
 {
     // file extension is required
     if (strlen($this->file_extension)) {
         // check file directory
         if ($this->file_directory) {
             // locate it
             $path = ICE_Scheme::instance()->locate_file($this->file_directory);
             // find it?
             if ($path) {
                 // found the path, list files with extension
                 $images = ICE_Files::list_filtered($path, sprintf('/\\.%s$/', $this->file_extension), true);
                 // find any images?
                 if (count($images)) {
                     // options to return
                     $field_options = array();
                     // format the array
                     foreach ($images as $key => $value) {
                         // clean up key
                         $key = str_replace('.', '-', $key);
                         // value is absolute URL
                         $field_options[$key] = ICE_Files::theme_file_to_url($value);
                     }
                     // all done, return them
                     return $field_options;
                 } else {
                     throw new Exception(sprintf('No images found with the ".%s" extension', $this->file_extension));
                 }
             } else {
                 throw new Exception(sprintf('Unable to locate the "%s" path', $this->file_directory));
             }
         } else {
             throw new Exception('No file directory has been set');
         }
     } else {
         throw new Exception('No file extension has been set');
     }
 }
예제 #2
0
 /**
  * Return file cache instance
  *
  * @return ICE_File_Cache
  */
 private static function file_cache()
 {
     if (!self::$fcache instanceof ICE_File_Cache) {
         self::$fcache = new ICE_File_Cache();
     }
     return self::$fcache;
 }
예제 #3
0
 /**
  * Return the file path for a given page
  *
  * @param string $page
  * @return string
  */
 private function find_page_file($page)
 {
     // valid formats
     $formats = join('|', array(self::MARKUP_HTML, self::MARKUP_MARKDOWN, self::MARKUP_MARKDOWN_LONG, self::MARKUP_TEXTILE, self::MARKUP_TEXTILE_LONG));
     // loop through all doc dirs looking for doc page
     foreach ($this->doc_dirs as $doc_dir) {
         try {
             // list all files in current dir that match page
             $files = ICE_Files::list_filtered($doc_dir, sprintf('/^%s\\.(%s)$/', $page, $formats), true);
         } catch (ICE_Files_Exception $e) {
             // ignore file errors
             continue;
         }
         // get any files?
         if (count($files)) {
             // return the first one
             return array_shift($files);
         }
     }
     // no doc page found
     throw new Exception(sprintf('A file for the doc page "%s" does not exist in any of the configured directories', $page));
 }
예제 #4
0
 /**
  * Determine path to enqueue
  *
  * @param string $theme
  * @param string $path
  * @return string
  */
 private function enqueue_path($theme, $path)
 {
     if (preg_match('/^https?:\\/\\//i', $path)) {
         return $path;
     } else {
         return ICE_Files::theme_file_url($theme, $path);
     }
 }
예제 #5
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;
 }
예제 #6
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;
 }
예제 #7
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;
 }
예제 #8
0
/**
 * Return URL to first script matching path in the scheme stack
 *
 * @package Infinity-api
 * @param string $path Script file path RELATIVE to your script_root setting
 */
function infinity_script_url($path)
{
    // locate script in scheme stack
    $script_path = infinity_script_path($path);
    // convert path to url
    return $script_path ? ICE_Files::theme_file_to_url($script_path) : null;
}
예제 #9
0
 /**
  * Remove the export file
  *
  * @return boolean
  */
 private function remove()
 {
     if (ICE_Files::cache($this->path)->is_writable()) {
         return unlink($this->path);
     }
 }
예제 #10
0
 /**
  * @internal
  * @param array $matches
  * @return string
  */
 protected function fix_url_path($matches)
 {
     // path is index 2
     $path = $matches[1];
     // fix if applicable
     switch (true) {
         // absolute path to doc root, leave alone
         case $path[0] == '/':
             break;
             // absolute URL, leave alone
         // absolute URL, leave alone
         case preg_match('/^https?:\\/\\//', $path):
             break;
             // anything else needs to be resolved
         // anything else needs to be resolved
         default:
             $path = ICE_Files::path_resolve($this->last_dirname, $path);
             $path = ICE_Files::file_to_uri_path($path);
     }
     // return fixed url value
     return sprintf("url('%s')", $path);
 }
예제 #11
0
 /**
  */
 public function get_image_url()
 {
     // get value
     $value = $this->get();
     // has a value?
     if ($value) {
         // yep, locate path
         $path = ICE_Scheme::instance()->locate_file($this->file_directory);
         // find that dir path?
         if ($path) {
             // yep, return as url
             return ICE_Files::theme_file_to_url($path . '/' . $value);
         }
     }
     // value not set
     return null;
 }
예제 #12
0
 /**
  * Return URL to an ext file
  *
  * @param string $filename
  * @return string|false
  */
 public final function locate_file_url($filename)
 {
     // locate the file path
     $path = $this->locate_file($filename);
     // was a path found?
     if ($path) {
         // yes, use files util to get URL
         return ICE_Files::theme_file_to_url($path);
     }
     // no file found
     return false;
 }
예제 #13
0
 /**
  */
 public function get_image_url($size = 'thumbnail')
 {
     // get the value
     $value = $this->get();
     // did we get a number?
     if (is_numeric($value) && $value >= 1) {
         // get the details
         $src = $this->get_image_src($size, $value);
         // try to return a url
         return $src ? $src[0] : false;
     } elseif (is_string($value) && strlen($value) >= 1) {
         // use default
         $directive = $this->directive()->get('default_value');
         // they must have provided an image path
         return ICE_Files::theme_file_url($directive->get_theme(), $directive->get_value());
     }
     return null;
 }
예제 #14
0
/**
 * Return path to a dashboard image
 *
 * @package Infinity
 * @subpackage dashboard
 * @param string $name image file name
 * @return string
 */
function infinity_dashboard_image($name)
{
    $path = infinity_locate_file(INFINITY_ADMIN_DIR . '/assets/images/' . $name);
    if ($path) {
        return ICE_Files::theme_file_to_url($path);
    } else {
        return '';
    }
}