PluginProbe
Extendify / trunk
Extendify vtrunk
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 0.6.0 All 127 releases
← All changes | app/Assist/Controllers/DomainsSuggestionController.php +25 -11 3.0.4 → trunk View file →
@@ -5,8 +5,9 @@
5 5 */
6 6
7 7 namespace Extendify\Assist\Controllers;
8 8
9 +use Extendify\Constants;
9 10 use Extendify\Shared\Services\Sanitizer;
10 11
11 12 defined('ABSPATH') || die('No direct access.');
12 13
@@ -16,15 +17,8 @@
16 17
17 18 class DomainsSuggestionController
18 19 {
19 20 /**
20 - * The url for the server.
21 - *
22 - * @var string
23 - */
24 - public static $host = 'https://ai.extendify.com';
25 -
26 - /**
27 21 * The list of url strings in the site name to block from using the api.
28 22 *
29 23 * @var array
30 24 */
@@ -65,25 +59,36 @@
65 59 if (!self::hasValidSiteTitle($siteName)) {
66 60 return new \WP_REST_Response([]);
67 61 }
68 62
63 + $cleanedSiteTitle = self::cleanSiteTitle($siteName);
64 + if ($cleanedSiteTitle === '') {
65 + return new \WP_REST_Response([]);
66 + }
67 +
69 68 $siteProfile = \get_option('extendify_site_profile', []);
69 + if (empty($siteProfile)) {
70 + return new \WP_REST_Response([]);
71 + }
72 +
70 73 $businessDescription = ($siteProfile['description'] ?? '');
71 74 $data = [
72 - 'query' => self::cleanSiteTitle($siteName),
75 + 'query' => $cleanedSiteTitle,
73 76 'devbuild' => defined('EXTENDIFY_DEVMODE')
74 77 ? constant('EXTENDIFY_DEVMODE')
75 78 : is_readable(EXTENDIFY_PATH . '.devbuild'),
76 79 'siteId' => \get_option('extendify_site_id', ''),
77 80 'tlds' => ($partnerData['domainTLDs'] ?? []),
81 + 'priorityTlds' => ($partnerData['priorityDomainTLDs'] ?? []),
78 82 'partnerId' => \esc_attr(constant('EXTENDIFY_PARTNER_ID')),
79 83 'wpLanguage' => \get_locale(),
80 84 'wpVersion' => \get_bloginfo('version'),
81 85 'businessDescription' => \esc_attr($businessDescription),
86 + 'siteProfile' => $siteProfile,
82 87 ];
83 88
84 89 $response = \wp_remote_post(
85 - sprintf('%s/api/domains/suggest', static::$host),
90 + sprintf('%s/api/domains/suggest', Constants::AI_HOST),
86 91 [
87 92 'body' => \wp_json_encode($data),
88 93 'headers' => ['Content-Type' => 'application/json'],
89 94 ]
@@ -92,14 +97,19 @@
92 97 if (is_wp_error($response)) {
93 98 return new \WP_REST_Response([]);
94 99 }
95 100
101 + $status = \wp_remote_retrieve_response_code($response);
102 + if ($status < 200 || $status >= 300) {
103 + return new \WP_REST_Response([]);
104 + }
105 +
96 106 $body = wp_remote_retrieve_body($response);
97 107 if (empty($body)) {
98 108 return new \WP_REST_Response([]);
99 109 }
100 110
101 - return new \WP_REST_Response(json_decode($body, true), \wp_remote_retrieve_response_code($response));
111 + return new \WP_REST_Response(json_decode($body, true), $status);
102 112 }
103 113
104 114 /**
105 115 * Clean site title.
@@ -108,9 +118,13 @@
108 118 * @return string
109 119 */
110 120 public static function cleanSiteTitle($siteTitle)
111 121 {
112 - return preg_replace('/[^\p{L}\p{N}\s\-]+/u', '', html_entity_decode($siteTitle));
122 + return trim(preg_replace(
123 + '/[^\p{L}\p{N}\s\-]+/u',
124 + '',
125 + html_entity_decode($siteTitle, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401)
126 + ));
113 127 }
114 128
115 129 /**
116 130 * Check if the site Title is part of the blocked list.