/** * Sorted a nested array by '$sort_by' * property on each sub-array. , if you want * to see the original php file look filters/dictsort.php */ static function generator($cmp, $args, $redirected) { if (!$redirected) { $cmp->Error("dictsort must be redirected to a variable using AS <varname>"); } if (count($args) != 2) { $cmp->Error("Dictsort must have two params"); } if (!Haanga_AST::is_var($args[0])) { $cmp->Error("Dictsort: First parameter must be an array"); } $var = $cmp->get_context($args[0]['var']); $cmp->set_context($redirected, $var); $redirected = hvar($redirected); $field = hvar('field'); $key = hvar('key'); $code = hcode(); $body = hcode(); $body->decl(hvar('field', $key), hvar('item', $args[1])); $code->decl($redirected, $args[0]); $code->decl($field, array()); $code->do_foreach($redirected, 'item', $key, $body); $code->do_exec('array_multisort', $field, hconst('SORT_REGULAR'), $redirected); return $code; }
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($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], hvar('vars'), TRUE, array()); $cmp->do_print($code, $exec); return $code; }
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; }
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; }
function set_unsafe($name) { if (!Haanga_AST::is_Var($name)) { $name = hvar($name)->getArray(); } unset($this->safes[serialize($name)]); }
function append($name, $value) { if (is_string($name)) { $name = hvar($name); } $this->getValue($value, $stmt); $this->getValue($name, $name); $this->stack[] = array('op' => 'append_var', 'name' => $name['var'], $stmt); return $this; }
function expr_call_base_template() { return hexec('Haanga::Load', $this->subtemplate, hvar('vars'), TRUE, hvar('blocks')); }
static function generator($cmp, $args, $assign = NULL) { $code = hcode(); if ($assign) { /* Return the variable */ $assign = hvar($assign); #$code->decl($assign, Haanga_AST::Str('http://')); #$code->append($assign, hexec('get_server_name')); $code->append($assign, hvar('globals', 'base_static')); foreach ($args as $arg) { $code->append($assign, $arg); } } else { /* print */ #$cmp->do_print($code, Haanga_AST::str('http://')); #$cmp->do_print($code, hexec('get_server_name')); $cmp->do_print($code, hvar('globals', 'base_static')); foreach ($args as $arg) { $cmp->do_print($code, $arg); } } return $code; }
function expr_call_base_template() { return hexec('Haanga::Load', $this->subtemplate, $this->getScopeVariable(), TRUE, hvar('blocks')); }