SmartyHelper.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace MGModule\DNSManager2\mgLibs\custom\mailer;
  3. class SmartyHelper {
  4. public static function getSmarty() {
  5. global $templates_compiledir;
  6. if(WHMCS6) {
  7. if(!class_exists('SmartyBC')) {
  8. if(file_exists(MAIN_WHMCS_DIR.DS.'vandor'.DS.'smarty'.DS.'smarty'.DS.'libs'.DS.'SmartyBC.class.php')) {
  9. require_once(MAIN_WHMCS_DIR.DS.'vandor'.DS.'smarty'.DS.'smarty'.DS.'libs'.DS.'SmartyBC.class.php');
  10. } else {
  11. die('Smarty does not exists!');
  12. }
  13. }
  14. } else {
  15. if(!class_exists('Smarty')) {
  16. if(file_exists(MAIN_WHMCS_DIR.DS.'includes'.DS.'smarty'.DS.'Smarty.class.php')) {
  17. require_once(MAIN_WHMCS_DIR.DS.'includes'.DS.'smarty'.DS.'Smarty.class.php');
  18. } else {
  19. die('Smarty does not exists!');
  20. }
  21. }
  22. }
  23. if(WHMCS6)
  24. $smarty = new \SmartyBC();
  25. else
  26. $smarty = new \Smarty();
  27. $smarty->caching = 0;
  28. $smarty->compile_dir = $templates_compiledir;
  29. //$smarty->error_reporting = 0;
  30. return $smarty;
  31. }
  32. public static function registerResources($smarty) {
  33. $smarty->register_resource("fromstr",
  34. array(
  35. array('MG_SMS_SmartyHelper','fromstr_template'),
  36. array('MG_SMS_SmartyHelper','fromstr_timestamp'),
  37. array('MG_SMS_SmartyHelper','fromstr_secure'),
  38. array('MG_SMS_SmartyHelper','fromstr_trusted'),
  39. )
  40. );
  41. }
  42. public static function fromstr_template($tpl_name, &$tpl_source, &$smarty_obj) {
  43. $tpl_source = $smarty_obj->get_template_vars($tpl_name);
  44. return empty($tpl_source)?false:true;
  45. }
  46. public static function fromstr_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj) {
  47. $tpl_timestamp = time();
  48. return true;
  49. }
  50. public static function fromstr_secure($tpl_name, &$smarty_obj) {
  51. return true;
  52. }
  53. public static function fromstr_trusted($tpl_name, &$smarty_obj) {
  54. }
  55. public static function fetchFromString($string,$data=false) {
  56. $smarty = self::getSmarty();
  57. self::registerResources($smarty);
  58. if(is_array($data)) {
  59. foreach($data as $key => $value) {
  60. $smarty->assign($key, $value);
  61. }
  62. }
  63. $uid = uniqid(); //caching prevent
  64. $smarty->assign($uid, $string);
  65. if(WHMCS6)
  66. return $smarty->fetch('string:'.$string, $uid);
  67. else
  68. return $smarty->fetch('fromstr:'.$uid);
  69. }
  70. }