forked from halo-battle/game
Upgrade jpgrah to 4.3.4
This commit is contained in:
parent
7c3999c5cd
commit
b5868f05f6
72 changed files with 19157 additions and 10327 deletions
|
|
@ -1,15 +1,22 @@
|
|||
<?php
|
||||
//=======================================================================
|
||||
// File: JPGRAPH_ERRHANDLER.PHP
|
||||
// Description: Error handler class together with handling of localized
|
||||
// error messages. All localized error messages are stored
|
||||
// in a separate file under the "lang/" subdirectory.
|
||||
// Created: 2006-09-24
|
||||
// Ver: $Id: jpgraph_errhandler.inc.php 973 2008-03-09 15:29:44Z ljp $
|
||||
// File: JPGRAPH_ERRHANDLER.PHP
|
||||
// Description: Error handler class together with handling of localized
|
||||
// error messages. All localized error messages are stored
|
||||
// in a separate file under the "lang/" subdirectory.
|
||||
// Created: 2006-09-24
|
||||
// Ver: $Id: jpgraph_errhandler.inc.php 1920 2009-12-08 10:02:26Z ljp $
|
||||
//
|
||||
// Copyright 2006 (c) Aditus Consulting. All rights reserved.
|
||||
//========================================================================
|
||||
|
||||
if (!defined('DEFAULT_ERR_LOCALE')) {
|
||||
define('DEFAULT_ERR_LOCALE', 'en');
|
||||
}
|
||||
|
||||
if (!defined('USE_IMAGE_ERROR_HANDLER')) {
|
||||
define('USE_IMAGE_ERROR_HANDLER', true);
|
||||
}
|
||||
|
||||
global $__jpg_err_locale ;
|
||||
$__jpg_err_locale = DEFAULT_ERR_LOCALE;
|
||||
|
|
@ -17,7 +24,7 @@ $__jpg_err_locale = DEFAULT_ERR_LOCALE;
|
|||
class ErrMsgText
|
||||
{
|
||||
private $lt=null;
|
||||
public function ErrMsgText()
|
||||
public function __construct()
|
||||
{
|
||||
global $__jpg_err_locale;
|
||||
$file = 'lang/'.$__jpg_err_locale.'.inc.php';
|
||||
|
|
@ -65,30 +72,30 @@ class ErrMsgText
|
|||
return $ea[0];
|
||||
}
|
||||
switch ($numargs) {
|
||||
case 1:
|
||||
$msg = sprintf($ea[0], $argv[0]);
|
||||
break;
|
||||
case 2:
|
||||
$msg = sprintf($ea[0], $argv[0], $argv[1]);
|
||||
break;
|
||||
case 3:
|
||||
$msg = sprintf($ea[0], $argv[0], $argv[1], $argv[2]);
|
||||
break;
|
||||
case 4:
|
||||
$msg = sprintf($ea[0], $argv[0], $argv[1], $argv[2], $argv[3]);
|
||||
break;
|
||||
case 5:
|
||||
$msg = sprintf($ea[0], $argv[0], $argv[1], $argv[2], $argv[3], $argv[4]);
|
||||
break;
|
||||
case 0:
|
||||
default:
|
||||
$msg = sprintf($ea[0]);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
$msg = sprintf($ea[0], $argv[0]);
|
||||
break;
|
||||
case 2:
|
||||
$msg = sprintf($ea[0], $argv[0], $argv[1]);
|
||||
break;
|
||||
case 3:
|
||||
$msg = sprintf($ea[0], $argv[0], $argv[1], $argv[2]);
|
||||
break;
|
||||
case 4:
|
||||
$msg = sprintf($ea[0], $argv[0], $argv[1], $argv[2], $argv[3]);
|
||||
break;
|
||||
case 5:
|
||||
$msg = sprintf($ea[0], $argv[0], $argv[1], $argv[2], $argv[3], $argv[4]);
|
||||
break;
|
||||
case 0:
|
||||
default:
|
||||
$msg = sprintf($ea[0]);
|
||||
break;
|
||||
}
|
||||
return $msg;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// A wrapper class that is used to access the specified error object
|
||||
// (to hide the global error parameter and avoid having a GLOBAL directive
|
||||
|
|
@ -96,14 +103,12 @@ class ErrMsgText
|
|||
//
|
||||
class JpGraphError
|
||||
{
|
||||
private static $__jpg_err;
|
||||
public static function Install($aErrObject)
|
||||
{
|
||||
self::$__jpg_err = new $aErrObject;
|
||||
}
|
||||
private static $__iImgFlg = true;
|
||||
private static $__iLogFile = '';
|
||||
private static $__iTitle = 'JpGraph Error: ';
|
||||
public static function Raise($aMsg, $aHalt=true)
|
||||
{
|
||||
self::$__jpg_err->Raise($aMsg, $aHalt);
|
||||
throw new JpGraphException($aMsg);
|
||||
}
|
||||
public static function SetErrLocale($aLoc)
|
||||
{
|
||||
|
|
@ -112,12 +117,91 @@ class JpGraphError
|
|||
}
|
||||
public static function RaiseL($errnbr, $a1=null, $a2=null, $a3=null, $a4=null, $a5=null)
|
||||
{
|
||||
$t = new ErrMsgText();
|
||||
$msg = $t->Get($errnbr, $a1, $a2, $a3, $a4, $a5);
|
||||
self::$__jpg_err->Raise($msg);
|
||||
throw new JpGraphExceptionL($errnbr, $a1, $a2, $a3, $a4, $a5);
|
||||
}
|
||||
public static function SetImageFlag($aFlg=true)
|
||||
{
|
||||
self::$__iImgFlg = $aFlg;
|
||||
}
|
||||
public static function GetImageFlag()
|
||||
{
|
||||
return self::$__iImgFlg;
|
||||
}
|
||||
public static function SetLogFile($aFile)
|
||||
{
|
||||
self::$__iLogFile = $aFile;
|
||||
}
|
||||
public static function GetLogFile()
|
||||
{
|
||||
return self::$__iLogFile;
|
||||
}
|
||||
public static function SetTitle($aTitle)
|
||||
{
|
||||
self::$__iTitle = $aTitle;
|
||||
}
|
||||
public static function GetTitle()
|
||||
{
|
||||
return self::$__iTitle;
|
||||
}
|
||||
}
|
||||
|
||||
class JpGraphException extends Exception
|
||||
{
|
||||
// Redefine the exception so message isn't optional
|
||||
public function __construct($message, $code = 0)
|
||||
{
|
||||
// make sure everything is assigned properly
|
||||
parent::__construct($message, $code);
|
||||
}
|
||||
// custom string representation of object
|
||||
public function _toString()
|
||||
{
|
||||
return __CLASS__ . ": [{$this->code}]: {$this->message} at " . basename($this->getFile()) . ":" . $this->getLine() . "\n" . $this->getTraceAsString() . "\n";
|
||||
}
|
||||
// custom representation of error as an image
|
||||
public function Stroke()
|
||||
{
|
||||
if (JpGraphError::GetImageFlag()) {
|
||||
$errobj = new JpGraphErrObjectImg();
|
||||
$errobj->SetTitle(JpGraphError::GetTitle());
|
||||
} else {
|
||||
$errobj = new JpGraphErrObject();
|
||||
$errobj->SetTitle(JpGraphError::GetTitle());
|
||||
$errobj->SetStrokeDest(JpGraphError::GetLogFile());
|
||||
}
|
||||
$errobj->Raise($this->getMessage());
|
||||
}
|
||||
public static function defaultHandler(Throwable $exception)
|
||||
{
|
||||
global $__jpg_OldHandler;
|
||||
if ($exception instanceof JpGraphException) {
|
||||
$exception->Stroke();
|
||||
} else {
|
||||
// Restore old handler
|
||||
if ($__jpg_OldHandler !== null) {
|
||||
set_exception_handler($__jpg_OldHandler);
|
||||
}
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class JpGraphExceptionL extends JpGraphException
|
||||
{
|
||||
// Redefine the exception so message isn't optional
|
||||
public function __construct($errcode, $a1=null, $a2=null, $a3=null, $a4=null, $a5=null)
|
||||
{
|
||||
// make sure everything is assigned properly
|
||||
$errtxt = new ErrMsgText();
|
||||
JpGraphError::SetTitle('JpGraph Error: '.$errcode);
|
||||
parent::__construct($errtxt->Get($errcode, $a1, $a2, $a3, $a4, $a5), 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Setup the default handler
|
||||
global $__jpg_OldHandler;
|
||||
$__jpg_OldHandler = set_exception_handler(array('JpGraphException','defaultHandler'));
|
||||
|
||||
//
|
||||
// First of all set up a default error handler
|
||||
//
|
||||
|
|
@ -127,11 +211,11 @@ class JpGraphError
|
|||
//=============================================================
|
||||
class JpGraphErrObject
|
||||
{
|
||||
protected $iTitle = "JpGraph Error";
|
||||
protected $iTitle = "JpGraph error: ";
|
||||
protected $iDest = false;
|
||||
|
||||
|
||||
public function JpGraphErrObject()
|
||||
public function __construct()
|
||||
{
|
||||
// Empty. Reserved for future use
|
||||
}
|
||||
|
|
@ -147,20 +231,31 @@ class JpGraphErrObject
|
|||
}
|
||||
|
||||
// If aHalt is true then execution can't continue. Typical used for fatal errors
|
||||
public function Raise($aMsg, $aHalt=true)
|
||||
public function Raise($aMsg, $aHalt=false)
|
||||
{
|
||||
$aMsg = $this->iTitle.' '.$aMsg;
|
||||
if ($this->iDest) {
|
||||
$f = @fopen($this->iDest, 'a');
|
||||
if ($f) {
|
||||
@fwrite($f, $aMsg);
|
||||
@fclose($f);
|
||||
if ($this->iDest != '') {
|
||||
if ($this->iDest == 'syslog') {
|
||||
error_log($this->iTitle.$aMsg);
|
||||
} else {
|
||||
$str = '['.date('r').'] '.$this->iTitle.$aMsg."\n";
|
||||
$f = @fopen($this->iDest, 'a');
|
||||
if ($f) {
|
||||
@fwrite($f, $str);
|
||||
@fclose($f);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo $aMsg;
|
||||
$aMsg = $this->iTitle.$aMsg;
|
||||
// Check SAPI and if we are called from the command line
|
||||
// send the error to STDERR instead
|
||||
if (PHP_SAPI == 'cli') {
|
||||
fwrite(STDERR, $aMsg);
|
||||
} else {
|
||||
echo $aMsg;
|
||||
}
|
||||
}
|
||||
if ($aHalt) {
|
||||
die();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -170,25 +265,32 @@ class JpGraphErrObject
|
|||
//==============================================================
|
||||
class JpGraphErrObjectImg extends JpGraphErrObject
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// Empty. Reserved for future use
|
||||
}
|
||||
|
||||
public function Raise($aMsg, $aHalt=true)
|
||||
{
|
||||
$img_iconerror =
|
||||
'iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAMAAAC7IEhfAAAAaV'.
|
||||
'BMVEX//////2Xy8mLl5V/Z2VvMzFi/v1WyslKlpU+ZmUyMjEh/'.
|
||||
'f0VyckJlZT9YWDxMTDjAwMDy8sLl5bnY2K/MzKW/v5yyspKlpY'.
|
||||
'iYmH+MjHY/PzV/f2xycmJlZVlZWU9MTEXY2Ms/PzwyMjLFTjea'.
|
||||
'AAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACx'.
|
||||
'IAAAsSAdLdfvwAAAAHdElNRQfTBgISOCqusfs5AAABLUlEQVR4'.
|
||||
'2tWV3XKCMBBGWfkranCIVClKLd/7P2Q3QsgCxjDTq+6FE2cPH+'.
|
||||
'xJ0Ogn2lQbsT+Wr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3LYgK7r6A/noDAfjtS'.
|
||||
'IXaIzbJSv6WgUebTMV4EoRB8a2mQiQjgtF91HdKDKZ1gtFtQjk'.
|
||||
'YcWaR5OKOhkYt+ZsTFdJRfPAApOpQYJTNHvCRSJR6SJngQadfc'.
|
||||
'vd69OLMddVOPCGVnmrFD8bVYd3JXfxXPtLR/+mtv59/ALWiiMx'.
|
||||
'qL72fwAAAABJRU5ErkJggg==' ;
|
||||
|
||||
|
||||
if (function_exists("imagetypes")) {
|
||||
$supported = imagetypes();
|
||||
} else {
|
||||
|
|
@ -198,7 +300,7 @@ class JpGraphErrObjectImg extends JpGraphErrObject
|
|||
if (!function_exists('imagecreatefromstring')) {
|
||||
$supported = 0;
|
||||
}
|
||||
|
||||
|
||||
if (ob_get_length() || headers_sent() || !($supported & IMG_PNG)) {
|
||||
// Special case for headers already sent or that the installation doesn't support
|
||||
// the PNG format (which the error icon is encoded in).
|
||||
|
|
@ -224,7 +326,7 @@ class JpGraphErrObjectImg extends JpGraphErrObject
|
|||
$img->FilledRectangle(5, 5, $w-1, $h-1, 10);
|
||||
$img->SetColor("gray:0.7");
|
||||
$img->FilledRectangle(5, 5, $w-3, $h-3, 10);
|
||||
|
||||
|
||||
// Window background
|
||||
$img->SetColor("lightblue");
|
||||
$img->FilledRectangle(1, 1, $w-5, $h-5);
|
||||
|
|
@ -234,7 +336,7 @@ class JpGraphErrObjectImg extends JpGraphErrObject
|
|||
$img->SetColor("black");
|
||||
$img->Rectangle(1, 1, $w-5, $h-5);
|
||||
$img->Rectangle(0, 0, $w-4, $h-4);
|
||||
|
||||
|
||||
// Window top row
|
||||
$img->SetColor("darkred");
|
||||
for ($y=3; $y < 18; $y += 2) {
|
||||
|
|
@ -257,17 +359,18 @@ class JpGraphErrObjectImg extends JpGraphErrObject
|
|||
|
||||
// Window title
|
||||
$m = floor($w/2-5);
|
||||
$l = 100;
|
||||
$l = 110;
|
||||
$img->SetColor("lightgray:1.3");
|
||||
$img->FilledRectangle($m-$l, 2, $m+$l, 16);
|
||||
|
||||
// Stroke text
|
||||
$img->SetColor("darkred");
|
||||
$img->SetFont(FF_FONT2, FS_BOLD);
|
||||
$img->StrokeText($m-50, 15, $this->iTitle);
|
||||
$img->StrokeText($m-90, 15, $this->iTitle);
|
||||
$img->SetColor("black");
|
||||
$img->SetFont(FF_FONT1, FS_NORMAL);
|
||||
$txt = new Text($aMsg, 52, 25);
|
||||
$txt->SetFont(FF_FONT1);
|
||||
$txt->Align("left", "top");
|
||||
$txt->Stroke($img);
|
||||
if ($this->iDest) {
|
||||
|
|
@ -283,9 +386,7 @@ class JpGraphErrObjectImg extends JpGraphErrObject
|
|||
}
|
||||
|
||||
|
||||
// Install the default error handler
|
||||
if (USE_IMAGE_ERROR_HANDLER) {
|
||||
JpGraphError::Install("JpGraphErrObjectImg");
|
||||
} else {
|
||||
JpGraphError::Install("JpGraphErrObject");
|
||||
|
||||
if (! USE_IMAGE_ERROR_HANDLER) {
|
||||
JpGraphError::SetImageFlag(false);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue