mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-19 23:11:45 +02:00
- fixes for the following bugs:
#5326 #5318 #5304 #5290 #5288 #5278 #5276 #5272 #5266 - also fixed the "Call-time pass-by-reference" bug #5252 - within this step changed the normalize calls to require references. - added captcha size variables to the class scope (suggestion was posted at area51) git-svn-id: file:///svn/phpbb/trunk@6584 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
@@ -16,33 +16,18 @@
|
||||
*/
|
||||
class captcha
|
||||
{
|
||||
var $width = 360;
|
||||
var $height = 96;
|
||||
|
||||
function execute($code)
|
||||
{
|
||||
global $config;
|
||||
$stats = gd_info();
|
||||
|
||||
if (substr($stats['GD Version'], 0, 7) === 'bundled')
|
||||
{
|
||||
$bundled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$bundled = false;
|
||||
}
|
||||
$bundled = (substr($stats['GD Version'], 0, 7) === 'bundled') ? true : false;
|
||||
|
||||
preg_match('/[\\d.]+/', $stats['GD Version'], $version);
|
||||
if (version_compare($version[0], '2.0.1', '>='))
|
||||
{
|
||||
$gd_version = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
$gd_version = 1;
|
||||
}
|
||||
|
||||
// set dimension of image
|
||||
$lx = 360;
|
||||
$ly = 96;
|
||||
$gd_version = (version_compare($version[0], '2.0.1', '>=')) ? 2 : 1;
|
||||
|
||||
// create the image, stay compat with older versions of GD
|
||||
if ($gd_version === 2)
|
||||
@@ -56,7 +41,7 @@ class captcha
|
||||
$func2 = 'imagecolorclosest';
|
||||
}
|
||||
|
||||
$image = $func1($lx, $ly);
|
||||
$image = $func1($this->width, $this->height);
|
||||
|
||||
if ($bundled)
|
||||
{
|
||||
@@ -65,7 +50,7 @@ class captcha
|
||||
|
||||
// set background color
|
||||
$back = imagecolorallocate($image, mt_rand(224, 255), mt_rand(224, 255), mt_rand(224, 255));
|
||||
imagefilledrectangle($image, 0, 0, $lx, $ly, $back);
|
||||
imagefilledrectangle($image, 0, 0, $this->width, $this->height, $back);
|
||||
|
||||
// allocates the 216 websafe color palette to the image
|
||||
if ($gd_version === 1)
|
||||
@@ -82,7 +67,6 @@ class captcha
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// fill with noise or grid
|
||||
if ($config['captcha_gd_noise'])
|
||||
{
|
||||
@@ -92,7 +76,7 @@ class captcha
|
||||
$size = mt_rand(8, 23);
|
||||
$angle = mt_rand(0, 360);
|
||||
$x = mt_rand(0, 360);
|
||||
$y = mt_rand(0, (int)($ly - ($size / 5)));
|
||||
$y = mt_rand(0, (int)($this->height - ($size / 5)));
|
||||
$color = $func2($image, mt_rand(160, 224), mt_rand(160, 224), mt_rand(160, 224));
|
||||
$text = chr(mt_rand(45, 250));
|
||||
imagettftext($image, $size, $angle, $x, $y, $color, $this->get_font(), $text);
|
||||
@@ -101,15 +85,16 @@ class captcha
|
||||
else
|
||||
{
|
||||
// generate grid
|
||||
for ($i = 0; $i < $lx; $i += 13)
|
||||
for ($i = 0; $i < $this->width; $i += 13)
|
||||
{
|
||||
$color = $func2($image, mt_rand(160, 224), mt_rand(160, 224), mt_rand(160, 224));
|
||||
imageline($image, $i, 0, $i, $ly, $color);
|
||||
imageline($image, $i, 0, $i, $this->height, $color);
|
||||
}
|
||||
for ($i = 0; $i < $ly; $i += 11)
|
||||
|
||||
for ($i = 0; $i < $this->height; $i += 11)
|
||||
{
|
||||
$color = $func2($image, mt_rand(160, 224), mt_rand(160, 224), mt_rand(160, 224));
|
||||
imageline($image, 0, $i, $lx, $i, $color);
|
||||
imageline($image, 0, $i, $this->width, $i, $color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +105,7 @@ class captcha
|
||||
$text = strtoupper($code[$i]);
|
||||
$angle = mt_rand(-30, 30);
|
||||
$size = mt_rand(20, 40);
|
||||
$y = mt_rand((int)($size * 1.5), (int)($ly - ($size / 7)));
|
||||
$y = mt_rand((int)($size * 1.5), (int)($this->height - ($size / 7)));
|
||||
|
||||
$color = $func2($image, mt_rand(0, 127), mt_rand(0, 127), mt_rand(0, 127));
|
||||
$shadow = $func2($image, mt_rand(127, 254), mt_rand(127, 254), mt_rand(127, 254));
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
class captcha
|
||||
{
|
||||
var $filtered_pngs;
|
||||
var $width = 320;
|
||||
var $height = 50;
|
||||
|
||||
/**
|
||||
* Define filtered pngs on init
|
||||
@@ -32,9 +34,7 @@ class captcha
|
||||
*/
|
||||
function execute($code)
|
||||
{
|
||||
$total_width = 320;
|
||||
$total_height = 50;
|
||||
$img_height = 40;
|
||||
$img_height = $this->height - 10;
|
||||
$img_width = 0;
|
||||
|
||||
list($usec, $sec) = explode(' ', microtime());
|
||||
@@ -45,7 +45,7 @@ class captcha
|
||||
|
||||
for ($i = 0; $i < $code_len; $i++)
|
||||
{
|
||||
$char = $code{$i};
|
||||
$char = $code[$i];
|
||||
|
||||
$width = mt_rand(0, 4);
|
||||
$raw_width = $this->filtered_pngs[$char]['width'];
|
||||
@@ -59,11 +59,11 @@ class captcha
|
||||
}
|
||||
}
|
||||
|
||||
$offset_x = mt_rand(0, $total_width - $img_width);
|
||||
$offset_y = mt_rand(0, $total_height - $img_height);
|
||||
$offset_x = mt_rand(0, $this->width - $img_width);
|
||||
$offset_y = mt_rand(0, $this->height - $img_height);
|
||||
|
||||
$image = '';
|
||||
for ($i = 0; $i < $total_height; $i++)
|
||||
for ($i = 0; $i < $this->height; $i++)
|
||||
{
|
||||
$image .= chr(0);
|
||||
|
||||
@@ -79,14 +79,14 @@ class captcha
|
||||
$image .= $this->randomise(substr($hold_chars[$code{$j}][$i - $offset_y - 1], 1), $char_widths[$j]);
|
||||
}
|
||||
|
||||
for ($j = $offset_x + $img_width; $j < $total_width; $j++)
|
||||
for ($j = $offset_x + $img_width; $j < $this->width; $j++)
|
||||
{
|
||||
$image .= chr(mt_rand(140, 255));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for ($j = 0; $j < $total_width; $j++)
|
||||
for ($j = 0; $j < $this->width; $j++)
|
||||
{
|
||||
$image .= chr(mt_rand(140, 255));
|
||||
}
|
||||
@@ -94,7 +94,7 @@ class captcha
|
||||
}
|
||||
unset($hold_chars);
|
||||
|
||||
$image = $this->create_png($image, $total_width, $total_height);
|
||||
$image = $this->create_png($image, $this->width, $this->height);
|
||||
|
||||
// Output image
|
||||
header('Content-Type: image/png');
|
||||
|
||||
Reference in New Issue
Block a user