/**
  * Assigns values to the template
  *
  */
 protected function setupTemplate()
 {
     global $cfg;
     //Get the required utilities
     $sess = Session::getInstance();
     //Flag indicating if the session is newly created
     $sessData['isNew'] = $sess->isSessionNew();
     $auth = Auth::getInstance();
     $this->auth['user'] = $auth->getUser();
     //Assign to smarty variables
     $this->template->assign('DATA', $this->fieldData);
     $this->template->assign('ERRORS', $this->invalidFields);
     $this->template->assign('SESSION', $sessData);
     $this->template->assign('CONFIG', $cfg);
     $this->template->assign('AUTH', $this->auth);
     //Assign formName and templateID. Notice that $this->assign is used, ()
     //not $this->template->assign(). Assignments done this way will end up
     //in the $VIEWER smarty variable array. This is the mechanism though
     //which a viewer sends data to a template.
     $this->assign('formName', $this->formName);
     $this->assign('templateID', end($this->templateIDStack));
     $this->assign('templateIDStack', $this->templateIDStack);
     //Setup file handler. This allows multiple directories to be searched,
     //instead of using smarties one directory default.
     $this->template->register_resource('rfile', array('SmartyResources', 'smarty_resource_rfile_source', 'smarty_resource_rfile_timestamp', 'smarty_resource_rfile_secure', 'smarty_resource_rfile_trusted'));
     //Set this template access method as default. This makes this
     //process transparent to the smarty coder.
     $this->template->default_resource_type = 'rfile';
     //Register functions specific to this application. These may be
     //found in SmartyFunctions.class.php.
     $this->template->register_function('getTemplateID', array('SmartyFunctions', 'SMARTY_getTemplateID'));
     $this->template->register_function('templateLink', array('SmartyFunctions', 'SMARTY_templateLink'));
     $this->template->register_function('use', array($this, 'SMARTY_use'));
 }
Example #2
0
 /**
  * Smarty instance setter
  *
  * it also setup Smarty with predefined values
  *
  * @param  Smarty $smarty
  * @return SimpleMail_Template_SmartyRenderer
  */
 public function setSmarty(Smarty $smarty)
 {
     $this->smarty = $smarty;
     $this->smarty->register_resource('plain', array(array($this, 'loadPlain'), array($this, 'loadTimestamp'), array($this, 'loadSecure'), array($this, 'loadTrusted')));
     $this->o_smarty->register_resource('html', array(array($this, 'loadHtml'), array($this, 'loadTimestamp'), array($this, 'loadSecure'), array($this, 'loadTrusted')));
     $this->smarty->register_resource('subject', array(array($this, 'loadSubject'), array($this, 'loadTimestamp'), array($this, 'loadSecure'), array($this, 'loadTrusted')));
     $cache_dir = $this->getOption('cache_dir');
     if ($cache_dir) {
         $this->smarty->compile_dir = $cache_dir;
     }
     $this->smarty->left_delimiter = $this->getOption('left_delimiter');
     $this->smarty->right_delimiter = $this->getOption('right_delimiter');
     return $this;
 }
