| @@ -1,158 +1,120 @@ | ||
| 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 | - * Sources module class. | |
| 23 | - * | |
| 24 | - * @category Visualizer | |
| 25 | - * @package Module | |
| 26 | - * | |
| 27 | - * @since 1.1.0 | |
| 28 | - */ | |
| 29 | -class Visualizer_Module_Sources extends Visualizer_Module { | |
| 30 | - | |
| 31 | - const NAME = __CLASS__; | |
| 32 | - | |
| 33 | - /** | |
| 34 | - * The array of fetched sources. | |
| 35 | - * | |
| 36 | - * @since 1.1.0 | |
| 37 | - * | |
| 38 | - * @access private | |
| 39 | - * @var array | |
| 40 | - */ | |
| 41 | - private $_sources = array(); | |
| 42 | - | |
| 43 | - /** | |
| 44 | - * Constructor. | |
| 45 | - * | |
| 46 | - * @since 1.1.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->_addFilter( Visualizer_Plugin::FILTER_GET_CHART_SERIES, 'filterChartSeries', 1, 2 ); | |
| 55 | - $this->_addFilter( Visualizer_Plugin::FILTER_GET_CHART_DATA, 'filterChartData', 1, 2 ); | |
| 56 | - $this->_addFilter( 'visualizer_pro_upsell', 'addProUpsell', 10, 2 ); | |
| 57 | - } | |
| 58 | - | |
| 59 | - /** | |
| 60 | - * Filters chart sereis. | |
| 61 | - * | |
| 62 | - * @since 1.1.0 | |
| 63 | - * | |
| 64 | - * @access public | |
| 65 | - * | |
| 66 | - * @param array $series The array of chart series. | |
| 67 | - * @param int $chart_id The chart id. | |
| 68 | - * | |
| 69 | - * @return array The array of filtered series. | |
| 70 | - */ | |
| 71 | - public function filterChartSeries( $series, $chart_id ) { | |
| 72 | - $source = $this->_getSource( $chart_id ); | |
| 73 | - if ( ! $source ) { | |
| 74 | - return $series; | |
| 75 | - } | |
| 76 | - | |
| 77 | - return $source->repopulateSeries( $series, $chart_id ); | |
| 78 | - } | |
| 79 | - | |
| 80 | - /** | |
| 81 | - * Returns appropriate source object for a chart. | |
| 82 | - * | |
| 83 | - * @since 1.1.0 | |
| 84 | - * | |
| 85 | - * @access private | |
| 86 | - * | |
| 87 | - * @param int $chart_id The chart id. | |
| 88 | - * | |
| 89 | - * @return Visualizer_Source The source object if source exists, otherwise FALSE. | |
| 90 | - */ | |
| 91 | - private function _getSource( $chart_id ) { | |
| 92 | - if ( ! isset( $this->_sources[ $chart_id ] ) ) { | |
| 93 | - $class = get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ); | |
| 94 | - if ( ! class_exists( $class, true ) ) { | |
| 95 | - return false; | |
| 96 | - } | |
| 97 | - $this->_sources[ $chart_id ] = new $class(); | |
| 98 | - } | |
| 99 | - | |
| 100 | - return $this->_sources[ $chart_id ]; | |
| 101 | - } | |
| 102 | - | |
| 103 | - /** | |
| 104 | - * Filters chart data. | |
| 105 | - * | |
| 106 | - * @since 1.1.0 | |
| 107 | - * | |
| 108 | - * @access public | |
| 109 | - * | |
| 110 | - * @param array $data The array of chart data. | |
| 111 | - * @param int $chart_id The chart id. | |
| 112 | - * | |
| 113 | - * @return array The array of filtered data. | |
| 114 | - */ | |
| 115 | - public function filterChartData( $data, $chart_id ) { | |
| 116 | - $source = $this->_getSource( $chart_id ); | |
| 117 | - if ( ! $source ) { | |
| 118 | - return $data; | |
| 119 | - } | |
| 120 | - | |
| 121 | - return $source->repopulateData( $data, $chart_id ); | |
| 122 | - } | |
| 123 | - | |
| 124 | - /** | |
| 125 | - * Add the pro upsell html. | |
| 126 | - * | |
| 127 | - * @param string $old The previous html string. | |
| 128 | - * @param string $feature What feature is this filter running for. | |
| 129 | - * | |
| 130 | - * @return string The new html code. | |
| 131 | - */ | |
| 132 | - public function addProUpsell( $old, $feature = null ) { | |
| 133 | - $biz_features = array( 'schedule-chart', 'chart-permissions' ); | |
| 134 | - $return = ''; | |
| 135 | - $feature = strval( $feature ); | |
| 136 | - if ( empty( $feature ) || ( in_array( $feature, $biz_features ) && ! apply_filters( 'visualizer_is_business', false ) ) ) { | |
| 137 | - $plan = 'PRO'; | |
| 138 | - if ( in_array( $feature, $biz_features ) ) { | |
| 139 | - $plan = 'BUSINESS'; | |
| 140 | - } | |
| 141 | - $return = '<div class="only-pro-content">'; | |
| 142 | - $return .= ' <div class="only-pro-container">'; | |
| 143 | - $return .= ' <div class="only-pro-inner">'; | |
| 144 | - $return .= ' <p>' . sprintf( __( 'Enable this feature in %s version!', 'visualizer' ), $plan ) . '</p>'; | |
| 145 | - $return .= ' <a target="_blank" href="' . Visualizer_Plugin::PRO_TEASER_URL . '" title="' . __( 'Buy now', 'visualizer' ) . '">' . __( 'Buy now', 'visualizer' ) . '</a>'; | |
| 146 | - $return .= ' </div>'; | |
| 147 | - $return .= ' </div>'; | |
| 148 | - $return .= '</div>'; | |
| 149 | - } | |
| 150 | - if ( empty( $feature ) && defined( 'VISUALIZER_PRO_VERSION' ) ) { | |
| 151 | - remove_filter( 'visualizer_pro_upsell', 'addProUpsell', 10, 1 ); | |
| 152 | - $return = ''; | |
| 153 | - } | |
| 154 | - | |
| 155 | - return $return; | |
| 156 | - } | |
| 157 | - | |
| 158 | -} | |
| 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 | + * Sources module class. | |
| 25 | + * | |
| 26 | + * @category Visualizer | |
| 27 | + * @package Module | |
| 28 | + * | |
| 29 | + * @since 1.1.0 | |
| 30 | + */ | |
| 31 | +class Visualizer_Module_Sources extends Visualizer_Module { | |
| 32 | + | |
| 33 | + const NAME = __CLASS__; | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * The array of fetched sources. | |
| 37 | + * | |
| 38 | + * @since 1.1.0 | |
| 39 | + * | |
| 40 | + * @access private | |
| 41 | + * @var array | |
| 42 | + */ | |
| 43 | + private $_sources = array(); | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * Constructor. | |
| 47 | + * | |
| 48 | + * @since 1.1.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->_addFilter( Visualizer_Plugin::FILTER_GET_CHART_SERIES, 'filterChartSeries', 1, 2 ); | |
| 57 | + $this->_addFilter( Visualizer_Plugin::FILTER_GET_CHART_DATA, 'filterChartData', 1, 2 ); | |
| 58 | + } | |
| 59 | + | |
| 60 | + /** | |
| 61 | + * Returns appropriate source object for a chart. | |
| 62 | + * | |
| 63 | + * @since 1.1.0 | |
| 64 | + * | |
| 65 | + * @access private | |
| 66 | + * @param int $chart_id The chart id. | |
| 67 | + * @return Visualizer_Source The source object if source exists, otherwise FALSE. | |
| 68 | + */ | |
| 69 | + private function _getSource( $chart_id ) { | |
| 70 | + if ( !isset( $this->_sources[$chart_id] ) ) { | |
| 71 | + $class = get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ); | |
| 72 | + if ( !class_exists( $class, true ) ) { | |
| 73 | + return false; | |
| 74 | + } | |
| 75 | + | |
| 76 | + $this->_sources[$chart_id] = new $class(); | |
| 77 | + } | |
| 78 | + | |
| 79 | + return $this->_sources[$chart_id]; | |
| 80 | + } | |
| 81 | + | |
| 82 | + /** | |
| 83 | + * Filters chart sereis. | |
| 84 | + * | |
| 85 | + * @since 1.1.0 | |
| 86 | + * | |
| 87 | + * @access public | |
| 88 | + * @param array $series The array of chart series. | |
| 89 | + * @param int $chart_id The chart id. | |
| 90 | + * @return array The array of filtered series. | |
| 91 | + */ | |
| 92 | + public function filterChartSeries( $series, $chart_id ) { | |
| 93 | + $source = $this->_getSource( $chart_id ); | |
| 94 | + if ( !$source ) { | |
| 95 | + return $series; | |
| 96 | + } | |
| 97 | + | |
| 98 | + return $source->repopulateSeries( $series, $chart_id ); | |
| 99 | + } | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * Filters chart data. | |
| 103 | + * | |
| 104 | + * @since 1.1.0 | |
| 105 | + * | |
| 106 | + * @access public | |
| 107 | + * @param array $data The array of chart data. | |
| 108 | + * @param int $chart_id The chart id. | |
| 109 | + * @return array The array of filtered data. | |
| 110 | + */ | |
| 111 | + public function filterChartData( $data, $chart_id ) { | |
| 112 | + $source = $this->_getSource( $chart_id ); | |
| 113 | + if ( !$source ) { | |
| 114 | + return $data; | |
| 115 | + } | |
| 116 | + | |
| 117 | + return $source->repopulateData( $data, $chart_id ); | |
| 118 | + } | |
| 119 | + | |
| 120 | +} | |