PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.2.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.2.0
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
visualizer / classes / Visualizer / Module / Admin.php

Admin.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.2.0, at classes/Visualizer/Module/Admin.php

787 lines 22.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // +----------------------------------------------------------------------+
3 // | Copyright 2013 Madpixels (email : visualizer@madpixels.net) |
4 // +----------------------------------------------------------------------+
5 // | This program is free software; you can redistribute it and/or modify |
6 // | it under the terms of the GNU General Public License, version 2, as |
7 // | published by the Free Software Foundation. |
8 // | |
9 // | This program is distributed in the hope that it will be useful, |
10 // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 // | GNU General Public License for more details. |
13 // | |
14 // | You should have received a copy of the GNU General Public License |
15 // | along with this program; if not, write to the Free Software |
16 // | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
17 // | MA 02110-1301 USA |
18 // +----------------------------------------------------------------------+
19 // | Author: Eugene Manuilov <eugene@manuilov.org> |
20 // +----------------------------------------------------------------------+
21 /**
22 * The module for all admin stuff.
23 *
24 * @category Visualizer
25 * @package Module
26 *
27 * @since 1.0.0
28 */
29 class Visualizer_Module_Admin extends Visualizer_Module {
30
31 const NAME = __CLASS__;
32
33 /**
34 * Library page suffix.
35 *
36 * @since 1.0.0
37 *
38 * @access private
39 * @var string
40 */
41 private $_libraryPage;
42
43 /**
44 * Constructor.
45 *
46 * @since 1.0.0
47 *
48 * @access public
49 *
50 * @param Visualizer_Plugin $plugin The instance of the plugin.
51 */
52 public function __construct( Visualizer_Plugin $plugin ) {
53 parent::__construct( $plugin );
54 $this->_addAction( 'load-post.php', 'enqueueMediaScripts' );
55 $this->_addAction( 'load-post-new.php', 'enqueueMediaScripts' );
56 $this->_addAction( 'admin_footer', 'renderTemplates' );
57 $this->_addAction( 'admin_enqueue_scripts', 'enqueueLibraryScripts', null, 8 );
58 $this->_addAction( 'admin_menu', 'registerAdminMenu' );
59 $this->_addFilter( 'media_view_strings', 'setupMediaViewStrings' );
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 // revision support.
66 $this->_addFilter( 'wp_revisions_to_keep', 'limitRevisions', null, 10, 2 );
67 $this->_addAction( '_wp_put_post_revision', 'addRevision', null, 10, 1 );
68 $this->_addAction( 'wp_restore_post_revision', 'restoreRevision', null, 10, 2 );
69
70 $this->_addAction( 'admin_init', 'init' );
71 }
72
73 /**
74 * No limits on revisions.
75 */
76 public function limitRevisions( $num, $post ) {
77 if ( Visualizer_Plugin::CPT_VISUALIZER === $post->post_type ) {
78 return -1;
79 }
80 return $num;
81 }
82
83 /**
84 * Add a revision.
85 */
86 public function addRevision( $revision_id ) {
87 $parent_id = wp_is_post_revision( $revision_id );
88 if ( Visualizer_Plugin::CPT_VISUALIZER === get_post_type( $parent_id ) ) {
89 // add the meta data to this revision.
90 $meta = get_post_meta( $parent_id, '', true );
91
92 if ( $meta ) {
93 foreach ( $meta as $key => $value ) {
94 if ( 0 === strpos( $key, 'visualizer' ) ) {
95 add_metadata( 'post', $revision_id, $key, maybe_unserialize( $value[0] ) );
96 }
97 }
98 }
99 }
100 }
101
102 /**
103 * Restore a revision.
104 */
105 public function restoreRevision( $post_id, $revision_id ) {
106 if ( Visualizer_Plugin::CPT_VISUALIZER === get_post_type( $post_id ) ) {
107 // get the meta information from the revision.
108 $meta = get_metadata( 'post', $revision_id, '', true );
109
110 // delete all meta information from the post before adding.
111 $post_meta = get_post_meta( $post_id, '', true );
112 if ( $post_meta ) {
113 foreach ( $meta as $key => $value ) {
114 if ( 0 === strpos( $key, 'visualizer' ) ) {
115 delete_post_meta( $post_id, $key );
116 }
117 }
118 }
119
120 if ( $meta ) {
121 foreach ( $meta as $key => $value ) {
122 if ( 0 === strpos( $key, 'visualizer' ) ) {
123 add_post_meta( $post_id, $key, maybe_unserialize( $value[0] ) );
124 }
125 }
126 }
127 }
128 }
129
130 /**
131 * Admin init.
132 *
133 * @access public
134 */
135 public function init() {
136 // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
137 if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) && 'true' == get_user_option( 'rich_editing' ) ) {
138 $this->_addFilter( 'mce_external_languages', 'add_tinymce_lang', 10, 1 );
139 $this->_addFilter( 'mce_external_plugins', 'tinymce_plugin', 10, 1 );
140 $this->_addFilter( 'mce_buttons', 'register_mce_button', 10, 1 );
141 }
142 }
143
144 /**
145 * Load plugin translation for - TinyMCE API
146 *
147 * @access public
148 * @param array $arr The tinymce_lang array.
149 * @return array
150 */
151 public function add_tinymce_lang( $arr ) {
152 $ui_lang = VISUALIZER_ABSPATH . '/classes/Visualizer/Module/Language.php';
153 $ui_lang = apply_filters( 'visualizer_ui_lang_filter', $ui_lang );
154 $arr[] = $ui_lang;
155 return $arr;
156 }
157
158 /**
159 * Load custom js options - TinyMCE API
160 *
161 * @access public
162 * @param array $plugin_array The tinymce plugin array.
163 * @return array
164 */
165 public function tinymce_plugin( $plugin_array ) {
166 $plugin_array['visualizer_mce_button'] = VISUALIZER_ABSURL . 'js/mce.js';
167 return $plugin_array;
168 }
169
170 /**
171 * Register new button in the editor
172 *
173 * @access public
174 * @param array $buttons The tinymce buttons array.
175 * @return array
176 */
177 public function register_mce_button( $buttons ) {
178 array_push( $buttons, 'visualizer_mce_button' );
179 return $buttons;
180 }
181
182 /**
183 * Whether to show the feedback review or not.
184 *
185 * @access public
186 */
187 public function feedbackReviewTrigger( $dumb ) {
188 $query = new WP_Query(
189 array(
190 'posts_per_page' => 50,
191 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
192 'fields' => 'ids',
193 'update_post_meta_cache' => false,
194 'update_post_term_cache' => false,
195 )
196 );
197
198 if ( $query->have_posts() && $query->post_count > 0 ) {
199 return true;
200 }
201 return false;
202 }
203
204 /**
205 * Enqueues media scripts and styles.
206 *
207 * @since 1.0.0
208 * @uses wp_enqueue_style To enqueue style file.
209 * @uses wp_enqueue_script To enqueue script file.
210 *
211 * @access public
212 */
213 public function enqueueMediaScripts() {
214 global $typenow;
215 if ( post_type_supports( $typenow, 'editor' ) ) {
216 wp_enqueue_style( 'visualizer-media', VISUALIZER_ABSURL . 'css/media.css', array( 'media-views' ), Visualizer_Plugin::VERSION );
217
218 // Load all the assets for the different libraries we support.
219 $deps = array(
220 Visualizer_Render_Sidebar_Google::enqueue_assets( array( 'media-editor' ) ),
221 Visualizer_Render_Sidebar_Type_DataTable::enqueue_assets( array( 'media-editor' ) ),
222 );
223
224 wp_enqueue_script( 'visualizer-media-model', VISUALIZER_ABSURL . 'js/media/model.js', $deps, Visualizer_Plugin::VERSION, true );
225 wp_enqueue_script( 'visualizer-media-collection', VISUALIZER_ABSURL . 'js/media/collection.js', array( 'visualizer-media-model' ), Visualizer_Plugin::VERSION, true );
226 wp_enqueue_script( 'visualizer-media-controller', VISUALIZER_ABSURL . 'js/media/controller.js', array( 'visualizer-media-collection' ), Visualizer_Plugin::VERSION, true );
227 wp_enqueue_script( 'visualizer-media-view', VISUALIZER_ABSURL . 'js/media/view.js', array( 'visualizer-media-controller' ), Visualizer_Plugin::VERSION, true );
228 wp_localize_script(
229 'visualizer-media-view',
230 'visualizer',
231 array(
232 'i10n' => array(
233 'insert' => __( 'Insert', 'visualizer' ),
234 ),
235 )
236 );
237 wp_enqueue_script( 'visualizer-media-toolbar', VISUALIZER_ABSURL . 'js/media/toolbar.js', array( 'visualizer-media-view' ), Visualizer_Plugin::VERSION, true );
238 wp_enqueue_script( 'visualizer-media', VISUALIZER_ABSURL . 'js/media.js', array( 'visualizer-media-toolbar' ), Visualizer_Plugin::VERSION, true );
239 }
240 }
241
242 /**
243 * Extends media view strings with visualizer strings.
244 *
245 * @since 1.0.0
246 *
247 * @access public
248 *
249 * @param array $strings The array of media view strings.
250 *
251 * @return array The extended array of media view strings.
252 */
253 public function setupMediaViewStrings( $strings ) {
254 $chart_types = self::_getChartTypesLocalized( true, true, true );
255 $strings['visualizer'] = array(
256 'actions' => array(
257 'get_charts' => Visualizer_Plugin::ACTION_GET_CHARTS,
258 'delete_chart' => Visualizer_Plugin::ACTION_DELETE_CHART,
259 ),
260 'controller' => array(
261 'title' => esc_html__( 'Visualizations', 'visualizer' ),
262 ),
263 'routers' => array(
264 'library' => esc_html__( 'From Library', 'visualizer' ),
265 'create' => esc_html__( 'Create New', 'visualizer' ),
266 ),
267 'library' => array(
268 'filters' => $chart_types,
269 'types' => array_keys( $chart_types ),
270 ),
271 'nonce' => wp_create_nonce(),
272 'buildurl' => add_query_arg( 'action', Visualizer_Plugin::ACTION_CREATE_CHART, admin_url( 'admin-ajax.php' ) ),
273 );
274
275 return $strings;
276 }
277
278 /**
279 * Returns associated array of chart types and localized names.
280 *
281 * @since 1.0.0
282 *
283 * @static
284 * @access private
285 * @return array The associated array of chart types with localized names.
286 */
287 public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darray = false, $add_select = false, $where = null ) {
288 $additional = array();
289 if ( $add_select ) {
290 $additional['select'] = array(
291 'name' => esc_html__( 'All', 'visualizer' ),
292 'enabled' => true,
293 );
294 }
295
296 $types = array_merge(
297 $additional,
298 array(
299 'dataTable' => array(
300 'name' => esc_html__( 'Table (New)', 'visualizer' ),
301 'enabled' => true,
302 ),
303 'pie' => array(
304 'name' => esc_html__( 'Pie', 'visualizer' ),
305 'enabled' => true,
306 ),
307 'line' => array(
308 'name' => esc_html__( 'Line', 'visualizer' ),
309 'enabled' => true,
310 ),
311 'area' => array(
312 'name' => esc_html__( 'Area', 'visualizer' ),
313 'enabled' => true,
314 ),
315 'geo' => array(
316 'name' => esc_html__( 'Geo', 'visualizer' ),
317 'enabled' => true,
318 ),
319 'bar' => array(
320 'name' => esc_html__( 'Bar', 'visualizer' ),
321 'enabled' => true,
322 ),
323 'column' => array(
324 'name' => esc_html__( 'Column', 'visualizer' ),
325 'enabled' => true,
326 ),
327 'scatter' => array(
328 'name' => esc_html__( 'Scatter', 'visualizer' ),
329 'enabled' => true,
330 ),
331 'gauge' => array(
332 'name' => esc_html__( 'Gauge', 'visualizer' ),
333 'enabled' => true,
334 ),
335 'candlestick' => array(
336 'name' => esc_html__( 'Candlestick', 'visualizer' ),
337 'enabled' => true,
338 ),
339 // pro types
340 'table' => array(
341 'name' => esc_html__( 'Table (Deprecated)', 'visualizer' ),
342 'enabled' => false,
343 ),
344 'timeline' => array(
345 'name' => esc_html__( 'Timeline', 'visualizer' ),
346 'enabled' => false,
347 ),
348 'combo' => array(
349 'name' => esc_html__( 'Combo', 'visualizer' ),
350 'enabled' => false,
351 ),
352 )
353 );
354 $types = apply_filters( 'visualizer_pro_chart_types', $types );
355 if ( $enabledOnly ) {
356 $filtered = array();
357 foreach ( $types as $type => $array ) {
358 if ( ! is_array( $array ) ) {
359 // support for old pro
360 $array = array( 'enabled' => true, 'name' => $array );
361 }
362 if ( ! $array['enabled'] ) {
363 continue;
364 }
365 $filtered[ $type ] = $array;
366 }
367 $types = $filtered;
368 }
369 if ( $get2Darray ) {
370 $doubleD = array();
371 foreach ( $types as $type => $array ) {
372 if ( ! is_array( $array ) ) {
373 // support for old pro
374 $array = array( 'enabled' => true, 'name' => $array );
375 }
376 $doubleD[ $type ] = $array['name'];
377 }
378 $types = $doubleD;
379 }
380
381 return self::handleDeprecatedCharts( $types, $enabledOnly, $get2Darray, $where );
382 }
383
384 /**
385 * Handle (soon-to-be) deprecated charts.
386 */
387 private static function handleDeprecatedCharts( $types, $enabledOnly, $get2Darray, $where ) {
388 $deprecated = array();
389
390 switch ( $where ) {
391 case 'library':
392 // if the user has a Google Table chart, show it as deprecated otherwise remove the option from the library.
393 if ( ! self::hasChartType( 'table' ) ) {
394 $deprecated[] = 'table';
395 if ( $get2Darray ) {
396 $types['dataTable'] = esc_html__( 'Table', 'visualizer' );
397 } else {
398 $types['dataTable']['name'] = esc_html__( 'Table', 'visualizer' );
399 }
400 }
401
402 // if a user has a Gauge/Candlestick chart, then let them keep using it.
403 if ( ! VISUALIZER_PRO ) {
404 if ( ! self::hasChartType( 'gauge' ) ) {
405 if ( $get2Darray ) {
406 $deprecated[] = 'gauge';
407 } else {
408 $types['gauge']['enabled'] = false;
409 }
410 }
411 if ( ! self::hasChartType( 'candlestick' ) ) {
412 if ( $get2Darray ) {
413 $deprecated[] = 'candlestick';
414 } else {
415 $types['candlestick']['enabled'] = false;
416 }
417 }
418 }
419 break;
420 default:
421 // remove the option to create a Google Table chart.
422 $deprecated[] = 'table';
423
424 // rename the new table chart type.
425 if ( $get2Darray ) {
426 $types['dataTable'] = esc_html__( 'Table', 'visualizer' );
427 } else {
428 $types['dataTable']['name'] = esc_html__( 'Table', 'visualizer' );
429 }
430
431 // if a user has a Gauge/Candlestick chart, then let them keep using it.
432 if ( ! VISUALIZER_PRO ) {
433 if ( ! self::hasChartType( 'gauge' ) ) {
434 if ( $get2Darray ) {
435 $deprecated[] = 'gauge';
436 } else {
437 $types['gauge']['enabled'] = false;
438 }
439 }
440 if ( ! self::hasChartType( 'candlestick' ) ) {
441 if ( $get2Darray ) {
442 $deprecated[] = 'candlestick';
443 } else {
444 $types['candlestick']['enabled'] = false;
445 }
446 }
447 }
448 }
449
450 if ( $deprecated ) {
451 foreach ( $deprecated as $type ) {
452 unset( $types[ $type ] );
453 }
454 }
455
456 return $types;
457 }
458
459 /**
460 * Renders templates to use in media popup.
461 *
462 * @since 1.0.0
463 * @global string $pagenow The name of the current page.
464 *
465 * @access public
466 */
467 public function renderTemplates() {
468 global $pagenow;
469 if ( 'post.php' !== $pagenow && 'post-new.php' !== $pagenow ) {
470 return;
471 }
472 $render = new Visualizer_Render_Templates();
473 $render->render();
474 }
475
476 /**
477 * Enqueues library scripts and styles.
478 *
479 * @since 1.0.0
480 * @uses wp_enqueue_style() To enqueue library stylesheet.
481 * @uses wp_enqueue_script() To enqueue javascript file.
482 * @uses wp_enqueue_media() To enqueue media stuff.
483 *
484 * @access public
485 *
486 * @param string $suffix The current page suffix.
487 */
488 public function enqueueLibraryScripts( $suffix ) {
489 if ( $suffix === $this->_libraryPage ) {
490 wp_enqueue_style( 'visualizer-library', VISUALIZER_ABSURL . 'css/library.css', array(), Visualizer_Plugin::VERSION );
491 $this->_addFilter( 'media_upload_tabs', 'setupVisualizerTab' );
492 wp_enqueue_media();
493 wp_enqueue_script(
494 'visualizer-library',
495 VISUALIZER_ABSURL . 'js/library.js',
496 array(
497 'jquery',
498 'media-views',
499 ),
500 Visualizer_Plugin::VERSION,
501 true
502 );
503
504 wp_enqueue_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true );
505
506 $query = $this->getQuery();
507 while ( $query->have_posts() ) {
508 $chart = $query->next_post();
509 $library = $this->load_chart_type( $chart->ID );
510 if ( is_null( $library ) ) {
511 continue;
512 }
513 wp_enqueue_script(
514 "visualizer-render-$library",
515 VISUALIZER_ABSURL . 'js/render-facade.js',
516 apply_filters( 'visualizer_assets_render', array( 'visualizer-library', 'visualizer-customization' ), true ),
517 Visualizer_Plugin::VERSION,
518 true
519 );
520 }
521 }
522 }
523
524 /**
525 * Adds visualizer tab for media upload tabs array.
526 *
527 * @since 1.0.0
528 *
529 * @access public
530 *
531 * @param array $tabs The array of media upload tabs.
532 *
533 * @return array Extended array of media upload tabs.
534 */
535 public function setupVisualizerTab( $tabs ) {
536 $tabs['visualizer'] = 'Visualizer';
537
538 return $tabs;
539 }
540
541 /**
542 * Registers admin menu for visualizer library.
543 *
544 * @since 1.0.0
545 *
546 * @access public
547 */
548 public function registerAdminMenu() {
549 $title = esc_html__( 'Visualizer Library', 'visualizer' );
550 $callback = array( $this, 'renderLibraryPage' );
551 $this->_libraryPage = add_submenu_page( 'upload.php', $title, $title, 'edit_posts', Visualizer_Plugin::NAME, $callback );
552 }
553
554 /**
555 * Get the instance of WP_Query that fetches the charts as per the given criteria.
556 */
557 private function getQuery() {
558 static $q;
559 if ( ! is_null( $q ) ) {
560 return $q;
561 }
562
563 // get current page
564 $page = filter_input(
565 INPUT_GET,
566 'vpage',
567 FILTER_VALIDATE_INT,
568 array(
569 'options' => array(
570 'min_range' => 1,
571 'default' => 1,
572 ),
573 )
574 );
575 // the initial query arguments to fetch charts
576 $query_args = array(
577 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
578 'posts_per_page' => 6,
579 'paged' => $page,
580 );
581 // add chart type filter to the query arguments
582 $filter = filter_input( INPUT_GET, 'type' );
583 if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes(), true ) ) {
584 $query_args['meta_query'] = array(
585 array(
586 'key' => Visualizer_Plugin::CF_CHART_TYPE,
587 'value' => $filter,
588 'compare' => '=',
589 ),
590 );
591 } else {
592 $filter = 'all';
593 }
594 // Added by Ash/Upwork
595 $filterByMeta = filter_input( INPUT_GET, 's', FILTER_SANITIZE_STRING );
596 if ( $filterByMeta ) {
597 $query = array(
598 'key' => Visualizer_Plugin::CF_SETTINGS,
599 'value' => $filterByMeta,
600 'compare' => 'LIKE',
601 );
602 $meta = isset( $query_args['meta_query'] ) ? $query_args['meta_query'] : array();
603 $meta[] = $query;
604 $query_args['meta_query'] = $meta;
605 }
606 $q = new WP_Query( $query_args );
607 return $q;
608 }
609
610 /**
611 * Renders visualizer library page.
612 *
613 * @since 1.0.0
614 *
615 * @access public
616 */
617 public function renderLibraryPage() {
618 $charts = array();
619 $query = $this->getQuery();
620
621 // get current page
622 $page = filter_input(
623 INPUT_GET,
624 'vpage',
625 FILTER_VALIDATE_INT,
626 array(
627 'options' => array(
628 'min_range' => 1,
629 'default' => 1,
630 ),
631 )
632 );
633 // add chart type filter to the query arguments
634 $filter = filter_input( INPUT_GET, 'type' );
635 if ( ! ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes(), true ) ) ) {
636 $filter = 'all';
637 }
638
639 $css = '';
640 while ( $query->have_posts() ) {
641 $chart = $query->next_post();
642
643 // if the user has updated a chart and instead of saving it, has closed the modal. If the user refreshes, they should get the original chart.
644 $chart = $this->handleExistingRevisions( $chart->ID, $chart );
645 // refresh a "live" db query chart.
646 $chart = apply_filters( 'visualizer_schedule_refresh_chart', $chart, $chart->ID, false );
647
648 $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
649
650 // fetch and update settings
651 $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
652
653 $settings = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SETTINGS, $settings, $chart->ID, $type );
654 if ( ! empty( $atts['settings'] ) ) {
655 $settings = apply_filters( $atts['settings'], $settings, $chart->ID, $type );
656 }
657
658 unset( $settings['height'], $settings['width'] );
659 $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type );
660 $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( html_entity_decode( $chart->post_content ) ), $chart->ID, $type );
661
662 $library = $this->load_chart_type( $chart->ID );
663
664 $id = 'visualizer-' . $chart->ID;
665 $arguments = $this->get_inline_custom_css( $id, $settings );
666 if ( ! empty( $arguments ) ) {
667 $css .= $arguments[0];
668 $settings = $arguments[1];
669 }
670
671 // add chart to the array
672 $charts[ $id ] = array(
673 'id' => $chart->ID,
674 'type' => $type,
675 'series' => $series,
676 'settings' => $settings,
677 'data' => $data,
678 'library' => $library,
679 );
680 }
681 // enqueue charts array
682 $ajaxurl = admin_url( 'admin-ajax.php' );
683 wp_localize_script(
684 'visualizer-library',
685 'visualizer',
686 array(
687 'language' => $this->get_language(),
688 'map_api_key' => get_option( 'visualizer-map-api-key' ),
689 'charts' => $charts,
690 'urls' => array(
691 'base' => add_query_arg( 'vpage', false ),
692 'create' => add_query_arg(
693 array(
694 'action' => Visualizer_Plugin::ACTION_CREATE_CHART,
695 'library' => 'yes',
696 'type' => isset( $_GET['type'] ) ? $_GET['type'] : '',
697 ),
698 $ajaxurl
699 ),
700 'edit' => add_query_arg(
701 array(
702 'action' => Visualizer_Plugin::ACTION_EDIT_CHART,
703 'library' => 'yes',
704 ),
705 $ajaxurl
706 ),
707 ),
708 'page_type' => 'library',
709 'is_front' => false,
710 )
711 );
712 // render library page
713 $render = new Visualizer_Render_Library();
714 $render->charts = $charts;
715 $render->type = $filter;
716 $render->types = self::_getChartTypesLocalized( false, false, false, true );
717 $render->custom_css = $css;
718 $render->pagination = paginate_links(
719 array(
720 'base' => add_query_arg( 'vpage', '%#%' ),
721 'format' => '',
722 'current' => $page,
723 'total' => $query->max_num_pages,
724 'type' => 'array',
725 )
726 );
727 $render->render();
728 }
729
730 /**
731 * Updates the plugin's action links, which will be rendered at the plugins table.
732 *
733 * @since 1.0.0
734 *
735 * @access public
736 *
737 * @param array $links The array of original action links.
738 * @param string $file The plugin basename.
739 *
740 * @return array Updated array of action links.
741 */
742 public function getPluginActionLinks( $links, $file ) {
743 if ( $file === plugin_basename( VISUALIZER_BASEFILE ) ) {
744 array_unshift(
745 $links,
746 sprintf(
747 '<a href="%s">%s</a>',
748 admin_url( 'upload.php?page=' . Visualizer_Plugin::NAME ),
749 esc_html__( 'Library', 'visualizer' )
750 )
751 );
752 }
753
754 return $links;
755 }
756
757 /**
758 * Updates the plugin's meta links, which will be rendered at the plugins table.
759 *
760 * @since 1.0.0
761 *
762 * @access public
763 *
764 * @param array $plugin_meta The array of a plugin meta links.
765 * @param string $plugin_file The plugin's basename.
766 *
767 * @return array Updated array of plugin meta links.
768 */
769 public function getPluginMetaLinks( $plugin_meta, $plugin_file ) {
770 if ( $plugin_file === plugin_basename( VISUALIZER_BASEFILE ) ) {
771 // knowledge base link
772 $plugin_meta[] = sprintf(
773 '<a href="https://github.com/codeinwp/visualizer/wiki" target="_blank">%s</a>',
774 esc_html__( 'Knowledge Base', 'visualizer' )
775 );
776 // flattr link
777 $plugin_meta[] = sprintf(
778 '<a style="color:red" href="https://themeisle.com/plugins/visualizer-charts-and-graphs-pro-addon/" target="_blank">%s</a>',
779 esc_html__( 'Pro Addon', 'visualizer' )
780 );
781 }
782
783 return $plugin_meta;
784 }
785
786 }
787