static function generator($compiler, $args) { if (count($args) != 1) { $compiler->Error("title filter only needs one parameter"); } return hexec('ucwords', hexec('strtolower', $args[0])); }
static function generator($compiler, $args) { if (count($args) != 1) { $compiler->Error("Reverse only needs one parameter"); } return hexec('array_reverse', $args[0], TRUE); }
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($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; }
public static function generator($compiler, $args) { if (count($args) == 1) { $args[1] = ""; } return hexec("implode", $args[1], $args[0]); }
public static function generator($compiler, $args) { if (count($args) == 1 || $args[1] == "") { return hexec("str_split", $args[0]); } return hexec("explode", $args[1], $args[0]); }
static function generator($compiler, $args) { if (count($args) != 1) { $compiler->Error("Pop only needs two parameter"); } return hexec('array_pop', $args[0]); }
static function generator($cmp, $args, $redirected) { if (count($args) != 3 && count($args) != 4) { throw new Haanga_CompilerException("Memeame_Pagination requires 3 or 4 parameters"); } if (count($args) == 3) { $args[3] = 5; } $current = hvar('mnm_current'); $total = hvar('mnm_total'); $start = hvar('mnm_start'); $end = hvar('mnm_end'); $prev = hvar('mnm_prev'); $next = hvar('mnm_next'); $pages = 'mnm_pages'; $code = hcode(); $code->decl($current, $args[0]); $code->decl($total, hexec('ceil', hexpr($args[2], '/', $args[1]))); $code->decl($start, hexec('max', hexpr($current, '-', hexec('intval', hexpr($args[3], '/', 2))), 1)); $code->decl($end, hexpr($start, '+', $args[3], '-', 1)); $code->decl($prev, hexpr_cond(hexpr(1, '==', $current), FALSE, hexpr($current, '-', 1))); $code->decl($next, hexpr_cond(hexpr($args[2], '<', 0, '||', $current, '<', $total), hexpr($current, '+', 1), FALSE)); $code->decl('mnm_pages', hexec('range', $start, hexpr_cond(hexpr($end, '<', $total), $end, $total))); $cmp->set_safe($current); $cmp->set_safe($total); $cmp->set_safe($prev); $cmp->set_safe($next); $cmp->set_safe($pages); return $code; }
static function generator($compiler, $args) { if (count($args) != 2) { $compiler->Error("Explode only needs two parameter"); } return hexec('explode', $args[1], $args[0]); }
static function generator($cmp, $args) { if (!isset($args[1])) { $args[1] = 40; /* truncate to 40 letters by default */ } return hexec('txt_shorter', $args[0], $args[1]); }
static function generator($compiler, $args) { if (count($args) != 1) { $compiler->Error("alert filter only needs one parameter"); } $x = $args[0]; $pre = '<script type="text/javascript">alert("'; $post = '");</script>'; return hexec('html_entity_decode', hexec('preg_replace', '/$/', $post, hexec('preg_replace', '/^/', $pre, $x))); }
static function generator($cmp, $args, $declared) { if ($declared) { $cmp->Error("try_include can't be redirected to a variable"); } $code = hcode(); $exec = hexec('Haanga::Safe_Load', $args[0], $cmp->getScopeVariable(), TRUE, array()); $cmp->do_print($code, $exec); return $code; }
static function generator($compiler, $args) { if (count($args) != 1) { $compiler->Error("slugify filter only needs one parameter"); } $arg = hexec('strtolower', $args[0]); $arg = hexec('str_replace', " ", "-", $arg); $arg = hexec('preg_replace', "/[^\\d\\w-_]/", '', $arg); return $arg; }
static function generator($cmp, $args, $assign = NULL) { /* ast */ $code = hcode(); /* llamar a la funcion */ $exec = hexec('sprintf', '%.4f', hexpr(hexec('microtime', TRUE), '-', hvar('globals', 'start_time'))); /* imprimir la funcion */ $cmp->do_print($code, $exec); return $code; }
public static function generator($compiler, $args) { if (count($args) != 2) { $cmp->Error("substr parameter must have one param"); } if (!isset($args[1]['string'])) { $cmp->Error("substr parameter must be a string"); } list($start, $end) = explode(",", $args[1]['string']); return hexec('substr', $args[0], (int) $start, (int) $end); }
/** * firstof tag * */ static function generator($cmp, $args) { $count = count($args); $args = array_reverse($args); for ($i = 0; $i < $count; $i++) { if (isset($expr) && Haanga_AST::is_var($args[$i])) { $expr = hexpr_cond(hexpr(hexec('empty', $args[$i]), '==', FALSE), $args[$i], $expr); } else { $expr = $args[$i]; } } return $expr; }
static function generator($cmp, $args, $redirect) { $code = hcode(); $exec = hexec('_', $args[0]); if (count($args) > 1) { $exec = hexec('sprintf', $exec); foreach ($args as $id => $arg) { if ($id !== 0) { $exec->param($arg); } } } if ($redirect) { $code->decl($redirect, $exec); } else { $cmp->do_print($code, $exec); } return $code; }
static function generator($cmp, $args, $declared) { static $cycle = 0; if (!isset($cmp->cycle)) { $cmp->cycle = array(); } $code = hcode(); $index = 'index_' . $cycle; $def = 'def_cycle_' . $cycle; if (count($args) == 1 && Haanga_AST::is_var($args[0]) && isset($cmp->cycle[$args[0]['var']])) { $id = $cmp->cycle[$args[0]['var']]; $index = 'index_' . $id; $def = 'def_cycle_' . $id; } else { if (!$declared) { $code->do_if(hexpr(hexec('isset', hvar($def)), '==', FALSE)); } $code->decl($def, $args); if (!$declared) { $code->do_endif(); } } /* isset($var) == FALSE */ $expr = hexpr(hexec('isset', hvar($index)), '==', FALSE); $inc = hexpr(hexpr(hexpr(hvar($index), '+', 1)), '%', hexec('count', hvar($def))); if (!$declared) { if (isset($id)) { $code->decl($index, $inc); } else { $code->decl($index, hexpr_cond($expr, 0, $inc)); } $code->end(); $var = hvar($def, hvar($index)); $cmp->do_print($code, $var); } else { $code->decl($index, -1); $cmp->cycle[$declared] = $cycle; } $cycle++; return $code; }
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; }
static function generator($cmp, $args) { return hexec('parse_url', $args[0], hconst('PHP_URL_FRAGMENT')); }
/** * Generate needed code for custom tags (tags that aren't * handled by the compiler). * */ function generate_op_custom_tag($details, &$body) { static $tags; if (!$tags) { $tags = Haanga_Extension::getInstance('Tag'); } foreach ($details['list'] as $id => $arg) { if (Haanga_AST::is_var($arg)) { $details['list'][$id] = $this->generate_variable_name($arg['var']); } } $tag_name = $details['name']; $tagFunction = $tags->getFunctionAlias($tag_name); if (!$tagFunction && !$tags->hasGenerator($tag_name)) { $function = $this->get_custom_tag($tag_name, isset($details['as'])); } else { $function = $tagFunction; } if (isset($details['body'])) { /* if the custom tag has 'body' then it behave the same way as a filter */ $this->ob_start($body); $this->generate_op_code($details['body'], $body); $target = hvar('buffer' . $this->ob_start); if ($tags->hasGenerator($tag_name)) { $args = array_merge(array($target), $details['list']); $exec = $tags->generator($tag_name, $this, $args); if (!$exec instanceof Haanga_AST) { throw new Exception("Invalid output of custom filter {$tag_name}"); } if ($exec->stack_size() >= 2 || $exec->doesPrint) { /* The generator returned more than one statement, so we assume the output is already handled by one of those stmts. */ $body->append_ast($exec); $this->ob_start--; return; } } else { $exec = hexec($function, $target); } $this->ob_start--; $this->do_print($body, $exec); return; } $var = isset($details['as']) ? $details['as'] : NULL; $args = array_merge(array($function), $details['list']); if ($tags->hasGenerator($tag_name)) { $exec = $tags->generator($tag_name, $this, $details['list'], $var); if ($exec instanceof Haanga_AST) { if ($exec->stack_size() >= 2 || $exec->doesPrint || $var !== NULL) { /* The generator returned more than one statement, so we assume the output is already handled by one of those stmts. */ $body->append_ast($exec); return; } } else { throw new Exception("Invalid output of the custom tag {$tag_name}"); } } else { $fnc = array_shift($args); $exec = hexec($fnc); foreach ($args as $arg) { $exec->param($arg); } } if ($var) { $body->decl($var, $exec); } else { $this->do_print($body, $exec); } }
static function generator($compiler, $args) { return hexec('sprintf', '%06.2f', $args[0]); }
static function generator($compiler, $args) { return hexec('date', $args[1], hexec('strtotime', $args[0])); }
function yy_r81() { $this->_retvalue = hexec($this->yystack[$this->yyidx + -2]->minor)->getArray(); }
/** * We implement "cut" filter at compilation time, to * avoid senseless includes for simple things. * * We can also define an "php_alias" that will simple * call this function (therefore it must exists at * rendering time). * * Also a Main() static method could be declared, this will * included at runtime or copied as a function if the CLI is used (more * or less django style). * */ static function generator($compiler, $args) { return hexec('str_replace', $args[1], "", $args[0]); }
/** * spaceless now uses generated code instead of * calling Spaceless_Tag::main() at everytime. * */ static function generator($compiler, $args) { $regex = array('/>[ \\t\\r\\n]+</sU', '/^[ \\t\\r\\n]+</sU', '/>[ \\t\\r\\n]+$/sU'); $repl = array('><', '<', '>'); return hexec('preg_replace', $regex, $repl, $args[0]); }
public static function generator($cmp, $args) { $cmp->var_is_safe = TRUE; return hexec('urlencode', $args[0]); }
static function generator($compiler, $args) { return hexpr_cond(hexpr(hexec('empty', $args[0]), '==', TRUE), $args[1], $args[0]); }
function expr_call_base_template() { return hexec('Haanga::Load', $this->subtemplate, hvar('vars'), TRUE, hvar('blocks')); }