Skip to content

Commit 01f8f01

Browse files
authored
Merge pull request #201 from contactashish13/issue-78
add permission feature #78
2 parents 42bd412 + 938d05d commit 01f8f01

File tree

10 files changed

+147
-1603
lines changed

10 files changed

+147
-1603
lines changed

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/Chart.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ 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();
@@ -257,15 +258,19 @@ public function renderChartPages() {
257258
}
258259
// dispatch pages
259260
$this->_chart = get_post( $chart_id );
260-
switch ( isset( $_GET['tab'] ) ? $_GET['tab'] : '' ) {
261+
$tab = isset( $_GET['tab'] ) || empty( $_GET['tab'] ) ? $_GET['tab'] : 'visualizer';
262+
switch ( $tab ) {
261263
case 'settings':
262264
// changed by Ash/Upwork
263265
$this->_handleDataAndSettingsPage();
264266
break;
265-
case 'type':
266-
default:
267+
case 'type': // fall through.
268+
case 'visualizer': // fall through.
267269
$this->_handleTypesPage();
268270
break;
271+
default:
272+
do_action( 'visualizer_pro_handle_tab', $tab, $this->_chart );
273+
break;
269274
}
270275
defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
271276
}

classes/Visualizer/Module/Frontend.php

Lines changed: 12 additions & 4 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'] );
@@ -239,12 +245,14 @@ public function renderChart( $atts ) {
239245
),
240246
)
241247
);
248+
wp_enqueue_style( 'visualizer-front' );
242249

