| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | // +----------------------------------------------------------------------+ |
| 3 | 4 | // | Copyright 2013 Madpixels (email : visualizer@madpixels.net) | |
| 4 | 5 | // +----------------------------------------------------------------------+ |
| 5 | 6 | // | This program is free software; you can redistribute it and/or modify | |
| @@ -17,8 +18,9 @@ | ||
| 17 | 18 | // | MA 02110-1301 USA | |
| 18 | 19 | // +----------------------------------------------------------------------+ |
| 19 | 20 | // | Author: Eugene Manuilov <eugene@manuilov.org> | |
| 20 | 21 | // +----------------------------------------------------------------------+ |
| 22 | + | |
| 21 | 23 | /** |
| 22 | 24 | * Sources module class. |
| 23 | 25 | * |
| 24 | 26 | * @category Visualizer |
| @@ -45,60 +47,56 @@ | ||
| 45 | 47 | * |
| 46 | 48 | * @since 1.1.0 |
| 47 | 49 | * |
| 48 | 50 | * @access public |
| 49 | - * | |
| 50 | 51 | * @param Visualizer_Plugin $plugin The instance of the plugin. |
| 51 | 52 | */ |
| 52 | 53 | public function __construct( Visualizer_Plugin $plugin ) { |
| 53 | 54 | parent::__construct( $plugin ); |
| 55 | + | |
| 54 | 56 | $this->_addFilter( Visualizer_Plugin::FILTER_GET_CHART_SERIES, 'filterChartSeries', 1, 2 ); |
| 55 | 57 | $this->_addFilter( Visualizer_Plugin::FILTER_GET_CHART_DATA, 'filterChartData', 1, 2 ); |
| 56 | - $this->_addFilter( 'visualizer_pro_upsell', 'addProUpsell', 10, 2 ); | |
| 57 | 58 | } |
| 58 | 59 | |
| 59 | 60 | /** |
| 60 | - * Filters chart sereis. | |
| 61 | + * Returns appropriate source object for a chart. | |
| 61 | 62 | * |
| 62 | 63 | * @since 1.1.0 |
| 63 | 64 | * |
| 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. | |
| 65 | + * @access private | |
| 66 | + * @param int $chart_id The chart id. | |
| 67 | + * @return Visualizer_Source The source object if source exists, otherwise FALSE. | |
| 70 | 68 | */ |
| 71 | - public function filterChartSeries( $series, $chart_id ) { | |
| 72 | - $source = $this->_getSource( $chart_id ); | |
| 73 | - if ( ! $source ) { | |
| 74 | - return $series; | |
| 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(); | |
| 75 | 77 | } |
| 76 | 78 | |
| 77 | - return $source->repopulateSeries( $series, $chart_id ); | |
| 79 | + return $this->_sources[$chart_id]; | |
| 78 | 80 | } |
| 79 | 81 | |
| 80 | 82 | /** |
| 81 | - * Returns appropriate source object for a chart. | |
| 83 | + * Filters chart sereis. | |
| 82 | 84 | * |
| 83 | 85 | * @since 1.1.0 |
| 84 | 86 | * |
| 85 | - * @access private | |
| 86 | - * | |
| 87 | + * @access public | |
| 88 | + * @param array $series The array of chart series. | |
| 87 | 89 | * @param int $chart_id The chart id. |
| 88 | - * | |
| 89 | - * @return Visualizer_Source The source object if source exists, otherwise FALSE. | |
| 90 | + * @return array The array of filtered series. | |
| 90 | 91 | */ |
| 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(); | |
| 92 | + public function filterChartSeries( $series, $chart_id ) { | |
| 93 | + $source = $this->_getSource( $chart_id ); | |
| 94 | + if ( !$source ) { | |
| 95 | + return $series; | |
| 98 | 96 | } |
| 99 | 97 | |
| 100 | - return $this->_sources[ $chart_id ]; | |
| 98 | + return $source->repopulateSeries( $series, $chart_id ); | |
| 101 | 99 | } |
| 102 | 100 | |
| 103 | 101 | /** |
| 104 | 102 | * Filters chart data. |
| @@ -105,17 +103,15 @@ | ||
| 105 | 103 | * |
| 106 | 104 | * @since 1.1.0 |
| 107 | 105 | * |
| 108 | 106 | * @access public |
| 109 | - * | |
| 110 | 107 | * @param array $data The array of chart data. |
| 111 | - * @param int $chart_id The chart id. | |
| 112 | - * | |
| 108 | + * @param int $chart_id The chart id. | |
| 113 | 109 | * @return array The array of filtered data. |
| 114 | 110 | */ |
| 115 | 111 | public function filterChartData( $data, $chart_id ) { |
| 116 | 112 | $source = $this->_getSource( $chart_id ); |
| 117 | - if ( ! $source ) { | |
| 113 | + if ( !$source ) { | |
| 118 | 114 | return $data; |
| 119 | 115 | } |
| 120 | 116 | |
| 121 | 117 | return $source->repopulateData( $data, $chart_id ); |
| @@ -120,39 +116,5 @@ | ||
| 120 | 116 | |
| 121 | 117 | return $source->repopulateData( $data, $chart_id ); |
| 122 | 118 | } |
| 123 | 119 | |
| 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 | -} | |
| 120 | +} | |