TEMPLATE_GLOBAL_TAGS = array('upper', 'tofloat','trrep', 'unsetck' ,'sample_with_args', 'debug', 'url', 'url2', 'function_deny', 'isset', 'empty', 'formatDate', 'zh_in_array', 'zh_empty', 'fileExists', 'odd', 'mbsub', 'zhisset', 'totime'); /** Define as class (optional) class TemplateTag { public static test(){} public static test2(){} } * */ function zhisset($str) { return isset($str); } function upper($str) { return strtoupper($str); } function tofloat($str) { return sprintf("%.2f", $str); } function unsetck($str){ setcookie ( $str, "", time () + 3600 * 24, "/", COOKIE_WEB_SITE ); return true; } function sample_with_args($str, $prefix) { return $str . ' with args: ' . $prefix; } function debug($var) { if (!empty($var)) { echo '
';
print_r($var);
echo '';
}
}
//This will be called when a function NOT Registered is used in IF or ElseIF statment
function function_deny($var = null) {
echo 'Function denied in IF or ElseIF statement!';
exit;
}
//Build URL based on route id
function url($id, $param = null, $addRootUrl = false) {
Doo::loadHelper('DooUrlBuilder');
// param pass in as string with format
// 'param1=>this_is_my_value, param2=>something_here'
if ($param != null) {
$param = explode(', ', $param);
$param2 = null;
foreach ($param as $p) {
$splited = explode('=>', $p);
$param2[$splited[0]] = $splited[1];
}
return DooUrlBuilder::url($id, $param2, $addRootUrl);
}
return DooUrlBuilder::url($id, null, $addRootUrl);
}
//Build URL based on controller and method name
function url2($controller, $method, $param = null, $addRootUrl = false) {
Doo::loadHelper('DooUrlBuilder');
// param pass in as string with format
// 'param1=>this_is_my_value, param2=>something_here'
if ($param != null) {
$param = explode(', ', $param);
$param2 = null;
foreach ($param as $p) {
$splited = explode('=>', $p);
$param2[$splited[0]] = $splited[1];
}
return DooUrlBuilder::url2($controller, $method, $param2, $addRootUrl);
}
return DooUrlBuilder::url2($controller, $method, null, $addRootUrl);
}
function formatDate($date, $format = 'Y-m-d H:i:s') {
return date($format, $date);
}
function zh_in_array($value, $arr) {
return in_array($value, $arr);
}
function trrep($str){
return str_replace("à","m3",str_replace("'","",$str));
}
function zh_empty($value) {
return empty($value);
}
function fileExists($filename) {
return file_exists($filename);
}
function odd($rownum) {
return $rownum % 2;
}
function mbsub($content) {
return mb_substr($content, 0, 35, 'utf-8');
}
function totime($s){
if($s<10){
return '00:00:0'.$s;
}elseif($s<60){
return '00:00:'.$s;
}elseif($s<3600){
$m = floor($s/60);
$s = $s%60;
if($m<10){
$m = '0'.$m;
}
if($s<10){
$s = '0'.$s;
}
return '00:'.$m.':'.$s;
}elseif($s>3600){
$h = floor($s/3600);
$m = floor($s/60);
$s = $s%60;
if($h<10){
$h = '0'.$h;
}
if($m<10){
$m = '0'.$m;
}
if($s<10){
$s = '0'.$s;
}
return $h.':'.$m.':'.$s;
}
}
?>