Ejemplo n.º 1
0
 /**
  * Renders the current node
  *
  * @param Context $context
  *
  * @return string
  */
 public function render(Context $context)
 {
     $collection = $context->get($this->collectionName);
     if (!is_array($collection)) {
         die('not array, ' . var_export($collection, true));
     }
     // discard keys
     $collection = array_values($collection);
     if (isset($this->attributes['limit']) || isset($this->attributes['offset'])) {
         $limit = $context->get($this->attributes['limit']);
         $offset = $context->get($this->attributes['offset']);
         $collection = array_slice($collection, $offset, $limit);
     }
     $length = count($collection);
     $cols = $context->get($this->attributes['cols']);
     $row = 1;
     $col = 0;
     $result = "<tr class=\"row1\">\n";
     $context->push();
     foreach ($collection as $index => $item) {
         $context->set($this->variableName, $item);
         $context->set('tablerowloop', array('length' => $length, 'index' => $index + 1, 'index0' => $index, 'rindex' => $length - $index, 'rindex0' => $length - $index - 1, 'first' => (int) ($index == 0), 'last' => (int) ($index == $length - 1)));
         $result .= "<td class=\"col" . ++$col . "\">" . $this->renderAll($this->nodelist, $context) . "</td>";
         if ($col == $cols && !($index == $length - 1)) {
             $col = 0;
             $result .= "</tr>\n<tr class=\"row" . ++$row . "\">";
         }
     }
     $context->pop();
     $result .= "</tr>\n";
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * Renders the tag
  *
  * @param Context $context
  *
  * @return string|void
  */
 public function render(Context $context)
 {
     $output = $context->get($this->from);
     foreach ($this->filters as $filter) {
         list($filtername, $filterArgKeys) = $filter;
         $filterArgValues = array();
         foreach ($filterArgKeys as $arg_key) {
             $filterArgValues[] = $context->get($arg_key);
         }
         $output = $context->invoke($filtername, $output, $filterArgValues);
     }
     $context->set($this->to, $output, true);
 }
Ejemplo n.º 3
0
 /**
  * Renders the tag
  *
  * @var Context $context
  * @return string
  */
 public function render(Context $context)
 {
     $context->push();
     $key = $context->get($this->name);
     if (isset($context->registers['cycle'][$key])) {
         $iteration = $context->registers['cycle'][$key];
     } else {
         $iteration = 0;
     }
     $result = $context->get($this->variables[$iteration]);
     $iteration += 1;
     if ($iteration >= count($this->variables)) {
         $iteration = 0;
     }
     $context->registers['cycle'][$key] = $iteration;
     $context->pop();
     return $result;
 }
Ejemplo n.º 4
0
 /**
  * Renders the tag
  *
  * @param Context $context
  *
  * @return null|string
  */
 public function render(Context $context)
 {
     if (!isset($context->registers['for'])) {
         $context->registers['for'] = array();
     }
     $collection = $context->get($this->collectionName);
     if (is_null($collection) || !is_array($collection) || count($collection) == 0) {
         return '';
     }
     $range = array(0, count($collection));
     if (isset($this->attributes['limit']) || isset($this->attributes['offset'])) {
         $offset = 0;
         if (isset($this->attributes['offset'])) {
             $offset = $this->attributes['offset'] == 'continue' ? $context->registers['for'][$this->name] : $context->get($this->attributes['offset']);
         }
         $limit = isset($this->attributes['limit']) ? $context->get($this->attributes['limit']) : null;
         $rangeEnd = $limit ? $limit : count($collection) - $offset;
         $range = array($offset, $rangeEnd);
         $context->registers['for'][$this->name] = $rangeEnd + $offset;
     }
     $result = '';
     $segment = array_slice($collection, $range[0], $range[1]);
     if (!count($segment)) {
         return null;
     }
     $context->push();
     $length = count($segment);
     // todo: If $segment keys are not integer, forloop not work
     // array_values is only a little help without being tested.
     $segment = array_values($segment);
     foreach ($segment as $index => $item) {
         $context->set($this->variableName, $item);
         $context->set('forloop', array('name' => $this->name, 'length' => $length, 'index' => $index + 1, 'index0' => $index, 'rindex' => $length - $index, 'rindex0' => $length - $index - 1, 'first' => (int) ($index == 0), 'last' => (int) ($index == $length - 1)));
         $result .= $this->renderAll($this->nodelist, $context);
     }
     $context->pop();
     return $result;
 }
Ejemplo n.º 5
0
 /**
  * Renders the tag
  *
  * @param Context $context
  *
  * @return string|void
  */
 public function render(Context $context)
 {
     // if the value is not set in the environment check to see if it
     // exists in the context, and if not set it to 0
     if (!isset($context->environments[0][$this->toDecrement])) {
         // check for a context value
         $fromContext = $context->get($this->toDecrement);
         // we already have a value in the context
         $context->environments[0][$this->toDecrement] = null !== $fromContext ? $fromContext : 0;
     }
     // decrement the environment value
     $context->environments[0][$this->toDecrement]--;
     return '';
 }
Ejemplo n.º 6
0
 /**
  * Returns the current page URL
  *
  * @param Context $context
  *
  * @return string
  *
  */
 public function currentUrl($context)
 {
     $uri = explode('?', $context->get('REQUEST_URI'));
     $url = 'http';
     if ($context->get('HTTPS') == 'on') {
         $url .= 's';
     }
     $url .= '://' . $context->get('HTTP_HOST') . reset($uri);
     return $url;
 }
Ejemplo n.º 7
0
 /**
  * Renders the tag
  *
  * @param Context $context
  *
  * @return null|string
  */
 public function render(Context $context)
 {
     if (!isset($context->registers['for'])) {
         $context->registers['for'] = array();
     }
     switch ($this->type) {
         case 'collection':
             $collection = $context->get($this->collectionName);
             if (is_null($collection) || !is_array($collection) || count($collection) == 0) {
                 return '';
             }
             $range = array(0, count($collection));
             if (isset($this->attributes['limit']) || isset($this->attributes['offset'])) {
                 $offset = 0;
                 if (isset($this->attributes['offset'])) {
                     $offset = $this->attributes['offset'] == 'continue' ? $context->registers['for'][$this->name] : $context->get($this->attributes['offset']);
                 }
                 $limit = isset($this->attributes['limit']) ? $context->get($this->attributes['limit']) : null;
                 $rangeEnd = $limit ? $limit : count($collection) - $offset;
                 $range = array($offset, $rangeEnd);
                 $context->registers['for'][$this->name] = $rangeEnd + $offset;
             }
             $result = '';
             $segment = array_slice($collection, $range[0], $range[1]);
             if (!count($segment)) {
                 return null;
             }
             $context->push();
             $length = count($segment);
             $index = 0;
             foreach ($segment as $key => $item) {
                 $value = is_numeric($key) ? $item : array($key, $item);
                 $context->set($this->variableName, $value);
                 $context->set('forloop', array('name' => $this->name, 'length' => $length, 'index' => $index + 1, 'index0' => $index, 'rindex' => $length - $index, 'rindex0' => $length - $index - 1, 'first' => (int) ($index == 0), 'last' => (int) ($index == $length - 1)));
                 $result .= $this->renderAll($this->nodelist, $context);
                 $index++;
             }
             break;
         case 'digit':
             $start = $this->start;
             if (!is_integer($this->start)) {
                 $start = $context->get($this->start);
             }
             $end = $this->collectionName;
             if (!is_integer($this->collectionName)) {
                 $end = $context->get($this->collectionName);
             }
             $range = array($start, $end);
             $context->push();
             $result = '';
             $index = 0;
             $length = $range[1] - $range[0];
             for ($i = $range[0]; $i <= $range[1]; $i++) {
                 $context->set($this->variableName, $i);
                 $context->set('forloop', array('name' => $this->name, 'length' => $length, 'index' => $index + 1, 'index0' => $index, 'rindex' => $length - $index, 'rindex0' => $length - $index - 1, 'first' => (int) ($index == 0), 'last' => (int) ($index == $length - 1)));
                 $result .= $this->renderAll($this->nodelist, $context);
                 $index++;
             }
             break;
     }
     $context->pop();
     return $result;
 }
Ejemplo n.º 8
0
 /**
  * Renders the node
  *
  * @param Context $context
  *
  * @return string
  */
 public function render(Context $context)
 {
     $result = '';
     $variable = $context->get($this->variable);
     $context->push();
     foreach ($this->attributes as $key => $value) {
         $context->set($key, $context->get($value));
     }
     if ($this->collection) {
         foreach ($variable as $item) {
             $context->set($this->templateName, $item);
             $result .= $this->document->render($context);
         }
     } else {
         if (!is_null($this->variable)) {
             $context->set($this->templateName, $variable);
         }
         $result .= $this->document->render($context);
     }
     $context->pop();
     return $result;
 }