PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 2.0.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v2.0.0
4.0.8 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 All 149 releases
← All changes | classes/Visualizer/Module/Admin.php +175 -97 1.7.62.0.0 View file →
@@ -1,6 +1,5 @@
1 1 <?php
2 -
3 2 // +----------------------------------------------------------------------+
4 3 // | Copyright 2013 Madpixels (email : visualizer@madpixels.net) |
5 4 // +----------------------------------------------------------------------+
6 5 // | This program is free software; you can redistribute it and/or modify |
@@ -46,71 +45,48 @@
46 45 *
47 46 * @since 1.0.0
48 47 *
49 48 * @access public
49 + *
50 50 * @param Visualizer_Plugin $plugin The instance of the plugin.
51 51 */
52 52 public function __construct( Visualizer_Plugin $plugin ) {
53 53 parent::__construct( $plugin );
54 -
55 54 $this->_addAction( 'load-post.php', 'enqueueMediaScripts' );
56 55 $this->_addAction( 'load-post-new.php', 'enqueueMediaScripts' );
57 56 $this->_addAction( 'admin_footer', 'renderTempaltes' );
58 - $this->_addAction( 'admin_enqueue_scripts', 'enqueueLibraryScripts' );
57 + $this->_addAction( 'admin_enqueue_scripts', 'enqueueLibraryScripts', null, 9 );
59 58 $this->_addAction( 'admin_menu', 'registerAdminMenu' );
60 -
61 59 $this->_addFilter( 'media_view_strings', 'setupMediaViewStrings' );
62 60 $this->_addFilter( 'plugin_action_links', 'getPluginActionLinks', 10, 2 );
63 61 $this->_addFilter( 'plugin_row_meta', 'getPluginMetaLinks', 10, 2 );
62 + $this->_addFilter( 'visualizer_logger_flag', 'get_logger_flag', 10, 1 );
63 + $this->_addAjaxAction( Visualizer_Plugin::ACTION_TRACK, 'visualizer_enable_track' );
64 64 }
65 65
66 66 /**
67 - * Returns associated array of chart types and localized names.
68 - *
69 - * @since 1.0.0
70 - *
71 - * @static
72 - * @access private
73 - * @return array The associated array of chart types with localized names.
67 + * Enable track ajax action.
74 68 */
75 - public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darray = false ) {
76 - $types = array(
77 - 'pie' => array( 'name' => esc_html__( 'Pie', 'visualizer' ), 'enabled' => true ),
78 - 'line' => array( 'name' => esc_html__( 'Line', 'visualizer' ), 'enabled' => true ),
79 - 'area' => array( 'name' => esc_html__( 'Area', 'visualizer' ), 'enabled' => true ),
80 - 'geo' => array( 'name' => esc_html__( 'Geo', 'visualizer' ), 'enabled' => true ),
81 - 'bar' => array( 'name' => esc_html__( 'Bar', 'visualizer' ), 'enabled' => true ),
82 - 'column' => array( 'name' => esc_html__( 'Column', 'visualizer' ), 'enabled' => true ),
83 - 'gauge' => array( 'name' => esc_html__( 'Gauge', 'visualizer' ), 'enabled' => true ),
84 - 'scatter' => array( 'name' => esc_html__( 'Scatter', 'visualizer' ), 'enabled' => true ),
85 - 'candlestick' => array( 'name' => esc_html__( 'Candlestick', 'visualizer' ), 'enabled' => true ),
86 - // pro types
87 - 'table' => array( 'name' => esc_html__( 'Table', 'visualizer' ), 'enabled' => false ),
88 - 'timeline' => array( 'name' => esc_html__( 'Timeline', 'visualizer' ), 'enabled' => false ),
89 - 'combo' => array( 'name' => esc_html__( 'Combo', 'visualizer' ), 'enabled' => false ),
90 - );
91 -
92 - $types = apply_filters( 'visualizer_pro_chart_types', $types );
93 -
94 - if ( $enabledOnly ) {
95 - $filtered = array();
96 - foreach ( $types as $type => $array ) {
97 - if ( ! $array['enabled'] ) { continue;
98 - }
99 - $filtered[ $type ] = $array;
100 - }
101 - $types = $filtered;
69 + public function visualizer_enable_track() {
70 + check_admin_referer( Visualizer_Plugin::ACTION_TRACK, 'nonce' );
71 + $status = $_GET['status'];
72 + if ( $status == 'yes' ) {
73 + update_option( 'visualizer_logger_flag', 'yes' );
74 + } else {
75 + update_option( 'visualizer_logger_flag', 'no' );
102 76 }
77 + wp_send_json_success( array( 'status' => $status ) );
78 + }
103 79
104 - if ( $get2Darray ) {
105 - $doubleD = array();
106 - foreach ( $types as $type => $array ) {
107 - $doubleD[ $type ] = $array['name'];
108 - }
109 - $types = $doubleD;
110 - }
80 + /**
81 + * Either the tracking is active or not.
82 + *
83 + * @return bool The flag status.
84 + */
85 + public function get_logger_flag() {
86 + $flag = get_option( 'visualizer_logger_flag', 'no' );
111 87
112 - return $types;
88 + return ( $flag === 'yes' );
113 89 }
114 90
115 91 /**
116 92 * Enqueues media scripts and styles.
@@ -122,20 +98,18 @@
122 98 * @access public
123 99 */
124 100 public function enqueueMediaScripts() {
125 101 global $typenow;
126 -
127 102 if ( post_type_supports( $typenow, 'editor' ) ) {
128 103 wp_enqueue_style( 'visualizer-media', VISUALIZER_ABSURL . 'css/media.css', array( 'media-views' ), Visualizer_Plugin::VERSION );
129 -
130 - wp_enqueue_script( 'visualizer-google-jsapi-new', '//www.gstatic.com/charts/loader.js', array( 'media-editor' ), null, true );
131 - wp_enqueue_script( 'visualizer-google-jsapi-old', '//www.google.com/jsapi', array( 'visualizer-google-jsapi-new' ), null, true );
132 - wp_enqueue_script( 'visualizer-media-model', VISUALIZER_ABSURL . 'js/media/model.js', array( 'visualizer-google-jsapi-old' ), Visualizer_Plugin::VERSION, true );
133 - wp_enqueue_script( 'visualizer-media-collection', VISUALIZER_ABSURL . 'js/media/collection.js', array( 'visualizer-media-model' ), Visualizer_Plugin::VERSION, true );
104 + wp_enqueue_script( 'visualizer-google-jsapi-new', '//www.gstatic.com/charts/loader.js', array( 'media-editor' ), null, true );
105 + wp_enqueue_script( 'visualizer-google-jsapi-old', '//www.google.com/jsapi', array( 'visualizer-google-jsapi-new' ), null, true );
106 + wp_enqueue_script( 'visualizer-media-model', VISUALIZER_ABSURL . 'js/media/model.js', array( 'visualizer-google-jsapi-old' ), Visualizer_Plugin::VERSION, true );
107 + wp_enqueue_script( 'visualizer-media-collection', VISUALIZER_ABSURL . 'js/media/collection.js', array( 'visualizer-media-model' ), Visualizer_Plugin::VERSION, true );
134 108 wp_enqueue_script( 'visualizer-media-controller', VISUALIZER_ABSURL . 'js/media/controller.js', array( 'visualizer-media-collection' ), Visualizer_Plugin::VERSION, true );
135 - wp_enqueue_script( 'visualizer-media-view', VISUALIZER_ABSURL . 'js/media/view.js', array( 'visualizer-media-controller' ), Visualizer_Plugin::VERSION, true );
136 - wp_enqueue_script( 'visualizer-media-toolbar', VISUALIZER_ABSURL . 'js/media/toolbar.js', array( 'visualizer-media-view' ), Visualizer_Plugin::VERSION, true );
137 - wp_enqueue_script( 'visualizer-media', VISUALIZER_ABSURL . 'js/media.js', array( 'visualizer-media-toolbar' ), Visualizer_Plugin::VERSION, true );
109 + wp_enqueue_script( 'visualizer-media-view', VISUALIZER_ABSURL . 'js/media/view.js', array( 'visualizer-media-controller' ), Visualizer_Plugin::VERSION, true );
110 + wp_enqueue_script( 'visualizer-media-toolbar', VISUALIZER_ABSURL . 'js/media/toolbar.js', array( 'visualizer-media-view' ), Visualizer_Plugin::VERSION, true );
111 + wp_enqueue_script( 'visualizer-media', VISUALIZER_ABSURL . 'js/media.js', array( 'visualizer-media-toolbar' ), Visualizer_Plugin::VERSION, true );
138 112 }
139 113 }
140 114
141 115 /**
@@ -143,14 +117,16 @@
143 117 *
144 118 * @since 1.0.0
145 119 *
146 120 * @access public
121 + *
147 122 * @param array $strings The array of media view strings.
123 + *
148 124 * @return array The extended array of media view strings.
149 125 */
150 126 public function setupMediaViewStrings( $strings ) {
151 127 $strings['visualizer'] = array(
152 - 'actions' => array(
128 + 'actions' => array(
153 129 'get_charts' => Visualizer_Plugin::ACTION_GET_CHARTS,
154 130 'delete_chart' => Visualizer_Plugin::ACTION_DELETE_CHART,
155 131 ),
156 132 'controller' => array(
@@ -155,18 +131,18 @@
155 131 ),
156 132 'controller' => array(
157 133 'title' => esc_html__( 'Visualizations', 'visualizer' ),
158 134 ),
159 - 'routers' => array(
135 + 'routers' => array(
160 136 'library' => esc_html__( 'From Library', 'visualizer' ),
161 137 'create' => esc_html__( 'Create New', 'visualizer' ),
162 138 ),
163 - 'library' => array(
164 - 'filters' => self::_getChartTypesLocalized( true, true ),
165 - 'types' => array_keys( self::_getChartTypesLocalized( true, true ) ),
139 + 'library' => array(
140 + 'filters' => self::_getChartTypesLocalized( true, true ),
141 + 'types' => array_keys( self::_getChartTypesLocalized( true, true ) ),
166 142 ),
167 - 'nonce' => wp_create_nonce(),
168 - 'buildurl' => add_query_arg( 'action', Visualizer_Plugin::ACTION_CREATE_CHART, admin_url( 'admin-ajax.php' ) ),
143 + 'nonce' => wp_create_nonce(),
144 + 'buildurl' => add_query_arg( 'action', Visualizer_Plugin::ACTION_CREATE_CHART, admin_url( 'admin-ajax.php' ) ),
169 145 );
170 146
171 147 return $strings;
172 148 }
@@ -171,8 +147,99 @@
171 147 return $strings;
172 148 }
173 149
174 150 /**
151 + * Returns associated array of chart types and localized names.
152 + *
153 + * @since 1.0.0
154 + *
155 + * @static
156 + * @access private
157 + * @return array The associated array of chart types with localized names.
158 + */
159 + public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darray = false ) {
160 + $types = array(
161 + 'pie' => array(
162 + 'name' => esc_html__( 'Pie', 'visualizer' ),
163 + 'enabled' => true,
164 + ),
165 + 'line' => array(
166 + 'name' => esc_html__( 'Line', 'visualizer' ),
167 + 'enabled' => true,
168 + ),
169 + 'area' => array(
170 + 'name' => esc_html__( 'Area', 'visualizer' ),
171 + 'enabled' => true,
172 + ),
173 + 'geo' => array(
174 + 'name' => esc_html__( 'Geo', 'visualizer' ),
175 + 'enabled' => true,
176 + ),
177 + 'bar' => array(
178 + 'name' => esc_html__( 'Bar', 'visualizer' ),
179 + 'enabled' => true,
180 + ),
181 + 'column' => array(
182 + 'name' => esc_html__( 'Column', 'visualizer' ),
183 + 'enabled' => true,
184 + ),
185 + 'gauge' => array(
186 + 'name' => esc_html__( 'Gauge', 'visualizer' ),
187 + 'enabled' => true,
188 + ),
189 + 'scatter' => array(
190 + 'name' => esc_html__( 'Scatter', 'visualizer' ),
191 + 'enabled' => true,
192 + ),
193 + 'candlestick' => array(
194 + 'name' => esc_html__( 'Candlestick', 'visualizer' ),
195 + 'enabled' => true,
196 + ),
197 + // pro types
198 + 'table' => array(
199 + 'name' => esc_html__( 'Table', 'visualizer' ),
200 + 'enabled' => false,
201 + ),
202 + 'timeline' => array(
203 + 'name' => esc_html__( 'Timeline', 'visualizer' ),
204 + 'enabled' => false,
205 + ),
206 + 'combo' => array(
207 + 'name' => esc_html__( 'Combo', 'visualizer' ),
208 + 'enabled' => false,
209 + ),
210 + );
211 + $types = apply_filters( 'visualizer_pro_chart_types', $types );
212 + if ( $enabledOnly ) {
213 + $filtered = array();
214 + foreach ( $types as $type => $array ) {
215 + if ( ! is_array( $array ) ) {
216 + // support for old pro
217 + $array = array( 'enabled' => true, 'name' => $array );
218 + }
219 + if ( ! $array['enabled'] ) {
220 + continue;
221 + }
222 + $filtered[ $type ] = $array;
223 + }
224 + $types = $filtered;
225 + }
226 + if ( $get2Darray ) {
227 + $doubleD = array();
228 + foreach ( $types as $type => $array ) {
229 + if ( ! is_array( $array ) ) {
230 + // support for old pro
231 + $array = array( 'enabled' => true, 'name' => $array );
232 + }
233 + $doubleD[ $type ] = $array['name'];
234 + }
235 + $types = $doubleD;
236 + }
237 +
238 + return $types;
239 + }
240 +
241 + /**
175 242 * Renders templates to use in media popup.
176 243 *
177 244 * @since 1.0.0
178 245 * @global string $pagenow The name of the current page.
@@ -180,13 +247,11 @@
180 247 * @access public
181 248 */
182 249 public function renderTempaltes() {
183 250 global $pagenow;
184 -
185 251 if ( 'post.php' != $pagenow && 'post-new.php' != $pagenow ) {
186 252 return;
187 253 }
188 -
189 254 $render = new Visualizer_Render_Templates();
190 255 $render->render();
191 256 }
192 257
@@ -198,21 +263,26 @@
198 263 * @uses wp_enqueue_script() To enqueue javascript file.
199 264 * @uses wp_enqueue_media() To enqueue media stuff.
200 265 *
201 266 * @access public
267 + *
202 268 * @param string $suffix The current page suffix.
203 269 */
204 270 public function enqueueLibraryScripts( $suffix ) {
205 271 if ( $suffix == $this->_libraryPage ) {
206 272 wp_enqueue_style( 'visualizer-library', VISUALIZER_ABSURL . 'css/library.css', array(), Visualizer_Plugin::VERSION );
207 -
208 273 $this->_addFilter( 'media_upload_tabs', 'setupVisualizerTab' );
209 -
210 274 wp_enqueue_media();
211 - wp_enqueue_script( 'visualizer-library', VISUALIZER_ABSURL . 'js/library.js', array( 'jquery', 'media-views' ), Visualizer_Plugin::VERSION, true );
275 + wp_enqueue_script( 'visualizer-library', VISUALIZER_ABSURL . 'js/library.js', array(
276 + 'jquery',
277 + 'media-views',
278 + ), Visualizer_Plugin::VERSION, true );
212 279 wp_enqueue_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true );
213 280 wp_enqueue_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true );
214 - wp_enqueue_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'google-jsapi-old', 'visualizer-library' ), Visualizer_Plugin::VERSION, true );
281 + wp_enqueue_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array(
282 + 'google-jsapi-old',
283 + 'visualizer-library',
284 + ), Visualizer_Plugin::VERSION, true );
215 285 }
216 286 }
217 287
218 288 /**
@@ -220,13 +290,16 @@
220 290 *
221 291 * @since 1.0.0
222 292 *
223 293 * @access public
294 + *
224 295 * @param array $tabs The array of media upload tabs.
296 + *
225 297 * @return array Extended array of media upload tabs.
226 298 */
227 299 public function setupVisualizerTab( $tabs ) {
228 300 $tabs['visualizer'] = 'Visualizer';
301 +
229 302 return $tabs;
230 303 }
231 304
232 305 /**
@@ -236,10 +309,10 @@
236 309 *
237 310 * @access public
238 311 */
239 312 public function registerAdminMenu() {
240 - $title = esc_html__( 'Visualizer Library', 'visualizer' );
241 - $callback = array( $this, 'renderLibraryPage' );
313 + $title = esc_html__( 'Visualizer Library', 'visualizer' );
314 + $callback = array( $this, 'renderLibraryPage' );
242 315 $this->_libraryPage = add_submenu_page( 'upload.php', $title, $title, 'edit_posts', Visualizer_Plugin::NAME, $callback );
243 316 }
244 317
245 318 /**
@@ -256,9 +329,8 @@
256 329 'min_range' => 1,
257 330 'default' => 1,
258 331 ),
259 332 ) );
260 -
261 333 // the initial query arguments to fetch charts
262 334 $query_args = array(
263 335 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
264 336 'posts_per_page' => 6,
@@ -263,9 +335,8 @@
263 335 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
264 336 'posts_per_page' => 6,
265 337 'paged' => $page,
266 338 );
267 -
268 339 // add chart type filter to the query arguments
269 340 $filter = filter_input( INPUT_GET, 'type' );
270 341 if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes() ) ) {
271 342 $query_args['meta_query'] = array(
@@ -277,36 +348,32 @@
277 348 );
278 349 } else {
279 350 $filter = 'all';
280 351 }
281 -
282 352 // Added by Ash/Upwork
283 - $filterByMeta = filter_input( INPUT_GET, 'filter', FILTER_SANITIZE_STRING );
353 + $filterByMeta = filter_input( INPUT_GET, 's', FILTER_SANITIZE_STRING );
284 354 if ( $filterByMeta ) {
285 - $query = array(
286 - 'key' => Visualizer_Plugin::CF_SETTINGS,
287 - 'value' => $filterByMeta,
288 - 'compare' => 'LIKE',
355 + $query = array(
356 + 'key' => Visualizer_Plugin::CF_SETTINGS,
357 + 'value' => $filterByMeta,
358 + 'compare' => 'LIKE',
289 359 );
290 - $meta = isset( $query_args['meta_query'] ) ? $query_args['meta_query'] : array();
291 - $meta[] = $query;
292 - $query_args['meta_query'] = $meta;
360 + $meta = isset( $query_args['meta_query'] ) ? $query_args['meta_query'] : array();
361 + $meta[] = $query;
362 + $query_args['meta_query'] = $meta;
293 363 }
294 364 // Added by Ash/Upwork
295 365 // fetch charts
296 366 $charts = array();
297 - $query = new WP_Query( $query_args );
367 + $query = new WP_Query( $query_args );
298 368 while ( $query->have_posts() ) {
299 369 $chart = $query->next_post();
300 -
301 370 // fetch and update settings
302 371 $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
303 372 unset( $settings['height'], $settings['width'] );
304 -
305 - $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
373 + $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
306 374 $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type );
307 - $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( $chart->post_content ), $chart->ID, $type );
308 -
375 + $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( $chart->post_content ), $chart->ID, $type );
309 376 // add chart to the array
310 377 $charts[ 'visualizer-' . $chart->ID ] = array(
311 378 'id' => $chart->ID,
312 379 'type' => $type,
@@ -314,9 +381,8 @@
314 381 'settings' => $settings,
315 382 'data' => $data,
316 383 );
317 384 }
318 -
319 385 // enqueue charts array
320 386 $ajaxurl = admin_url( 'admin-ajax.php' );
321 387 wp_localize_script( 'visualizer-library', 'visualizer', array(
322 388 'charts' => $charts,
@@ -321,19 +387,28 @@
321 387 wp_localize_script( 'visualizer-library', 'visualizer', array(
322 388 'charts' => $charts,
323 389 'urls' => array(
324 390 'base' => add_query_arg( 'vpage', false ),
325 - 'create' => add_query_arg( array( 'action' => Visualizer_Plugin::ACTION_CREATE_CHART, 'library' => 'yes' ), $ajaxurl ),
326 - 'edit' => add_query_arg( array( 'action' => Visualizer_Plugin::ACTION_EDIT_CHART, 'library' => 'yes' ), $ajaxurl ),
391 + 'create' => add_query_arg( array(
392 + 'action' => Visualizer_Plugin::ACTION_CREATE_CHART,
393 + 'library' => 'yes',
394 + ), $ajaxurl ),
395 + 'edit' => add_query_arg( array(
396 + 'action' => Visualizer_Plugin::ACTION_EDIT_CHART,
397 + 'library' => 'yes',
398 + ), $ajaxurl ),
399 + 'logger' => add_query_arg( array(
400 + 'action' => Visualizer_Plugin::ACTION_TRACK,
401 + 'library' => 'yes',
402 + 'nonce' => wp_create_nonce( Visualizer_Plugin::ACTION_TRACK ),
403 + ), $ajaxurl ),
327 404 ),
328 405 ) );
329 -
330 406 // render library page
331 - $render = new Visualizer_Render_Library();
332 -
333 - $render->charts = $charts;
334 - $render->type = $filter;
335 - $render->types = self::_getChartTypesLocalized();
407 + $render = new Visualizer_Render_Library();
408 + $render->charts = $charts;
409 + $render->type = $filter;
410 + $render->types = self::_getChartTypesLocalized();
336 411 $render->pagination = paginate_links( array(
337 412 'base' => add_query_arg( 'vpage', '%#%' ),
338 413 'format' => '',
339 414 'current' => $page,
@@ -339,9 +414,8 @@
339 414 'current' => $page,
340 415 'total' => $query->max_num_pages,
341 416 'type' => 'array',
342 417 ) );
343 -
344 418 $render->render();
345 419 }
346 420
347 421 /**
@@ -349,10 +423,12 @@
349 423 *
350 424 * @since 1.0.0
351 425 *
352 426 * @access public
427 + *
353 428 * @param array $links The array of original action links.
354 429 * @param string $file The plugin basename.
430 + *
355 431 * @return array Updated array of action links.
356 432 */
357 433 public function getPluginActionLinks( $links, $file ) {
358 434 if ( $file == plugin_basename( VISUALIZER_BASEFILE ) ) {
@@ -374,10 +450,12 @@
374 450 *
375 451 * @since 1.0.0
376 452 *
377 453 * @access public
454 + *
378 455 * @param array $plugin_meta The array of a plugin meta links.
379 456 * @param string $plugin_file The plugin's basename.
457 + *
380 458 * @return array Updated array of plugin meta links.
381 459 */
382 460 public function getPluginMetaLinks( $plugin_meta, $plugin_file ) {
383 461 if ( $plugin_file == plugin_basename( VISUALIZER_BASEFILE ) ) {