Пример #1
0
 /**
  * First function called to begin loading template
  * @param string  $template The template file to be loaded
  * @param array   $vars     Array of variables to be used in template
  * @param boolean $ajax     If true then echo the rendered template
  * @throws Exception
  * @return void
  */
 public static function load($template, $vars, $ajax = false)
 {
     //Get the location of the templates folder
     $setup['templates'] = file_get_contents(__DIR__ . '/setup.json');
     $setup['templates'] = json_decode($setup['templates']);
     $setup['templates'] = $setup['templates']->templates;
     $dir = explode('/', __DIR__);
     if ($dir[sizeof($dir) - 1] == "templator" && $dir[sizeof($dir) - 2] == "drroach" && $dir[sizeof($dir) - 3] == "vendor") {
         self::$templateLocation = dirname(dirname(dirname(__DIR__))) . $setup['templates'] . 'templates/' . $template . '.tpl';
     } else {
         self::$templateLocation = dirname(__DIR__) . '/templates/' . $template . '.tpl';
     }
     self::$definedVars = $vars;
     //Check to see if a cached file already exists
     if (Cache::cacheExists($template)) {
         $timedOut = Cache::cacheTimedOut($template);
         if (!$timedOut) {
             Cache::loadCacheFile($template, $vars);
             return;
         }
     }
     self::checkTemplateExists($template);
     $templateHtml = self::getTemplateHtml($template);
     if ($vars === null) {
         $vars = [];
     }
     extract($vars);
     include Generate::parse($templateHtml, $template);
 }
 public function GetOutput()
 {
     $yams = YAMS::GetInstance();
     $errorList = '';
     if (count($this->itsErrorMessages) > 0) {
         $errorList .= '<ul>';
         foreach ($this->itsErrorMessages as $msg) {
             $errorList .= '<li>' . YamsUtils::Escape($msg) . '</li>';
         }
         $errorList .= '</ul>';
     }
     $tpl = new Templator();
     $tpl->LoadTemplateFromFile('yams/module/yams.error.tpl.html');
     $tpl->RegisterPlaceholder('error_list', $errorList);
     return $tpl->Parse();
 }
 public function ParseLanguageText(Templator &$tpl)
 {
     // Parses a template, resolving all language specific placeholders
     // Parses in the current language first, then the default language after
     if (!$tpl->IsTemplateLoaded()) {
         throw new Exception('YamsLangMgr: A template must be loaded in before parsing the language text');
     }
     $parseCurrent = true;
     if ($this->itsDefaultLang == $this->itsCurrentLang) {
         $parseCurrent = false;
     } else {
         $currentLangFile = $this->itsCurrentLang . '.inc.php';
         $currentLangPath = $this->itsLangDir . $currentLangFile;
         if (!is_file($currentLangPath)) {
             if (!is_file($currentLangPath)) {
                 throw new Exception('YamsLangMgr: Could not load current language file: ' . $currentLangPath);
             }
         }
     }
     $defaultLangFile = $this->itsDefaultLang . '.inc.php';
     $defaultLangPath = $this->itsLangDir . $defaultLangFile;
     if (!is_file($defaultLangPath)) {
         throw new Exception('YamsLangMgr: Could not load default language file: ' . $defaultLangPath);
     }
     $removeUnrecognisedPlaceholders = $tpl->IsRemoveUnrecognisedPlaceHolders();
     $tpl->SetRemoveUnrecognisedPlaceHolders(false);
     // Register the placeholders
     if ($parseCurrent) {
         require $currentLangPath;
         $tpl->Parse(NULL, true);
     }
     require $defaultLangPath;
     $tpl->Parse(NULL, true);
     // restore the placeholder removal mode
     $tpl->SetRemoveUnrecognisedPlaceHolders($removeUnrecognisedPlaceholders);
 }
Пример #4
0
<?php

require_once 'Templator.php';
new Templator();
$vars = $_POST['data'];
$template = $_POST['filename'];
Templator::load($template, $vars, true);
 /**
  * 404!
  * @return string
  */
 public function serveNotFound()
 {
     $templator = new Templator();
     return $this->serveCache($templator->notFound());
 }
 public function GetOutput()
 {
     $yams = YAMS::GetInstance();
     $YEM = YamsErrorMgr::GetInstance();
     $YLM = YamsLangMgr::GetInstance();
     // Load the module template
     $tpl = new Templator();
     $success = $tpl->LoadTemplateFromFile('yams/module/yams.module.tpl.html');
     if (!$success) {
         return;
     }
     if (YamsUtils::IsHTTPS()) {
         $protocol = 'https://';
     } else {
         $protocol = 'http://';
     }
     $requestURL = YamsUtils::Escape($protocol . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
     // Define the placholders
     $tpl->RegisterPlaceholder('form_action', '[+request_url+]');
     $tpl->RegisterPlaceholder('error_messages', $YEM->GetOutput());
     $tpl->RegisterPlaceholder('lang_chooser', $YLM->GetOutput());
     // Parse non-language placeholders
     $tpl->Parse(NULL, true);
     $tpl->ClearStoredPlaceholders();
     // Register global placeholders...
     $tpl->RegisterPlaceholder('request_url', $requestURL);
     $tpl->RegisterPlaceholder('modx_manager_theme', $modx->config['manager_theme']);
     $tpl->RegisterPlaceholder('modx_site_url', $modx->config['site_url']);
     $tpl->RegisterPlaceholder('modx_charset', $modx->config['modx_charset']);
     $tpl->RegisterPlaceholder('yams_contact_en_url', 'http://nashi.podzone.org/en/contact.xhtml');
     $tpl->RegisterPlaceholder('yams_contact_fr_url', 'http://nashi.podzone.org/fr/contact.xhtml');
     $tpl->RegisterPlaceholder('yams_contact_ja_url', 'http://nashi.podzone.org/ja/contact.xhtml');
     $tpl->RegisterPlaceholder('yams_donate_en_url', 'http://nashi.podzone.org/en/donate.xhtml');
     $tpl->RegisterPlaceholder('yams_donate_fr_url', 'http://nashi.podzone.org/fr/donate.xhtml');
     $tpl->RegisterPlaceholder('yams_donate_ja_url', 'http://nashi.podzone.org/ja/donate.xhtml');
     $tpl->RegisterPlaceholder('yams_package_url', 'http://modxcms.com/extras/package/?package=543');
     $tpl->RegisterPlaceholder('yams_forums_url', 'http://modxcms.com/forums/index.php/board,381.0.html');
     $tpl->RegisterPlaceholder('yams_author_url', 'http://modxcms.com/forums/index.php?action=profile;u=12570');
     $tpl->RegisterPlaceholder('yams_author', '<a href="[+yams_author_url+]" target="_blank">PMS</a>');
     $tpl->RegisterPlaceholder('yams_copyright', '<a href="http://nashi.podzone.org/" target="_blank">Nashi Power</a> 2009');
     $tpl->RegisterPlaceholder('yams_licence', 'GPL v3');
     $tpl->RegisterPlaceholder('yams_version', YamsUtils::Escape($yams->GetVersion()));
     // Parse language text...
     $YLM->ParseLanguageText($tpl);
     // Temporarily comment out this line so it's easy to find missing placeholders...
     // $tpl->RemovePlaceholdersFromTpl( NULL, true );
     return $tpl->GetTpl();
 }
Пример #7
0
 public function testThatPopulateJsFunctionReturnsTrue()
 {
     $result = Templator::populateJs(['test' => 'This is test data']);
     $this->assertTrue($result);
 }