converted to unix-style eol
[www-register-wizard.git] / libraries / Pagination.php
index 5435f42..54ddd4c 100644 (file)
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');\r
-/**\r
- * CodeIgniter\r
- *\r
- * An open source application development framework for PHP 4.3.2 or newer\r
- *\r
- * @package            CodeIgniter\r
- * @author             ExpressionEngine Dev Team\r
- * @copyright  Copyright (c) 2008, EllisLab, Inc.\r
- * @license            http://codeigniter.com/user_guide/license.html\r
- * @link               http://codeigniter.com\r
- * @since              Version 1.0\r
- * @filesource\r
- */\r
-\r
-// ------------------------------------------------------------------------\r
-\r
-/**\r
- * Pagination Class\r
- *\r
- * @package            CodeIgniter\r
- * @subpackage Libraries\r
- * @category   Pagination\r
- * @author             ExpressionEngine Dev Team\r
- * @link               http://codeigniter.com/user_guide/libraries/pagination.html\r
- */\r
-class CI_Pagination {\r
-\r
-       var $base_url                   = ''; // The page we are linking to\r
-       var $total_rows                 = ''; // Total number of items (database results)\r
-       var $per_page                   = 10; // Max number of items you want shown per page\r
-       var $num_links                  =  2; // Number of "digit" links to show before/after the currently viewed page\r
-       var $cur_page                   =  0; // The current page being viewed\r
-       var $first_link                 = '&lsaquo; First';\r
-       var $next_link                  = '&gt;';\r
-       var $prev_link                  = '&lt;';\r
-       var $last_link                  = 'Last &rsaquo;';\r
-       var $uri_segment                = 3;\r
-       var $full_tag_open              = '';\r
-       var $full_tag_close             = '';\r
-       var $first_tag_open             = '';\r
-       var $first_tag_close    = '&nbsp;';\r
-       var $last_tag_open              = '&nbsp;';\r
-       var $last_tag_close             = '';\r
-       var $cur_tag_open               = '&nbsp;<b>';\r
-       var $cur_tag_close              = '</b>';\r
-       var $next_tag_open              = '&nbsp;';\r
-       var $next_tag_close             = '&nbsp;';\r
-       var $prev_tag_open              = '&nbsp;';\r
-       var $prev_tag_close             = '';\r
-       var $num_tag_open               = '&nbsp;';\r
-       var $num_tag_close              = '';\r
-       var $page_query_string  = FALSE;\r
-       var $query_string_segment = 'per_page';\r
-\r
-       /**\r
-        * Constructor\r
-        *\r
-        * @access      public\r
-        * @param       array   initialization parameters\r
-        */\r
-       function CI_Pagination($params = array())\r
-       {\r
-               if (count($params) > 0)\r
-               {\r
-                       $this->initialize($params);             \r
-               }\r
-               \r
-               log_message('debug', "Pagination Class Initialized");\r
-       }\r
-       \r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Initialize Preferences\r
-        *\r
-        * @access      public\r
-        * @param       array   initialization parameters\r
-        * @return      void\r
-        */\r
-       function initialize($params = array())\r
-       {\r
-               if (count($params) > 0)\r
-               {\r
-                       foreach ($params as $key => $val)\r
-                       {\r
-                               if (isset($this->$key))\r
-                               {\r
-                                       $this->$key = $val;\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-       \r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Generate the pagination links\r
-        *\r
-        * @access      public\r
-        * @return      string\r
-        */     \r
-       function create_links()\r
-       {\r
-               // If our item count or per-page total is zero there is no need to continue.\r
-               if ($this->total_rows == 0 OR $this->per_page == 0)\r
-               {\r
-                  return '';\r
-               }\r
-\r
-               // Calculate the total number of pages\r
-               $num_pages = ceil($this->total_rows / $this->per_page);\r
-\r
-               // Is there only one page? Hm... nothing more to do here then.\r
-               if ($num_pages == 1)\r
-               {\r
-                       return '';\r
-               }\r
-\r
-               // Determine the current page number.           \r
-               $CI =& get_instance();\r
-               \r
-               if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)\r
-               {\r
-                       if ($CI->input->get($this->query_string_segment) != 0)\r
-                       {\r
-                               $this->cur_page = $CI->input->get($this->query_string_segment);\r
-                               \r
-                               // Prep the current page - no funny business!\r
-                               $this->cur_page = (int) $this->cur_page;\r
-                       }\r
-               }\r
-               else\r
-               {\r
-                       if ($CI->uri->segment($this->uri_segment) != 0)\r
-                       {\r
-                               $this->cur_page = $CI->uri->segment($this->uri_segment);\r
-                               \r
-                               // Prep the current page - no funny business!\r
-                               $this->cur_page = (int) $this->cur_page;\r
-                       }\r
-               }\r
-\r
-               $this->num_links = (int)$this->num_links;\r
-               \r
-               if ($this->num_links < 1)\r
-               {\r
-                       show_error('Your number of links must be a positive number.');\r
-               }\r
-                               \r
-               if ( ! is_numeric($this->cur_page))\r
-               {\r
-                       $this->cur_page = 0;\r
-               }\r
-               \r
-               // Is the page number beyond the result range?\r
-               // If so we show the last page\r
-               if ($this->cur_page > $this->total_rows)\r
-               {\r
-                       $this->cur_page = ($num_pages - 1) * $this->per_page;\r
-               }\r
-               \r
-               $uri_page_number = $this->cur_page;\r
-               $this->cur_page = floor(($this->cur_page/$this->per_page) + 1);\r
-\r
-               // Calculate the start and end numbers. These determine\r
-               // which number to start and end the digit links with\r
-               $start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1;\r
-               $end   = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages;\r
-\r
-               // Is pagination being used over GET or POST?  If get, add a per_page query\r
-               // string. If post, add a trailing slash to the base URL if needed\r
-               if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)\r
-               {\r
-                       $this->base_url = rtrim($this->base_url).'&amp;'.$this->query_string_segment.'=';\r
-               }\r
-               else\r
-               {\r
-                       $this->base_url = rtrim($this->base_url, '/') .'/';\r
-               }\r
-\r
-               // And here we go...\r
-               $output = '';\r
-\r
-               // Render the "First" link\r
-               if  ($this->cur_page > ($this->num_links + 1))\r
-               {\r
-                       $output .= $this->first_tag_open.'<a href="'.$this->base_url.'">'.$this->first_link.'</a>'.$this->first_tag_close;\r
-               }\r
-\r
-               // Render the "previous" link\r
-               if  ($this->cur_page != 1)\r
-               {\r
-                       $i = $uri_page_number - $this->per_page;\r
-                       if ($i == 0) $i = '';\r
-                       $output .= $this->prev_tag_open.'<a href="'.$this->base_url.$i.'">'.$this->prev_link.'</a>'.$this->prev_tag_close;\r
-               }\r
-\r
-               // Write the digit links\r
-               for ($loop = $start -1; $loop <= $end; $loop++)\r
-               {\r
-                       $i = ($loop * $this->per_page) - $this->per_page;\r
-                                       \r
-                       if ($i >= 0)\r
-                       {\r
-                               if ($this->cur_page == $loop)\r
-                               {\r
-                                       $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page\r
-                               }\r
-                               else\r
-                               {\r
-                                       $n = ($i == 0) ? '' : $i;\r
-                                       $output .= $this->num_tag_open.'<a href="'.$this->base_url.$n.'">'.$loop.'</a>'.$this->num_tag_close;\r
-                               }\r
-                       }\r
-               }\r
-\r
-               // Render the "next" link\r
-               if ($this->cur_page < $num_pages)\r
-               {\r
-                       $output .= $this->next_tag_open.'<a href="'.$this->base_url.($this->cur_page * $this->per_page).'">'.$this->next_link.'</a>'.$this->next_tag_close;\r
-               }\r
-\r
-               // Render the "Last" link\r
-               if (($this->cur_page + $this->num_links) < $num_pages)\r
-               {\r
-                       $i = (($num_pages * $this->per_page) - $this->per_page);\r
-                       $output .= $this->last_tag_open.'<a href="'.$this->base_url.$i.'">'.$this->last_link.'</a>'.$this->last_tag_close;\r
-               }\r
-\r
-               // Kill double slashes.  Note: Sometimes we can end up with a double slash\r
-               // in the penultimate link so we'll kill all double slashes.\r
-               $output = preg_replace("#([^:])//+#", "\\1/", $output);\r
-\r
-               // Add the wrapper HTML if exists\r
-               $output = $this->full_tag_open.$output.$this->full_tag_close;\r
-               \r
-               return $output;         \r
-       }\r
-}\r
-// END Pagination Class\r
-\r
-/* End of file Pagination.php */\r
+<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 4.3.2 or newer
+ *
+ * @package            CodeIgniter
+ * @author             ExpressionEngine Dev Team
+ * @copyright  Copyright (c) 2008, EllisLab, Inc.
+ * @license            http://codeigniter.com/user_guide/license.html
+ * @link               http://codeigniter.com
+ * @since              Version 1.0
+ * @filesource
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * Pagination Class
+ *
+ * @package            CodeIgniter
+ * @subpackage Libraries
+ * @category   Pagination
+ * @author             ExpressionEngine Dev Team
+ * @link               http://codeigniter.com/user_guide/libraries/pagination.html
+ */
+class CI_Pagination {
+
+       var $base_url                   = ''; // The page we are linking to
+       var $total_rows                 = ''; // Total number of items (database results)
+       var $per_page                   = 10; // Max number of items you want shown per page
+       var $num_links                  =  2; // Number of "digit" links to show before/after the currently viewed page
+       var $cur_page                   =  0; // The current page being viewed
+       var $first_link                 = '&lsaquo; First';
+       var $next_link                  = '&gt;';
+       var $prev_link                  = '&lt;';
+       var $last_link                  = 'Last &rsaquo;';
+       var $uri_segment                = 3;
+       var $full_tag_open              = '';
+       var $full_tag_close             = '';
+       var $first_tag_open             = '';
+       var $first_tag_close    = '&nbsp;';
+       var $last_tag_open              = '&nbsp;';
+       var $last_tag_close             = '';
+       var $cur_tag_open               = '&nbsp;<b>';
+       var $cur_tag_close              = '</b>';
+       var $next_tag_open              = '&nbsp;';
+       var $next_tag_close             = '&nbsp;';
+       var $prev_tag_open              = '&nbsp;';
+       var $prev_tag_close             = '';
+       var $num_tag_open               = '&nbsp;';
+       var $num_tag_close              = '';
+       var $page_query_string  = FALSE;
+       var $query_string_segment = 'per_page';
+
+       /**
+        * Constructor
+        *
+        * @access      public
+        * @param       array   initialization parameters
+        */
+       function CI_Pagination($params = array())
+       {
+               if (count($params) > 0)
+               {
+                       $this->initialize($params);             
+               }
+               
+               log_message('debug', "Pagination Class Initialized");
+       }
+       
+       // --------------------------------------------------------------------
+       
+       /**
+        * Initialize Preferences
+        *
+        * @access      public
+        * @param       array   initialization parameters
+        * @return      void
+        */
+       function initialize($params = array())
+       {
+               if (count($params) > 0)
+               {
+                       foreach ($params as $key => $val)
+                       {
+                               if (isset($this->$key))
+                               {
+                                       $this->$key = $val;
+                               }
+                       }
+               }
+       }
+       
+       // --------------------------------------------------------------------
+       
+       /**
+        * Generate the pagination links
+        *
+        * @access      public
+        * @return      string
+        */     
+       function create_links()
+       {
+               // If our item count or per-page total is zero there is no need to continue.
+               if ($this->total_rows == 0 OR $this->per_page == 0)
+               {
+                  return '';
+               }
+
+               // Calculate the total number of pages
+               $num_pages = ceil($this->total_rows / $this->per_page);
+
+               // Is there only one page? Hm... nothing more to do here then.
+               if ($num_pages == 1)
+               {
+                       return '';
+               }
+
+               // Determine the current page number.           
+               $CI =& get_instance();
+               
+               if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
+               {
+                       if ($CI->input->get($this->query_string_segment) != 0)
+                       {
+                               $this->cur_page = $CI->input->get($this->query_string_segment);
+                               
+                               // Prep the current page - no funny business!
+                               $this->cur_page = (int) $this->cur_page;
+                       }
+               }
+               else
+               {
+                       if ($CI->uri->segment($this->uri_segment) != 0)
+                       {
+                               $this->cur_page = $CI->uri->segment($this->uri_segment);
+                               
+                               // Prep the current page - no funny business!
+                               $this->cur_page = (int) $this->cur_page;
+                       }
+               }
+
+               $this->num_links = (int)$this->num_links;
+               
+               if ($this->num_links < 1)
+               {
+                       show_error('Your number of links must be a positive number.');
+               }
+                               
+               if ( ! is_numeric($this->cur_page))
+               {
+                       $this->cur_page = 0;
+               }
+               
+               // Is the page number beyond the result range?
+               // If so we show the last page
+               if ($this->cur_page > $this->total_rows)
+               {
+                       $this->cur_page = ($num_pages - 1) * $this->per_page;
+               }
+               
+               $uri_page_number = $this->cur_page;
+               $this->cur_page = floor(($this->cur_page/$this->per_page) + 1);
+
+               // Calculate the start and end numbers. These determine
+               // which number to start and end the digit links with
+               $start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1;
+               $end   = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages;
+
+               // Is pagination being used over GET or POST?  If get, add a per_page query
+               // string. If post, add a trailing slash to the base URL if needed
+               if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
+               {
+                       $this->base_url = rtrim($this->base_url).'&amp;'.$this->query_string_segment.'=';
+               }
+               else
+               {
+                       $this->base_url = rtrim($this->base_url, '/') .'/';
+               }
+
+               // And here we go...
+               $output = '';
+
+               // Render the "First" link
+               if  ($this->cur_page > ($this->num_links + 1))
+               {
+                       $output .= $this->first_tag_open.'<a href="'.$this->base_url.'">'.$this->first_link.'</a>'.$this->first_tag_close;
+               }
+
+               // Render the "previous" link
+               if  ($this->cur_page != 1)
+               {
+                       $i = $uri_page_number - $this->per_page;
+                       if ($i == 0) $i = '';
+                       $output .= $this->prev_tag_open.'<a href="'.$this->base_url.$i.'">'.$this->prev_link.'</a>'.$this->prev_tag_close;
+               }
+
+               // Write the digit links
+               for ($loop = $start -1; $loop <= $end; $loop++)
+               {
+                       $i = ($loop * $this->per_page) - $this->per_page;
+                                       
+                       if ($i >= 0)
+                       {
+                               if ($this->cur_page == $loop)
+                               {
+                                       $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page
+                               }
+                               else
+                               {
+                                       $n = ($i == 0) ? '' : $i;
+                                       $output .= $this->num_tag_open.'<a href="'.$this->base_url.$n.'">'.$loop.'</a>'.$this->num_tag_close;
+                               }
+                       }
+               }
+
+               // Render the "next" link
+               if ($this->cur_page < $num_pages)
+               {
+                       $output .= $this->next_tag_open.'<a href="'.$this->base_url.($this->cur_page * $this->per_page).'">'.$this->next_link.'</a>'.$this->next_tag_close;
+               }
+
+               // Render the "Last" link
+               if (($this->cur_page + $this->num_links) < $num_pages)
+               {
+                       $i = (($num_pages * $this->per_page) - $this->per_page);
+                       $output .= $this->last_tag_open.'<a href="'.$this->base_url.$i.'">'.$this->last_link.'</a>'.$this->last_tag_close;
+               }
+
+               // Kill double slashes.  Note: Sometimes we can end up with a double slash
+               // in the penultimate link so we'll kill all double slashes.
+               $output = preg_replace("#([^:])//+#", "\\1/", $output);
+
+               // Add the wrapper HTML if exists
+               $output = $this->full_tag_open.$output.$this->full_tag_close;
+               
+               return $output;         
+       }
+}
+// END Pagination Class
+
+/* End of file Pagination.php */
 /* Location: ./system/libraries/Pagination.php */
\ No newline at end of file