PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/upload/libraries/template.class.php

https://github.com/sahilbabu/phpb2b
PHP | 149 lines | 135 code | 5 blank | 9 comment | 22 complexity | d414cf6dc9ad6b05be92ad4a4528ffd2 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * [PHPB2B] Copyright (C) 2007-2099, Ualink Inc. All Rights Reserved.
  4. * The contents of this file are subject to the License; you may not use this file except in compliance with the License.
  5. *
  6. * @version $Revision: 2161 $
  7. */
  8. require(LIB_PATH . "smarty/Smarty.class.php");
  9. class TemplateEngines extends Smarty {
  10. var $flash_layout = 'flash';
  11. var $tpl_ext = '.html';
  12. var $compile_sub_dirs = true;
  13. function TemplateEngines()
  14. {
  15. global $debug, $app_lang;
  16. $this->Smarty();
  17. if (isset($debug)) {
  18. switch ($debug) {
  19. case 1:
  20. error_reporting(E_ALL & ~E_DEPRECATED);
  21. if(function_exists('ini_set')) {
  22. ini_set('display_errors', 1);
  23. }
  24. break;
  25. case 2:
  26. error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
  27. if(function_exists('ini_set')) {
  28. ini_set('display_errors', 1);
  29. }
  30. break;
  31. case 3:
  32. error_reporting(E_ERROR);
  33. if(function_exists('ini_set')) {
  34. ini_set('display_errors', 1);
  35. }
  36. break;
  37. case 4:
  38. error_reporting(E_ALL);
  39. if(function_exists('ini_set')) {
  40. ini_set('display_errors', 1);
  41. }
  42. $GLOBALS['pdb']->debug = true;
  43. break;
  44. case 5:
  45. error_reporting(E_ALL);
  46. if(function_exists('ini_set')) {
  47. ini_set('display_errors', 1);
  48. }
  49. $GLOBALS['pdb']->debug = true;
  50. $this->debugging = true;
  51. break;
  52. default:
  53. error_reporting(0);
  54. if(function_exists('ini_set')) {
  55. ini_set('display_errors', 0);
  56. }
  57. break;
  58. }
  59. }
  60. $this->plugins_dir[] = PLUGIN_PATH."slug".DS;
  61. $this->template_dir = PHPB2B_ROOT ."templates".DS;
  62. $this->config_dir = PHPB2B_ROOT ."configs".DS;
  63. $this->compile_dir = DATA_PATH."templates_c".DS.$app_lang.DS;
  64. $this->cache_dir = DATA_PATH."templates_cache".DS.$app_lang.DS;
  65. $this->cache_lifetime = 86400;
  66. $this->caching = false;
  67. $this->cache_modified_check = false;
  68. // $this->use_sub_dirs = true;
  69. // if safemode, set user_sub_dirs false
  70. // $this->use_sub_dirs = false;
  71. $this->load_filter('pre','fix');
  72. }
  73. function setCompileDir($compile_dir = '')
  74. {
  75. if (!$this->compile_sub_dirs) {
  76. if(!is_dir($this->compile_dir)) {
  77. pb_create_folder($this->compile_dir);
  78. @chmod($this->compile_dir, 0777);
  79. }
  80. return false;
  81. }
  82. $comp_d = $this->compile_dir.$compile_dir;
  83. if(!is_dir($comp_d)) {
  84. pb_create_folder($comp_d);
  85. @chmod($comp_d, 0777);
  86. }
  87. $smarty_cache = false;
  88. if (defined("SMARTY_CACHE")) {
  89. $smarty_cache = SMARTY_CACHE;
  90. }
  91. if($this->caching || $smarty_cache) {
  92. if(!is_dir($this->cache_dir)) {
  93. pb_create_folder($this->cache_dir);
  94. @chmod($this->cache_dir, 0777);
  95. }
  96. }
  97. $this->compile_dir =$comp_d;
  98. }
  99. function flash($message_code, $url, $pause = 1, $extra = '') {
  100. global $theme_name;
  101. $images = array("failed.png", "success.png", "notice.png");
  102. $styles = array("error", "true");
  103. if (empty($message_code) || !$message_code || $message_code=="failed") {
  104. $image = $images[0];
  105. $message = L('action_failed', "msg", $extra);
  106. $style = $styles[0];
  107. }elseif($message_code=="success" or true===$message_code or strstr("success", $message_code)){
  108. $image = $images[1];
  109. $style = $styles[1];
  110. $message = L("success", "msg", $extra);
  111. }else{
  112. $image = $images[2];
  113. $style = null;
  114. $message = L($message_code, "msg", $extra);
  115. }
  116. $this->assign('action_img', $image);
  117. $this->assign('action_style', $style);
  118. $this->assign('url', $url);
  119. $this->assign('message', $message);
  120. $this->assign('title', strip_tags($message));
  121. if($pause!=0){
  122. $this->assign('redirect', $this->redirect($url, $pause));
  123. }
  124. $this->assign('page_title', strip_tags($message));
  125. if(strstr($this->flash_layout, "/")){
  126. if (!$this->template_exists($this->flash_layout.$this->tpl_ext)) {
  127. $this->assign('ThemeName', 'default');
  128. $this->flash_layout = 'default/flash';
  129. }
  130. }
  131. if (!$this->template_exists($this->flash_layout.$this->tpl_ext)) {
  132. die($message);
  133. }
  134. template($this->flash_layout);
  135. exit();
  136. }
  137. function redirect($url, $pause) {
  138. return "<script>\n".
  139. "function redirect() {\nwindow.location.replace('$url');\n}\n".
  140. "setTimeout('redirect();', ".($pause*1000).");\n".
  141. "</script>";
  142. }
  143. }
  144. ?>