Example #3
0
function renderWidget(&$parser, $widgetName)
{
    global $IP;
    $smarty = new Smarty();
    $smarty->left_delimiter = '<!--{';
    $smarty->right_delimiter = '}-->';
    $smarty->compile_dir = "{$IP}/extensions/Widgets/compiled_templates/";
    $smarty->security = true;
    $smarty->security_settings = array('IF_FUNCS' => array('is_array', 'isset', 'array', 'list', 'count', 'sizeof', 'in_array', 'true', 'false', 'null'));
    // register the resource name "db"
    $smarty->register_resource("wiki", array("wiki_get_template", "wiki_get_timestamp", "wiki_get_secure", "wiki_get_trusted"));
    $params = func_get_args();
    array_shift($params);
    # first one is parser - we don't need it
    array_shift($params);
    # second one is widget name
    $params_tree = array();
    foreach ($params as $param) {
        $pair = explode('=', $param, 2);
        if (count($pair) == 2) {
            $key = trim($pair[0]);
            $val = trim($pair[1]);
            /* If the name of the parameter has object notation
            
            				a.b.c.d
            
            			   then we assign stuff to hash of hashes, not scalar
            
            			*/
            $keys = explode('.', $key);
            // $subtree will be moved from top to the bottom and at the end will point to the last level
            $subtree =& $params_tree;
            // go throught all the keys but last one
            $last_key = array_pop($keys);
            foreach ($keys as $subkey) {
                // if next level of subtree doesn't exist yet, create an empty one
                if (!array_key_exists($subkey, $subtree)) {
                    $subtree[$subkey] = array();
                }
                // move to the lower level
                $subtree =& $subtree[$subkey];
            }
            // last portion of the key points to itself
            if (isset($subtree[$last_key])) {
                // if already an array, push into it, otherwise, convert into array first
                if (!is_array($subtree[$last_key])) {
                    $subtree[$last_key] = array($subtree[$last_key]);
                }
                $subtree[$last_key][] = $val;
            } else {
                // doesn't exist yet, just setting a value
                $subtree[$last_key] = $val;
            }
        }
    }
    $smarty->assign($params_tree);
    try {
        $output = $smarty->fetch("wiki:{$widgetName}");
    } catch (Exception $e) {
        return "<div class=\"error\">Error in [[Widget:{$widgetName}]]</div>";
    }
    return $parser->insertStripItem($output, $parser->mStripState);
}
Example #4
0
 public static function renderWidget(&$parser, $widgetName)
 {
     global $IP;
     $smarty = new Smarty();
     $smarty->left_delimiter = '<!--{';
     $smarty->right_delimiter = '}-->';
     $smarty->compile_dir = "{$IP}/extensions/Widgets/compiled_templates/";
     // registering custom Smarty plugins
     $smarty->plugins_dir[] = "{$IP}/extensions/Widgets/smarty_plugins/";
     $smarty->security = true;
     $smarty->security_settings = array('IF_FUNCS' => array('is_array', 'isset', 'array', 'list', 'count', 'sizeof', 'in_array', 'true', 'false', 'null'), 'MODIFIER_FUNCS' => array('validate'));
     // register the resource name "db"
     $smarty->register_resource('wiki', array('WidgetRenderer::wiki_get_template', 'WidgetRenderer::wiki_get_timestamp', 'WidgetRenderer::wiki_get_secure', 'WidgetRenderer::wiki_get_trusted'));
     $params = func_get_args();
     array_shift($params);
     # first one is parser - we don't need it
     array_shift($params);
     # second one is widget name
     $params_tree = array();
     foreach ($params as $param) {
         $pair = explode('=', $param, 2);
         if (count($pair) == 2) {
             $key = trim($pair[0]);
             $val = trim($pair[1]);
         } else {
             $key = $param;
             $val = true;
         }
         if ($val == 'false') {
             $val = false;
         }
         /* If the name of the parameter has object notation
         
         			a.b.c.d
         
         		   then we assign stuff to hash of hashes, not scalar
         
         		*/
         $keys = explode('.', $key);
         // $subtree will be moved from top to the bottom and at the end will point to the last level
         $subtree =& $params_tree;
         // go throught all the keys but last one
         $last_key = array_pop($keys);
         foreach ($keys as $subkey) {
             // if next level of subtree doesn't exist yet, create an empty one
             if (!array_key_exists($subkey, $subtree)) {
                 $subtree[$subkey] = array();
             }
             // move to the lower level
             $subtree =& $subtree[$subkey];
         }
         // last portion of the key points to itself
         if (isset($subtree[$last_key])) {
             // if already an array, push into it, otherwise, convert into array first
             if (!is_array($subtree[$last_key])) {
                 $subtree[$last_key] = array($subtree[$last_key]);
             }
             $subtree[$last_key][] = $val;
         } else {
             // doesn't exist yet, just setting a value
             $subtree[$last_key] = $val;
         }
     }
     $smarty->assign($params_tree);
     try {
         $output = $smarty->fetch("wiki:{$widgetName}");
     } catch (Exception $e) {
         wfLoadExtensionMessages('Widgets');
         return '<div class=\\"error\\">' . wfMsgExt('widgets-desc', array('parsemag'), htmlentities($widgetName)) . '</div>';
     }
     // Hide the widget from the parser
     $output = 'ENCODED_CONTENT ' . base64_encode($output) . ' END_ENCODED_CONTENT';
     return $output;
 }
 /**
  * initTemplate($tmpl_path = '', array $options = [ ], array $extres = [ ])
  *
  * テンプレートエンジンのインスタンスを生成する
  *
  * @access    private
  *
  * @param     string $tmpl_path テンプレートファイルが格納されているディレクトリのパス
  * @param     array  $options Smartyに引き渡すオプション
  * @param     array  $extres 外部リソースの定義
  *
  * @return    object    テンプレートエンジンのインスタンス
  */
 private function initTemplate($tmpl_path = '', array $options = ['cache' => ['mode' => \Smarty::CACHING_LIFETIME_SAVED, 'lifetime' => 3600, 'modified_check' => true], 'compile' => ['check' => true, 'force' => false], 'debug' => ['enable' => false, 'ctrl' => 'NONE']], array $extres = [])
 {
     // テンプレートパスをアプリケーション格納フォルダ配下に限定
     $tmpl_path = str_replace(DS . DS, DS, RISOLUTO_APPS . 'RisolutoApps/' . str_replace('../', '', $tmpl_path));
     // テンプレートエンジン関連定義(Smartyを使用)
     $tmpl = new \Smarty();
     //--- テンプレートキャッシュの設定
     $tmpl->setCacheDir(RISOLUTO_CACHE);
     $tmpl->caching = isset($options['cache']['mode']) ? $options['cache']['mode'] : \Smarty::CACHING_LIFETIME_SAVED;
     $tmpl->cache_lifetime = isset($options['cache']['lifetime']) ? $options['cache']['lifetime'] : 3600;
     $tmpl->cache_modified_check = isset($options['cache']['modified_check']) ? $options['cache']['modified_check'] : true;
     //--- コンパイル済みテンプレートの設定
     $tmpl->setCompileDir(RISOLUTO_CACHE);
     $tmpl->compile_check = isset($options['compile']['check']) ? $options['compile']['check'] : true;
     $tmpl->force_compile = isset($options['compile']['force']) ? $options['compile']['force'] : false;
     //--- テンプレート用コンフィグファイルの設定
     $tmpl->setConfigDir($tmpl_path);
     //--- テンプレートのデバッグ設定
     $tmpl->debugging = isset($options['debug']['enable']) ? $options['debug']['enable'] : false;
     $tmpl->debugging_ctrl = isset($options['debug']['ctrl']) ? $options['debug']['ctrl'] : 'NONE';
     //--- テンプレートファイルのパス
     $tmpl->setTemplateDir($tmpl_path);
     // 外部リソースの登録
     if (isset($extres)) {
         foreach ($extres as $dat) {
             if (isset($dat['name']) and isset($dat['class'])) {
                 $tmpl->register_resource($dat['name'], [$dat['class'], 'getTemplate', 'getTimeStamp', 'getSecure', 'getTrusted']);
             }
         }
     }
     return $tmpl;
 }
