<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing namespace MailPoet\Newsletter; if (!defined('ABSPATH')) exit; class ApiDataSanitizer { /** @var NewsletterHtmlSanitizer */ private $htmlSanitizer; /** * Configuration specifies which block types and properties within newsletters content blocks are sanitized */ private const SANITIZATION_CONFIG = [ 'header' => ['text'], 'footer' => ['text'], 'text' => ['text'], ]; public function __construct( NewsletterHtmlSanitizer $htmlSanitizer ) { $this->htmlSanitizer = $htmlSanitizer; } public function sanitizeBody(array $body): array { if (isset($body['content']) && isset($body['content']['blocks']) && is_array($body['content']['blocks'])) { $body['content']['blocks'] = $this->sanitizeBlocks($body['content']['blocks']); } return $body; } private function sanitizeBlocks(array $blocks): array { foreach ($blocks as $key => $block) { if (!is_array($block) || !isset($block['type'])) { continue; } if (isset($block['blocks']) && is_array($block['blocks'])) { $blocks[$key]['blocks'] = $this->sanitizeBlocks($block['blocks']); } else { $blocks[$key] = $this->sanitizeBlock($block); } }; return $blocks; } private function sanitizeBlock(array $block): array { if (!isset(self::SANITIZATION_CONFIG[$block['type']])) { return $block; } foreach (self::SANITIZATION_CONFIG[$block['type']] as $property) { if (!isset($block[$property])) { continue; } $block[$property] = $this->htmlSanitizer->sanitize($block[$property]); } return $block; } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
Editor | Folder | 0755 |
|
|
Links | Folder | 0755 |
|
|
Listing | Folder | 0755 |
|
|
Options | Folder | 0755 |
|
|
Preview | Folder | 0755 |
|
|
Renderer | Folder | 0755 |
|
|
Scheduler | Folder | 0755 |
|
|
Segment | Folder | 0755 |
|
|
Sending | Folder | 0755 |
|
|
Shortcodes | Folder | 0755 |
|
|
Statistics | Folder | 0755 |
|
|
ViewInBrowser | Folder | 0755 |
|
|
ApiDataSanitizer.php | File | 1.69 KB | 0644 |
|
AutomatedLatestContent.php | File | 4.34 KB | 0644 |
|
AutomaticEmailsRepository.php | File | 2.1 KB | 0644 |
|
BlockPostQuery.php | File | 5.9 KB | 0644 |
|
NewsletterCoupon.php | File | 1.08 KB | 0644 |
|
NewsletterDeleteController.php | File | 6.85 KB | 0644 |
|
NewsletterHtmlSanitizer.php | File | 2.94 KB | 0644 |
|
NewsletterPostsRepository.php | File | 1.01 KB | 0644 |
|
NewsletterSaveController.php | File | 17.11 KB | 0644 |
|
NewsletterValidator.php | File | 4.59 KB | 0644 |
|
NewslettersRepository.php | File | 21.2 KB | 0644 |
|
Url.php | File | 2.27 KB | 0644 |
|
index.php | File | 6 B | 0644 |
|