-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpChartWebservice.php
executable file
·92 lines (77 loc) · 3.44 KB
/
pChartWebservice.php
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
<?php
/**
* pChartWebservice.php
* Webservice to generate charts using pChart
* written by Robert Horlings
* http://www.mediawiki.org/wiki/Extension:pChart4mw
*
*/
// Include library functions
require_once( "library.inc.php" );
//
// Default parameters
//
// Image format to save the charts. Can be 'png', 'jpeg' or 'gif'
$wgPChart4mwImageFormat = "png";
// Flag whether the built-in cache should be used. Using the cache the
// system will only create each chart once and save it to disk. If no
// changes are detected, the image that is already created will be used
$wgPChart4mwCacheEnabled = true;
// Directory to save generated charts to. It must be relative to the document
// root. This directory must exist and be writable. If it does not, the
// system will attempt to create it.
$wgPChart4mwCacheDir = "/wiki/images/pChart4mw";
// Path where PChart is installed. This directory must contain a subdirectory
// Fonts with truetype fonts installed
$wgPChart4mwPChartPath = dirname( __FILE__) . "/pChart";
// Absolute path to the font that is used for writing text into the charts.
// This variable contains the path and filename that directs to the TTF-file
$wgPChart4mwFontPath = dirname( __FILE__) . "/fonts";
// Directory containing the color schemes. These color schemes are text files with
// a color on each line. Every color is a comma-separated RGB color. An example is
$wgPChart4mwDefaultColorSchemeDir = dirname( __FILE__ ) . "/colorschemes";
// Make sure classes for pChart4mw and pChart itself can be loaded.
$currentDir = dirname(__FILE__);
$wgAutoloadClasses[ 'pChart' ] = $wgPChart4mwPChartPath . '/pChart.class';
$wgAutoloadClasses[ 'pChart4mw' ] = $currentDir . '/pChart4mw.class.php';
$wgAutoloadClasses[ 'pChart4mwBars' ] = $currentDir . '/pChart4mw.bars.class.php';
$wgAutoloadClasses[ 'pChart4mwLines' ] = $currentDir . '/pChart4mw.lines.class.php';
$wgAutoloadClasses[ 'pChart4mwRadar' ] = $currentDir . '/pChart4mw.radar.class.php';
$wgAutoloadClasses[ 'pChart4mwPie' ] = $currentDir . '/pChart4mw.pie.class.php';
$wgAutoloadClasses[ 'pChart4mwScatter' ] = $currentDir . '/pChart4mw.scatter.class.php';
$wgAutoloadClasses[ 'pChart4mwBubble' ] = $currentDir . '/pChart4mw.bubble.class.php';
// Make sure classes can be loaded
function __autoload( $class_name ) {
global $wgAutoloadClasses;
if( array_key_exists( $class_name, $wgAutoloadClasses ) ) {
require_once( $wgAutoloadClasses[ $class_name ] );
} else {
return false;
}
}
// Analyze the type, data and arguments
if( array_key_exists( "_type", $_REQUEST ) ) {
$type = $_REQUEST[ "_type" ];
} else {
$type = "bars";
}
if( array_key_exists( "_data", $_REQUEST ) ) {
$data = $_REQUEST[ "_data" ];
} else {
$data = "";
}
// Create chart object
switch( $type ) {
case "bars": $pChart = new pChart4mwBars(); break;
case "lines": $pChart = new pChart4mwLines(); break;
case "radar": $pChart = new pChart4mwRadar(); break;
case "pie": $pChart = new pChart4mwPie(); break;
case "scatter": $pChart = new pChart4mwScatter(); break;
case "bubble": $pChart = new pChart4mwBubble(); break;
default: $pChart = new pChart4mwBars(); break;
}
// Parse the data and get all arguments into an array
$data = str_replace( "|", "\n", $data );
$args = $_REQUEST;
// Show the chart
$pChart->showChart( $data, $args );