Example #6
0
 /**
  * Register a resource to fetch a template
  *
  * @param string $type Name of resource
  * @param array $functions Array of functions to handle resource
  * @return void
  */
 function registerResource($type, $functions)
 {
     $this->_smarty->register_resource($type, $functions);
 }
Example #7
0
 /**
  * Returns an instance of the Smarty Template Engine
  * 
  * @static 
  * @return Smarty
  */
 static function getInstance()
 {
     static $instance = null;
     if (null == $instance) {
         define('SMARTY_RESOURCE_CHAR_SET', LANG_CHARSET_CODE);
         require DEVBLOCKS_PATH . 'libs/smarty/Smarty.class.php';
         $instance = new Smarty();
         $instance->template_dir = APP_PATH . '/templates';
         $instance->compile_dir = APP_TEMP_PATH . '/templates_c';
         $instance->cache_dir = APP_TEMP_PATH . '/cache';
         $instance->caching = 0;
         $instance->cache_lifetime = 0;
         $instance->compile_check = false;
         // Devblocks plugins
         $instance->register_block('devblocks_url', array(_DevblocksTemplateManager, 'block_devblocks_url'));
         $instance->register_modifier('devblocks_date', array(_DevblocksTemplateManager, 'modifier_devblocks_date'));
         $instance->register_modifier('devblocks_prettytime', array(_DevblocksTemplateManager, 'modifier_devblocks_prettytime'));
         $instance->register_modifier('devblocks_translate', array(_DevblocksTemplateManager, 'modifier_devblocks_translate'));
         $instance->register_resource('devblocks', array(array(_DevblocksSmartyTemplateResource, 'get_template'), array(_DevblocksSmartyTemplateResource, 'get_timestamp'), array(_DevblocksSmartyTemplateResource, 'get_secure'), array(_DevblocksSmartyTemplateResource, 'get_trusted')));
     }
     return $instance;
 }
