post_type == 'gvn_schart'): if (!current_user_can('manage_options')) { echo '

Only administrators can manage this page
'; die(); } echo '
'; if (empty($_GET["post"]) and strpos($_SERVER["REQUEST_URI"], "post-new") === false): $gf_message = 'Use Add new button above to create new sql report. And click on any existing rule names below to manage them. '; else: $gf_message = ' 1. Give any name to your report.
2. Choose chart type, type sql query, enter field names, labels and then press to Publish/Update
3. After update you will see needed shortcode below. You can use that shortcode anywhere in your website: in pages, posts, widgets etc.
'; ?> ' . $gf_message . '
', 'guaven_sqlcharts'); echo '
Contact us for custom reports
'; endif; } add_action('admin_notices', 'guaven_sqlcharts_my_admin_notice'); function guaven_sqlcharts_enqueue_main_style() { wp_enqueue_style('guaven_sqlcharts_main_style', plugins_url('guaven_sqlcharts.css', __FILE__)); } add_action('admin_enqueue_scripts', 'guaven_sqlcharts_enqueue_main_style'); function guaven_sqlcharts_isJson($string) { json_decode($string); return (json_last_error() == JSON_ERROR_NONE); } add_action('init', 'guaven_sqlcharts_register_post'); function guaven_sqlcharts_register_post() { //register_taxonomy('guaven_update_push_tag', 'termin'); register_post_type('gvn_schart', array( 'labels' => array( 'name' => __('My SQL Charts'), 'singular_name' => __('My SQL chart') ), 'public' => true, //'taxonomies' => array('guaven_update_push_tag'), 'supports' => array( 'title', 'postmeta' ), 'register_meta_box_cb' => 'guaven_sqlcharts_metabox_area' )); guaven_sqlcharts_load_defaults(); } add_action('admin_footer', 'guaven_sqlcharts_admin_front'); function guaven_sqlcharts_admin_front() { global $post; if (!empty($post) and $post->post_type == 'gvn_schart') { ?>

Choose your graph


Your SQL code

(Use double " " quotes instead of single ' ' ones)

Need help with custom SQL reports? Contact us.


Arguments

Label for Y axis:

SQL field name of Y axis (Write corresponding SQL field name here, which has a number value. f.e. post_count):

Label for X axis:

SQL field name of X axis (Write corresponding SQL field name here, which usually has a string value. f.e. display_name):


Width and height (with px. don't type px itself, just numbers)


ID, 'guaven_sqlcharts_graphtype', true) != '') { ?>

Text shortcode: [gvn_schart id="ID; ?>"]

PHP shorcode: <?php echo do_shortcode(' [gvn_schart id="ID; ?>"]'); ?>

Note: Shortcodes supports width and height attributes. F.e. [gvn_schart id="1" width="500" height="400"]. If no attributes, default width, height (which you enter in this page above) will be used.

Demo

ID . '"]'); } } function gvn_schart_save_metabox_area($post_id, $post) { if (!isset($_POST['meta_box_nonce_field']) or !wp_verify_nonce($_POST['meta_box_nonce_field'], 'meta_box_nonce_action')) { return $post->ID; } $fields = array( "guaven_sqlcharts_chartheight", "guaven_sqlcharts_chartwidth", "guaven_sqlcharts_graphtype", "guaven_sqlcharts_code", "guaven_sqlcharts_xarg_s", "guaven_sqlcharts_xarg_l", "guaven_sqlcharts_yarg_s", "guaven_sqlcharts_yarg_l" ); foreach ($fields as $key => $value) { update_post_meta($post->ID, $value, esc_attr($_POST[$value])); } } add_action('save_post', 'gvn_schart_save_metabox_area', 1, 2); // save the custom fields function gvn_schart_libloads($type, $step) { $stty = array( 'bar' => array( 'packages' => "'corechart', 'bar'", 'charts' => "BarChart" ), 'column' => array( 'packages' => "'corechart', 'bar'", 'charts' => "ColumnChart" ), 'area' => array( 'packages' => "'corechart'", 'charts' => "AreaChart" ), 'pie' => array( 'packages' => "'corechart'", 'charts' => "PieChart" ), '3dpie' => array( 'packages' => "'corechart'", 'charts' => "PieChart" ) ); return $stty[$type][$step]; } function gvn_schart_shortcode($atts) { global $wpdb; $sql = html_entity_decode(get_post_meta($atts['id'], 'guaven_sqlcharts_code', true)); $blacklister = array( "delete", "update", "insert", "drop", "truncate" ); //add all $blacklister_f = 0; foreach ($blacklister as $key => $value) { if (strpos($sql, $value) !== false) $blacklister_f = 1; } if ($blacklister_f == 1) return 'You given SQL code contains forbidden commands. Remember that you should only use SELECT queries'; $fvs = $wpdb->get_results($sql); $wpdb->show_errors(); ob_start(); $wpdb->print_error(); $printerror = ob_get_clean(); if ($printerror != '' and strpos($printerror, "[]") === false) return $printerror; elseif (empty($fvs)) return 'Your SQL returnes empty date, please recheck your SQL query above'; else { ob_start(); ?>
"DESC", "orderby" => "count", "number" => 10 )); $html = ''; $itag = 0; $html60 = ''; foreach ($tags as $tag) { $itag++; $html_temp .= "['{$tag->name}', {$tag->count}, '#b87333'],"; } ?> var data = google.visualization.arrayToDataTable([ ['Element', 'Density', { role: 'style' }], ]); var options = { chart: { title: 'Company Performance', subtitle: 'Sales, Expenses, and Profit: 2014-2017', } };