mirror of
https://gh.wpcy.net/https://github.com/elementor/one-click-accessibility.git
synced 2026-04-21 07:09:20 +08:00
* PHPCS and remediation POC WIP * WIP Wizard module * Added scanner module * [APP-929][APP-930] Add initial setup for wizard, added btn to the topbar (#230) * [APP-929][APP-930] * [APP-929][APP-930] * update logic * update init app * [APP-0000] store plan scope after register/switch * change return of load * add header * Move into shadow dom, add context, add headers components * add UI components * add UI components * add UI components * merge current develop * merge current develop * Add AltText Form * Add scroll to current element * Align with current design, add loader, added preview for svg * Align with current design, add loader, added preview for svg * Resolve comments * Resolve comments * Resolve comments * [APP-934] add submit logic (#259) * [APP-934] add submit logic * [APP-934] add submit logic * [APP-934] add submit logic * [APP-934] add submit logic * Added replace remediation action * Add submit logic * Add submit alt text logic, generate AI alt text * Add AI generate request, add convert from SVG to png base64, added manual fix block * Add AI generate request, add convert from SVG to png base64, added manual fix block * Add texts, add remediation submit, fix logic to store remediation * Add texts, add remediation submit, fix logic to store remediation * Add texts, add remediation submit, fix logic to store remediation * Add texts, add remediation submit, fix logic to store remediation * Add texts, add remediation submit, fix logic to store remediation * Add texts, add remediation submit, fix logic to store remediation --------- Co-authored-by: Raz Ohad <admin@bainternet.info> * Add texts, add remediation submit, fix logic to store remediation * [APP-0000] add store request to the Service API (#268) * [APP-0000] add store request to the Service API * [APP-0000] add store request to the Service API * [APP-0000] add store request to the Service API * [APP-0000] add store request to the Service API * [APP-0000] add request to store scanner summary * [APP-0000] add request to store scanner summary * [APP-0000] add request to store scanner summary * [APP-1432] fix with AI flow (#275) * [APP-1432] fix with AI flow * [APP-1432] fix with AI flow * [APP-1432] fix with AI flow * [APP-1432] fix with AI flow * [APP-1432] fix with AI flow * [APP-1432] fix with AI flow * [APP-1432] fix with AI flow * [APP-1432] fix with AI flow * [APP-1432] fix with AI flow * [APP-1432] fix with AI flow * [APP-1432] fix with AI flow * [APP-1446] sidebar menu update (#276) * update: simplify menu * add: headings and scanner menu options * [APP-945] add column for tables (#282) * [APP-945] add column for tables * [APP-945] add column for tables * [APP-945] add column for tables * [APP-945] add column for tables * [APP-1447] Updated quota bar designs (#278) * update: quota bar designs * fix: the popover was partially visible * update: AI credits name * update: usage calculation logic * add: quota indicators * update: quotas tooltip text * update: quotas notices text * update: make toggle icon dynamic * fix: @elementor/ui imports * Update modules/settings/assets/js/layouts/quota-bar.js Co-authored-by: VasylD <vasyld@elementor.red> * update: styling of component --------- Co-authored-by: VasylD <vasyld@elementor.red> * [APP-1507] add UI changes (#286) * [APP-1507] add UI changes * [APP-1507] add UI changes * [APP-1507] add UI changes * [APP-1507] add UI changes * [APP-1507] add UI changes * [APP-1507] add UI changes * [APP-1507] add UI changes * [APP-1387] add mixpanel events (#288) * [APP-1387] add mixpanel events * [APP-1387] add mixpanel events * New: Add the a11y assistant dashboard's UI [APP-1445] (#289) * [APP-1513] add disconnected msg (#290) * [APP-1513] add disconnected msg * [APP-1513] add disconnected msg * [APP-1513] add disconnected msg * [APP-1547][APP-1548][APP-948] update alt text view, fix list issues (#291) * [APP-1547][APP-1548][APP-948] update alt text view, fix list issues, add rest route for update status * [APP-1547][APP-1548][APP-948] update alt text view, fix list issues, add rest route for update status * fix: infotip icon padding and font style (#293) * fix: infotip icon padding and font style * fix: infotip icon padding and font style * update: caniuse database * [APP-1525] add edit mode (#294) * [APP-1525] add edit mode * [APP-1525] add edit mode * [APP-1525] add edit mode * Bug/app 1544 (#295) * Fix: Resolve QA comments [APP-1544] * New: Add beta tags [APP-1555] * New: Add the "no results" state [APP-1544] * [APP-1554] rename violations (#297) * [APP-1512] add backend logic for remediation management (#298) * [APP-1512] add backend logic for remediation management * [APP-1512] add backend logic for remediation management * Update modules/remediation/database/remediation-entry.php Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com> * Update modules/remediation/rest/items.php Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com> * [APP-1512] add backend logic for remediation management --------- Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com> * Fix: Resolve QA comments [n/a] (#299) * [APP-1512] add FE remediation management (#300) * [APP-1512] add backend logic for remediation management * [APP-1512] add backend logic for remediation management * Update modules/remediation/database/remediation-entry.php Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com> * Update modules/remediation/rest/items.php Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com> * [APP-1512] add backend logic for remediation management * [APP-1512] add FE remediation management * [APP-1512] add FE remediation management * [APP-1512] add FE remediation management * [APP-1512] add FE remediation management * [APP-1512] add FE remediation management * [APP-1512] add FE remediation management * [APP-1512] add FE remediation management * [APP-1512] add FE remediation management --------- Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com> * [APP-1609] fix tooltip * [APP-1609] fix resolved btn click * [APP-1401] clear cache on update (#302) * [APP-1401] clear cache on update * [APP-1401] clear cache on update * [APP-1401] clear cache on update * [APP-1401] clear cache on update * [APP-1401] clear cache on update * update with latest develop branch * fix copies * [APP-1619] add mixpanel event (#303) * [APP-1619] add mixpanel event * [APP-1619] add mixpanel event * [APP-1593] Add locked variant for quota bar (#301) * update: add locked version of quota status bar * fix: text color for infotip * fix: width issues * fix: add check for 0 * [APP-1637][APP-1643] add UI fixes, add excluded rules array (#307) * fix: make sidebar collapsible (#306) * Merge current dev * [APP-1603] Add dashboard menu (#309) * [APP-1603] Add dashboard menu * [APP-1603] Add dashboard menu * [APP-1603] Add dashboard menu * [APP-1603] Add dashboard menu * Bug/app 1607 (#311) * Fix: Update stats calculation logic [APP-1607] * Fix: Set fixed width for the results table [APP-1650] * Fix: Update filter rules [APP-1634] * New: Add the no search results state [APP-1651] * Fix: Convert indents [n/a] * [APP-1670] add menu on Manage Fixes (#315) * [APP-1670] add menu on Manage Fixes * [APP-1670] update menu * [APP-1611] fix comments * fix: direction of snippet (#313) * [APP-1561] New menu layout (#308) * update: app menu and layout * merge: latest changes from feature/remediation * add: alert indicator to the closed sidebar * fix: page layout for statement page * update: menu display names * fix: topbar menu layout * update: sidebar menu width * update: sidebar menu width * fix: popup menu layout * add: hover action to the toggle button * update: my account menu * fix: quota indicator for closed sidebar * fix: icon alignments * fix: scroll behaviour * fix: page scroll behaviour * fix: popup menu hover state * update: quota bar and group layouts * add: tooltips to the menu items * update: make scans page fixed height and scrollable * update: styles with theme references and added new styled components * fix: make sidebar smoother * update: accessibility page heading * Merge latest develop * [APP-1611] trigger save entry for clean cache (#314) * [APP-1611] trigger save entry for clean cache * [APP-1611] fix comments * [APP-1611] fix comments * [APP-1611] fix comments * [APP-1611] fix comments * [APP-0000] call trigger save async (#319) * [APP-1611] trigger save entry for clean cache * [APP-1611] fix comments * [APP-1611] fix comments * [APP-1611] fix comments * [APP-1611] fix comments * [APP-0000] call trigger save async * fix: scrollbar issues (#318) * [APP-1615] add remediation for wp image (#321) * POC - FrontEnd remediations to handle Dynamic Data [APP-1644] (#312) * POC - FrontEnd remediations to handle Dynamic Data * Update modules/remediation/components/remediation-runner.php Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com> * added MutationObserver to cover elements that are added later on the page runs until remediations are all done, and disconnect * added $use_frontend flag instead of using "false" * Update modules/remediation/components/remediation-runner.php Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com> * WIP on poc/fe-remediations * [APP-0000] call trigger save async * [APP-1644] apply FE remediation * [APP-1644] apply FE remediation * [APP-1644] apply FE remediation * Add timeout (wait for FE remediation timeout) * Add timeout (wait for FE remediation timeout) * Add timeout (wait for FE remediation timeout) * Add timeout (wait for FE remediation timeout) * Add timeout (wait for FE remediation timeout) * Small fixes * Small fixes * Small fixes * Small fixes --------- Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com> Co-authored-by: vasyldinets <vasyld@elementor.red> * [APP-1611] Fix cache issue (#324) * [APP-1611] trigger save entry for clean cache * [APP-1611] fix comments * [APP-1611] fix comments * [APP-1611] fix comments * [APP-1611] fix comments * [APP-0000] call trigger save async * [APP-1611] clear cache * [APP-1657] upgrade cta (#323) * update: added logic to show button based on plan * Update modules/settings/assets/js/components/quota-bar/quota-bar-group.js Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com> * fix: eslint error --------- Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com> * [APP-1658] Update accessibility admin column design (#322) * update: wpadmin column layout * update: move icon to assets * Fix: Resolve remediation encoding issue [APP-1646] (#325) --------- Co-authored-by: Ohad <ohad@elementor.com> Co-authored-by: Raz Ohad <admin@bainternet.info> Co-authored-by: Nirbhay Singh <121793120+nirbhayel@users.noreply.github.com> Co-authored-by: Pavlo Kniazevych <139438463+pkniazevych@users.noreply.github.com> Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>
357 lines
8.7 KiB
PHP
357 lines
8.7 KiB
PHP
<?php
|
|
|
|
namespace EA11y\Modules\Connect\Classes;
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit; // Exit if accessed directly
|
|
}
|
|
|
|
/**
|
|
* Class Data
|
|
*/
|
|
class Data {
|
|
const CLIENT_ID = '_client_id';
|
|
const CLIENT_SECRET = '_client_secret';
|
|
const ACCESS_TOKEN = '_access_token';
|
|
const REFRESH_TOKEN = '_refresh_token';
|
|
const TOKEN_ID = '_token_id';
|
|
const SUBSCRIPTION_ID = '_subscription_id';
|
|
const OPTION_OWNER_USER_ID = '_owner_user_id';
|
|
const HOME_URL = '_home_url';
|
|
|
|
/**
|
|
* get_option
|
|
* @param $option_name
|
|
* @param $default
|
|
*
|
|
* @return false|mixed|null
|
|
*/
|
|
public static function get_option( $option_name, $default ) {
|
|
return get_option( Config::APP_PREFIX . $option_name, $default );
|
|
}
|
|
|
|
/**
|
|
* set_option
|
|
* @param $option_name
|
|
* @param $option_value
|
|
* @param bool $auto_load
|
|
*
|
|
* @return bool
|
|
*/
|
|
public static function set_option( $option_name, $option_value, $auto_load = false ) : bool {
|
|
return update_option( Config::APP_PREFIX . $option_name, $option_value, $auto_load );
|
|
}
|
|
|
|
/**
|
|
* delete_option
|
|
* @param $option_name
|
|
*
|
|
* @return bool
|
|
*/
|
|
public static function delete_option( $option_name ) : bool {
|
|
return delete_option( Config::APP_PREFIX . $option_name );
|
|
}
|
|
|
|
/**
|
|
* get_user_data
|
|
* @param $user_id
|
|
* @param $data_name
|
|
* @param mixed|bool $default
|
|
*
|
|
* @return false|mixed
|
|
*/
|
|
public static function get_user_data( $user_id, $data_name, $default = false ) {
|
|
$data = get_user_meta( $user_id, Config::APP_PREFIX . $data_name, true );
|
|
|
|
return empty( $data ) ? $default : $data;
|
|
}
|
|
|
|
/**
|
|
* set_user_data
|
|
* @param $user_id
|
|
* @param $data_name
|
|
* @param $value
|
|
*
|
|
* @return bool|int
|
|
*/
|
|
public static function set_user_data( $user_id, $data_name, $value ) {
|
|
return update_user_meta( $user_id, Config::APP_PREFIX . $data_name, $value );
|
|
}
|
|
|
|
/**
|
|
* delete_user_data
|
|
* @param $user_id
|
|
* @param $data_name
|
|
*
|
|
* @return bool
|
|
*/
|
|
public static function delete_user_data( $user_id, $data_name ) : bool {
|
|
return delete_user_meta( $user_id, Config::APP_PREFIX . $data_name );
|
|
}
|
|
|
|
/**
|
|
* get_connect_mode_data
|
|
* @param ...$data
|
|
*
|
|
* @return false|mixed|null|string
|
|
*/
|
|
public static function get_connect_mode_data( ...$data ) {
|
|
if ( Config::CONNECT_MODE === 'site' ) {
|
|
return self::get_option( ...$data );
|
|
}
|
|
$user_id = get_current_user_id();
|
|
return self::get_user_data( ...( [ $user_id, ...$data ] ) );
|
|
}
|
|
|
|
/**
|
|
* set_connect_mode_data
|
|
* @param ...$data
|
|
*
|
|
* @return bool|int
|
|
*/
|
|
public static function set_connect_mode_data( ...$data ) {
|
|
if ( Config::CONNECT_MODE === 'site' ) {
|
|
return self::set_option( ...$data );
|
|
}
|
|
$user_id = get_current_user_id();
|
|
return self::set_user_data( ...( [ $user_id, ...$data ] ) );
|
|
}
|
|
|
|
/**
|
|
* get_client_id
|
|
*
|
|
* @return string|bool|mixed
|
|
*/
|
|
public static function get_client_id() {
|
|
return self::get_connect_mode_data( self::CLIENT_ID, false );
|
|
}
|
|
|
|
/**
|
|
* get_client_secret
|
|
* @return false|mixed|string|null
|
|
*/
|
|
public static function get_client_secret() {
|
|
return self::get_connect_mode_data( self::CLIENT_SECRET, false );
|
|
}
|
|
|
|
/**
|
|
* set_client_id
|
|
* @param $value
|
|
*
|
|
* @return bool
|
|
*/
|
|
public static function set_client_id( $value ) : bool {
|
|
return self::set_connect_mode_data( self::CLIENT_ID, $value );
|
|
}
|
|
|
|
public static function get_subscription_id() {
|
|
return self::get_connect_mode_data( self::SUBSCRIPTION_ID, false );
|
|
}
|
|
|
|
public static function set_subscription_id( $value ) : bool {
|
|
return self::set_connect_mode_data( self::SUBSCRIPTION_ID, $value );
|
|
}
|
|
|
|
/**
|
|
* set_client_secret
|
|
* @param $value
|
|
*
|
|
* @return bool
|
|
*/
|
|
public static function set_client_secret( $value ) : bool {
|
|
return self::set_connect_mode_data( self::CLIENT_SECRET, $value );
|
|
}
|
|
|
|
/**
|
|
* get_access_token
|
|
* @return false|mixed|string|null
|
|
*/
|
|
public static function get_access_token() {
|
|
return self::get_connect_mode_data( self::ACCESS_TOKEN, false );
|
|
}
|
|
|
|
public static function get_token_id() {
|
|
return self::get_connect_mode_data( self::TOKEN_ID, false );
|
|
}
|
|
|
|
/**
|
|
* get_refresh_token
|
|
* @return false|mixed|string|null
|
|
*/
|
|
public static function get_refresh_token() {
|
|
return self::get_connect_mode_data( self::REFRESH_TOKEN, false );
|
|
}
|
|
|
|
/**
|
|
* get_home_url
|
|
*
|
|
* Return a plain text version of a based64 encoded home URL if it's stored as base64 encoded
|
|
* @return string|null
|
|
*/
|
|
public static function get_home_url() {
|
|
$raw = self::get_connect_mode_data( self::HOME_URL, false );
|
|
$is_base64 = base64_encode( base64_decode( $raw, true ) ) === $raw;
|
|
return $is_base64 ? base64_decode( $raw ) : $raw;
|
|
}
|
|
|
|
/**
|
|
* set_home_url
|
|
*
|
|
* Stores home URL as a base64 string to avoid migration/stg tools from overriding value
|
|
*/
|
|
public static function set_home_url( ?string $home_url = null ) : bool {
|
|
$home_url = $home_url ?? home_url();
|
|
return self::set_connect_mode_data( self::HOME_URL, base64_encode( $home_url ) );
|
|
}
|
|
|
|
/**
|
|
* set_user_is_owner_option
|
|
*/
|
|
public static function set_user_is_owner_option( $value ) {
|
|
return self::set_connect_mode_data( self::OPTION_OWNER_USER_ID, $value );
|
|
}
|
|
|
|
/**
|
|
* get_user_is_owner_option
|
|
*/
|
|
public static function get_user_is_owner_option() {
|
|
return self::get_connect_mode_data( self::OPTION_OWNER_USER_ID, false );
|
|
}
|
|
|
|
/**
|
|
* fetch_option
|
|
* direct query to avoid cache and race condition issues
|
|
*
|
|
* @param $option_name
|
|
* @param $default
|
|
*
|
|
* @return mixed|null
|
|
*/
|
|
public static function fetch_option( $option_name, $default = null ) {
|
|
global $wpdb;
|
|
if ( ! self::is_option_whitelisted_for_direct_access( $option_name ) ) {
|
|
return $default;
|
|
}
|
|
|
|
$cache_buster = wp_generate_uuid4();
|
|
$option = $wpdb->get_col(
|
|
$wpdb->prepare(
|
|
"SELECT option_value
|
|
FROM $wpdb->options
|
|
WHERE option_name = %s
|
|
AND %s = %s
|
|
LIMIT 1",
|
|
$option_name,
|
|
$cache_buster,
|
|
$cache_buster
|
|
)
|
|
);
|
|
if ( ! empty( $option ) ) {
|
|
return $option[0];
|
|
}
|
|
return $default;
|
|
}
|
|
|
|
/**
|
|
* insert_option_uniquely
|
|
*
|
|
* used to insert option if not there already
|
|
* direct query to avoid cache and race condition issues
|
|
*
|
|
* @param $option_name
|
|
* @param $option_value
|
|
*
|
|
* @return bool
|
|
*/
|
|
public static function insert_option_uniquely( $option_name, $option_value ) : bool {
|
|
global $wpdb;
|
|
if ( ! self::is_option_whitelisted_for_direct_access( $option_name ) ) {
|
|
return false;
|
|
}
|
|
$cache_buster = wp_generate_uuid4();
|
|
$result = $wpdb->query(
|
|
$wpdb->prepare(
|
|
"INSERT INTO $wpdb->options (option_name, option_value, autoload)
|
|
SELECT * FROM (SELECT %s, %s, 'no') AS tmp
|
|
WHERE NOT EXISTS (
|
|
SELECT option_name
|
|
FROM $wpdb->options
|
|
WHERE option_name = %s
|
|
AND option_value = %s
|
|
AND %s = %s
|
|
) LIMIT 1",
|
|
$option_name,
|
|
$option_value,
|
|
$option_name,
|
|
$option_value,
|
|
$cache_buster,
|
|
$cache_buster
|
|
)
|
|
);
|
|
|
|
if ( false === $result || 0 === $result ) {
|
|
// false means query failed, 0 means no row inserted because it exists
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* is_option_whitelisted_for_direct_access
|
|
* allowed only list of option names
|
|
*
|
|
* @param string $option_name
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public static function is_option_whitelisted_for_direct_access( string $option_name ) : bool {
|
|
$options_whitelist = [
|
|
Config::APP_NAME . Service::REFRESH_TOKEN_LOCK,
|
|
];
|
|
return in_array( $option_name, $options_whitelist, true );
|
|
}
|
|
|
|
/**
|
|
* User is subscription owner.
|
|
*
|
|
* Check if current user is subscription owner.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public static function user_is_subscription_owner(): bool {
|
|
$owner_id = (int) self::get_connect_mode_data( self::OPTION_OWNER_USER_ID, false );
|
|
|
|
return get_current_user_id() === $owner_id;
|
|
}
|
|
|
|
/**
|
|
* clear_session
|
|
*/
|
|
public static function clear_session( $with_client = false ) {
|
|
if ( Config::CONNECT_MODE === 'site' ) {
|
|
if ( $with_client ) {
|
|
self::delete_option( self::CLIENT_ID );
|
|
self::delete_option( self::CLIENT_SECRET );
|
|
}
|
|
self::delete_option( self::ACCESS_TOKEN );
|
|
self::delete_option( self::REFRESH_TOKEN );
|
|
self::delete_option( self::TOKEN_ID );
|
|
self::delete_option( self::SUBSCRIPTION_ID );
|
|
self::delete_option( self::OPTION_OWNER_USER_ID );
|
|
self::delete_option( self::HOME_URL );
|
|
} else {
|
|
$user_id = get_current_user_id();
|
|
if ( $with_client ) {
|
|
self::delete_user_data( $user_id, self::CLIENT_ID );
|
|
self::delete_user_data( $user_id, self::CLIENT_SECRET );
|
|
}
|
|
self::delete_user_data( $user_id, self::ACCESS_TOKEN );
|
|
self::delete_user_data( $user_id, self::REFRESH_TOKEN );
|
|
self::delete_user_data( $user_id, self::TOKEN_ID );
|
|
self::delete_user_data( $user_id, self::SUBSCRIPTION_ID );
|
|
self::delete_user_data( $user_id, self::OPTION_OWNER_USER_ID );
|
|
self::delete_user_data( $user_id, self::HOME_URL );
|
|
}
|
|
}
|
|
}
|