PluginProbe
Extendify / 3.2.2
Extendify v3.2.2
3.2.2 3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 All 128 releases
← All changes | app/PartnerData.php +141 -11 3.1.6 → 3.2.2 View file →
@@ -64,8 +64,11 @@
64 64 'domainSearchURL' => '',
65 65 'showDraft' => false,
66 66 'showChat' => false,
67 67 'showAIPageCreation' => false,
68 + 'mcpConfig' => [],
69 + 'mcpWriteList' => [],
70 + 'mcpReadList' => [],
68 71 'enableImageImports-1-14-6' => false,
69 72 'disableLibraryAutoOpen' => false,
70 73 'enableApexDomain' => false,
71 74 'showLaunch' => false,
@@ -98,8 +101,9 @@
98 101 'useAutoUpdate' => false,
99 102 'showLaunchUpdate' => false,
100 103 'activeTests' => [],
101 104 'showExtendifyCode' => false,
105 + 'useComingSoon' => false,
102 106 'extendifyCodeData' => [
103 107 'link' => '',
104 108 'title' => '',
105 109 'message' => '',
@@ -104,8 +108,10 @@
104 108 'title' => '',
105 109 'message' => '',
106 110 'cta-primary' => '',
107 111 ],
112 + 'customDesign' => null,
113 + 'strings' => [],
108 114 ];
109 115
110 116 // phpcs:disable Generic.Metrics.CyclomaticComplexity.MaxExceeded
111 117 /**
@@ -114,8 +120,16 @@
114 120 * @return void
115 121 */
116 122 public function __construct()
117 123 {
124 + self::load();
125 + }
126 +
127 + /**
128 + * @return void
129 + */
130 + public static function load()
131 + {
118 132 self::$id = defined('EXTENDIFY_PARTNER_ID') ? constant('EXTENDIFY_PARTNER_ID') : null;
119 133 $data = self::getPartnerData();
120 134 self::$config['showDomainBanner'] = ($data['showDomainBanner'] ?? self::$config['showDomainBanner']);
121 135 self::$config['showDomainTask'] = ($data['showDomainTask'] ?? self::$config['showDomainTask']);
@@ -150,8 +164,11 @@
150 164 'secondaryColor' => ($data['secondaryColor'] ?? ($data['backgroundColor'] ?? null)),
151 165 'secondaryColorText' => '#ffffff',
152 166 ];
153 167 self::$config['showAIPageCreation'] = ($data['showAIPageCreation'] ?? self::$config['showAIPageCreation']);
168 + self::$config['mcpConfig'] = ($data['mcpConfig'] ?? self::$config['mcpConfig']);
169 + self::$config['mcpWriteList'] = ($data['mcpWriteList'] ?? self::$config['mcpWriteList']);
170 + self::$config['mcpReadList'] = ($data['mcpReadList'] ?? self::$config['mcpReadList']);
154 171 self::$config['showLaunch'] = ($data['showLaunch'] ?? self::$config['showLaunch']);
155 172 self::$config['showLaunchTitle'] = ($data['showLaunchTitle'] ?? self::$config['showLaunchTitle']);
156 173 self::$config['deactivated'] = ($data['deactivated'] ?? self::$config['deactivated']);
157 174 self::$config['launchRedirectWebsite'] = ($data['launchRedirectWebsite']
@@ -187,9 +204,12 @@
187 204 self::$config['useAutoUpdate'] = ($data['useAutoUpdate'] ?? self::$config['useAutoUpdate']);
188 205 self::$config['showLaunchUpdate'] = ($data['showLaunchUpdate'] ?? self::$config['showLaunchUpdate']);
189 206 self::$config['activeTests'] = ($data['activeTests'] ?? self::$config['activeTests']);
190 207 self::$config['showExtendifyCode'] = ($data['showExtendifyCode'] ?? self::$config['showExtendifyCode']);
208 + self::$config['useComingSoon'] = ($data['useComingSoon'] ?? self::$config['useComingSoon']);
191 209 self::$config['extendifyCodeData'] = ($data['extendifyCodeData'] ?? self::$config['extendifyCodeData']);
210 + self::$config['customDesign'] = ($data['customDesign'] ?? self::$config['customDesign']);
211 + self::$config['strings'] = ($data['strings'] ?? self::$config['strings']);
192 212
193 213 // Add the job hook to fetch the partner data.
194 214 \add_action('extendify_fetch_partner_data', [self::class, 'fetchPartnerData']);
195 215 }
@@ -209,15 +229,12 @@
209 229 $partnerData = \get_option('extendify_partner_data_v2', 'empty');
210 230 if ($partnerData !== 'empty') {
211 231 // We have data, but if it's been 10 minutes, check for new data.
212 232 $partnerRefresh = \get_transient('extendify_partner_data_cache_check');
213 - if (!$partnerRefresh && \is_admin()) {
214 - \add_action('init', function () {
215 - if (!\wp_next_scheduled('extendify_fetch_partner_data')) {
216 - \wp_schedule_single_event(time(), 'extendify_fetch_partner_data');
217 - \spawn_cron();
218 - }
219 - });
233 + if (!$partnerRefresh && \is_user_logged_in()) {
234 + \did_action('init')
235 + ? self::scheduleRefresh()
236 + : \add_action('init', [self::class, 'scheduleRefresh']);
220 237 }
221 238
222 239 return array_merge(self::$config, $partnerData);
223 240 }
@@ -229,8 +246,49 @@
229 246 return $mergedData;
230 247 }
231 248
232 249 /**
250 + * A token request may be the only visitor a site gets, so it fetches a stale config itself.
251 + *
252 + * @return void
253 + */
254 + public static function refreshIfStale()
255 + {
256 + if (\get_transient('extendify_partner_data_cache_check')) {
257 + return;
258 + }
259 +
260 + // The 45s timeout the plugin gives its hosts is longer than a waiting MCP client allows.
261 + $brief = function ($args) {
262 + $args['timeout'] = 5;
263 + return $args;
264 + };
265 + \add_filter('http_request_args', $brief, 101);
266 + try {
267 + $fetched = self::fetchPartnerData();
268 + } finally {
269 + \remove_filter('http_request_args', $brief, 101);
270 + }
271 +
272 + if ($fetched) {
273 + self::load();
274 + }
275 + }
276 +
277 + /**
278 + * @return void
279 + */
280 + public static function scheduleRefresh()
281 + {
282 + if (\wp_next_scheduled('extendify_fetch_partner_data')) {
283 + return;
284 + }
285 +
286 + \wp_schedule_single_event(time(), 'extendify_fetch_partner_data');
287 + \spawn_cron();
288 + }
289 +
290 + /**
233 291 * Fetch or refresh the partner data
234 292 *
235 293 * @return array
236 294 */
@@ -273,12 +331,16 @@
273 331 }
274 332
275 333 $sanitizedData = array_merge(
276 334 Sanitizer::sanitizeUnknown($result['data']),
277 - ['consentTermsCustom' => \sanitize_text_field(htmlentities(
278 - ($result['data']['consentTermsCustom'] ?? ''),
279 - ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401
280 - ))]
335 + [
336 + 'consentTermsCustom' => \sanitize_text_field(htmlentities(
337 + ($result['data']['consentTermsCustom'] ?? ''),
338 + ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401
339 + )),
340 + 'customDesign' => self::sanitizeDesign($result['data']['customDesign'] ?? null),
341 + 'strings' => self::sanitizeStrings($result['data']['strings'] ?? null),
342 + ]
281 343 );
282 344
283 345 // Merge before persisting as this data is accessed directly elsewhere.
284 346 $mergedData = array_merge(self::$config, $sanitizedData);
@@ -284,8 +346,76 @@
284 346 $mergedData = array_merge(self::$config, $sanitizedData);
285 347 \update_option('extendify_partner_data_v2', $mergedData);
286 348
287 349 return $mergedData;
350 + }
351 +
352 + /**
353 + * Partner copy overriding the shipped strings.
354 + *
355 + * Which keys exist is the flow's to know, so only shape and text are checked here.
356 + *
357 + * @param mixed $strings The map as the partner-data response carried it.
358 + * @return array
359 + */
360 + public static function sanitizeStrings($strings)
361 + {
362 + return array_map(
363 + 'sanitize_text_field',
364 + self::designEntries($strings, '/^[a-zA-Z][a-zA-Z0-9]*$/', 'is_string')
365 + );
366 + }
367 +
368 + /**
369 + * A design carries GLSL, which the text sanitizers break, so only its shape is checked.
370 + *
371 + * Empty members are left out rather than kept: json_encode writes an empty
372 + * PHP array as [], and the page reads the design as an object.
373 + *
374 + * @param mixed $design The design as the partner-data response carried it.
375 + * @return array|null
376 + */
377 + private static function sanitizeDesign($design)
378 + {
379 + if (!is_array($design)) {
380 + return null;
381 + }
382 +
383 + $shader = ($design['shader'] ?? null);
384 + $logo = ($design['logo'] ?? null);
385 + $kept = array_filter([
386 + 'vars' => self::designEntries(
387 + ($design['vars'] ?? null),
388 + '/^--ext-(ui|tpl)-[a-z0-9-]+$/',
389 + function ($value) {
390 + // A CSS value is a string, but 0.88 is a natural way to write one.
391 + return is_string($value) || is_int($value) || is_float($value);
392 + }
393 + ),
394 + 'templates' => self::designEntries(($design['templates'] ?? null), '/^[A-Za-z0-9_-]+$/', 'is_string'),
395 + 'shader' => is_string($shader) ? \wp_check_invalid_utf8($shader) : '',
396 + 'logo' => is_string($logo) ? \esc_url_raw($logo) : '',
397 + ]);
398 +
399 + return $kept ?: null;
400 + }
401 +
402 + private static function designEntries($entries, $keyPattern, callable $accepts)
403 + {
404 + if (!is_array($entries)) {
405 + return [];
406 + }
407 +
408 + $kept = [];
409 + foreach ($entries as $key => $value) {
410 + if (!is_string($key) || !preg_match($keyPattern, $key) || !$accepts($value)) {
411 + continue;
412 + }
413 +
414 + $kept[$key] = is_string($value) ? \wp_check_invalid_utf8($value) : $value;
415 + }
416 +
417 + return $kept;
288 418 }
289 419
290 420 /**
291 421 * Return colors mapped as css variables