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

159 lines 5.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 do_shortocde hook for widget_text filter
61 if ( !has_filter( 'widget_text', 'do_shortcode' ) ) {
62 add_filter( 'widget_text', 'do_shortcode' );
63 }
64
65 // add do_shortcode hook for term_description filter
66 if ( !has_filter( 'term_description', 'do_shortcode' ) ) {
67 add_filter( 'term_description', 'do_shortcode' );
68 }
69 }
70
71 /**
72 * Registers scripts for charts rendering.
73 *
74 * @since 1.0.0
75 * @uses wp_register_script To register javascript file.
76 *
77 * @access public
78 */
79 public function enqueueScripts() {
80 wp_register_script( 'visualizer-google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true );
81 wp_register_script( 'visualizer-google-jsapi-old', '//www.google.com/jsapi', array('visualizer-google-jsapi-new'), null, true );
82 wp_register_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'visualizer-google-jsapi-old', 'jquery' ), Visualizer_Plugin::VERSION, true );
83 }
84
85 /**
86 * Returns placeholder for chart according to visualizer shortcode attributes.
87 *
88 * @since 1.0.0
89 * @uses shortcode_atts() To parse income shortocdes.
90 * @uses apply_filters() To filter chart's data and series arrays.
91 * @uses get_post_meta() To fetch chart's meta information.
92 * @uses wp_enqueue_script() To enqueue charts render script.
93 * @uses wp_localize_script() To add chart data to the page inline script.
94 *
95 * @access public
96 * @param array $atts The array of shortcode attributes.
97 */
98 public function renderChart( $atts ) {
99 $atts = shortcode_atts( array(
100 'id' => false, // chart id
101 'class' => false, // chart class
102 'series' => false, // series filter hook
103 'data' => false, // data filter hook
104 'settings' => false, // data filter hook
105 ), $atts );
106
107 // if empty id or chart does not exists, then return empty string
108 if ( !$atts['id'] || !( $chart = get_post( $atts['id'] ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
109 return '';
110 }
111
112 $id = 'visualizer-' . $atts['id'];
113 $defaultClass = "visualizer-front";
114 $class = apply_filters( Visualizer_Plugin::FILTER_CHART_WRAPPER_CLASS, $atts['class'], $atts['id'] );
115 $class = $defaultClass . " " . $class;
116 $class = !empty( $class ) ? ' class="' . trim($class) . '"' : '';
117
118 $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
119
120 // faetch and update settings
121 $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
122 if ( empty( $settings['height'] ) ) {
123 $settings['height'] = '400';
124 }
125
126 // handle series filter hooks
127 $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type );
128 if ( !empty( $atts['series'] ) ) {
129 $series = apply_filters( $atts['series'], $series, $chart->ID, $type );
130 }
131 // handle settings filter hooks
132 $settings = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SETTINGS, $settings, $chart->ID, $type );
133 if ( !empty( $atts['settings'] ) ) {
134 $settings = apply_filters( $atts['settings'], $settings, $chart->ID, $type );
135 }
136
137 // handle data filter hooks
138 $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( $chart->post_content ), $chart->ID, $type );
139 if ( !empty( $atts['data'] ) ) {
140 $data = apply_filters( $atts['data'], $data, $chart->ID, $type );
141 }
142
143 // add chart to the array
144 $this->_charts[$id] = array(
145 'type' => $type,
146 'series' => $series,
147 'settings' => $settings,
148 'data' => $data,
149 );
150
151 // enqueue visualizer render and update render localizations
152 wp_enqueue_script( 'visualizer-render' );
153 wp_localize_script( 'visualizer-render', 'visualizer', array( 'charts' => $this->_charts ) );
154
155 // return placeholder div
156 return '<div id="' . $id . '"' . $class . '></div>';
157 }
158
159 }