From 9b6663f87a7e679ffba691cf516191fc840cf978 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 24 Nov 2009 19:20:36 -0800 Subject: Update to Kohana r4684 which is now Kohana 2.4 and has substantial changes. --- application/Bootstrap.php | 59 +++++++++++++++++++++++++++++++++++++++++++ application/config/config.php | 6 +++++ 2 files changed, 65 insertions(+) create mode 100644 application/Bootstrap.php (limited to 'application') diff --git a/application/Bootstrap.php b/application/Bootstrap.php new file mode 100644 index 00000000..b15cbfce --- /dev/null +++ b/application/Bootstrap.php @@ -0,0 +1,59 @@ + Date: Thu, 26 Nov 2009 14:38:01 -0800 Subject: Add kohana23_compat module to bring along functionality that got deleted, but we still want. Start off with the Pagination library. --- application/config/config.php | 1 + modules/kohana23_compat/config/pagination.php | 25 +++ modules/kohana23_compat/libraries/Pagination.php | 234 +++++++++++++++++++++++ 3 files changed, 260 insertions(+) create mode 100644 modules/kohana23_compat/config/pagination.php create mode 100644 modules/kohana23_compat/libraries/Pagination.php (limited to 'application') diff --git a/application/config/config.php b/application/config/config.php index ad485266..aecc400c 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -142,6 +142,7 @@ $config['config_drivers'] = array(); */ $config["modules"] = array( MODPATH . "forge", + MODPATH . "kohana23_compat", MODPATH . "gallery", // gallery must be *last* in the order ); diff --git a/modules/kohana23_compat/config/pagination.php b/modules/kohana23_compat/config/pagination.php new file mode 100644 index 00000000..808fc315 --- /dev/null +++ b/modules/kohana23_compat/config/pagination.php @@ -0,0 +1,25 @@ + 'pagination', + 'style' => 'classic', + 'uri_segment' => 3, + 'query_string' => '', + 'items_per_page' => 20, + 'auto_hide' => FALSE, +); diff --git a/modules/kohana23_compat/libraries/Pagination.php b/modules/kohana23_compat/libraries/Pagination.php new file mode 100644 index 00000000..8ff8bf94 --- /dev/null +++ b/modules/kohana23_compat/libraries/Pagination.php @@ -0,0 +1,234 @@ +initialize($config); + } + + /** + * Sets config values. + * + * @throws Kohana_Exception + * @param array configuration settings + * @return void + */ + public function initialize($config = array()) + { + // Load config group + if (isset($config['group'])) + { + // Load and validate config group + if ( ! is_array($group_config = Kohana::config('pagination.'.$config['group']))) + throw new Kohana_Exception('pagination.undefined_group: ' . $config['group']); + + // All pagination config groups inherit default config group + if ($config['group'] !== 'default') + { + // Load and validate default config group + if ( ! is_array($default_config = Kohana::config('pagination.default'))) + throw new Kohana_Exception('pagination.undefined_group: default'); + + // Merge config group with default config group + $group_config += $default_config; + } + + // Merge custom config items with config group + $config += $group_config; + } + + // Assign config values to the object + foreach ($config as $key => $value) + { + if (property_exists($this, $key)) + { + $this->$key = $value; + } + } + + // Clean view directory + $this->directory = trim($this->directory, '/').'/'; + + // Build generic URL with page in query string + if ($this->query_string !== '') + { + // Extract current page + $this->current_page = isset($_GET[$this->query_string]) ? (int) $_GET[$this->query_string] : 1; + + // Insert {page} placeholder + $_GET[$this->query_string] = '{page}'; + + // Create full URL + $base_url = ($this->base_url === '') ? Router::$current_uri : $this->base_url; + $this->url = url::site($base_url).'?'.str_replace('%7Bpage%7D', '{page}', http_build_query($_GET)); + + // Reset page number + $_GET[$this->query_string] = $this->current_page; + } + + // Build generic URL with page as URI segment + else + { + // Use current URI if no base_url set + $this->url = ($this->base_url === '') ? Router::$segments : explode('/', trim($this->base_url, '/')); + + // Convert uri 'label' to corresponding integer if needed + if (is_string($this->uri_segment)) + { + if (($key = array_search($this->uri_segment, $this->url)) === FALSE) + { + // If uri 'label' is not found, auto add it to base_url + $this->url[] = $this->uri_segment; + $this->uri_segment = count($this->url) + 1; + } + else + { + $this->uri_segment = $key + 2; + } + } + + // Insert {page} placeholder + $this->url[$this->uri_segment - 1] = '{page}'; + + // Create full URL + $this->url = url::site(implode('/', $this->url)).Router::$query_string; + + // Extract current page + $this->current_page = URI::instance()->segment($this->uri_segment); + } + + // Core pagination values + $this->total_items = (int) max(0, $this->total_items); + $this->items_per_page = (int) max(1, $this->items_per_page); + $this->total_pages = (int) ceil($this->total_items / $this->items_per_page); + $this->current_page = (int) min(max(1, $this->current_page), max(1, $this->total_pages)); + $this->current_first_item = (int) min((($this->current_page - 1) * $this->items_per_page) + 1, $this->total_items); + $this->current_last_item = (int) min($this->current_first_item + $this->items_per_page - 1, $this->total_items); + + // If there is no first/last/previous/next page, relative to the + // current page, value is set to FALSE. Valid page number otherwise. + $this->first_page = ($this->current_page === 1) ? FALSE : 1; + $this->last_page = ($this->current_page >= $this->total_pages) ? FALSE : $this->total_pages; + $this->previous_page = ($this->current_page > 1) ? $this->current_page - 1 : FALSE; + $this->next_page = ($this->current_page < $this->total_pages) ? $this->current_page + 1 : FALSE; + + // SQL values + $this->sql_offset = (int) ($this->current_page - 1) * $this->items_per_page; + $this->sql_limit = sprintf(' LIMIT %d OFFSET %d ', $this->items_per_page, $this->sql_offset); + } + + /** + * Generates the HTML for the chosen pagination style. + * + * @param string pagination style + * @return string pagination html + */ + public function render($style = NULL) + { + // Hide single page pagination + if ($this->auto_hide === TRUE AND $this->total_pages <= 1) + return ''; + + if ($style === NULL) + { + // Use default style + $style = $this->style; + } + + // Return rendered pagination view + return View::factory($this->directory.$style, get_object_vars($this))->render(); + } + + /** + * Magically converts Pagination object to string. + * + * @return string pagination html + */ + public function __toString() + { + return $this->render(); + } + + /** + * Magically gets a pagination variable. + * + * @param string variable key + * @return mixed variable value if the key is found + * @return void if the key is not found + */ + public function __get($key) + { + if (isset($this->$key)) + return $this->$key; + } + + /** + * Adds a secondary interface for accessing properties, e.g. $pagination->total_pages(). + * Note that $pagination->total_pages is the recommended way to access properties. + * + * @param string function name + * @return string + */ + public function __call($func, $args = NULL) + { + return $this->__get($func); + } + +} // End Pagination Class \ No newline at end of file -- cgit v1.2.3 From 2be72bb1c3c5790e0ce68c2609de141bf9756614 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Dec 2009 20:42:38 -0800 Subject: Overload Kohana_Exception::text() to dump out the complete stack trace so that we have useful data in the logs. --- application/Bootstrap.php | 2 +- modules/gallery/libraries/MY_Kohana_Exception.php | 29 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 modules/gallery/libraries/MY_Kohana_Exception.php (limited to 'application') diff --git a/application/Bootstrap.php b/application/Bootstrap.php index b15cbfce..f36fac14 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -30,7 +30,7 @@ require SYSPATH.'core/Kohana'.EXT; final class Kohana extends Kohana_Core {} require SYSPATH.'core/Kohana_Exception'.EXT; -class Kohana_Exception extends Kohana_Exception_Core {} +require MODPATH.'gallery/libraries/MY_Kohana_Exception'.EXT; require SYSPATH.'core/Kohana_Config'.EXT; require SYSPATH.'libraries/drivers/Config'.EXT; diff --git a/modules/gallery/libraries/MY_Kohana_Exception.php b/modules/gallery/libraries/MY_Kohana_Exception.php new file mode 100644 index 00000000..32b4ab93 --- /dev/null +++ b/modules/gallery/libraries/MY_Kohana_Exception.php @@ -0,0 +1,29 @@ +getCode(), strip_tags($e->getMessage()), $e->getTraceAsString()); + } +} \ No newline at end of file -- cgit v1.2.3 From 9c5df1d31bd214fab051b71d092c751a1da20ecc Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 19:59:44 -0800 Subject: Fix preambles, and fix the File_Structure_Test to be more lenient because of preamble variation in K24. --- application/Bootstrap.php | 22 +++++++++---- modules/gallery/config/log_file.php | 20 ++++++++++- modules/gallery/tests/File_Structure_Test.php | 16 ++++++--- modules/kohana23_compat/config/pagination.php | 42 +++++++++++++----------- modules/kohana23_compat/libraries/Pagination.php | 20 ++++++++++- 5 files changed, 87 insertions(+), 33 deletions(-) (limited to 'application') diff --git a/application/Bootstrap.php b/application/Bootstrap.php index f36fac14..95f7b8d2 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -1,13 +1,21 @@ -\n"; + $expected_2 = " 'pagination', - 'style' => 'classic', - 'uri_segment' => 3, - 'query_string' => '', - 'items_per_page' => 20, - 'auto_hide' => FALSE, +$config["default"] = array( + "directory" => "pagination", + "style" => "classic", + "uri_segment" => 3, + "query_string" => "", + "items_per_page" => 20, + "auto_hide" => FALSE ); diff --git a/modules/kohana23_compat/libraries/Pagination.php b/modules/kohana23_compat/libraries/Pagination.php index 8ff8bf94..012bc484 100644 --- a/modules/kohana23_compat/libraries/Pagination.php +++ b/modules/kohana23_compat/libraries/Pagination.php @@ -1,4 +1,22 @@ -