| 1 |
<?php |
| 2 |
/** |
| 3 |
* Assisted Scan utilities. |
| 4 |
* |
| 5 |
* @package SureCookie\Inc\Modules\AssistedScan |
| 6 |
* @since 1.3.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace SureCookie\Inc\Modules\AssistedScan; |
| 10 |
|
| 11 |
use SureCookie\Inc\Modules\SiteScanner\SaasClient; |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; // Exit if accessed directly. |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Utils |
| 19 |
* |
| 20 |
* @since 1.3.0 |
| 21 |
*/ |
| 22 |
class Utils { |
| 23 |
/** |
| 24 |
* Page allowance when the site has no cached SaaS quota. |
| 25 |
* |
| 26 |
* Deliberately higher than the cloud scanner's default of 5: sites that need an |
| 27 |
* assisted scan are the ones whose registration or scan the host blocked, and an |
| 28 |
* unregistered site has no quota to read, so quota caching would otherwise cap a |
| 29 |
* paying customer at the free-tier allowance on the only scanner that works for them. |
| 30 |
* Assisted scanning costs no SaaS compute, only the admin's browser and time. Ten |
| 31 |
* covers home, shop, cart, checkout, contact, privacy and a few templates while |
| 32 |
* keeping the walk short enough that the admin sees it through. |
| 33 |
* |
| 34 |
* @since 1.3.0 |
| 35 |
*/ |
| 36 |
public const DEFAULT_MAX_PAGES = 10; |
| 37 |
|
| 38 |
/** |
| 39 |
* Whether the Assisted Scan feature is available on this site. |
| 40 |
* |
| 41 |
* The kill switch: it clears cookies and drives a real browser tab, so support must |
| 42 |
* be able to disable it with a snippet, not a patch release. False removes the REST |
| 43 |
* routes, front-end collector and admin entry point. |
| 44 |
* |
| 45 |
* @since 1.3.0 |
| 46 |
* @return bool |
| 47 |
*/ |
| 48 |
public static function is_enabled(): bool { |
| 49 |
/** |
| 50 |
* Filter whether Assisted Scan is available. |
| 51 |
* |
| 52 |
* @since 1.3.0 |
| 53 |
* @param bool $enabled Whether the feature is enabled. |
| 54 |
*/ |
| 55 |
return (bool) apply_filters( 'surecookie_assisted_scan_enabled', true ); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Max pages per assisted walk: SaaS quota cache, else {@see self::DEFAULT_MAX_PAGES}. |
| 60 |
* |
| 61 |
* @since 1.3.0 |
| 62 |
* @return int |
| 63 |
*/ |
| 64 |
public static function get_max_pages(): int { |
| 65 |
$cached = SaasClient::get_instance()->get_cached_quota(); |
| 66 |
|
| 67 |
if ( ! empty( $cached['pages_per_scan_limit'] ) ) { |
| 68 |
return (int) $cached['pages_per_scan_limit']; |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Filter the assisted-scan page allowance used when no SaaS quota is cached. |
| 73 |
* |
| 74 |
* @since 1.3.0 |
| 75 |
* @param int $max_pages Maximum pages an assisted walk may visit. |
| 76 |
*/ |
| 77 |
$max_pages = (int) apply_filters( 'surecookie_assisted_max_scan_pages', self::DEFAULT_MAX_PAGES ); |
| 78 |
|
| 79 |
return $max_pages > 0 ? $max_pages : self::DEFAULT_MAX_PAGES; |
| 80 |
} |
| 81 |
} |
| 82 |
|