PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 1.4.2.2
Visualizer – Tables & Charts Manager with Built-in AI Generator v1.4.2.2
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 +24 -190 3.1.21.4.2.2 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,103 +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->_addAction( 'visualizer_enqueue_scripts', 'enqueueScripts' );
58 - $this->_addFilter( 'visualizer_get_language', 'getLanguage' );
59 58 $this->_addShortcode( 'visualizer', 'renderChart' );
60 59
61 60 // add do_shortocde hook for widget_text filter
62 - if ( ! has_filter( 'widget_text', 'do_shortcode' ) ) {
61 + if ( !has_filter( 'widget_text', 'do_shortcode' ) ) {
63 62 add_filter( 'widget_text', 'do_shortcode' );
64 63 }
65 64
66 65 // add do_shortcode hook for term_description filter
67 - if ( ! has_filter( 'term_description', 'do_shortcode' ) ) {
66 + if ( !has_filter( 'term_description', 'do_shortcode' ) ) {
68 67 add_filter( 'term_description', 'do_shortcode' );
69 68 }
70 -
71 - add_action( 'rest_api_init', array( $this, 'endpoint_register' ) );
72 69 }
73 70
74 71 /**
75 - * Returns the language/locale.
76 - */
77 - function getLanguage( $dummy, $only_language ) {
78 - return $this->get_language();
79 - }
80 -
81 -
82 - /**
83 - * Registers the endpoints
84 - */
85 - function endpoint_register() {
86 - register_rest_route(
87 - 'visualizer/v' . VISUALIZER_REST_VERSION,
88 - '/action/(?P<chart>\d+)/(?P<type>.+)/',
89 - array(
90 - 'methods' => array( 'GET', 'POST' ),
91 - 'callback' => array( $this, 'perform_action' ),
92 - )
93 - );
94 - }
95 -
96 - /**
97 - * All possible actions and their labels
98 - *
99 - * @access private
100 - */
101 - private function get_actions() {
102 - return apply_filters(
103 - 'visualizer_action_buttons',
104 - array(
105 - 'print' => __( 'Print', 'visualizer' ),
106 - 'csv' => __( 'CSV', 'visualizer' ),
107 - 'xls' => __( 'Excel', 'visualizer' ),
108 - 'copy' => __( 'Copy', 'visualizer' ),
109 - )
110 - );
111 - }
112 -
113 - /**
114 - * The print button
115 - *
116 - * @since 1.0.0
117 - *
118 - * @access public
119 - */
120 - public function perform_action( WP_REST_Request $params ) {
121 - $chart_id = filter_var( sanitize_text_field( $params['chart'] ), FILTER_VALIDATE_INT );
122 - $type = sanitize_text_field( $params['type'] );
123 - $data = null;
124 -
125 - if ( ! $chart_id ) {
126 - return new WP_REST_Response( array( 'error' => new WP_Error( __( 'Invalid chart ID', 'visualizer' ) ) ) );
127 - }
128 -
129 - if ( ! $type ) {
130 - return new WP_REST_Response( array( 'error' => new WP_Error( __( 'Invalid action', 'visualizer' ) ) ) );
131 - }
132 -
133 - switch ( $type ) {
134 - case 'print':
135 - $data = $this->_getDataAs( $chart_id, 'print' );
136 - break;
137 - case 'csv':
138 - $data = $this->_getDataAs( $chart_id, 'csv' );
139 - break;
140 - case 'xls':
141 - $data = $this->_getDataAs( $chart_id, 'xls' );
142 - break;
143 - default:
144 - $data = apply_filters( 'visualizer_action_data', $data, $chart_id, $type, $params, $this );
145 - break;
146 - }
147 -
148 - return new WP_REST_Response( array( 'data' => $data ) );
149 - }
150 -
151 - /**
152 72 * Registers scripts for charts rendering.
153 73 *
154 74 * @since 1.0.0
155 75 * @uses wp_register_script To register javascript file.
@@ -156,12 +76,10 @@
156 76 *
157 77 * @access public
158 78 */
159 79 public function enqueueScripts() {
160 - wp_register_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, 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' );
80 + wp_register_script( 'visualizer-google-jsapi', '//www.google.com/jsapi', array(), null, true );
81 + wp_register_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'visualizer-google-jsapi', 'jquery' ), Visualizer_Plugin::VERSION, true );
164 82 }
165 83
166 84 /**
167 85 * Returns placeholder for chart according to visualizer shortcode attributes.
@@ -176,45 +94,27 @@
176 94 * @access public
177 95 * @param array $atts The array of shortcode attributes.
178 96 */
179 97 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 - ),
189 - $atts
190 - );
98 + $atts = shortcode_atts( array(
99 + 'id' => false, // chart id
100 + 'class' => false, // chart class
101 + 'series' => false, // series filter hook
102 + 'data' => false, // data filter hook
103 + ), $atts );
191 104
192 105 // if empty id or chart does not exists, then return empty string
193 - if ( ! $atts['id'] || ! ( $chart = get_post( $atts['id'] ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
106 + if ( !$atts['id'] || !( $chart = get_post( $atts['id'] ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
194 107 return '';
195 108 }
196 109
197 - if ( ! apply_filters( 'visualizer_pro_show_chart', true, $atts['id'] ) ) {
198 - return '';
199 - }
200 -
201 - // in case revisions exist.
202 - if ( true === ( $revisions = $this->undoRevisions( $chart->ID, true ) ) ) {
203 - $chart = get_post( $chart->ID );
204 - }
205 -
206 110 $id = 'visualizer-' . $atts['id'];
207 - $defaultClass = 'visualizer-front';
208 111 $class = apply_filters( Visualizer_Plugin::FILTER_CHART_WRAPPER_CLASS, $atts['class'], $atts['id'] );
209 - $class = $defaultClass . ' ' . $class . ' ' . 'visualizer-front-' . $atts['id'];
210 - $class = ! empty( $class ) ? ' class="' . trim( $class ) . '"' : '';
112 + $class = !empty( $class ) ? ' class="' . $class . '"' : '';
211 113
212 114 $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
213 115
214 - $chart = apply_filters( 'visualizer_schedule_refresh_chart', $chart, $chart->ID, false );
215 -
216 - // fetch and update settings
116 + // faetch and update settings
217 117 $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
218 118 if ( empty( $settings['height'] ) ) {
219 119 $settings['height'] = '400';
220 120 }
@@ -220,97 +120,31 @@
220 120 }
221 121
222 122 // handle series filter hooks
223 123 $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type );
224 - if ( ! empty( $atts['series'] ) ) {
124 + if ( !empty( $atts['series'] ) ) {
225 125 $series = apply_filters( $atts['series'], $series, $chart->ID, $type );
226 126 }
227 - // handle settings filter hooks
228 - $settings = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SETTINGS, $settings, $chart->ID, $type );
229 - if ( ! empty( $atts['settings'] ) ) {
230 - $settings = apply_filters( $atts['settings'], $settings, $chart->ID, $type );
231 - }
232 127
233 128 // handle data filter hooks
234 - $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( html_entity_decode( $chart->post_content ) ), $chart->ID, $type );
235 - if ( ! empty( $atts['data'] ) ) {
129 + $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( $chart->post_content ), $chart->ID, $type );
130 + if ( !empty( $atts['data'] ) ) {
236 131 $data = apply_filters( $atts['data'], $data, $chart->ID, $type );
237 132 }
238 133
239 - $css = '';
240 - $arguments = $this->get_inline_custom_css( $id, $settings );
241 - if ( ! empty( $arguments ) ) {
242 - $css = $arguments[0];
243 - $settings = $arguments[1];
244 - }
245 -
246 - $library = $this->load_chart_type( $chart->ID );
247 -
248 134 // add chart to the array
249 - $this->_charts[ $id ] = array(
135 + $this->_charts[$id] = array(
250 136 'type' => $type,
251 137 'series' => $series,
252 138 'settings' => $settings,
253 139 'data' => $data,
254 - 'library' => $library,
255 140 );
256 141
257 - wp_register_script(
258 - "visualizer-render-$library",
259 - VISUALIZER_ABSURL . 'js/render-facade.js',
260 - apply_filters( 'visualizer_assets_render', array( 'jquery', 'visualizer-customization' ), true ),
261 - Visualizer_Plugin::VERSION,
262 - true
263 - );
142 + // enqueue visualizer render and update render localizations
143 + wp_enqueue_script( 'visualizer-render' );
144 + wp_localize_script( 'visualizer-render', 'visualizer', array( 'charts' => $this->_charts ) );
264 145
265 - wp_enqueue_script( "visualizer-render-$library" );
266 - wp_localize_script(
267 - "visualizer-render-$library",
268 - 'visualizer',
269 - array(
270 - 'charts' => $this->_charts,
271 - 'language' => $this->get_language(),
272 - 'map_api_key' => get_option( 'visualizer-map-api-key' ),
273 - 'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '',
274 - 'i10n' => array(
275 - 'copied' => __( 'Copied!', 'visualizer' ),
276 - ),
277 - 'page_type' => 'frontend',
278 - )
279 - );
280 - wp_enqueue_style( 'visualizer-front' );
281 -
282 - $actions_div = '';
283 - $actions_visible = apply_filters( 'visualizer_pro_add_actions', isset( $settings['actions'] ) ? $settings['actions'] : array(), $atts['id'] );
284 - if ( ! empty( $actions_visible ) ) {
285 - $actions = $this->get_actions();
286 - $actions_div = '<div class="visualizer-actions">';
287 - foreach ( $actions_visible as $action_type ) {
288 - $key = $action_type;
289 - $mime = '';
290 - if ( strpos( $action_type, ';' ) !== false ) {
291 - $array = explode( ';', $action_type );
292 - $key = $array[0];
293 - $mime = end( $array );
294 - }
295 - $label = $actions[ $key ];
296 - $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 . '" ';
297 -
298 - if ( 'copy' === $key ) {
299 - $copy = $this->_getDataAs( $atts['id'], 'csv' );
300 - $actions_div .= ' data-clipboard-text="' . esc_attr( $copy['csv'] ) . '"';
301 - wp_enqueue_script( 'visualizer-clipboardjs' );
302 - }
303 -
304 - $actions_div .= apply_filters( 'visualizer_action_attributes', '', $key, $atts['id'] );
305 - $actions_div .= '>' . $label . '</a> &nbsp;';
306 - }
307 -
308 - $actions_div .= '</div>';
309 - }
310 -
311 - $actions_div .= $css;
312 -
313 146 // return placeholder div
314 - return $actions_div . '<div id="' . $id . '"' . $class . '></div>';
147 + return '<div id="' . $id . '"' . $class . '></div>';
315 148 }
316 -}
149 +
150 +}