Menu

[r8]: / includes / jpgraph / jpgraph_errhandler.inc.php  Maximize  Restore  History

Download this file

278 lines (242 with data), 7.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?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,v 1.2 2007/07/03 06:37:19 mindblender Exp $
//
// Copyright 2006 (c) Aditus Consulting. All rights reserved.
//========================================================================
// Since the error handler needs to be accessed from anywhere this must be
// made a global variable.
GLOBAL $__jpg_err;
GLOBAL $__jpg_err_locale ;
$__jpg_err_locale = DEFAULT_ERR_LOCALE;
// Handles the retrieval of localized error messages
class ErrMsgText {
var $lt=NULL;
function ErrMsgText() {
GLOBAL $__jpg_err_locale;
$file = 'lang/'.$__jpg_err_locale.'.inc.php';
// If the chosen locale doesn't exist try english
if( !file_exists(dirname(__FILE__).'/'.$file) ) {
$__jpg_err_locale = 'en';
}
$file = 'lang/'.$__jpg_err_locale.'.inc.php';
if( !file_exists(dirname(__FILE__).'/'.$file) ) {
die('Internal error: Chosen locale file for error messages does not exist.');
}
require_once($file);
$this->lt = $_jpg_messages;
}
function Get($errnbr,$a1=null,$a2=null,$a3=null,$a4=null,$a5=null) {
GLOBAL $__jpg_err_locale;
if( !isset($this->lt[$errnbr]) ) {
return 'Internal error: The specified error message ('.$errnbr.') does not exist in the chosen locale ('.$__jpg_err_locale.')';
}
$ea = $this->lt[$errnbr];
$j=0;
if( $a1 !== null ) {
$argv[$j++] = $a1;
if( $a2 !== null ) {
$argv[$j++] = $a2;
if( $a3 !== null ) {
$argv[$j++] = $a3;
if( $a4 !== null ) {
$argv[$j++] = $a4;
if( $a5 !== null ) {
$argv[$j++] = $a5;
}
}
}
}
}
$numargs = $j;
if( $ea[1] != $numargs ) {
// Error message argument count do not match.
// Just return the error message without arguments.
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;
}
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
// in all methods.
//
class JpGraphError {
function Install($aErrObject) {
GLOBAL $__jpg_err;
$__jpg_err = $aErrObject;
}
function SetErrLocale($aLoc) {
GLOBAL $__jpg_err_locale ;
$__jpg_err_locale = $aLoc;
}
function Raise($aMsg,$aHalt=true){
GLOBAL $__jpg_err;
$tmp = new $__jpg_err;
$tmp->Raise($aMsg,$aHalt);
}
function RaiseL($errnbr,$a1=null,$a2=null,$a3=null,$a4=null,$a5=null) {
GLOBAL $__jpg_err;
$t = new ErrMsgText();
$msg = $t->Get($errnbr,$a1,$a2,$a3,$a4,$a5);
$tmp = new $__jpg_err;
$tmp->Raise($msg);
}
}
// The default trivial text error handler.
class JpGraphErrObject {
var $iTitle = "JpGraph Error";
var $iDest = false;
function JpGraphErrObject() {
// Empty. Reserved for future use
}
function SetTitle($aTitle) {
$this->iTitle = $aTitle;
}
function SetStrokeDest($aDest) {
$this->iDest = $aDest;
}
// If aHalt is true then execution can't continue. Typical used for fatal errors.
function Raise($aMsg,$aHalt=true) {
$aMsg = $this->iTitle.' '.$aMsg;
if ($this->iDest) {
$f = @fopen($this->iDest,'a');
if( $f ) {
@fwrite($f,$aMsg);
@fclose($f);
}
}
else {
echo $aMsg;
}
if( $aHalt )
die();
}
}
//==============================================================
// An image based error handler
//==============================================================
class JpGraphErrObjectImg extends JpGraphErrObject {
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+Wrs+buAZAV4W5T6Bs0YXBBwpKgEuIu+JERAX6'.
'wM2rHjmDdEITmsQEEmWADgZm6rAjhXsoMGY9B/NZBwJzBvn+e3'.
'wHntCAJdGu9SviwIwoZVDxPB9+Rc0TSEbQr0j3SA1gwdSn6Db0'.
'6Tm1KfV6yzWGQO7zdpvyKLKBDmRFjzeB3LYgK7r6A/noDAfjtS'.
'IXaIzbJSv6WgUebTMV4EoRB8a2mQiQjgtF91HdKDKZ1gtFtQjk'.
'YcWaR5OKOhkYt+ZsTFdJRfPAApOpQYJTNHvCRSJR6SJngQadfc'.
'vd69OLMddVOPCGVnmrFD8bVYd3JXfxXPtLR/+mtv59/ALWiiMx'.
'qL72fwAAAABJRU5ErkJggg==' ;
if( function_exists("imagetypes") )
$supported = imagetypes();
else
$supported = 0;
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).
// Dont return an image since it can't be displayed
die($this->iTitle.' '.$aMsg);
}
$aMsg = wordwrap($aMsg,55);
$lines = substr_count($aMsg,"\n");
// Create the error icon GD
$erricon = Image::CreateFromString(base64_decode($img_iconerror));
// Create an image that contains the error text.
$w=400;
$h=100 + 15*max(0,$lines-3);
$img = new Image($w,$h);
// Drop shadow
$img->SetColor("gray");
$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);
$img->CopyCanvasH($img->img,$erricon,5,30,0,0,40,40);
// Window border
$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 )
$img->Line(1,$y,$w-6,$y);
// "White shadow"
$img->SetColor("white");
// Left window edge
$img->Line(2,2,2,$h-5);
$img->Line(2,2,$w-6,2);
// "Gray button shadow"
$img->SetColor("darkgray");
// Gray window shadow
$img->Line(2,$h-6,$w-5,$h-6);
$img->Line(3,$h-7,$w-5,$h-7);
// Window title
$m = floor($w/2-5);
$l = 100;
$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->SetColor("black");
$img->SetFont(FF_FONT1,FS_NORMAL);
$txt = new Text($aMsg,52,25);
$txt->Align("left","top");
$txt->Stroke($img);
if ($this->iDest) {
$img->Stream($this->iDest);
} else {
$img->Headers();
$img->Stream();
}
if( $aHalt )
die();
}
}
// Install the default error handler in a global accessible variable
if( USE_IMAGE_ERROR_HANDLER ) {
$__jpg_err = "JpGraphErrObjectImg";
}
else {
$__jpg_err = "JpGraphErrObject";
}
?>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.