| @@ -53,93 +53,31 @@ | ||
| 53 | 53 | parent::__construct( $plugin ); |
| 54 | 54 | $this->_addAction( 'load-post.php', 'enqueueMediaScripts' ); |
| 55 | 55 | $this->_addAction( 'load-post-new.php', 'enqueueMediaScripts' ); |
| 56 | 56 | $this->_addAction( 'admin_footer', 'renderTempaltes' ); |
| 57 | - $this->_addAction( 'admin_enqueue_scripts', 'enqueueLibraryScripts', null, 8 ); | |
| 57 | + $this->_addAction( 'admin_enqueue_scripts', 'enqueueLibraryScripts', null, 9 ); | |
| 58 | 58 | $this->_addAction( 'admin_menu', 'registerAdminMenu' ); |
| 59 | 59 | $this->_addFilter( 'media_view_strings', 'setupMediaViewStrings' ); |
| 60 | 60 | $this->_addFilter( 'plugin_action_links', 'getPluginActionLinks', 10, 2 ); |
| 61 | - $this->_addFilter( 'visualizer_logger_data', 'getLoggerData' ); | |
| 62 | - $this->_addFilter( 'visualizer_get_chart_counts', 'getChartCountsByTypeAndMeta' ); | |
| 63 | - $this->_addFilter( 'visualizer_feedback_review_trigger', 'feedbackReviewTrigger' ); | |
| 64 | - | |
| 65 | - $this->_addAction( 'admin_init', 'init' ); | |
| 61 | + $this->_addFilter( 'plugin_row_meta', 'getPluginMetaLinks', 10, 2 ); | |
| 62 | + $this->_addAjaxAction( Visualizer_Plugin::ACTION_TRACK, 'visualizer_enable_track' ); | |
| 66 | 63 | } |
| 67 | 64 | |
| 68 | 65 | /** |
| 69 | - * Admin init. | |
| 70 | - * | |
| 71 | - * @access public | |
| 66 | + * Enable track ajax action. | |
| 72 | 67 | */ |
| 73 | - public function init() { | |
| 74 | - if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) && 'true' == get_user_option( 'rich_editing' ) ) { | |
| 75 | - $this->_addFilter( 'mce_external_languages', 'add_tinymce_lang', 10, 1 ); | |
| 76 | - $this->_addFilter( 'mce_external_plugins', 'tinymce_plugin', 10, 1 ); | |
| 77 | - $this->_addFilter( 'mce_buttons', 'register_mce_button', 10, 1 ); | |
| 68 | + public function visualizer_enable_track() { | |
| 69 | + check_admin_referer( Visualizer_Plugin::ACTION_TRACK, 'nonce' ); | |
| 70 | + $status = $_GET['status']; | |
| 71 | + if ( $status == 'yes' ) { | |
| 72 | + update_option( 'visualizer_logger_flag', 'yes' ); | |
| 73 | + } else { | |
| 74 | + update_option( 'visualizer_logger_flag', 'no' ); | |
| 78 | 75 | } |
| 76 | + wp_send_json_success( array( 'status' => $status ) ); | |
| 79 | 77 | } |
| 80 | 78 | |
| 81 | 79 | /** |
| 82 | - * Load plugin translation for - TinyMCE API | |
| 83 | - * | |
| 84 | - * @access public | |
| 85 | - * @param array $arr The tinymce_lang array. | |
| 86 | - * @return array | |
| 87 | - */ | |
| 88 | - public function add_tinymce_lang( $arr ) { | |
| 89 | - $ui_lang = VISUALIZER_ABSPATH . '/classes/Visualizer/Module/Language.php'; | |
| 90 | - $ui_lang = apply_filters( 'visualizer_ui_lang_filter', $ui_lang ); | |
| 91 | - $arr[] = $ui_lang; | |
| 92 | - return $arr; | |
| 93 | - } | |
| 94 | - | |
| 95 | - /** | |
| 96 | - * Load custom js options - TinyMCE API | |
| 97 | - * | |
| 98 | - * @access public | |
| 99 | - * @param array $plugin_array The tinymce plugin array. | |
| 100 | - * @return array | |
| 101 | - */ | |
| 102 | - public function tinymce_plugin( $plugin_array ) { | |
| 103 | - $plugin_array['visualizer_mce_button'] = VISUALIZER_ABSURL . 'js/mce.js'; | |
| 104 | - return $plugin_array; | |
| 105 | - } | |
| 106 | - | |
| 107 | - /** | |
| 108 | - * Register new button in the editor | |
| 109 | - * | |
| 110 | - * @access public | |
| 111 | - * @param array $buttons The tinymce buttons array. | |
| 112 | - * @return array | |
| 113 | - */ | |
| 114 | - public function register_mce_button( $buttons ) { | |
| 115 | - array_push( $buttons, 'visualizer_mce_button' ); | |
| 116 | - return $buttons; | |
| 117 | - } | |
| 118 | - | |
| 119 | - /** | |
| 120 | - * Whether to show the feedback review or not. | |
| 121 | - * | |
| 122 | - * @access public | |
| 123 | - */ | |
| 124 | - public function feedbackReviewTrigger( $dumb ) { | |
| 125 | - $query = new WP_Query( | |
| 126 | - array( | |
| 127 | - 'posts_per_page' => 50, | |
| 128 | - 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, | |
| 129 | - 'fields' => 'ids', | |
| 130 | - 'update_post_meta_cache' => false, | |
| 131 | - 'update_post_term_cache' => false, | |
| 132 | - ) | |
| 133 | - ); | |
| 134 | - | |
| 135 | - if ( $query->have_posts() && $query->post_count > 0 ) { | |
| 136 | - return true; | |
| 137 | - } | |
| 138 | - return false; | |
| 139 | - } | |
| 140 | - | |
| 141 | - /** | |
| 142 | 80 | * Enqueues media scripts and styles. |
| 143 | 81 | * |
| 144 | 82 | * @since 1.0.0 |
| 145 | 83 | * @uses wp_enqueue_style To enqueue style file. |
| @@ -156,15 +94,8 @@ | ||
| 156 | 94 | wp_enqueue_script( 'visualizer-media-model', VISUALIZER_ABSURL . 'js/media/model.js', array( 'visualizer-google-jsapi-old' ), Visualizer_Plugin::VERSION, true ); |
| 157 | 95 | wp_enqueue_script( 'visualizer-media-collection', VISUALIZER_ABSURL . 'js/media/collection.js', array( 'visualizer-media-model' ), Visualizer_Plugin::VERSION, true ); |
| 158 | 96 | wp_enqueue_script( 'visualizer-media-controller', VISUALIZER_ABSURL . 'js/media/controller.js', array( 'visualizer-media-collection' ), Visualizer_Plugin::VERSION, true ); |
| 159 | 97 | wp_enqueue_script( 'visualizer-media-view', VISUALIZER_ABSURL . 'js/media/view.js', array( 'visualizer-media-controller' ), Visualizer_Plugin::VERSION, true ); |
| 160 | - wp_localize_script( | |
| 161 | - 'visualizer-media-view', 'visualizer', array( | |
| 162 | - 'i10n' => array( | |
| 163 | - 'insert' => __( 'Insert', 'visualizer' ), | |
| 164 | - ), | |
| 165 | - ) | |
| 166 | - ); | |
| 167 | 98 | wp_enqueue_script( 'visualizer-media-toolbar', VISUALIZER_ABSURL . 'js/media/toolbar.js', array( 'visualizer-media-view' ), Visualizer_Plugin::VERSION, true ); |
| 168 | 99 | wp_enqueue_script( 'visualizer-media', VISUALIZER_ABSURL . 'js/media.js', array( 'visualizer-media-toolbar' ), Visualizer_Plugin::VERSION, true ); |
| 169 | 100 | } |
| 170 | 101 | } |
| @@ -180,9 +111,8 @@ | ||
| 180 | 111 | * |
| 181 | 112 | * @return array The extended array of media view strings. |
| 182 | 113 | */ |
| 183 | 114 | public function setupMediaViewStrings( $strings ) { |
| 184 | - $chart_types = self::_getChartTypesLocalized( true, true, true ); | |
| 185 | 115 | $strings['visualizer'] = array( |
| 186 | 116 | 'actions' => array( |
| 187 | 117 | 'get_charts' => Visualizer_Plugin::ACTION_GET_CHARTS, |
| 188 | 118 | 'delete_chart' => Visualizer_Plugin::ACTION_DELETE_CHART, |
| @@ -194,10 +124,10 @@ | ||
| 194 | 124 | 'library' => esc_html__( 'From Library', 'visualizer' ), |
| 195 | 125 | 'create' => esc_html__( 'Create New', 'visualizer' ), |
| 196 | 126 | ), |
| 197 | 127 | 'library' => array( |
| 198 | - 'filters' => $chart_types, | |
| 199 | - 'types' => array_keys( $chart_types ), | |
| 128 | + 'filters' => self::_getChartTypesLocalized( true, true ), | |
| 129 | + 'types' => array_keys( self::_getChartTypesLocalized( true, true ) ), | |
| 200 | 130 | ), |
| 201 | 131 | 'nonce' => wp_create_nonce(), |
| 202 | 132 | 'buildurl' => add_query_arg( 'action', Visualizer_Plugin::ACTION_CREATE_CHART, admin_url( 'admin-ajax.php' ) ), |
| 203 | 133 | ); |
| @@ -213,69 +143,59 @@ | ||
| 213 | 143 | * @static |
| 214 | 144 | * @access private |
| 215 | 145 | * @return array The associated array of chart types with localized names. |
| 216 | 146 | */ |
| 217 | - public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darray = false, $add_select = false ) { | |
| 218 | - $additional = array(); | |
| 219 | - if ( $add_select ) { | |
| 220 | - $additional['select'] = array( | |
| 221 | - 'name' => esc_html__( 'All', 'visualizer' ), | |
| 147 | + public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darray = false ) { | |
| 148 | + $types = array( | |
| 149 | + 'pie' => array( | |
| 150 | + 'name' => esc_html__( 'Pie', 'visualizer' ), | |
| 222 | 151 | 'enabled' => true, |
| 223 | - ); | |
| 224 | - } | |
| 225 | - | |
| 226 | - $types = array_merge( | |
| 227 | - $additional, array( | |
| 228 | - 'pie' => array( | |
| 229 | - 'name' => esc_html__( 'Pie', 'visualizer' ), | |
| 230 | - 'enabled' => true, | |
| 231 | - ), | |
| 232 | - 'line' => array( | |
| 233 | - 'name' => esc_html__( 'Line', 'visualizer' ), | |
| 234 | - 'enabled' => true, | |
| 235 | - ), | |
| 236 | - 'area' => array( | |
| 237 | - 'name' => esc_html__( 'Area', 'visualizer' ), | |
| 238 | - 'enabled' => true, | |
| 239 | - ), | |
| 240 | - 'geo' => array( | |
| 241 | - 'name' => esc_html__( 'Geo', 'visualizer' ), | |
| 242 | - 'enabled' => true, | |
| 243 | - ), | |
| 244 | - 'bar' => array( | |
| 245 | - 'name' => esc_html__( 'Bar', 'visualizer' ), | |
| 246 | - 'enabled' => true, | |
| 247 | - ), | |
| 248 | - 'column' => array( | |
| 249 | - 'name' => esc_html__( 'Column', 'visualizer' ), | |
| 250 | - 'enabled' => true, | |
| 251 | - ), | |
| 252 | - 'gauge' => array( | |
| 253 | - 'name' => esc_html__( 'Gauge', 'visualizer' ), | |
| 254 | - 'enabled' => true, | |
| 255 | - ), | |
| 256 | - 'scatter' => array( | |
| 257 | - 'name' => esc_html__( 'Scatter', 'visualizer' ), | |
| 258 | - 'enabled' => true, | |
| 259 | - ), | |
| 260 | - 'candlestick' => array( | |
| 261 | - 'name' => esc_html__( 'Candlestick', 'visualizer' ), | |
| 262 | - 'enabled' => true, | |
| 263 | - ), | |
| 264 | - // pro types | |
| 265 | - 'table' => array( | |
| 266 | - 'name' => esc_html__( 'Table', 'visualizer' ), | |
| 267 | - 'enabled' => false, | |
| 268 | - ), | |
| 269 | - 'timeline' => array( | |
| 270 | - 'name' => esc_html__( 'Timeline', 'visualizer' ), | |
| 271 | - 'enabled' => false, | |
| 272 | - ), | |
| 273 | - 'combo' => array( | |
| 274 | - 'name' => esc_html__( 'Combo', 'visualizer' ), | |
| 275 | - 'enabled' => false, | |
| 276 | - ), | |
| 277 | - ) | |
| 152 | + ), | |
| 153 | + 'line' => array( | |
| 154 | + 'name' => esc_html__( 'Line', 'visualizer' ), | |
| 155 | + 'enabled' => true, | |
| 156 | + ), | |
| 157 | + 'area' => array( | |
| 158 | + 'name' => esc_html__( 'Area', 'visualizer' ), | |
| 159 | + 'enabled' => true, | |
| 160 | + ), | |
| 161 | + 'geo' => array( | |
| 162 | + 'name' => esc_html__( 'Geo', 'visualizer' ), | |
| 163 | + 'enabled' => true, | |
| 164 | + ), | |
| 165 | + 'bar' => array( | |
| 166 | + 'name' => esc_html__( 'Bar', 'visualizer' ), | |
| 167 | + 'enabled' => true, | |
| 168 | + ), | |
| 169 | + 'column' => array( | |
| 170 | + 'name' => esc_html__( 'Column', 'visualizer' ), | |
| 171 | + 'enabled' => true, | |
| 172 | + ), | |
| 173 | + 'gauge' => array( | |
| 174 | + 'name' => esc_html__( 'Gauge', 'visualizer' ), | |
| 175 | + 'enabled' => true, | |
| 176 | + ), | |
| 177 | + 'scatter' => array( | |
| 178 | + 'name' => esc_html__( 'Scatter', 'visualizer' ), | |
| 179 | + 'enabled' => true, | |
| 180 | + ), | |
| 181 | + 'candlestick' => array( | |
| 182 | + 'name' => esc_html__( 'Candlestick', 'visualizer' ), | |
| 183 | + 'enabled' => true, | |
| 184 | + ), | |
| 185 | + // pro types | |
| 186 | + 'table' => array( | |
| 187 | + 'name' => esc_html__( 'Table', 'visualizer' ), | |
| 188 | + 'enabled' => false, | |
| 189 | + ), | |
| 190 | + 'timeline' => array( | |
| 191 | + 'name' => esc_html__( 'Timeline', 'visualizer' ), | |
| 192 | + 'enabled' => false, | |
| 193 | + ), | |
| 194 | + 'combo' => array( | |
| 195 | + 'name' => esc_html__( 'Combo', 'visualizer' ), | |
| 196 | + 'enabled' => false, | |
| 197 | + ), | |
| 278 | 198 | ); |
| 279 | 199 | $types = apply_filters( 'visualizer_pro_chart_types', $types ); |
| 280 | 200 | if ( $enabledOnly ) { |
| 281 | 201 | $filtered = array(); |
| @@ -339,22 +259,18 @@ | ||
| 339 | 259 | if ( $suffix == $this->_libraryPage ) { |
| 340 | 260 | wp_enqueue_style( 'visualizer-library', VISUALIZER_ABSURL . 'css/library.css', array(), Visualizer_Plugin::VERSION ); |
| 341 | 261 | $this->_addFilter( 'media_upload_tabs', 'setupVisualizerTab' ); |
| 342 | 262 | wp_enqueue_media(); |
| 343 | - wp_enqueue_script( | |
| 344 | - 'visualizer-library', VISUALIZER_ABSURL . 'js/library.js', array( | |
| 345 | - 'jquery', | |
| 346 | - 'media-views', | |
| 347 | - ), Visualizer_Plugin::VERSION, true | |
| 348 | - ); | |
| 263 | + wp_enqueue_script( 'visualizer-library', VISUALIZER_ABSURL . 'js/library.js', array( | |
| 264 | + 'jquery', | |
| 265 | + 'media-views', | |
| 266 | + ), Visualizer_Plugin::VERSION, true ); | |
| 349 | 267 | wp_enqueue_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true ); |
| 350 | 268 | wp_enqueue_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true ); |
| 351 | - wp_enqueue_script( | |
| 352 | - 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( | |
| 353 | - 'google-jsapi-old', | |
| 354 | - 'visualizer-library', | |
| 355 | - ), Visualizer_Plugin::VERSION, true | |
| 356 | - ); | |
| 269 | + wp_enqueue_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( | |
| 270 | + 'google-jsapi-old', | |
| 271 | + 'visualizer-library', | |
| 272 | + ), Visualizer_Plugin::VERSION, true ); | |
| 357 | 273 | } |
| 358 | 274 | } |
| 359 | 275 | |
| 360 | 276 | /** |
| @@ -395,16 +311,14 @@ | ||
| 395 | 311 | * @access public |
| 396 | 312 | */ |
| 397 | 313 | public function renderLibraryPage() { |
| 398 | 314 | // get current page |
| 399 | - $page = filter_input( | |
| 400 | - INPUT_GET, 'vpage', FILTER_VALIDATE_INT, array( | |
| 401 | - 'options' => array( | |
| 402 | - 'min_range' => 1, | |
| 403 | - 'default' => 1, | |
| 404 | - ), | |
| 405 | - ) | |
| 406 | - ); | |
| 315 | + $page = filter_input( INPUT_GET, 'vpage', FILTER_VALIDATE_INT, array( | |
| 316 | + 'options' => array( | |
| 317 | + 'min_range' => 1, | |
| 318 | + 'default' => 1, | |
| 319 | + ), | |
| 320 | + ) ); | |
| 407 | 321 | // the initial query arguments to fetch charts |
| 408 | 322 | $query_args = array( |
| 409 | 323 | 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, |
| 410 | 324 | 'posts_per_page' => 6, |
| @@ -457,44 +371,39 @@ | ||
| 457 | 371 | ); |
| 458 | 372 | } |
| 459 | 373 | // enqueue charts array |
| 460 | 374 | $ajaxurl = admin_url( 'admin-ajax.php' ); |
| 461 | - wp_localize_script( | |
| 462 | - 'visualizer-library', 'visualizer', array( | |
| 463 | - 'language' => $this->get_language(), | |
| 464 | - 'map_api_key' => get_option( 'visualizer-map-api-key' ), | |
| 465 | - 'charts' => $charts, | |
| 466 | - 'urls' => array( | |
| 467 | - 'base' => add_query_arg( 'vpage', false ), | |
| 468 | - 'create' => add_query_arg( | |
| 469 | - array( | |
| 470 | - 'action' => Visualizer_Plugin::ACTION_CREATE_CHART, | |
| 471 | - 'library' => 'yes', | |
| 472 | - ), $ajaxurl | |
| 473 | - ), | |
| 474 | - 'edit' => add_query_arg( | |
| 475 | - array( | |
| 476 | - 'action' => Visualizer_Plugin::ACTION_EDIT_CHART, | |
| 477 | - 'library' => 'yes', | |
| 478 | - ), $ajaxurl | |
| 479 | - ), | |
| 480 | - ), | |
| 481 | - ) | |
| 482 | - ); | |
| 375 | + wp_localize_script( 'visualizer-library', 'visualizer', array( | |
| 376 | + 'charts' => $charts, | |
| 377 | + 'urls' => array( | |
| 378 | + 'base' => add_query_arg( 'vpage', false ), | |
| 379 | + 'create' => add_query_arg( array( | |
| 380 | + 'action' => Visualizer_Plugin::ACTION_CREATE_CHART, | |
| 381 | + 'library' => 'yes', | |
| 382 | + ), $ajaxurl ), | |
| 383 | + 'edit' => add_query_arg( array( | |
| 384 | + 'action' => Visualizer_Plugin::ACTION_EDIT_CHART, | |
| 385 | + 'library' => 'yes', | |
| 386 | + ), $ajaxurl ), | |
| 387 | + 'logger' => add_query_arg( array( | |
| 388 | + 'action' => Visualizer_Plugin::ACTION_TRACK, | |
| 389 | + 'library' => 'yes', | |
| 390 | + 'nonce' => wp_create_nonce( Visualizer_Plugin::ACTION_TRACK ), | |
| 391 | + ), $ajaxurl ), | |
| 392 | + ), | |
| 393 | + ) ); | |
| 483 | 394 | // render library page |
| 484 | 395 | $render = new Visualizer_Render_Library(); |
| 485 | 396 | $render->charts = $charts; |
| 486 | 397 | $render->type = $filter; |
| 487 | 398 | $render->types = self::_getChartTypesLocalized(); |
| 488 | - $render->pagination = paginate_links( | |
| 489 | - array( | |
| 490 | - 'base' => add_query_arg( 'vpage', '%#%' ), | |
| 491 | - 'format' => '', | |
| 492 | - 'current' => $page, | |
| 493 | - 'total' => $query->max_num_pages, | |
| 494 | - 'type' => 'array', | |
| 495 | - ) | |
| 496 | - ); | |
| 399 | + $render->pagination = paginate_links( array( | |
| 400 | + 'base' => add_query_arg( 'vpage', '%#%' ), | |
| 401 | + 'format' => '', | |
| 402 | + 'current' => $page, | |
| 403 | + 'total' => $query->max_num_pages, | |
| 404 | + 'type' => 'array', | |
| 405 | + ) ); | |
| 497 | 406 | $render->render(); |
| 498 | 407 | } |
| 499 | 408 | |
| 500 | 409 | /** |