mirror of
https://github.com/e107inc/e107.git
synced 2025-03-14 01:19:44 +01:00
Issue #439 CAPTCHA was difficult to read on some backgrounds. Added support for constant e_CAPTCHA_FONTCOLOR (use hex color) which may be used in theme.php
This commit is contained in:
parent
6dd2738e0b
commit
7678f3fecc
@ -18,6 +18,10 @@ if (!defined('e107_INIT'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
define('e_CAPTCHA_FONTCOLOR','#F9A533');
|
||||
|
||||
|
||||
// Required for a clean v1.x -> v2 upgrade.
|
||||
$core = e107::getConfig('core');
|
||||
if($core->get('admintheme') != 'bootstrap')
|
||||
|
@ -24,6 +24,7 @@ class secure_image
|
||||
protected $MYSQL_INFO;
|
||||
protected $THIS_DIR;
|
||||
protected $BASE_DIR;
|
||||
public $FONT_COLOR = "90,90,90";
|
||||
|
||||
function secure_image()
|
||||
{
|
||||
@ -135,25 +136,60 @@ class secure_image
|
||||
}
|
||||
|
||||
|
||||
|
||||
//XXX Discuss - Add more posibilities for themers? e_CAPTCHA_BGIMAGE, e_CAPTCH_WIDTH, e_CAPTCHA_HEIGHT?
|
||||
function r_image()
|
||||
{
|
||||
if ($user_func = e107::getOverride()->check($this,'r_image'))
|
||||
{
|
||||
return call_user_func($user_func);
|
||||
}
|
||||
|
||||
|
||||
if(defined('e_CAPTCHA_FONTCOLOR'))
|
||||
{
|
||||
$color = str_replace("#","", e_CAPTCHA_FONTCOLOR);
|
||||
}
|
||||
else
|
||||
{
|
||||
$color = 'cccccc';
|
||||
}
|
||||
|
||||
$code = $this->create_code();
|
||||
return "<img src='".e_HTTP.$this->IMAGES_DIRECTORY."secimg.php?{$code}' class='icon secure-image' alt='Missing Code' style='max-width:100%' />";
|
||||
return "<img src='".e_HTTP.$this->IMAGES_DIRECTORY."secimg.php?id={$code}&clr={$color}' class='icon secure-image' alt='Missing Code' style='max-width:100%' />";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function renderImage() // Alias of r_image
|
||||
{
|
||||
return $this->r_image();
|
||||
}
|
||||
|
||||
|
||||
function hex2rgb($hex)
|
||||
{
|
||||
$hex = str_replace("#", "", $hex);
|
||||
|
||||
if(strlen($hex) == 3)
|
||||
{
|
||||
$r = hexdec(substr($hex,0,1).substr($hex,0,1));
|
||||
$g = hexdec(substr($hex,1,1).substr($hex,1,1));
|
||||
$b = hexdec(substr($hex,2,1).substr($hex,2,1));
|
||||
}
|
||||
else
|
||||
{
|
||||
$r = hexdec(substr($hex,0,2));
|
||||
$g = hexdec(substr($hex,2,2));
|
||||
$b = hexdec(substr($hex,4,2));
|
||||
}
|
||||
|
||||
$rgb = array($r, $g, $b);
|
||||
|
||||
return implode(",", $rgb);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function renderInput()
|
||||
{
|
||||
@ -180,8 +216,14 @@ class secure_image
|
||||
/**
|
||||
* Render the generated Image. Called without class2 environment (standalone).
|
||||
*/
|
||||
function render($qcode)
|
||||
function render($qcode, $color='')
|
||||
{
|
||||
if($color)
|
||||
{
|
||||
$this->FONT_COLOR = $this->hex2rgb($color);
|
||||
}
|
||||
|
||||
// echo "COLOR: ".$this->FONT_COLOR;
|
||||
|
||||
require_once($this->BASE_DIR.$this->HANDLERS_DIRECTORY."override_class.php");
|
||||
$over = new override;
|
||||
@ -262,7 +304,7 @@ class secure_image
|
||||
$fontpath = $this->BASE_DIR.$this->FONTS_DIRECTORY;
|
||||
$secureimg['image'] = "generic/code_bg";
|
||||
$secureimg['angle'] = "0";
|
||||
$secureimg['color'] = "90,90,90"; // red,green,blue
|
||||
$secureimg['color'] = $this->FONT_COLOR; // red,green,blue
|
||||
$secureimg['x'] = "1";
|
||||
$secureimg['y'] = "21";
|
||||
|
||||
@ -323,18 +365,21 @@ class secure_image
|
||||
|
||||
|
||||
// removing the black from the placeholder
|
||||
|
||||
$image = $this->imageCreateTransparent(100,35); //imagecreatetruecolor(100, 35);
|
||||
|
||||
|
||||
|
||||
if(isset($secureimg['color']))
|
||||
{
|
||||
$tmp = explode(",",$secureimg['color']);
|
||||
$text_color = imagecolorallocate($image,$tmp[0],$tmp[1],$tmp[2]);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$text_color = imagecolorallocate($image, 90, 90, 90);
|
||||
}
|
||||
|
||||
|
||||
header("Content-type: image/{$type}");
|
||||
|
||||
if(isset($secureimg['font']) && is_readable($fontpath.$secureimg['font']))
|
||||
@ -346,6 +391,8 @@ class secure_image
|
||||
imagestring ($image, 5, 12, 2, $code, $text_color);
|
||||
}
|
||||
|
||||
imagesavealpha($image, true);
|
||||
|
||||
switch($type)
|
||||
{
|
||||
case "jpeg":
|
||||
@ -363,7 +410,14 @@ class secure_image
|
||||
}
|
||||
|
||||
|
||||
|
||||
function imageCreateTransparent($x, $y)
|
||||
{
|
||||
$imageOut = imagecreatetruecolor($x, $y);
|
||||
$backgroundColor = imagecolorallocatealpha($imageOut, 0, 0, 0, 127);
|
||||
imagefill($imageOut, 0, 0, $backgroundColor);
|
||||
return $imageOut;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -40,7 +40,18 @@ require_once(realpath(e_BASE.$HANDLERS_DIRECTORY.DIRECTORY_SEPARATOR."secure_img
|
||||
|
||||
$sim = new secure_image();
|
||||
|
||||
$sim->render($_SERVER['QUERY_STRING']);
|
||||
$code = $_GET['id'];
|
||||
|
||||
if(preg_match('/^[a-f0-9]{6}$/i', $_GET['clr'])) //hex color is valid
|
||||
{
|
||||
$color = $_GET['clr'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$color = "cccccc";
|
||||
}
|
||||
|
||||
$sim->render($code,$color);
|
||||
|
||||
exit;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user