Example #1
0
 public function display()
 {
     $template = SPLoader::loadTemplate($this->_tpl, 'php');
     if ($template) {
         include $template;
     } else {
         throw new SPException(SPLang::e('CANNOT_LOAD_TEMPLATE_FILE_AT', SPLoader::loadTemplate($this->_tpl, 'php', false)));
     }
 }
Example #2
0
 /**
  * @param string $out - output type
  * @param array $functions - array with PHP function to register
  * @throws SPException
  * @return mixed|string
  */
 public function display($out = 'html', $functions = array())
 {
     $class = SPLoader::loadClass('helpers.template');
     $methods = get_class_methods($class);
     if (count($methods)) {
         foreach ($methods as $method) {
             $functions[] = $class . '::' . $method;
         }
     }
     /* standard function registered via the core ini file */
     $stdFunctions = SPLoader::loadIniFile('etc.template_functions');
     if (count($stdFunctions)) {
         foreach ($stdFunctions as $class => $fns) {
             if (strstr($class, '.')) {
                 $class = SPLoader::loadClass($class, false, 'sp-root');
             }
             if (count($fns)) {
                 foreach ($fns as $method => $state) {
                     if ($state) {
                         $functions[] = $class == 'functions' ? $method : $class . '::' . $method;
                     }
                 }
             }
         }
     }
     Sobi::Trigger('TemplateEngine', 'RegisterFunctions', array(&$functions));
     $this->createXML();
     if (SPRequest::cmd('xml') && Sobi::Cfg('debug.xml_raw', false) && (!Sobi::Cfg('debug.xml_ip', null) || Sobi::Cfg('debug.xml_ip') == SPRequest::ip('REMOTE_ADDR', 0, 'SERVER'))) {
         SPFactory::mainframe()->cleanBuffer();
         echo $this->_xml->saveXML();
         exit;
     } elseif (SPRequest::cmd('xml')) {
         Sobi::Error('Debug', 'You have no permission to access this site', SPC::ERROR, 403, __LINE__, __FILE__);
     }
     $template = SPLoader::loadTemplate($this->_tpl, 'xsl');
     if (!$template) {
         $template = SPLoader::loadTemplate($this->_tpl, 'xslt');
     }
     if (Sobi::Cfg('cache.xml_enabled')) {
         SPFactory::cache()->addView($this->_xml, $template, $this->_cacheData);
     }
     if ($template) {
         try {
             if (!($style = DOMDocument::load($template))) {
                 Sobi::Error('template', SPLang::e('CANNOT_PARSE_TEMPLATE_FILE', $template), SPC::ERROR, 500, __LINE__, __FILE__);
             }
         } catch (DOMException $x) {
             Sobi::Error('template', SPLang::e('CANNOT_LOAD_TEMPLATE_FILE', $template, $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
         Sobi::Trigger('TemplateEngine', 'LoadStyle', array(&$style));
         $processor = new XSLTProcessor();
         $processor->setParameter('block', 'xmlns', 'http://www.w3.org/1999/xhtml');
         $processor->registerPHPFunctions($functions);
         SPException::catchErrors(SPC::WARNING);
         try {
             $processor->importStylesheet($style);
         } catch (SPException $x) {
             Sobi::Error('template', SPLang::e('CANNOT_PARSE_TEMPLATE_FILE', $template) . $x->getMessage(), SPC::ERROR, 500, __LINE__, __FILE__);
         }
         SPException::catchErrors(0);
         if ($out == 'html') {
             $doc = $processor->transformToDoc($this->_xml);
             $doc->formatOutput = true;
             return $this->cleanOut($doc->saveXML());
         } else {
             $doc = $processor->transformToDoc($this->_xml);
             $doc->formatOutput = true;
             return $doc->saveXML();
         }
     } else {
         throw new SPException(SPLang::e('CANNOT_LOAD_TEMPLATE_FILE_AT', SPLoader::loadTemplate($this->_tpl, 'xsl', false)));
     }
 }