Example #8
0
 function sendAdminMessage($name, $email_merge_fields = array(), $to = "system", $deptid = "", $adminid = "", $ticketnotify = "")
 {
     global $whmcs;
     global $CONFIG;
     global $templates_compiledir;
     global $smtp_debug;
     $result = select_query("tblemailtemplates", "", array("name" => $name, "language" => ""));
     $data = mysql_fetch_array($result);
     $type = $data['type'];
     $subject = $data['subject'];
     $message = $data['message'];
     $fromname = $data['fromname'];
     $fromemail = $data['fromemail'];
     $disabled = $data['disabled'];
     $copyto = $data['copyto'];
     $plaintext = $data['plaintext'];
     if ($disabled) {
         return false;
     }
     if (!$fromname) {
         $fromname = $CONFIG['SystemEmailsFromName'];
     }
     if (!$fromemail) {
         $fromemail = $CONFIG['SystemEmailsFromEmail'];
     }
     $email_merge_fields['company_name'] = $CONFIG['CompanyName'];
     $email_merge_fields['signature'] = nl2br(html_entity_decode($CONFIG['Signature'], ENT_QUOTES));
     $email_merge_fields['whmcs_url'] = $CONFIG['SystemURL'];
     $email_merge_fields['whmcs_link'] = "<a href=\"" . $CONFIG['SystemURL'] . "\">" . $CONFIG['SystemURL'] . "</a>";
     $adminurl = $CONFIG['SystemSSLURL'] ? $CONFIG['SystemSSLURL'] : $CONFIG['SystemURL'];
     $adminurl .= "/" . $whmcs->get_admin_folder_name() . "/";
     $email_merge_fields['whmcs_admin_url'] = $adminurl;
     $email_merge_fields['whmcs_admin_link'] = "<a href=\"" . $adminurl . "\">" . $adminurl . "</a>";
     include_once ROOTDIR . "/includes/smarty/Smarty.class.php";
     $smarty = new Smarty();
     $smarty->caching = 0;
     $smarty->compile_dir = $templates_compiledir;
     $smarty->compile_id = md5($subject . $message);
     $smarty->register_resource("emailtpl", array("emailtpl_template", "emailtpl_timestamp", "emailtpl_secure", "emailtpl_trusted"));
     $smarty->assign("emailsubject", $subject);
     $smarty->assign("emailmessage", $message);
     foreach ($email_merge_fields as $mergefield => $mergevalue) {
         $smarty->assign($mergefield, $mergevalue);
     }
     $subject = $smarty->fetch("emailtpl:emailsubject");
     $message = $smarty->fetch("emailtpl:emailmessage");
     $whmcs->load_class("phpmailer");
     $mail = new PHPMailer();
     if ($deptid) {
         $result = select_query("tblticketdepartments", "name,email", array("id" => $deptid));
         $data = mysql_fetch_array($result);
         $mail->From = $data['email'];
         $mail->FromName = html_entity_decode($CONFIG['CompanyName'] . " " . $data['name'], ENT_QUOTES);
     } else {
         $mail->From = $fromemail;
         $mail->FromName = html_entity_decode($fromname, ENT_QUOTES);
     }
     $mail->Subject = $subject;
     $mail->CharSet = $CONFIG['Charset'];
     if ($CONFIG['MailType'] == "mail") {
         $mail->Mailer = "mail";
     } else {
         if ($CONFIG['MailType'] == "smtp") {
             $mail->IsSMTP();
             $mail->Host = $CONFIG['SMTPHost'];
             $mail->Port = $CONFIG['SMTPPort'];
             $mail->Hostname = $_SERVER['SERVER_NAME'];
             if ($CONFIG['SMTPSSL']) {
                 $mail->SMTPSecure = $CONFIG['SMTPSSL'];
             }
             if ($CONFIG['SMTPUsername']) {
                 $mail->SMTPAuth = true;
                 $mail->Username = $CONFIG['SMTPUsername'];
                 $mail->Password = decrypt($CONFIG['SMTPPassword']);
             }
             $mail->Sender = $mail->From;
         }
     }
     if ($plaintext) {
         $message = str_replace("<br>", "", $message);
         $message = str_replace("<br />", "", $message);
         $message = strip_tags($message);
         $mail->Body = html_entity_decode($message, ENT_QUOTES);
     } else {
         $message_text = str_replace("</p>", "\r\n\r\n", $message);
         $message_text = str_replace("<br>", "\r\n", $message_text);
         $message_text = str_replace("<br />", "\r\n", $message_text);
         $message_text = strip_tags($message_text);
         if ($CONFIG['LogoURL']) {
             $message = "<p><a href=\"" . $CONFIG['Domain'] . "\" target=\"_blank\"><img src=\"" . $CONFIG['LogoURL'] . "\" alt=\"" . $CONFIG['CompanyName'] . "\" border=\"0\" /></a></p>" . "\r\n" . $message;
         }
         if ($CONFIG['EmailCSS']) {
             $message = "<style>\r\n" . $CONFIG['EmailCSS'] . ("\r\n</style>\r\n" . $message);
         }
         $mail->Body = $message;
         $mail->AltBody = $message_text;
     }
     if ($adminid) {
         $where = "tbladmins.disabled=0 AND tbladmins.id='" . (int) $adminid . "'";
         if ($type == "support") {
             $where .= " AND tbladminroles.supportemails='1'";
         }
     } else {
         $where = "tbladmins.disabled=0 AND tbladminroles." . db_escape_string($to) . "emails='1'";
         if ($deptid) {
             $where .= " AND tbladmins.ticketnotifications!=''";
         }
     }
     $emailcount = 0;
     $result = select_query("tbladmins", "firstname,lastname,email,supportdepts,ticketnotifications", $where, "", "", "", "tbladminroles ON tbladminroles.id=tbladmins.roleid");
     while ($data = mysql_fetch_array($result)) {
         if ($data['email']) {
             $adminsend = true;
             if ($ticketnotify) {
                 $ticketnotifications = $data['ticketnotifications'];
                 $ticketnotifications = explode(",", $ticketnotifications);
                 if (!in_array($deptid, $ticketnotifications)) {
                     $adminsend = false;
                 }
             } else {
                 if ($deptid) {
                     $supportdepts = $data['supportdepts'];
                     $supportdepts = explode(",", $supportdepts);
                     if (!in_array($deptid, $supportdepts)) {
                         $adminsend = false;
                     }
                 }
             }
             if ($adminsend) {
                 $mail->AddAddress(trim($data['email']), $data['firstname'] . " " . $data['lastname']);
                 ++$emailcount;
             }
         }
     }
     if ($copyto) {
         $copytoarray = explode(",", $copyto);
         if ($CONFIG['MailType'] == "mail") {
             foreach ($copytoarray as $copytoemail) {
                 $mail->AddBCC(trim($copytoemail));
             }
         } else {
             foreach ($copytoarray as $copytoemail) {
                 $mail->AddCC(trim($copytoemail));
             }
         }
     }
     if (!$emailcount) {
         return false;
     }
     if ($smtp_debug) {
         $mail->SMTPDebug = true;
     }
     if (!$mail->Send()) {
         logActivity("Admin Email Notification Sending Failed - " . $mail->ErrorInfo . (" (Subject: " . $subject . ")"), "none");
     }
     $mail->ClearAddresses();
 }
