PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 1.4.1.1
Visualizer – Tables & Charts Manager with Built-in AI Generator v1.4.1.1
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 / Frontend.php

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

139 lines 4.9 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 * Frontend module class.
25 *
26 * @category Visualizer
27 * @package Module
28 *
29 * @since 1.0.0
30 */
31 class Visualizer_Module_Frontend extends Visualizer_Module {
32
33 const NAME = __CLASS__;
34
35 /**
36 * The array of charts to render.
37 *
38 * @since 1.0.0
39 *
40 * @access private
41 * @var array
42 */
43 private $_charts = array();
44
45 /**
46 * Constructor.
47 *
48 * @since 1.0.0
49 * @uses add_filter() To add "do_shortcode" hook for "widget_text" and "term_description" filters.
50 *
51 * @access public
52 * @param Visualizer_Plugin $plugin The instance of the plugin.
53 */
54 public function __construct( Visualizer_Plugin $plugin ) {
55 parent::__construct( $plugin );
56
57 $this->_addAction( 'wp_enqueue_scripts', 'enqueueScripts' );
58 $this->_addShortcode( 'visualizer', 'renderChart' );
59
60 add_filter( 'widget_text', 'do_shortcode' );
61 add_filter( 'term_description', 'do_shortcode' );
62 }
63
64 /**
65 * Registers scripts for charts rendering.
66 *
67 * @since 1.0.0
68 * @uses wp_register_script To register javascript file.
69 *
70 * @access public
71 */
72 public function enqueueScripts() {
73 wp_register_script( 'google-jsapi', '//www.google.com/jsapi', array(), null, true );
74 wp_register_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'google-jsapi', 'jquery' ), Visualizer_Plugin::VERSION, true );
75 }
76
77 /**
78 * Returns placeholder for chart according to visualizer shortcode attributes.
79 *
80 * @since 1.0.0
81 * @uses shortcode_atts() To parse income shortocdes.
82 * @uses apply_filters() To filter chart's data and series arrays.
83 * @uses get_post_meta() To fetch chart's meta information.
84 * @uses wp_enqueue_script() To enqueue charts render script.
85 * @uses wp_localize_script() To add chart data to the page inline script.
86 *
87 * @access public
88 * @param array $atts The array of shortcode attributes.
89 */
90 public function renderChart( $atts ) {
91 $atts = shortcode_atts( array(
92 'id' => false, // chart id
93 'series' => false, // series filter hook
94 'data' => false, // data filter hook
95 ), $atts );
96
97 // if empty id or chart does not exists, then return empty string
98 if ( !$atts['id'] || !( $chart = get_post( $atts['id'] ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
99 return '';
100 }
101
102 $id = 'visualizer-' . $atts['id'];
103 $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
104
105 // faetch and update settings
106 $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
107 if ( empty( $settings['height'] ) ) {
108 $settings['height'] = '400';
109 }
110
111 // handle series filter hooks
112 $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type );
113 if ( !empty( $atts['series'] ) ) {
114 $series = apply_filters( $atts['series'], $series, $chart->ID, $type );
115 }
116
117 // handle data filter hooks
118 $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( $chart->post_content ), $chart->ID, $type );
119 if ( !empty( $atts['data'] ) ) {
120 $data = apply_filters( $atts['data'], $data, $chart->ID, $type );
121 }
122
123 // add chart to the array
124 $this->_charts[$id] = array(
125 'type' => $type,
126 'series' => $series,
127 'settings' => $settings,
128 'data' => $data,
129 );
130
131 // enqueue visualizer render and update render localizations
132 wp_enqueue_script( 'visualizer-render' );
133 wp_localize_script( 'visualizer-render', 'visualizer', array( 'charts' => $this->_charts ) );
134
135 // return placeholder div
136 return '<div id="' . $id . '"></div>';
137 }
138
139 }