* @author Roman Ožana * @author Sander Kruger * @author Zoli Szabó */ class Emogrifier { /** * @var int */ const CACHE_KEY_CSS = 0; /** * @var int */ const CACHE_KEY_SELECTOR = 1; /** * @var int */ const CACHE_KEY_XPATH = 2; /** * @var int */ const CACHE_KEY_CSS_DECLARATIONS_BLOCK = 3; /** * @var int */ const CACHE_KEY_COMBINED_STYLES = 4; /** * for calculating nth-of-type and nth-child selectors * * @var int */ const INDEX = 0; /** * for calculating nth-of-type and nth-child selectors * * @var int */ const MULTIPLIER = 1; /** * @var string */ const ID_ATTRIBUTE_MATCHER = '/(\\w+)?\\#([\\w\\-]+)/'; /** * @var string */ const CLASS_ATTRIBUTE_MATCHER = '/(\\w+|[\\*\\]])?((\\.[\\w\\-]+)+)/'; /** * Regular expression component matching a static pseudo class in a selector, without the preceding ":", * for which the applicable elements can be determined (by converting the selector to an XPath expression). * (Contains alternation without a group and is intended to be placed within a capturing, non-capturing or lookahead * group, as appropriate for the usage context.) * * @var string */ const PSEUDO_CLASS_MATCHER = '(?:first|last|nth)-child|nth-of-type|not\\([[:ascii:]]*\\)'; /** * @var string */ const CONTENT_TYPE_META_TAG = ''; /** * @var string */ const DEFAULT_DOCUMENT_TYPE = ''; /** * @var string Regular expression part to match tag names that PHP's DOMDocument implementation is not aware are * self-closing. These are mostly HTML5 elements, but for completeness (obsolete) and * (deprecated) are also included. * * @see https://bugs.php.net/bug.php?id=73175 */ const PHP_UNRECOGNIZED_VOID_TAGNAME_MATCHER = '(?:command|embed|keygen|source|track|wbr)'; /** * @var \DOMDocument */ protected $domDocument = null; /** * @var \DOMXPath */ protected $xPath = null; /** * @var string */ private $css = ''; /** * @var bool[] */ private $excludedSelectors = []; /** * @var string[] */ private $unprocessableHtmlTags = ['wbr']; /** * @var bool[] */ private $allowedMediaTypes = ['all' => true, 'screen' => true, 'print' => true]; /** * @var mixed[] */ private $caches = [ self::CACHE_KEY_CSS => [], self::CACHE_KEY_SELECTOR => [], self::CACHE_KEY_XPATH => [], self::CACHE_KEY_CSS_DECLARATIONS_BLOCK => [], self::CACHE_KEY_COMBINED_STYLES => [], ]; /** * the visited nodes with the XPath paths as array keys * * @var \DOMElement[] */ private $visitedNodes = []; /** * the styles to apply to the nodes with the XPath paths as array keys for the outer array * and the attribute names/values as key/value pairs for the inner array * * @var string[][] */ private $styleAttributesForNodes = []; /** * Determines whether the "style" attributes of tags in the the HTML passed to this class should be preserved. * If set to false, the value of the style attributes will be discarded. * * @var bool */ private $isInlineStyleAttributesParsingEnabled = true; /** * Determines whether the