PluginProbe
OPcache Manager / 3.3.0
OPcache Manager v3.3.0
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 2.0.0 2.1.0 2.10.0 2.11.0 2.12.0 2.13.0 2.13.1 2.14.0 2.2.0 2.3.0 2.3.1 2.3.2 2.4.0 2.5.0 2.6.0 All 36 releases
opcache-manager / includes / features / class-analyticsfactory.php

class-analyticsfactory.php in OPcache Manager 3.3.0, at includes/features/class-analyticsfactory.php

76 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Analytics factory
4 *
5 * Handles all analytics creation and queries.
6 *
7 * @package Features
8 * @author Pierre Lannoy <https://pierre.lannoy.fr/>.
9 * @since 1.0.0
10 */
11
12 namespace OPcacheManager\Plugin\Feature;
13
14 use OPcacheManager\Plugin\Feature\Analytics;
15 use OPcacheManager\System\Blog;
16 use OPcacheManager\System\Date;
17 use OPcacheManager\System\Timezone;
18
19 /**
20 * Define the analytics factory functionality.
21 *
22 * Handles all analytics creation and queries.
23 *
24 * @package Features
25 * @author Pierre Lannoy <https://pierre.lannoy.fr/>.
26 * @since 1.0.0
27 */
28 class AnalyticsFactory {
29
30 /**
31 * Ajax callback.
32 *
33 * @since 1.0.0
34 */
35 public static function get_stats_callback() {
36 check_ajax_referer( 'ajax_opcm', 'nonce' );
37 $analytics = self::get_analytics( true );
38 $query = filter_input( INPUT_POST, 'query' );
39 $queried = filter_input( INPUT_POST, 'queried' );
40 exit( wp_json_encode( $analytics->query( $query, $queried ) ) );
41 }
42
43 /**
44 * Get the content of the analytics page.
45 *
46 * @param boolean $reload Optional. Is it a reload of an already displayed analytics.
47 * @since 1.0.0
48 */
49 public static function get_analytics( $reload = false ) {
50 if ( ! ( $start = filter_input( INPUT_GET, 'start' ) ) ) {
51 $start = filter_input( INPUT_POST, 'start' );
52 }
53 if ( empty( $start ) || ! Date::is_date_exists( $start, 'Y-m-d' ) ) {
54 $sdatetime = new \DateTime( 'now' );
55 $start = $sdatetime->format( 'Y-m-d' );
56 } else {
57 $sdatetime = new \DateTime( $start );
58 }
59 if ( ! ( $end = filter_input( INPUT_GET, 'end' ) ) ) {
60 $end = filter_input( INPUT_POST, 'end' );
61 }
62 if ( empty( $end ) || ! Date::is_date_exists( $end, 'Y-m-d' ) ) {
63 $edatetime = new \DateTime( 'now' );
64 $end = $edatetime->format( 'Y-m-d' );
65 } else {
66 $edatetime = new \DateTime( $end );
67 }
68 if ( $edatetime->getTimestamp() < $sdatetime->getTimestamp() ) {
69 $start = $edatetime->format( 'Y-m-d' );
70 $end = $sdatetime->format( 'Y-m-d' );
71 }
72 return new Analytics( $start, $end, $reload );
73 }
74
75 }
76