| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FireBox |
| 4 | - * @version 1.0.2 Free | |
| 4 | + * @version 2.0.10 Free | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <info@fireplugins.com> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | - * @copyright Copyright © 2021 FirePlugins All Rights Reserved | |
| 8 | + * @copyright Copyright © 2023 FirePlugins All Rights Reserved | |
| 9 | 9 | * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | namespace FireBox\Core\Admin\Analytics\Overview; |
| @@ -29,15 +29,8 @@ | ||
| 29 | 29 | 'date' => 'this_month' |
| 30 | 30 | ]; |
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | - * Configuration | |
| 34 | - * | |
| 35 | - * @var array | |
| 36 | - */ | |
| 37 | - private $configuration; | |
| 38 | - | |
| 39 | - /** | |
| 40 | 33 | * Analytics Toolbar |
| 41 | 34 | * |
| 42 | 35 | * @var Toolbar |
| 43 | 36 | */ |
| @@ -42,24 +35,18 @@ | ||
| 42 | 35 | * @var Toolbar |
| 43 | 36 | */ |
| 44 | 37 | private $toolbar; |
| 45 | 38 | |
| 46 | - public function __construct($configuration = []) | |
| 39 | + public function __construct() | |
| 47 | 40 | { |
| 48 | - // set the configuration data of the Analytics Helper class | |
| 49 | - AnalyticsHelper::setConfigurationData($configuration); | |
| 50 | - | |
| 51 | 41 | // Ensure we can show analytics overview on current page |
| 52 | - if (!wp_doing_ajax() && !$this->canRun()) | |
| 42 | + if (!\FireBox\Core\Admin\Analytics\Helpers\AnalyticsHelper::canRun('firebox')) | |
| 53 | 43 | { |
| 54 | 44 | return; |
| 55 | 45 | } |
| 56 | 46 | |
| 57 | - $this->configuration = $configuration; | |
| 58 | - $this->toolbar = new \FireBox\Core\Admin\Analytics\Toolbar($configuration); | |
| 47 | + $this->init(); | |
| 59 | 48 | |
| 60 | - $this->ajax = new Ajax($this); | |
| 61 | - | |
| 62 | 49 | // render overview filters |
| 63 | 50 | add_action('firebox/analytics/overview/filters', [$this, 'renderFilters']); |
| 64 | 51 | |
| 65 | 52 | // render overview |
| @@ -65,42 +52,11 @@ | ||
| 65 | 52 | // render overview |
| 66 | 53 | add_action('firebox/dashboard/content', [$this, 'render']); |
| 67 | 54 | } |
| 68 | 55 | |
| 69 | - /** | |
| 70 | - * Whether we can run analytics overview or not | |
| 71 | - * | |
| 72 | - * @return boolean | |
| 73 | - */ | |
| 74 | - protected function canRun() | |
| 56 | + public function init() | |
| 75 | 57 | { |
| 76 | - // we must be on admin panel | |
| 77 | - if (!is_admin()) | |
| 78 | - { | |
| 79 | - return false; | |
| 80 | - } | |
| 81 | - | |
| 82 | - // ensure we have correct priviledges | |
| 83 | - if (!is_user_logged_in() || !current_user_can('manage_options')) | |
| 84 | - { | |
| 85 | - return false; | |
| 86 | - } | |
| 87 | - | |
| 88 | - // we must be on admin.php page | |
| 89 | - global $pagenow; | |
| 90 | - if (!$pagenow == 'admin.php') | |
| 91 | - { | |
| 92 | - return false; | |
| 93 | - } | |
| 94 | - | |
| 95 | - // ensure we are on firebox dashboard | |
| 96 | - $page = fpframework()->getPluginPage(); | |
| 97 | - if (!$page || !in_array($page, ['firebox'])) | |
| 98 | - { | |
| 99 | - return false; | |
| 100 | - } | |
| 101 | - | |
| 102 | - return true; | |
| 58 | + $this->toolbar = new \FireBox\Core\Admin\Analytics\Toolbar(); | |
| 103 | 59 | } |
| 104 | 60 | |
| 105 | 61 | /** |
| 106 | 62 | * Display the Analytics Overview |
| @@ -110,10 +66,8 @@ | ||
| 110 | 66 | public function render() |
| 111 | 67 | { |
| 112 | 68 | // Load CSS & JS files |
| 113 | 69 | $this->loadMedia(); |
| 114 | - | |
| 115 | - $payload = $this->getOverviewItemsPayload(); | |
| 116 | 70 | |
| 117 | 71 | firebox()->renderer->admin->render('analytics/overview/tmpl', [ |
| 118 | 72 | 'overview_items_names' => $this->getOverviewItemsNames(), |
| 119 | 73 | 'default_filters' => $this->default_filters |
| @@ -122,9 +76,9 @@ | ||
| 122 | 76 | |
| 123 | 77 | public function renderFilters() |
| 124 | 78 | { |
| 125 | 79 | firebox()->renderer->admin->render('analytics/overview/filters', [ |
| 126 | - 'configuration' => $this->configuration, | |
| 80 | + 'configuration' => firebox()->analytics_configuration, | |
| 127 | 81 | 'filters' => $this->getFilters() |
| 128 | 82 | ]); |
| 129 | 83 | } |
| 130 | 84 | |
| @@ -129,21 +83,33 @@ | ||
| 129 | 83 | } |
| 130 | 84 | |
| 131 | 85 | public function getOverviewItemsNames() |
| 132 | 86 | { |
| 133 | - $payload = $this->getOverviewItemsPayload(); | |
| 87 | + $names = array_keys($this->getOverviewItemsPayload()); | |
| 88 | + | |
| 134 | 89 | |
| 135 | - return array_keys($payload); | |
| 90 | + if (FBOX_LICENSE_TYPE === 'lite') | |
| 91 | + { | |
| 92 | + unset($names['submissions']); | |
| 93 | + unset($names['conversionrate']); | |
| 94 | + unset($names['countries']); | |
| 95 | + unset($names['referrers']); | |
| 96 | + unset($names['pie']); // Devices | |
| 97 | + } | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + return $names; | |
| 136 | 103 | } |
| 137 | 104 | |
| 138 | 105 | public function getOverviewItemsPayload() |
| 139 | 106 | { |
| 140 | - $configuration = $this->toolbar->getConfiguration(); | |
| 107 | + $configuration = firebox()->analytics_configuration; | |
| 141 | 108 | |
| 142 | 109 | return [ |
| 143 | 110 | 'impressions' => [ |
| 144 | 111 | 'overview_type' => 'chart', |
| 145 | - 'url_chart_metrics' => ['impressions'], | |
| 146 | 112 | 'metrics' => ['impressions'], |
| 147 | 113 | 'allowed_filters' => [ |
| 148 | 114 | 'box', |
| 149 | 115 | 'date' |
| @@ -156,10 +122,9 @@ | ||
| 156 | 122 | ], |
| 157 | 123 | ], |
| 158 | 124 | 'avg_time_open' => [ |
| 159 | 125 | 'overview_type' => 'chart', |
| 160 | - 'url_chart_metrics' => ['theaveragetimeopen'], | |
| 161 | - 'metrics' => ['theaveragetimeopen'], | |
| 126 | + 'metrics' => ['averagetimeopen'], | |
| 162 | 127 | 'allowed_filters' => [ |
| 163 | 128 | 'box', |
| 164 | 129 | 'date' |
| 165 | 130 | ], |
| @@ -170,20 +135,81 @@ | ||
| 170 | 135 | ] |
| 171 | 136 | ], |
| 172 | 137 | ], |
| 173 | 138 | |
| 139 | + 'boxes' => [ | |
| 140 | + 'overview_title' => firebox()->_('FB_TOP_BOXES'), | |
| 141 | + 'overview_type' => 'boxestable', | |
| 142 | + 'layout' => 'table', | |
| 143 | + 'reference_toolbar_item' => 'box', | |
| 144 | + 'metrics' => ['impressions'], | |
| 145 | + 'show_total' => false, | |
| 146 | + 'show_percentage' => false, | |
| 147 | + 'allowed_filters' => [ | |
| 148 | + 'box', | |
| 149 | + 'date' | |
| 150 | + ], | |
| 151 | + 'other_data' => [ | |
| 152 | + 'modify_query_data' => [ | |
| 153 | + 'select' => [ | |
| 154 | + 'boxes.ID as box_id', | |
| 155 | + 'boxes.post_title as label', | |
| 156 | + 'count(bl.id) as total' | |
| 157 | + ], | |
| 158 | + 'join' => [ | |
| 159 | + 'left join ' . $configuration['boxes_table'] . ' as boxes' => ' ON boxes.ID = bl.box' | |
| 160 | + ], | |
| 161 | + 'groupby' => 'bl.box', | |
| 162 | + 'orderby' => 'total desc' | |
| 163 | + ], | |
| 164 | + 'options' => [ | |
| 165 | + 'skip_filling_dates' => true, | |
| 166 | + 'skip_compare_check_to_retrieve_previous_data' => true | |
| 167 | + ] | |
| 168 | + ], | |
| 169 | + 'table_columns' => [ | |
| 170 | + 'box' => [ | |
| 171 | + 'label' => firebox()->_('FB_POPUP'), | |
| 172 | + ], | |
| 173 | + 'impressions' => [ | |
| 174 | + 'label' => fpframework()->_('FPF_IMPRESSIONS'), | |
| 175 | + ], | |
| 176 | + 'percentage' => [ | |
| 177 | + 'label' => '%', | |
| 178 | + 'title' => fpframework()->_('FPF_PERCENTAGE_CHANGE_OVER_PREVIOUS_PERIOD') | |
| 179 | + ] | |
| 180 | + ], | |
| 181 | + 'toolbar_items' => [ | |
| 182 | + 'date' => [ | |
| 183 | + 'method' => 'filter', | |
| 184 | + 'options_key' => 'this_month', | |
| 185 | + ] | |
| 186 | + ], | |
| 187 | + ], | |
| 174 | 188 | |
| 175 | - 'boxes_pro' => [ | |
| 176 | - 'overview_title' => firebox()->_('FB_TOP_BOXES'), | |
| 189 | + | |
| 190 | + 'submissions_pro' => [ | |
| 191 | + 'overview_title' => fpframework()->_('FPF_SUBMISSIONS'), | |
| 177 | 192 | 'overview_type' => 'pro', |
| 178 | 193 | 'layout' => 'pro', |
| 179 | 194 | 'redirect_base' => true, |
| 180 | - 'feature' => firebox()->_('FB_TOP_BOXES'), | |
| 181 | - 'image' => FBOX_MEDIA_ADMIN_URL . 'images/analytics_overview_boxes.png', | |
| 195 | + 'feature' => fpframework()->_('FPF_SUBMISSIONS_CHART'), | |
| 196 | + 'image' => FBOX_MEDIA_ADMIN_URL . 'images/analytics_overview_submissions.png', | |
| 182 | 197 | 'show_overlay_message' => true, |
| 183 | - 'class' => 'overlay-bg full-width', | |
| 198 | + 'class' => 'overlay-bg corner', | |
| 184 | 199 | 'message' => 'FPF_ANALYTICS_OVERVIEW_OVERLAY_PRO_MSG1' |
| 185 | 200 | ], |
| 201 | + 'conversionrate_pro' => [ | |
| 202 | + 'overview_title' => fpframework()->_('FPF_CONVERSION_RATE'), | |
| 203 | + 'overview_type' => 'pro', | |
| 204 | + 'layout' => 'pro', | |
| 205 | + 'redirect_base' => true, | |
| 206 | + 'feature' => fpframework()->_('FPF_CONVERSION_RATE_CHART'), | |
| 207 | + 'image' => FBOX_MEDIA_ADMIN_URL . 'images/analytics_overview_conversionrate.png', | |
| 208 | + 'show_overlay_message' => true, | |
| 209 | + 'class' => 'overlay-bg corner', | |
| 210 | + 'message' => 'FPF_ANALYTICS_OVERVIEW_OVERLAY_PRO_MSG1' | |
| 211 | + ], | |
| 186 | 212 | 'devices_pro' => [ |
| 187 | 213 | 'overview_title' => fpframework()->_('FPF_TOP_DEVICES'), |
| 188 | 214 | 'overview_type' => 'pro', |
| 189 | 215 | 'layout' => 'pro', |
| @@ -190,9 +216,9 @@ | ||
| 190 | 216 | 'redirect_base' => true, |
| 191 | 217 | 'feature' => fpframework()->_('FPF_TOP_DEVICES'), |
| 192 | 218 | 'image' => FBOX_MEDIA_ADMIN_URL . 'images/analytics_overview_devices.png', |
| 193 | 219 | 'show_overlay_message' => true, |
| 194 | - 'class' => 'overlay-bg full-width', | |
| 220 | + 'class' => 'overlay-bg corner', | |
| 195 | 221 | 'message' => 'FPF_ANALYTICS_OVERVIEW_OVERLAY_PRO_MSG1' |
| 196 | 222 | ], |
| 197 | 223 | 'countries_pro' => [ |
| 198 | 224 | 'overview_title' => fpframework()->_('FPF_TOP_COUNTRIES'), |
| @@ -201,9 +227,9 @@ | ||
| 201 | 227 | 'redirect_base' => true, |
| 202 | 228 | 'feature' => fpframework()->_('FPF_TOP_COUNTRIES'), |
| 203 | 229 | 'image' => FBOX_MEDIA_ADMIN_URL . 'images/analytics_overview_countries.png', |
| 204 | 230 | 'show_overlay_message' => true, |
| 205 | - 'class' => 'overlay-bg full-width', | |
| 231 | + 'class' => 'overlay-bg corner', | |
| 206 | 232 | 'message' => 'FPF_ANALYTICS_OVERVIEW_OVERLAY_PRO_MSG1' |
| 207 | 233 | ], |
| 208 | 234 | 'referrers_pro' => [ |
| 209 | 235 | 'overview_title' => fpframework()->_('FPF_TOP_REFERRERS'), |
| @@ -212,9 +238,9 @@ | ||
| 212 | 238 | 'redirect_base' => true, |
| 213 | 239 | 'feature' => fpframework()->_('FPF_TOP_REFERRERS'), |
| 214 | 240 | 'image' => FBOX_MEDIA_ADMIN_URL . 'images/analytics_overview_referrers.png', |
| 215 | 241 | 'show_overlay_message' => true, |
| 216 | - 'class' => 'overlay-bg full-width', | |
| 242 | + 'class' => 'overlay-bg corner', | |
| 217 | 243 | 'message' => 'FPF_ANALYTICS_OVERVIEW_OVERLAY_PRO_MSG1' |
| 218 | 244 | ], |
| 219 | 245 | |
| 220 | 246 | ]; |
| @@ -231,9 +257,9 @@ | ||
| 231 | 257 | 'default_label' => firebox()->_('FB_ALL_POPUPS'), |
| 232 | 258 | 'item' => firebox()->_('FB_POPUP_SELECTION') |
| 233 | 259 | ], |
| 234 | 260 | 'date_pro' => [ |
| 235 | - 'default_label' => fpframework()->_('FB_THIS_MONTH'), | |
| 261 | + 'default_label' => firebox()->_('FB_THIS_MONTH'), | |
| 236 | 262 | 'item' => fpframework()->_('FPF_DATE_PERIOD') |
| 237 | 263 | ] |
| 238 | 264 | |
| 239 | 265 | ]; |