summaryrefslogtreecommitdiff
path: root/src/Readability.php
diff options
context:
space:
mode:
authorAndres Rey <[email protected]>2016-11-22 15:39:21 +0000
committerAndres Rey <[email protected]>2016-11-22 15:39:21 +0000
commitcba167695482cca7492303e3de1f59333c0127b6 (patch)
tree1d8e9900642a16476ff15751ee1ef09f3c20cad5 /src/Readability.php
parent37dba87cce8498abaa4ef4c1892a83585abd2c43 (diff)
Removed old reference to elementsToScore, switched the moment when elements are initialized
Diffstat (limited to 'src/Readability.php')
-rw-r--r--src/Readability.php43
1 files changed, 20 insertions, 23 deletions
diff --git a/src/Readability.php b/src/Readability.php
index f7a2e3d..7c04044 100644
--- a/src/Readability.php
+++ b/src/Readability.php
@@ -44,30 +44,27 @@ class Readability extends Element implements ReadabilityInterface
{
parent::__construct($node);
- if (get_class($node) !== 'DOMText') {
- /*
- * Restore the score if the object has been already scored.
- *
- * An if must be added before calling the getAttribute function, because if we reach the DOMDocument
- * by getting the node parents we'll get a undefined function fatal error
- */
- $score = 0;
-
- // Check if the getAttribute method exists, as some elements lack of it (and calling it anyway throws an exception)
- if (method_exists($node, 'getAttribute')) {
- $hasScore = $node->getAttribute('data-readability');
- if ($hasScore !== '') {
- // Node was initialized previously. Restoring score and setting flag.
- $this->initialized = true;
- $score = $hasScore;
- } else {
- // Fresh, uninitialized node.
- $score = 0;
- }
+ /*
+ * Restore the score if the object has been already scored.
+ *
+ * An if must be added before calling the getAttribute function, because if we reach the DOMDocument
+ * by getting the node parents we'll get a undefined function fatal error
+ */
+ $score = 0;
+
+ // Check if the getAttribute method exists, as some elements lack of it (and calling it anyway throws an exception)
+ if (method_exists($node, 'getAttribute')) {
+ if ($node->hasAttribute('data-readability')) {
+ // Node was initialized previously. Restoring score and setting flag.
+ $this->initialized = true;
+ $score = $node->getAttribute('data-readability');
+ } else {
+ // Fresh, uninitialized node.
+ $score = 0;
}
-
- $this->setContentScore($score);
}
+
+ $this->setContentScore($score);
}
/**
@@ -102,7 +99,7 @@ class Readability extends Element implements ReadabilityInterface
$node = $this->getParent();
while ($node) {
- $ancestors[] = $node->initializeNode();
+ $ancestors[] = $node;
$level++;
if ($level >= $maxLevel) {
break;