1
1
<?php
2
-
3
2
// +----------------------------------------------------------------------+
4
3
// | Copyright 2013 Madpixels (email : [email protected] ) |
5
4
// +----------------------------------------------------------------------+
19
18
// +----------------------------------------------------------------------+
20
19
// | Author: Eugene Manuilov <[email protected] > |
21
20
// +----------------------------------------------------------------------+
21
+
22
22
/**
23
23
* The module for all admin stuff.
24
24
*
@@ -52,7 +52,6 @@ class Visualizer_Module_Admin extends Visualizer_Module {
52
52
*/
53
53
public function __construct ( Visualizer_Plugin $ plugin ) {
54
54
parent ::__construct ( $ plugin );
55
-
56
55
$ this ->_addAction ( 'load-post.php ' , 'enqueueMediaScripts ' );
57
56
$ this ->_addAction ( 'load-post-new.php ' , 'enqueueMediaScripts ' );
58
57
$ this ->_addAction ( 'admin_footer ' , 'renderTempaltes ' );
@@ -61,6 +60,30 @@ public function __construct( Visualizer_Plugin $plugin ) {
61
60
$ this ->_addFilter ( 'media_view_strings ' , 'setupMediaViewStrings ' );
62
61
$ this ->_addFilter ( 'plugin_action_links ' , 'getPluginActionLinks ' , 10 , 2 );
63
62
$ this ->_addFilter ( 'plugin_row_meta ' , 'getPluginMetaLinks ' , 10 , 2 );
63
+ $ this ->_addFilter ( 'visualizer_logger_flag ' , 'get_logger_flag ' , 10 , 1 );
64
+ $ this ->_addAjaxAction ( Visualizer_Plugin::ACTION_TRACK , 'visualizer_enable_track ' );
65
+ }
66
+
67
+ public function visualizer_enable_track () {
68
+ check_admin_referer ( Visualizer_Plugin::ACTION_TRACK , 'nonce ' );
69
+ $ status = $ _GET ['status ' ];
70
+ if ( $ status == 'yes ' ) {
71
+ update_option ( 'visualizer_logger_flag ' , 'yes ' );
72
+ } else {
73
+ update_option ( 'visualizer_logger_flag ' , 'no ' );
74
+ }
75
+ wp_send_json_success ( array ( 'status ' => $ status ) );
76
+ }
77
+
78
+ /**
79
+ * Either the tracking is active or not.
80
+ *
81
+ * @return bool The flag status.
82
+ */
83
+ public function get_logger_flag () {
84
+ $ flag = get_option ( 'visualizer_logger_flag ' , 'no ' );
85
+
86
+ return ( $ flag === 'yes ' );
64
87
}
65
88
66
89
/**
@@ -74,10 +97,8 @@ public function __construct( Visualizer_Plugin $plugin ) {
74
97
*/
75
98
public function enqueueMediaScripts () {
76
99
global $ typenow ;
77
-
78
100
if ( post_type_supports ( $ typenow , 'editor ' ) ) {
79
101
wp_enqueue_style ( 'visualizer-media ' , VISUALIZER_ABSURL . 'css/media.css ' , array ( 'media-views ' ), Visualizer_Plugin::VERSION );
80
-
81
102
wp_enqueue_script ( 'visualizer-google-jsapi-new ' , '//www.gstatic.com/charts/loader.js ' , array ( 'media-editor ' ), null , true );
82
103
wp_enqueue_script ( 'visualizer-google-jsapi-old ' , '//www.google.com/jsapi ' , array ( 'visualizer-google-jsapi-new ' ), null , true );
83
104
wp_enqueue_script ( 'visualizer-media-model ' , VISUALIZER_ABSURL . 'js/media/model.js ' , array ( 'visualizer-google-jsapi-old ' ), Visualizer_Plugin::VERSION , true );
@@ -136,58 +157,56 @@ public function setupMediaViewStrings( $strings ) {
136
157
public static function _getChartTypesLocalized ( $ enabledOnly = false , $ get2Darray = false ) {
137
158
$ types = array (
138
159
'pie ' => array (
139
- 'name ' => esc_html__ ( 'Pie ' , 'visualizer ' ),
160
+ 'name ' => esc_html__ ( 'Pie ' , 'visualizer ' ),
140
161
'enabled ' => true ,
141
162
),
142
163
'line ' => array (
143
- 'name ' => esc_html__ ( 'Line ' , 'visualizer ' ),
164
+ 'name ' => esc_html__ ( 'Line ' , 'visualizer ' ),
144
165
'enabled ' => true ,
145
166
),
146
167
'area ' => array (
147
- 'name ' => esc_html__ ( 'Area ' , 'visualizer ' ),
168
+ 'name ' => esc_html__ ( 'Area ' , 'visualizer ' ),
148
169
'enabled ' => true ,
149
170
),
150
171
'geo ' => array (
151
- 'name ' => esc_html__ ( 'Geo ' , 'visualizer ' ),
172
+ 'name ' => esc_html__ ( 'Geo ' , 'visualizer ' ),
152
173
'enabled ' => true ,
153
174
),
154
175
'bar ' => array (
155
- 'name ' => esc_html__ ( 'Bar ' , 'visualizer ' ),
176
+ 'name ' => esc_html__ ( 'Bar ' , 'visualizer ' ),
156
177
'enabled ' => true ,
157
178
),
158
179
'column ' => array (
159
- 'name ' => esc_html__ ( 'Column ' , 'visualizer ' ),
180
+ 'name ' => esc_html__ ( 'Column ' , 'visualizer ' ),
160
181
'enabled ' => true ,
161
182
),
162
183
'gauge ' => array (
163
- 'name ' => esc_html__ ( 'Gauge ' , 'visualizer ' ),
184
+ 'name ' => esc_html__ ( 'Gauge ' , 'visualizer ' ),
164
185
'enabled ' => true ,
165
186
),
166
187
'scatter ' => array (
167
- 'name ' => esc_html__ ( 'Scatter ' , 'visualizer ' ),
188
+ 'name ' => esc_html__ ( 'Scatter ' , 'visualizer ' ),
168
189
'enabled ' => true ,
169
190
),
170
191
'candlestick ' => array (
171
- 'name ' => esc_html__ ( 'Candlestick ' , 'visualizer ' ),
192
+ 'name ' => esc_html__ ( 'Candlestick ' , 'visualizer ' ),
172
193
'enabled ' => true ,
173
194
),
174
195
// pro types
175
196
'table ' => array (
176
- 'name ' => esc_html__ ( 'Table ' , 'visualizer ' ),
197
+ 'name ' => esc_html__ ( 'Table ' , 'visualizer ' ),
177
198
'enabled ' => false ,
178
199
),
179
200
'timeline ' => array (
180
- 'name ' => esc_html__ ( 'Timeline ' , 'visualizer ' ),
201
+ 'name ' => esc_html__ ( 'Timeline ' , 'visualizer ' ),
181
202
'enabled ' => false ,
182
203
),
183
204
'combo ' => array (
184
- 'name ' => esc_html__ ( 'Combo ' , 'visualizer ' ),
205
+ 'name ' => esc_html__ ( 'Combo ' , 'visualizer ' ),
185
206
'enabled ' => false ,
186
207
),
187
208
);
188
-
189
209
$ types = apply_filters ( 'visualizer_pro_chart_types ' , $ types );
190
-
191
210
if ( $ enabledOnly ) {
192
211
$ filtered = array ();
193
212
foreach ( $ types as $ type => $ array ) {
@@ -198,7 +217,6 @@ public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darra
198
217
}
199
218
$ types = $ filtered ;
200
219
}
201
-
202
220
if ( $ get2Darray ) {
203
221
$ doubleD = array ();
204
222
foreach ( $ types as $ type => $ array ) {
@@ -220,11 +238,9 @@ public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darra
220
238
*/
221
239
public function renderTempaltes () {
222
240
global $ pagenow ;
223
-
224
241
if ( 'post.php ' != $ pagenow && 'post-new.php ' != $ pagenow ) {
225
242
return ;
226
243
}
227
-
228
244
$ render = new Visualizer_Render_Templates ();
229
245
$ render ->render ();
230
246
}
@@ -244,9 +260,7 @@ public function renderTempaltes() {
244
260
public function enqueueLibraryScripts ( $ suffix ) {
245
261
if ( $ suffix == $ this ->_libraryPage ) {
246
262
wp_enqueue_style ( 'visualizer-library ' , VISUALIZER_ABSURL . 'css/library.css ' , array (), Visualizer_Plugin::VERSION );
247
-
248
263
$ this ->_addFilter ( 'media_upload_tabs ' , 'setupVisualizerTab ' );
249
-
250
264
wp_enqueue_media ();
251
265
wp_enqueue_script ( 'visualizer-library ' , VISUALIZER_ABSURL . 'js/library.js ' , array (
252
266
'jquery ' ,
@@ -306,14 +320,12 @@ public function renderLibraryPage() {
306
320
'default ' => 1 ,
307
321
),
308
322
) );
309
-
310
323
// the initial query arguments to fetch charts
311
324
$ query_args = array (
312
325
'post_type ' => Visualizer_Plugin::CPT_VISUALIZER ,
313
326
'posts_per_page ' => 6 ,
314
327
'paged ' => $ page ,
315
328
);
316
-
317
329
// add chart type filter to the query arguments
318
330
$ filter = filter_input ( INPUT_GET , 'type ' );
319
331
if ( $ filter && in_array ( $ filter , Visualizer_Plugin::getChartTypes () ) ) {
@@ -327,7 +339,6 @@ public function renderLibraryPage() {
327
339
} else {
328
340
$ filter = 'all ' ;
329
341
}
330
-
331
342
// Added by Ash/Upwork
332
343
$ filterByMeta = filter_input ( INPUT_GET , 's ' , FILTER_SANITIZE_STRING );
333
344
if ( $ filterByMeta ) {
@@ -346,15 +357,12 @@ public function renderLibraryPage() {
346
357
$ query = new WP_Query ( $ query_args );
347
358
while ( $ query ->have_posts () ) {
348
359
$ chart = $ query ->next_post ();
349
-
350
360
// fetch and update settings
351
361
$ settings = get_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_SETTINGS , true );
352
362
unset( $ settings ['height ' ], $ settings ['width ' ] );
353
-
354
363
$ type = get_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_CHART_TYPE , true );
355
364
$ series = apply_filters ( Visualizer_Plugin::FILTER_GET_CHART_SERIES , get_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_SERIES , true ), $ chart ->ID , $ type );
356
365
$ data = apply_filters ( Visualizer_Plugin::FILTER_GET_CHART_DATA , unserialize ( $ chart ->post_content ), $ chart ->ID , $ type );
357
-
358
366
// add chart to the array
359
367
$ charts [ 'visualizer- ' . $ chart ->ID ] = array (
360
368
'id ' => $ chart ->ID ,
@@ -364,7 +372,6 @@ public function renderLibraryPage() {
364
372
'data ' => $ data ,
365
373
);
366
374
}
367
-
368
375
// enqueue charts array
369
376
$ ajaxurl = admin_url ( 'admin-ajax.php ' );
370
377
wp_localize_script ( 'visualizer-library ' , 'visualizer ' , array (
@@ -379,12 +386,15 @@ public function renderLibraryPage() {
379
386
'action ' => Visualizer_Plugin::ACTION_EDIT_CHART ,
380
387
'library ' => 'yes ' ,
381
388
), $ ajaxurl ),
389
+ 'logger ' => add_query_arg ( array (
390
+ 'action ' => Visualizer_Plugin::ACTION_TRACK ,
391
+ 'library ' => 'yes ' ,
392
+ 'nonce ' => wp_create_nonce ( Visualizer_Plugin::ACTION_TRACK ),
393
+ ), $ ajaxurl ),
382
394
),
383
395
) );
384
-
385
396
// render library page
386
- $ render = new Visualizer_Render_Library ();
387
-
397
+ $ render = new Visualizer_Render_Library ();
388
398
$ render ->charts = $ charts ;
389
399
$ render ->type = $ filter ;
390
400
$ render ->types = self ::_getChartTypesLocalized ();
@@ -395,7 +405,6 @@ public function renderLibraryPage() {
395
405
'total ' => $ query ->max_num_pages ,
396
406
'type ' => 'array ' ,
397
407
) );
398
-
399
408
$ render ->render ();
400
409
}
401
410
@@ -406,7 +415,7 @@ public function renderLibraryPage() {
406
415
*
407
416
* @access public
408
417
*
409
- * @param array $links The array of original action links.
418
+ * @param array $links The array of original action links.
410
419
* @param string $file The plugin basename.
411
420
*
412
421
* @return array Updated array of action links.
@@ -433,7 +442,7 @@ public function getPluginActionLinks( $links, $file ) {
433
442
*
434
443
* @access public
435
444
*
436
- * @param array $plugin_meta The array of a plugin meta links.
445
+ * @param array $plugin_meta The array of a plugin meta links.
437
446
* @param string $plugin_file The plugin's basename.
438
447
*
439
448
* @return array Updated array of plugin meta links.
@@ -455,6 +464,4 @@ public function getPluginMetaLinks( $plugin_meta, $plugin_file ) {
455
464
return $ plugin_meta ;
456
465
}
457
466
458
-
459
-
460
467
}
0 commit comments