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
 /**
  * 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.º 3
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.º 4
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;
 }