示例#1
0
 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;
 }
示例#2
0
 /**
  *  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;
 }
示例#4
0
 static function generator($cmp, $args)
 {
     foreach ($args as $arg) {
         if (Haanga_AST::is_var($arg)) {
             $cmp->set_safe($arg['var']);
         }
     }
     return hcode();
 }
示例#5
0
 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;
 }
示例#6
0
文件: haanga.php 项目: scalia/Vevui
 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;
 }
示例#7
0
 static function generator($cmp, $args, $redirected)
 {
     if (count($args) != 2) {
         $cmp->Error("buffer filter must have one parameter");
     }
     /* get new code object */
     $code = hcode();
     /* redirect buffer to $args[1] */
     $code->decl($args[1], $args[0]);
     /* telling to Haanga that we're handling the output */
     $code->doesPrint = TRUE;
     /* $args[1] is already safe (it might have HTML) */
     $cmp->set_safe($args[1]['var']);
     return $code;
 }
示例#8
0
 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;
 }
示例#9
0
 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;
 }
示例#10
0
 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;
 }
示例#11
0
 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;
 }
示例#12
0
 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;
 }
示例#13
0
 protected function generate_op_loop($details, &$body)
 {
     if (isset($details['empty'])) {
         $body->do_if(hexpr(hexec('count', hvar($details['array'])), '==', 0));
         $this->generate_op_code($details['empty'], $body);
         $body->do_else();
     }
     /* ForID */
     $oldid = $this->forid;
     $this->forid = $oldid + 1;
     $this->forloop[$this->forid] = array();
     if (isset($details['range'])) {
         $this->set_safe($details['variable']);
     } else {
         /* check variable context */
         /* Check if the array to iterate is an object */
         $var =& $details['array'][0];
         if (is_string($var) && $this->var_is_object(array($var), FALSE)) {
             /* It is an object, call to get_object_vars */
             $body->decl($var . '_arr', hexec('get_object_vars', hvar($var)));
             $var .= '_arr';
         }
         unset($var);
         /* variables */
         $array = $this->get_filtered_var($details['array'], $varname);
         /* Loop body */
         if ($this->is_safe(hvar($varname))) {
             $this->set_safe(hvar($details['variable']));
         }
         if ($array instanceof Haanga_AST) {
             // filtered var
             $tmp = hvar('tmp' . ($oldid + 1));
             $body->decl($tmp, $array);
             $array = $tmp;
         }
         $details['array'] = $array;
     }
     /* for_body {{{ */
     $for_body = hcode();
     $this->generate_op_code($details['body'], $for_body);
     $oid = $this->forid;
     $size = hvar('psize_' . $oid);
     // counter {{{
     if (isset($this->forloop[$oid]['counter'])) {
         $var = hvar('forcounter1_' . $oid);
         $body->decl($var, 1);
         $for_body->decl($var, hexpr($var, '+', 1));
     }
     // }}}
     // counter0 {{{
     if (isset($this->forloop[$oid]['counter0'])) {
         $var = hvar('forcounter0_' . $oid);
         $body->decl($var, 0);
         $for_body->decl($var, hexpr($var, '+', 1));
     }
     // }}}
     // last {{{
     if (isset($this->forloop[$oid]['last'])) {
         if (!isset($cnt)) {
             $body->decl('psize_' . $oid, hexec('count', hvar_ex($details['array'])));
             $cnt = TRUE;
         }
         $var = 'islast_' . $oid;
         $body->decl($var, hexpr(hvar('forcounter1_' . $oid), '==', $size));
         $for_body->decl($var, hexpr(hvar('forcounter1_' . $oid), '==', $size));
     }
     // }}}
     // first {{{
     if (isset($this->forloop[$oid]['first'])) {
         $var = hvar('isfirst_' . $oid);
         $body->decl($var, TRUE);
         $for_body->decl($var, FALSE);
     }
     // }}}
     // revcounter {{{
     if (isset($this->forloop[$oid]['revcounter'])) {
         if (!isset($cnt)) {
             $body->decl('psize_' . $oid, hexec('count', hvar_ex($details['array'])));
             $cnt = TRUE;
         }
         $var = hvar('revcount_' . $oid);
         $body->decl($var, $size);
         $for_body->decl($var, hexpr($var, '-', 1));
     }
     // }}}
     // revcounter0 {{{
     if (isset($this->forloop[$oid]['revcounter0'])) {
         if (!isset($cnt)) {
             $body->decl('psize_' . $oid, hexec('count', hvar_ex($details['array'])));
             $cnt = TRUE;
         }
         $var = hvar('revcount0_' . $oid);
         $body->decl($var, hexpr($size, "-", 1));
         $for_body->decl($var, hexpr($var, '-', 1));
     }
     // }}}
     /* }}} */
     /* Restore old ForID */
     $this->forid = $oldid;
     /* Merge loop body  */
     if (!isset($details['range'])) {
         $body->do_foreach($array, $details['variable'], $details['index'], $for_body);
         if ($this->is_safe(hvar($varname))) {
             $this->set_unsafe($details['variable']);
         }
     } else {
         for ($i = 0; $i < 2; $i++) {
             if (Haanga_AST::is_var($details['range'][$i])) {
                 $details['range'][$i] = $this->generate_variable_name($details['range'][$i]['var']);
             }
         }
         if (Haanga_AST::is_var($details['step'])) {
             $details['step'] = $this->generate_variable_name($details['step']['var']);
         }
         $body->do_for($details['variable'], $details['range'][0], $details['range'][1], $details['step'], $for_body);
         $this->set_unsafe(hvar($details['variable']));
     }
     if (isset($details['empty'])) {
         $body->do_endif();
     }
 }
