| @@ -53,10 +53,8 @@ | ||
| 53 | 53 | public function __construct( Visualizer_Plugin $plugin ) { |
| 54 | 54 | parent::__construct( $plugin ); |
| 55 | 55 | |
| 56 | 56 | $this->_addAction( 'wp_enqueue_scripts', 'enqueueScripts' ); |
| 57 | - $this->_addAction( 'visualizer_enqueue_scripts', 'enqueueScripts' ); | |
| 58 | - $this->_addFilter( 'visualizer_get_language', 'getLanguage' ); | |
| 59 | 57 | $this->_addShortcode( 'visualizer', 'renderChart' ); |
| 60 | 58 | |
| 61 | 59 | // add do_shortocde hook for widget_text filter |
| 62 | 60 | if ( ! has_filter( 'widget_text', 'do_shortcode' ) ) { |
| @@ -71,16 +69,8 @@ | ||
| 71 | 69 | add_action( 'rest_api_init', array( $this, 'endpoint_register' ) ); |
| 72 | 70 | } |
| 73 | 71 | |
| 74 | 72 | /** |
| 75 | - * Returns the language/locale. | |
| 76 | - */ | |
| 77 | - function getLanguage( $dummy, $only_language ) { | |
| 78 | - return $this->get_language(); | |
| 79 | - } | |
| 80 | - | |
| 81 | - | |
| 82 | - /** | |
| 83 | 73 | * Registers the endpoints |
| 84 | 74 | */ |
| 85 | 75 | function endpoint_register() { |
| 86 | 76 | register_rest_route( |
| @@ -99,10 +89,9 @@ | ||
| 99 | 89 | * @access private |
| 100 | 90 | */ |
| 101 | 91 | private function get_actions() { |
| 102 | 92 | return apply_filters( |
| 103 | - 'visualizer_action_buttons', | |
| 104 | - array( | |
| 93 | + 'visualizer_action_buttons', array( | |
| 105 | 94 | 'print' => __( 'Print', 'visualizer' ), |
| 106 | 95 | 'csv' => __( 'CSV', 'visualizer' ), |
| 107 | 96 | 'xls' => __( 'Excel', 'visualizer' ), |
| 108 | 97 | 'copy' => __( 'Copy', 'visualizer' ), |
| @@ -156,10 +145,13 @@ | ||
| 156 | 145 | * |
| 157 | 146 | * @access public |
| 158 | 147 | */ |
| 159 | 148 | public function enqueueScripts() { |
| 160 | - wp_register_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true ); | |
| 149 | + wp_register_script( 'visualizer-google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true ); | |
| 150 | + wp_register_script( 'visualizer-google-jsapi-old', '//www.google.com/jsapi', array( 'visualizer-google-jsapi-new' ), null, true ); | |
| 151 | + wp_register_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'visualizer-google-jsapi-old', 'jquery' ), Visualizer_Plugin::VERSION, true ); | |
| 161 | 152 | wp_register_script( 'visualizer-clipboardjs', VISUALIZER_ABSURL . 'js/lib/clipboardjs/clipboard.min.js', array( 'jquery' ), Visualizer_Plugin::VERSION, true ); |
| 153 | + wp_enqueue_script( 'visualizer-clipboardjs' ); | |
| 162 | 154 | wp_register_style( 'visualizer-front', VISUALIZER_ABSURL . 'css/front.css', array(), Visualizer_Plugin::VERSION ); |
| 163 | 155 | do_action( 'visualizer_pro_frontend_load_resources' ); |
| 164 | 156 | } |
| 165 | 157 | |
| @@ -176,18 +168,16 @@ | ||
| 176 | 168 | * @access public |
| 177 | 169 | * @param array $atts The array of shortcode attributes. |
| 178 | 170 | */ |
| 179 | 171 | public function renderChart( $atts ) { |
| 180 | - global $wp_version; | |
| 181 | 172 | $atts = shortcode_atts( |
| 182 | 173 | array( |
| 183 | 174 | '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 | |
| 175 | + 'class' => false, // chart class | |
| 176 | + 'series' => false, // series filter hook | |
| 177 | + 'data' => false, // data filter hook | |
| 178 | + 'settings' => false, // data filter hook | |
| 179 | + ), $atts | |
| 190 | 180 | ); |
| 191 | 181 | |
| 192 | 182 | // if empty id or chart does not exists, then return empty string |
| 193 | 183 | if ( ! $atts['id'] || ! ( $chart = get_post( $atts['id'] ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) { |
| @@ -197,13 +187,8 @@ | ||
| 197 | 187 | if ( ! apply_filters( 'visualizer_pro_show_chart', true, $atts['id'] ) ) { |
| 198 | 188 | return ''; |
| 199 | 189 | } |
| 200 | 190 | |
| 201 | - // in case revisions exist. | |
| 202 | - if ( true === ( $revisions = $this->undoRevisions( $chart->ID, true ) ) ) { | |
| 203 | - $chart = get_post( $chart->ID ); | |
| 204 | - } | |
| 205 | - | |
| 206 | 191 | $id = 'visualizer-' . $atts['id']; |
| 207 | 192 | $defaultClass = 'visualizer-front'; |
| 208 | 193 | $class = apply_filters( Visualizer_Plugin::FILTER_CHART_WRAPPER_CLASS, $atts['class'], $atts['id'] ); |
| 209 | 194 | $class = $defaultClass . ' ' . $class . ' ' . 'visualizer-front-' . $atts['id']; |
| @@ -210,11 +195,9 @@ | ||
| 210 | 195 | $class = ! empty( $class ) ? ' class="' . trim( $class ) . '"' : ''; |
| 211 | 196 | |
| 212 | 197 | $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ); |
| 213 | 198 | |
| 214 | - $chart = apply_filters( 'visualizer_schedule_refresh_chart', $chart, $chart->ID, false ); | |
| 215 | - | |
| 216 | - // fetch and update settings | |
| 199 | + // faetch and update settings | |
| 217 | 200 | $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true ); |
| 218 | 201 | if ( empty( $settings['height'] ) ) { |
| 219 | 202 | $settings['height'] = '400'; |
| 220 | 203 | } |
| @@ -230,23 +213,18 @@ | ||
| 230 | 213 | $settings = apply_filters( $atts['settings'], $settings, $chart->ID, $type ); |
| 231 | 214 | } |
| 232 | 215 | |
| 233 | 216 | // handle data filter hooks |
| 234 | - $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( html_entity_decode( $chart->post_content ) ), $chart->ID, $type ); | |
| 217 | + $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( $chart->post_content ), $chart->ID, $type ); | |
| 235 | 218 | if ( ! empty( $atts['data'] ) ) { |
| 236 | 219 | $data = apply_filters( $atts['data'], $data, $chart->ID, $type ); |
| 237 | 220 | } |
| 238 | 221 | |
| 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 | 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]; | |
| 249 | 227 | |
| 250 | 228 | // add chart to the array |
| 251 | 229 | $this->_charts[ $id ] = array( |
| 252 | 230 | 'type' => $type, |
| @@ -252,32 +230,20 @@ | ||
| 252 | 230 | 'type' => $type, |
| 253 | 231 | 'series' => $series, |
| 254 | 232 | 'settings' => $settings, |
| 255 | 233 | 'data' => $data, |
| 256 | - 'library' => $library, | |
| 257 | 234 | ); |
| 258 | 235 | |
| 259 | - wp_register_script( | |
| 260 | - "visualizer-render-$library", | |
| 261 | - VISUALIZER_ABSURL . 'js/render-facade.js', | |
| 262 | - apply_filters( 'visualizer_assets_render', array( 'jquery', 'visualizer-customization' ), true ), | |
| 263 | - Visualizer_Plugin::VERSION, | |
| 264 | - true | |
| 265 | - ); | |
| 266 | - | |
| 267 | - wp_enqueue_script( "visualizer-render-$library" ); | |
| 236 | + // enqueue visualizer render and update render localizations | |
| 237 | + wp_enqueue_script( 'visualizer-render' ); | |
| 268 | 238 | wp_localize_script( |
| 269 | - "visualizer-render-$library", | |
| 270 | - 'visualizer', | |
| 271 | - array( | |
| 239 | + 'visualizer-render', 'visualizer', array( | |
| 272 | 240 | 'charts' => $this->_charts, |
| 273 | - 'language' => $this->get_language(), | |
| 274 | 241 | 'map_api_key' => get_option( 'visualizer-map-api-key' ), |
| 275 | - 'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '', | |
| 242 | + 'rest_url' => rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ), | |
| 276 | 243 | 'i10n' => array( |
| 277 | 244 | 'copied' => __( 'Copied!', 'visualizer' ), |
| 278 | 245 | ), |
| 279 | - 'page_type' => 'frontend', | |
| 280 | 246 | ) |
| 281 | 247 | ); |
| 282 | 248 | wp_enqueue_style( 'visualizer-front' ); |
| 283 | 249 | |
| @@ -294,14 +260,13 @@ | ||
| 294 | 260 | $key = $array[0]; |
| 295 | 261 | $mime = end( $array ); |
| 296 | 262 | } |
| 297 | 263 | $label = $actions[ $key ]; |
| 298 | - $actions_div .= '<a href="#" class="visualizer-action visualizer-action-' . $key . '" data-visualizer-type="' . $key . '" data-visualizer-chart-id="' . $atts['id'] . '" data-visualizer-container-id="' . $id . '" data-visualizer-mime="' . $mime . '" title="' . $label . '" '; | |
| 264 | + $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 . '" '; | |
| 299 | 265 | |
| 300 | 266 | if ( 'copy' === $key ) { |
| 301 | 267 | $copy = $this->_getDataAs( $atts['id'], 'csv' ); |
| 302 | 268 | $actions_div .= ' data-clipboard-text="' . esc_attr( $copy['csv'] ) . '"'; |
| 303 | - wp_enqueue_script( 'visualizer-clipboardjs' ); | |
| 304 | 269 | } |
| 305 | 270 | |
| 306 | 271 | $actions_div .= apply_filters( 'visualizer_action_attributes', '', $key, $atts['id'] ); |
| 307 | 272 | $actions_div .= '>' . $label . '</a> '; |