diff options
author | Andres Rey <[email protected]> | 2016-11-27 00:13:34 +0000 |
---|---|---|
committer | Andres Rey <[email protected]> | 2016-11-27 00:13:34 +0000 |
commit | 17d67164ea2632fc5121f35602bb52386aaeaf27 (patch) | |
tree | 0d7351ede975f0aad6346f3be05f92c173ef35d9 /src/Readability.php | |
parent | 48d99d0e4bb6657aaa1d4428d60dc47c51fb0565 (diff) |
Added cleanConditionally
Diffstat (limited to 'src/Readability.php')
-rw-r--r-- | src/Readability.php | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/Readability.php b/src/Readability.php index a6390c9..d647e63 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -453,4 +453,29 @@ class Readability extends Element implements ReadabilityInterface return false; } + + /** + * Check if a given node has one of its ancestor tag name matching the + * provided one. + * + * @param Readability $node + * @param string $tagName + * @param int $maxDepth + * @return bool + */ + public function hasAncestorTag(Readability $node, $tagName, $maxDepth = 3) + { + $depth = 0; + while ($node->getParent()) { + if ($depth > $maxDepth) { + return false; + } + if ($node->getParent()->tagNameEqualsTo($tagName)) { + return true; + } + $node = $node->getParent(); + $depth++; + } + return false; + } } |