PluginProbe
Image Optimization – Compress Images and Convert to WebP or AVIF / 1.6.6
Image Optimization – Compress Images and Convert to WebP or AVIF v1.6.6
1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 All 32 releases
image-optimization / modules / connect / classes / utils.php

utils.php in Image Optimization – Compress Images and Convert to WebP or AVIF 1.6.6, at modules/connect/classes/utils.php

129 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImageOptimization\Modules\Connect\Classes;
4
5 use ImageOptimization\Modules\Connect\Classes\Exceptions\Service_Exception;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly
9 }
10
11 /**
12 * Class Utils
13 */
14 class Utils {
15 /**
16 * get_clients_url
17 * @return string
18 */
19 public static function get_clients_url(): string {
20 return self::get_base_url() . '/api/v1/clients';
21 }
22
23 /**
24 * get_redirect_uri
25 * @return string
26 */
27 public static function get_redirect_uri( string $domain = '' ): string {
28 if ( false !== strpos( Config::ADMIN_PAGE, '?page=' ) ) {
29 $admin_url = admin_url( Config::ADMIN_PAGE );
30 } else {
31 $admin_url = admin_url( 'options-general.php?page=' . Config::ADMIN_PAGE );
32 }
33
34 if ( $domain ) {
35 $parsed_url = parse_url( $admin_url );
36 $path = $parsed_url['path'] . ( isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '' );
37
38 return rtrim( $domain, '/' ) . $path;
39 }
40
41 return $admin_url;
42 }
43
44 public static function get_auth_url(): string {
45 return self::get_base_url() . '/v1/oauth2/auth';
46 }
47
48 /**
49 * Get full authorization URL with all required parameters
50 *
51 * @param string $client_id
52 *
53 * @return string
54 * @throws Service_Exception
55 */
56 public static function get_authorize_url( string $client_id ): string {
57 return add_query_arg( [
58 'client_id' => $client_id,
59 'redirect_uri' => rawurlencode( self::get_redirect_uri() ),
60 'response_type' => 'code',
61 'scope' => Config::SCOPES,
62 'state' => wp_create_nonce( Config::STATE_NONCE ),
63 ], self::get_auth_url() );
64 }
65
66 /**
67 * get_deactivation_url
68 * @param string $client_id
69 *
70 * @return string
71 */
72 public static function get_deactivation_url( string $client_id ): string {
73 return self::get_base_url() . "/api/v1/clients/{$client_id}/activation";
74 }
75
76 public static function get_jwks_url(): string {
77 return self::get_base_url() . '/v1/.well-known/jwks.json';
78 }
79
80 /**
81 * get_sessions_url
82 * @return string
83 */
84 public static function get_sessions_url(): string {
85 return self::get_base_url() . '/api/v1/session';
86 }
87
88 public static function get_token_url(): string {
89 return self::get_base_url() . '/api/v1/oauth2/token';
90 }
91
92 /**
93 * Get clients URL
94 *
95 * @param string $client_id
96 *
97 * @return string
98 */
99 public static function get_clients_patch_url( string $client_id ): string {
100 return self::get_base_url() . "/api/v1/clients/{$client_id}";
101 }
102
103 /**
104 * get_base_url
105 * @return string
106 */
107 public static function get_base_url(): string {
108 return apply_filters( 'image_optimizer_connect_get_base_url', Config::BASE_URL );
109 }
110
111 /**
112 * is_valid_home_url
113 * @return bool
114 */
115 public static function is_valid_home_url(): bool {
116 static $valid = null;
117
118 if ( null === $valid ) {
119 if ( empty( Data::get_home_url() ) ) {
120 $valid = true;
121 } else {
122 $valid = Data::get_home_url() === home_url();
123 }
124 }
125
126 return $valid;
127 }
128 }
129