diff options
author | Andres Rey <[email protected]> | 2016-11-18 19:46:26 +0000 |
---|---|---|
committer | Andres Rey <[email protected]> | 2016-11-18 19:46:26 +0000 |
commit | 60227c697142a6a71cd521572becb2c0423f2fcd (patch) | |
tree | 20211e0a355557b0768d54a38cff222889e574f8 /src | |
parent | 060654dab569e9f3bef56bfedacdbf748678c4d0 (diff) |
Check for previously initialized nodes, restore the score and set the flag
Diffstat (limited to 'src')
-rw-r--r-- | src/Readability.php | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/Readability.php b/src/Readability.php index 543c088..3ba4538 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -54,10 +54,18 @@ class Readability extends Element implements ReadabilityInterface $score = 0; if (!in_array(get_class($node), ['DOMDocument', 'DOMComment'])) { - $score = $node->getAttribute('readability'); + $hasScore = $node->getAttribute('readability'); + if ($hasScore !== '') { + // Node was initialized previously. Restoring score and setting flag. + $this->initialized = true; + $score = $hasScore; + } else { + // Fresh, uninitialized node. + $score = 0; + } } - $this->setContentScore(($score) ? $score : 0); + $this->setContentScore($score); } } @@ -248,7 +256,7 @@ class Readability extends Element implements ReadabilityInterface { if (!in_array(get_class($this->node), ['DOMDocument', 'DOMComment'])) { - $this->contentScore = $score; + $this->contentScore = (float)$score; // Set score in an attribute of the tag to prevent losing it while creating new Readability objects. $this->node->setAttribute('readability', $this->contentScore); |