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;
 }
Example #2
0
 static function generator($cmp, $args, $assign = NULL)
 {
     /* ast */
     $code = hcode();
     /* llamar a la funcion */
     $exec = hexec('sprintf', "<!--Delivered to you in %4.3f seconds-->", hexpr(hexec('microtime', TRUE), '-', hvar('globals', 'start_time')));
     /* imprimir la funcion */
     $cmp->do_print($code, $exec);
     return $code;
 }
Example #3
0
 /**
  *  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;
 }
Example #4
0
 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);
 }
Example #5
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;
 }
Example #6
0
 protected function generate_op_ifchanged($details, &$body)
 {
     static $ifchanged = 0;
     $ifchanged++;
     $var1 = 'ifchanged' . $ifchanged;
     if (!isset($details['check'])) {
         /* ugly */
         $this->ob_start($body);
         $var2 = hvar('buffer' . $this->ob_start);
         $this->generate_op_code($details['body'], $body);
         $this->ob_start--;
         $body->do_if(hexpr(hexec('isset', hvar($var1)), '==', FALSE, '||', hvar($var1), '!=', $var2));
         $this->do_print($body, $var2);
         $body->decl($var1, $var2);
     } else {
         /* beauty :-) */
         foreach ($details['check'] as $id => $type) {
             if (!Haanga_AST::is_var($type)) {
                 throw new Exception("Unexpected string {$type['string']}, expected a varabile");
             }
             $this_expr = hexpr(hexpr(hexec('isset', hvar($var1, $id)), '==', FALSE, '||', hvar($var1, $id), '!=', $type));
             if (isset($expr)) {
                 $this_expr = hexpr($expr, '&&', $this_expr);
             }
             $expr = $this_expr;
         }
         $body->do_if($expr);
         $this->generate_op_code($details['body'], $body);
         $body->decl($var1, $details['check']);
     }
     if (isset($details['else'])) {
         $body->do_else();
         $this->generate_op_code($details['else'], $body);
     }
     $body->do_endif();
 }
Example #7
0
 static function generator($compiler, $args)
 {
     return hexpr_cond(hexpr(hexec('empty', $args[0]), '==', TRUE), $args[1], $args[0]);
 }