Example #1
0
 public static function dynamic404($params = array())
 {
     header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
     $params['bodyId'] = 'p404';
     $params['bodyClasses'] = 'error-page';
     print TextProcessor::doTemplate('main', 'http.404', $params);
     die;
 }
Example #2
0
 /**
  * Renders master template using block values as set by the time of calling
  *
  * @param Page $page
  *
  * @return string
  * @throws \Exception
  */
 public function render($page)
 {
     // get initial set of blocks from the page
     $blocks = $page->getBlocks();
     //region Normalize styles and scripts, accumulated in meta, styles, scripts, cssFiles and jsFiles
     $templateContent = $this->getTemplate('index.meta');
     foreach ($page->getMeta() as $key => $value) {
         $blocks['meta'] .= TextProcessor::doText($templateContent, array('key' => $key, 'value' => $value));
     }
     $templateContent = $this->getTemplate('index.og');
     foreach ($page->getOg() as $property => $content) {
         $blocks['og'] .= TextProcessor::doText($templateContent, array('property' => $property, 'content' => $content));
     }
     $templateContent = $this->getTemplate('index.cssFile');
     foreach ($page->getCcsFiles() as $cssFileName) {
         $blocks['cssFiles'] .= TextProcessor::doText($templateContent, array('filename' => $cssFileName));
     }
     $styles = $page->getStyles();
     if (count($styles) > 0) {
         $blocks['styles'] = join(PHP_EOL, $styles);
     }
     $templateContent = $this->getTemplate('framework', 'index.jsFile');
     foreach ($page->getHeadJsFiles() as $jsFileName) {
         $blocks['headJsFiles'] .= TextProcessor::doText($templateContent, array('filename' => $jsFileName));
     }
     foreach ($page->getBodyJsFiles() as $jsFileName) {
         $blocks['bodyJsFiles'] .= TextProcessor::doText($templateContent, array('filename' => $jsFileName));
     }
     $headScripts = $page->getHeadScripts();
     if (count($headScripts) > 0) {
         $blocks['headScripts'] = join(PHP_EOL, $headScripts);
     }
     $bodyScripts = $page->getBodyScripts();
     if (count($bodyScripts) > 0) {
         $blocks['bodyScripts'] = join(PHP_EOL, $bodyScripts);
     }
     //endregion
     // Parse the location of master template
     list($moduleName, $templateName) = explode(':', $page->getMasterTemplate(), 2);
     // Return parsed value
     return TextProcessor::doTemplate($moduleName, $templateName, $blocks);
 }
Example #3
0
 public function dot($moduleName, $templateName, $params = array())
 {
     return TextProcessor::doTemplate($moduleName, $templateName, $params);
 }
Example #4
0
<?php

use Kasha\Core\Runtime;
use Kasha\Core\Validator;
use Kasha\Temple\Util;
use Kasha\Templar\TextProcessor;
$url = Util::lavnn('_nextUrl', $_REQUEST, '');
$validator = new Validator($_REQUEST);
$validator->removeFields(['f', 'PHPSESSID', 'SQLiteManager_currentLangue', '_nextUrl']);
//$validator->checkMetadata($model->getMetadata(), ['id']);
$request = $validator->getFields();
$errors = $validator->getErrors();
if (count($errors) > 0) {
    $_SESSION['form']['data'] = $request;
    $_SESSION['form']['errors'] = $errors;
} else {
    //	$updateId = $model->load($id)->update($request);
    if ($updateId == $id) {
        $_SESSION['flash'] = TextProcessor::doTemplate('%MODULE%', 'flash.%NAME%.success');
    } else {
        $_SESSION['error'] = TextProcessor::doTemplate('%MODULE%', 'error.%NAME%.failure');
    }
}
Runtime::redirect($url);
Example #5
0
<?php

require_once "vendor/autoload.php";
use Kasha\Templar\TextProcessor;
use Kasha\Templar\Locator;
// this should be handled while framework bootstraps
$folders = array('app' => __DIR__ . '/app/', 'shared' => __DIR__ . '/shared/');
Locator::getInstance()->setFolders($folders);
Locator::getInstance()->setLanguage('en');
$params = array('name' => array('first' => 'John', 'last' => 'Doe'));
// to run the test, create a file app/modules/main/templates/index.html
//  and use {{name.first}} and {{name.last|uppercase}} placeholders in its HTML
print TextProcessor::doTemplate('main', 'index', $params) . PHP_EOL;
Example #6
0
 /**
  * Prepares mail signature
  *
  * @param string $signatureCode
  * @param bool $html
  * @param string $language
  * @param int $sender
  *
  * @return string
  */
 public static function prepareMailSignature($signatureCode = 'team', $html = false, $language = 'en', $sender = 0)
 {
     $output = '';
     $cachedSignatureCode = $signatureCode . ($signatureCode != 'team' && $sender > 0 ? $sender : '') . ($html ? '.html' : '.txt');
     $format = $html ? 'html' : 'text';
     if (isset(self::$cache['signature'][$cachedSignatureCode])) {
         $output = self::$cache['signature'][$cachedSignatureCode];
     } else {
         // try to get template for $signatureCode from the database
         $output = MailMessageSignature::getByCodeFormatLanguage($signatureCode, $format, $language);
         // If not found, try to locate default signature template in the database
         if ($output == '' && $signatureCode != 'team') {
             $output = self::prepareMailSignature('team', $html, $language, $sender);
         } elseif ($output == '' && $signatureCode == 'team') {
             // If signature is still not found, use static templates.
             $templateName = 'mail.' . ($html ? 'html' : 'text') . '.signature';
             $output = TextProcessor::doTemplate('cron', $templateName);
         }
         // if non-empty template is found for user/user-empty signature, process text with sender data
         if ($output != '' && in_array($signatureCode, ['user', 'user-empty']) && $sender > 0) {
             $userModel = new User();
             if ($userModel->load($sender)->isValid()) {
                 $output = TextProcessor::doText($output, $userModel->getData());
             }
         }
         // save rendered signature to inner cache to reuse on the same HTTP request
         self::$cache['signature'][$cachedSignatureCode] = $output;
     }
     return $output;
 }