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 / Core / PayloadBuilder.php
custom-facebook-feed / inc / UsageTracking / Core Last commit date
PayloadBuilder.php 3 weeks ago RegisterSite.php 3 weeks ago Scheduler.php 3 weeks ago Sender.php 3 weeks ago
PayloadBuilder.php
153 lines
1 <?php
2 /**
3 * Builds the full usage report payload (schema_version, site_token, snapshot, dynamic_metrics).
4 *
5 * @package CustomFacebookFeed\UsageTracking\Core
6 * @since 4.0
7 */
8
9 namespace CustomFacebookFeed\UsageTracking\Core;
10
11 use CustomFacebookFeed\UsageTracking\Config;
12 use CustomFacebookFeed\UsageTracking\ReporterInterface;
13 use CustomFacebookFeed\CFF_Utils;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 class PayloadBuilder {
20
21 /**
22 * @var ReporterInterface
23 */
24 private $reporter;
25
26 /**
27 * @param ReporterInterface $reporter Plugin-specific reporter.
28 */
29 public function __construct( ReporterInterface $reporter ) {
30 $this->reporter = $reporter;
31 }
32
33 /**
34 * Build the full payload for the usage-report endpoint.
35 *
36 * @param string $site_token Site token from RegisterSite.
37 * @param string $period_start Period start (e.g. Y-m-d).
38 * @param string $period_end Period end (e.g. Y-m-d).
39 * @return array
40 */
41 public function build( $site_token, $period_start, $period_end ) {
42 $payload_id = $this->generate_payload_id();
43 $slug = $this->reporter->get_plugin_slug();
44 $snapshot = $this->reporter->get_configuration_snapshot();
45 $license_tier = isset( $snapshot['license_tier'] ) ? $snapshot['license_tier'] : 'free';
46 $license_status = isset( $snapshot['license_status'] ) ? $snapshot['license_status'] : null;
47 $license_expires = isset( $snapshot['license_expires'] ) ? $snapshot['license_expires'] : null;
48 $license_item_id = isset( $snapshot['license_item_id'] ) ? $snapshot['license_item_id'] : null;
49 $version = isset( $snapshot['version'] ) ? $snapshot['version'] : (defined( 'CFFVER' ) ? CFFVER : '');
50 unset( $snapshot['license_tier'], $snapshot['license_status'], $snapshot['license_expires'], $snapshot['license_item_id'], $snapshot['version'] );
51
52 $type = CFF_Utils::cff_is_pro_version() ? 'pro' : 'free';
53
54 $dynamic_metrics = $this->reporter->get_dynamic_metrics( $period_start, $period_end );
55 $errors = isset( $dynamic_metrics['errors'] ) ? $dynamic_metrics['errors'] : array();
56 unset( $dynamic_metrics['errors'] );
57
58 return array(
59 'schema_version' => $this->reporter->get_schema_version(),
60 'plugin' => $slug,
61 'type' => $type,
62 'site_token' => $site_token,
63 'payload_id' => $payload_id,
64 'period_start' => $period_start,
65 'period_end' => $period_end,
66 'plugin_info' => array(
67 'slug' => $slug,
68 'version' => $version,
69 'license_tier' => $license_tier,
70 'license_status' => $license_status,
71 'license_expires' => $license_expires,
72 'license_item_id' => $license_item_id,
73 ),
74 'configuration_snapshot' => $snapshot,
75 'errors' => $errors,
76 'dynamic_metrics' => $dynamic_metrics,
77 'active_plugins' => $this->get_active_plugins(),
78 'active_theme' => $this->get_active_theme(),
79 );
80 }
81
82 /**
83 * Generate a unique payload ID (UUID v4 style).
84 *
85 * @return string
86 */
87 private function generate_payload_id() {
88 if ( function_exists( 'wp_generate_uuid4' ) ) {
89 return wp_generate_uuid4();
90 }
91 return sprintf(
92 '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
93 wp_rand( 0, 0xffff ),
94 wp_rand( 0, 0xffff ),
95 wp_rand( 0, 0xffff ),
96 wp_rand( 0, 0x0fff ) | 0x4000,
97 wp_rand( 0, 0x3fff ) | 0x8000,
98 wp_rand( 0, 0xffff ),
99 wp_rand( 0, 0xffff ),
100 wp_rand( 0, 0xffff )
101 );
102 }
103
104 /**
105 * Get array of active plugins with slug, name, version, author.
106 *
107 * @return array
108 */
109 private function get_active_plugins(): array {
110 if ( ! function_exists( 'get_plugins' ) ) {
111 require_once ABSPATH . 'wp-admin/includes/plugin.php';
112 }
113
114 $all_plugins = get_plugins();
115 $active_basenames = array_merge(
116 (array) get_option( 'active_plugins', array() ),
117 array_keys( (array) get_site_option( 'active_sitewide_plugins', array() ) )
118 );
119
120 $result = array();
121 foreach ( array_unique( $active_basenames ) as $basename ) {
122 if ( ! isset( $all_plugins[ $basename ] ) ) {
123 continue;
124 }
125 $data = $all_plugins[ $basename ];
126 $result[] = array(
127 'slug' => $basename,
128 'name' => isset( $data['Name'] ) ? sanitize_text_field( (string) $data['Name'] ) : null,
129 'version' => isset( $data['Version'] ) ? sanitize_text_field( (string) $data['Version'] ) : null,
130 'author' => isset( $data['Author'] ) ? wp_strip_all_tags( (string) $data['Author'] ) : null,
131 );
132 }
133
134 return $result;
135 }
136
137 /**
138 * Get active theme name and version.
139 *
140 * @return array|null
141 */
142 private function get_active_theme(): ?array {
143 $theme = wp_get_theme();
144 if ( ! $theme->exists() ) {
145 return null;
146 }
147 return array(
148 'name' => sanitize_text_field( (string) $theme->get( 'Name' ) ),
149 'version' => sanitize_text_field( (string) $theme->get( 'Version' ) ),
150 );
151 }
152 }
153