1
|
|
|
<?php |
|
|
|
|
2
|
|
|
//======================================================================= |
3
|
|
|
// File: JPGRAPH.PHP |
4
|
|
|
// Description: PHP Graph Plotting library. Base module. |
5
|
|
|
// Created: 2001-01-08 |
6
|
|
|
// Ver: $Id: jpgraph.php 1924 2010-01-11 14:03:26Z ljp $ |
7
|
|
|
// |
8
|
|
|
// Copyright (c) Asial Corporation. All rights reserved. |
9
|
|
|
//======================================================================== |
10
|
|
|
|
11
|
|
|
require_once 'jpg-config.inc.php'; |
12
|
|
|
//require_once('jpgraph_gradient.php'); * |
|
|
|
|
13
|
|
|
//require_once('jpgraph_errhandler.inc.php');* |
14
|
|
|
require_once 'jpgraph_ttf.inc.php'; |
15
|
|
|
//require_once('jpgraph_rgb.inc.php');* |
|
|
|
|
16
|
|
|
//require_once('jpgraph_text.inc.php');* |
17
|
|
|
//require_once('jpgraph_legend.inc.php');* |
18
|
|
|
//require_once('jpgraph_theme.inc.php');* |
19
|
|
|
//require_once('gd_image.inc.php');* |
20
|
|
|
|
21
|
|
|
// Line styles |
22
|
|
|
define('LINESTYLE_SOLID', 1); |
23
|
|
|
define('LINESTYLE_DOTTED', 2); |
24
|
|
|
define('LINESTYLE_DASHED', 3); |
25
|
|
|
define('LINESTYLE_LONGDASH', 4); |
26
|
|
|
|
27
|
|
|
// The DEFAULT_GFORMAT sets the default graphic encoding format, i.e. |
28
|
|
|
// PNG, JPG or GIF depending on what is installed on the target system |
29
|
|
|
// in that order. |
30
|
|
|
if (!DEFINED("DEFAULT_GFORMAT")) { |
31
|
|
|
define("DEFAULT_GFORMAT", "auto"); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
require_once 'imageSmoothArc.php'; |
35
|
|
|
|
36
|
|
|
// Styles for gradient color fill |
37
|
|
|
define("GRAD_VER", 1); |
38
|
|
|
define("GRAD_VERT", 1); |
39
|
|
|
define("GRAD_HOR", 2); |
40
|
|
|
define("GRAD_MIDHOR", 3); |
41
|
|
|
define("GRAD_MIDVER", 4); |
42
|
|
|
define("GRAD_CENTER", 5); |
43
|
|
|
define("GRAD_WIDE_MIDVER", 6); |
44
|
|
|
define("GRAD_WIDE_MIDHOR", 7); |
45
|
|
|
define("GRAD_LEFT_REFLECTION", 8); |
46
|
|
|
define("GRAD_RIGHT_REFLECTION", 9); |
47
|
|
|
define("GRAD_RAISED_PANEL", 10); |
48
|
|
|
define("GRAD_DIAGONAL", 11); |
49
|
|
|
DEFINE('_DEFAULT_LPM_SIZE', 8); // Default Legend Plot Mark size |
50
|
|
|
|
51
|
|
|
// Version info |
52
|
|
|
define('JPG_VERSION', '3.5.0b1'); |
53
|
|
|
|
54
|
|
|
// Minimum required PHP version |
55
|
|
|
define('MIN_PHPVERSION', '5.1.0'); |
56
|
|
|
|
57
|
|
|
// Special file name to indicate that we only want to calc |
58
|
|
|
// the image map in the call to Graph::Stroke() used |
59
|
|
|
// internally from the GetHTMLCSIM() method. |
60
|
|
|
define('_CSIM_SPECIALFILE', '_csim_special_'); |
61
|
|
|
|
62
|
|
|
// HTTP GET argument that is used with image map |
63
|
|
|
// to indicate to the script to just generate the image |
64
|
|
|
// and not the full CSIM HTML page. |
65
|
|
|
define('_CSIM_DISPLAY', '_jpg_csimd'); |
66
|
|
|
|
67
|
|
|
// Special filename for Graph::Stroke(). If this filename is given |
68
|
|
|
// then the image will NOT be streamed to browser of file. Instead the |
69
|
|
|
// Stroke call will return the handler for the created GD image. |
70
|
|
|
define('_IMG_HANDLER', '__handle'); |
71
|
|
|
|
72
|
|
|
// Special filename for Graph::Stroke(). If this filename is given |
73
|
|
|
// the image will be stroked to a file with a name based on the script name. |
74
|
|
|
define('_IMG_AUTO', 'auto'); |
75
|
|
|
|
76
|
|
|
// Tick density |
77
|
|
|
define("TICKD_DENSE", 1); |
78
|
|
|
define("TICKD_NORMAL", 2); |
79
|
|
|
define("TICKD_SPARSE", 3); |
80
|
|
|
define("TICKD_VERYSPARSE", 4); |
81
|
|
|
|
82
|
|
|
// Side for ticks and labels. |
83
|
|
|
define("SIDE_LEFT", -1); |
84
|
|
|
define("SIDE_RIGHT", 1); |
85
|
|
|
define("SIDE_DOWN", -1); |
86
|
|
|
define("SIDE_BOTTOM", -1); |
87
|
|
|
define("SIDE_UP", 1); |
88
|
|
|
define("SIDE_TOP", 1); |
89
|
|
|
|
90
|
|
|
// Legend type stacked vertical or horizontal |
91
|
|
|
define("LEGEND_VERT", 0); |
92
|
|
|
define("LEGEND_HOR", 1); |
93
|
|
|
|
94
|
|
|
// Mark types for plot marks |
95
|
|
|
define("MARK_SQUARE", 1); |
96
|
|
|
define("MARK_UTRIANGLE", 2); |
97
|
|
|
define("MARK_DTRIANGLE", 3); |
98
|
|
|
define("MARK_DIAMOND", 4); |
99
|
|
|
define("MARK_CIRCLE", 5); |
100
|
|
|
define("MARK_FILLEDCIRCLE", 6); |
101
|
|
|
define("MARK_CROSS", 7); |
102
|
|
|
define("MARK_STAR", 8); |
103
|
|
|
define("MARK_X", 9); |
104
|
|
|
define("MARK_LEFTTRIANGLE", 10); |
105
|
|
|
define("MARK_RIGHTTRIANGLE", 11); |
106
|
|
|
define("MARK_FLASH", 12); |
107
|
|
|
define("MARK_IMG", 13); |
108
|
|
|
define("MARK_FLAG1", 14); |
109
|
|
|
define("MARK_FLAG2", 15); |
110
|
|
|
define("MARK_FLAG3", 16); |
111
|
|
|
define("MARK_FLAG4", 17); |
112
|
|
|
|
113
|
|
|
// Builtin images |
114
|
|
|
define("MARK_IMG_PUSHPIN", 50); |
115
|
|
|
define("MARK_IMG_SPUSHPIN", 50); |
116
|
|
|
define("MARK_IMG_LPUSHPIN", 51); |
117
|
|
|
define("MARK_IMG_DIAMOND", 52); |
118
|
|
|
define("MARK_IMG_SQUARE", 53); |
119
|
|
|
define("MARK_IMG_STAR", 54); |
120
|
|
|
define("MARK_IMG_BALL", 55); |
121
|
|
|
define("MARK_IMG_SBALL", 55); |
122
|
|
|
define("MARK_IMG_MBALL", 56); |
123
|
|
|
define("MARK_IMG_LBALL", 57); |
124
|
|
|
define("MARK_IMG_BEVEL", 58); |
125
|
|
|
|
126
|
|
|
// Inline defines |
127
|
|
|
define("INLINE_YES", 1); |
128
|
|
|
define("INLINE_NO", 0); |
129
|
|
|
|
130
|
|
|
// Format for background images |
131
|
|
|
define("BGIMG_FILLPLOT", 1); |
132
|
|
|
define("BGIMG_FILLFRAME", 2); |
133
|
|
|
define("BGIMG_COPY", 3); |
134
|
|
|
define("BGIMG_CENTER", 4); |
135
|
|
|
define("BGIMG_FREE", 5); |
136
|
|
|
|
137
|
|
|
// Depth of objects |
138
|
|
|
define("DEPTH_BACK", 0); |
139
|
|
|
define("DEPTH_FRONT", 1); |
140
|
|
|
|
141
|
|
|
// Direction |
142
|
|
|
define("VERTICAL", 1); |
143
|
|
|
define("HORIZONTAL", 0); |
144
|
|
|
|
145
|
|
|
// Axis styles for scientific style axis |
146
|
|
|
define('AXSTYLE_SIMPLE', 1); |
147
|
|
|
define('AXSTYLE_BOXIN', 2); |
148
|
|
|
define('AXSTYLE_BOXOUT', 3); |
149
|
|
|
define('AXSTYLE_YBOXIN', 4); |
150
|
|
|
define('AXSTYLE_YBOXOUT', 5); |
151
|
|
|
|
152
|
|
|
// Style for title backgrounds |
153
|
|
|
define('TITLEBKG_STYLE1', 1); |
154
|
|
|
define('TITLEBKG_STYLE2', 2); |
155
|
|
|
define('TITLEBKG_STYLE3', 3); |
156
|
|
|
define('TITLEBKG_FRAME_NONE', 0); |
157
|
|
|
define('TITLEBKG_FRAME_FULL', 1); |
158
|
|
|
define('TITLEBKG_FRAME_BOTTOM', 2); |
159
|
|
|
define('TITLEBKG_FRAME_BEVEL', 3); |
160
|
|
|
define('TITLEBKG_FILLSTYLE_HSTRIPED', 1); |
161
|
|
|
define('TITLEBKG_FILLSTYLE_VSTRIPED', 2); |
162
|
|
|
define('TITLEBKG_FILLSTYLE_SOLID', 3); |
163
|
|
|
|
164
|
|
|
// Styles for axis labels background |
165
|
|
|
define('LABELBKG_NONE', 0); |
166
|
|
|
define('LABELBKG_XAXIS', 1); |
167
|
|
|
define('LABELBKG_YAXIS', 2); |
168
|
|
|
define('LABELBKG_XAXISFULL', 3); |
169
|
|
|
define('LABELBKG_YAXISFULL', 4); |
170
|
|
|
define('LABELBKG_XYFULL', 5); |
171
|
|
|
define('LABELBKG_XY', 6); |
172
|
|
|
|
173
|
|
|
// Style for background gradient fills |
174
|
|
|
define('BGRAD_FRAME', 1); |
175
|
|
|
define('BGRAD_MARGIN', 2); |
176
|
|
|
define('BGRAD_PLOT', 3); |
177
|
|
|
|
178
|
|
|
// Width of tab titles |
179
|
|
|
define('TABTITLE_WIDTHFIT', 0); |
180
|
|
|
define('TABTITLE_WIDTHFULL', -1); |
181
|
|
|
|
182
|
|
|
// Defines for 3D skew directions |
183
|
|
|
define('SKEW3D_UP', 0); |
184
|
|
|
define('SKEW3D_DOWN', 1); |
185
|
|
|
define('SKEW3D_LEFT', 2); |
186
|
|
|
define('SKEW3D_RIGHT', 3); |
187
|
|
|
|
188
|
|
|
// For internal use only |
189
|
|
|
define("_JPG_DEBUG", false); |
190
|
|
|
define("_FORCE_IMGTOFILE", false); |
191
|
|
|
define("_FORCE_IMGDIR", '/tmp/jpgimg/'); |
192
|
|
|
|
193
|
|
|
// |
194
|
|
|
// Automatic settings of path for cache and font directory |
195
|
|
|
// if they have not been previously specified |
196
|
|
|
// |
197
|
|
|
if (USE_CACHE) { |
198
|
|
View Code Duplication |
if (!defined('CACHE_DIR')) { |
|
|
|
|
199
|
|
|
if (strstr(PHP_OS, 'WIN')) { |
200
|
|
|
if (empty($_SERVER['TEMP'])) { |
201
|
|
|
$t = new ErrMsgText(); |
202
|
|
|
$msg = $t->Get(11, $file, $lineno); |
203
|
|
|
die($msg); |
204
|
|
|
} else { |
205
|
|
|
define('CACHE_DIR', $_SERVER['TEMP'] . '/'); |
206
|
|
|
} |
207
|
|
|
} else { |
208
|
|
|
define('CACHE_DIR', '/tmp/jpgraph_cache/'); |
209
|
|
|
} |
210
|
|
|
} |
211
|
|
|
} elseif (!defined('CACHE_DIR')) { |
212
|
|
|
define('CACHE_DIR', ''); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
// |
216
|
|
|
// Setup path for western/latin TTF fonts |
217
|
|
|
// |
218
|
|
View Code Duplication |
if (!defined('TTF_DIR')) { |
|
|
|
|
219
|
|
|
if (strstr(PHP_OS, 'WIN')) { |
220
|
|
|
$sroot = getenv('SystemRoot'); |
221
|
|
|
if (empty($sroot)) { |
222
|
|
|
$t = new ErrMsgText(); |
223
|
|
|
$msg = $t->Get(12, $file, $lineno); |
224
|
|
|
die($msg); |
225
|
|
|
} else { |
226
|
|
|
define('TTF_DIR', $sroot . '/fonts/'); |
227
|
|
|
} |
228
|
|
|
} else { |
229
|
|
|
define('TTF_DIR', '/usr/share/fonts/truetype/'); |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
// |
234
|
|
|
// Setup path for MultiByte TTF fonts (japanese, chinese etc.) |
235
|
|
|
// |
236
|
|
View Code Duplication |
if (!defined('MBTTF_DIR')) { |
|
|
|
|
237
|
|
|
if (strstr(PHP_OS, 'WIN')) { |
238
|
|
|
$sroot = getenv('SystemRoot'); |
239
|
|
|
if (empty($sroot)) { |
240
|
|
|
$t = new ErrMsgText(); |
241
|
|
|
$msg = $t->Get(12, $file, $lineno); |
242
|
|
|
die($msg); |
243
|
|
|
} else { |
244
|
|
|
define('MBTTF_DIR', $sroot . '/fonts/'); |
245
|
|
|
} |
246
|
|
|
} else { |
247
|
|
|
define('MBTTF_DIR', '/usr/share/fonts/truetype/'); |
248
|
|
|
} |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
// |
252
|
|
|
// Check minimum PHP version |
253
|
|
|
// |
254
|
|
|
function CheckPHPVersion($aMinVersion) |
255
|
|
|
{ |
256
|
|
|
return version_compare(PHP_VERSION, $aMinVersion) >= 0; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
// |
260
|
|
|
// Make sure PHP version is high enough |
261
|
|
|
// |
262
|
|
|
if (!CheckPHPVersion(MIN_PHPVERSION)) { |
263
|
|
|
Amenadiel\JpGraph\Util\JpGraphError::RaiseL(13, PHP_VERSION, MIN_PHPVERSION); |
264
|
|
|
die(); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
// |
268
|
|
|
// Make GD sanity check |
269
|
|
|
// |
270
|
|
|
if (!function_exists("imagetypes") || !function_exists('imagecreatefromstring')) { |
271
|
|
|
Amenadiel\JpGraph\Util\JpGraphError::RaiseL(25001); |
272
|
|
|
//("This PHP installation is not configured with the GD library. Please recompile PHP with GD support to run JpGraph. (Neither function imagetypes() nor imagecreatefromstring() does exist)"); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
// |
276
|
|
|
// Setup PHP error handler |
277
|
|
|
// |
278
|
|
|
function _phpErrorHandler($errno, $errmsg, $filename, $linenum, $vars) |
|
|
|
|
279
|
|
|
{ |
280
|
|
|
// Respect current error level |
281
|
|
|
if ($errno & error_reporting()) { |
282
|
|
|
Amenadiel\JpGraph\Util\JpGraphError::RaiseL(25003, basename($filename), $linenum, $errmsg); |
283
|
|
|
} |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
if (INSTALL_PHP_ERR_HANDLER) { |
287
|
|
|
set_error_handler("_phpErrorHandler"); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
// |
291
|
|
|
// Check if there were any warnings, perhaps some wrong includes by the user. In this |
292
|
|
|
// case we raise it immediately since otherwise the image will not show and makes |
293
|
|
|
// debugging difficult. This is controlled by the user setting CATCH_PHPERRMSG |
294
|
|
|
// |
295
|
|
|
if (isset($GLOBALS['php_errormsg']) && CATCH_PHPERRMSG && !preg_match('/|Deprecated|/i', $GLOBALS['php_errormsg'])) { |
296
|
|
|
Amenadiel\JpGraph\Util\JpGraphError::RaiseL(25004, $GLOBALS['php_errormsg']); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
// Useful mathematical function |
300
|
|
|
function sign($a) |
301
|
|
|
{ |
302
|
|
|
return $a >= 0 ? 1 : -1; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
// |
306
|
|
|
// Utility function to generate an image name based on the filename we |
307
|
|
|
// are running from and assuming we use auto detection of graphic format |
308
|
|
|
// (top level), i.e it is safe to call this function |
309
|
|
|
// from a script that uses JpGraph |
310
|
|
|
// |
311
|
|
|
function GenImgName() |
312
|
|
|
{ |
313
|
|
|
// Determine what format we should use when we save the images |
314
|
|
|
$supported = imagetypes(); |
315
|
|
|
if ($supported & IMG_PNG) { |
316
|
|
|
$img_format = "png"; |
317
|
|
|
} elseif ($supported & IMG_GIF) { |
318
|
|
|
$img_format = "gif"; |
319
|
|
|
} elseif ($supported & IMG_JPG) { |
320
|
|
|
$img_format = "jpeg"; |
321
|
|
|
} elseif ($supported & IMG_WBMP) { |
322
|
|
|
$img_format = "wbmp"; |
323
|
|
|
} elseif ($supported & IMG_XPM) { |
324
|
|
|
$img_format = "xpm"; |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
if (!isset($_SERVER['PHP_SELF'])) { |
328
|
|
|
Amenadiel\JpGraph\Util\JpGraphError::RaiseL(25005); |
329
|
|
|
//(" Can't access PHP_SELF, PHP global variable. You can't run PHP from command line if you want to use the 'auto' naming of cache or image files."); |
330
|
|
|
} |
331
|
|
|
$fname = basename($_SERVER['PHP_SELF']); |
332
|
|
|
if (!empty($_SERVER['QUERY_STRING'])) { |
333
|
|
|
$q = @$_SERVER['QUERY_STRING']; |
334
|
|
|
$fname .= '_' . preg_replace("/\W/", "_", $q) . '.' . $img_format; |
|
|
|
|
335
|
|
|
} else { |
336
|
|
|
$fname = substr($fname, 0, strlen($fname) - 4) . '.' . $img_format; |
337
|
|
|
} |
338
|
|
|
return $fname; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
global $gDateLocale; |
|
|
|
|
342
|
|
|
// Global object handlers |
343
|
|
|
$gDateLocale = new Amenadiel\JpGraph\Util\DateLocale(); |
344
|
|
|
$gJpgDateLocale = new Amenadiel\JpGraph\Util\DateLocale(); |
345
|
|
|
|
346
|
|
|
// <EOF> |
347
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.