Example #1
0
 /**
  * Generate content from template compilation
  *
  * @param string $template
  * @param array $vars
  * @param array $blocks
  * @return string
  */
 public function render($template, array $vars = [], array $blocks = [])
 {
     $directory = rtrim($this->directory, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
     $file = $directory . trim($template, DIRECTORY_SEPARATOR) . $this->suffix;
     $vars += $this->vars;
     $sandbox = new Template($this, $file, $blocks, $this->helpers);
     return $sandbox->compile($vars);
 }
Example #2
0
 static function GetInstance($arrayconfig = array())
 {
     if (self::$instance == null) {
         self::$instance = new Template();
     }
     self::$compile = new Compile();
     self::$config = $arrayconfig + self::$config;
     return self::$instance;
 }
 /**
  * Compile the template
  *
  * @internal
  */
 protected function compile()
 {
     // User agent class (see #3074 and #6277)
     $this->ua = \Environment::get('agent')->class;
     // Style sheets
     if (!empty($GLOBALS['TL_CSS']) && is_array($GLOBALS['TL_CSS'])) {
         $strStyleSheets = '';
         foreach (array_unique($GLOBALS['TL_CSS']) as $stylesheet) {
             $options = \StringUtil::resolveFlaggedUrl($stylesheet);
             $strStyleSheets .= \Template::generateStyleTag($this->addStaticUrlTo($stylesheet), $options->media);
         }
         $this->stylesheets = $strStyleSheets;
     }
     // JavaScripts
     if (!empty($GLOBALS['TL_JAVASCRIPT']) && is_array($GLOBALS['TL_JAVASCRIPT'])) {
         $strJavaScripts = '';
         foreach (array_unique($GLOBALS['TL_JAVASCRIPT']) as $javascript) {
             $options = \StringUtil::resolveFlaggedUrl($javascript);
             $strJavaScripts .= \Template::generateScriptTag($this->addStaticUrlTo($javascript), $options->async) . "\n";
         }
         $this->javascripts = $strJavaScripts;
     }
     // MooTools scripts (added at the page bottom)
     if (!empty($GLOBALS['TL_MOOTOOLS']) && is_array($GLOBALS['TL_MOOTOOLS'])) {
         $strMootools = '';
         foreach (array_unique($GLOBALS['TL_MOOTOOLS']) as $script) {
             $strMootools .= "\n" . trim($script) . "\n";
         }
         $this->mootools = $strMootools;
     }
     $strBuffer = $this->parse();
     $strBuffer = static::replaceOldBePaths($strBuffer);
     // HOOK: add custom output filter
     if (isset($GLOBALS['TL_HOOKS']['outputBackendTemplate']) && is_array($GLOBALS['TL_HOOKS']['outputBackendTemplate'])) {
         foreach ($GLOBALS['TL_HOOKS']['outputBackendTemplate'] as $callback) {
             $this->import($callback[0]);
             $strBuffer = $this->{$callback}[0]->{$callback}[1]($strBuffer, $this->strTemplate);
         }
     }
     $this->strBuffer = $strBuffer;
     parent::compile();
 }
Example #4
0
 public static function error($code, $number = null, $string = null, $file = null, $line = null)
 {
     $error = new Template();
     $error->setContent(file_get_contents(__DIR__ . "/../../error/error.html"));
     if (Aegis::$debugging) {
         $error->data["description"] = "<p><b>OS:</b> " . PHP_OS . "</p>";
         $error->data["description"] .= "<p><b>PHP Version:</b> " . PHP_VERSION . "</p>";
         $error->data["description"] .= "<p><b>Aegis Version:</b> " . Aegis::$version . "</p>";
         if ($number != null) {
             $error->data["description"] = "<p><b>Error Code:</b> {$number}</p>";
             $error->data["description"] .= "<p><b>Message:</b> {$string}</p>";
             $error->data["description"] .= "<p><b>File:</b> {$file}</p>";
             $error->data["description"] .= "<p><b>Line:</b> {$line}</p>";
         }
     }
     switch ($code) {
         case 404:
             header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found", true, 404);
             $error->data["title"] = "Page Not Found";
             $error->data["message"] = "Sorry, the page you are trying to access does not exist.";
             break;
         case 500:
             header($_SERVER["SERVER_PROTOCOL"] . " 500 Internal Server Error", true, 500);
             $error->data["title"] = "Server Error";
             $error->data["message"] = "Sorry, it seems there's been an error. Please try later.";
             break;
     }
     if (Aegis::$debugging) {
         $error->data["description"] = "<div>" . $error->data["description"] . "</div>";
     } else {
         $error->data["description"] = "";
     }
     $error->compile();
     echo $error;
     die;
 }
Example #5
0
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage is not a valid tag
  */
 public function testThrowExceptionIfRequiredTagExistInTemplateButNotInTagsList()
 {
     $configurations = ['app' => ['templates-dir' => '/app/templates', 'temporary-dir' => 'app/temp'], 'apache' => ['host' => 'apache', 'ip' => '192.168.4.2', 'server-name' => 'marvin.dev', 'server-alias' => 'www.marvin.dev marvin.local.dev marvin.develop.host', 'document-root' => '/home/marvin/site/public', 'file-name' => 'marvin.dev.conf'], 'defaults' => ['port' => '8080']];
     $configRepository = $this->getMockBuilder('Marvin\\Config\\Repository')->setMethods(['get'])->getMock();
     $configRepository->expects($this->any())->method('get')->with($this->equalTo('app.templates-dir'))->will($this->returnValue($configurations['app']['templates-dir']));
     // VHostManager setups
     $vhManager = $this->getMockBuilder('Marvin\\Contracts\\HostManager')->setMethods([])->getMock();
     $vhManager->expects($this->any())->method('get')->will($this->returnCallback(function ($key) use($configurations) {
         if (key_exists($key, $configurations['apache'])) {
             return $configurations['apache'][$key];
         }
         if (key_exists($key, $configurations['defaults'])) {
             return $configurations['defaults'][$key];
         }
         return $configurations;
     }));
     // Filesystem\Template setups
     $templateApacheFile = $configurations['app']['templates-dir'] . DIRECTORY_SEPARATOR . 'apache.stub';
     $templateContent = 'They are a simple {{tag}} and a {{fake-tag}}';
     $filesystem = $this->getMockBuilder('Marvin\\Filesystem\\Filesystem')->setMethods(['get', 'files'])->getMock();
     $filesystem->expects($this->once())->method('files')->with($this->equalTo($configurations['app']['templates-dir']))->will($this->returnValue([$templateApacheFile, 'ngnix.stub']));
     $filesystem->expects($this->once())->method('get')->with($this->equalTo($templateApacheFile))->will($this->returnValue($templateContent));
     $template = new Template($configRepository, $filesystem);
     $this->assertTrue($template->compile($vhManager));
 }
Example #6
0
function mysql_errors($description)
{
    $tpl = new Template();
    $tpl->dir = ROOT_DIR . "/templates/";
    $tpl->load_template('mysql.tpl');
    $tpl->set('{THEME}', $templates);
    $tpl->set('{description}', charset_x_win($description));
    $tpl->compile('mysql_errors');
    eval(' ?' . '>' . $tpl->result['mysql_errors'] . '<' . '?php ');
    $tpl->global_clear();
}
Example #7
0
 private function build_footer()
 {
     $footer = new Template('_partials/footer', false, false);
     $footer->setTemplateVars(array('VERSION_NUMBER' => VERSION, 'YEAR' => date('Y')));
     $this->footer .= $footer->compile();
 }