From ed8bf452061ed121fbd2407fda65f6b7e8c082e7 Mon Sep 17 00:00:00 2001 From: Nikita Date: Tue, 14 Feb 2012 18:40:20 +0700 Subject: [PATCH 1/5] fix 3.2 config --- classes/captcha.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/classes/captcha.php b/classes/captcha.php index 3e83160..137c169 100644 --- a/classes/captcha.php +++ b/classes/captcha.php @@ -61,7 +61,7 @@ public static function instance($group = 'default') if ( ! isset(Captcha::$instance)) { // Load the configuration for this group - $config = Kohana::config('captcha')->get($group); + $config = Kohana::$config->load('captcha')->get($group); // Set the captcha driver class name $class = 'Captcha_'.ucfirst($config['style']); @@ -95,7 +95,7 @@ public function __construct($group = NULL) } // Load and validate config group - if ( ! is_array($config = Kohana::config('captcha')->get($group))) + if ( ! is_array($config = Kohana::$config->load('captcha')->get($group))) throw new Kohana_Exception('Captcha group not defined in :group configuration', array(':group' => $group)); @@ -103,7 +103,7 @@ public function __construct($group = NULL) if ($group !== 'default') { // Load and validate default config group - if ( ! is_array($default = Kohana::config('captcha')->get('default'))) + if ( ! is_array($default = Kohana::$config->load('captcha')->get('default'))) throw new Kohana_Exception('Captcha group not defined in :group configuration', array(':group' => 'default')); From ffb22c03b7783b097c72001b23fe53f7feed49cb Mon Sep 17 00:00:00 2001 From: Nikita Date: Tue, 14 Feb 2012 18:46:59 +0700 Subject: [PATCH 2/5] fix 3.2 Request --- classes/captcha.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/classes/captcha.php b/classes/captcha.php index 137c169..7ef65be 100644 --- a/classes/captcha.php +++ b/classes/captcha.php @@ -434,10 +434,11 @@ public function image_render($html) return 'Captcha'; // Send the correct HTTP header - Request::instance()->headers['Content-Type'] = 'image/'.$this->image_type; - Request::instance()->headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'; - Request::instance()->headers['Pragma'] = 'no-cache'; - Request::instance()->headers['Connection'] = 'close'; + + Request::initial()->headers['Content-Type'] = 'image/'.$this->image_type; + Request::initial()->headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'; + Request::initial()->headers['Pragma'] = 'no-cache'; + Request::initial()->headers['Connection'] = 'close'; // Pick the correct output function $function = 'image'.$this->image_type; From 8412017ad8d17c83d4007f62e66c7110222e7a87 Mon Sep 17 00:00:00 2001 From: Nikita Date: Tue, 14 Feb 2012 19:02:07 +0700 Subject: [PATCH 3/5] fix 3.2 Request and Config --- classes/captcha.php | 49 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/classes/captcha.php b/classes/captcha.php index 7ef65be..d0e6851 100644 --- a/classes/captcha.php +++ b/classes/captcha.php @@ -61,7 +61,7 @@ public static function instance($group = 'default') if ( ! isset(Captcha::$instance)) { // Load the configuration for this group - $config = Kohana::$config->load('captcha')->get($group); + $config = self::_get_config($group); // Set the captcha driver class name $class = 'Captcha_'.ucfirst($config['style']); @@ -95,7 +95,7 @@ public function __construct($group = NULL) } // Load and validate config group - if ( ! is_array($config = Kohana::$config->load('captcha')->get($group))) + if ( ! is_array($config = self::_get_config($group))) throw new Kohana_Exception('Captcha group not defined in :group configuration', array(':group' => $group)); @@ -103,7 +103,7 @@ public function __construct($group = NULL) if ($group !== 'default') { // Load and validate default config group - if ( ! is_array($default = Kohana::$config->load('captcha')->get('default'))) + if ( ! is_array($default = self::_get_config())) throw new Kohana_Exception('Captcha group not defined in :group configuration', array(':group' => 'default')); @@ -434,11 +434,10 @@ public function image_render($html) return 'Captcha'; // Send the correct HTTP header - - Request::initial()->headers['Content-Type'] = 'image/'.$this->image_type; - Request::initial()->headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'; - Request::initial()->headers['Pragma'] = 'no-cache'; - Request::initial()->headers['Connection'] = 'close'; + $this->_get_request()->headers['Content-Type'] = 'image/'.$this->image_type; + $this->_get_request()->headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'; + $this->_get_request()->headers['Pragma'] = 'no-cache'; + $this->_get_request()->headers['Connection'] = 'close'; // Pick the correct output function $function = 'image'.$this->image_type; @@ -448,6 +447,40 @@ public function image_render($html) imagedestroy($this->image); } + /** + * Return multiversional config + * @param string $group + * @return Array + */ + protected static function _get_config($group = 'default') { + + $version = Kohana_Core::VERSION; + + if($version == '3.2.0') { + $config = Kohana::$config->load('captcha')->get($group); + } else { + $config = Kohana::config('captcha')->get($group); + } + + return $config; + } + + /** + * Return multiversional request + * @return Request + */ + protected function _get_request() { + + $version = Kohana_Core::VERSION; + + if($version == '3.2.0') { + $request = Request::initial(); + } else { + $request = Request::instance(); + } + + return $request; + } /* DRIVER METHODS */ /** From 0aef78c9f6df9200d1ff489c41beb64a0e5b6b0d Mon Sep 17 00:00:00 2001 From: Nikita Date: Thu, 23 Feb 2012 17:23:57 +0700 Subject: [PATCH 4/5] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1cb921c..705400d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -#Captcha for Kohana 3.x +#Captcha for Kohana 3.2 -This is the Captcha library ported from Kohana 2.3.x to 3.x. Very little has changed API-wise, although there have been a few changes. +This is the Captcha library ported from Kohana 3.0.x to 3.2. Very little has changed API-wise, although there have been a few changes. ##Getting Started From 7e200c1de77686e4a09c9f5010b4ff1dac853ef6 Mon Sep 17 00:00:00 2001 From: YK Date: Fri, 30 Mar 2012 08:55:15 -0300 Subject: [PATCH 5/5] Changes required for me to get it to work in Kohana 3.2 (and master from GitHub) --- classes/captcha.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/classes/captcha.php b/classes/captcha.php index d0e6851..10bce13 100644 --- a/classes/captcha.php +++ b/classes/captcha.php @@ -434,10 +434,10 @@ public function image_render($html) return 'Captcha'; // Send the correct HTTP header - $this->_get_request()->headers['Content-Type'] = 'image/'.$this->image_type; - $this->_get_request()->headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'; - $this->_get_request()->headers['Pragma'] = 'no-cache'; - $this->_get_request()->headers['Connection'] = 'close'; + $this->_get_request()->response()->headers('Content-Type', 'image/'.$this->image_type); + $this->_get_request()->response()->headers('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); + $this->_get_request()->response()->headers('Pragma', 'no-cache'); + $this->_get_request()->response()->headers('Connection', 'close'); // Pick the correct output function $function = 'image'.$this->image_type;