Skip to content

Commit 84af54b

Browse files
Support for PRO version
Support PRO version as an add-on. PRO version includes live editor feature.
1 parent 94f93ff commit 84af54b

File tree

6 files changed

+83
-7
lines changed

6 files changed

+83
-7
lines changed

classes/Visualizer/Module.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public function __construct( Visualizer_Plugin $plugin ) {
7979
* @param int $accepted_args optional. The number of arguments the function accept (default 1).
8080
* @return Visualizer_Module
8181
*/
82-
protected function _addAction( $tag, $method, $priority = 10, $accepted_args = 1 ) {
83-
add_action( $tag, array( $this, $method ), $priority, $accepted_args );
82+
protected function _addAction( $tag, $method, $methodClass=NULL, $priority = 10, $accepted_args = 1 ) {
83+
add_action( $tag, array( $methodClass ? $methodClass : $this, $method ), $priority, $accepted_args );
8484
return $this;
8585
}
8686

@@ -96,13 +96,13 @@ protected function _addAction( $tag, $method, $priority = 10, $accepted_args = 1
9696
* @param boolean $public Optional. Determines if we should register hook for not logged in users.
9797
* @return Visualizer_Module
9898
*/
99-
protected function _addAjaxAction( $tag, $method = '', $private = true, $public = false ) {
99+
protected function _addAjaxAction( $tag, $method = '', $methodClass=NULL, $private = true, $public = false ) {
100100
if ( $private ) {
101-
$this->_addAction( 'wp_ajax_' . $tag, $method );
101+
$this->_addAction( 'wp_ajax_' . $tag, $method, $methodClass );
102102
}
103103

104104
if ( $public ) {
105-
$this->_addAction( 'wp_ajax_nopriv_' . $tag, $method );
105+
$this->_addAction( 'wp_ajax_nopriv_' . $tag, $method, $methodClass );
106106
}
107107

108108
return $this;

classes/Visualizer/Module/Chart.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ public function __construct( Visualizer_Plugin $plugin ) {
5959
$this->_addAjaxAction( Visualizer_Plugin::ACTION_EDIT_CHART, 'renderChartPages' );
6060
$this->_addAjaxAction( Visualizer_Plugin::ACTION_UPLOAD_DATA, 'uploadData' );
6161
$this->_addAjaxAction( Visualizer_Plugin::ACTION_CLONE_CHART, 'cloneChart' );
62+
63+
// Added by Ash/Upwork
64+
if( defined( 'Visualizer_Pro' ) ){
65+
global $Visualizer_Pro;
66+
list($action, $name, $class) = $Visualizer_Pro->_getAjaxAction($this);
67+
$this->_addAjaxAction($action, $name, $class);
68+
}
69+
// Added by Ash/Upwork
70+
6271
}
6372

6473
/**
@@ -69,7 +78,7 @@ public function __construct( Visualizer_Plugin $plugin ) {
6978
* @access private
7079
* @param array $results The response array.
7180
*/
72-
private function _sendResponse( $results ) {
81+
public function _sendResponse( $results ) {
7382
header( 'Content-type: application/json' );
7483
nocache_headers();
7584

@@ -234,6 +243,12 @@ public function renderChartPages() {
234243
wp_register_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'google-jsapi', 'visualizer-frame' ), Visualizer_Plugin::VERSION, true );
235244
wp_register_script( 'visualizer-preview', VISUALIZER_ABSURL . 'js/preview.js', array( 'wp-color-picker', 'visualizer-render' ), Visualizer_Plugin::VERSION, true );
236245

246+
// added by Ash/Upwork
247+
if( defined( 'Visualizer_Pro' ) ){
248+
global $Visualizer_Pro;
249+
$Visualizer_Pro->_addScriptsAndStyles();
250+
}
251+
237252
// dispatch pages
238253
$this->_chart = $chart;
239254
switch ( filter_input( INPUT_GET, 'tab' ) ) {
@@ -323,6 +338,13 @@ private function _handleDataPage() {
323338
),
324339
) );
325340

341+
// Added by Ash/Upwork
342+
if( defined( 'Visualizer_Pro' ) ){
343+
global $Visualizer_Pro;
344+
$Visualizer_Pro->_enqueueScriptsAndStyles($data);
345+
}
346+
// Added by Ash/Upwork
347+
326348
$this->_addAction( 'admin_head', 'renderFlattrScript' );
327349

328350
wp_iframe( array( $render, 'render') );
@@ -440,6 +462,13 @@ public function uploadData() {
440462
$source = new Visualizer_Source_Csv_Remote( $_POST['remote_data'] );
441463
} elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) {
442464
$source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] );
465+
466+
// Added by Ash/Upwork
467+
} elseif ( defined( 'Visualizer_Pro' ) && isset( $_POST['chart_data'] ) && strlen( $_POST['chart_data'] ) > 0){
468+
global $Visualizer_Pro;
469+
$source = $Visualizer_Pro->_handleChartData($_POST['chart_data']);
470+
// Added by Ash/Upwork
471+
443472
} else {
444473
$render->message = esc_html__( "CSV file with chart data was not uploaded. Please, try again.", Visualizer_Plugin::NAME );
445474
}

classes/Visualizer/Plugin.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ class Visualizer_Plugin {
5555
const FILTER_GET_CHART_SERIES = 'visualizer-get-chart-series';
5656
const FILTER_GET_CHART_DATA = 'visualizer-get-chart-data';
5757

58+
// Added by Ash/Upwork
59+
const PRO_TEASER_URL = "http://www.google.com";
60+
const PRO_TEASER_TITLE = "blah";
61+
// Added by Ash/Upwork
62+
5863
/**
5964
* Singletone instance of the plugin.
6065
*

classes/Visualizer/Render/Page/Data.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ class Visualizer_Render_Page_Data extends Visualizer_Render_Page {
3939
* @access protected
4040
*/
4141
protected function _renderContent() {
42-
echo '<div id="canvas">';
42+
// Added by Ash/Upwork
43+
if( defined( 'Visualizer_Pro' ) ){
44+
global $Visualizer_Pro;
45+
$Visualizer_Pro->_addEditor();
46+
}
47+
// Added by Ash/Upwork
48+
49+
echo '<div id="canvas">';
4350
echo '<img src="', VISUALIZER_ABSURL, 'images/ajax-loader.gif" class="loader">';
4451
echo '</div>';
4552
}
@@ -81,10 +88,31 @@ protected function _renderSidebarContent() {
8188
esc_attr_e( 'From Computer', Visualizer_Plugin::NAME );
8289
echo '</div>';
8390

91+
// Added by Ash/Upwork
92+
if( defined( 'Visualizer_Pro' ) ){
93+
global $Visualizer_Pro;
94+
$Visualizer_Pro->_addFormElements();
95+
}
96+
// Added by Ash/Upwork
97+
8498
echo '<div>';
8599
echo '<a id="remote-file" class="button" href="javascript:;">', esc_html__( 'From Web', Visualizer_Plugin::NAME ), '</a>';
86100
echo '</div>';
87101
echo '</form>';
102+
103+
// added by Ash/Upwork
104+
if( defined( 'Visualizer_Pro' ) ){
105+
global $Visualizer_Pro;
106+
$Visualizer_Pro->_addEditorElements();
107+
}else{
108+
?>
109+
<a href="<?php echo Visualizer_Plugin::PRO_TEASER_URL;?>" title="<?php echo Visualizer_Plugin::PRO_TEASER_TITLE;?>" target="_new">
110+
<input type="button" class="button" id="existing-chart-free" value="<?php esc_attr_e( 'From Chart', Visualizer_Plugin::NAME );?>:"><select id="chart-id-free"></select>
111+
</a>
112+
<?php
113+
}
114+
// Added by Ash/Upwork
115+
88116
echo '</div>';
89117
echo '</div>';
90118
echo '</li>';

classes/Visualizer/Render/Page/Update.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ protected function _toHTML() {
5252
echo 'win.visualizer.charts.canvas.data = ', $this->data, ';';
5353
echo 'win.visualizer.render();';
5454
echo '}';
55+
56+
// added by Ash/Upwork
57+
if( defined( 'Visualizer_Pro' ) ){
58+
global $Visualizer_Pro;
59+
$Visualizer_Pro->_addUpdateHook($this->series, $this->data);
60+
}
61+
// Added by Ash/Upwork
62+
5563
} else {
5664
echo 'alert("', $this->message, '");';
5765
}

index.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
return;
4343
}
4444

45+
// Added by Ash/Upwork
46+
if ( class_exists( 'Visualizer_Pro', false ) ){
47+
define( 'Visualizer_Pro', true);
48+
}
49+
// Added by Ash/Upwork
50+
4551
/**
4652
* Automatically loads classes for the plugin. Checks a namespace and loads only
4753
* approved classes.

0 commit comments

Comments
 (0)