<?php namespace MailPoet\Models; if (!defined('ABSPATH')) exit; use MailPoet\Util\Helpers; use MailPoet\WP\Functions as WPFunctions; class ModelValidator extends \MailPoetVendor\Sudzy\Engine { public $validators; const EMAIL_MIN_LENGTH = 6; const EMAIL_MAX_LENGTH = 150; const ROLE_EMAILS = [ 'abuse', 'compliance', 'devnull', 'dns', 'ftp', 'hostmaster', 'inoc', 'ispfeedback', 'ispsupport', 'list-request', 'list', 'maildaemon', 'noc', 'no-reply', 'noreply', 'nospam', 'null', 'phish', 'phishing', 'postmaster', 'privacy', 'registrar', 'root', 'security', 'spam', 'sysadmin', 'undisclosed-recipients', 'unsubscribe', 'usenet', 'uucp', 'webmaster', 'www', ]; public function __construct() { parent::__construct(); $this->validators = [ 'validEmail' => 'validateEmail', 'validRenderedNewsletterBody' => 'validateRenderedNewsletterBody', ]; $this->setupValidators(); } private function setupValidators() { $_this = $this; foreach ($this->validators as $validator => $action) { $this->addValidator($validator, function($params) use ($action, $_this) { $callback = [$_this, $action]; if (is_callable($callback)) { return call_user_func($callback, $params); } }); } } public function validateEmail($email) { $permittedLength = (strlen($email) >= self::EMAIL_MIN_LENGTH && strlen($email) <= self::EMAIL_MAX_LENGTH); $validEmail = WPFunctions::get()->isEmail($email) !== false && parent::_isEmail($email, null); return ($permittedLength && $validEmail); } public function validateNonRoleEmail($email) { if (!$this->validateEmail($email)) return false; $firstPart = strtolower(substr($email, 0, (int)strpos($email, '@'))); return array_search($firstPart, self::ROLE_EMAILS) === false; } public function validateRenderedNewsletterBody($newsletterBody) { if (is_serialized($newsletterBody)) { $newsletterBody = unserialize($newsletterBody); } else if (Helpers::isJson($newsletterBody)) { $newsletterBody = json_decode($newsletterBody, true); } return (is_null($newsletterBody) || (is_array($newsletterBody) && !empty($newsletterBody['html']) && !empty($newsletterBody['text']))); } public function validateIPAddress(string $ip): bool { return (bool)filter_var($ip, FILTER_VALIDATE_IP); } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
CustomField.php | File | 3.79 KB | 0644 |
|
DynamicSegment.php | File | 4.05 KB | 0644 |
|
DynamicSegmentFilter.php | File | 1.35 KB | 0644 |
|
Form.php | File | 4.02 KB | 0644 |
|
MappingToExternalEntities.php | File | 378 B | 0644 |
|
Model.php | File | 13.58 KB | 0644 |
|
ModelValidator.php | File | 2.44 KB | 0644 |
|
Newsletter.php | File | 15.14 KB | 0644 |
|
NewsletterLink.php | File | 530 B | 0644 |
|
NewsletterOption.php | File | 670 B | 0644 |
|
NewsletterOptionField.php | File | 939 B | 0644 |
|
NewsletterSegment.php | File | 312 B | 0644 |
|
ScheduledTask.php | File | 6.58 KB | 0644 |
|
ScheduledTaskSubscriber.php | File | 5.31 KB | 0644 |
|
Segment.php | File | 10.89 KB | 0644 |
|
SendingQueue.php | File | 4.31 KB | 0644 |
|
StatisticsClicks.php | File | 1.08 KB | 0644 |
|
StatisticsForms.php | File | 1.85 KB | 0644 |
|
StatisticsNewsletters.php | File | 1.61 KB | 0644 |
|
StatisticsOpens.php | File | 807 B | 0644 |
|
StatisticsUnsubscribes.php | File | 821 B | 0644 |
|
StatisticsWooCommercePurchases.php | File | 1.5 KB | 0644 |
|
Subscriber.php | File | 20.83 KB | 0644 |
|
SubscriberCustomField.php | File | 2.5 KB | 0644 |
|
SubscriberIP.php | File | 1.12 KB | 0644 |
|
SubscriberSegment.php | File | 5.2 KB | 0644 |
|
index.php | File | 0 B | 0644 |
|