| @@ -3,9 +3,12 @@ | ||
| 3 | 3 | namespace Extendify\Notifications; |
| 4 | 4 | |
| 5 | 5 | defined('ABSPATH') || die('No direct access.'); |
| 6 | 6 | |
| 7 | +use Extendify\Config; | |
| 7 | 8 | use Extendify\PartnerData; |
| 9 | +use Extendify\SiteVisibility; | |
| 10 | +use Extendify\SiteSettings; | |
| 8 | 11 | |
| 9 | 12 | /** |
| 10 | 13 | * The site conditions a notification can ask to be gated on, each mapped to the |
| 11 | 14 | * predicate that answers it. A notification without a trigger is unconditional. |
| @@ -14,10 +17,16 @@ | ||
| 14 | 17 | { |
| 15 | 18 | // phpcs:ignore PSR12.Properties.ConstantVisibility.NotFound -- 7.0 floor: no const visibility |
| 16 | 19 | const PREDICATES = [ |
| 17 | 20 | 'trial-domain' => 'onTrialDomain', |
| 21 | + 'unpublished' => 'siteUnpublished', | |
| 22 | + 'trial-block' => 'onExpiredTrialDomain', | |
| 23 | + 'search-engine-block' => 'searchEnginesBlocked', | |
| 18 | 24 | ]; |
| 19 | 25 | |
| 26 | + // phpcs:ignore PSR12.Properties.ConstantVisibility.NotFound -- 7.0 floor: no const visibility | |
| 27 | + const TRIAL_WINDOW_DAYS = 16; | |
| 28 | + | |
| 20 | 29 | public static function passes($trigger) |
| 21 | 30 | { |
| 22 | 31 | if ($trigger === null || $trigger === '') { |
| 23 | 32 | return true; |
| @@ -29,8 +38,20 @@ | ||
| 29 | 38 | |
| 30 | 39 | return call_user_func([self::class, self::PREDICATES[$trigger]]); |
| 31 | 40 | } |
| 32 | 41 | |
| 42 | + private static function siteUnpublished() | |
| 43 | + { | |
| 44 | + return !SiteVisibility::isPublished(); | |
| 45 | + } | |
| 46 | + | |
| 47 | + private static function searchEnginesBlocked() | |
| 48 | + { | |
| 49 | + return PartnerData::setting('useSearchEngineBlock') | |
| 50 | + && SiteVisibility::searchEnginesBlocked() | |
| 51 | + && (PartnerData::setting('showAIAgents') || Config::preview('ai-agent')); | |
| 52 | + } | |
| 53 | + | |
| 33 | 54 | // Substring match, mirroring the domain-suggestion matcher in src/Assist/lib/domains.js. |
| 34 | 55 | private static function onTrialDomain() |
| 35 | 56 | { |
| 36 | 57 | $host = strtolower((string) \wp_parse_url(\home_url(), PHP_URL_HOST)); |
| @@ -43,6 +64,24 @@ | ||
| 43 | 64 | } |
| 44 | 65 | } |
| 45 | 66 | |
| 46 | 67 | return false; |
| 68 | + } | |
| 69 | + | |
| 70 | + private static function onExpiredTrialDomain() | |
| 71 | + { | |
| 72 | + return self::onTrialDomain() && self::olderThanTrialWindow(); | |
| 73 | + } | |
| 74 | + | |
| 75 | + private static function olderThanTrialWindow() | |
| 76 | + { | |
| 77 | + $createdAt = SiteSettings::getSiteCreatedAt(); | |
| 78 | + $createdAt = $createdAt === null ? false : strtotime($createdAt); | |
| 79 | + | |
| 80 | + // A zero MySQL date parses to a negative timestamp, not false, and must not block. | |
| 81 | + if ($createdAt === false || $createdAt <= 0) { | |
| 82 | + return false; | |
| 83 | + } | |
| 84 | + | |
| 85 | + return $createdAt <= (time() - (self::TRIAL_WINDOW_DAYS * DAY_IN_SECONDS)); | |
| 47 | 86 | } |
| 48 | 87 | } |