mirror of
https://github.com/e107inc/e107.git
synced 2025-08-01 20:30:39 +02:00
img-code performance
This commit is contained in:
@@ -16,31 +16,38 @@
|
|||||||
|
|
||||||
if (!defined('e107_INIT')) { exit; }
|
if (!defined('e107_INIT')) { exit; }
|
||||||
|
|
||||||
class secure_image
|
class secure_image
|
||||||
{
|
{
|
||||||
var $random_number;
|
public $random_number;
|
||||||
var $HANDLERS_DIRECTORY;
|
protected $HANDLERS_DIRECTORY;
|
||||||
var $IMAGES_DIRECTORY;
|
protected $IMAGES_DIRECTORY;
|
||||||
var $THIS_DIR;
|
protected $MYSQL_INFO;
|
||||||
|
protected $THIS_DIR;
|
||||||
|
protected $BASE_DIR;
|
||||||
|
|
||||||
function secure_image()
|
function secure_image()
|
||||||
{
|
{
|
||||||
list($usec, $sec) = explode(" ", microtime());
|
list($usec, $sec) = explode(" ", microtime());
|
||||||
$this->random_number = str_replace(".", "", $sec.$usec);
|
$this->random_number = str_replace(".", "", $sec.$usec);
|
||||||
|
|
||||||
$imgp = dirname(__FILE__);
|
$imgp = dirname(__FILE__);
|
||||||
if (substr($imgp,-1,1) != '/') $imgp .= '/';
|
if (substr($imgp,-1,1) != DIRECTORY_SEPARATOR) $imgp .= DIRECTORY_SEPARATOR;
|
||||||
if(!require($imgp.'../e107_config.php'))
|
$imgp = str_replace('/', DIRECTORY_SEPARATOR, $imgp);
|
||||||
|
@include($imgp.'..'.DIRECTORY_SEPARATOR.'e107_config.php');
|
||||||
|
if(!isset($mySQLserver))
|
||||||
{
|
{
|
||||||
if(defined('e_DEBUG'))
|
if(defined('e_DEBUG'))
|
||||||
{
|
{
|
||||||
echo "FAILED TO LOAD e107_config.php in secure_img_handler.php";
|
echo "FAILED TO LOAD e107_config.php in secure_img_handler.php";
|
||||||
}
|
}
|
||||||
}
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
$this->THIS_DIR = $imgp;
|
$this->THIS_DIR = $imgp;
|
||||||
$this->HANDLERS_DIRECTORY = $HANDLERS_DIRECTORY;
|
$this->BASE_DIR = realpath($imgp.'..'.DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
|
||||||
$this->IMAGES_DIRECTORY = $IMAGES_DIRECTORY;
|
$this->HANDLERS_DIRECTORY = str_replace('/', DIRECTORY_SEPARATOR, $HANDLERS_DIRECTORY);
|
||||||
|
$this->IMAGES_DIRECTORY = str_replace('/', DIRECTORY_SEPARATOR, $IMAGES_DIRECTORY);
|
||||||
|
$this->MYSQL_INFO = array('db' => $mySQLdefaultdb, 'server' => $mySQLserver, 'user' => $mySQLuser, 'password' => $mySQLpassword, 'prefix' => $mySQLprefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_code()
|
function create_code()
|
||||||
@@ -48,15 +55,6 @@ class secure_image
|
|||||||
|
|
||||||
$pref = e107::getPref();
|
$pref = e107::getPref();
|
||||||
$sql = e107::getDb();
|
$sql = e107::getDb();
|
||||||
|
|
||||||
/*
|
|
||||||
require_once('e107_class.php');
|
|
||||||
$e107 = new e107(false, false);
|
|
||||||
$e107->set_paths();
|
|
||||||
|
|
||||||
$imgpy = str_replace($HANDLERS_DIRECTORY, "", $e107->file_path);
|
|
||||||
*/
|
|
||||||
$imgp = str_replace($this->HANDLERS_DIRECTORY, $this->IMAGES_DIRECTORY, $this->THIS_DIR);
|
|
||||||
|
|
||||||
mt_srand ((double)microtime() * 1000000);
|
mt_srand ((double)microtime() * 1000000);
|
||||||
$maxran = 1000000;
|
$maxran = 1000000;
|
||||||
@@ -66,20 +64,21 @@ class secure_image
|
|||||||
$code = substr($rcode, 2, 6);
|
$code = substr($rcode, 2, 6);
|
||||||
$recnum = $this->random_number;
|
$recnum = $this->random_number;
|
||||||
$del_time = time()+1200;
|
$del_time = time()+1200;
|
||||||
$sql->db_Insert("tmp", "'{$recnum}',{$del_time},'{$code},{$imgp}'");
|
$sql->db_Insert("tmp", "'{$recnum}',{$del_time},'{$code}'");
|
||||||
return $recnum;
|
return $recnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function verify_code($rec_num, $checkstr)
|
function verify_code($rec_num, $checkstr)
|
||||||
{
|
{
|
||||||
$sql = e107::getDb();
|
$sql = e107::getDb();
|
||||||
$tp = e107::getParser();
|
$tp = e107::getParser();
|
||||||
|
|
||||||
if ($sql->db_Select("tmp", "tmp_info", "tmp_ip = '".$tp -> toDB($rec_num)."'")) {
|
if ($sql->db_Select("tmp", "tmp_info", "tmp_ip = '".$tp -> toDB($rec_num)."'")) {
|
||||||
$row = $sql->db_Fetch();
|
$row = $sql->db_Fetch();
|
||||||
$sql->db_Delete("tmp", "tmp_ip = '".$tp -> toDB($rec_num)."'");
|
$sql->db_Delete("tmp", "tmp_ip = '".$tp -> toDB($rec_num)."'");
|
||||||
list($code, $path) = explode(",", $row['tmp_info']);
|
//list($code, $path) = explode(",", $row['tmp_info']);
|
||||||
|
$code = intval($row['tmp_ip']);
|
||||||
return ($checkstr == $code);
|
return ($checkstr == $code);
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -90,34 +89,34 @@ class secure_image
|
|||||||
$code = $this->create_code();
|
$code = $this->create_code();
|
||||||
return "<img src='".e_HTTP.$this->HANDLERS_DIRECTORY."secure_img_render.php?{$code}' class='icon secure-image' alt='' />";
|
return "<img src='".e_HTTP.$this->HANDLERS_DIRECTORY."secure_img_render.php?{$code}' class='icon secure-image' alt='' />";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the generated Image.
|
* Render the generated Image. Called without class2 environment (standalone).
|
||||||
*/
|
*/
|
||||||
function render()
|
function render($qcode)
|
||||||
{
|
{
|
||||||
$sql = e107::getDb();
|
if(!is_numeric($qcode)){ exit; }
|
||||||
|
$recnum = preg_replace('#\D#',"",$qcode);
|
||||||
|
|
||||||
$imgtypes = array('jpg'=>"jpeg",'png'=>"png",'gif'=>"gif");
|
$imgtypes = array('jpg'=>"jpeg",'png'=>"png",'gif'=>"gif");
|
||||||
|
|
||||||
$recnum = preg_replace("#\D#","",e_QUERY);
|
|
||||||
|
|
||||||
if($recnum == false){ exit; }
|
|
||||||
|
|
||||||
$sql->db_Select_gen("SELECT tmp_info FROM #tmp WHERE tmp_ip = '{$recnum}' LIMIT 1");
|
|
||||||
|
|
||||||
if(!$row = $sql->db_Fetch(MYSQL_ASSOC))
|
@mysql_connect($this->MYSQL_INFO['server'], $this->MYSQL_INFO['user'], $this->MYSQL_INFO['password']) || die('db connection failed');
|
||||||
|
@mysql_select_db($this->MYSQL_INFO['db']);
|
||||||
|
|
||||||
|
$result = mysql_query("SELECT tmp_info FROM {$this->MYSQL_INFO['prefix']}tmp WHERE tmp_ip = '{$recnum}'");
|
||||||
|
if(!$result || !($row = mysql_fetch_array($result, MYSQL_ASSOC)))
|
||||||
{
|
{
|
||||||
echo "Render Failed";
|
echo "Render Failed";
|
||||||
|
echo "SELECT tmp_info FROM {$this->MYSQL_INFO['prefix']}tmp WHERE tmp_ip = '{$recnum}'";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
list($code, $url) = explode(",",$row['tmp_info']);
|
$code = intval($row['tmp_info']); // new value
|
||||||
|
|
||||||
$type = "none";
|
$type = "none";
|
||||||
|
|
||||||
foreach($imgtypes as $k=>$t)
|
foreach($imgtypes as $k=>$t)
|
||||||
{
|
{
|
||||||
if(function_exists("imagecreatefrom".$t))
|
if(function_exists("imagecreatefrom".$t))
|
||||||
@@ -127,27 +126,36 @@ class secure_image
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$path = e_IMAGE;
|
|
||||||
// TODO - add support for adding it in the THEME folder.
|
|
||||||
|
|
||||||
if(is_readable(e_IMAGE."secure_image_custom.php"))
|
|
||||||
{
|
|
||||||
|
|
||||||
require_once(e_IMAGE."secure_image_custom.php");
|
|
||||||
|
|
||||||
|
$path = $this->BASE_DIR.$this->IMAGES_DIRECTORY;
|
||||||
|
$secureimg = array();
|
||||||
|
|
||||||
|
if(is_readable($path."secure_image_custom.php"))
|
||||||
|
{
|
||||||
|
|
||||||
|
require_once($path."secure_image_custom.php");
|
||||||
|
/* Example secure_image_custom.php file:
|
||||||
|
|
||||||
|
$secureimg['image'] = "code_bg_custom"; // filename excluding the .ext
|
||||||
|
$secureimg['size'] = "15";
|
||||||
|
$secureimg['angle'] = "0";
|
||||||
|
$secureimg['x'] = "6";
|
||||||
|
$secureimg['y'] = "22";
|
||||||
|
$secureimg['font'] = "imagecode.ttf";
|
||||||
|
$secureimg['color'] = "90,90,90"; // red,green,blue
|
||||||
|
|
||||||
|
*/
|
||||||
$bg_file = $secureimg['image'];
|
$bg_file = $secureimg['image'];
|
||||||
|
|
||||||
if(!is_readable(e_IMAGE.$secureimg['font']))
|
if(!is_readable(e_IMAGE.$secureimg['font']))
|
||||||
{
|
{
|
||||||
echo "Font missing"; // for debug only. translation not necessary.
|
echo "Font missing"; // for debug only. translation not necessary.
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!is_readable(e_IMAGE.$secureimg['image'].$ext))
|
if(!is_readable(e_IMAGE.$secureimg['image'].$ext))
|
||||||
{
|
{
|
||||||
echo "Missing Background-Image: ".$secureimg['image'].$ext; // for debug only. translation not necessary.
|
echo "Missing Background-Image: ".$secureimg['image'].$ext; // for debug only. translation not necessary.
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
// var_dump($secureimg);
|
// var_dump($secureimg);
|
||||||
@@ -156,7 +164,7 @@ class secure_image
|
|||||||
{
|
{
|
||||||
$bg_file = "generic/code_bg";
|
$bg_file = "generic/code_bg";
|
||||||
}
|
}
|
||||||
|
|
||||||
switch($type)
|
switch($type)
|
||||||
{
|
{
|
||||||
case "jpeg":
|
case "jpeg":
|
||||||
@@ -169,9 +177,9 @@ class secure_image
|
|||||||
$image = ImageCreateFromGIF($path.$bg_file.".gif");
|
$image = ImageCreateFromGIF($path.$bg_file.".gif");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(isset($secureimg['color']))
|
if(isset($secureimg['color']))
|
||||||
{
|
{
|
||||||
$tmp = explode(",",$secureimg['color']);
|
$tmp = explode(",",$secureimg['color']);
|
||||||
@@ -181,9 +189,9 @@ class secure_image
|
|||||||
{
|
{
|
||||||
$text_color = ImageColorAllocate($image, 90, 90, 90);
|
$text_color = ImageColorAllocate($image, 90, 90, 90);
|
||||||
}
|
}
|
||||||
|
|
||||||
header("Content-type: image/{$type}");
|
header("Content-type: image/{$type}");
|
||||||
|
|
||||||
if(isset($secureimg['font']) && is_readable($path.$secureimg['font']))
|
if(isset($secureimg['font']) && is_readable($path.$secureimg['font']))
|
||||||
{
|
{
|
||||||
imagettftext($image, $secureimg['size'],$secureimg['angle'], $secureimg['x'], $secureimg['y'], $text_color,$path.$secureimg['font'], $code);
|
imagettftext($image, $secureimg['size'],$secureimg['angle'], $secureimg['x'], $secureimg['y'], $text_color,$path.$secureimg['font'], $code);
|
||||||
@@ -192,8 +200,7 @@ class secure_image
|
|||||||
{
|
{
|
||||||
imagestring ($image, 5, 12, 2, $code, $text_color);
|
imagestring ($image, 5, 12, 2, $code, $text_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
ob_end_clean();
|
|
||||||
switch($type)
|
switch($type)
|
||||||
{
|
{
|
||||||
case "jpeg":
|
case "jpeg":
|
||||||
@@ -206,15 +213,15 @@ class secure_image
|
|||||||
imagegif($image);
|
imagegif($image);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
/* Example Custom secure_image_custom.php file:
|
/* Example Custom secure_image_custom.php file:
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$secureimg['image'] = "code_bg_custom"; // filename excluding the .ext
|
$secureimg['image'] = "code_bg_custom"; // filename excluding the .ext
|
||||||
$secureimg['size'] = "15";
|
$secureimg['size'] = "15";
|
||||||
$secureimg['angle'] = "0";
|
$secureimg['angle'] = "0";
|
||||||
@@ -24,16 +24,16 @@
|
|||||||
$secureimg['y'] = "22";
|
$secureimg['y'] = "22";
|
||||||
$secureimg['font'] = "imagecode.ttf";
|
$secureimg['font'] = "imagecode.ttf";
|
||||||
$secureimg['color'] = "90,90,90"; // red,green,blue
|
$secureimg['color'] = "90,90,90"; // red,green,blue
|
||||||
|
|
||||||
?>
|
?>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once(realpath(dirname(__FILE__).'/../class2.php'));
|
define('e107_INIT', true);
|
||||||
|
require_once(realpath(dirname(__FILE__)."/secure_img_handler.php"));
|
||||||
|
|
||||||
require_once(e_HANDLER."secure_img_handler.php");
|
$sim = new secure_image();
|
||||||
|
$sim->render($_SERVER['QUERY_STRING']);
|
||||||
$sim = new secure_image;
|
|
||||||
$sim->render();
|
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
?>
|
?>
|
Reference in New Issue
Block a user