243250
$actions_div = '';
244-
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 ) ) {
245253
$actions = $this->get_actions();
246254
$actions_div = '<div class="visualizer-actions">';
247-
foreach ( $settings['actions'] as $action_type ) {
255+
foreach ( $actions_visible as $action_type ) {
248256
$key = $action_type;
249257
$mime = '';
250258
if ( strpos( $action_type, ';' ) !== false ) {

classes/Visualizer/Render/Page/Data.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class="dashicons dashicons-lock"></span></h2>
240240
</ul>
241241
</li>
242242
</ul>
243-
<li class="group group-category bottom-fixed " id="vz-chart-settings">
243+
<li class="group group-category bottom-fixed sidebar-footer-link" id="vz-chart-settings">
244244
<h2><?php _e( 'Advanced Settings', 'visualizer' ); ?></h2>
245245
<div class="group-header">
246246
<button class="customize-section-back" tabindex="0"></button>
@@ -253,6 +253,7 @@ class="dashicons dashicons-lock"></span></h2>
253253
</form>
254254
</ul>
255255
</li>
256+
<?php echo apply_filters( 'visualizer_pro_sidebar_footer_links', '', $this->chart->ID ); ?>
256257
<li class=" group bottom-fixed" id="vz-chart-review">
257258
<a href="https://wordpress.org/support/plugin/visualizer/reviews/?filter=5#new-post"
258259
target="_blank"><?php _e( 'Rate our plugin', 'visualizer' ); ?></a>

classes/Visualizer/Render/Sidebar.php

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -428,20 +428,30 @@ protected function _renderViewSettings() {
428428
* @since 1.0.0
429429
*
430430
* @static
431-
* @access protected
431+
* @access public
432432
* @param string $title The title of the select item.
433433
* @param string $name The name of the select item.
434434
* @param string $value The actual value of the select item.
435435
* @param array $options The array of select options.
436436
* @param string $desc The description of the select item.
437+
* @param bool $multiple Is this a multiple select box.
438+
* @param array $classes Any additional classes.
439+
* @param array $attributes Custom attributes.
437440
*/
438-
protected static function _renderSelectItem( $title, $name, $value, array $options, $desc ) {
441+
public static function _renderSelectItem( $title, $name, $value, array $options, $desc, $multiple = false, $classes = array(), $attributes = array() ) {
442+
$atts = '';
443+
if ( $attributes ) {
444+
foreach ( $attributes as $k => $v ) {
445+
$atts .= ' data-visualizer-' . $k . '=' . esc_attr( $v );
446+
}
447+
}
439448
echo '<div class="section-item">';
440449
echo '<a class="more-info" href="javascript:;">[?]</a>';
441450
echo '<b>', $title, '</b>';
442-
echo '<select class="control-select" name="', $name, '">';
451+
echo '<select class="control-select ', implode( ' ', $classes ) , '" name="', $name, '" ', ( $multiple ? 'multiple' : '' ), ' ' , $atts, '>';
443452
foreach ( $options as $key => $label ) {
444-
echo '<option value="', $key, '"', selected( $key, $value, false ), '>';
453+
$extra = $multiple && is_array( $value ) ? ( in_array( $key, $value ) ? 'selected' : '' ) : selected( $key, $value, false );
454+
echo '<option value="', $key, '"', $extra, '>';
445455
echo $label;
446456
echo '</option>';
447457
}
@@ -507,10 +517,10 @@ protected static function _renderTextItem( $title, $name, $value, $desc, $placeh
507517
* @since 1.0.0
508518
*
509519
* @static
510-
* @access protected
520+
* @access public
511521
* @param string $title The title of this group.
512522
*/
513-
protected static function _renderGroupStart( $title ) {
523+
public static function _renderGroupStart( $title ) {
514524
echo '<li class="group">';
515525
echo '<h3 class="group-title">', $title, '</h3>';
516526
echo '<ul class="group-content">';
@@ -522,9 +532,9 @@ protected static function _renderGroupStart( $title ) {
522532
* @since 1.0.0
523533
*
524534
* @static
525-
* @access protected
535+
* @access public
526536
*/
527-
protected static function _renderGroupEnd() {
537+
public static function _renderGroupEnd() {
528538
echo '</ul>';
529539
echo '</li>';
530540
}
@@ -535,11 +545,11 @@ protected static function _renderGroupEnd() {
535545
* @since 1.0.0
536546
*
537547
* @static
538-
* @access protected
548+
* @access public
539549
* @param string $title The title of this section. If the title is empty, no title will be displayed.
540550
* @param boolean $open Determines whether the section items block has to be expanded or collapsed.
541551
*/
542-
protected static function _renderSectionStart( $title = false, $open = true ) {
552+
public static function _renderSectionStart( $title = false, $open = true ) {
543553

544554
if ( ! empty( $title ) ) {
545555
echo '<li class="subsection">';
@@ -555,10 +565,10 @@ protected static function _renderSectionStart( $title = false, $open = true ) {
555565
*
556566
* @since 1.0.0
557567
*
558-
* @static
568+
* @public
559569
* @access protected
560570
*/
561-
protected static function _renderSectionEnd() {
571+
public static function _renderSectionEnd() {
562572
echo '</div>';
563573
echo '</li>';
564574
}
@@ -569,10 +579,10 @@ protected static function _renderSectionEnd() {
569579
* @since 1.0.0
570580
*
571581
* @static
572-
* @access protected
582+
* @access public
573583
* @param string $description The description text.
574584
*/
575-
protected static function _renderSectionDescription( $description ) {
585+
public static function _renderSectionDescription( $description ) {
576586
echo '<div class="section-item">';
577587
echo '<div class="section-description">', $description, '</div>';
578588
echo '</div>';

css/frame.css

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ button#editor-chart-button {
809809
}
810810

811811
#vz-chart-settings h2:hover,
812+
.sidebar-footer-link h2:hover,
812813
#vz-chart-review a:hover {
813814
text-decoration: underline;
814815
}
@@ -819,6 +820,7 @@ button#editor-chart-button {
819820
}
820821

821822
#vz-chart-settings h2,
823+
.sidebar-footer-link h2,
822824
#vz-chart-review h2 {
823825
padding: 0;
824826
border: none;
@@ -849,21 +851,24 @@ button#editor-chart-button {
849851
text-align: left;
850852
}
851853

852-
#vz-chart-review,
853-
#vz-chart-settings h2 {
854+
#vz-chart-settings h2,
855+
.sidebar-footer-link h2 {
854856
display: inline;
855857
color: #00a0d2;
856858
background: none;
857859
font-family: "Open Sans",sans-serif;
858860
cursor: pointer;
859861
}
860862

863+
.sidebar-footer-link,
864+
#vz-chart-review,
861865
#vz-chart-settings {
862866
display: inline;
863867
background: none;
864868
cursor: pointer;
865869
}
866870

871+
.sidebar-footer-link > ul,
867872
#vz-chart-source > ul,
868873
#vz-chart-settings > ul {
869874
position: relative;
@@ -895,6 +900,20 @@ button#editor-chart-button {
895900
display: none;
896901
}
897902

903+
.sidebar-footer-link.open h2 {
904+
position: absolute;
905+
bottom: 28px;
906+
left: 20px;
907+
}
908+
909+
.sidebar-footer-link.open .group-header {
910+
display: block;
911+
}
912+
913+
.sidebar-footer-link .group-header {
914+
display: none;
915+
}
916+
898917
#vz-csv-file-form,
899918
#vz-one-time-import,
900919
#vz-schedule-import,

css/front.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.locker,
2+
.locker-loader {
3+
position: absolute;
4+
top: 0;
5+
left: 0;
6+
width: 100%;
7+
height: 100%;
8+
}
9+
10+
.locker {
11+
z-index: 1000;
12+
opacity: 0.8;
13+
background-color: white;
14+
15+
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";
16+
filter: alpha(opacity=80);
17+
}
18+
19+
.locker-loader {
20+
z-index: 1001;
21+
background: url(../images/ajax-loader.gif) no-repeat center center;
22+
}

js/frame.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
$('#vz-chart-settings h2').click(function () {
1313
$("#vz-chart-source").hide();
14+
$("#vz-chart-permissions").removeClass('open').addClass('bottom-fixed');
1415
$(this).parent().removeClass('bottom-fixed').addClass('open');
1516

1617
return false;

js/render.js

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@
241241
$('a.visualizer-action[data-visualizer-type!=copy]').on('click', function(e) {
242242
var type = $(this).attr( 'data-visualizer-type' );
243243
var chart = $(this).attr( 'data-visualizer-chart-id' );
244+
var lock = $('.visualizer-front.visualizer-front-' + chart);
245+
lock.lock();
244246
e.preventDefault();
245247
$.ajax({
246248
url : v.rest_url.replace('#id#', chart).replace('#type#', type),
@@ -283,11 +285,12 @@
283285
break;
284286
default:
285287
if(window.visualizer_perform_action) {
286-
window.visualizer_perform_action(type, data.data);
288+
window.visualizer_perform_action(type, chart, data.data);
287289
}
288290
break;
289291
}
290292
}
293+
lock.unlock();
291294
}
292295
});
293296
});
@@ -319,4 +322,53 @@
319322
});
320323
}
321324

322-
})(jQuery, visualizer);
325+
})(jQuery, visualizer);
326+
327+
(function ($) {
328+
$.fn.lock = function () {
329+
$(this).each(function () {
330+
var $this = $(this);
331+
var position = $this.css('position');
332+
333+
if (!position) {
334+
position = 'static';
335+
}
336+
337+
switch (position) {
338+
case 'absolute':
339+
case 'relative':
340+
break;
341+
default:
342+
$this.css('position', 'relative');
343+
break;
344+
}
345+
$this.data('position', position);
346+
347+
var width = $this.width(),
348+
height = $this.height();
349+
350+
var locker = $('<div class="locker"></div>');
351+
locker.width(width).height(height);
352+
353+
var loader = $('<div class="locker-loader"></div>');
354+
loader.width(width).height(height);
355+
356+
locker.append(loader);
357+
$this.append(locker);
358+
$(window).resize(function () {
359+
$this.find('.locker,.locker-loader').width($this.width()).height($this.height());
360+
});
361+
});
362+
363+
return $(this);
364+
};
365+
366+
$.fn.unlock = function () {
367+
$(this).each(function () {
368+
$(this).find('.locker').remove();
369+
$(this).css('position', $(this).data('position'));
370+
});
371+
372+
return $(this);
373+
};
374+
})(jQuery);

0 commit comments

Comments
 (0)