PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 1.6.5
Visualizer – Tables & Charts Manager with Built-in AI Generator v1.6.5
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 1.6.5, at classes/Visualizer/Module/Admin.php

379 lines 13.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // +----------------------------------------------------------------------+
4 // | Copyright 2013 Madpixels (email : visualizer@madpixels.net) |
5 // +----------------------------------------------------------------------+
6 // | This program is free software; you can redistribute it and/or modify |
7 // | it under the terms of the GNU General Public License, version 2, as |
8 // | published by the Free Software Foundation. |
9 // | |
10 // | This program is distributed in the hope that it will be useful, |
11 // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 // | GNU General Public License for more details. |
14 // | |
15 // | You should have received a copy of the GNU General Public License |
16 // | along with this program; if not, write to the Free Software |
17 // | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
18 // | MA 02110-1301 USA |
19 // +----------------------------------------------------------------------+
20 // | Author: Eugene Manuilov <eugene@manuilov.org> |
21 // +----------------------------------------------------------------------+
22
23 /**
24 * The module for all admin stuff.
25 *
26 * @category Visualizer
27 * @package Module
28 *
29 * @since 1.0.0
30 */
31 class Visualizer_Module_Admin extends Visualizer_Module {
32
33 const NAME = __CLASS__;
34
35 /**
36 * Library page suffix.
37 *
38 * @since 1.0.0
39 *
40 * @access private
41 * @var string
42 */
43 private $_libraryPage;
44
45 /**
46 * Constructor.
47 *
48 * @since 1.0.0
49 *
50 * @access public
51 * @param Visualizer_Plugin $plugin The instance of the plugin.
52 */
53 public function __construct( Visualizer_Plugin $plugin ) {
54 parent::__construct( $plugin );
55
56 $this->_addAction( 'load-post.php', 'enqueueMediaScripts' );
57 $this->_addAction( 'load-post-new.php', 'enqueueMediaScripts' );
58 $this->_addAction( 'admin_footer', 'renderTempaltes' );
59 $this->_addAction( 'admin_enqueue_scripts', 'enqueueLibraryScripts' );
60 $this->_addAction( 'admin_menu', 'registerAdminMenu' );
61
62 $this->_addFilter( 'media_view_strings', 'setupMediaViewStrings' );
63 $this->_addFilter( 'plugin_action_links', 'getPluginActionLinks', 10, 2 );
64 $this->_addFilter( 'plugin_row_meta', 'getPluginMetaLinks', 10, 2 );
65 }
66
67 /**
68 * Returns associated array of chart types and localized names.
69 *
70 * @since 1.0.0
71 *
72 * @static
73 * @access private
74 * @return array The associated array of chart types with localized names.
75 */
76 public static function _getChartTypesLocalized() {
77 $types = 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__( 'Candlestick', Visualizer_Plugin::NAME ),
88 );
89
90 $types = apply_filters("visualizer_pro_chart_types", $types);
91
92 return $types;
93 }
94
95 /**
96 * Enqueues media scripts and styles.
97 *
98 * @since 1.0.0
99 * @uses wp_enqueue_style To enqueue style file.
100 * @uses wp_enqueue_script To enqueue script file.
101 *
102 * @access public
103 */
104 public function enqueueMediaScripts() {
105 global $typenow;
106
107 if ( post_type_supports( $typenow, 'editor' ) ) {
108 wp_enqueue_style( 'visualizer-media', VISUALIZER_ABSURL . 'css/media.css', array( 'media-views' ), Visualizer_Plugin::VERSION );
109
110 wp_enqueue_script( 'visualizer-google-jsapi-new', '//www.gstatic.com/charts/loader.js', array( 'media-editor' ), null, true );
111 wp_enqueue_script( 'visualizer-google-jsapi-old', '//www.google.com/jsapi', array( 'visualizer-google-jsapi-new' ), null, true );
112 wp_enqueue_script( 'visualizer-media-model', VISUALIZER_ABSURL . 'js/media/model.js', array( 'visualizer-google-jsapi-old' ), Visualizer_Plugin::VERSION, true );
113 wp_enqueue_script( 'visualizer-media-collection', VISUALIZER_ABSURL . 'js/media/collection.js', array( 'visualizer-media-model' ), Visualizer_Plugin::VERSION, true );
114 wp_enqueue_script( 'visualizer-media-controller', VISUALIZER_ABSURL . 'js/media/controller.js', array( 'visualizer-media-collection' ), Visualizer_Plugin::VERSION, true );
115 wp_enqueue_script( 'visualizer-media-view', VISUALIZER_ABSURL . 'js/media/view.js', array( 'visualizer-media-controller' ), Visualizer_Plugin::VERSION, true );
116 wp_enqueue_script( 'visualizer-media-toolbar', VISUALIZER_ABSURL . 'js/media/toolbar.js', array( 'visualizer-media-view' ), Visualizer_Plugin::VERSION, true );
117 wp_enqueue_script( 'visualizer-media', VISUALIZER_ABSURL . 'js/media.js', array( 'visualizer-media-toolbar' ), Visualizer_Plugin::VERSION, true );
118 }
119 }
120
121 /**
122 * Extends media view strings with visualizer strings.
123 *
124 * @since 1.0.0
125 *
126 * @access public
127 * @param array $strings The array of media view strings.
128 * @return array The extended array of media view strings.
129 */
130 public function setupMediaViewStrings( $strings ) {
131 $strings['visualizer'] = array(
132 'actions' => array(
133 'get_charts' => Visualizer_Plugin::ACTION_GET_CHARTS,
134 'delete_chart' => Visualizer_Plugin::ACTION_DELETE_CHART,
135 ),
136 'controller' => array(
137 'title' => esc_html__( 'Visualizations', Visualizer_Plugin::NAME ),
138 ),
139 'routers' => array(
140 'library' => esc_html__( 'From Library', Visualizer_Plugin::NAME ),
141 'create' => esc_html__( 'Create New', Visualizer_Plugin::NAME ),
142 ),
143 'library' => array(
144 'filters' => self::_getChartTypesLocalized(),
145 ),
146 'nonce' => wp_create_nonce(),
147 'buildurl' => add_query_arg( 'action', Visualizer_Plugin::ACTION_CREATE_CHART, admin_url( 'admin-ajax.php' ) ),
148 );
149
150 return $strings;
151 }
152
153 /**
154 * Renders templates to use in media popup.
155 *
156 * @since 1.0.0
157 * @global string $pagenow The name of the current page.
158 *
159 * @access public
160 */
161 public function renderTempaltes() {
162 global $pagenow;
163
164 if ( 'post.php' != $pagenow && 'post-new.php' != $pagenow ) {
165 return;
166 }
167
168 $render = new Visualizer_Render_Templates();
169 $render->render();
170 }
171
172 /**
173 * Enqueues library scripts and styles.
174 *
175 * @since 1.0.0
176 * @uses wp_enqueue_style() To enqueue library stylesheet.
177 * @uses wp_enqueue_script() To enqueue javascript file.
178 * @uses wp_enqueue_media() To enqueue media stuff.
179 *
180 * @access public
181 * @param string $suffix The current page suffix.
182 */
183 public function enqueueLibraryScripts( $suffix ) {
184 if ( $suffix == $this->_libraryPage ) {
185 wp_enqueue_style( 'visualizer-library', VISUALIZER_ABSURL . 'css/library.css', array(), Visualizer_Plugin::VERSION );
186
187 $this->_addFilter( 'media_upload_tabs', 'setupVisualizerTab' );
188
189 wp_enqueue_media();
190 wp_enqueue_script( 'visualizer-library', VISUALIZER_ABSURL . 'js/library.js', array( 'jquery', 'media-views' ), Visualizer_Plugin::VERSION, true );
191 wp_enqueue_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true );
192 wp_enqueue_script( 'google-jsapi-old', '//www.google.com/jsapi', array('google-jsapi-new'), null, true );
193 wp_enqueue_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'google-jsapi-old', 'visualizer-library' ), Visualizer_Plugin::VERSION, true );
194 }
195 }
196
197 /**
198 * Adds visualizer tab for media upload tabs array.
199 *
200 * @since 1.0.0
201 *
202 * @access public
203 * @param array $tabs The array of media upload tabs.
204 * @return array Extended array of media upload tabs.
205 */
206 public function setupVisualizerTab( $tabs ) {
207 $tabs['visualizer'] = 'Visualizer';
208 return $tabs;
209 }
210
211 /**
212 * Registers admin menu for visualizer library.
213 *
214 * @since 1.0.0
215 *
216 * @access public
217 */
218 public function registerAdminMenu() {
219 $title = esc_html__( 'Visualizer Library', Visualizer_Plugin::NAME );
220 $callback = array( $this, 'renderLibraryPage' );
221 $this->_libraryPage = add_submenu_page( 'upload.php', $title, $title, 'edit_posts', Visualizer_Plugin::NAME, $callback );
222 }
223
224 /**
225 * Renders visualizer library page.
226 *
227 * @since 1.0.0
228 *
229 * @access public
230 */
231 public function renderLibraryPage() {
232 // get current page
233 $page = filter_input( INPUT_GET, 'vpage', FILTER_VALIDATE_INT, array(
234 'options' => array(
235 'min_range' => 1,
236 'default' => 1,
237 )
238 ) );
239
240 // the initial query arguments to fetch charts
241 $query_args = array(
242 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
243 'posts_per_page' => 6,
244 'paged' => $page,
245 );
246
247 // add chart type filter to the query arguments
248 $filter = filter_input( INPUT_GET, 'type' );
249 if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes() ) ) {
250 $query_args['meta_query'] = array(
251 array(
252 'key' => Visualizer_Plugin::CF_CHART_TYPE,
253 'value' => $filter,
254 'compare' => '=',
255 ),
256 );
257 } else {
258 $filter = 'all';
259 }
260
261 // Added by Ash/Upwork
262 $filterByMeta = filter_input( INPUT_GET, 'filter', FILTER_SANITIZE_STRING );
263 if($filterByMeta){
264 $query = array(
265 'key' => Visualizer_Plugin::CF_SETTINGS,
266 'value' => $filterByMeta,
267 'compare' => 'LIKE',
268 );
269 $meta = isset($query_args['meta_query']) ? $query_args['meta_query'] : array();
270 $meta[] = $query;
271 $query_args['meta_query'] = $meta;
272 }
273 // Added by Ash/Upwork
274
275 // fetch charts
276 $charts = array();
277 $query = new WP_Query( $query_args );
278 while( $query->have_posts() ) {
279 $chart = $query->next_post();
280
281 // fetch and update settings
282 $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
283 unset( $settings['height'], $settings['width'] );
284
285 $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
286 $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type );
287 $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( $chart->post_content ), $chart->ID, $type );
288
289 // add chart to the array
290 $charts['visualizer-' . $chart->ID] = array(
291 'id' => $chart->ID,
292 'type' => $type,
293 'series' => $series,
294 'settings' => $settings,
295 'data' => $data,
296 );
297 }
298
299 // enqueue charts array
300 $ajaxurl = admin_url( 'admin-ajax.php' );
301 wp_localize_script( 'visualizer-library', 'visualizer', array(
302 'charts' => $charts,
303 'urls' => array(
304 'base' => add_query_arg( 'vpage', false ),
305 'create' => add_query_arg( array( 'action' => Visualizer_Plugin::ACTION_CREATE_CHART, 'library' => 'yes' ), $ajaxurl ),
306 'edit' => add_query_arg( array( 'action' => Visualizer_Plugin::ACTION_EDIT_CHART, 'library' => 'yes' ), $ajaxurl ),
307 ),
308 ) );
309
310 // render library page
311 $render = new Visualizer_Render_Library();
312
313 $render->charts = $charts;
314 $render->type = $filter;
315 $render->types = self::_getChartTypesLocalized();
316 $render->pagination = paginate_links( array(
317 'base' => add_query_arg( 'vpage', '%#%' ),
318 'format' => '',
319 'current' => $page,
320 'total' => $query->max_num_pages,
321 'type' => 'array',
322 ) );
323
324 $render->render();
325 }
326
327 /**
328 * Updates the plugin's action links, which will be rendered at the plugins table.
329 *
330 * @since 1.0.0
331 *
332 * @access public
333 * @param array $links The array of original action links.
334 * @param string $file The plugin basename.
335 * @return array Updated array of action links.
336 */
337 public function getPluginActionLinks( $links, $file ) {
338 if ( $file == plugin_basename( VISUALIZER_BASEFILE ) ) {
339 array_unshift(
340 $links,
341 sprintf(
342 '<a href="%s">%s</a>',
343 admin_url( 'upload.php?page=' . Visualizer_Plugin::NAME ),
344 esc_html__( 'Library', Visualizer_Plugin::NAME )
345 )
346 );
347 }
348
349 return $links;
350 }
351
352 /**
353 * Updates the plugin's meta links, which will be rendered at the plugins table.
354 *
355 * @since 1.0.0
356 *
357 * @access public
358 * @param array $plugin_meta The array of a plugin meta links.
359 * @param string $plugin_file The plugin's basename.
360 * @return array Updated array of plugin meta links.
361 */
362 public function getPluginMetaLinks( $plugin_meta, $plugin_file ) {
363 if ( $plugin_file == plugin_basename( VISUALIZER_BASEFILE ) ) {
364 // knowledge base link
365 $plugin_meta[] = sprintf(
366 '<a href="https://github.com/codeinwp/visualizer/wiki" target="_blank">%s</a>',
367 esc_html__( 'Knowledge Base', Visualizer_Plugin::NAME )
368 );
369 // flattr link
370 $plugin_meta[] = sprintf(
371 '<a style="color:red" href="https://themeisle.com/plugins/visualizer-charts-and-graphs-pro-addon/" target="_blank">%s</a>',
372 esc_html__( 'Pro Addon', Visualizer_Plugin::NAME )
373 );
374 }
375
376 return $plugin_meta;
377 }
378
379 }