DataInconsistency
2 weeks ago
License
2 months ago
Notices
2 months ago
pQuery
2 months ago
APIPermissionHelper.php
1 year ago
CdnAssetUrl.php
3 years ago
ConflictResolver.php
1 month ago
Cookies.php
2 months ago
DBCollationChecker.php
2 months ago
DOM.php
2 years ago
DateConverter.php
3 years ago
FreeDomains.php
3 years ago
Headers.php
1 year ago
Helpers.php
1 month ago
Installation.php
1 year ago
LegacyDatabase.php
1 year ago
Request.php
2 months ago
SecondLevelDomainNames.php
3 years ago
Security.php
2 months ago
ThirdPartyOutput.php
1 month ago
Url.php
2 months ago
index.php
3 years ago
DOM.php
45 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Util; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoetVendor\pQuery\DomNode; |
| 9 | |
| 10 | class DOM { |
| 11 | /** |
| 12 | * Splits a DOM tree around the cut element, bringing it up to bound |
| 13 | * ancestor and splitting left and right siblings into subtrees along |
| 14 | * the way, retaining order and nesting level. |
| 15 | */ |
| 16 | public static function splitOn(DomNode $bound, DomNode $cutElement) { |
| 17 | $ignoreTextAndCommentNodes = false; |
| 18 | $grandparent = $cutElement->parent; |
| 19 | for ($parent = $cutElement->parent; $bound != $parent; $parent = $grandparent) { |
| 20 | // Clone parent node without children, but with attributes |
| 21 | $parent->after($parent->toString()); |
| 22 | $right = $parent->getNextSibling($ignoreTextAndCommentNodes); |
| 23 | $right->clear(); |
| 24 | |
| 25 | while ($sibling = $cutElement->getNextSibling($ignoreTextAndCommentNodes)) { |
| 26 | $sibling->move($right); |
| 27 | } |
| 28 | |
| 29 | // Reattach cut_element and right siblings to grandparent |
| 30 | $grandparent = $parent->parent; |
| 31 | $indexAfterParent = $parent->index() + 1; |
| 32 | $right->move($grandparent, $indexAfterParent); |
| 33 | $indexAfterParent = $parent->index() + 1; |
| 34 | $cutElement->move($grandparent, $indexAfterParent); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | public static function findTopAncestor(DomNode $item) { |
| 39 | while ($item->parent->parent !== null) { |
| 40 | $item = $item->parent; |
| 41 | } |
| 42 | return $item; |
| 43 | } |
| 44 | } |
| 45 |