diff options
author | Andres Rey <[email protected]> | 2017-12-01 17:54:28 +0000 |
---|---|---|
committer | Andres Rey <[email protected]> | 2017-12-01 17:54:28 +0000 |
commit | a2eded4e4df7e48a6f20d9e0449c52bf8003c471 (patch) | |
tree | ba04e036dc4d713020c7a45ecfb04385c239446a | |
parent | 460e936bff25821ecb2685be54468390c8ddb4de (diff) |
Add readabilityDataTable param with getters and setters
-rw-r--r-- | src/NodeClass/NodeClassTrait.php | 23 | ||||
-rw-r--r-- | src/Readability.php | 18 |
2 files changed, 32 insertions, 9 deletions
diff --git a/src/NodeClass/NodeClassTrait.php b/src/NodeClass/NodeClassTrait.php index 4c1442b..ae3eeb1 100644 --- a/src/NodeClass/NodeClassTrait.php +++ b/src/NodeClass/NodeClassTrait.php @@ -21,6 +21,13 @@ trait NodeClassTrait private $initialized = false; /** + * Flag data tables. + * + * @var bool + */ + private $readabilityDataTable = false; + + /** * @var array */ private $divToPElements = [ @@ -48,6 +55,22 @@ trait NodeClassTrait } /** + * @return bool + */ + public function isReadabilityDataTable() + { + return $this->readabilityDataTable; + } + + /** + * @param bool $param + */ + public function setReadabilityDataTable($param) + { + $this->readabilityDataTable = $param; + } + + /** * Initializer. Calculates the current score of the node and returns a full Readability object. * * @ TODO: I don't like the weightClasses param. How can we get the config here? diff --git a/src/Readability.php b/src/Readability.php index ea1595a..db0774a 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -1088,47 +1088,47 @@ class Readability /** @var DOMElement $table */ $role = $table->getAttribute('role'); if ($role === 'presentation') { - $table->readabilityDataTable = false; + $table->setReadabilityDataTable(false); continue; } $datatable = $table->getAttribute('datatable'); if ($datatable == '0') { - $table->readabilityDataTable = false; + $table->setReadabilityDataTable(false); continue; } $summary = $table->getAttribute('summary'); if ($summary) { - $table->readabilityDataTable = true; + $table->setReadabilityDataTable(true); continue; } $caption = $table->getElementsByTagName('caption'); if ($caption->length > 0 && $caption->item(0)->childNodes->length > 0) { - $table->readabilityDataTable = true; + $table->setReadabilityDataTable(true); continue; } // If the table has a descendant with any of these tags, consider a data table: foreach (['col', 'colgroup', 'tfoot', 'thead', 'th'] as $dataTableDescendants) { if ($table->getElementsByTagName($dataTableDescendants)->length > 0) { - $table->readabilityDataTable = true; + $table->setReadabilityDataTable(true); continue 2; } } // Nested tables indicate a layout table: if ($table->getElementsByTagName('table')->length > 0) { - $table->readabilityDataTable = false; + $table->setReadabilityDataTable(false); continue; } $sizeInfo = $table->getRowAndColumnCount(); if ($sizeInfo['rows'] >= 10 || $sizeInfo['columns'] > 4) { - $table->readabilityDataTable = true; + $table->setReadabilityDataTable(true); continue; } // Now just go by size entirely: - $table->readabilityDataTable = $sizeInfo['rows'] * $sizeInfo['columns'] > 10; + $table->setReadabilityDataTable($sizeInfo['rows'] * $sizeInfo['columns'] > 10); } } @@ -1245,7 +1245,7 @@ class Readability $node = $DOMNodeList->item($length - 1 - $i); // First check if we're in a data table, in which case don't remove us. - if ($node->hasAncestorTag($node, 'table', -1) && isset($node->readabilityDataTable)) { + if ($node->hasAncestorTag($node, 'table', -1) && $node->isReadabilityDataTable()) { continue; } |