| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace MGModule\DNSManager2\mgLibs\custom\mailer;
- class SmartyHelper {
- public static function getSmarty() {
- global $templates_compiledir;
- if(WHMCS6) {
- if(!class_exists('SmartyBC')) {
- if(file_exists(MAIN_WHMCS_DIR.DS.'vandor'.DS.'smarty'.DS.'smarty'.DS.'libs'.DS.'SmartyBC.class.php')) {
- require_once(MAIN_WHMCS_DIR.DS.'vandor'.DS.'smarty'.DS.'smarty'.DS.'libs'.DS.'SmartyBC.class.php');
- } else {
- die('Smarty does not exists!');
- }
- }
- } else {
- if(!class_exists('Smarty')) {
- if(file_exists(MAIN_WHMCS_DIR.DS.'includes'.DS.'smarty'.DS.'Smarty.class.php')) {
- require_once(MAIN_WHMCS_DIR.DS.'includes'.DS.'smarty'.DS.'Smarty.class.php');
- } else {
- die('Smarty does not exists!');
- }
- }
- }
-
- if(WHMCS6)
- $smarty = new \SmartyBC();
- else
- $smarty = new \Smarty();
-
- $smarty->caching = 0;
- $smarty->compile_dir = $templates_compiledir;
- //$smarty->error_reporting = 0;
- return $smarty;
- }
-
- public static function registerResources($smarty) {
- $smarty->register_resource("fromstr",
- array(
- array('MG_SMS_SmartyHelper','fromstr_template'),
- array('MG_SMS_SmartyHelper','fromstr_timestamp'),
- array('MG_SMS_SmartyHelper','fromstr_secure'),
- array('MG_SMS_SmartyHelper','fromstr_trusted'),
- )
- );
- }
-
- public static function fromstr_template($tpl_name, &$tpl_source, &$smarty_obj) {
- $tpl_source = $smarty_obj->get_template_vars($tpl_name);
- return empty($tpl_source)?false:true;
- }
- public static function fromstr_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj) {
- $tpl_timestamp = time();
- return true;
- }
- public static function fromstr_secure($tpl_name, &$smarty_obj) {
- return true;
- }
- public static function fromstr_trusted($tpl_name, &$smarty_obj) {
-
- }
-
- public static function fetchFromString($string,$data=false) {
- $smarty = self::getSmarty();
- self::registerResources($smarty);
-
- if(is_array($data)) {
- foreach($data as $key => $value) {
- $smarty->assign($key, $value);
- }
- }
-
- $uid = uniqid(); //caching prevent
- $smarty->assign($uid, $string);
- if(WHMCS6)
- return $smarty->fetch('string:'.$string, $uid);
- else
- return $smarty->fetch('fromstr:'.$uid);
- }
- }
|