summaryrefslogtreecommitdiffstats
path: root/system/helpers/captcha_helper.php
diff options
context:
space:
mode:
authorPascal Kriete <pascal.kriete@ellislab.com>2010-11-04 22:59:52 +0100
committerPascal Kriete <pascal.kriete@ellislab.com>2010-11-04 22:59:52 +0100
commite917f9be8b05c81357c1c2c9730d5060685d644d (patch)
treeb6a7d5ce8ba57b69ba61454f77829b04f2ce5974 /system/helpers/captcha_helper.php
parent5b2d2da5ae2e97043c6bef53e565d30e50196e2b (diff)
parente1f6e9ddff788f6a154f5f35dc117d14aeb0c484 (diff)
Automated merge with http://hg.ellislab.com/CodeIgniter2
Diffstat (limited to 'system/helpers/captcha_helper.php')
-rw-r--r--system/helpers/captcha_helper.php74
1 files changed, 37 insertions, 37 deletions
diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php
index 67db50947..3c80bb756 100644
--- a/system/helpers/captcha_helper.php
+++ b/system/helpers/captcha_helper.php
@@ -40,9 +40,9 @@
if ( ! function_exists('create_captcha'))
{
function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = '')
- {
- $defaults = array('word' => '', 'img_path' => '', 'img_url' => '', 'img_width' => '150', 'img_height' => '30', 'font_path' => '', 'expiration' => 7200);
-
+ {
+ $defaults = array('word' => '', 'img_path' => '', 'img_url' => '', 'img_width' => '150', 'img_height' => '30', 'font_path' => '', 'expiration' => 7200);
+
foreach ($defaults as $key => $val)
{
if ( ! is_array($data))
@@ -53,11 +53,11 @@ if ( ! function_exists('create_captcha'))
}
}
else
- {
+ {
$$key = ( ! isset($data[$key])) ? $val : $data[$key];
}
}
-
+
if ($img_path == '' OR $img_url == '')
{
return FALSE;
@@ -67,45 +67,45 @@ if ( ! function_exists('create_captcha'))
{
return FALSE;
}
-
+
if ( ! is_writable($img_path))
{
return FALSE;
}
-
+
if ( ! extension_loaded('gd'))
{
return FALSE;
- }
-
+ }
+
// -----------------------------------
- // Remove old images
+ // Remove old images
// -----------------------------------
-
+
list($usec, $sec) = explode(" ", microtime());
$now = ((float)$usec + (float)$sec);
-
+
$current_dir = @opendir($img_path);
-
+
while($filename = @readdir($current_dir))
{
if ($filename != "." and $filename != ".." and $filename != "index.html")
{
$name = str_replace(".jpg", "", $filename);
-
+
if (($name + $expiration) < $now)
{
@unlink($img_path.$filename);
}
}
}
-
+
@closedir($current_dir);
// -----------------------------------
// Do we have a "word" yet?
// -----------------------------------
-
+
if ($word == '')
{
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
@@ -115,23 +115,23 @@ if ( ! function_exists('create_captcha'))
{
$str .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
}
-
+
$word = $str;
}
-
+
// -----------------------------------
- // Determine angle and position
+ // Determine angle and position
// -----------------------------------
-
+
$length = strlen($word);
$angle = ($length >= 6) ? rand(-($length-6), ($length-6)) : 0;
- $x_axis = rand(6, (360/$length)-16);
+ $x_axis = rand(6, (360/$length)-16);
$y_axis = ($angle >= 0 ) ? rand($img_height, $img_width) : rand(6, $img_height);
-
+
// -----------------------------------
// Create image
// -----------------------------------
-
+
// PHP.net recommends imagecreatetruecolor(), but it isn't always available
if (function_exists('imagecreatetruecolor'))
{
@@ -141,11 +141,11 @@ if ( ! function_exists('create_captcha'))
{
$im = imagecreate($img_width, $img_height);
}
-
+
// -----------------------------------
// Assign colors
// -----------------------------------
-
+
$bg_color = imagecolorallocate ($im, 255, 255, 255);
$border_color = imagecolorallocate ($im, 153, 102, 102);
$text_color = imagecolorallocate ($im, 204, 153, 153);
@@ -155,13 +155,13 @@ if ( ! function_exists('create_captcha'))
// -----------------------------------
// Create the rectangle
// -----------------------------------
-
+
ImageFilledRectangle($im, 0, 0, $img_width, $img_height, $bg_color);
-
+
// -----------------------------------
// Create the spiral pattern
// -----------------------------------
-
+
$theta = 1;
$thetac = 7;
$radius = 16;
@@ -185,9 +185,9 @@ if ( ! function_exists('create_captcha'))
// -----------------------------------
// Write the text
// -----------------------------------
-
+
$use_font = ($font_path != '' AND file_exists($font_path) AND function_exists('imagettftext')) ? TRUE : FALSE;
-
+
if ($use_font == FALSE)
{
$font_size = 5;
@@ -210,32 +210,32 @@ if ( ! function_exists('create_captcha'))
$x += ($font_size*2);
}
else
- {
+ {
$y = rand($img_height/2, $img_height-3);
imagettftext($im, $font_size, $angle, $x, $y, $text_color, $font_path, substr($word, $i, 1));
$x += $font_size;
}
}
-
+
// -----------------------------------
// Create the border
// -----------------------------------
- imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $border_color);
+ imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $border_color);
// -----------------------------------
// Generate the image
// -----------------------------------
-
+
$img_name = $now.'.jpg';
ImageJPEG($im, $img_path.$img_name);
-
+
$img = "<img src=\"$img_url$img_name\" width=\"$img_width\" height=\"$img_height\" style=\"border:0;\" alt=\" \" />";
-
+
ImageDestroy($im);
-
+
return array('word' => $word, 'time' => $now, 'image' => $img);
}
}