static function generator($cmp, $args, $assign = NULL) { if (!$cmp->getOption('allow_exec')) { $cmp->Error("Tag exec is disabled for security reasons"); } $code = hcode(); if (Haanga_AST::is_var($args[0])) { $args[0] = $args[0]['var']; } else { if (Haanga_AST::is_str($args[0])) { $args[0] = $args[0]['string']; } else { $cmp->Error("invalid param"); } } $exec = hexec($args[0]); for ($i = 1; $i < count($args); $i++) { $exec->param($args[$i]); } $exec->end(); if ($assign) { $code->decl($assign, $exec); } else { $cmp->do_print($code, $exec); } return $code; }
static function generator($compiler, $args) { if (Haanga_AST::is_str($args[0])) { return hexec('strlen', $args[0]); } return hexpr_cond(hexec('is_array', $args[0]), hexec('count', $args[0]), hexec('strlen', $args[0])); }
static function generator($compiler, $args) { $count = hexec('count', $args[0]); $strlen = hexec('strlen', $args[0]); $vars = hexec('count', hexec('get_object_vars', $args[0])); $guess = hexpr_cond(hexec('is_array', $args[0]), hexec('count', $args[0]), hexec('strlen', $args[0])); if (Haanga_AST::is_var($args[0])) { /* if it is a variable, best effort to detect its type at compile time */ $value = $compiler->get_context($args[0]['var']); if (is_array($value)) { return $count; } else { if (is_string($value)) { return $strlen; } else { if (is_object($value)) { return $vars; } else { return $gess; } } } } if (Haanga_AST::is_str($args[0])) { return $strlen; } return $guess; }
static function generator($compiler, $args) { if (count($args) != 1) { $compiler->Error("templatetag only needs one parameter"); } if (Haanga_AST::is_var($args[0])) { $type = $args[0]['var']; if (!is_string($type)) { $compiler->Error("Invalid parameter"); } } else { if (Haanga_AST::is_str($args[0])) { $type = $args[0]['string']; } } switch ($type) { case 'openblock': $str = '{%'; break; case 'closeblock': $str = '%}'; break; case 'openbrace': $str = '{'; break; case 'closebrace': $str = '}'; break; case 'openvariable': $str = '{{'; break; case 'closevariable': $str = '}}'; break; case 'opencomment': $str = '{#'; break; case 'closecomment': $str = '#}'; break; default: $compiler->Error("Invalid parameter"); break; } $code = hcode(); $compiler->do_print($code, Haanga_AST::str($str)); return $code; }
public static function generator($cmp, $args, $redirected) { if (count($args) != 1) { $cmp->Error("inline needs one argument"); } if ($redirected) { $cmp->Error("inline can't be redirected to one variable"); } if (!Haanga_AST::is_str($args[0])) { $cmp->Error("The argument to inline must be an string"); } $file = $args[0]['string']; if (class_exists('Haanga')) { $file = Haanga::getTemplatePath($file); } if (!is_file($file)) { $cmp->Error("{$file} is not a template"); } return $cmp->getOpCodes(file_get_contents($file), $file); }
static function generator($compiler, $args) { if (count($args) > 1) { if (!Haanga_AST::is_str($args[1])) { $compiler->Error("pluralize: First parameter must be an string"); } $parts = explode(",", $args[1]['string']); $singular = ""; if (count($parts) == 1) { $plural = $parts[0]; } else { $singular = $parts[0]; $plural = $parts[1]; } } else { $singular = ""; $plural = "s"; } return hexpr_cond(hexpr($args[0], '<=', 1), $singular, $plural); }
static function generator($cmp, $args, $assign = NULL) { if (!$cmp->getOption('allow_exec')) { $cmp->Error("Tag exec is disabled for security reasons"); } $code = hcode(); if (Haanga_AST::is_var($args[0])) { $args[0] = $args[0]['var']; } else { if (Haanga_AST::is_str($args[0])) { $args[0] = $args[0]['string']; } else { $cmp->Error("invalid param"); } } // fix for static calls {{{ if (is_array($args[0])) { $end = end($args[0]); if (isset($end['class'])) { $args[0][key($args[0])]['class'] = substr($end['class'], 1); } } // }}} $exec = hexec($args[0]); for ($i = 1; $i < count($args); $i++) { $exec->param($args[$i]); } $exec->end(); if ($assign) { $code->decl($assign, $exec); // make it global $code->decl($cmp->getScopeVariable($assign), hvar($assign)); } else { $cmp->do_print($code, $exec); } return $code; }
public function do_print(Haanga_AST $code, $stmt) { /* Flag this object as a printing one */ $code->doesPrint = TRUE; if (self::$strip_whitespace && Haanga_AST::is_str($stmt)) { $stmt['string'] = preg_replace('/\\s+/', ' ', $stmt['string']); } if ($this->ob_start == 0) { $code->do_echo($stmt); return; } $buffer = hvar('buffer' . $this->ob_start); $code->append($buffer, $stmt); }