PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 1.7.1
Visualizer – Tables & Charts Manager with Built-in AI Generator v1.7.1
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 3.10.4 All 148 releases
← All changes | classes/Visualizer/Source.php +37 -193 3.1.31.7.1 View file →
@@ -1,5 +1,6 @@
1 1 <?php
2 +
2 3 // +----------------------------------------------------------------------+
3 4 // | Copyright 2013 Madpixels (email : visualizer@madpixels.net) |
4 5 // +----------------------------------------------------------------------+
5 6 // | This program is free software; you can redistribute it and/or modify |
@@ -29,17 +30,8 @@
29 30 */
30 31 abstract class Visualizer_Source {
31 32
32 33 /**
33 - * The array of allowed types.
34 - *
35 - * @since 1.0.0
36 - *
37 - * @access protected
38 - * @var array
39 - */
40 - protected static $allowed_types = array( 'string', 'number', 'boolean', 'date', 'datetime', 'timeofday' );
41 - /**
42 34 * The array of data.
43 35 *
44 36 * @since 1.0.0
45 37 *
@@ -46,8 +38,9 @@
46 38 * @access protected
47 39 * @var array
48 40 */
49 41 protected $_data = array();
42 +
50 43 /**
51 44 * The array of series.
52 45 *
53 46 * @since 1.0.0
@@ -57,43 +50,8 @@
57 50 */
58 51 protected $_series = array();
59 52
60 53 /**
61 - * Return allowed types
62 - *
63 - * @since 1.0.1
64 - *
65 - * @static
66 - * @access public
67 - * @return array the allowed types
68 - */
69 - public static function getAllowedTypes() {
70 - return self::$allowed_types;
71 - }
72 -
73 - /**
74 - * Validates series tyeps.
75 - *
76 - * @since 1.0.1
77 - *
78 - * @static
79 - * @access protected
80 - *
81 - * @param array $types The icoming series types.
82 - *
83 - * @return boolean TRUE if sereis types are valid, otherwise FALSE.
84 - */
85 - protected static function _validateTypes( $types ) {
86 - foreach ( $types as $type ) {
87 - if ( ! in_array( $type, self::$allowed_types ) ) {
88 - return false;
89 - }
90 - }
91 -
92 - return true;
93 - }
94 -
95 - /**
96 54 * Returns source name.
97 55 *
98 56 * @since 1.0.0
99 57 *
@@ -149,67 +107,35 @@
149 107 return $this->_data;
150 108 }
151 109
152 110 /**
153 - * Re populates series if the source is dynamic.
154 - *
155 - * @since 1.1.0
156 - *
157 - * @access public
158 - *
159 - * @param array $series The actual array of series.
160 - * @param int $chart_id The chart id.
161 - *
162 - * @return array The re populated array of series or old one.
163 - */
164 - public function repopulateSeries( $series, $chart_id ) {
165 - return $series;
166 - }
167 -
168 - /**
169 - * Re populates data if the source is dynamic.
170 - *
171 - * @since 1.1.0
172 - *
173 - * @access public
174 - *
175 - * @param array $data The actual array of data.
176 - * @param int $chart_id The chart id.
177 - *
178 - * @return array The re populated array of data or old one.
179 - */
180 - public function repopulateData( $data, $chart_id ) {
181 - return $data;
182 - }
183 -
184 - /**
185 111 * Normalizes values according to series' type.
186 112 *
187 113 * @since 1.0.0
188 114 *
189 115 * @access protected
190 - *
191 116 * @param array $data The row of data.
192 - *
193 117 * @return array Normalized row of data.
194 118 */
195 119 protected function _normalizeData( $data ) {
196 120 // normalize values
197 - // error_log(print_r($data,true));
121 + // print_r($data);
198 122 foreach ( $this->_series as $i => $series ) {
199 123 // if no value exists for the seires, then add null
200 124 if ( ! isset( $data[ $i ] ) ) {
201 125 $data[ $i ] = null;
202 126 }
203 - if ( is_null( $data[ $i ] ) ) {
127 +
128 + if ( is_null( $data[ $i ] ) && ! is_numeric( $data[ $i ] ) ) {
204 129 continue;
205 130 }
131 +
206 132 switch ( $series['type'] ) {
207 133 case 'number':
208 - $data[ $i ] = ( is_numeric( $data[ $i ] ) ) ? floatval( $data[ $i ] ) : ( is_numeric( str_replace( ',', '', $data[ $i ] ) ) ? floatval( str_replace( ',', '', $data[ $i ] ) ) : null );
134 + $data[ $i ] = ( is_numeric( $data[ $i ] ) ) ? floatval( $data[ $i ] ) : null;
209 135 break;
210 136 case 'boolean':
211 - $data[ $i ] = ! empty( $data[ $i ] ) ? filter_var( $data[ $i ], FILTER_VALIDATE_BOOLEAN ) : null;
137 + $data[ $i ] = ! empty( $data[ $i ] ) ? filter_validate( $data[ $i ], FILTER_VALIDATE_BOOLEAN ) : null;
212 138 break;
213 139 case 'timeofday':
214 140 $date = new DateTime( '1984-03-16T' . $data[ $i ] );
215 141 if ( $date ) {
@@ -220,141 +146,59 @@
220 146 0,
221 147 );
222 148 }
223 149 break;
224 - case 'string':
225 - $data[ $i ] = $this->toUTF8( $data[ $i ] );
226 - break;
227 150 }
228 151 }
229 -
230 - // error_log(print_r($data,true));
231 152 return $data;
232 153 }
233 154
234 -
235 155 /**
236 - * Converts values to UTF8, if required.
156 + * Validates series tyeps.
237 157 *
158 + * @since 1.0.1
159 + *
160 + * @static
238 161 * @access protected
239 - *
240 - * @param string $datum The data to convert.
241 - *
242 - * @return string The converted data.
162 + * @param array $types The icoming series types.
163 + * @return boolean TRUE if sereis types are valid, otherwise FALSE.
243 164 */
244 - protected final function toUTF8( $datum ) {
245 - if ( ! function_exists( 'mb_detect_encoding' ) || mb_detect_encoding( $datum ) !== 'ASCII' ) {
246 - $datum = \ForceUTF8\Encoding::toUTF8( $datum );
165 + protected static function _validateTypes( $types ) {
166 + $allowed_types = array( 'string', 'number', 'boolean', 'date', 'datetime', 'timeofday' );
167 + foreach ( $types as $type ) {
168 + if ( ! in_array( $type, $allowed_types ) ) {
169 + return false;
170 + }
247 171 }
248 - return $datum;
172 +
173 + return true;
249 174 }
250 175
251 176 /**
252 - * Determines the formats of date/time columns.
177 + * Re populates series if the source is dynamic.
253 178 *
179 + * @since 1.1.0
180 + *
254 181 * @access public
255 - *
256 182 * @param array $series The actual array of series.
257 - * @param array $data The actual array of data.
258 - *
259 - * @return array
183 + * @param int $chart_id The chart id.
184 + * @return array The re populated array of series or old one.
260 185 */
261 - public static final function get_date_formats_if_exists( $series, $data ) {
262 - $date_formats = array();
263 - $types = array();
264 - $index = 0;
265 - foreach ( $series as $column ) {
266 - if ( in_array( $column['type'], array( 'date', 'datetime', 'timeofday' ) ) ) {
267 - $types[] = array( 'index' => $index, 'type' => $column['type'] );
268 - }
269 - $index++;
270 - }
271 -
272 - if ( ! $types ) {
273 - return $date_formats;
274 - }
275 -
276 - $random = $data;
277 - // let's randomly pick 5 data points instead of cycling through the entire data set.
278 - if ( count( $data ) > 5 ) {
279 - $random = array();
280 - for ( $x = 0; $x < 5; $x++ ) {
281 - $random = $data[ rand( 0, count( $data ) - 1 ) ];
282 - }
283 - }
284 -
285 - foreach ( $types as $type ) {
286 - $formats = array();
287 - foreach ( $random as $datum ) {
288 - $f = self::determine_date_format( $datum[ $type['index'] ], $type['type'] );
289 - if ( $f ) {
290 - $formats[] = $f;
291 - }
292 - }
293 - // if there are multiple formats, use the most frequent format.
294 - $formats = array_filter( $formats );
295 - if ( $formats ) {
296 - $formats = array_count_values( $formats );
297 - arsort( $formats );
298 - $formats = array_keys( $formats );
299 - $final_format = reset( $formats );
300 - // we have determined the PHP format; now we have to change this into the JS format where m = MM, d = DD etc.
301 - $date_formats[] = array( 'index' => $type['index'], 'format' => str_replace( array( 'Y', 'm', 'd', 'H', 'i', 's' ), array( 'YYYY', 'MM', 'DD', 'HH', 'mm', 'ss' ), $final_format ) );
302 - }
303 - }
304 - return $date_formats;
186 + public function repopulateSeries( $series, $chart_id ) {
187 + return $series;
305 188 }
306 189
307 190 /**
308 - * Determines the date/time format of the given string.
191 + * Re populates data if the source is dynamic.
309 192 *
310 - * @access private
193 + * @since 1.1.0
311 194 *
312 - * @param string $value The string.
313 - * @param string $type 'date', 'timeofday' or 'datetime'.
314 - *
315 - * @return string|null
195 + * @access public
196 + * @param array $data The actual array of data.
197 + * @param int $chart_id The chart id.
198 + * @return array The re populated array of data or old one.
316 199 */
317 - private static final function determine_date_format( $value, $type ) {
318 - if ( version_compare( phpversion(), '5.3.0', '<' ) ) {
319 - return null;
320 - }
321 -
322 - $formats = array(
323 - 'Y/m/d',
324 - 'Y-m-d',
325 - 'm/d/Y',
326 - 'm-d-Y',
327 - 'd-m-Y',
328 - 'd/m/Y',
329 - );
330 -
331 - switch ( $type ) {
332 - case 'datetime':
333 - $formats += array(
334 - 'Y/m/d H:i:s',
335 - 'Y-m-d H:i:s',
336 - 'm/d/Y H:i:s',
337 - 'm-d-Y H:i:s',
338 - );
339 - break;
340 - case 'timeofday':
341 - $formats += array(
342 - 'H:i:s',
343 - 'H:i',
344 - );
345 - break;
346 - }
347 -
348 - $formats = apply_filters( 'visualizer_date_formats', $formats, $type );
349 -
350 - foreach ( $formats as $format ) {
351 - $return = DateTime::createFromFormat( $format, $value );
352 - if ( $return !== false ) {
353 - return $format;
354 - }
355 - }
356 - // invalid format
357 - return null;
200 + public function repopulateData( $data, $chart_id ) {
201 + return $data;
358 202 }
359 203
360 204 }