PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 1.6.6
Visualizer – Tables & Charts Manager with Built-in AI Generator v1.6.6
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 3.10.4 All 148 releases
← All changes | classes/Visualizer/Module/Frontend.php +23 -166 3.0.91.6.6 View file →
@@ -18,8 +18,9 @@
18 18 // | MA 02110-1301 USA |
19 19 // +----------------------------------------------------------------------+
20 20 // | Author: Eugene Manuilov <eugene@manuilov.org> |
21 21 // +----------------------------------------------------------------------+
22 +
22 23 /**
23 24 * Frontend module class.
24 25 *
25 26 * @category Visualizer
@@ -53,101 +54,22 @@
53 54 public function __construct( Visualizer_Plugin $plugin ) {
54 55 parent::__construct( $plugin );
55 56
56 57 $this->_addAction( 'wp_enqueue_scripts', 'enqueueScripts' );
57 - $this->_addFilter( 'visualizer_get_language', 'getLanguage' );
58 58 $this->_addShortcode( 'visualizer', 'renderChart' );
59 59
60 60 // add do_shortocde hook for widget_text filter
61 - if ( ! has_filter( 'widget_text', 'do_shortcode' ) ) {
61 + if ( !has_filter( 'widget_text', 'do_shortcode' ) ) {
62 62 add_filter( 'widget_text', 'do_shortcode' );
63 63 }
64 64
65 65 // add do_shortcode hook for term_description filter
66 - if ( ! has_filter( 'term_description', 'do_shortcode' ) ) {
66 + if ( !has_filter( 'term_description', 'do_shortcode' ) ) {
67 67 add_filter( 'term_description', 'do_shortcode' );
68 68 }
69 -
70 - add_action( 'rest_api_init', array( $this, 'endpoint_register' ) );
71 69 }
72 70
73 71 /**
74 - * Returns the language/locale.
75 - */
76 - function getLanguage( $dummy, $only_language ) {
77 - return $this->get_language();
78 - }
79 -
80 -
81 - /**
82 - * Registers the endpoints
83 - */
84 - function endpoint_register() {
85 - register_rest_route(
86 - 'visualizer/v' . VISUALIZER_REST_VERSION,
87 - '/action/(?P<chart>\d+)/(?P<type>.+)/',
88 - array(
89 - 'methods' => array( 'GET', 'POST' ),
90 - 'callback' => array( $this, 'perform_action' ),
91 - )
92 - );
93 - }
94 -
95 - /**
96 - * All possible actions and their labels
97 - *
98 - * @access private
99 - */
100 - private function get_actions() {
101 - return apply_filters(
102 - 'visualizer_action_buttons', array(
103 - 'print' => __( 'Print', 'visualizer' ),
104 - 'csv' => __( 'CSV', 'visualizer' ),
105 - 'xls' => __( 'Excel', 'visualizer' ),
106 - 'copy' => __( 'Copy', 'visualizer' ),
107 - )
108 - );
109 - }
110 -
111 - /**
112 - * The print button
113 - *
114 - * @since 1.0.0
115 - *
116 - * @access public
117 - */
118 - public function perform_action( WP_REST_Request $params ) {
119 - $chart_id = filter_var( sanitize_text_field( $params['chart'] ), FILTER_VALIDATE_INT );
120 - $type = sanitize_text_field( $params['type'] );
121 - $data = null;
122 -
123 - if ( ! $chart_id ) {
124 - return new WP_REST_Response( array( 'error' => new WP_Error( __( 'Invalid chart ID', 'visualizer' ) ) ) );
125 - }
126 -
127 - if ( ! $type ) {
128 - return new WP_REST_Response( array( 'error' => new WP_Error( __( 'Invalid action', 'visualizer' ) ) ) );
129 - }
130 -
131 - switch ( $type ) {
132 - case 'print':
133 - $data = $this->_getDataAs( $chart_id, 'print' );
134 - break;
135 - case 'csv':
136 - $data = $this->_getDataAs( $chart_id, 'csv' );
137 - break;
138 - case 'xls':
139 - $data = $this->_getDataAs( $chart_id, 'xls' );
140 - break;
141 - default:
142 - $data = apply_filters( 'visualizer_action_data', $data, $chart_id, $type, $params, $this );
143 - break;
144 - }
145 -
146 - return new WP_REST_Response( array( 'data' => $data ) );
147 - }
148 -
149 - /**
150 72 * Registers scripts for charts rendering.
151 73 *
152 74 * @since 1.0.0
153 75 * @uses wp_register_script To register javascript file.
@@ -155,13 +77,10 @@
155 77 * @access public
156 78 */
157 79 public function enqueueScripts() {
158 80 wp_register_script( 'visualizer-google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true );
159 - wp_register_script( 'visualizer-google-jsapi-old', '//www.google.com/jsapi', array( 'visualizer-google-jsapi-new' ), null, true );
81 + wp_register_script( 'visualizer-google-jsapi-old', '//www.google.com/jsapi', array('visualizer-google-jsapi-new'), null, true );
160 82 wp_register_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'visualizer-google-jsapi-old', 'jquery' ), Visualizer_Plugin::VERSION, true );
161 - wp_register_script( 'visualizer-clipboardjs', VISUALIZER_ABSURL . 'js/lib/clipboardjs/clipboard.min.js', array( 'jquery' ), Visualizer_Plugin::VERSION, true );
162 - wp_register_style( 'visualizer-front', VISUALIZER_ABSURL . 'css/front.css', array(), Visualizer_Plugin::VERSION );
163 - do_action( 'visualizer_pro_frontend_load_resources' );
164 83 }
165 84
166 85 /**
167 86 * Returns placeholder for chart according to visualizer shortcode attributes.
@@ -176,38 +95,26 @@
176 95 * @access public
177 96 * @param array $atts The array of shortcode attributes.
178 97 */
179 98 public function renderChart( $atts ) {
180 - global $wp_version;
181 - $atts = shortcode_atts(
182 - array(
183 - 'id' => false, // chart id
184 - 'class' => false, // chart class
185 - 'series' => false, // series filter hook
186 - 'data' => false, // data filter hook
187 - 'settings' => false, // data filter hook
188 - ), $atts
189 - );
99 + $atts = shortcode_atts( array(
100 + 'id' => false, // chart id
101 + 'class' => false, // chart class
102 + 'series' => false, // series filter hook
103 + 'data' => false, // data filter hook
104 + 'settings' => false, // data filter hook
105 + ), $atts );
190 106
191 107 // if empty id or chart does not exists, then return empty string
192 - if ( ! $atts['id'] || ! ( $chart = get_post( $atts['id'] ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
108 + if ( !$atts['id'] || !( $chart = get_post( $atts['id'] ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
193 109 return '';
194 110 }
195 111
196 - if ( ! apply_filters( 'visualizer_pro_show_chart', true, $atts['id'] ) ) {
197 - return '';
198 - }
199 -
200 - // in case revisions exist.
201 - if ( true === ( $revisions = $this->undoRevisions( $chart->ID, true ) ) ) {
202 - $chart = get_post( $chart->ID );
203 - }
204 -
205 112 $id = 'visualizer-' . $atts['id'];
206 - $defaultClass = 'visualizer-front';
113 + $defaultClass = "visualizer-front";
207 114 $class = apply_filters( Visualizer_Plugin::FILTER_CHART_WRAPPER_CLASS, $atts['class'], $atts['id'] );
208 - $class = $defaultClass . ' ' . $class . ' ' . 'visualizer-front-' . $atts['id'];
209 - $class = ! empty( $class ) ? ' class="' . trim( $class ) . '"' : '';
115 + $class = $defaultClass . " " . $class;
116 + $class = !empty( $class ) ? ' class="' . trim($class) . '"' : '';
210 117
211 118 $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
212 119
213 120 // faetch and update settings
@@ -217,34 +124,25 @@
217 124 }
218 125
219 126 // handle series filter hooks
220 127 $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type );
221 - if ( ! empty( $atts['series'] ) ) {
128 + if ( !empty( $atts['series'] ) ) {
222 129 $series = apply_filters( $atts['series'], $series, $chart->ID, $type );
223 130 }
224 131 // handle settings filter hooks
225 132 $settings = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SETTINGS, $settings, $chart->ID, $type );
226 - if ( ! empty( $atts['settings'] ) ) {
133 + if ( !empty( $atts['settings'] ) ) {
227 134 $settings = apply_filters( $atts['settings'], $settings, $chart->ID, $type );
228 135 }
229 136
230 137 // handle data filter hooks
231 138 $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( $chart->post_content ), $chart->ID, $type );
232 - if ( ! empty( $atts['data'] ) ) {
139 + if ( !empty( $atts['data'] ) ) {
233 140 $data = apply_filters( $atts['data'], $data, $chart->ID, $type );
234 141 }
235 142
236 - $id = $id . '-' . rand();
237 - $arguments = array( '', $id, $settings );
238 - $css = '';
239 - apply_filters_ref_array( 'visualizer_pro_inline_css', array( &$arguments ) );
240 - if ( ! empty( $arguments ) ) {
241 - $css = $arguments[0];
242 - $settings = $arguments[2];
243 - }
244 -
245 143 // add chart to the array
246 - $this->_charts[ $id ] = array(
144 + $this->_charts[$id] = array(
247 145 'type' => $type,
248 146 'series' => $series,
249 147 'settings' => $settings,
250 148 'data' => $data,
@@ -251,52 +149,11 @@
251 149 );
252 150
253 151 // enqueue visualizer render and update render localizations
254 152 wp_enqueue_script( 'visualizer-render' );
255 - wp_localize_script(
256 - 'visualizer-render', 'visualizer', array(
257 - 'charts' => $this->_charts,
258 - 'language' => $this->get_language(),
259 - 'map_api_key' => get_option( 'visualizer-map-api-key' ),
260 - 'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '',
261 - 'i10n' => array(
262 - 'copied' => __( 'Copied!', 'visualizer' ),
263 - ),
264 - )
265 - );
266 - wp_enqueue_style( 'visualizer-front' );
153 + wp_localize_script( 'visualizer-render', 'visualizer', array( 'charts' => $this->_charts ) );
267 154
268 - $actions_div = '';
269 - $actions_visible = apply_filters( 'visualizer_pro_add_actions', isset( $settings['actions'] ) ? $settings['actions'] : array(), $atts['id'] );
270 - if ( ! empty( $actions_visible ) ) {
271 - $actions = $this->get_actions();
272 - $actions_div = '<div class="visualizer-actions">';
273 - foreach ( $actions_visible as $action_type ) {
274 - $key = $action_type;
275 - $mime = '';
276 - if ( strpos( $action_type, ';' ) !== false ) {
277 - $array = explode( ';', $action_type );
278 - $key = $array[0];
279 - $mime = end( $array );
280 - }
281 - $label = $actions[ $key ];
282 - $actions_div .= '<a href="#" class="visualizer-action visualizer-action-' . $key . '" data-visualizer-type="' . $key . '" data-visualizer-chart-id="' . $atts['id'] . '" data-visualizer-mime="' . $mime . '" title="' . $label . '" ';
283 -
284 - if ( 'copy' === $key ) {
285 - $copy = $this->_getDataAs( $atts['id'], 'csv' );
286 - $actions_div .= ' data-clipboard-text="' . esc_attr( $copy['csv'] ) . '"';
287 - wp_enqueue_script( 'visualizer-clipboardjs' );
288 - }
289 -
290 - $actions_div .= apply_filters( 'visualizer_action_attributes', '', $key, $atts['id'] );
291 - $actions_div .= '>' . $label . '</a> &nbsp;';
292 - }
293 -
294 - $actions_div .= '</div>';
295 - }
296 -
297 - $actions_div .= $css;
298 -
299 155 // return placeholder div
300 - return $actions_div . '<div id="' . $id . '"' . $class . '></div>';
156 + return '<div id="' . $id . '"' . $class . '></div>';
301 157 }
302 -}
158 +
159 +}