TemplateTag.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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','defined','strip_tags','cut_str');
  6. /**
  7. Define as class (optional)
  8. class TemplateTag {
  9. public static test(){}
  10. public static test2(){}
  11. }
  12. **/
  13. function upper($str){
  14. return strtoupper($str);
  15. }
  16. function tofloat($str){
  17. return sprintf("%.2f", $str);
  18. }
  19. function sample_with_args($str, $prefix){
  20. return $str .' with args: '. $prefix;
  21. }
  22. function debug($var){
  23. if(!empty($var)){
  24. echo '<pre>';
  25. print_r($var);
  26. echo '</pre>';
  27. }
  28. }
  29. //This will be called when a function NOT Registered is used in IF or ElseIF statment
  30. function function_deny($var=null){
  31. echo '<span style="color:#ff0000;">Function denied in IF or ElseIF statement!</span>';
  32. exit;
  33. }
  34. //Build URL based on route id
  35. function url($id, $param=null, $addRootUrl=false){
  36. Doo::loadHelper('DooUrlBuilder');
  37. // param pass in as string with format
  38. // 'param1=>this_is_my_value, param2=>something_here'
  39. if($param!=null){
  40. $param = explode(', ', $param);
  41. $param2 = null;
  42. foreach($param as $p){
  43. $splited = explode('=>', $p);
  44. $param2[$splited[0]] = $splited[1];
  45. }
  46. return DooUrlBuilder::url($id, $param2, $addRootUrl);
  47. }
  48. return DooUrlBuilder::url($id, null, $addRootUrl);
  49. }
  50. //Build URL based on controller and method name
  51. function url2($controller, $method, $param=null, $addRootUrl=false){
  52. Doo::loadHelper('DooUrlBuilder');
  53. // param pass in as string with format
  54. // 'param1=>this_is_my_value, param2=>something_here'
  55. if($param!=null){
  56. $param = explode(', ', $param);
  57. $param2 = null;
  58. foreach($param as $p){
  59. $splited = explode('=>', $p);
  60. $param2[$splited[0]] = $splited[1];
  61. }
  62. return DooUrlBuilder::url2($controller, $method, $param2, $addRootUrl);
  63. }
  64. return DooUrlBuilder::url2($controller, $method, null, $addRootUrl);
  65. }
  66. ?>