Skip to content
This repository has been archived by the owner on Apr 1, 2019. It is now read-only.

Support of Kohana 3.2 #20

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
48 changes: 41 additions & 7 deletions classes/captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = self::_get_config($group);

// Set the captcha driver class name
$class = 'Captcha_'.ucfirst($config['style']);
Expand Down Expand Up @@ -95,15 +95,15 @@ public function __construct($group = NULL)
}

// Load and validate config group
if ( ! is_array($config = Kohana::config('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));

// All captcha config groups inherit default config group
if ($group !== 'default')
{
// Load and validate default config group
if ( ! is_array($default = Kohana::config('captcha')->get('default')))
if ( ! is_array($default = self::_get_config()))
throw new Kohana_Exception('Captcha group not defined in :group configuration',
array(':group' => 'default'));

Expand Down Expand Up @@ -434,10 +434,10 @@ public function image_render($html)
return '<img src="'.url::site('captcha/'.Captcha::$config['group']).'" width="'.Captcha::$config['width'].'" height="'.Captcha::$config['height'].'" alt="Captcha" class="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';
$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;
Expand All @@ -447,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 */

/**
Expand Down