/** * Add scene components * * @param array $components * @return void */ public function appendSceneComponents(array $components) { foreach ($components as $component) { /* * Check does component has any attributes to add to scene DOM element. * default attributes most of cases are ommited so we might not have any attributes to add */ if ($component->hasDOMAttributes()) { $this->scene->setAttributeNode($component->getDOMAttr()); } } }
/** * @param \DOMElement $parent * @param \DOMAttr $source */ private function importAttribute(\DOMElement $parent, \DOMAttr $source) { $document = $parent instanceof \DOMDocument ? $parent : $parent->ownerDocument; $namespaceUri = $this->getMappedNamespace($source->namespaceURI); if (empty($namespaceUri) || empty($source->prefix)) { $attribute = $document->createAttribute($source->localName); } else { $attribute = $document->createAttributeNS($namespaceUri, $source->nodeName); } $attribute->value = $source->value; $parent->setAttributeNode($attribute); }
/** * Initialize a node with the readability object. Also checks the * className/id for special names to add to its score. * * @param \DOMElement $node */ protected function initializeNode($node) { if (!isset($node->tagName)) { return; } $readability = $this->dom->createAttribute('readability'); // this is our contentScore $readability->value = 0; $node->setAttributeNode($readability); // using strtoupper just in case switch (strtoupper($node->tagName)) { case 'ARTICLE': $readability->value += 15; case 'DIV': $readability->value += 5; break; case 'PRE': case 'CODE': case 'TD': case 'BLOCKQUOTE': case 'FIGURE': $readability->value += 3; break; case 'SECTION': // often misused // $readability->value += 2; break; case 'OL': case 'UL': case 'DL': case 'DD': case 'DT': case 'LI': $readability->value -= 2 * round($this->getLinkDensity($node), 0, PHP_ROUND_HALF_UP); break; case 'ASIDE': case 'FOOTER': case 'HEADER': case 'ADDRESS': case 'FORM': case 'BUTTON': case 'TEXTAREA': case 'INPUT': case 'NAV': $readability->value -= 3; break; case 'H1': case 'H2': case 'H3': case 'H4': case 'H5': case 'H6': case 'TH': case 'HGROUP': $readability->value -= 5; break; } $readability->value += $this->getWeight($node); }
/** * Helper to add a attribute * * @param DOMElement $parent * @param string $name * @param mixed $value * * @return void */ protected function _addAttr($parent, $name, $value) { $parent->setAttributeNode(new DOMAttr($name, $value)); }
/** * Style attribute gets it's own setter as it's more complex than typical * * @param bool $returnAttr * @return DOMElementPlus|\DOMAttr */ protected function _setStyleAttributeValue($returnAttr = false) { if ($this->hasAttribute('style')) { $attr = $this->getAttributeNode('style'); $attr->value = $this->_getStyleAttributeString(); } else { $attr = new \DOMAttr('style', $this->_getStyleAttributeString()); parent::setAttributeNode($attr); } return $returnAttr ? $attr : $this; }