<?php
global $urlTo;
$urlTo = $this->getHelper("UrlTo");

function getURL($filters, $page) {
  global $urlTo;

  // retorna o front e o objeto request
  $frontController = Zend_Controller_Front::getInstance();
  $request = $frontController->getRequest();

  // monta o começo da url
  $url =  "cms/".$request->getControllerName() . "/" . $request->getActionName() . "/";

  // altera o registro de pagina
  $filters['p'] = $page;

  // finaliza a url
  $url .= "?" . http_build_query($filters);

  return $urlTo->urlTo($url);
}
?>

<?php if($this->pageCount){ ?>
<div class="span2" style="line-height: 38px"><?=$this->totalItemCount;?> item(s)</div>
<div class="pagination span8 center">
  <ul>
    <?php if($this->first != $this->filters['p']): ?>
    <li><a href="<?=getURL($this->filters, $this->first);?>">&laquo; First</a></li>
    <?php endif; ?>
    <?php if(isset($this->previous)): ?>
    <li><a href="<?=getURL($this->filters, $this->previous);?>">&laquo;</a></li>
    <?php endif; ?>
      <?php
      foreach($this->pagesInRange as $page)
      {
        echo '<li'. (($page == $this->filters['p'])? ' class="active"': '') .'><a href="'. (getURL($this->filters, $page, $this->view)) .'">'. $page .'</a></li>';
      }
      ?>
    <?php if(isset($this->next)): ?>
    <li><a href="<?=getURL($this->filters, $this->next);?>">&raquo;</a></li>
    <?php endif; ?>
    <?php if($this->last != $this->filters['p']): ?>
    <li><a href="<?=getURL($this->filters, $this->last);?>">&raquo; Last</a></li>
    <?php endif; ?>
  </ul>
</div>
<div class="span2" style="line-height: 38px">&nbsp;</div>
<?php } ?>