From 11c5f1654d2d13113ad06da46f560628d7e31dd3 Mon Sep 17 00:00:00 2001 From: Aaron Kuzemchak Date: Sat, 3 Sep 2011 20:59:07 -0400 Subject: Enables real page numbers for URI segment in Pagination library --- system/libraries/Pagination.php | 85 +++++++++++++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 12 deletions(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index cc62e660b..cdaacf2d4 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -34,6 +34,7 @@ class CI_Pagination { 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 $use_page_numbers = FALSE; // Use page number for segment instead of offset var $first_link = '‹ First'; var $next_link = '>'; var $prev_link = '<'; @@ -128,12 +129,22 @@ class CI_Pagination { return ''; } + // Set the base page index for starting page number + if ($this->use_page_numbers) + { + $base_page = 1; + } + else + { + $base_page = 0; + } + // 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) + if ($CI->input->get($this->query_string_segment) != $base_page) { $this->cur_page = $CI->input->get($this->query_string_segment); @@ -143,7 +154,7 @@ class CI_Pagination { } else { - if ($CI->uri->segment($this->uri_segment) != 0) + if ($CI->uri->segment($this->uri_segment) != $base_page) { $this->cur_page = $CI->uri->segment($this->uri_segment); @@ -151,6 +162,12 @@ class CI_Pagination { $this->cur_page = (int) $this->cur_page; } } + + // Set current page to 1 if using page numbers instead of offset + if ($this->use_page_numbers AND $this->cur_page == 0) + { + $this->cur_page = $base_page; + } $this->num_links = (int)$this->num_links; @@ -161,18 +178,32 @@ class CI_Pagination { if ( ! is_numeric($this->cur_page)) { - $this->cur_page = 0; + $this->cur_page = $base_page; } // Is the page number beyond the result range? // If so we show the last page - if ($this->cur_page > $this->total_rows) + if ($this->use_page_numbers) { - $this->cur_page = ($num_pages - 1) * $this->per_page; + if ($this->cur_page > $num_pages) + { + $this->cur_page = $num_pages; + } + } + else + { + 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); + + if ( ! $this->use_page_numbers) + { + $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 @@ -203,7 +234,14 @@ class CI_Pagination { // Render the "previous" link if ($this->prev_link !== FALSE AND $this->cur_page != 1) { - $i = $uri_page_number - $this->per_page; + if ($this->use_page_numbers) + { + $i = $uri_page_number - 1; + } + else + { + $i = $uri_page_number - $this->per_page; + } if ($i == 0 && $this->first_url != '') { @@ -223,9 +261,16 @@ class CI_Pagination { // Write the digit links for ($loop = $start -1; $loop <= $end; $loop++) { - $i = ($loop * $this->per_page) - $this->per_page; + if ($this->use_page_numbers) + { + $i = $loop; + } + else + { + $i = ($loop * $this->per_page) - $this->per_page; + } - if ($i >= 0) + if ($i >= $base_page) { if ($this->cur_page == $loop) { @@ -233,7 +278,7 @@ class CI_Pagination { } else { - $n = ($i == 0) ? '' : $i; + $n = ($i == $base_page) ? '' : $i; if ($n == '' && $this->first_url != '') { @@ -253,13 +298,29 @@ class CI_Pagination { // Render the "next" link if ($this->next_link !== FALSE AND $this->cur_page < $num_pages) { - $output .= $this->next_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.($this->cur_page * $this->per_page).$this->suffix.'">'.$this->next_link.''.$this->next_tag_close; + if ($this->use_page_numbers) + { + $i = $this->cur_page + 1; + } + else + { + $i = ($this->cur_page * $this->per_page); + } + + $output .= $this->next_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->next_link.''.$this->next_tag_close; } // Render the "Last" link if ($this->last_link !== FALSE AND ($this->cur_page + $this->num_links) < $num_pages) { - $i = (($num_pages * $this->per_page) - $this->per_page); + if ($this->use_page_numbers) + { + $i = $num_pages; + } + else + { + $i = (($num_pages * $this->per_page) - $this->per_page); + } $output .= $this->last_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->last_link.''.$this->last_tag_close; } -- cgit v1.2.3-24-g4f1b From a5e13f9bf78e0cf139b905d131075a146430ce0a Mon Sep 17 00:00:00 2001 From: Aaron Kuzemchak Date: Sun, 4 Sep 2011 16:39:47 -0400 Subject: utilizing ternary syntax to clean up some conditionals --- system/libraries/Pagination.php | 46 ++++++----------------------------------- 1 file changed, 6 insertions(+), 40 deletions(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index cdaacf2d4..f190d55fd 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -130,14 +130,7 @@ class CI_Pagination { } // Set the base page index for starting page number - if ($this->use_page_numbers) - { - $base_page = 1; - } - else - { - $base_page = 0; - } + $base_page = ($this->use_page_numbers) ? 1 : 0; // Determine the current page number. $CI =& get_instance(); @@ -234,14 +227,7 @@ class CI_Pagination { // Render the "previous" link if ($this->prev_link !== FALSE AND $this->cur_page != 1) { - if ($this->use_page_numbers) - { - $i = $uri_page_number - 1; - } - else - { - $i = $uri_page_number - $this->per_page; - } + $i = ($this->use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this->per_page; if ($i == 0 && $this->first_url != '') { @@ -261,14 +247,7 @@ class CI_Pagination { // Write the digit links for ($loop = $start -1; $loop <= $end; $loop++) { - if ($this->use_page_numbers) - { - $i = $loop; - } - else - { - $i = ($loop * $this->per_page) - $this->per_page; - } + $i = ($this->use_page_numbers) ? $loop : ($loop * $this->per_page) - $this->per_page; if ($i >= $base_page) { @@ -298,14 +277,7 @@ class CI_Pagination { // Render the "next" link if ($this->next_link !== FALSE AND $this->cur_page < $num_pages) { - if ($this->use_page_numbers) - { - $i = $this->cur_page + 1; - } - else - { - $i = ($this->cur_page * $this->per_page); - } + $i = ($this->use_page_numbers) ? $this->cur_page + 1 : $this->cur_page * $this->per_page; $output .= $this->next_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->next_link.''.$this->next_tag_close; } @@ -313,14 +285,8 @@ class CI_Pagination { // Render the "Last" link if ($this->last_link !== FALSE AND ($this->cur_page + $this->num_links) < $num_pages) { - if ($this->use_page_numbers) - { - $i = $num_pages; - } - else - { - $i = (($num_pages * $this->per_page) - $this->per_page); - } + $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; + $output .= $this->last_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->last_link.''.$this->last_tag_close; } -- cgit v1.2.3-24-g4f1b From 068e3dea797351448f743b1e3faac506bc0f6e2a Mon Sep 17 00:00:00 2001 From: narfbg Date: Sat, 17 Sep 2011 21:38:46 +0300 Subject: Fix ./system/database/drivers/oci8_driver.php to pass the configured database character set on connect. --- system/database/drivers/oci8/oci8_driver.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index d4adfd528..d4c27fa43 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -79,7 +79,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function db_connect() { - return @ocilogon($this->username, $this->password, $this->hostname); + return @ocilogon($this->username, $this->password, $this->hostname, $this->char_set); } // -------------------------------------------------------------------- @@ -92,7 +92,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function db_pconnect() { - return @ociplogon($this->username, $this->password, $this->hostname); + return @ociplogon($this->username, $this->password, $this->hostname, $this->char_set); } // -------------------------------------------------------------------- @@ -136,7 +136,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function db_set_charset($charset, $collation) { - // @todo - add support if needed + // this is done upon connect return TRUE; } -- cgit v1.2.3-24-g4f1b From 539dcb0b2968a2d83c16b42a20252011152f2e65 Mon Sep 17 00:00:00 2001 From: "Cloudmanic Labs, LLC" Date: Sun, 18 Sep 2011 12:08:56 -0700 Subject: Added support to select the name of the database table you are going to use in Migrations --- system/libraries/Migration.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 3734e18f5..682d90752 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -32,7 +32,8 @@ class CI_Migration { protected $_migration_enabled = FALSE; protected $_migration_path = NULL; protected $_migration_version = 0; - + protected $_migration_table = 'migrations'; + protected $_error_string = ''; public function __construct($config = array()) @@ -68,16 +69,22 @@ class CI_Migration { // They'll probably be using dbforge $this->load->dbforge(); + // Make sure the migration table name was set. + if ( (! isset($this->_migration_table)) OR (empty($this->_migration_table))) + { + show_error('Migrations configuration file (migration.php) must have "migration_table" set.'); + } + // If the migrations table is missing, make it - if ( ! $this->db->table_exists('migrations')) + if ( ! $this->db->table_exists($this->_migration_table)) { $this->dbforge->add_field(array( 'version' => array('type' => 'INT', 'constraint' => 3), )); - $this->dbforge->create_table('migrations', TRUE); + $this->dbforge->create_table($this->_migration_table, TRUE); - $this->db->insert('migrations', array('version' => 0)); + $this->db->insert($this->_migration_table, array('version' => 0)); } } @@ -299,7 +306,7 @@ class CI_Migration { */ protected function _get_version() { - $row = $this->db->get('migrations')->row(); + $row = $this->db->get($this->_migration_table)->row(); return $row ? $row->version : 0; } @@ -314,7 +321,7 @@ class CI_Migration { */ protected function _update_version($migrations) { - return $this->db->update('migrations', array( + return $this->db->update($this->_migration_table, array( 'version' => $migrations )); } -- cgit v1.2.3-24-g4f1b From d1ba8f790eb91deb2898ff19d7827ce86e40ee7c Mon Sep 17 00:00:00 2001 From: "Cloudmanic Labs, LLC" Date: Sun, 18 Sep 2011 12:23:00 -0700 Subject: Migrations: Added a config that allows the system to migration to the latest migration when you load the library. This way you do not have to call migrations anywhere else in your code and can always be at the latest migration --- system/libraries/Migration.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'system') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 682d90752..28b1dd69f 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -33,6 +33,7 @@ class CI_Migration { protected $_migration_path = NULL; protected $_migration_version = 0; protected $_migration_table = 'migrations'; + protected $_migration_auto_latest = FALSE; protected $_error_string = ''; @@ -86,6 +87,15 @@ class CI_Migration { $this->db->insert($this->_migration_table, array('version' => 0)); } + + // Do we auto migrate to the latest migration? + if ( $this->_migration_auto_latest == TRUE ) + { + if ( ! $this->latest() ) + { + show_error($this->error_string()); + } + } } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 63b61e3bedd2a5729bef15b79ea64fa0a9d54893 Mon Sep 17 00:00:00 2001 From: "Cloudmanic Labs, LLC" Date: Mon, 19 Sep 2011 09:35:05 -0700 Subject: Fixed style guide suggestion from philsturgeon on code review --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 28b1dd69f..840cefe08 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -71,7 +71,7 @@ class CI_Migration { $this->load->dbforge(); // Make sure the migration table name was set. - if ( (! isset($this->_migration_table)) OR (empty($this->_migration_table))) + if (empty($this->_migration_table)) { show_error('Migrations configuration file (migration.php) must have "migration_table" set.'); } -- cgit v1.2.3-24-g4f1b From ef3e2402b22a7687730520971c27bec466b5167d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 21 Sep 2011 14:39:29 +0300 Subject: Fix issue #182 in system/database/drivers/oci8_result.php by caching the num_rows property after statement execution --- system/database/drivers/oci8/oci8_result.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 88531b436..2713f6f12 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -42,15 +42,18 @@ class CI_DB_oci8_result extends CI_DB_result { */ function num_rows() { - $rowcount = count($this->result_array()); - @ociexecute($this->stmt_id); - - if ($this->curs_id) + if ($this->num_rows === 0 && count($this->result_array()) > 0) { - @ociexecute($this->curs_id); + $this->num_rows = count($this->result_array()); + @ociexecute($this->stmt_id); + + if ($this->curs_id) + { + @ociexecute($this->curs_id); + } } - return $rowcount; + return $this->num_rows; } // -------------------------------------------------------------------- @@ -246,4 +249,4 @@ class CI_DB_oci8_result extends CI_DB_result { /* End of file oci8_result.php */ -/* Location: ./system/database/drivers/oci8/oci8_result.php */ \ No newline at end of file +/* Location: ./system/database/drivers/oci8/oci8_result.php */ -- cgit v1.2.3-24-g4f1b From 48b2301d7e8cc2a4cb164a4bc24c59b656f4f49b Mon Sep 17 00:00:00 2001 From: garthkerr Date: Wed, 21 Sep 2011 20:52:50 -0300 Subject: Added a condition so that the previous link respects use_page_numbers configuration. --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index f190d55fd..eff754a1b 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -229,7 +229,7 @@ class CI_Pagination { { $i = ($this->use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this->per_page; - if ($i == 0 && $this->first_url != '') + if (($i == 0 OR ($this->use_page_numbers && $i == 1)) AND $this->first_url != '') { $output .= $this->prev_tag_open.'anchor_class.'href="'.$this->first_url.'">'.$this->prev_link.''.$this->prev_tag_close; } -- cgit v1.2.3-24-g4f1b From 99c6dd49e61c463499d1e50945ac29a3f383ec48 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 23 Sep 2011 03:07:01 +0300 Subject: Add ->db->insert_batch() support to the OCI8 (Oracle) driver --- system/database/drivers/oci8/oci8_driver.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index d4c27fa43..33991ab53 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -642,6 +642,32 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Insert_batch statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert_batch($table, $keys, $values) + { + $keys = implode(', ', $keys); + $sql = "INSERT ALL\n"; + + for ($i = 0, $c = count($values); $i < $c; $i++) + $sql .= ' INTO ' . $table . ' (' . $keys . ') VALUES ' . $values[$i] . "\n"; + + $sql .= 'SELECT * FROM dual'; + + return $sql; + } + + // -------------------------------------------------------------------- + /** * Update statement * @@ -776,4 +802,4 @@ class CI_DB_oci8_driver extends CI_DB { /* End of file oci8_driver.php */ -/* Location: ./system/database/drivers/oci8/oci8_driver.php */ \ No newline at end of file +/* Location: ./system/database/drivers/oci8/oci8_driver.php */ -- cgit v1.2.3-24-g4f1b From b83c4088829207af39e862d6252eff393bc71642 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 23 Sep 2011 03:32:45 +0300 Subject: Add brackets to the for() loop --- system/database/drivers/oci8/oci8_driver.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 33991ab53..1cf063ec1 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -659,7 +659,9 @@ class CI_DB_oci8_driver extends CI_DB { $sql = "INSERT ALL\n"; for ($i = 0, $c = count($values); $i < $c; $i++) + { $sql .= ' INTO ' . $table . ' (' . $keys . ') VALUES ' . $values[$i] . "\n"; + } $sql .= 'SELECT * FROM dual'; -- cgit v1.2.3-24-g4f1b From e378a39304723d77f1a3a378706d2a20b83f8e28 Mon Sep 17 00:00:00 2001 From: Rommel Castro A Date: Thu, 22 Sep 2011 18:52:25 -0600 Subject: fixed issue #192 --- system/core/Security.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system') diff --git a/system/core/Security.php b/system/core/Security.php index e99418bdd..6c4c59057 100755 --- a/system/core/Security.php +++ b/system/core/Security.php @@ -169,6 +169,7 @@ class CI_Security { // Nothing should last forever unset($_COOKIE[$this->_csrf_cookie_name]); + $this->_csrf_hash = ''; $this->_csrf_set_hash(); $this->csrf_set_cookie(); -- cgit v1.2.3-24-g4f1b