Ejemplo n.º 1
0
 /**
  * Get a concrete filename for automagically created content.
  *
  * Generates a filename path like: Theme / auto_id [/ source_dir / filename-l{lang}.ext]
  * the final part gets generated only if $auto_source is specified.
  *
  * @param string $path        The base path.
  * @param string $auto_source The file name (optional).
  * @param string $auto_id     The ID (optional).
  *
  * @return string The concrete path and file name to the content.
  */
 public function _get_auto_filename($path, $auto_source = null, $auto_id = null, $themedir = null)
 {
     // enables a flags to detect when is treating compiled templates
     $tocompile = $path == $this->compile_dir ? true : false;
     // format auto_source for os to make sure that id does not contain 'ugly' characters
     $auto_source = DataUtil::formatForOS($auto_source);
     // add the Theme name as first folder
     if (empty($themedir)) {
         $path .= '/' . $this->directory;
     } else {
         $path .= '/' . $themedir;
     }
     // the last folder is the cache_id if set
     $path .= !empty($auto_id) ? '/' . $auto_id : '';
     // takes in account the source subdirectory
     $path .= strpos($auto_source, '/') !== false ? '/' . dirname($auto_source) : '';
     // make sure the path exists to write the compiled/cached template there
     if (!file_exists($path)) {
         mkdir($path, $this->serviceManager['system.chmod_dir'], true);
     }
     // if there's a explicit source, it
     if ($auto_source) {
         $path .= '/';
         $extension = FileUtil::getExtension($auto_source);
         // isolates the filename on the source path passed
         $path .= FileUtil::getFilebase($auto_source);
         // if we are compiling we do not include cache variables
         if (!$tocompile) {
             // add the variable stuff only if $auto_source is present
             // to allow a easy flush cache for all the languages (if needed)
             $path .= '-l';
             if (System::getVar('multilingual') == 1) {
                 $path .= $this->language;
             }
             // end with a suffix convention of filename--Themename-lang.ext
             $path .= $extension ? ".{$extension}" : '';
         }
     }
     return $path;
 }
Ejemplo n.º 2
0
 /**
  * Internal function to delete cache of templates.
  *
  * @param string  $tplpath  Relative template path.
  * @param string  $template Template partial filename.
  * @param integer $expire   Expire limit of the cached templates.
  *
  * @return boolean True on success, false otherwise
  */
 protected function rmtpl($tplpath, $template, $expire = null)
 {
     if (!$template || !is_dir($tplpath) || !is_readable($tplpath)) {
         return false;
     }
     $filebase = FileUtil::getFilebase($template);
     $dh = opendir($tplpath);
     while (($entry = readdir($dh)) !== false) {
         if ($entry != '.' && $entry != '..') {
             $path = $tplpath . DIRECTORY_SEPARATOR . $entry;
             if (is_dir($path)) {
                 // search recusively
                 $this->rmtpl($path, $template, $expire);
             } elseif (strpos($entry, $filebase) === 0) {
                 // delete the files that matches the template base filename
                 $this->_unlink($path, $expire);
             }
         }
     }
     closedir($dh);
     return true;
 }