Example #9
0
 /**
  * sets properties of smarty object
  *
  * @param Smarty $smarty template processor object (smarty)
  */
 protected function _fillCommonSmartyProperties($smarty)
 {
     $config = $this->getConfig();
     $smarty->left_delimiter = '[{';
     $smarty->right_delimiter = '}]';
     $smarty->register_resource('ox', array('ox_get_template', 'ox_get_timestamp', 'ox_get_secure', 'ox_get_trusted'));
     $smartyDir = $this->getSmartyDir();
     $smarty->caching = false;
     $smarty->compile_dir = $smartyDir;
     $smarty->cache_dir = $smartyDir;
     $smarty->template_dir = $this->getTemplateDirs();
     $smarty->compile_id = $this->getTemplateCompileId();
     $smarty->default_template_handler_func = array(oxRegistry::get("oxUtilsView"), '_smartyDefaultTemplateHandler');
     array_unshift($smarty->plugins_dir, $config->getConfigParam('sShopDir') . 'Core/smarty/plugins');
     include_once dirname(__FILE__) . '/smarty/plugins/prefilter.oxblock.php';
     $smarty->register_prefilter('smarty_prefilter_oxblock');
     $debugMode = $config->getConfigParam('iDebug');
     if ($debugMode == 1 || $debugMode == 3 || $debugMode == 4) {
         $smarty->debugging = true;
     }
     if ($debugMode == 8 && !$config->isAdmin()) {
         include_once getShopBasePath() . 'Core/smarty/plugins/prefilter.oxtpldebug.php';
         $smarty->register_prefilter('smarty_prefilter_oxtpldebug');
     }
     //demo shop security
     if (!$config->isDemoShop()) {
         $smarty->php_handling = (int) $config->getConfigParam('iSmartyPhpHandling');
         $smarty->security = false;
     } else {
         $smarty->php_handling = SMARTY_PHP_REMOVE;
         $smarty->security = true;
         $smarty->security_settings['IF_FUNCS'][] = 'XML_ELEMENT_NODE';
         $smarty->security_settings['IF_FUNCS'][] = 'is_int';
         $smarty->security_settings['MODIFIER_FUNCS'][] = 'round';
         $smarty->security_settings['MODIFIER_FUNCS'][] = 'floor';
         $smarty->security_settings['MODIFIER_FUNCS'][] = 'trim';
         $smarty->security_settings['MODIFIER_FUNCS'][] = 'implode';
         $smarty->security_settings['MODIFIER_FUNCS'][] = 'is_array';
         $smarty->security_settings['ALLOW_CONSTANTS'] = true;
         $smarty->secure_dir = $smarty->template_dir;
     }
 }
        $tpl_source = get_value($arr['id'], $thulit['lang']);
        return true;
    } else {
        return false;
    }
}
function db_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
{
    global $db;
    global $thulit;
    //$set = db_get("select * from data where name_id='".$tpl_name."' and node_type='template'");
    //if ($arr = $set->fetchRow()){
    $tpl_timestamp = time();
    //$tpl_timestamp = get_value_prop($arr['id'],$thulit['lang'],'date_mod');
    return true;
    //}else{
    //  return false;
    //  }
}
function db_get_secure($tpl_name, &$smarty_obj)
{
    // assume all templates are secure
    return true;
}
function db_get_trusted($tpl_name, &$smarty_obj)
{
    // not used for templates
}
// register the resource name "db"
$smarty->register_resource("db", array("db_get_template", "db_get_timestamp", "db_get_secure", "db_get_trusted"));