summaryrefslogtreecommitdiff
path: root/src/Nodes
diff options
context:
space:
mode:
authorAndres Rey <[email protected]>2017-12-01 20:44:35 +0000
committerAndres Rey <[email protected]>2017-12-01 20:44:35 +0000
commitecebda06241ff34eac70b247c74175b162902582 (patch)
treec919efcf1b013cbd7f1221596328f93e0b54e367 /src/Nodes
parent8a266f2cae5dce8d1fa39c40caac8400406898bb (diff)
parenta2eded4e4df7e48a6f20d9e0449c52bf8003c471 (diff)
Merge remote-tracking branch 'origin/v1.0' into v1.0
# Conflicts: # src/NodeClass/DOMNode.php # src/Readability.php
Diffstat (limited to 'src/Nodes')
-rw-r--r--src/Nodes/DOMDocument.php2
-rw-r--r--src/Nodes/NodeTrait.php34
-rw-r--r--src/Nodes/NodeUtility.php15
3 files changed, 34 insertions, 17 deletions
diff --git a/src/Nodes/DOMDocument.php b/src/Nodes/DOMDocument.php
index f954f7d..510cdf2 100644
--- a/src/Nodes/DOMDocument.php
+++ b/src/Nodes/DOMDocument.php
@@ -14,7 +14,7 @@ class DOMDocument extends \DOMDocument
$this->registerNodeClass('DOMCdataSection', DOMCdataSection::class);
$this->registerNodeClass('DOMCharacterData', DOMCharacterData::class);
$this->registerNodeClass('DOMComment', DOMComment::class);
- $this->registerNodeClass('DOMDocument', DOMDocument::class);
+ $this->registerNodeClass('DOMDocument', self::class);
$this->registerNodeClass('DOMDocumentFragment', DOMDocumentFragment::class);
$this->registerNodeClass('DOMDocumentType', DOMDocumentType::class);
$this->registerNodeClass('DOMElement', DOMElement::class);
diff --git a/src/Nodes/NodeTrait.php b/src/Nodes/NodeTrait.php
index 3294612..5847178 100644
--- a/src/Nodes/NodeTrait.php
+++ b/src/Nodes/NodeTrait.php
@@ -5,20 +5,27 @@ namespace andreskrey\Readability\Nodes;
trait NodeTrait
{
/**
- * Content score of the node. Used to determine the value of the content
+ * Content score of the node. Used to determine the value of the content.
*
* @var int
*/
public $contentScore = 0;
/**
- * Flag for initialized status
+ * Flag for initialized status.
*
* @var bool
*/
private $initialized = false;
/**
+ * Flag data tables.
+ *
+ * @var bool
+ */
+ private $readabilityDataTable = false;
+
+ /**
* @var array
*/
private $divToPElements = [
@@ -36,7 +43,7 @@ trait NodeTrait
];
/**
- * initialized getter
+ * initialized getter.
*
* @return bool
*/
@@ -46,11 +53,28 @@ trait NodeTrait
}
/**
+ * @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?
*
* @param $weightClasses bool Weight classes?
+ *
* @return static
*/
public function initializeNode($weightClasses)
@@ -179,7 +203,6 @@ trait NodeTrait
return $linkLength / $textLength;
}
-
/**
* Calculates the weight of the class/id of the current element.
*
@@ -281,11 +304,10 @@ trait NodeTrait
return ['rows' => $rows, 'columns' => $columns];
}
-
/**
* Creates a new node based on the text content of the original node.
*
- * @param $originalNode DOMElement
+ * @param $originalNode DOMNode
* @param $tagName string
*
* @return DOMElement
diff --git a/src/Nodes/NodeUtility.php b/src/Nodes/NodeUtility.php
index f35e9c5..8938a49 100644
--- a/src/Nodes/NodeUtility.php
+++ b/src/Nodes/NodeUtility.php
@@ -3,14 +3,12 @@
namespace andreskrey\Readability\Nodes;
/**
- * Class NodeUtility
- * @package andreskrey\Readability
+ * Class NodeUtility.
*/
class NodeUtility
{
-
/**
- * Collection of regexps to check the node usability
+ * Collection of regexps to check the node usability.
*
* @var array
*/
@@ -32,12 +30,11 @@ class NodeUtility
'onlyWhitespace' => '/\x{00A0}|\s+/u'
];
-
/**
- *
- * Imported from the Element class on league\html-to-markdown
+ * Imported from the Element class on league\html-to-markdown.
*
* @param $node
+ *
* @return DOMElement
*/
public static function nextElement($node)
@@ -52,13 +49,13 @@ class NodeUtility
return $next;
}
-
/**
* Changes the node tag name. Since tagName on DOMElement is a read only value, this must be done creating a new
* element with the new tag name and importing it to the main DOMDocument.
*
* @param string $value
* @param bool $importAttributes
+ *
* @return DOMNode
*/
public static function setNodeTag($node, $value, $importAttributes = false)
@@ -68,7 +65,6 @@ class NodeUtility
$children = $node->childNodes;
/** @var $children \DOMNodeList $i */
-
for ($i = 0; $i < $children->length; $i++) {
$import = $new->importNode($children->item($i), true);
$new->firstChild->appendChild($import);
@@ -118,7 +114,6 @@ class NodeUtility
}
}
-
/**
* Returns the next node. First checks for children (if the flag allows it), then for siblings, and finally
* for parents.