Exemplo n.º 1
0
 protected static function _check_template($template)
 {
     // set filename
     $template_name = basename($template);
     $template_basedir = strpos($template, "/") ? dirname($template) . '/' : null;
     $template_directory = self::$tpl_dir . $template_basedir;
     $template_filepath = $template_directory . $template_name . '.' . self::$tpl_ext;
     $parsed_template_filepath = self::$cache_dir . $template_name . "." . md5($template_directory . self::$config_check_sum) . '.rtpl.php';
     $class_name = str_replace(array(".", "/"), "_", $parsed_template_filepath);
     // if the template doesn't exsist throw an error
     if (!file_exists($template_filepath)) {
         $e = new RainTpl_NotFoundException('Template ' . $template_name . ' not found!');
         throw $e->setTemplateFile($template_filepath);
     }
     // Compile the template if the original has been updated
     if (self::$debug || !file_exists($parsed_template_filepath) || filemtime($parsed_template_filepath) < filemtime($template_filepath)) {
         // compile template
         $compiler_class = "TplCompile" . ucfirst(strtolower(self::$template_syntax));
         include_once $compiler_class . ".php";
         $compiler_class::configure(get_class_vars(__CLASS__));
         $compiler_class::compileFile($template_name, $template_basedir, $template_filepath, $parsed_template_filepath);
     }
     return $parsed_template_filepath;
 }
Exemplo n.º 2
0
 /**
  * Check if has to compile the template
  *
  * @access protected
  * @param  string $tpl_name template name to check
  * @throws RainTpl_NotFoundException
  * @return bool return true if the template has changed
  */
 protected function check_template($tpl_name)
 {
     if (!isset($this->tpl['checked'])) {
         $tpl_basename = basename($tpl_name);
         // template basename
         $tpl_basedir = strpos($tpl_name, "/") ? dirname($tpl_name) . '/' : null;
         // template basedirectory
         $tpl_dir = PATH . self::$tpl_dir . $tpl_basedir;
         // template directory
         $this->tpl['tpl_filename'] = $tpl_dir . $tpl_basename . '.' . self::$tpl_ext;
         // template filename
         $temp_compiled_filename = PATH . self::$cache_dir . $tpl_basename . "." . md5($tpl_dir . serialize(self::$config_name_sum));
         $this->tpl['compiled_filename'] = $temp_compiled_filename . '.rtpl.php';
         // cache filename
         $this->tpl['cache_filename'] = $temp_compiled_filename . '.s_' . $this->cache_id . '.rtpl.php';
         // static cache filename
         // if the template doesn't exsist throw an error
         if (self::$check_template_update && !file_exists($this->tpl['tpl_filename'])) {
             $e = new RainTpl_NotFoundException('Template ' . $tpl_basename . ' not found!');
             throw $e->setTemplateFile($this->tpl['tpl_filename']);
         }
         // file doesn't exsist, or the template was updated, Rain will compile the template
         if (!file_exists($this->tpl['compiled_filename']) || self::$check_template_update && filemtime($this->tpl['compiled_filename']) < filemtime($this->tpl['tpl_filename'])) {
             $this->compileFile($tpl_basename, $tpl_basedir, $this->tpl['tpl_filename'], PATH . self::$cache_dir, $this->tpl['compiled_filename']);
             return true;
         }
         $this->tpl['checked'] = true;
     }
 }
Exemplo n.º 3
0
 protected function check_template($tpl_name)
 {
     if (!isset($this->tpl['checked'])) {
         $tpl_basename = basename($tpl_name);
         // template basename
         $tpl_basedir = strpos($tpl_name, "/") ? dirname($tpl_name) . '/' : null;
         // template basedirectory
         $this->tpl['template_directory'] = $this->tpl_dir . $tpl_basedir;
         // template directory
         $this->tpl['tpl_filename'] = $this->tpl['template_directory'] . $tpl_basename . '.' . $this->tpl_ext;
         // template filename
         $temp_compiled_filename = $this->cache_dir . $tpl_basename . "." . md5($this->tpl['template_directory'] . serialize($this->config_name_sum));
         $this->tpl['compiled_filename'] = $temp_compiled_filename . '.rtpl.php';
         // cache filename
         $this->tpl['cache_filename'] = $temp_compiled_filename . '.s_' . $this->cache_id . '.rtpl.php';
         // static cache filename
         $this->tpl['checked'] = true;
         // if the template doesn't exist and is not an external source throw an error
         if ($this->check_template_update && !file_exists($this->tpl['tpl_filename']) && !preg_match('/http/', $tpl_name)) {
             $e = new RainTpl_NotFoundException('Template ' . $tpl_basename . ' not found!');
             throw $e->setTemplateFile($this->tpl['tpl_filename']);
         }
         // We check if the template is not an external source
         if (preg_match('/http/', $tpl_name)) {
             $this->compileFile('', '', $tpl_name, $this->cache_dir, $this->tpl['compiled_filename']);
             return true;
         } elseif (!file_exists($this->tpl['compiled_filename']) || $this->check_template_update && filemtime($this->tpl['compiled_filename']) < filemtime($this->tpl['tpl_filename'])) {
             $this->compileFile($tpl_basename, $tpl_basedir, $this->tpl['tpl_filename'], $this->cache_dir, $this->tpl['compiled_filename']);
             return true;
         }
     }
 }
