root/trunk/Framework/Template/Smarty/plugins/function.framework_pager.php

Revision 196, 2.3 kB (checked in by ieure, 1 year ago)

Clean up whitespace, fixes #50

Line 
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6  * function.framework_pager.php
7  *
8  * @author      Joe Stump <joe@joestump.net>
9  * @copyright   (c) 2005 2006 Joseph C. Stump. All rights reserved.
10  * @package     Framework
11  * @subpackage  Template
12  * @filesource
13  */
14
15 /**
16  * smarty_function_framework_pager
17  *
18  * @author      Joe Stump <joe@joestump.net>
19  * @param       array       $params
20  * @param       object      $smarty
21  * @package     Framework
22  * @subpackage  Template
23  */
24 function smarty_function_framework_pager($params, &$smarty)
25 {
26     $required = array('start', 'limit', 'total');
27     foreach ($required as $r) {
28         if (!isset($params[$r])) {
29             $smarty->trigger_error("framework_pager: missing '$r' parameter");
30         }
31     }
32
33     extract($params);
34     if ($total <= $imit) {
35         return true;
36     }
37
38     $pageTotal = ($pages > 0) ? $pages : 10;
39
40     // Prep the URL string we use. We can't keep "start" in the URL because
41     // it will confuse scripts.
42     if ($params['url']) {
43         $url = $params['url'];
44     } else {
45         $url  = $_SERVER['SCRIPT_NAME'].$_SERVER['PATH_INFO'];
46     }
47
48     $sets = array();
49     foreach ($_GET as $key => $val) {
50         if ($key == 'start') {
51             continue;
52         }
53
54         if (strlen($key) && strlen($val)) {
55             if(!ereg($key."=",$_SERVER['PATH_INFO']) && !eregi('\?',$val)) {
56                 if (is_array($val)) {
57                     for($i = 0 ; $i < count($val) ; ++$i) {
58                         $sets[] = $key.'[]='.$val[$i];
59                     }
60                 } else {
61                     $sets[] = $key.'='.$val;
62                 }
63             }
64         }
65     }
66
67     $s = '?';
68     if (count($sets)) {
69         $url .= '?'.implode('&amp;',$sets);
70         $s = '&amp;';
71     }
72
73     // Only output if we have more than one page to show
74     $nav = & new Framework_Pager();
75     $nav->start = $start;
76     $nav->limit = $limit;
77     $nav->total = $total;
78     $nav->pages = $pageTotal;
79
80     if (($start + $limit) > $total) {
81         $stop = $total;
82     } else {
83         $stop = ($start + $limit);
84     }
85
86     $tpl = Framework_Template::factory('Smarty', 'Framework');
87     $tpl->assign('nav', $nav);
88     $tpl->assign('params', $params);
89     $tpl->assign('stop', $stop);
90     $tpl->assign('s', $s);
91     $tpl->assign('url', $url);
92     $tpl->display('framework_pager.tpl');
93 }
94
95 ?>
96
Note: See TracBrowser for help on using the browser.