| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | 2 | // +----------------------------------------------------------------------+ |
| 4 | 3 | // | Copyright 2013 Madpixels (email : visualizer@madpixels.net) | |
| 5 | 4 | // +----------------------------------------------------------------------+ |
| 6 | 5 | // | This program is free software; you can redistribute it and/or modify | |
| @@ -46,24 +45,48 @@ | ||
| 46 | 45 | * |
| 47 | 46 | * @since 1.1.0 |
| 48 | 47 | * |
| 49 | 48 | * @access public |
| 49 | + * | |
| 50 | 50 | * @param Visualizer_Plugin $plugin The instance of the plugin. |
| 51 | 51 | */ |
| 52 | 52 | public function __construct( Visualizer_Plugin $plugin ) { |
| 53 | 53 | parent::__construct( $plugin ); |
| 54 | - | |
| 55 | 54 | $this->_addFilter( Visualizer_Plugin::FILTER_GET_CHART_SERIES, 'filterChartSeries', 1, 2 ); |
| 56 | 55 | $this->_addFilter( Visualizer_Plugin::FILTER_GET_CHART_DATA, 'filterChartData', 1, 2 ); |
| 56 | + $this->_addFilter( 'visualizer_pro_upsell', 'addProUpsell', 10, 2 ); | |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 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 | + /** | |
| 60 | 81 | * Returns appropriate source object for a chart. |
| 61 | 82 | * |
| 62 | 83 | * @since 1.1.0 |
| 63 | 84 | * |
| 64 | 85 | * @access private |
| 86 | + * | |
| 65 | 87 | * @param int $chart_id The chart id. |
| 88 | + * | |
| 66 | 89 | * @return Visualizer_Source The source object if source exists, otherwise FALSE. |
| 67 | 90 | */ |
| 68 | 91 | private function _getSource( $chart_id ) { |
| 69 | 92 | if ( ! isset( $this->_sources[ $chart_id ] ) ) { |
| @@ -70,9 +93,8 @@ | ||
| 70 | 93 | $class = get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ); |
| 71 | 94 | if ( ! class_exists( $class, true ) ) { |
| 72 | 95 | return false; |
| 73 | 96 | } |
| 74 | - | |
| 75 | 97 | $this->_sources[ $chart_id ] = new $class(); |
| 76 | 98 | } |
| 77 | 99 | |
| 78 | 100 | return $this->_sources[ $chart_id ]; |
| @@ -78,42 +100,58 @@ | ||
| 78 | 100 | return $this->_sources[ $chart_id ]; |
| 79 | 101 | } |
| 80 | 102 | |
| 81 | 103 | /** |
| 82 | - * Filters chart sereis. | |
| 104 | + * Filters chart data. | |
| 83 | 105 | * |
| 84 | 106 | * @since 1.1.0 |
| 85 | 107 | * |
| 86 | 108 | * @access public |
| 87 | - * @param array $series The array of chart series. | |
| 109 | + * | |
| 110 | + * @param array $data The array of chart data. | |
| 88 | 111 | * @param int $chart_id The chart id. |
| 89 | - * @return array The array of filtered series. | |
| 112 | + * | |
| 113 | + * @return array The array of filtered data. | |
| 90 | 114 | */ |
| 91 | - public function filterChartSeries( $series, $chart_id ) { | |
| 115 | + public function filterChartData( $data, $chart_id ) { | |
| 92 | 116 | $source = $this->_getSource( $chart_id ); |
| 93 | 117 | if ( ! $source ) { |
| 94 | - return $series; | |
| 118 | + return $data; | |
| 95 | 119 | } |
| 96 | 120 | |
| 97 | - return $source->repopulateSeries( $series, $chart_id ); | |
| 121 | + return $source->repopulateData( $data, $chart_id ); | |
| 98 | 122 | } |
| 99 | 123 | |
| 100 | 124 | /** |
| 101 | - * Filters chart data. | |
| 125 | + * Add the pro upsell html. | |
| 102 | 126 | * |
| 103 | - * @since 1.1.0 | |
| 127 | + * @param string $old The previous html string. | |
| 128 | + * @param string $feature What feature is this filter running for. | |
| 104 | 129 | * |
| 105 | - * @access public | |
| 106 | - * @param array $data The array of chart data. | |
| 107 | - * @param int $chart_id The chart id. | |
| 108 | - * @return array The array of filtered data. | |
| 130 | + * @return string The new html code. | |
| 109 | 131 | */ |
| 110 | - public function filterChartData( $data, $chart_id ) { | |
| 111 | - $source = $this->_getSource( $chart_id ); | |
| 112 | - if ( ! $source ) { | |
| 113 | - return $data; | |
| 132 | + public function addProUpsell( $old, $feature = null ) { | |
| 133 | + $return = ''; | |
| 134 | + $feature = strval( $feature ); | |
| 135 | + if ( empty( $feature ) || ( $feature == 'schedule-chart' && ! apply_filters( 'visualizer_is_business', false ) ) ) { | |
| 136 | + $plan = 'PRO'; | |
| 137 | + if ( $feature === 'schedule-chart' ) { | |
| 138 | + $plan = 'BUSINESS'; | |
| 139 | + } | |
| 140 | + $return = '<div class="only-pro-content">'; | |
| 141 | + $return .= ' <div class="only-pro-container">'; | |
| 142 | + $return .= ' <div class="only-pro-inner">'; | |
| 143 | + $return .= ' <p>' . sprintf( __( 'Enable this feature in %s version!', 'visualizer' ), $plan ) . '</p>'; | |
| 144 | + $return .= ' <a target="_blank" href="' . Visualizer_Plugin::PRO_TEASER_URL . '" title="' . __( 'Buy now', 'visualizer' ) . '">' . __( 'Buy now', 'visualizer' ) . '</a>'; | |
| 145 | + $return .= ' </div>'; | |
| 146 | + $return .= ' </div>'; | |
| 147 | + $return .= '</div>'; | |
| 114 | 148 | } |
| 149 | + if ( empty( $feature ) && defined( 'VISUALIZER_PRO_VERSION' ) ) { | |
| 150 | + remove_filter( 'visualizer_pro_upsell', 'addProUpsell', 10, 1 ); | |
| 151 | + $return = ''; | |
| 152 | + } | |
| 115 | 153 | |
| 116 | - return $source->repopulateData( $data, $chart_id ); | |
| 154 | + return $return; | |
| 117 | 155 | } |
| 118 | 156 | |
| 119 | 157 | } |