PluginProbe
SQL Chart Builder / 3.0.3
SQL Chart Builder v3.0.3
3.0.5 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
← All changes | initial_data.php +96 -40 1.0.23.0.3 View file →
@@ -1,58 +1,114 @@
1 1 <?php
2 -function gvn_chart_sample_nonxml_data(){
3 -$data['titles']=array(
4 - 'Posts by month',
5 - 'Posts by year',
6 - 'Popular users/publishers',
7 - );
2 +if (!defined('ABSPATH')) {
3 + die;
4 +}
5 +function gvn_chart_sample_nonxml_data()
6 +{
7 + $data['titles'] = array(
8 + 'Sample: Posts by month',
9 + 'Sample: Posts and non-Posts by month',
10 + 'Sample: Posts by year',
11 + 'Sample: Popular users/publishers'
12 + );
13 + global $wpdb;
14 + $data['sql_queries'] = array(
15 + "select count(*) postcount,SUBSTRING(`post_date`,6,2) monthnum,SUBSTRING(`post_date`,1,4) yearnum,SUBSTRING(`post_date`,1,7) monthandyear from $wpdb->posts group by monthnum,yearnum order by monthnum ",
8 16
9 -$data['sql_queries']=array(
10 - 'select count(*) pcount,SUBSTRING(`post_date`,6,2) aysay,SUBSTRING(`post_date`,1,4) ilsay,SUBSTRING(`post_date`,1,7) ayilsay from wp_posts group by aysay,ilsay order by aysay ',
17 + "select count(*) postcount,SUBSTRING(`post_date`,6,2) monthnum,SUBSTRING(`post_date`,1,4) yearnum,SUBSTRING(`post_date`,1,7) monthandyear from $wpdb->posts where post_type=\"post\" group by monthnum,yearnum order by monthnum ;
18 + select count(*) postcount,SUBSTRING(`post_date`,6,2) monthnum,SUBSTRING(`post_date`,1,4) yearnum,SUBSTRING(`post_date`,1,7) monthandyear from $wpdb->posts where post_type!=\"post\" group by monthnum,yearnum order by monthnum",
11 19
12 - 'select count(*) pcount, SUBSTR(`post_date`,1,4) il from wp_posts group by il order by il asc limit 10 ',
20 + "select count(*) postcount, SUBSTR(`post_date`,1,4) yearnum from $wpdb->posts group by yearnum order by yearnum asc limit 10 ",
13 21
14 - 'select count(*) as pcount,a.post_author,b.display_name as dname
15 -from wp_posts a
16 -inner join wp_users b ON a.post_author=b.ID
17 -where a.post_status="publish"
18 -group by a.post_author order by pcount desc limit 10',
19 - );
22 + "select count(*) as postcount,a.post_author,b.display_name as dname
23 +from $wpdb->posts a
24 +inner join $wpdb->users b ON a.post_author=b.ID
25 +where a.post_status=\"publish\"
26 +group by a.post_author order by postcount desc limit 10"
27 + );
20 28
21 -$data['others']=array(
29 + $data['others'] = array(
22 30
23 -array('Post count','pcount','Monthes','ayilsay',500,400,'column'),
31 + array(
32 + 'Post count',
33 + 'postcount',
34 + 'Monthes',
35 + 'monthandyear',
36 + 500,
37 + 400,
38 + 'bar_l'
39 + ),
24 40
25 -array('Post count','pcount','Years','il',500,400,'pie'),
41 + array(
42 + 'Posts;non-Posts',
43 + 'postcount',
44 + 'Monthes',
45 + 'monthandyear',
46 + 500,
47 + 400,
48 + 'line_l'
49 + ),
26 50
27 -array('Post count','pcount','Display name','dname',500,400,'3dpie'),
51 + array(
52 + 'Post count',
53 + 'postcount',
54 + 'Years',
55 + 'yearnum',
56 + 500,
57 + 400,
58 + 'pie_l'
59 + ),
28 60
61 + array(
62 + 'Post count',
63 + 'postcount',
64 + 'Display name',
65 + 'dname',
66 + 500,
67 + 400,
68 + 'donut_l'
69 + )
29 70
30 - );
31 71
32 -$existence= get_page_by_title( 'Posts by month', OBJECT, 'gvn_schart' );
72 + );
33 73
34 -if (empty($existence)){
35 -foreach ($data['titles'] as $key => $value) {
36 - $newid=wp_insert_post(
37 - array('post_title' => $value,
38 - 'post_type'=>'gvn_schart',
39 - 'post_status'=>'private'
40 - )
41 - );
42 74
43 75
44 - add_post_meta($newid,'guaven_sqlcharts_code',$data["sql_queries"][$key]);
45 76
46 - add_post_meta($newid,'guaven_sqlcharts_chartwidth',$data["others"][$key][4]);
47 - add_post_meta($newid,'guaven_sqlcharts_chartheight',$data["others"][$key][5]);
48 - add_post_meta($newid,'guaven_sqlcharts_xarg_s',$data["others"][$key][1]);
49 - add_post_meta($newid,'guaven_sqlcharts_xarg_l',$data["others"][$key][0]);
50 - add_post_meta($newid,'guaven_sqlcharts_yarg_s',$data["others"][$key][3]);
51 - add_post_meta($newid,'guaven_sqlcharts_yarg_l',$data["others"][$key][2]);
52 - add_post_meta($newid,'guaven_sqlcharts_graphtype',$data["others"][$key][6]);
53 -}
54 -}
55 77
78 + foreach ($data['titles'] as $key => $value) {
79 + $args = [
80 + 'post_type' => 'gvn_schart',
81 + 'title' => $value,
82 + 'post_status' => 'any', // Adjust if you only want published posts
83 + 'numberposts' => 1,
84 + ];
85 +
86 + $query = new WP_Query($args);
87 + $existence = $query->have_posts() ? $query->posts[0] : null;
88 +
89 + // Clean up after the query
90 + wp_reset_postdata();
91 +
56 92
93 + if (empty($existence)) {
94 + $newid = wp_insert_post(array(
95 + 'post_title' => $value,
96 + 'post_type' => 'gvn_schart',
97 + 'post_status' => 'private'
98 + ));
99 + add_post_meta($newid, 'guaven_sqlcharts_code', $data["sql_queries"][$key]);
100 + add_post_meta($newid, 'guaven_sqlcharts_chartwidth', $data["others"][$key][4]);
101 + add_post_meta($newid, 'guaven_sqlcharts_chartheight', $data["others"][$key][5]);
102 + add_post_meta($newid, 'guaven_sqlcharts_xarg_s', $data["others"][$key][3]);
103 + add_post_meta($newid, 'guaven_sqlcharts_xarg_l', $data["others"][$key][2]);
104 + add_post_meta($newid, 'guaven_sqlcharts_yarg_s', $data["others"][$key][1]);
105 + add_post_meta($newid, 'guaven_sqlcharts_yarg_l', $data["others"][$key][0]);
106 + add_post_meta($newid, 'guaven_sqlcharts_graphtype', $data["others"][$key][6]);
107 +
108 + }
109 + }
110 +
111 +
112 +
57 113 }
58 -?>
114 +?>