Exemple #1
0
 /**
  * Loads a custom view into the parent view.
  * @param string $file
  * @param bool $use_cache
  * @param int $cache_lifetime
  * @return string
  */
 private function _addView($file, $use_cache = true, $cache_lifetime = null)
 {
     // Check if the view is cached
     if ($use_cache and $this->_cache_config->cache_enabled) {
         // Set specific cache life time
         if (!empty($cache_lifetime)) {
             $this->_cache_config->cache_lifetime = $cache_lifetime;
         }
         $this->_cache_config->file = $file;
         // Trying to read cache
         $cache = new View_Cache_Read($this->_cache_config);
         if ($cached_view = $cache->getCache()) {
             return $cached_view;
         }
     }
     // Load a custom view into the parent view
     $view = Registry::factory('View_Custom')->load($file);
     //print $file;
     // If a custom view has already been loaded
     if (!$view) {
         // Return the message
         return sprintf(__('[View file %s has already been loaded]'), $file . '.php');
     }
     // Parse a custom view
     $result = $view->parse($file, $this, new View_Helper());
     // If cached enabled, so we need to write a parsed view
     if ($use_cache and $this->_cache_config->cache_enabled) {
         // Set view data
         $this->_cache_config->data = $result;
         // Set view file name
         $this->_cache_config->file = $file;
         $cache = new View_Cache_Write($this->_cache_config);
         // Save cache
         $cache->setCache();
     }
     // Return the parsed result
     return $result;
 }
Exemple #2
0
 /**
  * Parse a view.
  * @param View $view
  * @param View_Helper $helper
  * @return string
  */
 public function parse(View $view, View_Helper $helper)
 {
     // Check if the view is cached
     if ($this->_cache_config->cache_enabled) {
         // Set specific cache life time
         if (!empty($cache_lifetime)) {
             $this->_cache_config->cache_lifetime = $cache_lifetime;
         }
         $this->_cache_config->file = $this->_file;
         // Trying to read cache
         $cache = new View_Cache_Read($this->_cache_config);
         if ($cached_view = $cache->getCache()) {
             return $cached_view;
         }
     }
     // Include the target file
     if (is_file($this->_file)) {
         // Start an output buffer
         ob_start();
         include $this->_file;
         // Return parsed content
         $result = ob_get_clean();
         // If cached enabled, so we need to write a parsed view
         if ($this->_cache_config->cache_enabled) {
             // Set view data
             $this->_cache_config->data = $result;
             // Set view file name
             $this->_cache_config->file = $this->_file;
             $cache = new View_Cache_Write($this->_cache_config);
             // Save cache
             $cache->setCache();
         }
         return $result;
     }
     // Return message that the file does not found.
     return $this->_file;
 }