Пример #1
0
 /**
  */
 public function tearDown()
 {
     if (!$this->useTemplate) {
         return;
     }
     if ($this->template->filename === null) {
         $tplPath = sprintf(MODULE_TEMPLATES, $this->divPath);
         $tplName = $tplPath . $this->_method . '.php';
         if (file_exists($tplName)) {
             $this->template->load($tplName);
         }
     }
     if (!$this->useBackbone) {
         if ($this->template->filename === null) {
             throw new \Exception('template not loaded.');
         }
         $this->_response = $this->template->compile();
         return;
     }
     $this->setUpLayout();
     $this->_response = Layout::compile($this->template->filename !== null ? $this->template->compile() : (DEBUG ? 'DEBUG Info: template not autoloaded.<br/> no such file: ' . str_replace(ROOT, '', $tplName) : ''));
 }
Пример #2
0
 /**
  * @param $content
  *
  * @return string
  * @throws \Exception
  */
 public static function compile($content)
 {
     $layoutTplVars = [];
     $layoutTplVars['content'] = $content;
     //TODO: special chars
     $layoutTplVars['keywords'] = !empty(static::$keywords) ? "<meta name='keywords' content='" . static::$keywords . "' />\n" : '';
     $layoutTplVars['title'] = !empty(static::$title) ? "<title>" . htmlspecialchars(static::$title) . "</title>\n" : '';
     //TODO: special chars
     $layoutTplVars['description'] = !empty(static::$description) ? "<meta name='description' content='" . static::$description . "' />\n" : '';
     $layoutTplVars['javascript'] = '';
     $layoutTplVars['css'] = '';
     $cssCnt = count(static::$css);
     if ($cssCnt > 0) {
         for ($i = 0; $i < $cssCnt; $i++) {
             $layoutTplVars['css'] .= '<link   type="text/css" rel="stylesheet" href="' . static::$css[$i] . '"/>' . "\n";
         }
     }
     $jsCnt = count(static::$js);
     if ($jsCnt > 0) {
         for ($i = 0; $i < $jsCnt; $i++) {
             $layoutTplVars['javascript'] .= '<script type="text/javascript" src="' . static::$js[$i] . '"></script>' . "\n";
         }
     }
     // make js init code for all js managers
     $jsMgrsCnt = count(static::$jsMgr);
     if ($jsMgrsCnt > 0) {
         $jsMgrsText = '';
         for ($i = 0; $i < $jsMgrsCnt; $i++) {
             $jsMgrsText .= "\tnew " . static::$jsMgr[$i] . "_mgr();\n";
         }
         static::addJsTextOnReady($jsMgrsText);
     }
     if (static::$jsTextOnReady != '') {
         static::addJsText("\$(document).ready(function(){\n" . static::$jsTextOnReady . '});');
     }
     $jsTextCnt = count(static::$jsText);
     if ($jsTextCnt > 0) {
         for ($i = 0; $i < $jsTextCnt; $i++) {
             $layoutTplVars['javascript'] .= "<script type=\"text/javascript\">\n" . static::$jsText[$i] . "\n</script>\n";
         }
     }
     if (static::$filename === null) {
         throw new \Exception('Layout template file name does not set: use Layout::setFilename().');
     }
     $tpl = new PhpTemplate(TEMPLATES . static::$filename);
     $tpl->vars = $layoutTplVars;
     //login error information - to be shown only once
     // @todo bring out
     if (isset($_SESSION['login_error'])) {
         $tpl->vars['login_error'] = $_SESSION['login_error'];
         unset($_SESSION['login_error']);
     }
     $compiledHtml = $tpl->compile();
     foreach ($layoutTplVars as $key => $value) {
         $compiledHtml = str_replace('{' . $key . '}', $value, $compiledHtml);
     }
     return $compiledHtml;
 }