Changeset 3169735
- Timestamp:
- 10/16/2024 05:00:36 AM (17 months ago)
- Location:
- crowdaa-sync
- Files:
-
- 4 added
- 6 edited
- 41 copied
-
tags/1.10.0 (copied) (copied from crowdaa-sync/trunk)
-
tags/1.10.0/CHANGELOG (copied) (copied from crowdaa-sync/trunk/CHANGELOG) (1 diff)
-
tags/1.10.0/README.txt (copied) (copied from crowdaa-sync/trunk/README.txt) (1 diff)
-
tags/1.10.0/admin/class-crowdaa-sync-add-info-api.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-add-info-api.php)
-
tags/1.10.0/admin/class-crowdaa-sync-add-info-wp.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-add-info-wp.php)
-
tags/1.10.0/admin/class-crowdaa-sync-admin-display.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-admin-display.php) (8 diffs)
-
tags/1.10.0/admin/class-crowdaa-sync-admin.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-admin.php)
-
tags/1.10.0/admin/class-crowdaa-sync-api.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-api.php) (2 diffs)
-
tags/1.10.0/admin/class-crowdaa-sync-ext-hooks.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-ext-hooks.php)
-
tags/1.10.0/admin/class-crowdaa-sync-rest-api.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-rest-api.php)
-
tags/1.10.0/admin/class-crowdaa-sync-wp-hooks.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-wp-hooks.php)
-
tags/1.10.0/admin/css/crowdaa-sync-admin.css (copied) (copied from crowdaa-sync/trunk/admin/css/crowdaa-sync-admin.css)
-
tags/1.10.0/admin/js/crowdaa-sync-admin.js (copied) (copied from crowdaa-sync/trunk/admin/js/crowdaa-sync-admin.js)
-
tags/1.10.0/admin/partials/crowdaa-sync-admin-display.php (copied) (copied from crowdaa-sync/trunk/admin/partials/crowdaa-sync-admin-display.php) (3 diffs)
-
tags/1.10.0/crowdaa-sync.php (copied) (copied from crowdaa-sync/trunk/crowdaa-sync.php) (2 diffs)
-
tags/1.10.0/includes/class-crowdaa-sync-activator.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-activator.php)
-
tags/1.10.0/includes/class-crowdaa-sync-deactivator.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-deactivator.php)
-
tags/1.10.0/includes/class-crowdaa-sync-exception.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-exception.php)
-
tags/1.10.0/includes/class-crowdaa-sync-i18n.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-i18n.php)
-
tags/1.10.0/includes/class-crowdaa-sync-loader.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-loader.php)
-
tags/1.10.0/includes/class-crowdaa-sync-lock.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-lock.php)
-
tags/1.10.0/includes/class-crowdaa-sync-logs.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-logs.php)
-
tags/1.10.0/includes/class-crowdaa-sync-permissions.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-permissions.php)
-
tags/1.10.0/includes/class-crowdaa-sync-syncdb.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-syncdb.php)
-
tags/1.10.0/includes/class-crowdaa-sync-timer.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-timer.php)
-
tags/1.10.0/includes/class-crowdaa-sync-utils.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-utils.php)
-
tags/1.10.0/includes/class-crowdaa-sync-versions.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-versions.php)
-
tags/1.10.0/includes/class-crowdaa-sync.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync.php)
-
tags/1.10.0/languages/crowdaa-sync-fr_FR.mo (added)
-
tags/1.10.0/languages/crowdaa-sync-fr_FR.po (added)
-
tags/1.10.0/vendor/autoload.php (copied) (copied from crowdaa-sync/trunk/vendor/autoload.php)
-
tags/1.10.0/vendor/composer/ClassLoader.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/ClassLoader.php)
-
tags/1.10.0/vendor/composer/InstalledVersions.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/InstalledVersions.php)
-
tags/1.10.0/vendor/composer/LICENSE (copied) (copied from crowdaa-sync/trunk/vendor/composer/LICENSE)
-
tags/1.10.0/vendor/composer/autoload_classmap.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/autoload_classmap.php)
-
tags/1.10.0/vendor/composer/autoload_files.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/autoload_files.php)
-
tags/1.10.0/vendor/composer/autoload_namespaces.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/autoload_namespaces.php)
-
tags/1.10.0/vendor/composer/autoload_psr4.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/autoload_psr4.php)
-
tags/1.10.0/vendor/composer/autoload_real.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/autoload_real.php)
-
tags/1.10.0/vendor/composer/autoload_static.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/autoload_static.php)
-
tags/1.10.0/vendor/composer/installed.json (copied) (copied from crowdaa-sync/trunk/vendor/composer/installed.json)
-
tags/1.10.0/vendor/composer/installed.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/installed.php)
-
tags/1.10.0/vendor/composer/platform_check.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/platform_check.php)
-
trunk/CHANGELOG (modified) (1 diff)
-
trunk/README.txt (modified) (1 diff)
-
trunk/admin/class-crowdaa-sync-admin-display.php (modified) (8 diffs)
-
trunk/admin/class-crowdaa-sync-api.php (modified) (2 diffs)
-
trunk/admin/partials/crowdaa-sync-admin-display.php (modified) (3 diffs)
-
trunk/crowdaa-sync.php (modified) (2 diffs)
-
trunk/languages/crowdaa-sync-fr_FR.mo (added)
-
trunk/languages/crowdaa-sync-fr_FR.po (added)
Legend:
- Unmodified
- Added
- Removed
-
crowdaa-sync/tags/1.10.0/CHANGELOG
r3150916 r3169735 7 7 8 8 ## [Unreleased] 9 10 ## [1.10.0] - 2024-10-16 11 12 ### Changed 13 14 - Added FR translations 15 - Updated interface for easier use 9 16 10 17 ## [1.9.0] - 2024-09-10 -
crowdaa-sync/tags/1.10.0/README.txt
r3150916 r3169735 6 6 Requires PHP: 7.3 7 7 Tested up to: 5.9 8 Stable tag: 1. 9.18 Stable tag: 1.10.0 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html -
crowdaa-sync/tags/1.10.0/admin/class-crowdaa-sync-admin-display.php
r3150916 r3169735 14 14 class Crowdaa_Sync_Admin_Display 15 15 { 16 private const AUTH_API_KEY = 'nQ9ZO9DEgfaOzWY44Xu2J2uaPtP92t176PpBkdqu'; 16 17 /** 17 18 * Initialize the class and set its properties. … … 112 113 { 113 114 $pluginApiKey = Crowdaa_Sync_Utils::generate_plugin_api_key(); 115 $syncDomainNames = get_option('crowdaa_sync_domain_names'); 114 116 $api = new Crowdaa_Sync_API(); 115 117 $response = $api->http_request('POST', '/websites/crowdaa-sync/autosetup', [ 118 'action' => 'setup', 116 119 'pluginApiKey' => $pluginApiKey, 120 'wordpressApiUrl' => preg_replace('~/$~', '', get_rest_url()), 121 'defaultWordpressUrl' => get_site_url(), 122 'syncDomainNames' => explode(',', $syncDomainNames), 117 123 ]); 118 124 … … 140 146 } 141 147 148 public function on_logout_unset() 149 { 150 $pluginApiKey = Crowdaa_Sync_Utils::get_plugin_api_key(); 151 $api = new Crowdaa_Sync_API(); 152 $api->http_request('POST', '/websites/crowdaa-sync/autosetup', [ 153 'action' => 'logout', 154 'pluginApiKey' => $pluginApiKey, 155 'wordpressApiUrl' => preg_replace('~/$~', '', get_rest_url()), 156 ]); 157 } 158 142 159 /** 143 160 * Admin notices … … 152 169 153 170 Crowdaa_Sync_Logs::log('Parameters', 'connection_settings', 'Enabling connection...'); 154 update_option('crowdaa_user_id', '');155 update_option('crowdaa_auth_token', '');156 update_option('crowdaa_api_url', '');157 update_option('crowdaa_user_email', '');158 update_option('crowdaa_user_password', '');159 update_option('crowdaa_user_auth_api_key', '');160 if (isset($_POST['api_url'])) {161 update_option('crowdaa_api_url', esc_url_raw($_POST['api_url']));162 } else {163 add_action(164 'admin_notices',165 function () {166 self::admin_notice('error', __('Add API URL, please', CROWDAA_SYNC_PLUGIN_NAME));167 }168 );169 return;170 }171 171 if (isset($_POST['status']) && $_POST['status'] == 'connect') { 172 if (isset($_POST['user_auth_api_key']) && isset($_POST['user_api_key']) && isset($_POST['user_email']) && isset($_POST['user_password'])) { 172 if (isset($_POST['api_url']) && isset($_POST['user_app_id']) && isset($_POST['user_email']) && isset($_POST['user_password'])) { 173 update_option('crowdaa_api_url', esc_url_raw($_POST['api_url'])); 173 174 $user_email = sanitize_email($_POST['user_email']); 174 175 $user_password = Crowdaa_Sync_Api::sanitize_api_password($_POST['user_password']); 175 $user_ap i_key = Crowdaa_Sync_Api::sanitize_api_key($_POST['user_api_key']);176 $ user_auth_api_key = Crowdaa_Sync_Api::sanitize_api_key($_POST['user_auth_api_key']);176 $user_app_id = Crowdaa_Sync_Api::sanitize_api_key($_POST['user_app_id']); 177 $sync_domain_names = Crowdaa_Sync_Api::sanitize_sync_domain_names($_POST['sync_domain_names']); 177 178 $data = [ 178 179 'email' => $user_email, … … 182 183 $api = new Crowdaa_Sync_API(); 183 184 184 $response = $api->http_request('POST', '/auth/login', $data, ['X-Api-Key' => $user_auth_api_key]);185 $response = $api->http_request('POST', '/auth/login', $data, ['X-Api-Key' => self::AUTH_API_KEY]); 185 186 $err = is_wp_error($response) ? $response->get_error_message() : null; 186 187 if (!$err) { … … 229 230 update_option('crowdaa_user_email', $user_email); 230 231 update_option('crowdaa_user_password', md5($user_password)); 231 update_option('crowdaa_user_api_key', $user_api_key); 232 update_option('crowdaa_user_auth_api_key', $user_auth_api_key); 232 update_option('crowdaa_user_api_key', 'appId:' . $user_app_id); 233 233 update_option('crowdaa_user_id', $json->data->userId); 234 234 update_option('crowdaa_auth_token', $json->data->authToken); 235 update_option('crowdaa_sync_domain_names', $sync_domain_names); 235 236 236 237 $ok = $this->post_login_setup(); … … 241 242 update_option('crowdaa_user_email', ''); 242 243 update_option('crowdaa_user_password', ''); 243 update_option('crowdaa_user_auth_api_key', ''); 244 update_option('crowdaa_user_api_key', ''); 245 update_option('crowdaa_sync_domain_names', ''); 244 246 245 247 self::admin_notice('error', __('Failed to complete login initialization process', CROWDAA_SYNC_PLUGIN_NAME)); … … 268 270 return; 269 271 } else { 272 $this->on_logout_unset(); 273 274 update_option('crowdaa_user_id', ''); 275 update_option('crowdaa_auth_token', ''); 276 update_option('crowdaa_api_url', ''); 277 update_option('crowdaa_user_email', ''); 278 update_option('crowdaa_user_password', ''); 279 update_option('crowdaa_user_api_key', ''); 280 update_option('crowdaa_sync_domain_names', ''); 281 270 282 Crowdaa_Sync_Logs::log('Parameters', 'connection_settings', 'Connection disabled'); 271 283 } -
crowdaa-sync/tags/1.10.0/admin/class-crowdaa-sync-api.php
r3149200 r3169735 1082 1082 * @return boolean 1083 1083 */ 1084 public function update_category($cat_id, $cat_name, $cat_slug, $parent_category_id, $badges, $picture_id = false, $is_event )1084 public function update_category($cat_id, $cat_name, $cat_slug, $parent_category_id, $badges, $picture_id = false, $is_event = false) 1085 1085 { 1086 1086 $data = [ … … 1250 1250 return (preg_replace('/(\s|[\x00-\x1F\x7F-\xFF]|[^\x00-\xFF])/is', '', $key)); 1251 1251 } 1252 1253 public static function sanitize_sync_domain_names($input) 1254 { 1255 $raw_list = explode(',', $input); 1256 1257 $filtered_list = array_filter($raw_list, function ($value) { 1258 $valid_regex = '/^[a-zA-Z0-9](([a-zA-Z0-9]|-)*[a-zA-Z0-9])?(\.[a-zA-Z0-9](([a-zA-Z0-9]|-)*[a-zA-Z0-9])?)*$/'; 1259 $trimmed = trim($value); 1260 if (!$trimmed) return false; 1261 if (!preg_match($valid_regex, $trimmed)) return false; 1262 return true; 1263 }); 1264 1265 return implode(',', $filtered_list); 1266 } 1252 1267 } -
crowdaa-sync/tags/1.10.0/admin/partials/crowdaa-sync-admin-display.php
r3149200 r3169735 28 28 $user_email = get_option('crowdaa_user_email'); 29 29 $user_password = get_option('crowdaa_user_password'); 30 $user_auth_api_key = get_option('crowdaa_user_auth_api_key');31 30 $user_api_key = get_option('crowdaa_user_api_key'); 32 31 $auth_token = get_option('crowdaa_auth_token'); 32 $sync_domain_names = get_option('crowdaa_sync_domain_names'); 33 33 $plugin_api_key = Crowdaa_Sync_Utils::get_plugin_api_key(); 34 35 $is_authenticated = ($user_email && $user_password && $user_api_key && $auth_token); 36 $user_app_id = $user_api_key ? substr($user_api_key, 6) : ''; 37 38 $api_urls = [ 39 'https://api.aws.crowdaa.com/v1' => __('US platform', CROWDAA_SYNC_PLUGIN_NAME), 40 'https://api-fr.aws.crowdaa.com/v1' => __('FR platform', CROWDAA_SYNC_PLUGIN_NAME), 41 ]; 42 if (isset($_GET['api'])) { 43 $api_urls[$_GET['api']] = $_GET['api']; 44 } 45 if ($api_url && !array_key_exists($api_url, $api_urls)) { 46 $api_urls[$api_url] = $api_url; 47 } 34 48 ?> 35 49 <div class="crowdaa-html-container"> 36 50 <p> 37 51 <label class="text-label" for="api_url"><?php esc_html_e('API URL', CROWDAA_SYNC_PLUGIN_NAME); ?></label> 38 <input type="text" required id="api_url" name="api_url" value="<?php echo esc_attr(($api_url && $auth_token) ? $api_url : ''); ?>" /> 39 </p> 40 <p> 41 <label class="text-label" for="user_auth_api_key"><?php esc_html_e('Authentication API key', CROWDAA_SYNC_PLUGIN_NAME); ?></label> 42 <input required id="user_auth_api_key" name="user_auth_api_key" value="<?php echo esc_attr(($user_auth_api_key && $auth_token) ? $user_auth_api_key : ''); ?>" /> 43 </p> 44 <p> 45 <label class="text-label" for="user_api_key"><?php esc_html_e('Application API key', CROWDAA_SYNC_PLUGIN_NAME); ?></label> 46 <input required id="user_api_key" name="user_api_key" value="<?php echo esc_attr(($user_api_key && $auth_token) ? $user_api_key : ''); ?>" /> 52 <select <?php echo $is_authenticated ? 'disabled' : '' ?> name="api_url"> 53 <?php 54 foreach ($api_urls as $url => $name) { ?> 55 <option value="<?php echo esc_attr($url); ?>" <?php echo ($url === $api_url ? 'selected="selected"' : ''); ?>> 56 <?php echo esc_html($name); ?> 57 </option> 58 <?php } ?> 59 </select> 60 </p> 61 <p> 62 <label class="text-label" for="user_app_id"><?php esc_html_e('App ID', CROWDAA_SYNC_PLUGIN_NAME); ?></label> 63 <input <?php echo $is_authenticated ? 'readonly' : '' ?> type="text" required id="user_app_id" name="user_app_id" value="<?php echo esc_attr(($user_app_id && $is_authenticated) ? $user_app_id : ''); ?>" /> 47 64 </p> 48 65 <p> 49 66 <label class="text-label" for="user_email"><?php esc_html_e('Email', CROWDAA_SYNC_PLUGIN_NAME); ?></label> 50 <input type="text" required id="user_email" name="user_email" value="<?php echo esc_attr(($user_email && $auth_token) ? $user_email : ''); ?>" />67 <input <?php echo $is_authenticated ? 'readonly' : '' ?> type="text" required id="user_email" name="user_email" value="<?php echo esc_attr(($user_email && $is_authenticated) ? $user_email : ''); ?>" /> 51 68 </p> 52 69 <p> 53 70 <label class="text-label" for="user_password"><?php esc_html_e('Password', CROWDAA_SYNC_PLUGIN_NAME); ?></label> 54 <input type="password" required id="user_password" name="user_password" value="<?php echo esc_attr(($user_password && $auth_token) ? $user_password : ''); ?>" /> 71 <input <?php echo $is_authenticated ? 'readonly' : '' ?> type="password" required id="user_password" name="user_password" value="<?php echo esc_attr(($user_password && $is_authenticated) ? $user_password : ''); ?>" /> 72 </p> 73 <p> 74 <?php 75 $site_url = get_site_url(); 76 if ($site_url) { 77 $current_domain = parse_url($site_url)['host']; 78 } else if (isset($_SERVER['HTTP_HOST'])) { 79 $current_domain = $_SERVER['HTTP_HOST']; 80 } else { 81 $current_domain = ''; 82 } 83 ?> 84 <label class="text-label" for="sync_domain_names"><?php esc_html_e('Domain names', CROWDAA_SYNC_PLUGIN_NAME); ?></label> 85 <input 86 <?php echo $is_authenticated ? 'readonly' : '' ?> 87 type="text" 88 pattern="[a-zA-Z0-9](([a-zA-Z0-9]|-)*[a-zA-Z0-9])?(\.[a-zA-Z0-9](([a-zA-Z0-9]|-)*[a-zA-Z0-9])?)*( *, *[a-zA-Z0-9](([a-zA-Z0-9]|-)*[a-zA-Z0-9])?(\.[a-zA-Z0-9](([a-zA-Z0-9]|-)*[a-zA-Z0-9])?)*)*" 89 title="<?php echo esc_attr_e('Comma-separated domain names list for your website, like example.com, www.example.com, other.subdomain.example.com', CROWDAA_SYNC_PLUGIN_NAME); ?>" 90 id="sync_domain_names" 91 name="sync_domain_names" 92 value="<?php echo esc_attr(($sync_domain_names && $is_authenticated) ? $sync_domain_names : $current_domain); ?>" /> 55 93 </p> 56 94 <p> … … 62 100 <?php 63 101 wp_nonce_field('crowdaa_login_data', 'crowdaa_login'); 64 if ($ user_email && $user_password && $user_auth_api_key && $user_api_key) {102 if ($is_authenticated) { 65 103 ?> 66 104 <input type="hidden" id="status" name="status" value="disconnect" /> 67 105 <?php 68 submit_button( 'Disconnect from Crowdaa');106 submit_button(__('Disconnect from Crowdaa', CROWDAA_SYNC_PLUGIN_NAME)); 69 107 } else { 70 108 ?> 71 109 <input type="hidden" id="status" name="status" value="connect" /> 72 110 <?php 73 submit_button( 'Connect to Crowdaa');111 submit_button(__('Connect to Crowdaa', CROWDAA_SYNC_PLUGIN_NAME)); 74 112 } 75 113 ?> … … 106 144 107 145 <?php 108 if ($ user_email && $user_password && $user_auth_api_key && $user_api_key && $auth_token) {146 if ($is_authenticated) { 109 147 ?> 110 148 <hr /> -
crowdaa-sync/tags/1.10.0/crowdaa-sync.php
r3150916 r3169735 14 14 * Plugin URI: 15 15 * Description: Plugin for synchronizing WordPress site and Crowdaa CMS 16 * Version: 1. 9.116 * Version: 1.10.0 17 17 * Requires at least: 5.5 18 18 * Requires PHP: 7.2 … … 34 34 * Uses SemVer - https://semver.org 35 35 */ 36 define('CROWDAA_SYNC_VERSION', '1. 9.1');36 define('CROWDAA_SYNC_VERSION', '1.10.0'); 37 37 define('CROWDAA_SYNC_PLUGIN_DIR', __DIR__); 38 38 define('CROWDAA_SYNC_PLUGIN_NAME', 'crowdaa-sync'); -
crowdaa-sync/trunk/CHANGELOG
r3150916 r3169735 7 7 8 8 ## [Unreleased] 9 10 ## [1.10.0] - 2024-10-16 11 12 ### Changed 13 14 - Added FR translations 15 - Updated interface for easier use 9 16 10 17 ## [1.9.0] - 2024-09-10 -
crowdaa-sync/trunk/README.txt
r3150916 r3169735 6 6 Requires PHP: 7.3 7 7 Tested up to: 5.9 8 Stable tag: 1. 9.18 Stable tag: 1.10.0 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html -
crowdaa-sync/trunk/admin/class-crowdaa-sync-admin-display.php
r3150916 r3169735 14 14 class Crowdaa_Sync_Admin_Display 15 15 { 16 private const AUTH_API_KEY = 'nQ9ZO9DEgfaOzWY44Xu2J2uaPtP92t176PpBkdqu'; 16 17 /** 17 18 * Initialize the class and set its properties. … … 112 113 { 113 114 $pluginApiKey = Crowdaa_Sync_Utils::generate_plugin_api_key(); 115 $syncDomainNames = get_option('crowdaa_sync_domain_names'); 114 116 $api = new Crowdaa_Sync_API(); 115 117 $response = $api->http_request('POST', '/websites/crowdaa-sync/autosetup', [ 118 'action' => 'setup', 116 119 'pluginApiKey' => $pluginApiKey, 120 'wordpressApiUrl' => preg_replace('~/$~', '', get_rest_url()), 121 'defaultWordpressUrl' => get_site_url(), 122 'syncDomainNames' => explode(',', $syncDomainNames), 117 123 ]); 118 124 … … 140 146 } 141 147 148 public function on_logout_unset() 149 { 150 $pluginApiKey = Crowdaa_Sync_Utils::get_plugin_api_key(); 151 $api = new Crowdaa_Sync_API(); 152 $api->http_request('POST', '/websites/crowdaa-sync/autosetup', [ 153 'action' => 'logout', 154 'pluginApiKey' => $pluginApiKey, 155 'wordpressApiUrl' => preg_replace('~/$~', '', get_rest_url()), 156 ]); 157 } 158 142 159 /** 143 160 * Admin notices … … 152 169 153 170 Crowdaa_Sync_Logs::log('Parameters', 'connection_settings', 'Enabling connection...'); 154 update_option('crowdaa_user_id', '');155 update_option('crowdaa_auth_token', '');156 update_option('crowdaa_api_url', '');157 update_option('crowdaa_user_email', '');158 update_option('crowdaa_user_password', '');159 update_option('crowdaa_user_auth_api_key', '');160 if (isset($_POST['api_url'])) {161 update_option('crowdaa_api_url', esc_url_raw($_POST['api_url']));162 } else {163 add_action(164 'admin_notices',165 function () {166 self::admin_notice('error', __('Add API URL, please', CROWDAA_SYNC_PLUGIN_NAME));167 }168 );169 return;170 }171 171 if (isset($_POST['status']) && $_POST['status'] == 'connect') { 172 if (isset($_POST['user_auth_api_key']) && isset($_POST['user_api_key']) && isset($_POST['user_email']) && isset($_POST['user_password'])) { 172 if (isset($_POST['api_url']) && isset($_POST['user_app_id']) && isset($_POST['user_email']) && isset($_POST['user_password'])) { 173 update_option('crowdaa_api_url', esc_url_raw($_POST['api_url'])); 173 174 $user_email = sanitize_email($_POST['user_email']); 174 175 $user_password = Crowdaa_Sync_Api::sanitize_api_password($_POST['user_password']); 175 $user_ap i_key = Crowdaa_Sync_Api::sanitize_api_key($_POST['user_api_key']);176 $ user_auth_api_key = Crowdaa_Sync_Api::sanitize_api_key($_POST['user_auth_api_key']);176 $user_app_id = Crowdaa_Sync_Api::sanitize_api_key($_POST['user_app_id']); 177 $sync_domain_names = Crowdaa_Sync_Api::sanitize_sync_domain_names($_POST['sync_domain_names']); 177 178 $data = [ 178 179 'email' => $user_email, … … 182 183 $api = new Crowdaa_Sync_API(); 183 184 184 $response = $api->http_request('POST', '/auth/login', $data, ['X-Api-Key' => $user_auth_api_key]);185 $response = $api->http_request('POST', '/auth/login', $data, ['X-Api-Key' => self::AUTH_API_KEY]); 185 186 $err = is_wp_error($response) ? $response->get_error_message() : null; 186 187 if (!$err) { … … 229 230 update_option('crowdaa_user_email', $user_email); 230 231 update_option('crowdaa_user_password', md5($user_password)); 231 update_option('crowdaa_user_api_key', $user_api_key); 232 update_option('crowdaa_user_auth_api_key', $user_auth_api_key); 232 update_option('crowdaa_user_api_key', 'appId:' . $user_app_id); 233 233 update_option('crowdaa_user_id', $json->data->userId); 234 234 update_option('crowdaa_auth_token', $json->data->authToken); 235 update_option('crowdaa_sync_domain_names', $sync_domain_names); 235 236 236 237 $ok = $this->post_login_setup(); … … 241 242 update_option('crowdaa_user_email', ''); 242 243 update_option('crowdaa_user_password', ''); 243 update_option('crowdaa_user_auth_api_key', ''); 244 update_option('crowdaa_user_api_key', ''); 245 update_option('crowdaa_sync_domain_names', ''); 244 246 245 247 self::admin_notice('error', __('Failed to complete login initialization process', CROWDAA_SYNC_PLUGIN_NAME)); … … 268 270 return; 269 271 } else { 272 $this->on_logout_unset(); 273 274 update_option('crowdaa_user_id', ''); 275 update_option('crowdaa_auth_token', ''); 276 update_option('crowdaa_api_url', ''); 277 update_option('crowdaa_user_email', ''); 278 update_option('crowdaa_user_password', ''); 279 update_option('crowdaa_user_api_key', ''); 280 update_option('crowdaa_sync_domain_names', ''); 281 270 282 Crowdaa_Sync_Logs::log('Parameters', 'connection_settings', 'Connection disabled'); 271 283 } -
crowdaa-sync/trunk/admin/class-crowdaa-sync-api.php
r3149200 r3169735 1082 1082 * @return boolean 1083 1083 */ 1084 public function update_category($cat_id, $cat_name, $cat_slug, $parent_category_id, $badges, $picture_id = false, $is_event )1084 public function update_category($cat_id, $cat_name, $cat_slug, $parent_category_id, $badges, $picture_id = false, $is_event = false) 1085 1085 { 1086 1086 $data = [ … … 1250 1250 return (preg_replace('/(\s|[\x00-\x1F\x7F-\xFF]|[^\x00-\xFF])/is', '', $key)); 1251 1251 } 1252 1253 public static function sanitize_sync_domain_names($input) 1254 { 1255 $raw_list = explode(',', $input); 1256 1257 $filtered_list = array_filter($raw_list, function ($value) { 1258 $valid_regex = '/^[a-zA-Z0-9](([a-zA-Z0-9]|-)*[a-zA-Z0-9])?(\.[a-zA-Z0-9](([a-zA-Z0-9]|-)*[a-zA-Z0-9])?)*$/'; 1259 $trimmed = trim($value); 1260 if (!$trimmed) return false; 1261 if (!preg_match($valid_regex, $trimmed)) return false; 1262 return true; 1263 }); 1264 1265 return implode(',', $filtered_list); 1266 } 1252 1267 } -
crowdaa-sync/trunk/admin/partials/crowdaa-sync-admin-display.php
r3149200 r3169735 28 28 $user_email = get_option('crowdaa_user_email'); 29 29 $user_password = get_option('crowdaa_user_password'); 30 $user_auth_api_key = get_option('crowdaa_user_auth_api_key');31 30 $user_api_key = get_option('crowdaa_user_api_key'); 32 31 $auth_token = get_option('crowdaa_auth_token'); 32 $sync_domain_names = get_option('crowdaa_sync_domain_names'); 33 33 $plugin_api_key = Crowdaa_Sync_Utils::get_plugin_api_key(); 34 35 $is_authenticated = ($user_email && $user_password && $user_api_key && $auth_token); 36 $user_app_id = $user_api_key ? substr($user_api_key, 6) : ''; 37 38 $api_urls = [ 39 'https://api.aws.crowdaa.com/v1' => __('US platform', CROWDAA_SYNC_PLUGIN_NAME), 40 'https://api-fr.aws.crowdaa.com/v1' => __('FR platform', CROWDAA_SYNC_PLUGIN_NAME), 41 ]; 42 if (isset($_GET['api'])) { 43 $api_urls[$_GET['api']] = $_GET['api']; 44 } 45 if ($api_url && !array_key_exists($api_url, $api_urls)) { 46 $api_urls[$api_url] = $api_url; 47 } 34 48 ?> 35 49 <div class="crowdaa-html-container"> 36 50 <p> 37 51 <label class="text-label" for="api_url"><?php esc_html_e('API URL', CROWDAA_SYNC_PLUGIN_NAME); ?></label> 38 <input type="text" required id="api_url" name="api_url" value="<?php echo esc_attr(($api_url && $auth_token) ? $api_url : ''); ?>" /> 39 </p> 40 <p> 41 <label class="text-label" for="user_auth_api_key"><?php esc_html_e('Authentication API key', CROWDAA_SYNC_PLUGIN_NAME); ?></label> 42 <input required id="user_auth_api_key" name="user_auth_api_key" value="<?php echo esc_attr(($user_auth_api_key && $auth_token) ? $user_auth_api_key : ''); ?>" /> 43 </p> 44 <p> 45 <label class="text-label" for="user_api_key"><?php esc_html_e('Application API key', CROWDAA_SYNC_PLUGIN_NAME); ?></label> 46 <input required id="user_api_key" name="user_api_key" value="<?php echo esc_attr(($user_api_key && $auth_token) ? $user_api_key : ''); ?>" /> 52 <select <?php echo $is_authenticated ? 'disabled' : '' ?> name="api_url"> 53 <?php 54 foreach ($api_urls as $url => $name) { ?> 55 <option value="<?php echo esc_attr($url); ?>" <?php echo ($url === $api_url ? 'selected="selected"' : ''); ?>> 56 <?php echo esc_html($name); ?> 57 </option> 58 <?php } ?> 59 </select> 60 </p> 61 <p> 62 <label class="text-label" for="user_app_id"><?php esc_html_e('App ID', CROWDAA_SYNC_PLUGIN_NAME); ?></label> 63 <input <?php echo $is_authenticated ? 'readonly' : '' ?> type="text" required id="user_app_id" name="user_app_id" value="<?php echo esc_attr(($user_app_id && $is_authenticated) ? $user_app_id : ''); ?>" /> 47 64 </p> 48 65 <p> 49 66 <label class="text-label" for="user_email"><?php esc_html_e('Email', CROWDAA_SYNC_PLUGIN_NAME); ?></label> 50 <input type="text" required id="user_email" name="user_email" value="<?php echo esc_attr(($user_email && $auth_token) ? $user_email : ''); ?>" />67 <input <?php echo $is_authenticated ? 'readonly' : '' ?> type="text" required id="user_email" name="user_email" value="<?php echo esc_attr(($user_email && $is_authenticated) ? $user_email : ''); ?>" /> 51 68 </p> 52 69 <p> 53 70 <label class="text-label" for="user_password"><?php esc_html_e('Password', CROWDAA_SYNC_PLUGIN_NAME); ?></label> 54 <input type="password" required id="user_password" name="user_password" value="<?php echo esc_attr(($user_password && $auth_token) ? $user_password : ''); ?>" /> 71 <input <?php echo $is_authenticated ? 'readonly' : '' ?> type="password" required id="user_password" name="user_password" value="<?php echo esc_attr(($user_password && $is_authenticated) ? $user_password : ''); ?>" /> 72 </p> 73 <p> 74 <?php 75 $site_url = get_site_url(); 76 if ($site_url) { 77 $current_domain = parse_url($site_url)['host']; 78 } else if (isset($_SERVER['HTTP_HOST'])) { 79 $current_domain = $_SERVER['HTTP_HOST']; 80 } else { 81 $current_domain = ''; 82 } 83 ?> 84 <label class="text-label" for="sync_domain_names"><?php esc_html_e('Domain names', CROWDAA_SYNC_PLUGIN_NAME); ?></label> 85 <input 86 <?php echo $is_authenticated ? 'readonly' : '' ?> 87 type="text" 88 pattern="[a-zA-Z0-9](([a-zA-Z0-9]|-)*[a-zA-Z0-9])?(\.[a-zA-Z0-9](([a-zA-Z0-9]|-)*[a-zA-Z0-9])?)*( *, *[a-zA-Z0-9](([a-zA-Z0-9]|-)*[a-zA-Z0-9])?(\.[a-zA-Z0-9](([a-zA-Z0-9]|-)*[a-zA-Z0-9])?)*)*" 89 title="<?php echo esc_attr_e('Comma-separated domain names list for your website, like example.com, www.example.com, other.subdomain.example.com', CROWDAA_SYNC_PLUGIN_NAME); ?>" 90 id="sync_domain_names" 91 name="sync_domain_names" 92 value="<?php echo esc_attr(($sync_domain_names && $is_authenticated) ? $sync_domain_names : $current_domain); ?>" /> 55 93 </p> 56 94 <p> … … 62 100 <?php 63 101 wp_nonce_field('crowdaa_login_data', 'crowdaa_login'); 64 if ($ user_email && $user_password && $user_auth_api_key && $user_api_key) {102 if ($is_authenticated) { 65 103 ?> 66 104 <input type="hidden" id="status" name="status" value="disconnect" /> 67 105 <?php 68 submit_button( 'Disconnect from Crowdaa');106 submit_button(__('Disconnect from Crowdaa', CROWDAA_SYNC_PLUGIN_NAME)); 69 107 } else { 70 108 ?> 71 109 <input type="hidden" id="status" name="status" value="connect" /> 72 110 <?php 73 submit_button( 'Connect to Crowdaa');111 submit_button(__('Connect to Crowdaa', CROWDAA_SYNC_PLUGIN_NAME)); 74 112 } 75 113 ?> … … 106 144 107 145 <?php 108 if ($ user_email && $user_password && $user_auth_api_key && $user_api_key && $auth_token) {146 if ($is_authenticated) { 109 147 ?> 110 148 <hr /> -
crowdaa-sync/trunk/crowdaa-sync.php
r3150916 r3169735 14 14 * Plugin URI: 15 15 * Description: Plugin for synchronizing WordPress site and Crowdaa CMS 16 * Version: 1. 9.116 * Version: 1.10.0 17 17 * Requires at least: 5.5 18 18 * Requires PHP: 7.2 … … 34 34 * Uses SemVer - https://semver.org 35 35 */ 36 define('CROWDAA_SYNC_VERSION', '1. 9.1');36 define('CROWDAA_SYNC_VERSION', '1.10.0'); 37 37 define('CROWDAA_SYNC_PLUGIN_DIR', __DIR__); 38 38 define('CROWDAA_SYNC_PLUGIN_NAME', 'crowdaa-sync');
Note: See TracChangeset
for help on using the changeset viewer.