示例#14
0
文件: Parser.php 项目: crodas/haanga
 function yy_r82()
 {
     $tmp = hcode();
     $args = array_merge(array($this->yystack[$this->yyidx + -3]->minor), $this->yystack[$this->yyidx + -1]->minor);
     $this->_retvalue = call_user_func_array(array($tmp, 'exec'), $args);
 }
示例#15
0
文件: AST.php 项目: crodas/haanga
 static function getValue($obj, &$value, $get_all = FALSE)
 {
     $class = __CLASS__;
     if ($obj instanceof $class) {
         $value = $obj->getArray($get_all);
     } else {
         if (is_string($obj)) {
             $value = self::str($obj);
         } else {
             if (is_numeric($obj) or $obj === 0) {
                 $value = self::num($obj);
             } else {
                 if ($obj === FALSE) {
                     $value = array('expr' => FALSE);
                 } else {
                     if ($obj === TRUE) {
                         $value = array('expr' => TRUE);
                     } else {
                         if (is_array($obj)) {
                             foreach (array('expr_cond', 'op_expr', 'exec', 'var', 'string', 'number', 'constant') as $type) {
                                 if (isset($obj[$type])) {
                                     $value = $obj;
                                     return;
                                 }
                             }
                             $h = hcode()->arr();
                             $first = 0;
                             foreach ($obj as $key => $value) {
                                 if ($key === $first) {
                                     $key = NULL;
                                     $first++;
                                 }
                                 $h->element($key, $value);
                             }
                             $value = $h->getArray();
                         } else {
                             if ($obj === NULL) {
                                 $value = array();
                             } else {
                                 var_Dump($obj);
                                 throw new Exception("Imposible to get the value of the object");
                             }
                         }
                     }
                 }
             }
         }
     }
 }
示例#16
0
 protected function generate_op_loop($details, &$body)
 {
     if (isset($details['empty'])) {
         $body->do_if(hexpr(hexec('count', hvar($details['array'])), '==', 0));
         $this->generate_op_code($details['empty'], $body);
         $body->do_else();
     }
     /* ForID */
     $oldid = $this->forid;
     $this->forid = $oldid + 1;
     $this->forloop[$this->forid] = array();
     /* Check if the array to iterate is an object */
     $var =& $details['array'][0];
     if (is_string($var) && $this->var_is_object(array($var), FALSE)) {
         /* It is an object, call to get_object_vars */
         $body->decl($var . '_arr', hexec('get_object_vars', hvar($var)));
         $var .= '_arr';
     }
     unset($var);
     /* variables */
     $array = $this->get_filtered_var($details['array'], $varname);
     /* Loop body */
     if ($this->is_safe(hvar($varname))) {
         $this->set_safe(hvar($details['variable']));
     }
     /* check if the elements in the array is an array or object */
     $for_body = hcode();
     $this->generate_op_code($details['body'], $for_body);
     if ($this->is_safe(hvar($varname))) {
         $this->set_unsafe($details['variable']);
     }
     $oid = $this->forid;
     $size = hvar('psize_' . $oid);
     // counter {{{
     if (isset($this->forloop[$oid]['counter'])) {
         $var = hvar('forcounter1_' . $oid);
         $body->decl($var, 1);
         $for_body->decl($var, hexpr($var, '+', 1));
     }
     // }}}
     // counter0 {{{
     if (isset($this->forloop[$oid]['counter0'])) {
         $var = hvar('forcounter0_' . $oid);
         $body->decl($var, 0);
         $for_body->decl($var, hexpr($var, '+', 1));
     }
     // }}}
     // last {{{
     if (isset($this->forloop[$oid]['last'])) {
         if (!isset($cnt)) {
             $body->decl('psize_' . $oid, hexec('count', hvar_ex($details['array'])));
             $cnt = TRUE;
         }
         $var = 'islast_' . $oid;
         $body->decl($var, hexpr(hvar('forcounter1_' . $oid), '==', $size));
         $for_body->decl($var, hexpr(hvar('forcounter1_' . $oid), '==', $size));
     }
     // }}}
     // first {{{
     if (isset($this->forloop[$oid]['first'])) {
         $var = hvar('isfirst_' . $oid);
         $body->decl($var, TRUE);
         $for_body->decl($var, FALSE);
     }
     // }}}
     // revcounter {{{
     if (isset($this->forloop[$oid]['revcounter'])) {
         if (!isset($cnt)) {
             $body->decl('psize_' . $oid, hexec('count', hvar_ex($details['array'])));
             $cnt = TRUE;
         }
         $var = hvar('revcount_' . $oid);
         $body->decl($var, $size);
         $for_body->decl($var, hexpr($var, '-', 1));
     }
     // }}}
     // revcounter0 {{{
     if (isset($this->forloop[$oid]['revcounter0'])) {
         if (!isset($cnt)) {
             $body->decl('psize_' . $oid, hexec('count', hvar_ex($details['array'])));
             $cnt = TRUE;
         }
         $var = hvar('revcount0_' . $oid);
         $body->decl($var, hexpr($size, "-", 1));
         $for_body->decl($var, hexpr($var, '-', 1));
     }
     // }}}
     /* Restore old ForID */
     $this->forid = $oldid;
     /* Merge loop body  */
     $body->do_foreach($array, $details['variable'], $details['index'], $for_body);
     if (isset($details['empty'])) {
         $body->do_endif();
     }
 }