PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 4.10.0
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v4.10.0
4.12.0 4.10.0 4.9.0 4.8.1 trunk 1.0 1.1 1.12.1 1.2.3 1.2.4 1.2.5 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5 1.5.1 1.5.2 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.5.1 1.6.6 1.6.6.1 1.6.6.2 1.6.6.3 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.9.0 1.9.1 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.8.1 1.9.9 1.9.9.1 1.9.9.2 1.9.9.3 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.10 2.11 2.11.1 2.12 2.12.1 2.12.2 2.12.3 2.12.4 2.13 2.14 2.14.1 2.15 2.15.1 2.16 2.16.1 2.17 2.17.1 2.18 2.18.1 2.18.2 2.18.3 2.19 2.19.1 2.19.2 2.19.3 2.2 2.2.1 2.3 2.3.1 2.3.10 2.3.2 2.3.3 2.3.4 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.1.1 2.4.1.2 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5 2.5.1 2.5.2 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.7 2.7.1 2.7.2 2.8 2.9 2.9.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.7.5 4.7.6 4.7.7
custom-facebook-feed / inc / UsageTracking / EventRecorder.php
custom-facebook-feed / inc / UsageTracking Last commit date
Core 3 weeks ago Facebook 3 weeks ago Config.php 3 weeks ago EventRecorder.php 3 weeks ago ReporterInterface.php 3 weeks ago SmashUsageTracking.php 3 weeks ago
EventRecorder.php
89 lines
1 <?php
2 /**
3 * Records usage events for the current period (stored in cff_smash_usage_events).
4 *
5 * @package CustomFacebookFeed\UsageTracking
6 * @since 4.0
7 */
8
9 namespace CustomFacebookFeed\UsageTracking;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 class EventRecorder {
16
17 const OPTION_NAME = 'cff_smash_usage_events';
18
19 /**
20 * Record one occurrence of an event (increments count and sets last_date to today).
21 *
22 * @param string $event_name Event name (e.g. plugin_installed, setting_changed).
23 */
24 public static function record( $event_name ) {
25 if ( ! Config::is_enabled() ) {
26 return;
27 }
28 if ( '' === $event_name || ! is_string( $event_name ) ) {
29 return;
30 }
31 $event_name = sanitize_text_field( $event_name );
32 if ( strlen( $event_name ) > 100 ) {
33 $event_name = substr( $event_name, 0, 100 );
34 }
35 $events = get_option( self::OPTION_NAME, array() );
36 if ( ! is_array( $events ) ) {
37 $events = array();
38 }
39 $current = isset( $events[ $event_name ] ) ? $events[ $event_name ] : 0;
40 $count = is_array( $current ) && isset( $current['count'] ) ? (int) $current['count'] + 1 : (is_numeric( $current ) ? (int) $current + 1 : 1);
41 $events[ $event_name ] = array(
42 'count' => $count,
43 'last_date' => gmdate( 'Y-m-d' ),
44 );
45 update_option( self::OPTION_NAME, $events, false );
46 }
47
48 /**
49 * Record today as an active day (for days_active metric). Keeps last 90 days.
50 */
51 public static function record_active_day() {
52 $option_key = \CustomFacebookFeed\UsageTracking\Config::OPTION_ACTIVE_DATES;
53 $dates = get_option( $option_key, array() );
54 if ( ! is_array( $dates ) ) {
55 $dates = array();
56 }
57 $today = gmdate( 'Y-m-d' );
58 if ( ! in_array( $today, $dates, true ) ) {
59 $dates[] = $today;
60 rsort( $dates );
61 $dates = array_slice( $dates, 0, 90 );
62 update_option( $option_key, $dates, false );
63 }
64 }
65
66 /**
67 * Record a session duration in seconds (for session_duration metric). Keeps last 10.
68 *
69 * @param int $seconds Duration in seconds.
70 */
71 public static function record_session_duration( $seconds ) {
72 if ( ! Config::is_enabled() ) {
73 return;
74 }
75 $seconds = (int) $seconds;
76 if ( $seconds <= 0 || $seconds > 86400 ) {
77 return;
78 }
79 $option_key = \CustomFacebookFeed\UsageTracking\Config::OPTION_SESSION_DURATIONS;
80 $durations = get_option( $option_key, array() );
81 if ( ! is_array( $durations ) ) {
82 $durations = array();
83 }
84 $durations[] = $seconds;
85 $durations = array_slice( $durations, -10 );
86 update_option( $option_key, $durations, false );
87 }
88 }
89