Ejemplo n.º 1
0
 public static function getByCodeFormatLanguage($code, $format, $language)
 {
     $sqlParams = array('code' => $code, 'format' => $format, 'language' => $language);
     $query = TextProcessor::doText(file_get_contents(__DIR__ . "/sql/GetMailSignature.sql"), $sqlParams);
     $result = Database::getInstance()->getRow($query);
     return is_array($result) && isset($result['content']) ? $result['content'] : '';
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
0
 public function loopt($moduleName, $templateName, $rows = array())
 {
     return TextProcessor::loopTemplate($moduleName, $templateName, $rows);
 }
Ejemplo n.º 5
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);
Ejemplo n.º 6
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;
Ejemplo n.º 7
0
 /**
  * Increases view counter for the model if it has needed fields
  *
  * @return int|resource
  */
 public function countVisit()
 {
     $result = 0;
     if ($this->has('cnt_viewed') && $this->has('last_viewed')) {
         $sqlParams = array('objectType' => $this->tableName, 'objectId' => $this->getID());
         $query = TextProcessor::doText(file_get_contents(__DIR__ . "/Templates/IncreaseViewCounter.sql"), $sqlParams);
         $result = mysql_query($query);
     }
     return $result;
 }
Ejemplo n.º 8
0
 /**
  * Returns result of DELETE query stored in the template
  *
  * @param $moduleName
  * @param $templateName
  * @param array $params
  *
  * @return int
  */
 public function delete($moduleName, $templateName, $params = array())
 {
     $query = TextProcessor::doSqlTemplate($moduleName, $templateName, $params);
     return $this->runQuery($query);
 }
Ejemplo n.º 9
0
 /**
  * Returns ID of identity field affected by INSERT query stored in the template
  *
  * @param $moduleName
  * @param $templateName
  * @param array $params
  *
  * @return int
  */
 public function getNewID($moduleName, $templateName, $params = array())
 {
     $query = TextProcessor::doSqlTemplate($moduleName, $templateName, $params);
     $result = $this->runQuery($query);
     return $result['result'] == 'OK' ? $this->db->insert_id : -1;
 }
Ejemplo n.º 10
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;
 }