Blocks
2 months ago
Columns
5 months ago
PostProcess
5 days ago
BodyRenderer.php
2 months ago
EscapeHelper.php
2 years ago
Preprocessor.php
1 year ago
Renderer.php
1 month ago
StylesHelper.php
2 months ago
Template.html
2 months ago
index.php
3 years ago
EscapeHelper.php
57 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Newsletter\Renderer; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | class EscapeHelper { |
| 9 | /** |
| 10 | * @param string $string |
| 11 | * @return string |
| 12 | */ |
| 13 | public static function escapeHtmlText($string) { |
| 14 | return htmlspecialchars((string)$string, ENT_NOQUOTES, 'UTF-8'); |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * @param string $string |
| 19 | * @return string |
| 20 | */ |
| 21 | public static function escapeHtmlAttr($string) { |
| 22 | return htmlspecialchars((string)$string, ENT_QUOTES, 'UTF-8'); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Escapes Style attributes, but preserves single quotes. Some email clients |
| 27 | * (e.g. Yahoo webmail) don't support encoded quoted font names. |
| 28 | * Previously used htmlspecialchars but switched to esc_attr which is more appropriate. |
| 29 | * @param string $string |
| 30 | * @return string |
| 31 | */ |
| 32 | public static function escapeHtmlStyleAttr($string) { |
| 33 | return str_replace(''', "'", esc_attr((string)$string)); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @param string $string |
| 38 | * @return string |
| 39 | */ |
| 40 | public static function unescapeHtmlStyleAttr($string) { |
| 41 | // This decodes entities which may have been added by esc_attr. |
| 42 | return htmlspecialchars_decode((string)$string, ENT_QUOTES); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @param string $string |
| 47 | * @return string |
| 48 | */ |
| 49 | public static function escapeHtmlLinkAttr($string) { |
| 50 | $string = self::escapeHtmlAttr($string); |
| 51 | if (preg_match('/\s*(javascript:|data:text|data:application)/ui', $string) === 1) { |
| 52 | return ''; |
| 53 | } |
| 54 | return $string; |
| 55 | } |
| 56 | } |
| 57 |