AJAX
1 year ago
Admin_Page
1 year ago
Click_Tracking
1 year ago
Custom_WordPress_Columns
2 years ago
Data_Pruning
1 year ago
Date_Picker
1 year ago
Date_Range
1 year ago
Ecommerce
1 year ago
Email_Reports
1 year ago
Filter_Lists
1 year ago
Form_Submissions
1 year ago
Interval
1 year ago
Menu_Bar_Stats
1 year ago
Migrations
1 year ago
Models
1 year ago
Public_API
1 year ago
Rows
1 year ago
Statistics
1 year ago
Tables
1 year ago
Utils
1 year ago
Campaign_Builder.php
1 year ago
Capability_Manager.php
1 year ago
Chart.php
1 year ago
Chart_Geo.php
1 year ago
Click_Tracking.php
1 year ago
Cron_Job.php
1 year ago
Cron_Manager.php
1 year ago
Current_Traffic_Finder.php
1 year ago
Dashboard_Options.php
1 year ago
Dashboard_Widget.php
2 years ago
Database.php
1 year ago
Database_Manager.php
2 years ago
Empty_Report_Option.php
2 years ago
Env.php
1 year ago
Filters.php
1 year ago
Geo_Database_Background_Job.php
2 years ago
Geo_Database_Manager.php
1 year ago
Geoposition.php
2 years ago
Icon_Directory.php
2 years ago
Icon_Directory_Factory.php
2 years ago
Illuminate_Builder.php
1 year ago
Independent_Analytics.php
1 year ago
Interrupt.php
1 year ago
Known_Referrers.php
2 years ago
MainWP.php
1 year ago
Patch.php
1 year ago
Payload_Validator.php
1 year ago
Plugin_Conflict_Detector.php
1 year ago
Plugin_Group.php
1 year ago
Plugin_Group_Option.php
2 years ago
Query.php
1 year ago
Query_Taps.php
1 year ago
Quick_Stats.php
1 year ago
REST_API.php
1 year ago
Real_Time.php
1 year ago
Report.php
1 year ago
Report_Finder.php
1 year ago
Report_Options_Parser.php
2 years ago
Resource_Identifier.php
1 year ago
Settings.php
1 year ago
Sort_Configuration.php
1 year ago
Tables.php
1 year ago
Track_Resource_Changes.php
1 year ago
View.php
1 year ago
View_Counter.php
1 year ago
Views_Over_Time_Finder.php
1 year ago
WP_Option_Cache_Bust.php
2 years ago
MainWP.php
47 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | use IAWP\Date_Range\Relative_Date_Range; |
| 6 | use IAWP\Statistics\Intervals\Intervals; |
| 7 | use IAWP\Utils\Security; |
| 8 | /** @internal */ |
| 9 | class MainWP |
| 10 | { |
| 11 | public static function initialize() |
| 12 | { |
| 13 | \add_filter('mainwp_site_sync_others_data', function ($information, $data = []) { |
| 14 | return self::attach_analytics($information, $data); |
| 15 | }, 10, 2); |
| 16 | } |
| 17 | private static function attach_analytics(array $information, array $data) : array |
| 18 | { |
| 19 | $should_sync_analytics = \array_key_exists('iawp_sync_analytics', $data) && \true === $data['iawp_sync_analytics']; |
| 20 | if (!$should_sync_analytics) { |
| 21 | return $information; |
| 22 | } |
| 23 | try { |
| 24 | $table = new \IAWP\Tables\Table_Pages(); |
| 25 | $statistics_class = $table->group()->statistics_class(); |
| 26 | $date_range = new Relative_Date_Range('LAST_THIRTY'); |
| 27 | $chart_interval = Intervals::default_for($date_range->number_of_days()); |
| 28 | $statistics = new $statistics_class($date_range, null, $chart_interval); |
| 29 | $views = $statistics->get_statistic('views'); |
| 30 | $visitors = $statistics->get_statistic('visitors'); |
| 31 | $labels = \array_map(function ($data_point) use($statistics) { |
| 32 | return Security::json_encode($statistics->chart_interval()->get_label_for($data_point[0])); |
| 33 | }, $views->statistic_over_time()); |
| 34 | $views_over_time = \array_map(function ($data_point) { |
| 35 | return $data_point[1]; |
| 36 | }, $views->statistic_over_time()); |
| 37 | $visitors_over_time = \array_map(function ($data_point) { |
| 38 | return $data_point[1]; |
| 39 | }, $visitors->statistic_over_time()); |
| 40 | $information['iawp_analytics'] = ['analytics_dashboard_url' => \IAWPSCOPED\iawp_dashboard_url(), 'labels' => $labels, 'views_over_time' => $views_over_time, 'visitors_over_time' => $visitors_over_time, 'views' => $views->value(), 'visitors' => $visitors->value()]; |
| 41 | } catch (\Throwable $e) { |
| 42 | // Do nothing |
| 43 | } |
| 44 | return $information; |
| 45 | } |
| 46 | } |
| 47 |