<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty {paginator} function plugin
 *
 * Type:     function<br>
 * Name:     paginator<br>
 * Purpose:  create pages links<br>
 * @param array
 * @param Smarty
 */
function smarty_function_paginator($params, &$smarty)
{
  $col = $params['col'];
  $cur = $params['cur'];
  $url = $params['url'];
  $delta = $params['delta'] ? $params['delta'] : 5;

  echo '<div class="pages">';
  if ($cur > 2)
    echo '<a href="' . sprintf($url, 1) .'" class="first">&lt;&lt;&lt;</a>';
  if ($cur > 1)
    echo '<a href="' . sprintf($url, $cur-1) .'" class="prev">&lt;&lt;</a>';

  $start = $cur - $delta;
  if ($start < 1) $start = 1;
  $end = $cur + $delta;
  if ($end > $col) $end = $col;

  for ($i = $start; $i <= $end; $i++) {
    if ($i == $cur) {
      echo '<b>'.$i.'</b>';
    } else {
      echo '<a href="' . sprintf($url, $i) .'" class="page">'.$i.'</a>';
    }
  }

  if ($cur < $col-1)
    echo '<a href="' . sprintf($url, $cur+1) .'" class="prev">&gt;&gt;</a>';
  if ($cur < $col)
    echo '<a href="' . sprintf($url, $col) .'" class="first">&gt;&gt;&gt;</a>';
  echo '</div>';

  return;
}

/* vim: set expandtab: */

?>
