PluginProbe
InfiniteWP Client / trunk
InfiniteWP Client vtrunk
1.13.10 1.13.7 trunk 0.1.4 0.1.5 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.10 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.11.0 1.11.1 1.12.1 1.12.3 All 92 releases
iwp-client / debug-chart / src / fusioncharts.php

fusioncharts.php in InfiniteWP Client trunk, at debug-chart/src/fusioncharts.php

67 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class FusionCharts {
4
5 private $constructorOptions = array();
6
7 private $constructorTemplate = '
8 <script type="text/javascript">
9 FusionCharts.ready(function () {
10 new FusionCharts(__constructorOptions__);
11 });
12 </script>';
13
14 private $renderTemplate = '
15 <script type="text/javascript">
16 FusionCharts.ready(function () {
17 FusionCharts("__chartId__").render();
18 });
19 </script>
20 ';
21
22 // constructor
23 function __construct($type, $id, $width = 400, $height = 300, $renderAt = null, $dataFormat = null, $dataSource = null) {
24 isset($type) ? $this->constructorOptions['type'] = $type : '';
25 isset($id) ? $this->constructorOptions['id'] = $id : 'php-fc-'.time();
26 isset($width) ? $this->constructorOptions['width'] = $width : '';
27 isset($height) ? $this->constructorOptions['height'] = $height : '';
28 isset($renderAt) ? $this->constructorOptions['renderAt'] = $renderAt : '';
29 isset($dataFormat) ? $this->constructorOptions['dataFormat'] = $dataFormat : '';
30 isset($dataSource) ? $this->constructorOptions['dataSource'] = $dataSource : '';
31
32 $tempArray = array();
33 foreach($this->constructorOptions as $key => $value) {
34 if ($key === 'dataSource') {
35 $tempArray['dataSource'] = '__dataSource__';
36 } else {
37 $tempArray[$key] = $value;
38 }
39 }
40
41 $jsonEncodedOptions = json_encode($tempArray);
42
43 if ($dataFormat === 'json') {
44 $jsonEncodedOptions = preg_replace('/\"__dataSource__\"/', $this->constructorOptions['dataSource'], $jsonEncodedOptions);
45 } elseif ($dataFormat === 'xml') {
46 $jsonEncodedOptions = preg_replace('/\"__dataSource__\"/', '\'__dataSource__\'', $jsonEncodedOptions);
47 $jsonEncodedOptions = preg_replace('/__dataSource__/', $this->constructorOptions['dataSource'], $jsonEncodedOptions);
48 } elseif ($dataFormat === 'xmlurl') {
49 $jsonEncodedOptions = preg_replace('/__dataSource__/', $this->constructorOptions['dataSource'], $jsonEncodedOptions);
50 } elseif ($dataFormat === 'jsonurl') {
51 $jsonEncodedOptions = preg_replace('/__dataSource__/', $this->constructorOptions['dataSource'], $jsonEncodedOptions);
52 }
53 $newChartHTML = preg_replace('/__constructorOptions__/', $jsonEncodedOptions, $this->constructorTemplate);
54
55 echo $newChartHTML;
56 }
57
58 // render the chart created
59 // It prints a script and calls the FusionCharts javascript render method of created chart
60 function render() {
61 $renderHTML = preg_replace('/__chartId__/', $this->constructorOptions['id'], $this->renderTemplate);
62 echo $renderHTML;
63 }
64
65 }
66 ?>
67