summaryrefslogtreecommitdiff
path: root/src/Readability.php
diff options
context:
space:
mode:
authorAndres Rey <[email protected]>2016-11-10 16:02:24 +0000
committerAndres Rey <[email protected]>2016-11-10 16:02:24 +0000
commitecda211428b058f6c7065bd9aec6c9465798677c (patch)
tree9b93e4764057e120709261d69eef1b24551fa194 /src/Readability.php
parenta65c0ee2921902cb6bc087680d458f0a714c118a (diff)
Refactored a bit, added comments to the functions
Diffstat (limited to 'src/Readability.php')
-rw-r--r--src/Readability.php45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/Readability.php b/src/Readability.php
index a792aeb..0740a08 100644
--- a/src/Readability.php
+++ b/src/Readability.php
@@ -309,6 +309,13 @@ class Readability extends Element implements ReadabilityInterface
return $this->node;
}
+ /**
+ * Removes the current node and returns the next node to be parsed (child, sibling or parent)
+ *
+ * @param Readability $node
+ *
+ * @return Readability
+ */
public function removeAndGetNext($node)
{
$nextNode = $this->getNextNode($node, true);
@@ -317,6 +324,16 @@ class Readability extends Element implements ReadabilityInterface
return $nextNode;
}
+ /**
+ * Returns the next node. First checks for childs (if the flag allows it), then for siblings, and finally
+ * for parents.
+ *
+ * @param Readability $originalNode
+ * @param bool $ignoreSelfAndKids
+ *
+ * @return Readability
+ */
+
public function getNextNode($originalNode, $ignoreSelfAndKids = false)
{
/*
@@ -346,4 +363,32 @@ class Readability extends Element implements ReadabilityInterface
return ($originalNode) ? new self($originalNode->node->nextSibling) : $originalNode;
}
+
+ /**
+ * Compares nodes. Checks for tag name and text content.
+ *
+ * It's a replacement of the original JS code, which looked like this:
+ *
+ * $node1 == $node2
+ *
+ * I'm not sure this works the same in PHP, so I created a mock function to check the actual content of the node.
+ * Should serve the same porpuse as the original comparison.
+ *
+ * @param Readability $node1
+ * @param Readability $node2
+ *
+ * @return bool
+ */
+ public function compareNodes($node1, $node2)
+ {
+ if ($node1->getTagName() !== $node2->getTagName()) {
+ return false;
+ }
+
+ if ($node1->getTextContent() !== $node2->getTextContent()) {
+ return false;
+ }
+
+ return true;
+ }
}