Exemplo n.º 4
0
 protected function check_template($tpl_name)
 {
     if (!isset($this->tpl['checked'])) {
         $tpl_basename = basename($tpl_name);
         $tpl_basedir = strpos($tpl_name, "/") ? dirname($tpl_name) . '/' : null;
         $tpl_dir = self::$tpl_dir . $tpl_basedir;
         $this->tpl['tpl_filename'] = $tpl_dir . $tpl_basename . '.' . self::$tpl_ext;
         $temp_compiled_filename = self::$cache_dir . $tpl_basename . "." . md5($tpl_dir . serialize(self::$config_name_sum));
         $this->tpl['compiled_filename'] = $temp_compiled_filename . '.rtpl.php';
         $this->tpl['cache_filename'] = $temp_compiled_filename . '.s_' . $this->cache_id . '.rtpl.php';
         if (self::$check_template_update && !file_exists($this->tpl['tpl_filename'])) {
             $e = new RainTpl_NotFoundException('Template ' . $tpl_basename . ' not found!');
             throw $e->setTemplateFile($this->tpl['tpl_filename']);
         }
         if (!file_exists($this->tpl['compiled_filename']) || self::$check_template_update && filemtime($this->tpl['compiled_filename']) < filemtime($this->tpl['tpl_filename'])) {
             $this->compileFile($tpl_basename, $tpl_basedir, $this->tpl['tpl_filename'], self::$cache_dir, $this->tpl['compiled_filename']);
             return true;
         }
         $this->tpl['checked'] = true;
     }
 }
Exemplo n.º 5
0
 protected function _check_template($template)
 {
     // set filename
     $template_name = basename($template);
     $template_basedir = strpos($template, "/") ? dirname($template) . '/' : null;
     $template_directory = static::$conf['tpl_dir'] . $template_basedir;
     $template_filepath = $template_directory . $template_name . '.' . static::$conf['tpl_ext'];
     $parsed_template_filepath = static::$conf['cache_dir'] . $template_name . "." . md5($template_directory . implode(static::$conf['checksum'])) . '.rtpl.php';
     // if the template doesn't exsist throw an error
     if (!file_exists($template_filepath)) {
         $e = new RainTpl_NotFoundException('Template ' . $template_name . ' not found!');
         throw $e->setTemplateFile($template_filepath);
     }
     // Compile the template if the original has been updated
     if (static::$conf['debug'] || !file_exists($parsed_template_filepath) || filemtime($parsed_template_filepath) < filemtime($template_filepath)) {
         $this->_compile_file($template_name, $template_basedir, $template_filepath, $parsed_template_filepath);
     }
     return $parsed_template_filepath;
 }
 protected function check_template($tpl_name)
 {
     if (!isset($this->tpl['checked'])) {
         $tpl_basename = basename($tpl_name);
         // template basename
         $tpl_basedir = strpos($tpl_name, "/") ? dirname($tpl_name) . '/' : null;
         // template basedirectory
         $tpl_dir = self::$tpl_dir . $tpl_basedir;
         /// buscamos la plantilla en los plugins activos
         if (isset($GLOBALS['plugins'])) {
             foreach ($GLOBALS['plugins'] as $plugin_dir) {
                 if (file_exists('plugins/' . $plugin_dir . '/view/' . $tpl_name . '.' . self::$tpl_ext)) {
                     $tpl_dir = 'plugins/' . $plugin_dir . '/view/' . $tpl_basedir;
                     break;
                 }
             }
         }
         $this->tpl['tpl_filename'] = $tpl_dir . $tpl_basename . '.' . self::$tpl_ext;
         // template filename
         $temp_compiled_filename = self::$cache_dir . $tpl_basename . "." . md5($tpl_dir . serialize(self::$config_name_sum));
         $this->tpl['compiled_filename'] = $temp_compiled_filename . '.rtpl.php';
         // cache filename
         $this->tpl['cache_filename'] = $temp_compiled_filename . '.s_' . $this->cache_id . '.rtpl.php';
         // static cache filename
         // if the template doesn't exsist throw an error
         if (self::$check_template_update && !file_exists($this->tpl['tpl_filename'])) {
             $e = new RainTpl_NotFoundException('No se encuentra el archivo ' . $this->tpl['tpl_filename']);
             throw $e->setTemplateFile($this->tpl['tpl_filename']);
         }
         // file doesn't exsist, or the template was updated, Rain will compile the template
         if (!file_exists($this->tpl['compiled_filename']) || self::$check_template_update && filemtime($this->tpl['compiled_filename']) < filemtime($this->tpl['tpl_filename'])) {
             $this->compileFile($tpl_basename, $tpl_basedir, $this->tpl['tpl_filename'], self::$cache_dir, $this->tpl['compiled_filename']);
             return true;
         }
         $this->tpl['checked'] = true;
     }
 }