Changeset 3036964
- Timestamp:
- 02/16/2024 07:21:44 PM (2 years ago)
- Location:
- uk-cookie-consent/trunk
- Files:
-
- 10 edited
-
changelog.txt (modified) (1 diff)
-
includes/controllers/class-account-api-controller.php (modified) (5 diffs)
-
includes/controllers/class-banner-settings-controller.php (modified) (1 diff)
-
includes/controllers/class-edit-cookie.php (modified) (18 diffs)
-
includes/controllers/class-robots-txt.php (modified) (5 diffs)
-
includes/controllers/class-site-scan-controller.php (modified) (10 diffs)
-
includes/models/class-site-scan-model.php (modified) (3 diffs)
-
includes/models/class-termly-api-model.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
uk-cookie-consent.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uk-cookie-consent/trunk/changelog.txt
r3009736 r3036964 1 = 3.2 = 2 * New: There is a new setting on the site scan page to add a specific allow line to an existing or virtual (provided by WordPress core) robots.txt file. 3 * Update: Changed the text of the "allow" line in the robots.txt to accurately reflect the new scraper's name. 4 * Removed: The plugin will no longer automatically save the "allow" line to the robots.txt file when regenerating rewrite rules. 5 1 6 = 3.1.1 = 2 7 * Update: Updates the embed script on the consent banner to include some additional information needed for European privacy framework. -
uk-cookie-consent/trunk/includes/controllers/class-account-api-controller.php
r2567699 r3036964 1 1 <?php 2 /** 3 * Account API Controller 4 * 5 * @package UKCookieConsent 6 */ 2 7 3 8 namespace termly; 4 9 10 /** 11 * Account API Controller class. 12 */ 5 13 class Account_API_Controller { 6 14 15 /** 16 * Hooks into WordPress for this class. 17 * 18 * @return void 19 */ 7 20 public static function hooks() { 8 21 … … 16 29 } 17 30 31 /** 32 * Adds the rewrite rule for the account status endpoint. 33 * 34 * @return void 35 */ 18 36 public static function add_rewrite_rule() { 19 37 … … 30 48 } 31 49 50 /** 51 * Maybe schedule the cron job. 52 * 53 * @return void 54 */ 32 55 public static function maybe_schedule_cron() { 33 56 … … 40 63 } 41 64 65 /** 66 * Update the account status. 67 * 68 * @return WP_REST_Response 69 */ 42 70 public static function update_account_status() { 43 71 … … 76 104 } else { 77 105 78 error_log( print_r( [ $response ], true ) ); 79 wp_send_json_error(); 106 return rest_ensure_response( [ 'message' => __( 'Failed to update account status.', 'uk-cookie-consent' ) ] ); 80 107 81 108 } 82 109 83 wp_send_json_success();110 return rest_ensure_response( [ 'message' => __( 'Account status updated.', 'uk-cookie-consent' ) ] ); 84 111 85 112 } 86 113 114 /** 115 * Check if the plugin is using a free account to communicate with the API. 116 * 117 * @return bool 118 */ 87 119 public static function is_free() { 88 120 -
uk-cookie-consent/trunk/includes/controllers/class-banner-settings-controller.php
r3006375 r3036964 172 172 '/consent-toggle', 173 173 [ 174 'methods' => 'POST', 175 'callback' => [ __CLASS__, 'handle_consent_toggle' ], 174 'methods' => 'POST', 175 'callback' => [ __CLASS__, 'handle_consent_toggle' ], 176 'permission_callback' => '__return_true', 176 177 ] 177 178 ); -
uk-cookie-consent/trunk/includes/controllers/class-edit-cookie.php
r3006375 r3036964 8 8 namespace termly; 9 9 10 // If the Termly API Controller has not been included 10 // If the Termly API Controller has not been included. 11 11 if ( ! class_exists( 'Termly_API_Controller' ) ) { 12 12 require_once TERMLY_CONTROLLERS . 'class-termly-api-controller.php'; … … 18 18 class Edit_Cookie { 19 19 20 /** 21 * The name prefix for ids. 22 * 23 * @var string 24 */ 20 25 public static $name_prefix = 'termly-edit-cookie-'; 21 26 22 27 /** 23 * hooks Hooks into WordPress for this class28 * Hooks into WordPress for this class. 24 29 * 25 30 * @return void … … 33 38 34 39 /** 35 * edit_page Adds submenu page for edit page with no parent40 * Adds submenu page for edit page with no parent. 36 41 * 37 42 * @return void … … 40 45 41 46 add_submenu_page( 42 null,47 'admin.php', 43 48 __( 'Edit Cookie', 'uk-cookie-consent' ), 44 49 '', … … 51 56 52 57 /** 53 * edit_page_viewThe view for the edit page.58 * The view for the edit page. 54 59 * Also triggers edit/add functionality if action is set 55 60 * … … 58 63 public static function edit_page_view() { 59 64 60 // Handle editing or adding a cookie if there is an action set in the request 65 // Handle editing or adding a cookie if there is an action set in the request. 61 66 if ( isset( $_REQUEST['action'] ) ) { 62 67 $status = self::handle_crud(); … … 64 69 65 70 // Whether this is editing or adding new 66 // Cookie ID is only set if we are editing 71 // Cookie ID is only set if we are editing. 67 72 $editing = isset( $_GET['cookie_id'] ); 68 73 69 // Name prefix for ids 74 // Name prefix for ids. 70 75 $name_prefix = self::$name_prefix; 71 76 72 77 // If a cookie has been added, an additional 73 // array value is added which is the cookie id 78 // array value is added which is the cookie id. 74 79 if ( isset( $status ) && 3 === count( $status ) ) { 75 80 $cookie_id = $status[2]; … … 77 82 } 78 83 79 // By default, cookie is set to false 84 // By default, cookie is set to false. 80 85 $cookie = false; 81 86 … … 117 122 118 123 /** 119 * handle_crudHandle editing and adding a cookie124 * Handle editing and adding a cookie 120 125 * 121 126 * @return array [0] is success/error [1] is message [2] (optional) is cookie id … … 123 128 public static function handle_crud() { 124 129 125 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'termly_cookie_nonce' ) ) {130 if ( ! isset( $_REQUEST['_wpnonce'], $_REQUEST['action'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'termly_cookie_nonce' ) ) { 126 131 die(); 127 132 } 128 133 129 $action = sanitize_text_field( $_REQUEST['action'] ); 130 131 // Check for required fields 132 $required_fields = [ 133 'name', 'category', 'domain', 134 ]; 134 $action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ); 135 136 // Check for required fields. 137 $required_fields = [ 'name', 'category', 'domain' ]; 135 138 136 139 foreach ( $required_fields as $field ) { … … 143 146 } 144 147 145 // Delete the transient which stores cookie list 148 // Delete the transient which stores cookie list. 146 149 delete_transient( 'termly-site-scan-results' ); 147 150 148 // Arguments for edit/add cookie 149 $arg_keys = [ 150 'name', 'category', 'expire', 'tracker_type', 151 'country', 'domain', 'service', 'service_policy_link', 152 'source', 'value', 'en_us', 153 ]; 151 // Arguments for edit/add cookie. 152 $arg_keys = [ 'name', 'category', 'expire', 'tracker_type', 'country', 'domain', 'service', 'service_policy_link', 'source', 'value', 'en_us' ]; 154 153 155 154 $args = []; 156 155 157 // Add arguments of they are set 156 // Add arguments of they are set. 158 157 foreach ( $arg_keys as $key ) { 159 158 if ( ! isset( $_REQUEST[ $key ] ) ) { 160 159 continue; 161 160 } 162 $args[ $key ] = sanitize_text_field( $_REQUEST[ $key ] ); 163 } 164 165 // Unslash the args 166 $args = wp_unslash( $args ); 167 168 // Edit a cookie 161 $args[ $key ] = sanitize_text_field( wp_unslash( $_REQUEST[ $key ] ) ); 162 } 163 164 // Edit a cookie. 169 165 if ( 'edit' === $action ) { 170 166 $status = self::edit_cookie( $args ); … … 172 168 } 173 169 174 // Add a cookie 170 // Add a cookie. 175 171 if ( 'add' === $action ) { 176 172 $status = self::add_cookie( $args ); … … 183 179 184 180 /** 185 * edit_cookie186 * 187 * @param array $args Post arguments 181 * Store the cookie and return the status. 182 * 183 * @param array $args Post arguments All posted arguments. 188 184 * 189 185 * @return array [0] is success/error [1] is message [2] is cookie id … … 191 187 public static function edit_cookie( $args ) { 192 188 193 // These fields cannot be edited 194 $non_editable_fields = [ 'name', 'expire', 'tracker_type', 'domain' ,];195 196 // Loop through and remove non editable fields if they are set 189 // These fields cannot be edited. 190 $non_editable_fields = [ 'name', 'expire', 'tracker_type', 'domain' ]; 191 192 // Loop through and remove non editable fields if they are set. 197 193 foreach ( $non_editable_fields as $field ) { 198 194 if ( ! isset( $args[ $field ] ) ) { … … 202 198 } 203 199 204 // Get the cookie ID 200 if ( ! isset( $_REQUEST['cookie_id'] ) ) { 201 return [ 202 'error', 203 __( 'Cookie not found', 'uk-cookie-consent' ), 204 ]; 205 } 206 207 // Get the cookie ID. 205 208 $cookie_id = intval( $_REQUEST['cookie_id'] ); 206 209 207 // PUT request to the API 210 // PUT request to the API. 208 211 $response = Termly_API_Controller::call( 'PUT', 'cookies/' . $cookie_id, $args ); 209 212 210 213 if ( 200 === wp_remote_retrieve_response_code( $response ) && ! is_wp_error( $response ) ) { 211 // Return success 214 215 // Return success. 212 216 return [ 213 217 'success', … … 215 219 $cookie_id, 216 220 ]; 217 } 218 219 // Return failure 221 222 } 223 224 // Return failure. 220 225 return [ 221 226 'error', … … 250 255 251 256 // If not adding another, set cookie id to go to edit screen. 252 if ( 'add_another' !== $_REQUEST['submit']) {257 if ( isset( $_REQUEST['submit'] ) && 'add_another' !== sanitize_text_field( wp_unslash( $_REQUEST['submit'] ) ) ) { 253 258 $success[] = intval( $cookie_id ); 254 259 } … … 268 273 * Highlight the "Cookie Management" submenu page when on the edit cookie page 269 274 * 270 * @param string $parent 275 * @param string $parent_page The slug of the parent page. 271 276 * 272 277 * @return string 273 278 */ 274 public static function highlight( $parent ) { 279 public static function highlight( $parent_page ) { 280 275 281 global $plugin_page; 276 282 if ( 'termly-edit-cookie' === $plugin_page ) { 277 $plugin_page = 'cookie-management'; 278 } 279 return $parent; 283 284 $plugin_page = 'cookie-management'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited 285 286 } 287 return $parent_page; 288 280 289 } 281 290 -
uk-cookie-consent/trunk/includes/controllers/class-robots-txt.php
r2570327 r3036964 21 21 22 22 \add_filter( 'robots_txt', [ __CLASS__, 'virtual' ], 10, 1 ); 23 \add_action( 'generate_rewrite_rules', [ __CLASS__, 'check_file' ] );24 23 25 24 } … … 31 30 * @return string $file 32 31 */ 33 public static function virtual( $file ) {32 public static function virtual( $file = '' ) { 34 33 35 return 'User-agent: Scrapy 34 return '# Termly scanner 35 User-agent: TermlyBot 36 36 Allow: / 37 37 … … 41 41 42 42 /** 43 * Check for an actual robots.txt file. 44 * Fired after rewrite rules are flushed. 45 * We needed a place where users could trigger this. 46 * 47 * @param WP_Rewrite $rules The WP_Rewrite object. 43 * Check for an actual robots.txt file and add the allow line. 48 44 * 49 45 * @return void 50 46 */ 51 public static function check_file( $rules) {47 public static function add_allow_line() { 52 48 53 49 // Include filesystem functionality. … … 87 83 // Check to see if the robots file already has the rule. 88 84 $robots_content = $wp_filesystem->get_contents( $robots_path ); 89 $robots_rule = 'User-agent: Scrapy 85 $scrapy_rule = '/User-agent: Scrapy\nAllow: \//'; 86 $robots_rule = '# Termly scanner 87 User-agent: TermlyBot 90 88 Allow: /'; 91 89 90 // Remove the Scrapy rule if it exists. 91 if ( 1 === preg_match( $scrapy_rule, $robots_content ) ) { 92 $robots_content = preg_replace( $scrapy_rule, '', $robots_content ); 93 } 94 95 // Check if the termly bot rule already exists. 92 96 if ( false !== strpos( $robots_content, $robots_rule ) ) { 93 97 return; … … 103 107 } 104 108 109 /** 110 * Check for an actual robots.txt file with the allo wline and remove it. 111 * 112 * @return void 113 */ 114 public static function remove_allow_line() { 115 116 // Include filesystem functionality. 117 require_once ABSPATH . 'wp-admin/includes/file.php'; 118 119 // Check that the robots file exists. 120 $robots_path = ABSPATH . '/robots.txt'; 121 if ( ! file_exists( $robots_path ) || ! is_file( $robots_path ) ) { 122 return; 123 } 124 125 // Initialize the filesystem API. 126 global $wp_filesystem; 127 128 $url = \wp_nonce_url( 129 \add_query_arg( 130 [ 131 'page' => 'termly', 132 ], 133 \admin_url( 'admin.php' ) 134 ), 135 'termly-robots-nonce' 136 ); 137 138 // Create and test creds. 139 $creds = \request_filesystem_credentials( $url, '', false, false, null ); 140 if ( false === $creds ) { 141 return; 142 } 143 144 if ( ! \WP_Filesystem( $creds ) ) { 145 // Prompt user to enter credentials. 146 \request_filesystem_credentials( $url, '', true, false, null ); 147 return; 148 } 149 150 // Check to see if the robots file already has the rule. 151 $robots_content = $wp_filesystem->get_contents( $robots_path ); 152 $rules = '/(User-agent: Scrapy\nAllow: \/|# Termly scanner\nUser-agent: TermlyBot\nAllow: \/)/'; 153 154 // Remove the Scrapy rule if it exists. 155 if ( 1 === preg_match( $rules, $robots_content ) ) { 156 $robots_content = preg_replace( $rules, '', $robots_content ); 157 } 158 159 // Prepend the rule. Robots file is read top to bottom. 160 $wp_filesystem->put_contents( $robots_path, $robots_content, FS_CHMOD_FILE ); 161 162 } 163 105 164 } 106 165 -
uk-cookie-consent/trunk/includes/controllers/class-site-scan-controller.php
r2567699 r3036964 13 13 class Site_Scan_Controller extends Menu_Controller { 14 14 15 /** 16 * The last request made to the API. 17 * 18 * @var \WP_Error 19 */ 15 20 private static $last_request = null; 16 21 22 /** 23 * Register the hooks for the class. 24 */ 17 25 public static function hooks() { 18 26 … … 35 43 } 36 44 45 /** 46 * Register the settings and fields for the Site Scan. 47 */ 37 48 public static function register_settings() { 38 49 39 50 // Register the API Key Setting. 40 register_setting( 'termly_site_scan', 'termly_site_scan', [ 'sanitize_callback' => [ new Site_Scan_Model, 'sanitize_site_scan' ] ] ); 51 register_setting( 52 'termly_site_scan', 53 'termly_site_scan', 54 [ 55 'sanitize_callback' => [ new Site_Scan_Model, 'sanitize_site_scan' ], 56 ] 57 ); 41 58 42 59 // Add a section to the Settings API. … … 56 73 ); 57 74 58 } 59 75 add_settings_field( 76 'termly_robots_txt', 77 __( 'Robots.txt', 'uk-cookie-consent' ), 78 [ __CLASS__, 'robots_txt_field' ], 79 'termly_site_scan', 80 'termly_site_scan_section' 81 ); 82 83 } 84 85 /** 86 * Output the section header. 87 * 88 * @param array $args The arguments for the section. 89 */ 60 90 public static function section_header( $args = [] ) { 61 91 // Don't output a heading. 62 92 } 63 93 64 public static function site_scan_field( $args = [] ) { 94 /** 95 * Output the Site Scan field. 96 */ 97 public static function site_scan_field() { 65 98 66 99 $feature_set_cache_key = 'termly-feature-set'; … … 107 140 } 108 141 142 /** 143 * Output the Robots.txt field. 144 */ 145 public static function robots_txt_field() { 146 147 $site_scan = get_option( 148 'termly_site_scan', 149 [ 150 'robots_txt' => 0, 151 ] 152 ); 153 $site_scan = wp_parse_args( $site_scan, [ 'robots_txt' => 0 ] ); 154 ?> 155 <p><label class="checkbox-container" for="termly-site-scan-robots-txt"> 156 <input type="checkbox" name="termly_site_scan[robots_txt]" id="termly-site-scan-robots-txt" value="1" <?php checked( 1, $site_scan['robots_txt'] ); ?>> 157 <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> 158 <path class="border" d="M3.5 6C3.5 4.61929 4.61929 3.5 6 3.5H18C19.3807 3.5 20.5 4.61929 20.5 6V18C20.5 19.3807 19.3807 20.5 18 20.5H6C4.61929 20.5 3.5 19.3807 3.5 18V6Z" fill="white" stroke="#CED4DA"/> 159 <path class="checkmark" fill-rule="evenodd" clip-rule="evenodd" d="M15.4937 9.25628C15.8383 8.91457 16.397 8.91457 16.7416 9.25628C17.0861 9.59799 17.0861 10.152 16.7416 10.4937L11.4474 15.7437C11.1029 16.0854 10.5442 16.0854 10.1996 15.7437L7.25844 12.8271C6.91385 12.4853 6.91385 11.9313 7.25844 11.5896C7.60302 11.2479 8.16169 11.2479 8.50627 11.5896L10.8235 13.8876L15.4937 9.25628Z" fill="#4672FF"/> 160 </svg> 161 <span><?php esc_html_e( 'Add Termly Scanner to robots.txt Allow list', 'uk-cookie-consent' ); ?></span> 162 </label></p> 163 <?php 164 } 165 166 /** 167 * Add the Site Scan submenu item. 168 */ 109 169 public static function menu() { 110 170 … … 120 180 } 121 181 182 /** 183 * Output the Site Scan page. 184 */ 122 185 public static function menu_page() { 123 186 … … 126 189 } 127 190 191 /** 192 * Make a call out to the Termly API to initiate a new scan. 193 */ 128 194 public static function handle_new_scan_request() { 129 195 … … 133 199 } 134 200 201 /** 202 * Output the new scan notice. 203 */ 135 204 public static function new_scan_notice() { 136 205 … … 168 237 } 169 238 239 /** 240 * Output the update notice. 241 */ 170 242 public static function maybe_update_notice() { 171 243 … … 175 247 'termly_site_scan', 176 248 [ 177 'enabled' => 0,249 'enabled' => 0, 178 250 ] 179 251 ); … … 207 279 } 208 280 281 /** 282 * Get the last scanned date. 283 * 284 * @return string 285 */ 209 286 public static function get_last_scanned() { 210 287 -
uk-cookie-consent/trunk/includes/models/class-site-scan-model.php
r2567699 r3036964 13 13 class Site_Scan_Model { 14 14 15 /** 16 * Sanitize the site scan settings. 17 * 18 * @param array $value The value to sanitize. 19 * 20 * @return array 21 */ 15 22 public static function sanitize_site_scan( $value ) { 16 23 … … 22 29 $value, 23 30 [ 24 'enabled' => 0, 25 'frequency' => 'trimonthly', 31 'enabled' => 0, 32 'frequency' => 'trimonthly', 33 'robots_txt' => 0, 26 34 ] 27 35 ); … … 31 39 if ( '' !== $value ) { 32 40 33 $response = Termly_API_Controller::call( 'PUT', 'website/scan_settings', [ 'scan_enabled' => boolval( $value['enabled'] ), 'scan_period' => $value['frequency'], ] ); 41 // Save the settings to the API. 42 $response = Termly_API_Controller::call( 43 'PUT', 44 'website/scan_settings', 45 [ 46 'scan_enabled' => boolval( $value['enabled'] ), 47 'scan_period' => $value['frequency'], 48 ] 49 ); 34 50 if ( 200 === wp_remote_retrieve_response_code( $response ) && ! is_wp_error( $response ) ) { 51 52 // If the robots.txt setting is enabled and the robots.txt file exists. 53 if ( 1 === intval( $value['robots_txt'] ) ) { 54 55 \termly\Robots_Txt::add_allow_line(); 56 57 } else { 58 59 \termly\Robots_Txt::remove_allow_line(); 60 61 } 35 62 36 63 $type = 'updated'; -
uk-cookie-consent/trunk/includes/models/class-termly-api-model.php
r2567699 r3036964 83 83 84 84 } 85 86 } else {87 88 error_log( print_r( [ $response ], true ) );89 85 90 86 } -
uk-cookie-consent/trunk/readme.txt
r3009736 r3036964 5 5 Requires PHP: 5.6 6 6 Tested up to: 6.2 7 Stable tag: 3. 1.17 Stable tag: 3.2 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 126 126 == Changelog == 127 127 128 = 3.2 = 129 * New: There is a new setting on the site scan page to add a specific allow line to an existing or virtual (provided by WordPress core) robots.txt file. 130 * Update: Changed the text of the "allow" line in the robots.txt to accurately reflect the new scraper's name. 131 * Removed: The plugin will no longer automatically save the "allow" line to the robots.txt file when regenerating rewrite rules. 132 128 133 = 3.1.1 = 129 134 * Update: Updates the embed script on the consent banner to include some additional information needed for European privacy framework. -
uk-cookie-consent/trunk/uk-cookie-consent.php
r3009737 r3036964 4 4 * Plugin URI: https://termly.io/products/ 5 5 * Description: Our easy to use cookie consent plugin can assist in your GDPR and ePrivacy Directive compliance efforts. 6 * Version: 3. 1.16 * Version: 3.2 7 7 * Author: Termly 8 8 * Author URI: https://termly.io/ … … 78 78 define( 'TERMLY_BASENAME', plugin_basename( __FILE__ ) ); 79 79 define( 'TERMLY_API_BASE', 'https://app.termly.io/api' ); 80 define( 'TERMLY_VERSION', '3. 1' );80 define( 'TERMLY_VERSION', '3.2' ); 81 81 define( 'TERMLY_URL', plugin_dir_url( __FILE__ ) ); 82 82 define( 'TERMLY_PATH', plugin_dir_path( __FILE__ ) );
Note: See TracChangeset
for help on using the changeset viewer.