Ejemplo n.º 1
0
 /**
  * Load a template file -- first look in the templates folder for an override
  *
  * @param   string  $tpl	The name of the template source file ...
  * 					automatically searches the template paths and compiles as needed.
  * @param   array   $hmvcParams	Extra parameters for HMVC.
  * @return  string   The output of the the template script.
  */
 public function loadTemplateFile($tpl = null, $hmvcParams = null)
 {
     KUNENA_PROFILER ? $this->profiler->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
     // HMVC legacy support.
     $view = $this->getName();
     $layout = $this->getLayout();
     list($name, $override) = $this->ktemplate->mapLegacyView("{$view}/{$layout}_{$tpl}");
     $hmvc = KunenaLayout::factory($name)->setLayout($override);
     if ($hmvc->getPath()) {
         if ($hmvcParams) {
             $hmvc->setProperties($hmvcParams);
         }
         KUNENA_PROFILER ? $this->profiler->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
         return $hmvc->setLegacy($this);
     }
     // Create the template file name based on the layout
     $file = isset($tpl) ? $layout . '_' . $tpl : $layout;
     if (!isset($this->templatefiles[$file])) {
         // Clean the file name
         $file = preg_replace('/[^A-Z0-9_\\.-]/i', '', $file);
         $tpl = isset($tpl) ? preg_replace('/[^A-Z0-9_\\.-]/i', '', $tpl) : $tpl;
         // Load the template script
         $filetofind = $this->_createFileName('template', array('name' => $file));
         $this->templatefiles[$file] = KunenaPath::find($this->_path['template'], $filetofind);
     }
     $this->_template = $this->templatefiles[$file];
     if ($this->_template != false) {
         $templatefile = preg_replace('%' . KunenaPath::clean(JPATH_ROOT, '/') . '/%', '', KunenaPath::clean($this->_template, '/'));
         // Unset so as not to introduce into template scope
         unset($tpl);
         unset($file);
         // Never allow a 'this' property
         if (isset($this->this)) {
             unset($this->this);
         }
         // Start capturing output into a buffer
         ob_start();
         // Include the requested template filename in the local scope
         // (this will execute the view logic).
         include $this->_template;
         // Done with the requested template; get the buffer and
         // clear it.
         $output = ob_get_contents();
         ob_end_clean();
         if (JDEBUG || $this->config->get('debug')) {
             $output = trim($output);
             $output = "\n<!-- START {$templatefile} -->\n{$output}\n<!-- END {$templatefile} -->\n";
         }
     } else {
         $output = JError::raiseError(500, JText::sprintf('JLIB_APPLICATION_ERROR_LAYOUTFILE_NOT_FOUND', $this->getName() . '/' . $file));
     }
     KUNENA_PROFILER ? $this->profiler->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
     return $output;
 }
Ejemplo n.º 2
0
 /**
  * Method to get the layout path. If layout file isn't found, fall back to default layout.
  *
  * @param   string  $layout  The layout name, defaulting to the current one.
  *
  * @return  mixed  The layout file name if found, false otherwise.
  */
 public function getPath($layout = null)
 {
     if (!$layout) {
         $layout = $this->getLayout();
     }
     $paths = array();
     foreach ($this->includePaths as $path) {
         $paths[] = $path;
     }
     // Find the layout file path.
     $path = KunenaPath::find($paths, "{$layout}.php");
     if (!$path) {
         $path = KunenaPath::find($paths, 'default.php');
     }
     return $path;
 }