PluginProbe
SQL Chart Builder / 3.0.4
SQL Chart Builder v3.0.4
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 | admin_metabox.php +287 -252 2.3.33.0.4 View file →
@@ -5,299 +5,334 @@
5 5
6 6 global $post;
7 7 wp_nonce_field('meta_box_nonce_action', 'meta_box_nonce_field');
8 8
9 +$gvnsql_meta = function ($key) use ($post) {
10 + return get_post_meta($post->ID, $key, true);
11 +};
9 12
10 -?>
11 -<div style="width:calc(100% - 110px);float:left">
13 +$gvnsql_rawtype = $gvnsql_meta('guaven_sqlcharts_graphtype');
14 +if ($gvnsql_rawtype == '') $gvnsql_rawtype = 'pie_l';
15 +$gvnsql_type = guaven_sqlcharts_normalize_type($gvnsql_rawtype);
16 +$gvnsql_catalog = guaven_sqlcharts_type_catalog();
17 +if (!isset($gvnsql_catalog[$gvnsql_type])) $gvnsql_type = 'pie_l';
12 18
13 -<h3>Required parameters</h3>
19 +$gvnsql_icons = array(
20 + 'pie_l' => '<svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="9" fill="none" stroke="currentColor" stroke-width="2"/><path d="M12 12V3a9 9 0 0 1 8.6 6.2L12 12z" fill="currentColor"/></svg>',
21 + 'donut_l' => '<svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="8.5" fill="none" stroke="currentColor" stroke-width="3.4" opacity=".35"/><path d="M12 3.5a8.5 8.5 0 0 1 8.1 5.9" fill="none" stroke="currentColor" stroke-width="3.4" stroke-linecap="round"/></svg>',
22 + 'polar_l' => '<svg viewBox="0 0 24 24"><path d="M12 12V4a8 8 0 0 1 8 8h-8z" fill="currentColor" opacity=".85"/><path d="M12 12h5.5a5.5 5.5 0 1 1-5.5-5.5V12z" fill="currentColor" opacity=".45"/><circle cx="12" cy="12" r="9.5" fill="none" stroke="currentColor" stroke-width="1.4" opacity=".5"/></svg>',
23 + 'radar_l' => '<svg viewBox="0 0 24 24"><path d="M12 2.5l9 6.5-3.4 10.5H6.4L3 9z" fill="none" stroke="currentColor" stroke-width="1.6"/><path d="M12 7l5 3.6-1.9 5.9H8.9L7 10.6z" fill="currentColor" opacity=".4"/></svg>',
24 + 'line_l' => '<svg viewBox="0 0 24 24"><path d="M3 18l6-7 4 3 8-9" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
25 + 'area_l' => '<svg viewBox="0 0 24 24"><path d="M3 18l6-7 4 3 8-9v14H3z" fill="currentColor" opacity=".45"/><path d="M3 18l6-7 4 3 8-9" fill="none" stroke="currentColor" stroke-width="2"/></svg>',
26 + 'steppedline_l' => '<svg viewBox="0 0 24 24"><path d="M3 18h4v-5h5V8h5V4h4" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
27 + 'bar_l' => '<svg viewBox="0 0 24 24"><rect x="4" y="11" width="4" height="9" fill="currentColor"/><rect x="10" y="5" width="4" height="15" fill="currentColor" opacity=".7"/><rect x="16" y="8" width="4" height="12" fill="currentColor" opacity=".45"/></svg>',
28 + 'horizontalbar_l' => '<svg viewBox="0 0 24 24"><rect x="3" y="4" width="15" height="4" fill="currentColor"/><rect x="3" y="10" width="18" height="4" fill="currentColor" opacity=".7"/><rect x="3" y="16" width="10" height="4" fill="currentColor" opacity=".45"/></svg>',
29 + 'stackedbar_l' => '<svg viewBox="0 0 24 24"><rect x="4" y="12" width="4" height="8" fill="currentColor"/><rect x="4" y="7" width="4" height="5" fill="currentColor" opacity=".45"/><rect x="10" y="9" width="4" height="11" fill="currentColor"/><rect x="10" y="4" width="4" height="5" fill="currentColor" opacity=".45"/><rect x="16" y="14" width="4" height="6" fill="currentColor"/><rect x="16" y="10" width="4" height="4" fill="currentColor" opacity=".45"/></svg>',
30 + 'scatter_l' => '<svg viewBox="0 0 24 24"><circle cx="6" cy="16" r="2" fill="currentColor"/><circle cx="10" cy="9" r="2" fill="currentColor" opacity=".75"/><circle cx="15" cy="13" r="2" fill="currentColor" opacity=".55"/><circle cx="19" cy="5" r="2" fill="currentColor" opacity=".85"/><circle cx="13" cy="19" r="2" fill="currentColor" opacity=".4"/></svg>',
31 +);
14 32
15 -<h4 class="gsql_h4">Step 1: Choose a chart type</h4>
33 +$gvnsql_svg_kses = array(
34 + 'svg' => array('viewbox' => array(), 'xmlns' => array()),
35 + 'path' => array('d' => array(), 'fill' => array(), 'stroke' => array(), 'stroke-width' => array(), 'stroke-linecap' => array(), 'stroke-linejoin' => array(), 'opacity' => array()),
36 + 'circle' => array('cx' => array(), 'cy' => array(), 'r' => array(), 'fill' => array(), 'stroke' => array(), 'stroke-width' => array(), 'opacity' => array()),
37 + 'rect' => array('x' => array(), 'y' => array(), 'width' => array(), 'height' => array(), 'fill' => array(), 'opacity' => array()),
38 +);
39 +?>
16 40
17 -<p>
18 -<select name="guaven_sqlcharts_graphtype" id="guaven_sqlcharts_graphtype">
19 -<option value="pie_l" <?php $smfootnote='';
20 -$guaven_sqlcharts_graphtype = get_post_meta($post->ID, 'guaven_sqlcharts_graphtype', true);
21 -echo ($guaven_sqlcharts_graphtype == 'pie_l' ? 'selected' : '');?>>Pie Chart</option>
22 -<option value="line_l" <?php echo ($guaven_sqlcharts_graphtype == 'line_l' ? 'selected' : '');?>>Line Chart</option>
23 -<option value="donut_l" <?php echo ($guaven_sqlcharts_graphtype == 'donut_l' ? 'selected' : '');?>>Donut Chart</option>
24 -<option value="bar_l" <?php echo ($guaven_sqlcharts_graphtype == 'bar_l' ? 'selected' : '');?>>Vertical Bar Chart</option>
25 -<option value="horizontalbar_l" <?php echo ($guaven_sqlcharts_graphtype == 'horizontalbar_l' ? 'selected' : '');?>>Horizontal Bar Chart</option>
26 -<option value="area_l" <?php echo ($guaven_sqlcharts_graphtype == 'area_l' ? 'selected' : '');?>>Area Chart</option>
27 -<option value="polar_l" <?php echo ($guaven_sqlcharts_graphtype == 'polar_l' ? 'selected' : '');?>>Polar Area</option>
41 +<div id="gvnsql-app">
28 42
29 -<?php
30 -if ($guaven_sqlcharts_graphtype!='' and strpos($guaven_sqlcharts_graphtype,'_l')===false) {
31 -?>
32 -<option value="pie" <?php echo ($guaven_sqlcharts_graphtype == 'pie' ? 'selected' : '');?>>Google Chart - Pie *</option>
33 -<option value="3dpie" <?php echo ($guaven_sqlcharts_graphtype == '3dpie' ? 'selected' : '');?>>Google Chart - 3D Pie *</option>
34 -<option value="column" <?php echo ($guaven_sqlcharts_graphtype == 'column' ? 'selected' : '');?>>Google Chart - Column *</option>
35 -<option value="bar" <?php echo ($guaven_sqlcharts_graphtype == 'bar' ? 'selected' : '');?>>Google Chart - Bar *</option>
36 -<option value="area" <?php echo ($guaven_sqlcharts_graphtype == 'area' ? 'selected' : '');?>>Google Chart - Area *</option>
37 -<?php
38 -$smfootnote='<br><small>
39 -* Google Chart options are deprecated and will be removed since 3.0 version.
40 -Currently those options support single queries only. Use non-Google Chart options above.
41 -</small>';
42 -} ?>
43 -</select>
44 -<?php
45 -echo $smfootnote;
46 -?>
47 -<br>
48 -</p>
43 +<?php if ($gvnsql_rawtype != $gvnsql_type) { ?>
44 + <div class="gvnsql-note gvnsql-note-migrate">
45 + This chart used the deprecated Google Chart type "<?php echo esc_html($gvnsql_rawtype); ?>".
46 + It has been automatically mapped to the equivalent modern chart type below — just press Update to finish the migration. Nothing else changes.
47 + </div>
48 +<?php } ?>
49 49
50 -<p><label><input type="checkbox" name="guaven_sqlcharts_tablepart" value="1" <?php echo get_post_meta($post->ID, 'guaven_sqlcharts_tablepart', true)!=''?'checked':''; ?>>
51 - Show table-view data below the graph</lable></p>
52 -</div>
53 -<div style="width:110px;float:left"><img src="<?php echo plugin_dir_url( __FILE__ ) . 'asset/img/pie.png';?>" class="charttype" style="opacity:0.5;margin-top:20px;float:right;width:100px"></div>
54 -<div style="clear:both;display:block"></div>
55 -<hr>
50 +<nav class="gvnsql-tabs" id="gvnsql-tabs">
51 + <button type="button" class="gvnsql-tab active" data-tab="data">Chart &amp; Data</button>
52 + <button type="button" class="gvnsql-tab" data-tab="filters">Input Filters</button>
53 + <button type="button" class="gvnsql-tab" data-tab="style">Style</button>
54 + <button type="button" class="gvnsql-tab" data-tab="advanced">Advanced</button>
55 +</nav>
56 56
57 +<!-- ============ TAB 1: CHART & DATA ============ -->
58 +<section class="gvnsql-section active" data-tab="data">
57 59
60 + <h4 class="gvnsql-step">Pick a chart type</h4>
61 + <div class="gvnsql-typegrid">
62 + <?php foreach ($gvnsql_catalog as $slug => $info) { ?>
63 + <label class="gvnsql-typecard<?php echo $slug == $gvnsql_type ? ' selected' : ''; ?>" data-type="<?php echo esc_attr($slug); ?>">
64 + <input type="radio" name="guaven_sqlcharts_graphtype" value="<?php echo esc_attr($slug); ?>" <?php checked($slug, $gvnsql_type); ?>>
65 + <span class="gvnsql-typeicon"><?php echo wp_kses($gvnsql_icons[$slug], $gvnsql_svg_kses); ?></span>
66 + <span class="gvnsql-typelabel"><?php echo esc_html($info['label']); ?></span>
67 + </label>
68 + <?php } ?>
69 + </div>
58 70
71 + <?php foreach ($gvnsql_catalog as $slug => $info) { ?>
72 + <div class="gvnsql-guide" data-guide="<?php echo esc_attr($slug); ?>" <?php echo $slug == $gvnsql_type ? '' : 'style="display:none"'; ?>>
73 + <div class="gvnsql-guide-text">
74 + <strong><?php echo esc_html($info['label']); ?> chart — when to use it:</strong>
75 + <?php echo esc_html($info['guide']); ?>
76 + </div>
77 + <div class="gvnsql-guide-example">
78 + <code><?php echo esc_html($info['example_sql']); ?></code>
79 + <button type="button" class="button gvnsql-use-example"
80 + data-sql="<?php echo esc_attr($info['example_sql']); ?>"
81 + data-x="<?php echo esc_attr($info['example_x']); ?>"
82 + data-y="<?php echo esc_attr(strpos($info['example_y'], ';') === false ? $info['example_y'] : 'postcount'); ?>"
83 + data-yl="<?php echo esc_attr($info['example_y']); ?>">Use this example</button>
84 + </div>
85 + </div>
86 + <?php } ?>
59 87
60 -<h4 class="gsql_h4">Step 2: Enter Your SQL Query </h4>
61 -<p>
62 -<textarea name="guaven_sqlcharts_code" id="guaven_sqlcharts_code" style="width:100%" rows="6"><?php
63 -echo (get_post_meta($post->ID, 'guaven_sqlcharts_code', true) != '' ? get_post_meta($post->ID, 'guaven_sqlcharts_code', true) : '');
64 -?>
65 -</textarea>
66 -<br><small>Separate sql queries with ";" if you would like to use multiple queries to build comparison graphs. <a href="https://www.dropbox.com/s/l9xggkeliqdswo9/mysqlchart_example.png?dl=0" target="_blank">See example</a>
67 -<br>
68 -<b>Some supported dynamic tags can be used in your query: {current_user_id},{current_user_login},{current_user_email},{current_user_display_name}.</b>
69 -</small>
70 -</p>
88 + <h4 class="gvnsql-step">Build your SQL query</h4>
71 89
72 -<hr>
90 + <div class="gvnsql-toolbar" id="gvnsql-toolbar">
91 + <span class="gvnsql-toolbar-group">
92 + <button type="button" class="gvnsql-kw" data-insert="SELECT ">SELECT</button>
93 + <button type="button" class="gvnsql-kw" data-insert="COUNT(*) ">COUNT(*)</button>
94 + <button type="button" class="gvnsql-kw" data-insert="FROM ">FROM</button>
95 + <button type="button" class="gvnsql-kw" data-insert="WHERE ">WHERE</button>
96 + <button type="button" class="gvnsql-kw" data-insert="AND ">AND</button>
97 + <button type="button" class="gvnsql-kw" data-insert="GROUP BY ">GROUP BY</button>
98 + <button type="button" class="gvnsql-kw" data-insert="ORDER BY ">ORDER BY</button>
99 + <button type="button" class="gvnsql-kw" data-insert="DESC ">DESC</button>
100 + <button type="button" class="gvnsql-kw" data-insert="LIMIT 10 ">LIMIT</button>
101 + </span>
102 + <span class="gvnsql-toolbar-group">
103 + <select id="gvnsql-table-select"><option value="">Insert table…</option></select>
104 + <select id="gvnsql-column-select"><option value="">Insert column…</option></select>
105 + <select id="gvnsql-tag-select"><option value="">Insert filter tag…</option></select>
106 + </span>
107 + </div>
73 108
109 + <div class="gvnsql-editorwrap">
110 + <textarea name="guaven_sqlcharts_code" id="guaven_sqlcharts_code" rows="8" spellcheck="false"
111 + placeholder="Start typing your query — autocomplete will suggest SQL keywords, your real table names and column names. Or click the buttons above to build the query step by step."><?php
112 + echo esc_textarea(guaven_sqlcharts_get_code($post->ID));
113 + ?></textarea>
114 + </div>
115 + <p class="gvnsql-hint">
116 + Tip: press <b>Ctrl+Space</b> for suggestions at any point. Separate multiple queries with <b>;</b> to build comparison charts.
117 + Supported dynamic tags: <code>{current_user_id}</code>, <code>{current_user_login}</code>, <code>{current_user_email}</code>, <code>{current_user_display_name}</code>
118 + — plus every filter you define in the Input Filters tab.
119 + </p>
74 120
121 + <div class="gvnsql-mapbox">
122 + <h4 class="gvnsql-step gvnsql-mapbox-title"><span class="gvnsql-mapbox-badge">Final step</span> Map query columns to the chart</h4>
123 + <p class="gvnsql-hint gvnsql-mapbox-hint">Tell the chart which query column goes to which axis. The dropdowns are filled with the columns found in your SQL query above.</p>
124 + <div class="gvnsql-grid2">
125 + <div class="gvnsql-field">
126 + <label for="guaven_sqlcharts_xarg_s_select">X axis — column from your query</label>
127 + <select id="guaven_sqlcharts_xarg_s_select" class="gvnsql-colselect" data-target="guaven_sqlcharts_xarg_s"></select>
128 + <input type="text" name="guaven_sqlcharts_xarg_s" id="guaven_sqlcharts_xarg_s" class="gvnsql-colcustom" list="gvnsql-columns"
129 + value="<?php echo esc_attr($gvnsql_meta('guaven_sqlcharts_xarg_s')); ?>" placeholder="e.g. monthandyear">
130 + <small>The column whose values become the labels/X positions.</small>
131 + </div>
132 + <div class="gvnsql-field">
133 + <label for="guaven_sqlcharts_yarg_s_select">Y axis — column from your query</label>
134 + <select id="guaven_sqlcharts_yarg_s_select" class="gvnsql-colselect" data-target="guaven_sqlcharts_yarg_s"></select>
135 + <input type="text" name="guaven_sqlcharts_yarg_s" id="guaven_sqlcharts_yarg_s" class="gvnsql-colcustom" list="gvnsql-columns"
136 + value="<?php echo esc_attr($gvnsql_meta('guaven_sqlcharts_yarg_s')); ?>" placeholder="e.g. postcount">
137 + <small>The numeric column that becomes the chart values. Use one output name even with multiple queries.</small>
138 + </div>
139 + <div class="gvnsql-field">
140 + <label for="guaven_sqlcharts_xarg_l">X axis label (display text)</label>
141 + <input type="text" name="guaven_sqlcharts_xarg_l" id="guaven_sqlcharts_xarg_l"
142 + value="<?php echo esc_attr($gvnsql_meta('guaven_sqlcharts_xarg_l')); ?>" placeholder="e.g. Months">
143 + <small>Shown as the X axis title on Bar, Line and Scatter charts, and as the first table-view header.</small>
144 + </div>
145 + <div class="gvnsql-field">
146 + <label for="guaven_sqlcharts_yarg_l">Y axis label / series name(s)</label>
147 + <input type="text" name="guaven_sqlcharts_yarg_l" id="guaven_sqlcharts_yarg_l"
148 + value="<?php echo esc_attr($gvnsql_meta('guaven_sqlcharts_yarg_l')); ?>" placeholder="e.g. Post count">
149 + <small>Shown in the legend and as the Y axis title. With multiple queries, separate one name per query with ";" (then only the legend is used).</small>
150 + </div>
151 + </div>
152 + </div>
153 + <datalist id="gvnsql-columns"></datalist>
75 154
155 + <p class="gvnsql-checkbox-row"><label><input type="checkbox" name="guaven_sqlcharts_tablepart" value="1" <?php echo $gvnsql_meta('guaven_sqlcharts_tablepart') != '' ? 'checked' : ''; ?>>
156 + Show table-view data below the graph</label></p>
157 +</section>
76 158
159 +<!-- ============ TAB 2: INPUT FILTERS ============ -->
160 +<section class="gvnsql-section" data-tab="filters">
161 + <h4 class="gvnsql-step">Input filters — no code needed</h4>
162 + <p class="gvnsql-hint">Each filter becomes an input field above your chart at the front-end, and a <code>{tag}</code> placed inside the SQL query.
163 + The tag dropdown suggests <code>{tags}</code> already written in your query and columns from its WHERE part.
164 + Example: pick or type <b>fromdate</b> with type <b>date</b>, click "Insert into query" and complete the condition, e.g. <code>WHERE post_date &gt; {fromdate}</code>.</p>
77 165
78 -<h4 class="gsql_h4">Step 3: Set Arguments and Values for a Chart - See <a href="https://www.dropbox.com/s/5tt0se24x6hfas0/mysqlchart_example-1.png?dl=0" target="_blank">Example 1</a>
79 - and <a href="https://www.dropbox.com/s/s8ygh1zngo2ajzi/mysqlchart_example-4.png?dl=0" target="_blank">Example 2</a></h4>
80 -<p>
81 -Label for X axis: <br><input type="text" name="guaven_sqlcharts_xarg_l" id="guaven_sqlcharts_xarg_l" value="<?php
82 -echo get_post_meta($post->ID, 'guaven_sqlcharts_xarg_l', true);
83 -?>">
84 -<br>
85 -<small>This is just label text for query argument, you can type any desired name here.</small>
86 -</p>
166 + <div id="gvnsql-filters-rows"></div>
87 167 <p>
88 -SQL field name of X axis:
89 -<br>
90 -<input type="text" name="guaven_sqlcharts_xarg_s" id="guaven_sqlcharts_xarg_s" value="<?php
91 -echo get_post_meta($post->ID, 'guaven_sqlcharts_xarg_s', true);
92 -?>"><br>
93 -<small>Write corresponding SQL field name here. f.e. display_name, post_date</small>
94 -</p>
168 + <button type="button" class="button button-secondary" id="gvnsql-add-filter">+ Add filter</button>
169 + <button type="button" class="button-link" id="gvnsql-raw-toggle">Edit raw format</button>
170 + </p>
95 171
96 -<p>
97 -Label for Y axis: <br><input type="text" name="guaven_sqlcharts_yarg_l" id="guaven_sqlcharts_yarg_l" value="<?php
98 -echo get_post_meta($post->ID, 'guaven_sqlcharts_yarg_l', true);
99 -?>">
100 -<br><small>This is just label text for query's main value, you can type any desired name here.<br>
101 - Use ";" separated label names if you have more than one query inside SQL CODE field.</small>
102 -</p>
103 -<p>
104 -SQL field name of Y axis:
105 -<br>
106 -<input type="text" name="guaven_sqlcharts_yarg_s" id="guaven_sqlcharts_yarg_s" value="<?php
107 -echo get_post_meta($post->ID, 'guaven_sqlcharts_yarg_s', true);
108 -?>"><br>
109 -<small>Write corresponding SQL field name here. f.e. post_count) - Use one single output name even if you have multiple queries in SQL CODE field.</small>
172 + <textarea name="guaven_sqlcharts_variables" id="guaven_sqlcharts_variables" class="gvnsql-raw" rows="2"><?php
173 + echo esc_textarea(trim($gvnsql_meta('guaven_sqlcharts_variables')));
174 + ?></textarea>
175 + <p class="gvnsql-hint gvnsql-raw">Raw format: <i>name~default~label~type | name~default~label~type</i> (type: text, number or date)</p>
110 176
111 -</p>
177 + <div class="gvnsql-grid2" style="margin-top:14px">
178 + <div class="gvnsql-field">
179 + <label>Visibility</label>
180 + <label class="gvnsql-inlinecheck"><input type="checkbox" name="guaven_sqlcharts_formpartrole" value="1"
181 + <?php echo $gvnsql_meta('guaven_sqlcharts_formpartrole') !== '' ? 'checked' : ''; ?>>
182 + Hide the filters form from not-logged-in visitors</label>
183 + </div>
184 + <div class="gvnsql-field">
185 + <label for="guaven_sqlcharts_formpartbutton">Submit button text</label>
186 + <input type="text" name="guaven_sqlcharts_formpartbutton" id="guaven_sqlcharts_formpartbutton"
187 + value="<?php echo esc_attr($gvnsql_meta('guaven_sqlcharts_formpartbutton')); ?>" placeholder="OK">
188 + </div>
189 + </div>
190 +</section>
112 191
113 -<hr>
114 -<h3>Optional parameters</h3>
192 +<!-- ============ TAB 3: STYLE ============ -->
193 +<section class="gvnsql-section" data-tab="style">
194 + <h4 class="gvnsql-step">Colors</h4>
195 + <p class="gvnsql-hint">One color per data series (or per slice for circular charts). Leave empty to use the built-in palette.</p>
196 + <div id="gvnsql-colors-rows" class="gvnsql-colors"></div>
197 + <p><button type="button" class="button button-secondary" id="gvnsql-add-color">+ Add color</button></p>
198 + <input type="hidden" name="guaven_sqlcharts_colors" id="guaven_sqlcharts_colors"
199 + value="<?php echo esc_attr($gvnsql_meta('guaven_sqlcharts_colors')); ?>">
115 200
201 + <div class="gvnsql-grid2">
202 + <div class="gvnsql-field">
203 + <label for="guaven_sqlcharts_legend_position">Legend position</label>
204 + <?php $gvnsql_legend = esc_attr($gvnsql_meta('guaven_sqlcharts_legend_position')); ?>
205 + <select name="guaven_sqlcharts_legend_position" id="guaven_sqlcharts_legend_position">
206 + <option value="default">Hidden (default)</option>
207 + <option value="top" <?php selected($gvnsql_legend, 'top'); ?>>Show at the top</option>
208 + <option value="bottom" <?php selected($gvnsql_legend, 'bottom'); ?>>Show at the bottom</option>
209 + <option value="left" <?php selected($gvnsql_legend, 'left'); ?>>Show at the left</option>
210 + <option value="right" <?php selected($gvnsql_legend, 'right'); ?>>Show at the right</option>
211 + </select>
212 + <small>The legend lists your series names (Y label field).</small>
213 + </div>
214 + <div class="gvnsql-field">
215 + <label>Value labels</label>
216 + <label class="gvnsql-inlinecheck"><input type="checkbox" name="guaven_sqlcharts_forcetooltips" id="guaven_sqlcharts_forcetooltips" value="1"
217 + <?php echo $gvnsql_meta('guaven_sqlcharts_forcetooltips') != '' ? 'checked' : ''; ?>>
218 + Always show values on the chart (not only on mouse-over). Works with every chart type.</label>
219 + </div>
220 + <div class="gvnsql-field">
221 + <label for="guaven_sqlcharts_chartwidth">Max width (px)</label>
222 + <input type="number" name="guaven_sqlcharts_chartwidth" id="guaven_sqlcharts_chartwidth"
223 + value="<?php echo esc_attr($gvnsql_meta('guaven_sqlcharts_chartwidth')); ?>" placeholder="auto">
224 + <small>Leave empty for full container width (responsive).</small>
225 + </div>
226 + <div class="gvnsql-field">
227 + <label for="guaven_sqlcharts_chartheight">Height (px)</label>
228 + <input type="number" name="guaven_sqlcharts_chartheight" id="guaven_sqlcharts_chartheight"
229 + value="<?php echo esc_attr($gvnsql_meta('guaven_sqlcharts_chartheight')); ?>" placeholder="auto">
230 + <small>Leave empty to keep the natural aspect ratio.</small>
231 + </div>
232 + </div>
233 +</section>
116 234
117 -<h4 class="gsql_h4">Dynamic filters - See <a href="https://www.dropbox.com/s/6xa6gk7uc75b8me/mysqlchart_example-2.png?dl=0" target="_blank">Example Settings</a>
118 - and <a href="https://www.dropbox.com/s/fq1gnqcqdbj65ch/mysqlchart_example-3.png?dl=0" target="_blank">Example Demo</a>
119 - </h4>
120 -<p>By using this section you can create dynamic variables inside SQL code. It also creates corresponding dynamic input form above each chart. <a class="btn button dynamicfieldbutton">Show/Hide</a></p>
121 -<script>
122 -jQuery(".dynamicfieldbutton").click(function(){jQuery(".dynamicfielddiv").toggle()});
123 -plugindirurl='<?php echo plugin_dir_url( __FILE__ ) . 'asset/img/'; ?>';
124 -jQuery("#guaven_sqlcharts_graphtype").change(function(){
125 - jQuery(".charttype").attr("src",plugindirurl+jQuery(this).val().replace("_l","").replace("column","bar")+'.png');
126 -});
127 -jQuery("#guaven_sqlcharts_graphtype").trigger('change');
235 +<!-- ============ TAB 4: ADVANCED ============ -->
236 +<section class="gvnsql-section" data-tab="advanced">
237 + <h4 class="gvnsql-step">Axis behavior (Line and Bar charts)</h4>
238 + <div class="gvnsql-checkgrid">
239 + <label class="gvnsql-inlinecheck"><input type="checkbox" name="guaven_sqlcharts_begin_with_0_x" value="1"
240 + <?php echo $gvnsql_meta('guaven_sqlcharts_begin_with_0_x') !== '' ? 'checked' : ''; ?>> Force X axis to start at 0</label>
241 + <label class="gvnsql-inlinecheck"><input type="checkbox" name="guaven_sqlcharts_begin_with_0_y" value="1"
242 + <?php echo $gvnsql_meta('guaven_sqlcharts_begin_with_0_y') !== '' ? 'checked' : ''; ?>> Force Y axis to start at 0</label>
243 + <label class="gvnsql-inlinecheck"><input type="checkbox" name="guaven_sqlcharts_round_y_values" value="1"
244 + <?php echo $gvnsql_meta('guaven_sqlcharts_round_y_values') !== '' ? 'checked' : ''; ?>> Show only round numbers on the Y axis</label>
245 + <label class="gvnsql-inlinecheck"><input type="checkbox" name="guaven_sqlcharts_nostacked" value="1"
246 + <?php echo $gvnsql_meta('guaven_sqlcharts_nostacked') !== '' ? 'checked' : ''; ?>> Disable stacking of multiple datasets (Bar charts)</label>
247 + <label class="gvnsql-inlinecheck"><input type="checkbox" name="guaven_sqlcharts_timeaxis" value="1"
248 + <?php echo $gvnsql_meta('guaven_sqlcharts_timeaxis') !== '' ? 'checked' : ''; ?>> Scale X axis by date/time (Bar and Line charts)</label>
249 + </div>
250 + <p class="gvnsql-hint">Date/time scaling places each point by real elapsed time instead of equal steps. X values must be dates such as
251 + <code>2024-02-23</code>, <code>2024-02</code>, <code>2024</code> or <code>2024-02-23 14:30</code>. If any X value is not a date, the normal axis is used.
252 + Bars are sized from the closest pair of dates, so very uneven gaps produce thin bars.</p>
128 253
129 -</script>
130 -<div class="dynamicfielddiv" style="display:none; padding: 10px; background: whitesmoke;">
131 -<p style="font-weight:bold">Enter dynamic filter variables using the format described below:</p>
132 -<textarea name="guaven_sqlcharts_variables" id="guaven_sqlcharts_variables" style="width:100%" rows="2"><?php
133 -echo (get_post_meta($post->ID, 'guaven_sqlcharts_variables', true) != '' ? get_post_meta($post->ID, 'guaven_sqlcharts_variables', true) : '');
134 -?>
135 -</textarea>
136 -<br><p>Use this format: <i>variable_name~default_value~variable_label~variable_type | variable_name~default_value~variable_label~variable_type</i> etc.<br>
137 - <ul style="padding-left:20px"><li>variable_name - any single name you want.</li><li>
138 - default_value - default value when no any variable chosen by a user</li><li>
139 - variable_label - Label which would be visible at a form above the chart</li><li>
140 - variable_type - number, text or date</li><li>
141 - ~ is a separator between variable elements.</li><li>
142 - | is a separator between variables</li></ul>
254 + <h4 class="gvnsql-step">Remote MySQL database (optional)</h4>
255 + <p class="gvnsql-hint">Leave all fields empty to use this WordPress site's own database.</p>
256 + <div class="gvnsql-grid2">
257 + <div class="gvnsql-field">
258 + <label for="guaven_sqlcharts_dbhost">Database host</label>
259 + <input type="text" name="guaven_sqlcharts_dbhost" id="guaven_sqlcharts_dbhost"
260 + value="<?php echo esc_attr($gvnsql_meta('guaven_sqlcharts_dbhost')); ?>" placeholder="e.g. 127.0.0.1">
261 + </div>
262 + <div class="gvnsql-field">
263 + <label for="guaven_sqlcharts_dbname">Database name</label>
264 + <input type="text" name="guaven_sqlcharts_dbname" id="guaven_sqlcharts_dbname"
265 + value="<?php echo esc_attr($gvnsql_meta('guaven_sqlcharts_dbname')); ?>">
266 + </div>
267 + <div class="gvnsql-field">
268 + <label for="guaven_sqlcharts_dblogin">Database username</label>
269 + <input type="text" name="guaven_sqlcharts_dblogin" id="guaven_sqlcharts_dblogin"
270 + value="<?php echo esc_attr($gvnsql_meta('guaven_sqlcharts_dblogin')); ?>">
271 + </div>
272 + <div class="gvnsql-field">
273 + <label for="guaven_sqlcharts_dbpass">Database password</label>
274 + <?php
275 + $gvnsql_dbpass = $gvnsql_meta('guaven_sqlcharts_dbpass');
276 + if (is_array($gvnsql_dbpass)) {
277 + $gvnsql_dbpass = guaven_sqlcharts_encrypt_decrypt('decrypt', $gvnsql_dbpass[1]);
278 + }
279 + ?>
280 + <input type="password" name="guaven_sqlcharts_dbpass" id="guaven_sqlcharts_dbpass"
281 + value="<?php echo esc_attr($gvnsql_dbpass); ?>" autocomplete="new-password">
282 + <small>Stored encrypted. WordPress supports MySQL databases; for other engines
283 + <a target="_blank" href="https://guaven.com/contact/solution-request/">contact us</a>.</small>
284 + </div>
285 + </div>
286 +</section>
143 287
144 - For example if to put <b>limit_tag~10~Count~number | post_date_tag~2010-07-05 17:25:18~Date Published~date</b> here,
145 - then you can use this SQL code <b>select * from wp_posts where post_date<{post_date_tag} limit {limit_tag}</b> in SQL CODE field.
146 - {post_date_tag} and {limit_tag} would be replaced with dynamic variables.
147 - So, the plugin will automatically recognize it and put corresponding selectboxes above the chart. <br></p>
148 -<p><label><input type="checkbox" name="guaven_sqlcharts_formpartrole" value="1"
149 - <?php echo get_post_meta($post->ID, 'guaven_sqlcharts_formpartrole', true)!=''?'checked':''; ?>>
150 - Hide dynamic filters form from not-loggedin users at frontend. </label></p>
288 +</div><!-- /gvnsql-app -->
151 289
152 - <p><label>Submit button text (default is "OK") <input type="text" name="guaven_sqlcharts_formpartbutton" value="<?php
153 - echo esc_attr(get_post_meta($post->ID, 'guaven_sqlcharts_formpartbutton', true) ); ?>" placeholder="Submit button text"></label></p>
154 -
155 -</div>
156 -
157 -<hr>
158 -
159 -
160 -<h4 class="gsql_h4">Width and height (with px. don't type px itself, just numbers)</h4>
161 -<p>
162 -
163 -<input type="number" name="guaven_sqlcharts_chartwidth" id="guaven_sqlcharts_chartwidth" value="<?php
164 -echo get_post_meta($post->ID, 'guaven_sqlcharts_chartwidth', true);
165 -?>">
166 -
167 -<input type="number" name="guaven_sqlcharts_chartheight" id="guaven_sqlcharts_chartheight" value="<?php
168 -echo get_post_meta($post->ID, 'guaven_sqlcharts_chartheight', true);
169 -?>">
170 -</p>
171 -
172 -<p>
173 -Color scheme (comma separated #RGB colors. f.e. <i>#FF0000</i> or <i>#00FF00,#BBCC00</i> ).
174 -<br>
175 -<input type="text" name="guaven_sqlcharts_colors" id="guaven_sqlcharts_colors" value="<?php
176 -echo get_post_meta($post->ID, 'guaven_sqlcharts_colors', true);
177 -?>" style="width:500px">
178 -<br><small>Leave empty if you want random colors</small>
179 -</p>
180 -
181 -<p>
182 -Legend block
183 -<br>
184 -<?php $guaven_sqlcharts_legend_position=get_post_meta($post->ID, 'guaven_sqlcharts_legend_position', true);?>
185 -<select name="guaven_sqlcharts_legend_position" id="guaven_sqlcharts_legend_position">
186 - <option value="default">Default</option>
187 - <option value="top" <?php echo $guaven_sqlcharts_legend_position=='top'?"selected":''; ?>>Shop at the top</option>
188 - <option value="bottom" <?php echo $guaven_sqlcharts_legend_position=='bottom'?"selected":''; ?>>Shop at the bottom</option>
189 - <option value="left" <?php echo $guaven_sqlcharts_legend_position=='left'?"selected":''; ?>>Shop at the left</option>
190 - <option value="right" <?php echo $guaven_sqlcharts_legend_position=='right'?"selected":''; ?>>Shop at the right</option>
191 - <option value="hide" <?php echo $guaven_sqlcharts_legend_position=='hide'?"selected":''; ?>>Hide legend</option>
192 -</select>
193 -<br><small>Legend in a chart is Y values which usually appears at the top/right part of the graph</small>
194 -</p>
195 -
196 -<h4 class="gsql_h4">X and Y Axis Ticks (for Line and Bar charts)</h4>
197 -<p>
198 -<label for="guaven_sqlcharts_begin_with_0_x">
199 - <input type="checkbox" name="guaven_sqlcharts_begin_with_0_x" id="guaven_sqlcharts_begin_with_0_x" value="1" <?php echo get_post_meta($post->ID, 'guaven_sqlcharts_begin_with_0_x', true)!=''?'checked':''; ?>>
200 - Force start X axes at 0
201 -</label>
202 -
203 -<label for="guaven_sqlcharts_begin_with_0_y">
204 - <input type="checkbox" name="guaven_sqlcharts_begin_with_0_y" id="guaven_sqlcharts_begin_with_0_y" value="1" <?php echo get_post_meta($post->ID, 'guaven_sqlcharts_begin_with_0_y', true)!=''?'checked':''; ?>>
205 - Force start X axes at 0
206 -</label>
207 -</p>
208 -
209 -<p>
210 -<label for="guaven_sqlcharts_round_y_values">
211 - <input type="checkbox" name="guaven_sqlcharts_round_y_values" id="guaven_sqlcharts_round_y_values" value="1" <?php echo get_post_meta($post->ID, 'guaven_sqlcharts_round_y_values', true)!=''?'checked':''; ?>>
212 - Show only round numbers in Y axis ticks
213 -</label>
214 -
215 -
216 - <label for="guaven_sqlcharts_nostacked">
217 -<input type="checkbox" name="guaven_sqlcharts_nostacked" id="guaven_sqlcharts_nostacked" value="1" <?php echo get_post_meta($post->ID, 'guaven_sqlcharts_nostacked', true)!=''?'checked':''; ?>
218 ->Disable "stackedness" for datasets
219 -</label>
220 -
221 -</p>
222 -
223 -
224 -
225 -<h4 class="gsql_h4">Remote MySQL Database Access Details</h4>
226 -
227 -Leave empty if you are connecting to local DB.<p>
228 -<input type="text" name="guaven_sqlcharts_dbhost" id="guaven_sqlcharts_dbhost" value="<?php
229 -echo get_post_meta($post->ID, 'guaven_sqlcharts_dbhost', true);
230 -?>" placeholder="database host">
231 -
232 -<input type="text" name="guaven_sqlcharts_dbname" id="guaven_sqlcharts_dbname" value="<?php
233 -echo get_post_meta($post->ID, 'guaven_sqlcharts_dbname', true);
234 -?>" placeholder="database name">
235 -
236 -<input type="text" name="guaven_sqlcharts_dblogin" id="guaven_sqlcharts_dblogin" value="<?php
237 -echo get_post_meta($post->ID, 'guaven_sqlcharts_dblogin', true);
238 -?>" placeholder="database username">
239 -
240 -<?php
241 -$dbpass=get_post_meta($post->ID, 'guaven_sqlcharts_dbpass', true);
242 -if(is_array($dbpass)){
243 - $dbpass=guaven_sqlcharts_encrypt_decrypt('decrypt',$dbpass[1]);
244 -}
245 -
246 -?>
247 -<input type="password" name="guaven_sqlcharts_dbpass" id="guaven_sqlcharts_dbpass" value="<?php
248 -echo $dbpass;
249 -?>" placeholder="database password">
250 -
251 -</p>
252 -<p>
253 -<small>Note: WordPress supports MySQL only Databases, to use non-MySQL databases some custom PHP code&driver would be needed.
254 -To discuss how to build that you can <a target="_blank" href="https://guaven.com/contact/solution-request/">contact us</a>.
255 -
256 -</small><br>
257 -</p>
258 -
259 -<hr>
260 -
261 -
262 -<style>
263 -.gsql_h4{color:#4693dd;margin-top:5px;margin-bottom:5px}
264 -.wpdberror{color:white;background: red;padding:10px;}
265 -#guaven_sqlcharts_begin_with_0_y{margin-left:24px;}
266 -</style>
267 290 <script>
268 -if (jQuery("#post").attr("action").indexOf("#")==-1){
269 - jQuery("#post").attr("action",jQuery("#post").attr("action")+"#sqldemo");
291 +if (jQuery("#post").attr("action") && jQuery("#post").attr("action").indexOf("#") === -1){
292 + jQuery("#post").attr("action", jQuery("#post").attr("action") + "#sqldemo");
270 293 }
271 294 </script>
295 +
272 296 <?php
273 -if (get_post_meta($post->ID, 'guaven_sqlcharts_graphtype', true) != '') {
274 - if (strpos(get_post_meta($post->ID, 'guaven_sqlcharts_graphtype', true), "_l") !== false)
275 - $postfix = '_2';
276 - else
277 - $postfix = '';
297 +$postfix = guaven_sqlcharts_graphtype($post);
298 +if ($postfix !== '' or $gvnsql_meta('guaven_sqlcharts_code') != '') {
299 + // legacy google types ($postfix === '') render via the [gvn_schart] alias shortcode
278 300 ?>
279 301 <div class="gf-alert-success gf-alert">
280 302 <h4>
281 303 Text shortcode: [gvn_schart<?php
282 - echo $postfix;
304 + echo esc_attr($postfix);
283 305 ?> id="<?php
284 - echo $post->ID;
285 -?>"<?php echo get_post_meta($post->ID,'guaven_sqlcharts_tablepart',true)!=''?' table="1"':''; ?>]
306 + echo esc_attr($post->ID);
307 +?>"<?php echo $gvnsql_meta('guaven_sqlcharts_tablepart') !== '' ? ' table="1"' : ''; ?>]
286 308 <br>
287 309 <br>
288 -PHP shorcode: &lt;?php echo do_shortcode(' [gvn_schart<?php
289 - echo $postfix;
310 +PHP shortcode: &lt;?php echo do_shortcode(' [gvn_schart<?php
311 + echo esc_attr($postfix);
290 312 ?> id="<?php
291 - echo $post->ID;
292 -?>"<?php echo get_post_meta($post->ID,'guaven_sqlcharts_tablepart',true)!=''?' table="1"':''; ?>]'); ?&gt;
313 + echo esc_attr($post->ID);
314 +?>"<?php echo $gvnsql_meta('guaven_sqlcharts_tablepart') !== '' ? ' table="1"' : ''; ?>]'); ?&gt;
293 315 </h4>
294 -<p>Note: Shortcodes supports width and height attributes. F.e. [gvn_schart<?php
295 - echo $postfix;
296 -?> id="1" width="500" height="400"]. If no attributes, default width, height (which you enter in this page above) will be used.
316 +<p>Note: Shortcodes support width and height attributes, f.e. [gvn_schart<?php
317 + echo esc_attr($postfix);
318 +?> id="1" width="500" height="400"]. Without attributes, the width/height from the Style tab is used.
319 +<?php
320 + preg_match_all('/\{arg([0-9]+)\}/', guaven_sqlcharts_get_code($post->ID), $gvnsql_argtags);
321 + $gvnsql_argtags = array_unique($gvnsql_argtags[1]);
322 + sort($gvnsql_argtags);
323 + if (!empty($gvnsql_argtags)) {
324 + $gvnsql_argexample = '';
325 + foreach ($gvnsql_argtags as $gvnsql_argn) $gvnsql_argexample .= ' arg' . (int) $gvnsql_argn . '="..."';
326 +?>
327 +<br><br><strong>This query uses shortcode arguments.</strong> Pass the values in the shortcode:
328 +[gvn_schart<?php echo esc_attr($postfix); ?> id="<?php echo esc_attr($post->ID); ?>"<?php echo esc_html($gvnsql_argexample); ?>].
329 +The live preview below runs without them (every {arg} is 0), so check the real result on a page or post.
330 +<?php } ?>
297 331 </div>
298 332 <hr>
299 -<h3 id="sqldemo" name="sqldemo">Save Changes and See Live Demo</h3>
333 +<h3 id="sqldemo" name="sqldemo">Live Preview <small style="font-weight:normal">(reflects the last saved state — press Update to refresh)</small></h3>
300 334 <?php
301 - echo do_shortcode(' [gvn_schart' . $postfix . ' id="' . $post->ID . '" '.(get_post_meta($post->ID,'guaven_sqlcharts_tablepart',true)!=''?' table="1"':'').']');
335 + echo do_shortcode('[gvn_schart' . esc_attr($postfix) . ' id="' . esc_attr($post->ID) . '" ' . ($gvnsql_meta('guaven_sqlcharts_tablepart') !== '' ? ' table="1"' : '') . ']');
302 336
303 337 }
338 +?>