| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | // +----------------------------------------------------------------------+ |
| 3 | 4 | // | Copyright 2013 Madpixels (email : visualizer@madpixels.net) | |
| 4 | 5 | // +----------------------------------------------------------------------+ |
| 5 | 6 | // | This program is free software; you can redistribute it and/or modify | |
| @@ -17,8 +18,9 @@ | ||
| 17 | 18 | // | MA 02110-1301 USA | |
| 18 | 19 | // +----------------------------------------------------------------------+ |
| 19 | 20 | // | Author: Eugene Manuilov <eugene@manuilov.org> | |
| 20 | 21 | // +----------------------------------------------------------------------+ |
| 22 | + | |
| 21 | 23 | /** |
| 22 | 24 | * The module for all admin stuff. |
| 23 | 25 | * |
| 24 | 26 | * @category Visualizer |
| @@ -45,98 +47,46 @@ | ||
| 45 | 47 | * |
| 46 | 48 | * @since 1.0.0 |
| 47 | 49 | * |
| 48 | 50 | * @access public |
| 49 | - * | |
| 50 | 51 | * @param Visualizer_Plugin $plugin The instance of the plugin. |
| 51 | 52 | */ |
| 52 | 53 | public function __construct( Visualizer_Plugin $plugin ) { |
| 53 | 54 | parent::__construct( $plugin ); |
| 55 | + | |
| 54 | 56 | $this->_addAction( 'load-post.php', 'enqueueMediaScripts' ); |
| 55 | 57 | $this->_addAction( 'load-post-new.php', 'enqueueMediaScripts' ); |
| 56 | 58 | $this->_addAction( 'admin_footer', 'renderTempaltes' ); |
| 57 | - $this->_addAction( 'admin_enqueue_scripts', 'enqueueLibraryScripts', null, 8 ); | |
| 59 | + $this->_addAction( 'admin_enqueue_scripts', 'enqueueLibraryScripts' ); | |
| 58 | 60 | $this->_addAction( 'admin_menu', 'registerAdminMenu' ); |
| 61 | + | |
| 59 | 62 | $this->_addFilter( 'media_view_strings', 'setupMediaViewStrings' ); |
| 60 | 63 | $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' ); | |
| 64 | + $this->_addFilter( 'plugin_row_meta', 'getPluginMetaLinks', 10, 2 ); | |
| 66 | 65 | } |
| 67 | 66 | |
| 68 | 67 | /** |
| 69 | - * Admin init. | |
| 68 | + * Returns associated array of chart types and localized names. | |
| 70 | 69 | * |
| 71 | - * @access public | |
| 72 | - */ | |
| 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 ); | |
| 78 | - } | |
| 79 | - } | |
| 80 | - | |
| 81 | - /** | |
| 82 | - * Load plugin translation for - TinyMCE API | |
| 70 | + * @since 1.0.0 | |
| 83 | 71 | * |
| 84 | - * @access public | |
| 85 | - * @param array $arr The tinymce_lang array. | |
| 86 | - * @return array | |
| 72 | + * @static | |
| 73 | + * @access private | |
| 74 | + * @return array The associated array of chart types with localized names. | |
| 87 | 75 | */ |
| 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 | - ) | |
| 76 | + private static function _getChartTypesLocalized() { | |
| 77 | + return array( | |
| 78 | + 'all' => esc_html__( 'All', Visualizer_Plugin::NAME ), | |
| 79 | + 'pie' => esc_html__( 'Pie', Visualizer_Plugin::NAME ), | |
| 80 | + 'line' => esc_html__( 'Line', Visualizer_Plugin::NAME ), | |
| 81 | + 'area' => esc_html__( 'Area', Visualizer_Plugin::NAME ), | |
| 82 | + 'geo' => esc_html__( 'Geo', Visualizer_Plugin::NAME ), | |
| 83 | + 'bar' => esc_html__( 'Bar', Visualizer_Plugin::NAME ), | |
| 84 | + 'column' => esc_html__( 'Column', Visualizer_Plugin::NAME ), | |
| 85 | + 'gauge' => esc_html__( 'Gauge', Visualizer_Plugin::NAME ), | |
| 86 | + 'scatter' => esc_html__( 'Scatter', Visualizer_Plugin::NAME ), | |
| 87 | + 'candlestick' => esc_html__( 'Candelstick', Visualizer_Plugin::NAME ), | |
| 133 | 88 | ); |
| 134 | - | |
| 135 | - if ( $query->have_posts() && $query->post_count > 0 ) { | |
| 136 | - return true; | |
| 137 | - } | |
| 138 | - return false; | |
| 139 | 89 | } |
| 140 | 90 | |
| 141 | 91 | /** |
| 142 | 92 | * Enqueues media scripts and styles. |
| @@ -148,25 +98,19 @@ | ||
| 148 | 98 | * @access public |
| 149 | 99 | */ |
| 150 | 100 | public function enqueueMediaScripts() { |
| 151 | 101 | global $typenow; |
| 102 | + | |
| 152 | 103 | if ( post_type_supports( $typenow, 'editor' ) ) { |
| 153 | 104 | wp_enqueue_style( 'visualizer-media', VISUALIZER_ABSURL . 'css/media.css', array( 'media-views' ), Visualizer_Plugin::VERSION ); |
| 154 | - wp_enqueue_script( 'visualizer-google-jsapi-new', '//www.gstatic.com/charts/loader.js', array( 'media-editor' ), null, true ); | |
| 155 | - wp_enqueue_script( 'visualizer-google-jsapi-old', '//www.google.com/jsapi', array( 'visualizer-google-jsapi-new' ), null, true ); | |
| 156 | - wp_enqueue_script( 'visualizer-media-model', VISUALIZER_ABSURL . 'js/media/model.js', array( 'visualizer-google-jsapi-old' ), Visualizer_Plugin::VERSION, true ); | |
| 157 | - wp_enqueue_script( 'visualizer-media-collection', VISUALIZER_ABSURL . 'js/media/collection.js', array( 'visualizer-media-model' ), Visualizer_Plugin::VERSION, true ); | |
| 105 | + | |
| 106 | + wp_enqueue_script( 'visualizer-google-jsapi', '//www.google.com/jsapi', array( 'media-editor' ), null, true ); | |
| 107 | + wp_enqueue_script( 'visualizer-media-model', VISUALIZER_ABSURL . 'js/media/model.js', array( 'visualizer-google-jsapi' ), Visualizer_Plugin::VERSION, true ); | |
| 108 | + wp_enqueue_script( 'visualizer-media-collection', VISUALIZER_ABSURL . 'js/media/collection.js', array( 'visualizer-media-model' ), Visualizer_Plugin::VERSION, true ); | |
| 158 | 109 | wp_enqueue_script( 'visualizer-media-controller', VISUALIZER_ABSURL . 'js/media/controller.js', array( 'visualizer-media-collection' ), Visualizer_Plugin::VERSION, true ); |
| 159 | - 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 | - wp_enqueue_script( 'visualizer-media-toolbar', VISUALIZER_ABSURL . 'js/media/toolbar.js', array( 'visualizer-media-view' ), Visualizer_Plugin::VERSION, true ); | |
| 168 | - wp_enqueue_script( 'visualizer-media', VISUALIZER_ABSURL . 'js/media.js', array( 'visualizer-media-toolbar' ), Visualizer_Plugin::VERSION, true ); | |
| 110 | + wp_enqueue_script( 'visualizer-media-view', VISUALIZER_ABSURL . 'js/media/view.js', array( 'visualizer-media-controller' ), Visualizer_Plugin::VERSION, true ); | |
| 111 | + wp_enqueue_script( 'visualizer-media-toolbar', VISUALIZER_ABSURL . 'js/media/toolbar.js', array( 'visualizer-media-view' ), Visualizer_Plugin::VERSION, true ); | |
| 112 | + wp_enqueue_script( 'visualizer-media', VISUALIZER_ABSURL . 'js/media.js', array( 'visualizer-media-toolbar' ), Visualizer_Plugin::VERSION, true ); | |
| 169 | 113 | } |
| 170 | 114 | } |
| 171 | 115 | |
| 172 | 116 | /** |
| @@ -174,33 +118,29 @@ | ||
| 174 | 118 | * |
| 175 | 119 | * @since 1.0.0 |
| 176 | 120 | * |
| 177 | 121 | * @access public |
| 178 | - * | |
| 179 | 122 | * @param array $strings The array of media view strings. |
| 180 | - * | |
| 181 | 123 | * @return array The extended array of media view strings. |
| 182 | 124 | */ |
| 183 | 125 | public function setupMediaViewStrings( $strings ) { |
| 184 | - $chart_types = self::_getChartTypesLocalized( true, true, true ); | |
| 185 | 126 | $strings['visualizer'] = array( |
| 186 | - 'actions' => array( | |
| 127 | + 'actions' => array( | |
| 187 | 128 | 'get_charts' => Visualizer_Plugin::ACTION_GET_CHARTS, |
| 188 | 129 | 'delete_chart' => Visualizer_Plugin::ACTION_DELETE_CHART, |
| 189 | 130 | ), |
| 190 | 131 | 'controller' => array( |
| 191 | - 'title' => esc_html__( 'Visualizations', 'visualizer' ), | |
| 132 | + 'title' => esc_html__( 'Visualizations', Visualizer_Plugin::NAME ), | |
| 192 | 133 | ), |
| 193 | - 'routers' => array( | |
| 194 | - 'library' => esc_html__( 'From Library', 'visualizer' ), | |
| 195 | - 'create' => esc_html__( 'Create New', 'visualizer' ), | |
| 134 | + 'routers' => array( | |
| 135 | + 'library' => esc_html__( 'From Library', Visualizer_Plugin::NAME ), | |
| 136 | + 'create' => esc_html__( 'Create New', Visualizer_Plugin::NAME ), | |
| 196 | 137 | ), |
| 197 | - 'library' => array( | |
| 198 | - 'filters' => $chart_types, | |
| 199 | - 'types' => array_keys( $chart_types ), | |
| 138 | + 'library' => array( | |
| 139 | + 'filters' => self::_getChartTypesLocalized(), | |
| 200 | 140 | ), |
| 201 | - 'nonce' => wp_create_nonce(), | |
| 202 | - 'buildurl' => add_query_arg( 'action', Visualizer_Plugin::ACTION_CREATE_CHART, admin_url( 'admin-ajax.php' ) ), | |
| 141 | + 'nonce' => Visualizer_Security::createNonce(), | |
| 142 | + 'buildurl' => add_query_arg( 'action', Visualizer_Plugin::ACTION_CREATE_CHART, admin_url( 'admin-ajax.php' ) ), | |
| 203 | 143 | ); |
| 204 | 144 | |
| 205 | 145 | return $strings; |
| 206 | 146 | } |
| @@ -205,109 +145,8 @@ | ||
| 205 | 145 | return $strings; |
| 206 | 146 | } |
| 207 | 147 | |
| 208 | 148 | /** |
| 209 | - * Returns associated array of chart types and localized names. | |
| 210 | - * | |
| 211 | - * @since 1.0.0 | |
| 212 | - * | |
| 213 | - * @static | |
| 214 | - * @access private | |
| 215 | - * @return array The associated array of chart types with localized names. | |
| 216 | - */ | |
| 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' ), | |
| 222 | - '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 | - ) | |
| 278 | - ); | |
| 279 | - $types = apply_filters( 'visualizer_pro_chart_types', $types ); | |
| 280 | - if ( $enabledOnly ) { | |
| 281 | - $filtered = array(); | |
| 282 | - foreach ( $types as $type => $array ) { | |
| 283 | - if ( ! is_array( $array ) ) { | |
| 284 | - // support for old pro | |
| 285 | - $array = array( 'enabled' => true, 'name' => $array ); | |
| 286 | - } | |
| 287 | - if ( ! $array['enabled'] ) { | |
| 288 | - continue; | |
| 289 | - } | |
| 290 | - $filtered[ $type ] = $array; | |
| 291 | - } | |
| 292 | - $types = $filtered; | |
| 293 | - } | |
| 294 | - if ( $get2Darray ) { | |
| 295 | - $doubleD = array(); | |
| 296 | - foreach ( $types as $type => $array ) { | |
| 297 | - if ( ! is_array( $array ) ) { | |
| 298 | - // support for old pro | |
| 299 | - $array = array( 'enabled' => true, 'name' => $array ); | |
| 300 | - } | |
| 301 | - $doubleD[ $type ] = $array['name']; | |
| 302 | - } | |
| 303 | - $types = $doubleD; | |
| 304 | - } | |
| 305 | - | |
| 306 | - return $types; | |
| 307 | - } | |
| 308 | - | |
| 309 | - /** | |
| 310 | 149 | * Renders templates to use in media popup. |
| 311 | 150 | * |
| 312 | 151 | * @since 1.0.0 |
| 313 | 152 | * @global string $pagenow The name of the current page. |
| @@ -315,11 +154,13 @@ | ||
| 315 | 154 | * @access public |
| 316 | 155 | */ |
| 317 | 156 | public function renderTempaltes() { |
| 318 | 157 | global $pagenow; |
| 158 | + | |
| 319 | 159 | if ( 'post.php' != $pagenow && 'post-new.php' != $pagenow ) { |
| 320 | 160 | return; |
| 321 | 161 | } |
| 162 | + | |
| 322 | 163 | $render = new Visualizer_Render_Templates(); |
| 323 | 164 | $render->render(); |
| 324 | 165 | } |
| 325 | 166 | |
| @@ -331,30 +172,20 @@ | ||
| 331 | 172 | * @uses wp_enqueue_script() To enqueue javascript file. |
| 332 | 173 | * @uses wp_enqueue_media() To enqueue media stuff. |
| 333 | 174 | * |
| 334 | 175 | * @access public |
| 335 | - * | |
| 336 | 176 | * @param string $suffix The current page suffix. |
| 337 | 177 | */ |
| 338 | 178 | public function enqueueLibraryScripts( $suffix ) { |
| 339 | 179 | if ( $suffix == $this->_libraryPage ) { |
| 340 | 180 | wp_enqueue_style( 'visualizer-library', VISUALIZER_ABSURL . 'css/library.css', array(), Visualizer_Plugin::VERSION ); |
| 181 | + | |
| 341 | 182 | $this->_addFilter( 'media_upload_tabs', 'setupVisualizerTab' ); |
| 183 | + | |
| 342 | 184 | 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 | - ); | |
| 349 | - wp_enqueue_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true ); | |
| 350 | - 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 | - ); | |
| 185 | + wp_enqueue_script( 'visualizer-library', VISUALIZER_ABSURL . 'js/library.js', array( 'jquery', 'media-views' ), Visualizer_Plugin::VERSION, true ); | |
| 186 | + wp_enqueue_script( 'google-jsapi', '//www.google.com/jsapi', array(), null, true ); | |
| 187 | + wp_enqueue_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'google-jsapi', 'visualizer-library' ), Visualizer_Plugin::VERSION, true ); | |
| 357 | 188 | } |
| 358 | 189 | } |
| 359 | 190 | |
| 360 | 191 | /** |
| @@ -362,16 +193,13 @@ | ||
| 362 | 193 | * |
| 363 | 194 | * @since 1.0.0 |
| 364 | 195 | * |
| 365 | 196 | * @access public |
| 366 | - * | |
| 367 | 197 | * @param array $tabs The array of media upload tabs. |
| 368 | - * | |
| 369 | 198 | * @return array Extended array of media upload tabs. |
| 370 | 199 | */ |
| 371 | 200 | public function setupVisualizerTab( $tabs ) { |
| 372 | 201 | $tabs['visualizer'] = 'Visualizer'; |
| 373 | - | |
| 374 | 202 | return $tabs; |
| 375 | 203 | } |
| 376 | 204 | |
| 377 | 205 | /** |
| @@ -381,10 +209,10 @@ | ||
| 381 | 209 | * |
| 382 | 210 | * @access public |
| 383 | 211 | */ |
| 384 | 212 | public function registerAdminMenu() { |
| 385 | - $title = esc_html__( 'Visualizer Library', 'visualizer' ); | |
| 386 | - $callback = array( $this, 'renderLibraryPage' ); | |
| 213 | + $title = esc_html__( 'Visualizer Library', Visualizer_Plugin::NAME ); | |
| 214 | + $callback = array( $this, 'renderLibraryPage' ); | |
| 387 | 215 | $this->_libraryPage = add_submenu_page( 'upload.php', $title, $title, 'edit_posts', Visualizer_Plugin::NAME, $callback ); |
| 388 | 216 | } |
| 389 | 217 | |
| 390 | 218 | /** |
| @@ -395,16 +223,15 @@ | ||
| 395 | 223 | * @access public |
| 396 | 224 | */ |
| 397 | 225 | public function renderLibraryPage() { |
| 398 | 226 | // 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 | - ), | |
| 227 | + $page = filter_input( INPUT_GET, 'vpage', FILTER_VALIDATE_INT, array( | |
| 228 | + 'options' => array( | |
| 229 | + 'min_range' => 1, | |
| 230 | + 'default' => 1, | |
| 405 | 231 | ) |
| 406 | - ); | |
| 232 | + ) ); | |
| 233 | + | |
| 407 | 234 | // the initial query arguments to fetch charts |
| 408 | 235 | $query_args = array( |
| 409 | 236 | 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, |
| 410 | 237 | 'posts_per_page' => 6, |
| @@ -409,8 +236,9 @@ | ||
| 409 | 236 | 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, |
| 410 | 237 | 'posts_per_page' => 6, |
| 411 | 238 | 'paged' => $page, |
| 412 | 239 | ); |
| 240 | + | |
| 413 | 241 | // add chart type filter to the query arguments |
| 414 | 242 | $filter = filter_input( INPUT_GET, 'type' ); |
| 415 | 243 | if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes() ) ) { |
| 416 | 244 | $query_args['meta_query'] = array( |
| @@ -422,34 +250,25 @@ | ||
| 422 | 250 | ); |
| 423 | 251 | } else { |
| 424 | 252 | $filter = 'all'; |
| 425 | 253 | } |
| 426 | - // Added by Ash/Upwork | |
| 427 | - $filterByMeta = filter_input( INPUT_GET, 's', FILTER_SANITIZE_STRING ); | |
| 428 | - if ( $filterByMeta ) { | |
| 429 | - $query = array( | |
| 430 | - 'key' => Visualizer_Plugin::CF_SETTINGS, | |
| 431 | - 'value' => $filterByMeta, | |
| 432 | - 'compare' => 'LIKE', | |
| 433 | - ); | |
| 434 | - $meta = isset( $query_args['meta_query'] ) ? $query_args['meta_query'] : array(); | |
| 435 | - $meta[] = $query; | |
| 436 | - $query_args['meta_query'] = $meta; | |
| 437 | - } | |
| 438 | - // Added by Ash/Upwork | |
| 254 | + | |
| 439 | 255 | // fetch charts |
| 440 | 256 | $charts = array(); |
| 441 | - $query = new WP_Query( $query_args ); | |
| 442 | - while ( $query->have_posts() ) { | |
| 257 | + $query = new WP_Query( $query_args ); | |
| 258 | + while( $query->have_posts() ) { | |
| 443 | 259 | $chart = $query->next_post(); |
| 260 | + | |
| 444 | 261 | // fetch and update settings |
| 445 | 262 | $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true ); |
| 446 | 263 | unset( $settings['height'], $settings['width'] ); |
| 447 | - $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ); | |
| 264 | + | |
| 265 | + $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ); | |
| 448 | 266 | $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type ); |
| 449 | - $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( html_entity_decode( $chart->post_content ) ), $chart->ID, $type ); | |
| 267 | + $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( $chart->post_content ), $chart->ID, $type ); | |
| 268 | + | |
| 450 | 269 | // add chart to the array |
| 451 | - $charts[ 'visualizer-' . $chart->ID ] = array( | |
| 270 | + $charts['visualizer-' . $chart->ID] = array( | |
| 452 | 271 | 'id' => $chart->ID, |
| 453 | 272 | 'type' => $type, |
| 454 | 273 | 'series' => $series, |
| 455 | 274 | 'settings' => $settings, |
| @@ -455,46 +274,34 @@ | ||
| 455 | 274 | 'settings' => $settings, |
| 456 | 275 | 'data' => $data, |
| 457 | 276 | ); |
| 458 | 277 | } |
| 278 | + | |
| 459 | 279 | // enqueue charts array |
| 460 | 280 | $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 | - ); | |
| 281 | + wp_localize_script( 'visualizer-library', 'visualizer', array( | |
| 282 | + 'charts' => $charts, | |
| 283 | + 'urls' => array( | |
| 284 | + 'base' => add_query_arg( 'vpage', false ), | |
| 285 | + 'create' => add_query_arg( array( 'action' => Visualizer_Plugin::ACTION_CREATE_CHART, 'library' => 'yes' ), $ajaxurl ), | |
| 286 | + 'edit' => add_query_arg( array( 'action' => Visualizer_Plugin::ACTION_EDIT_CHART, 'library' => 'yes' ), $ajaxurl ), | |
| 287 | + ), | |
| 288 | + ) ); | |
| 289 | + | |
| 483 | 290 | // render library page |
| 484 | - $render = new Visualizer_Render_Library(); | |
| 485 | - $render->charts = $charts; | |
| 486 | - $render->type = $filter; | |
| 487 | - $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 | - ); | |
| 291 | + $render = new Visualizer_Render_Library(); | |
| 292 | + | |
| 293 | + $render->charts = $charts; | |
| 294 | + $render->type = $filter; | |
| 295 | + $render->types = self::_getChartTypesLocalized(); | |
| 296 | + $render->pagination = paginate_links( array( | |
| 297 | + 'base' => add_query_arg( 'vpage', '%#%' ), | |
| 298 | + 'format' => '', | |
| 299 | + 'current' => $page, | |
| 300 | + 'total' => $query->max_num_pages, | |
| 301 | + 'type' => 'array', | |
| 302 | + ) ); | |
| 303 | + | |
| 497 | 304 | $render->render(); |
| 498 | 305 | } |
| 499 | 306 | |
| 500 | 307 | /** |
| @@ -502,12 +309,10 @@ | ||
| 502 | 309 | * |
| 503 | 310 | * @since 1.0.0 |
| 504 | 311 | * |
| 505 | 312 | * @access public |
| 506 | - * | |
| 507 | - * @param array $links The array of original action links. | |
| 313 | + * @param array $links The array of original action links. | |
| 508 | 314 | * @param string $file The plugin basename. |
| 509 | - * | |
| 510 | 315 | * @return array Updated array of action links. |
| 511 | 316 | */ |
| 512 | 317 | public function getPluginActionLinks( $links, $file ) { |
| 513 | 318 | if ( $file == plugin_basename( VISUALIZER_BASEFILE ) ) { |
| @@ -515,9 +320,9 @@ | ||
| 515 | 320 | $links, |
| 516 | 321 | sprintf( |
| 517 | 322 | '<a href="%s">%s</a>', |
| 518 | 323 | admin_url( 'upload.php?page=' . Visualizer_Plugin::NAME ), |
| 519 | - esc_html__( 'Library', 'visualizer' ) | |
| 324 | + esc_html__( 'Library', Visualizer_Plugin::NAME ) | |
| 520 | 325 | ) |
| 521 | 326 | ); |
| 522 | 327 | } |
| 523 | 328 | |
| @@ -529,12 +334,10 @@ | ||
| 529 | 334 | * |
| 530 | 335 | * @since 1.0.0 |
| 531 | 336 | * |
| 532 | 337 | * @access public |
| 533 | - * | |
| 534 | - * @param array $plugin_meta The array of a plugin meta links. | |
| 338 | + * @param array $plugin_meta The array of a plugin meta links. | |
| 535 | 339 | * @param string $plugin_file The plugin's basename. |
| 536 | - * | |
| 537 | 340 | * @return array Updated array of plugin meta links. |
| 538 | 341 | */ |
| 539 | 342 | public function getPluginMetaLinks( $plugin_meta, $plugin_file ) { |
| 540 | 343 | if ( $plugin_file == plugin_basename( VISUALIZER_BASEFILE ) ) { |
| @@ -539,18 +342,13 @@ | ||
| 539 | 342 | public function getPluginMetaLinks( $plugin_meta, $plugin_file ) { |
| 540 | 343 | if ( $plugin_file == plugin_basename( VISUALIZER_BASEFILE ) ) { |
| 541 | 344 | // knowledge base link |
| 542 | 345 | $plugin_meta[] = sprintf( |
| 543 | - '<a href="https://github.com/codeinwp/visualizer/wiki" target="_blank">%s</a>', | |
| 544 | - esc_html__( 'Knowledge Base', 'visualizer' ) | |
| 346 | + '<a href="https://github.com/madpixelslabs/visualizer/wiki">%s</a>', | |
| 347 | + esc_html__( 'Knowledge Base' ) | |
| 545 | 348 | ); |
| 546 | - // flattr link | |
| 547 | - $plugin_meta[] = sprintf( | |
| 548 | - '<a style="color:red" href="https://themeisle.com/plugins/visualizer-charts-and-graphs-pro-addon/" target="_blank">%s</a>', | |
| 549 | - esc_html__( 'Pro Addon', 'visualizer' ) | |
| 550 | - ); | |
| 551 | 349 | } |
| 552 | 350 | |
| 553 | 351 | return $plugin_meta; |
| 554 | 352 | } |
| 555 | 353 | |
| 556 | -} | |
| 354 | +} | |