TemplateTag.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. //register global/PHP functions to be used with your template files
  3. //You can move this to common.conf.php $config['TEMPLATE_GLOBAL_TAGS'] = array('isset', 'empty');
  4. //Every public static methods in TemplateTag class (or tag classes from modules) are available in templates without the need to define in TEMPLATE_GLOBAL_TAGS
  5. Doo::conf()->TEMPLATE_GLOBAL_TAGS = array('upper', 'tofloat', 'sample_with_args', 'debug', 'url', 'url2', 'function_deny', 'isset', 'empty','format_date','strReplace');
  6. /**
  7. Define as class (optional)
  8. class TemplateTag {
  9. public static test(){}
  10. public static test2(){}
  11. }
  12. **/
  13. function strReplace($replace){
  14. $replace=str_replace("www_qibosoft_com/Tmp_updir","www.smartcost.com.cn/upload_files",$replace);
  15. return str_replace("www_php168_com/Tmp_updir","www.smartcost.com.cn/upload_files",$replace);
  16. }
  17. function format_date($strtotime = 0, $format = "Y-m-d"){
  18. return date ( $format, $strtotime );
  19. }
  20. function upper($str){
  21. return strtoupper($str);
  22. }
  23. function tofloat($str){
  24. return sprintf("%.2f", $str);
  25. }
  26. function sample_with_args($str, $prefix){
  27. return $str .' with args: '. $prefix;
  28. }
  29. function debug($var){
  30. if(!empty($var)){
  31. echo '<pre>';
  32. print_r($var);
  33. echo '</pre>';
  34. }
  35. }
  36. //This will be called when a function NOT Registered is used in IF or ElseIF statment
  37. function function_deny($var=null){
  38. echo '<span style="color:#ff0000;">Function denied in IF or ElseIF statement!</span>';
  39. exit;
  40. }
  41. //Build URL based on route id
  42. function url($id, $param=null, $addRootUrl=false){
  43. Doo::loadHelper('DooUrlBuilder');
  44. // param pass in as string with format
  45. // 'param1=>this_is_my_value, param2=>something_here'
  46. if($param!=null){
  47. $param = explode(', ', $param);
  48. $param2 = null;
  49. foreach($param as $p){
  50. $splited = explode('=>', $p);
  51. $param2[$splited[0]] = $splited[1];
  52. }
  53. return DooUrlBuilder::url($id, $param2, $addRootUrl);
  54. }
  55. return DooUrlBuilder::url($id, null, $addRootUrl);
  56. }
  57. //Build URL based on controller and method name
  58. function url2($controller, $method, $param=null, $addRootUrl=false){
  59. Doo::loadHelper('DooUrlBuilder');
  60. // param pass in as string with format
  61. // 'param1=>this_is_my_value, param2=>something_here'
  62. if($param!=null){
  63. $param = explode(', ', $param);
  64. $param2 = null;
  65. foreach($param as $p){
  66. $splited = explode('=>', $p);
  67. $param2[$splited[0]] = $splited[1];
  68. }
  69. return DooUrlBuilder::url2($controller, $method, $param2, $addRootUrl);
  70. }
  71. return DooUrlBuilder::url2($controller, $method, null, $addRootUrl);
  72. }
  73. ?>