Skip to content

Commit 452e26d

Browse files
authored
Merge pull request #203 from Codeinwp/v221
Adds support manual configuration according to Google Visualization API. Improves compatibility with more features from the pro version.
2 parents 0807065 + 61767cc commit 452e26d

26 files changed

+8182
-155
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ php:
77
- '5.4'
88
- '5.3'
99
sudo: false
10+
dist: precise
1011
matrix:
1112
include:
1213
- php: '5.6'

classes/Visualizer/Module.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ protected function _addShortcode( $tag, $method ) {
146146
/**
147147
* Extracts the data for a chart and prepares it for the given type.
148148
*
149-
* @access protected
149+
* @access public
150150
* @param int $chart_id The chart id.
151151
* @param string $type The exported type.
152152
*/
153-
protected function _getDataAs( $chart_id, $type ) {
153+
public function _getDataAs( $chart_id, $type ) {
154154
$final = null;
155155
$success = false;
156156
if ( $chart_id ) {

classes/Visualizer/Module/Admin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ public function __construct( Visualizer_Plugin $plugin ) {
5858
$this->_addAction( 'admin_menu', 'registerAdminMenu' );
5959
$this->_addFilter( 'media_view_strings', 'setupMediaViewStrings' );
6060
$this->_addFilter( 'plugin_action_links', 'getPluginActionLinks', 10, 2 );
61-
$this->_addFilter( 'plugin_row_meta', 'getPluginMetaLinks', 10, 2 );
61+
$this->_addFilter( 'visualizer_logger_data', 'getLoggerData' );
62+
$this->_addFilter( 'visualizer_get_chart_counts', 'getChartCountsByTypeAndMeta' );
6263
}
6364

64-
6565
/**
6666
* Enqueues media scripts and styles.
6767
*

classes/Visualizer/Module/Chart.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,17 @@ public function renderChartPages() {
228228
'focusTarget' => 'datum',
229229
)
230230
);
231+
do_action( 'visualizer_pro_new_chart_defaults', $chart_id );
231232
}
232233
wp_redirect( add_query_arg( 'chart', (int) $chart_id ) );
233234
defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
234235
}
235236
// enqueue and register scripts and styles
236-
wp_register_style( 'visualizer-frame', VISUALIZER_ABSURL . 'css/frame.css', array(), Visualizer_Plugin::VERSION );
237-
wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'jquery' ), Visualizer_Plugin::VERSION, true );
237+
wp_register_script( 'visualizer-chosen', VISUALIZER_ABSURL . 'js/lib/chosen.jquery.min.js', array( 'jquery' ), Visualizer_Plugin::VERSION );
238+
wp_register_style( 'visualizer-chosen', VISUALIZER_ABSURL . 'css/lib/chosen.min.css', array(), Visualizer_Plugin::VERSION );
239+
240+
wp_register_style( 'visualizer-frame', VISUALIZER_ABSURL . 'css/frame.css', array( 'visualizer-chosen' ), Visualizer_Plugin::VERSION );
241+
wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'visualizer-chosen' ), Visualizer_Plugin::VERSION, true );
238242
wp_register_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true );
239243
wp_register_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true );
240244
wp_register_script(
@@ -257,15 +261,19 @@ public function renderChartPages() {
257261
}
258262
// dispatch pages
259263
$this->_chart = get_post( $chart_id );
260-
switch ( isset( $_GET['tab'] ) ? $_GET['tab'] : '' ) {
264+
$tab = isset( $_GET['tab'] ) || empty( $_GET['tab'] ) ? $_GET['tab'] : 'visualizer';
265+
switch ( $tab ) {
261266
case 'settings':
262267
// changed by Ash/Upwork
263268
$this->_handleDataAndSettingsPage();
264269
break;
265-
case 'type':
266-
default:
270+
case 'type': // fall through.
271+
case 'visualizer': // fall through.
267272
$this->_handleTypesPage();
268273
break;
274+
default:
275+
do_action( 'visualizer_pro_handle_tab', $tab, $this->_chart );
276+
break;
269277
}
270278
defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
271279
}
@@ -313,11 +321,21 @@ private function _handleDataAndSettingsPage() {
313321
'visualizer-render', 'visualizer', array(
314322
'l10n' => array(
315323
'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
324+
'loading' => esc_html__( 'Loading...', 'visualizer' ),
316325
),
317326
'charts' => array(
318327
'canvas' => $data,
319328
),
320329
'map_api_key' => get_option( 'visualizer-map-api-key' ),
330+
'ajax' => array(
331+
'url' => admin_url( 'admin-ajax.php' ),
332+
'nonces' => array(
333+
'permissions' => wp_create_nonce( Visualizer_Plugin::ACTION_FETCH_PERMISSIONS_DATA ),
334+
),
335+
'actions' => array(
336+
'permissions' => Visualizer_Plugin::ACTION_FETCH_PERMISSIONS_DATA,
337+
),
338+
),
321339
)
322340
);
323341
$render = new Visualizer_Render_Page_Data();
@@ -412,6 +430,12 @@ public function uploadData() {
412430
if ( ! isset( $_POST['vz-import-time'] ) ) {
413431
apply_filters( 'visualizer_pro_remove_schedule', $chart_id );
414432
}
433+
434+
if ( ! isset( $_POST['chart_data_src'] ) || Visualizer_Plugin::CF_SOURCE_FILTER !== $_POST['chart_data_src'] ) {
435+
// delete the filters in case this chart is being uploaded from other data sources
436+
delete_post_meta( $chart_id, 'visualizer-filter-config' );
437+
}
438+
415439
$source = null;
416440
$render = new Visualizer_Render_Page_Update();
417441
if ( isset( $_POST['remote_data'] ) && filter_var( $_POST['remote_data'], FILTER_VALIDATE_URL ) ) {
@@ -548,6 +572,7 @@ private function _handleDataPage() {
548572
'visualizer-render', 'visualizer', array(
549573
'l10n' => array(
550574
'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
575+
'loading' => esc_html__( 'Loading...', 'visualizer' ),
551576
),
552577
'charts' => array(
553578
'canvas' => $data,

classes/Visualizer/Module/Frontend.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function endpoint_register() {
7777
'visualizer/v' . VISUALIZER_REST_VERSION,
7878
'/action/(?P<chart>\d+)/(?P<type>.+)/',
7979
array(
80-
'methods' => 'GET',
80+
'methods' => array( 'GET', 'POST' ),
8181
'callback' => array( $this, 'perform_action' ),
8282
)
8383
);
@@ -130,7 +130,7 @@ public function perform_action( WP_REST_Request $params ) {
130130
$data = $this->_getDataAs( $chart_id, 'xls' );
131131
break;
132132
default:
133-
$data = apply_filters( 'visualizer_action_data', $data, $chart_id, $type );
133+
$data = apply_filters( 'visualizer_action_data', $data, $chart_id, $type, $params, $this );
134134
break;
135135
}
136136

@@ -151,6 +151,8 @@ public function enqueueScripts() {
151151
wp_register_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'visualizer-google-jsapi-old', 'jquery' ), Visualizer_Plugin::VERSION, true );
152152
wp_register_script( 'visualizer-clipboardjs', VISUALIZER_ABSURL . 'js/lib/clipboardjs/clipboard.min.js', array( 'jquery' ), Visualizer_Plugin::VERSION, true );
153153
wp_enqueue_script( 'visualizer-clipboardjs' );
154+
wp_register_style( 'visualizer-front', VISUALIZER_ABSURL . 'css/front.css', array(), Visualizer_Plugin::VERSION );
155+
do_action( 'visualizer_pro_frontend_load_resources' );
154156
}
155157

156158
/**
@@ -182,6 +184,10 @@ public function renderChart( $atts ) {
182184
return '';
183185
}
184186

187+
if ( ! apply_filters( 'visualizer_pro_show_chart', true, $atts['id'] ) ) {
188+
return '';
189+
}
190+
185191
$id = 'visualizer-' . $atts['id'];
186192
$defaultClass = 'visualizer-front';
187193
$class = apply_filters( Visualizer_Plugin::FILTER_CHART_WRAPPER_CLASS, $atts['class'], $atts['id'] );
@@ -213,7 +219,11 @@ public function renderChart( $atts ) {
213219
$data = apply_filters( $atts['data'], $data, $chart->ID, $type );
214220
}
215221

216-
$id = $id . '-' . rand();
222+
$id = $id . '-' . rand();
223+
$arguments = array( '', $id, $settings );
224+
apply_filters_ref_array( 'visualizer_pro_inline_css', array( &$arguments ) );
225+
$css = $arguments[0];
226+
$settings = $arguments[2];
217227

218228
// add chart to the array
219229
$this->_charts[ $id ] = array(
@@ -235,12 +245,14 @@ public function renderChart( $atts ) {
235245
),
236246
)
237247
);
248+
wp_enqueue_style( 'visualizer-front' );
238249

239250
$actions_div = '';
240-
if ( ! empty( $settings['actions'] ) ) {
251+
$actions_visible = apply_filters( 'visualizer_pro_add_actions', isset( $settings['actions'] ) ? $settings['actions'] : array(), $atts['id'] );
252+
if ( ! empty( $actions_visible ) ) {
241253
$actions = $this->get_actions();
242254
$actions_div = '<div class="visualizer-actions">';
243-
foreach ( $settings['actions'] as $action_type ) {
255+
foreach ( $actions_visible as $action_type ) {
244256
$key = $action_type;
245257
$mime = '';
246258
if ( strpos( $action_type, ';' ) !== false ) {
@@ -262,8 +274,10 @@ public function renderChart( $atts ) {
262274

263275
$actions_div .= '</div>';
264276
}
277+
278+
$actions_div .= $css;
279+
265280
// return placeholder div
266281
return $actions_div . '<div id="' . $id . '"' . $class . '></div>';
267282
}
268-
269283
}

classes/Visualizer/Module/Setup.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,57 @@ public function __construct( Visualizer_Plugin $plugin ) {
4444

4545
$this->_addAction( 'init', 'setupCustomPostTypes' );
4646
$this->_addAction( 'plugins_loaded', 'loadTextDomain' );
47+
$this->_addFilter( 'visualizer_logger_data', 'getLoggerData' );
48+
$this->_addFilter( 'visualizer_get_chart_counts', 'getChartCountsByTypeAndMeta' );
49+
}
50+
/**
51+
* Fetches the SDK logger data.
52+
*
53+
* @param array $data The default data that needs to be sent.
54+
*
55+
* @access public
56+
*/
57+
public function getLoggerData( $data ) {
58+
return $this->getChartCountsByTypeAndMeta();
59+
}
60+
61+
/**
62+
* Fetches the types of charts created and their counts.
63+
*
64+
* @param array $meta_keys An array of name vs. meta keys - to return how many charts have these keys.
65+
* @access private
66+
*/
67+
public function getChartCountsByTypeAndMeta( $meta_keys = array() ) {
68+
$charts = array();
69+
$charts['chart_types'] = array();
70+
// the initial query arguments to fetch charts
71+
$query_args = array(
72+
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
73+
'posts_per_page' => 300,
74+
'fields' => 'ids',
75+
'no_rows_found' => false,
76+
'update_post_meta_cache' => false,
77+
'update_post_term_cache' => false,
78+
79+
);
80+
81+
$query = new WP_Query( $query_args );
82+
while ( $query->have_posts() ) {
83+
$chart_id = $query->next_post();
84+
$type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true );
85+
$charts['chart_types'][ $type ] = isset( $charts['chart_types'][ $type ] ) ? $charts['chart_types'][ $type ] + 1 : 1;
86+
if ( ! empty( $meta_keys ) ) {
87+
foreach ( $meta_keys as $name => $key ) {
88+
$data = get_post_meta( $chart_id, $key, true );
89+
if ( ! empty( $data ) ) {
90+
$charts[ $name ] = isset( $charts[ $name ] ) ? $charts[ $name ] + 1 : 1;
91+
} else {
92+
$charts[ $name ] = 0;
93+
}
94+
}
95+
}
96+
}
97+
return $charts;
4798
}
4899

49100
/**

classes/Visualizer/Module/Sources.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,12 @@ public function filterChartData( $data, $chart_id ) {
130130
* @return string The new html code.
131131
*/
132132
public function addProUpsell( $old, $feature = null ) {
133+
$biz_features = array( 'schedule-chart', 'chart-permissions' );
133134
$return = '';
134135
$feature = strval( $feature );
135-
if ( empty( $feature ) || ( $feature == 'schedule-chart' && ! apply_filters( 'visualizer_is_business', false ) ) ) {
136+
if ( empty( $feature ) || ( in_array( $feature, $biz_features ) && ! apply_filters( 'visualizer_is_business', false ) ) ) {
136137
$plan = 'PRO';
137-
if ( $feature === 'schedule-chart' ) {
138+
if ( in_array( $feature, $biz_features ) ) {
138139
$plan = 'BUSINESS';
139140
}
140141
$return = '<div class="only-pro-content">';

classes/Visualizer/Plugin.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
class Visualizer_Plugin {
2929

3030
const NAME = 'visualizer';
31-
const VERSION = '2.2.0';
31+
const VERSION = '3.0.0';
3232

3333
// custom post types
3434
const CPT_VISUALIZER = 'visualizer';
@@ -40,6 +40,8 @@ class Visualizer_Plugin {
4040
const CF_DEFAULT_DATA = 'visualizer-default-data';
4141
const CF_SETTINGS = 'visualizer-settings';
4242

43+
const CF_SOURCE_FILTER = 'visualizer-source-filter';
44+
4345
// custom actions
4446
const ACTION_GET_CHARTS = 'visualizer-get-charts';
4547
const ACTION_CREATE_CHART = 'visualizer-create-chart';
@@ -50,6 +52,11 @@ class Visualizer_Plugin {
5052
// Added by Ash/Upwork
5153
const ACTION_EXPORT_DATA = 'visualizer-export-data';
5254

55+
/**
56+
*Action used for fetching specific users/roles for permissions.
57+
*/
58+
const ACTION_FETCH_PERMISSIONS_DATA = 'visualizer-fetch-permissions-data';
59+
5360
// custom filters
5461
const FILTER_CHART_WRAPPER_CLASS = 'visualizer-chart-wrapper-class';
5562
const FILTER_GET_CHART_SERIES = 'visualizer-get-chart-series';

classes/Visualizer/Render/Library.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ private function _renderSidebar() {
217217
echo '<h3>' . __( 'Gain more editing power', 'visualizer' ) . '</h3><ul>';
218218
echo '<li>' . __( 'Spreadsheet like editor', 'visualizer' ) . '</li>';
219219
echo '<li>' . __( 'Import from other charts', 'visualizer' ) . '</li>';
220+
echo '<li>' . __( 'Frontend editor', 'visualizer' ) . '</li>';
221+
echo '<li>' . __( 'Private charts', 'visualizer' ) . '</li>';
220222
echo '<li>' . __( 'Auto-sync with online files', 'visualizer' ) . '</li>';
221223
echo '<li>' . __( '3 more chart types', 'visualizer' ) . '</li></ul>';
222224
echo '<a href="' . Visualizer_Plugin::PRO_TEASER_URL . '" target="_blank" class="button button-primary">' . __( 'View more features', 'visualizer' ) . '</a>';

0 commit comments

Comments
 (0)