Skip to content

Commit e835861

Browse files
committed
added tracking for visualzier.
added sidebar.
1 parent 3b93cf1 commit e835861

File tree

5 files changed

+307
-263
lines changed

5 files changed

+307
-263
lines changed

classes/Visualizer/Module/Admin.php

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
// +----------------------------------------------------------------------+
43
// | Copyright 2013 Madpixels (email : [email protected]) |
54
// +----------------------------------------------------------------------+
@@ -19,6 +18,7 @@
1918
// +----------------------------------------------------------------------+
2019
// | Author: Eugene Manuilov <[email protected]> |
2120
// +----------------------------------------------------------------------+
21+
2222
/**
2323
* The module for all admin stuff.
2424
*
@@ -52,7 +52,6 @@ class Visualizer_Module_Admin extends Visualizer_Module {
5252
*/
5353
public function __construct( Visualizer_Plugin $plugin ) {
5454
parent::__construct( $plugin );
55-
5655
$this->_addAction( 'load-post.php', 'enqueueMediaScripts' );
5756
$this->_addAction( 'load-post-new.php', 'enqueueMediaScripts' );
5857
$this->_addAction( 'admin_footer', 'renderTempaltes' );
@@ -61,6 +60,30 @@ public function __construct( Visualizer_Plugin $plugin ) {
6160
$this->_addFilter( 'media_view_strings', 'setupMediaViewStrings' );
6261
$this->_addFilter( 'plugin_action_links', 'getPluginActionLinks', 10, 2 );
6362
$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' );
6487
}
6588

6689
/**
@@ -74,10 +97,8 @@ public function __construct( Visualizer_Plugin $plugin ) {
7497
*/
7598
public function enqueueMediaScripts() {
7699
global $typenow;
77-
78100
if ( post_type_supports( $typenow, 'editor' ) ) {
79101
wp_enqueue_style( 'visualizer-media', VISUALIZER_ABSURL . 'css/media.css', array( 'media-views' ), Visualizer_Plugin::VERSION );
80-
81102
wp_enqueue_script( 'visualizer-google-jsapi-new', '//www.gstatic.com/charts/loader.js', array( 'media-editor' ), null, true );
82103
wp_enqueue_script( 'visualizer-google-jsapi-old', '//www.google.com/jsapi', array( 'visualizer-google-jsapi-new' ), null, true );
83104
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 ) {
136157
public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darray = false ) {
137158
$types = array(
138159
'pie' => array(
139-
'name' => esc_html__( 'Pie', 'visualizer' ),
160+
'name' => esc_html__( 'Pie', 'visualizer' ),
140161
'enabled' => true,
141162
),
142163
'line' => array(
143-
'name' => esc_html__( 'Line', 'visualizer' ),
164+
'name' => esc_html__( 'Line', 'visualizer' ),
144165
'enabled' => true,
145166
),
146167
'area' => array(
147-
'name' => esc_html__( 'Area', 'visualizer' ),
168+
'name' => esc_html__( 'Area', 'visualizer' ),
148169
'enabled' => true,
149170
),
150171
'geo' => array(
151-
'name' => esc_html__( 'Geo', 'visualizer' ),
172+
'name' => esc_html__( 'Geo', 'visualizer' ),
152173
'enabled' => true,
153174
),
154175
'bar' => array(
155-
'name' => esc_html__( 'Bar', 'visualizer' ),
176+
'name' => esc_html__( 'Bar', 'visualizer' ),
156177
'enabled' => true,
157178
),
158179
'column' => array(
159-
'name' => esc_html__( 'Column', 'visualizer' ),
180+
'name' => esc_html__( 'Column', 'visualizer' ),
160181
'enabled' => true,
161182
),
162183
'gauge' => array(
163-
'name' => esc_html__( 'Gauge', 'visualizer' ),
184+
'name' => esc_html__( 'Gauge', 'visualizer' ),
164185
'enabled' => true,
165186
),
166187
'scatter' => array(
167-
'name' => esc_html__( 'Scatter', 'visualizer' ),
188+
'name' => esc_html__( 'Scatter', 'visualizer' ),
168189
'enabled' => true,
169190
),
170191
'candlestick' => array(
171-
'name' => esc_html__( 'Candlestick', 'visualizer' ),
192+
'name' => esc_html__( 'Candlestick', 'visualizer' ),
172193
'enabled' => true,
173194
),
174195
// pro types
175196
'table' => array(
176-
'name' => esc_html__( 'Table', 'visualizer' ),
197+
'name' => esc_html__( 'Table', 'visualizer' ),
177198
'enabled' => false,
178199
),
179200
'timeline' => array(
180-
'name' => esc_html__( 'Timeline', 'visualizer' ),
201+
'name' => esc_html__( 'Timeline', 'visualizer' ),
181202
'enabled' => false,
182203
),
183204
'combo' => array(
184-
'name' => esc_html__( 'Combo', 'visualizer' ),
205+
'name' => esc_html__( 'Combo', 'visualizer' ),
185206
'enabled' => false,
186207
),
187208
);
188-
189209
$types = apply_filters( 'visualizer_pro_chart_types', $types );
190-
191210
if ( $enabledOnly ) {
192211
$filtered = array();
193212
foreach ( $types as $type => $array ) {
@@ -198,7 +217,6 @@ public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darra
198217
}
199218
$types = $filtered;
200219
}
201-
202220
if ( $get2Darray ) {
203221
$doubleD = array();
204222
foreach ( $types as $type => $array ) {
@@ -220,11 +238,9 @@ public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darra
220238
*/
221239
public function renderTempaltes() {
222240
global $pagenow;
223-
224241
if ( 'post.php' != $pagenow && 'post-new.php' != $pagenow ) {
225242
return;
226243
}
227-
228244
$render = new Visualizer_Render_Templates();
229245
$render->render();
230246
}
@@ -244,9 +260,7 @@ public function renderTempaltes() {
244260
public function enqueueLibraryScripts( $suffix ) {
245261
if ( $suffix == $this->_libraryPage ) {
246262
wp_enqueue_style( 'visualizer-library', VISUALIZER_ABSURL . 'css/library.css', array(), Visualizer_Plugin::VERSION );
247-
248263
$this->_addFilter( 'media_upload_tabs', 'setupVisualizerTab' );
249-
250264
wp_enqueue_media();
251265
wp_enqueue_script( 'visualizer-library', VISUALIZER_ABSURL . 'js/library.js', array(
252266
'jquery',
@@ -306,14 +320,12 @@ public function renderLibraryPage() {
306320
'default' => 1,
307321
),
308322
) );
309-
310323
// the initial query arguments to fetch charts
311324
$query_args = array(
312325
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
313326
'posts_per_page' => 6,
314327
'paged' => $page,
315328
);
316-
317329
// add chart type filter to the query arguments
318330
$filter = filter_input( INPUT_GET, 'type' );
319331
if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes() ) ) {
@@ -327,7 +339,6 @@ public function renderLibraryPage() {
327339
} else {
328340
$filter = 'all';
329341
}
330-
331342
// Added by Ash/Upwork
332343
$filterByMeta = filter_input( INPUT_GET, 's', FILTER_SANITIZE_STRING );
333344
if ( $filterByMeta ) {
@@ -346,15 +357,12 @@ public function renderLibraryPage() {
346357
$query = new WP_Query( $query_args );
347358
while ( $query->have_posts() ) {
348359
$chart = $query->next_post();
349-
350360
// fetch and update settings
351361
$settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
352362
unset( $settings['height'], $settings['width'] );
353-
354363
$type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
355364
$series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type );
356365
$data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( $chart->post_content ), $chart->ID, $type );
357-
358366
// add chart to the array
359367
$charts[ 'visualizer-' . $chart->ID ] = array(
360368
'id' => $chart->ID,
@@ -364,7 +372,6 @@ public function renderLibraryPage() {
364372
'data' => $data,
365373
);
366374
}
367-
368375
// enqueue charts array
369376
$ajaxurl = admin_url( 'admin-ajax.php' );
370377
wp_localize_script( 'visualizer-library', 'visualizer', array(
@@ -379,12 +386,15 @@ public function renderLibraryPage() {
379386
'action' => Visualizer_Plugin::ACTION_EDIT_CHART,
380387
'library' => 'yes',
381388
), $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 ),
382394
),
383395
) );
384-
385396
// render library page
386-
$render = new Visualizer_Render_Library();
387-
397+
$render = new Visualizer_Render_Library();
388398
$render->charts = $charts;
389399
$render->type = $filter;
390400
$render->types = self::_getChartTypesLocalized();
@@ -395,7 +405,6 @@ public function renderLibraryPage() {
395405
'total' => $query->max_num_pages,
396406
'type' => 'array',
397407
) );
398-
399408
$render->render();
400409
}
401410

@@ -406,7 +415,7 @@ public function renderLibraryPage() {
406415
*
407416
* @access public
408417
*
409-
* @param array $links The array of original action links.
418+
* @param array $links The array of original action links.
410419
* @param string $file The plugin basename.
411420
*
412421
* @return array Updated array of action links.
@@ -433,7 +442,7 @@ public function getPluginActionLinks( $links, $file ) {
433442
*
434443
* @access public
435444
*
436-
* @param array $plugin_meta The array of a plugin meta links.
445+
* @param array $plugin_meta The array of a plugin meta links.
437446
* @param string $plugin_file The plugin's basename.
438447
*
439448
* @return array Updated array of plugin meta links.
@@ -455,6 +464,4 @@ public function getPluginMetaLinks( $plugin_meta, $plugin_file ) {
455464
return $plugin_meta;
456465
}
457466

458-
459-
460467
}

classes/Visualizer/Plugin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Visualizer_Plugin {
4343

4444
// custom actions
4545
const ACTION_GET_CHARTS = 'visualizer-get-charts';
46+
const ACTION_TRACK = 'visualizer-track';
4647
const ACTION_CREATE_CHART = 'visualizer-create-chart';
4748
const ACTION_EDIT_CHART = 'visualizer-edit-chart';
4849
const ACTION_CLONE_CHART = 'visualizer-clone-chart';

classes/Visualizer/Render/Library.php

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// +----------------------------------------------------------------------+
1919
// | Author: Eugene Manuilov <[email protected]> |
2020
// +----------------------------------------------------------------------+
21+
2122
/**
2223
* Renders visualizer library page.
2324
*
@@ -85,7 +86,7 @@ private function _renderLibrary() {
8586
$link = '<a class=" " href="' . esc_url( add_query_arg( array(
8687
'type' => $type,
8788
'vpage' => false,
88-
) ) ) . '">';
89+
) ) ) . '">';
8990
if ( ! $array['enabled'] ) {
9091
$link = "<a class=' visualizer-pro-only' href='" . Visualizer_Plugin::PRO_TEASER_URL . "' target='_blank'>";
9192
}
@@ -108,6 +109,7 @@ private function _renderLibrary() {
108109
<input type="submit" id="search-submit" class="button button-secondary" value="' . esc_attr__( 'Search', 'visualizer' ) . '">
109110
</p> </form>';
110111
echo '</div>';
112+
echo '<div id="visualizer-content-wrapper">';
111113
if ( ! empty( $this->charts ) ) {
112114
echo '<div id="visualizer-library" class="visualizer-clearfix">';
113115
foreach ( $this->charts as $placeholder_id => $chart ) {
@@ -139,22 +141,7 @@ private function _renderLibrary() {
139141
echo '</div>';
140142
echo '</div>';
141143
}
142-
echo '<div id="visualizer-sidebar">';
143-
echo '<div class="visualizer-sidebar-box">';
144-
echo '<h3>' . __( 'Upgrade to PRO', 'visualizer' ) . '</h3><ul>';
145-
echo '<li>' . __( 'Upgrade to PRO', 'visualizer' ) . '</li>';
146-
echo '<li>' . __( 'Upgrade to PRO', 'visualizer' ) . '</li>';
147-
echo '<li>' . __( 'Upgrade to PRO', 'visualizer' ) . '</li></ul>';
148-
echo '<a href="' . Visualizer_Plugin::PRO_TEASER_URL . '" target="_blank" class="button button-primary">' . __( 'View more', 'visualizer' ) . '</a>';
149-
echo '</div>';
150-
echo '<div class="visualizer-sidebar-box visualizer-tracking">';
151-
echo '<label class="visualizer-switch">';
152-
echo '<input type="checkbox" >';
153-
echo '<div class="visualizer-slider visualizer-round"></div>';
154-
echo '</label>';
155-
echo '<span>Enable Tracking<sup>*</sup></span>';
156-
echo '<p><small>' . __( 'You can help us improve the plugin by allowing to gather data.','visualizer' ) . '</small></p>';
157-
echo '</div>';
144+
$this->_renderSidebar();
158145
echo '</div>';
159146
}
160147

@@ -166,7 +153,7 @@ private function _renderLibrary() {
166153
* @access private
167154
*
168155
* @param string $placeholder_id The placeholder's id for the chart.
169-
* @param int $chart_id The id of the chart.
156+
* @param int $chart_id The id of the chart.
170157
*/
171158
private function _renderChartBox( $placeholder_id, $chart_id ) {
172159
$ajax_url = admin_url( 'admin-ajax.php' );
@@ -202,4 +189,30 @@ private function _renderChartBox( $placeholder_id, $chart_id ) {
202189
echo '</div>';
203190
}
204191

192+
/**
193+
* Render sidebar.
194+
*/
195+
private function _renderSidebar() {
196+
$checked = apply_filters( 'visualizer_logger_flag', false );
197+
$checked = ( $checked === false ) ? '' : 'checked';
198+
echo '<div id="visualizer-sidebar">';
199+
echo '<div class="visualizer-sidebar-box">';
200+
echo '<h3>' . __( 'Gain more editing power', 'visualizer' ) . '</h3><ul>';
201+
echo '<li>' . __( 'Spreadsheet editor', 'visualizer' ) . '</li>';
202+
echo '<li>' . __( 'Import from other charts', 'visualizer' ) . '</li>';
203+
echo '<li>' . __( 'Auto-sync with online files', 'visualizer' ) . '</li>';
204+
echo '<li>' . __( '+ 3 types of charts', 'visualizer' ) . '</li></ul>';
205+
echo '<a href="' . Visualizer_Plugin::PRO_TEASER_URL . '" target="_blank" class="button button-primary">' . __( 'View more features', 'visualizer' ) . '</a>';
206+
echo '</div>';
207+
echo '<div class="visualizer-sidebar-box visualizer-tracking">';
208+
echo '<label class="visualizer-switch">';
209+
echo '<input type="checkbox" ' . $checked . ' >';
210+
echo '<div class="visualizer-slider visualizer-round"></div>';
211+
echo '</label>';
212+
echo '<span>' . __( 'Enable Tracking', 'visualizer' ) . '<sup>*</sup></span>';
213+
echo '<p><small><sup>*</sup>' . __( 'Allow Visualizer to anonymously track how this plugin is used and help us make the plugin better. No sensitive data is tracked.', 'visualizer' ) . '</small></p>';
214+
echo '</div>';
215+
echo '</div>';
216+
}
217+
205218
}

0 commit comments

Comments
 (0)