PluginProbe ʕ •ᴥ•ʔ
Atarim – AI Agency for WordPress: Edit Pages, Fix Code, Update Plugins, SEO & Client Feedback / 5.1.2
Atarim – AI Agency for WordPress: Edit Pages, Fix Code, Update Plugins, SEO & Client Feedback v5.1.2
5.1.3 5.1.2 5.1.1 5.1 5.0 trunk 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 3.2.0 3.2.1 3.22 3.22.1 3.22.2 3.22.3 3.22.4 3.22.5 3.22.6 3.3.0 3.3.1 3.3.2 3.3.2.1 3.3.2.2 3.3.3 3.30 3.31 3.32 3.4 3.4.1 3.4.3 3.4.4 3.5 3.5.1 3.6 3.6.1 3.7 3.8 3.9 3.9.1 3.9.2 3.9.3 3.9.4 3.9.6 3.9.6.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.2 4.2.1 4.2.2 4.3 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.4
atarim-visual-collaboration / includes / inject-script.php
atarim-visual-collaboration / includes Last commit date
class-ajax-functions.php 2 weeks ago class-define-constant.php 2 weeks ago class-functions.php 2 weeks ago do-it.php 2 weeks ago inject-script.php 2 weeks ago
inject-script.php
280 lines
1 <?php
2 if (! defined('ABSPATH')) {
3 exit; // Exit if accessed directly
4 }
5
6 class AVCF_Inject_Script {
7 private $function;
8 private $license;
9 private $is_collab_active;
10 private $inisetup;
11
12 public function __construct() {
13 $this->function = new AVCF_Functions();
14 $this->license = $this->function->avcf_get_setting_data('avc_license');
15 $this->is_collab_active = $this->function->avcf_get_setting_data('avc_collab_active');
16 $this->inisetup = $this->function->avcf_get_setting_data('avc_initial_setup_complete');
17
18 // Initialize hooks
19 $this->init_hooks();
20 }
21
22 private function init_hooks() {
23 // Load collaboration script
24 add_action('wp_head', [$this, 'load_collaboration_script'], 11);
25 add_action('admin_head', [$this, 'load_collaboration_script'], 11);
26
27
28 // Load global styles and scripts
29 add_action('wp_enqueue_scripts', [$this, 'enqueue_global_assets']);
30 add_action('admin_enqueue_scripts', [$this, 'enqueue_global_assets']);
31
32 // Load footer scripts
33 add_action('wp_footer', [$this, 'load_footer_script']);
34 add_action('admin_footer', [$this, 'load_footer_script']);
35
36 // Auto login
37 add_action('init', array($this, 'avcf_autologin'));
38 //add_action('init', array($this, 'avcf_accept_invitation'));
39 }
40
41 public function load_collaboration_script() {
42 if (isset($_GET['site_id']) && ! empty($_GET['site_id'])) {
43 return;
44 }
45
46 $site_id = $this->function->avcf_get_setting_data('avc_site_id');
47 if (isset($_GET['activation_callback']) && ! empty($_GET['activation_callback'])) {
48 $site_id = '';
49 }
50
51 $user_id = $this->function->avcf_get_user_detail('id');
52 if (is_wp_error($user_id)) {
53 $user_id = 0;
54 }
55
56 $is_webmaster = $user_id ? (get_user_meta($user_id, 'avc_user_type', true) === 'webmaster') : false;
57 $has_consented = $user_id ? (bool) get_user_meta($user_id, 'avc_consent_status', true) : false;
58
59 $allow_collab = false;
60 if (! is_user_logged_in()) {
61 $allow_collab = $this->function->avcf_is_site_public($site_id);
62 }
63
64 if (isset($_GET['collab'])) {
65 $allow_collab = filter_var($_GET['collab'], FILTER_VALIDATE_BOOLEAN);
66 }
67
68 $is_setting_screen = $this->function->avcf_setting_screen();
69
70 if (
71 ! $allow_collab && (
72 $this->license !== 'valid' ||
73 $this->is_collab_active !== 'yes' ||
74 $this->inisetup !== 'yes' ||
75 ! is_user_logged_in() ||
76 ! $this->function->avcf_allowed_user_role() ||
77 (! $is_webmaster && ! $has_consented) ||
78 $site_id == ''
79 )
80 ) {
81 return;
82 }
83
84 echo $this->function->get_collab_js($site_id, $is_setting_screen);
85 }
86
87 public function enqueue_global_assets() {
88 wp_register_style(
89 'avc-global-style',
90 AVCF_PLUGIN_URL . 'assets/css/global.css',
91 [],
92 filemtime(AVCF_PLUGIN_DIR . 'assets/css/global.css')
93 );
94 wp_enqueue_style('avc-global-style');
95
96 wp_enqueue_script('jquery');
97
98 wp_register_script(
99 'avc-global-script',
100 AVCF_PLUGIN_URL . 'assets/js/global.js',
101 ['jquery'],
102 AVCF_VERSION,
103 true
104 );
105 wp_enqueue_script('avc-global-script');
106
107 wp_localize_script('avc-global-script', 'avcajax', [
108 'ajaxurl' => admin_url('admin-ajax.php')
109 ]);
110
111 $avc_nonce = wp_create_nonce('avc-script-nonce');
112 wp_localize_script('avc-global-script', 'avc_site_data', [
113 'site_url' => AVCF_HOME_URL,
114 'avc_nonce' => $avc_nonce
115 ]);
116 }
117
118 public function load_footer_script() {
119 $user_id = $this->function->avcf_get_user_detail('id');
120 if ( is_wp_error( $user_id ) ) {
121 $user_id = 0;
122 }
123
124 $is_webmaster = $user_id ? ( get_user_meta( $user_id, 'avc_user_type', true ) === 'webmaster' ) : false;
125 $has_consented = $user_id ? (bool) get_user_meta( $user_id, 'avc_consent_status', true ) : false;
126 $site_id = $this->function->avcf_get_setting_data('avc_site_id');
127
128 if (
129 $this->function->avcf_setting_screen() ||
130 $this->license !== 'valid' ||
131 $this->is_collab_active !== 'yes' ||
132 $this->inisetup !== 'yes' ||
133 ! is_user_logged_in() ||
134 ! $this->function->avcf_allowed_user_role() ||
135 $is_webmaster ||
136 $has_consented ||
137 $site_id == ''
138 ) {
139 return;
140 }
141
142 echo $this->function->avcf_user_consent_modal_trigger();
143 echo $this->function->avcf_user_consent_form();
144 }
145
146 public function avcf_autologin() {
147 if (! isset($_GET['wpf_token'])) {
148 return;
149 }
150
151 if (isset($_GET['wpf_token']) && is_user_logged_in()) {
152 return;
153 }
154
155 $webmaster = $this->function->avcf_get_setting_data('avc_website_developer');
156 if ($webmaster == '') {
157 return;
158 }
159
160 $payload = [
161 'site_id' => $this->function->avcf_get_setting_data('avc_site_id'),
162 ];
163
164 $wpf_token = sanitize_text_field(wp_unslash($_GET['wpf_token']));
165
166 $response = $this->function->avcf_make_api_call(
167 AVCF_CRM_API . 'wp-api/user/verify-access',
168 wp_json_encode($payload),
169 '',
170 $wpf_token
171 );
172
173 if (
174 $response['status_code'] === 200 &&
175 isset($response['data']['status']) &&
176 $response['data']['status'] == 1
177 ) {
178 $user = get_user_by('email', $webmaster);
179 if (! is_wp_error($user)) {
180 wp_clear_auth_cookie();
181 wp_set_current_user($user->ID);
182 wp_set_auth_cookie($user->ID);
183 $this->avcf_make_auth_cookies_embeddable();
184 }
185 }
186
187 $removeparam = array('wpf_token', 'wpf_username', 'wpf_login');
188 // Remove the params from the current request URL.
189 $newurl = remove_query_arg($removeparam);
190 // Redirect safely (same-host only).
191 wp_safe_redirect(esc_url_raw($newurl), 302);
192 exit;
193 }
194
195 /**
196 * Re-send the auth cookies WordPress just emitted with attributes that
197 * survive inside a cross-site iframe: the Atarim stage embeds the site
198 * on the app's origin, and WordPress emits its cookies without SameSite,
199 * which browsers treat as Lax and drop on embedded requests. Partitioned
200 * keeps them accepted once third-party cookies are fully phased out.
201 */
202 private function avcf_make_auth_cookies_embeddable() {
203 if (headers_sent()) {
204 return;
205 }
206
207 $cookies = array();
208 foreach (headers_list() as $header) {
209 if (stripos($header, 'Set-Cookie:') !== 0) {
210 continue;
211 }
212 $cookies[] = trim(substr($header, strlen('Set-Cookie:')));
213 }
214 if (empty($cookies)) {
215 return;
216 }
217
218 header_remove('Set-Cookie');
219 foreach ($cookies as $cookie) {
220 if (preg_match('/^wordpress_/i', $cookie)) {
221 $cookie = preg_replace('/;\s*samesite=[^;]*/i', '', $cookie);
222 if (! preg_match('/;\s*secure(;|$)/i', $cookie)) {
223 $cookie .= '; Secure';
224 }
225 $cookie .= '; SameSite=None; Partitioned';
226 }
227 header('Set-Cookie: ' . $cookie, false);
228 }
229 }
230
231 public function avcf_accept_invitation() {
232 if (
233 is_user_logged_in() ||
234 ! isset($_GET['token']) ||
235 empty($_GET['token'])
236 ) {
237 return;
238 }
239
240 $data = [
241 'token' => sanitize_text_field(wp_unslash($_GET['token']))
242 ];
243
244 $response = $this->function->avcf_make_api_call(
245 AVCF_CRM_API . 'collaborate/site/accept-invitation',
246 $data,
247 '',
248 '',
249 'GET'
250 );
251
252 if ($response['status_code'] === 200) {
253 if (
254 isset($response['data']['status']) &&
255 $response['data']['status'] == 1 &&
256 isset($response['data']['result']['access_token'])
257 ) {
258 $token = $response['data']['result']['access_token'];
259 setcookie('avc_token', $token, time() + (86400 * 30), '/');
260 } else if (
261 isset($response['data']['status']) &&
262 $response['data']['status'] == '' &&
263 isset($response['data']['data']['error'])
264 ) {
265 echo $response['data']['data']['message'];
266 die;
267 }
268 }
269
270 $removeparam = array('token', 'role');
271 // Remove the params from the current request URL.
272 $newurl = remove_query_arg($removeparam);
273 // Redirect safely (same-host only).
274 wp_safe_redirect(esc_url_raw($newurl), 302);
275 exit;
276 }
277 }
278
279 new AVCF_Inject_Script();
280