PluginProbe
SQL Chart Builder / 2.3.4
SQL Chart Builder v2.3.4
3.0.4 3.0.3 3.0.2 3.0.1 trunk 1.0.2 1.0.3 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.7.1 2.3.7.2 2.3.8 3.0.0
sql-chart-builder / googlecharts-deprecated.php

googlecharts-deprecated.php in SQL Chart Builder 2.3.4, at googlecharts-deprecated.php

143 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) {
3 die;
4 }
5 /*********************************Google Charts section**************************************/
6
7 function guaven_sqlcharts_libloads($type, $step)
8 {
9 $stty = array(
10 'bar' => array(
11 'packages' => "'corechart', 'bar'",
12 'charts' => "BarChart"
13 ),
14 'column' => array(
15 'packages' => "'corechart', 'bar'",
16 'charts' => "ColumnChart"
17 ),
18 'area' => array(
19 'packages' => "'corechart'",
20 'charts' => "AreaChart"
21 ),
22 'pie' => array(
23 'packages' => "'corechart'",
24 'charts' => "PieChart"
25 ),
26 '3dpie' => array(
27 'packages' => "'corechart'",
28 'charts' => "PieChart"
29 )
30 );
31
32 return $stty[$type][$step];
33 }
34
35
36 function guaven_sqlcharts_google_shortcode($atts)
37 {
38 wp_enqueue_script('guaven_sqlcharts_googlechart', 'https://www.gstatic.com/charts/loader.js');
39 wp_enqueue_style('guaven_sqlcharts_main_style', plugins_url('asset/guaven_sqlcharts.css', __FILE__),array(),GVNSQLCHARTS_VERSION);
40 global $wpdb;
41 $sql = html_entity_decode(get_post_meta($atts['id'], 'guaven_sqlcharts_code', true));
42 $sql=gvn_chart_put_variables($sql,$atts['id']);
43 $blacklister_f = gvn_chart_check_sql_query($sql);
44 if ($blacklister_f == 1)
45 return 'You given SQL code contains forbidden commands. Remember that you should only use SELECT queries';
46
47 for($i=1;$i<20;$i++){ $replacearg=!empty($atts["arg".$i])?$atts["arg".$i]:0;
48 $sql=str_replace("{arg".$i."}",esc_sql($replacearg),$sql);}
49 $sql_arr=explode(";",$sql);
50 $fvs = $wpdb->get_results($sql_arr[0]);
51
52 $wpdb->show_errors();
53 ob_start();
54 $wpdb->print_error();
55 $printerror = ob_get_clean();
56
57 if ($printerror != '' and strpos($printerror, "[]") === false)
58 return $printerror;
59 elseif (empty($fvs))
60 return 'Your SQL returnes empty date, please recheck your SQL query above';
61 else {
62 ob_start();
63 global $sqlcharts_inserted_script;
64 if (empty($sqlcharts_inserted_script))
65 $sqlcharts_inserted_script = 1;?>
66 <script type="text/javascript">;
67 google.charts.load('current', {'packages':[<?php
68 $tip_g = get_post_meta($atts['id'], 'guaven_sqlcharts_graphtype', true);
69
70 echo guaven_sqlcharts_libloads($tip_g, 'packages'); ?>]});
71 google.charts.setOnLoadCallback(drawChart_<?php echo $sqlcharts_inserted_script;?>);
72 csv_data='';csv_title='';
73 function drawChart_<?php echo $sqlcharts_inserted_script;?>() {
74 <?php
75 $html_temp = '';
76 $csv_temp = '';
77 $post_g = get_post($atts['id']);
78 $xarg_s = get_post_meta($atts['id'], 'guaven_sqlcharts_xarg_s', true);
79 $xarg_l = get_post_meta($atts['id'], 'guaven_sqlcharts_xarg_l', true);
80 $yarg_s = get_post_meta($atts['id'], 'guaven_sqlcharts_yarg_s', true);
81 $yarg_l = get_post_meta($atts['id'], 'guaven_sqlcharts_yarg_l', true);
82
83 $graph_width = get_post_meta($atts['id'], 'guaven_sqlcharts_chartwidth', true);
84 $graph_height = get_post_meta($atts['id'], 'guaven_sqlcharts_chartheight', true);
85
86 if (!empty($atts["width"])) {
87 $graph_width = intval($atts['width']);
88 }
89 if (!empty($atts["height"])) {
90 $graph_height = intval($atts['height']);
91 }
92
93 foreach ($fvs as $fv) {
94 $html_temp .= "['{$fv->$xarg_s}', {$fv->$yarg_s}, '#b87333'],";
95 $csv_temp .= addslashes($fv->$xarg_s) . "," . addslashes($fv->$yarg_s) . "<br>";
96
97 }
98 ?>
99 csv_data='<?php echo $csv_temp;?>';
100 csv_title='<?php echo '' . $xarg_l . ',' . $yarg_l . '';?><br>';
101 var data = google.visualization.arrayToDataTable([
102 ['<?php echo $xarg_l;?>', '<?php echo $yarg_l;?>', { role: 'style' }],
103 <?php echo $html_temp;?>
104 ]);
105
106 var options = {
107 <?php echo $tip_g == '3dpie' ? "is3D: true," : '';?>
108 chart_<?php echo $sqlcharts_inserted_script;?>: {
109 title: '<?php echo $post_g->post_title;?>',
110 }
111 };
112
113 var chart_<?php
114 echo $sqlcharts_inserted_script;
115 ?> = new google.visualization.<?php
116 echo guaven_sqlcharts_libloads(get_post_meta($atts['id'], 'guaven_sqlcharts_graphtype', true), 'charts');
117 ?>(document.getElementById('columnchart_material_<?php echo $sqlcharts_inserted_script;?>'));
118
119
120 var my_div = document.getElementById('chart_div_<?php echo $sqlcharts_inserted_script;?>');
121 google.visualization.events.addListener(chart_<?php echo $sqlcharts_inserted_script;?>, 'ready', function () {
122 my_div.innerHTML = '<img src="' + chart_<?php echo $sqlcharts_inserted_script;?>.getImageURI() + '">';
123 });
124
125 chart_<?php echo $sqlcharts_inserted_script;?>.draw(data, options);
126 }
127 </script>
128
129 <?php echo gvn_chart_top_form($atts);?>
130
131 <div id="chart_div_<?php echo $sqlcharts_inserted_script;?>" style="display:none"></div>
132 <a href="javascript://" onclick="saveaspng('chart_div_<?php echo $sqlcharts_inserted_script;?>')">Save as PNG</a>
133 <a href="javascript://" onclick="exportcsv()">Export CSV</a>
134 <div id="columnchart_material_<?php echo $sqlcharts_inserted_script;?>" style="width:<?php echo $graph_width > 0 ? intval($graph_width) : '500';?>px;
135 height: <?php echo $graph_height > 0 ? intval($graph_height) : '400';?>px"></div>
136 <?php
137 $sqlcharts_inserted_script++;
138
139 return ob_get_clean();
140 }
141 }
142 add_shortcode('gvn_schart', 'guaven_sqlcharts_google_shortcode');
143