PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.2.7
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.2.7
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
← All changes | includes/Utils/Http.php +20 -89 3.6.53.2.7 View file →
@@ -31,9 +31,9 @@
31 31 /**
32 32 * Setting the development mode.
33 33 */
34 34 public function __construct() {
35 - $this->dev_mode = Helper::is_dev_api();
35 + $this->dev_mode = defined( 'TEMPLATELY_DEV' ) && TEMPLATELY_DEV;
36 36 }
37 37
38 38 /**
39 39 * Determining the endpoint URL based on the mode.
@@ -40,68 +40,27 @@
40 40 *
41 41 * @return string
42 42 */
43 43 public function url() {
44 - if ( Helper::is_dev_api() ) {
44 + if ( $this->dev_mode ) {
45 45 $this->url = 'https://app.templately.dev/api/plugin';
46 46 }
47 -
48 - /**
49 - * Filter the API endpoint URL
50 - *
51 - * @since 3.5.0
52 - * @param string $url The endpoint URL
53 - */
54 - $this->url = apply_filters('templately_dev_api_endpoint_url', $this->url);
55 -
56 47 return $this->url;
57 48 }
58 49
59 50 /**
60 - * Generate Google OAuth authentication URL
61 - *
62 - * @param string $redirect_to Optional redirect path after authentication
63 - * @return string The Google auth URL with query parameters
64 - */
65 -public function google_auth_url($redirect_to = '', $current_url = '') {
66 - $base_url = $this->url();
67 - // Replace /api/plugin with /api/auth/plugin/google
68 - $auth_url = str_replace('/api/plugin', '/api/auth/plugin/google', $base_url);
69 -
70 - // Get the referer to return to the exact same page we initiated login from securely
71 - if ( ! empty( $current_url ) ) {
72 - $referer = esc_url_raw( $current_url );
73 - } else {
74 - $referer = isset( $_SERVER['HTTP_REFERER'] ) ? esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '';
51 + * Preparing query arguments.
52 + * Unknown.
53 + *
54 + * @return string
55 + */
56 + public static function prepare( $query, ...$args ) {
57 + return sprintf( $query, ...$args );
75 58 }
76 59
77 - $return_url = wp_validate_redirect( $referer, '' );
78 -
79 - if ( empty( $return_url ) ) {
80 - $return_url = admin_url( 'admin.php?page=templately' );
81 - }
82 -
83 - $return_params = [
84 - 'templately_google_login' => '1',
85 - ];
86 -
87 - // Add redirect-to parameter if provided
88 - if (!empty($redirect_to)) {
89 - $return_params['redirect-to'] = $redirect_to;
90 - }
91 -
92 - $site_url_with_params = add_query_arg($return_params, $return_url);
93 -
94 - $query_params = [
95 - 'site_url' => urlencode($site_url_with_params),
96 - 'site_ip' => Helper::get_ip(),
97 - 'state' => wp_generate_password(32, false) // Add unique random state for cache busting
98 - ];
99 -
100 - return add_query_arg($query_params, $auth_url);
101 -}
102 -
103 -/**
60 + /**
61 + * Preparing query arguments
62 + *
104 63 * @param array $args
105 64 * @return string
106 65 */
107 66 protected function prepareArgs( $args ) {
@@ -113,9 +72,9 @@
113 72 case is_string( $value ) && ( $value === 'true' || $value === 'false' ):
114 73 $prepareArgs .= "$key:" . $value . ",";
115 74 break;
116 75 default:
117 - $prepareArgs .= "$key:" . '"' . Helper::esc_json_string( $value ) . '"' . ",";
76 + $prepareArgs .= "$key:" . '"' . $value . '"' . ",";
118 77 break;
119 78 }
120 79 }
121 80
@@ -196,9 +155,9 @@
196 155 Helper::log( 'QUERY: ' . $query );
197 156 }
198 157
199 158 $_default_args = [
200 - 'timeout' => $this->dev_mode ? 120 : 30,
159 + 'timeout' => $this->dev_mode ? 40 : 30,
201 160 'headers' => $headers,
202 161 'body' => wp_json_encode( [
203 162 'query' => $query
204 163 ] )
@@ -213,11 +172,11 @@
213 172 } while ( is_wp_error( $response ) && $retryCount < $maxRetries );
214 173
215 174 if ( defined( 'TEMPLATELY_DEBUG_LOG' ) && TEMPLATELY_DEBUG_LOG ) {
216 175 Helper::log( 'Retry Count: ' . $retryCount );
217 - // Helper::log( 'RAW RESPONSE: ' );
218 - // Helper::log( $response );
219 - // Helper::log( 'END RAW RESPONSE' );
176 + Helper::log( 'RAW RESPONSE: ' );
177 + Helper::log( $response );
178 + Helper::log( 'END RAW RESPONSE' );
220 179 }
221 180
222 181 return $this->maybeErrors( $response, $args );
223 182 }
@@ -222,9 +181,9 @@
222 181 return $this->maybeErrors( $response, $args );
223 182 }
224 183
225 184 /**
226 - * Formatting the self::post() response
185 + * Formating the self::post() response
227 186 *
228 187 * @param mixed $response
229 188 * @param array $args
230 189 * @return mixed
@@ -233,17 +192,13 @@
233 192 if ( $response instanceof WP_Error ) {
234 193 return $response; // Return WP_Error, if it is an error.
235 194 }
236 195
237 - // Check for verification header before processing response body
238 - Helper::check_verification_header( $response );
239 - Helper::check_site_disconnection( $response );
240 -
241 196 $response_code = wp_remote_retrieve_response_code( $response );
242 197 $response_message = wp_remote_retrieve_response_message( $response );
243 198
244 199 /**
245 - * Retrieve Data from Response Body.
200 + * Retrive Data from Response Body.
246 201 */
247 202 $response = json_decode( wp_remote_retrieve_body( $response ), true );
248 203 /**
249 204 * If the graphql hit with any error.
@@ -266,16 +221,12 @@
266 221 } );
267 222 }
268 223 } );
269 224 } else {
270 - $error_data = [];
271 - if(!empty($error["extensions"]["statusText"])) {
272 - $error_data["statusText"] = $error["extensions"]["statusText"];
273 - }
274 225 if ( isset( $error['debugMessage'] ) ) {
275 226 $wp_error->add( 'templately_graphql_error', $error['debugMessage'] );
276 227 } else {
277 - $wp_error->add( 'templately_graphql_error', $error['message'], $error_data );
228 + $wp_error->add( 'templately_graphql_error', $error['message'] );
278 229 }
279 230 }
280 231 }
281 232 } );
@@ -293,31 +244,11 @@
293 244 }
294 245
295 246 return $wp_error;
296 247 }
297 - } elseif ( ! empty( $response['status'] ) && $response['status'] === 'error' ) {
298 -
299 - if ( defined( 'TEMPLATELY_DEBUG_LOG' ) && TEMPLATELY_DEBUG_LOG ) {
300 - Helper::log( 'ERROR: ' );
301 - Helper::log( $response );
302 - Helper::log( 'END ERROR' );
303 - }
304 -
305 - $error_data = [];
306 - if ( ! empty( $response['statusText'] ) ) {
307 - $error_data['statusText'] = $response['statusText'];
308 - }
309 -
310 - $error_message = ! empty( $response['message'] ) ? $response['message'] : __( 'Unknown error occurred', 'templately' );
311 -
312 - return new WP_Error( 'templately_api_error', $error_message, $error_data );
313 248 }
314 249
315 250 $_response = isset( $response['data'][$this->endpoint] ) ? $response['data'][$this->endpoint] : [];
316 - // {"data":{"connectWithApiKey":{"status":"error","message":"Invalid API key.","user":null}}}
317 - if ( ! empty( $response['status'] ) && $response['status'] === 'error' ) {
318 -
319 - }
320 251
321 252 if ( defined( 'TEMPLATELY_DEBUG_LOG' ) && TEMPLATELY_DEBUG_LOG ) {
322 253 Helper::log( 'RESPONSE: ' );
323 254 Helper::log( $_response );