/** * Parse given Flickr Image element * * @param DomElement $image */ public function __construct(DomElement $image) { $this->uri = (string) $image->getAttribute('source'); $this->clickUri = (string) $image->getAttribute('url'); $this->height = (int) $image->getAttribute('height'); $this->width = (int) $image->getAttribute('width'); }
protected function setUp() { // Setup DOM $this->domDocument = new \DOMDocument('1', 'UTF-8'); $html = $this->domDocument->createElement('html'); $this->domAnchor = $this->domDocument->createElement('a', 'fake'); $this->domAnchor->setAttribute('href', 'http://php-spider.org/contact/'); $this->domDocument->appendChild($html); $html->appendChild($this->domAnchor); $this->uri = new DiscoveredUri(new Uri($this->domAnchor->getAttribute('href'))); // Setup Spider\Resource $content = $this->domDocument->saveHTML(); $this->spiderResource = new Resource($this->uri, new Response(200, [], $content)); }
/** * @param DomElement $domElement */ public static function hasClass(DomElement $domElement, $className) { $classString = $domElement->getAttribute('class'); if (empty($classString)) { return false; } return in_array($className, preg_split('/[\\s]+/', $classString)); }
public function run(\DomElement $element) { $transphporm = $element->getAttribute('transphporm'); if ($transphporm == 'remove') { $element->parentNode->removeChild($element); } else { $element->removeAttribute('transphporm'); } }
public function run($value, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { if ($element->getAttribute('transphporm') === 'remove') { return; } $value = $this->formatter->format($value, $rules); if (!$this->processPseudo($value, $element, $pseudoMatcher)) { //Remove the current contents $this->removeAllChildren($element); //Now make a text node if ($this->getContentMode($rules) === 'replace') { $this->replaceContent($element, $value); } else { $this->appendContent($element, $value); } } }
public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { $values = $this->fixEmpty($values); if ($element->getAttribute('transphporm') === 'added') { return $element->parentNode->removeChild($element); } $max = $this->getMax($values); $count = 0; foreach ($values[0] as $key => $iteration) { if ($count + 1 > $max) { break; } $clone = $this->cloneElement($element, $iteration, $key, $count++); //Re-run the hook on the new element, but use the iterated data //Don't run repeat on the clones element or it will loop forever unset($rules['repeat']); $this->createHook($rules, $pseudoMatcher, $properties)->run($clone); } //Remove the original element $element->parentNode->removeChild($element); return false; }
/** * Allocates member variables of currentElement with found attributes in XML Documenttype for element "field". * Parses for top elements "field" and their atrributes. * * @param DomElement $field * @param Publish_Model_FormElement $currentElement * * @return false: field has no attributes */ private function _parseAttributes(DomElement $field, $currentElement) { if ($field->hasAttributes()) { $elementName = $field->getAttribute('name'); $required = $field->getAttribute('required'); $formElement = $field->getAttribute('formelement'); $datatype = $field->getAttribute('datatype'); $multiplicity = $field->getAttribute('multiplicity'); if ($datatype === 'Enrichment') { if ($this->isValidEnrichmentKey($elementName)) { $elementName = 'Enrichment' . $elementName; } } if ($datatype == 'Collection' || $datatype == 'CollectionLeaf') { $collectionRole = $field->getAttribute('root'); $currentElement->setCollectionRole($collectionRole); $currentElement->setCurrentCollectionId(); } $this->zendConformElementName($elementName); $currentElement->setElementName($elementName); if ($required === 'yes') { $currentElement->setRequired(true); } else { $currentElement->setRequired(false); } $currentElement->setFormElement($formElement); $currentElement->setDatatype($datatype); $currentElement->setMultiplicity($multiplicity); } else { return false; } }
/** * @param \DomElement $node * * @return string */ protected function buildNavBarElementFromDomElement($node) { switch ($node->getAttribute('type')) { case 'Logo': $html = $this->getLogo($node); break; case 'NavMenu': $html = $this->getNavMenu($node); break; case 'PageTools': $html = $this->getPageTools($node); break; case 'SearchBar': $html = $this->getSearchBar($node); break; case 'PersonalTools': $html = $this->getPersonalTools(); break; case 'Menu': $html = $this->getMenu($node); break; default: $html = ''; } return $html; }
/** * Get Node Json * * @param mixed $node * @param int $level * @return array */ protected function _getNodeJson(DomElement $node, $level = 0) { $item = array(); $selres = $this->getSelectedResources(); if ($level != 0) { $item['text'] = Mage::helper('Mage_User_Helper_Data')->__((string) $node->getAttribute('title')); // @codingStandardsIgnoreStart $item['sortOrder'] = $node->hasAttribute('sortOrder') ? (string) $node->getAttribute('sortOrder') : 0; // @codingStandardsIgnoreEnd $item['id'] = (string) $node->getAttribute('id'); if (in_array($item['id'], $selres)) { $item['checked'] = true; } } $children = $node->childNodes; if (!empty($children)) { $item['children'] = array(); //$item['cls'] = 'fiche-node'; foreach ($children as $child) { if ($child instanceof DOMElement) { if (!(string) $child->getAttribute('title')) { continue; } if ($level != 0) { $item['children'][] = $this->_getNodeJson($child, $level + 1); } else { $item = $this->_getNodeJson($child, $level + 1); } } } usort($item['children'], array($this, '_sortTree')); } return $item; }
/** * Returns value given $attributeName on a link or embed element. * * If given $element is embed attribute value will be copied with a prefixed name. * * @param \DOMElement $element * @param string $attributeName * * @return string */ protected function getElementAttribute(DomElement $element, $attributeName) { // First try to return for link if ($element->localName === 'link') { return $element->getAttribute($attributeName); } // Second return for embed return $element->getAttribute(EmbedLinking::TEMP_PREFIX . $attributeName); }
public function run(array $args, \DomElement $element) { return $element->getAttribute(trim($args[0])); }
function __construct(DomElement $span) { if (strpos($span->getAttribute('class'), 'modconflict') !== false) { $this->conflict = true; } foreach ($span->childNodes as $child) { $text = $child->textContent; if (strpos($text, '(moderation-rejected-auto)') !== false) { $this->rejected_auto = true; } if (strpos($text, '(moderation-rejected-batch)') !== false) { $this->rejected_batch = true; } $matches = null; if (preg_match('/\\(moderation-whois-link: ([^)]*)\\)/', $text, $matches)) { $this->ip = $matches[1]; } } $links = $span->getElementsByTagName('a'); foreach ($links as $link) { if (strpos($link->getAttribute('class'), 'mw-userlink') !== false) { $text = $link->textContent; # This is # 1) either the user who made an edit, # 2) or the moderator who rejected it. # Let's check the text BEFORE this link for # the presence of 'moderation-rejected-by'. if (strpos($link->previousSibling->textContent, "moderation-rejected-by") !== false) { $this->rejected_by_user = $text; } else { $this->user = $text; } continue; } $href = $link->getAttribute('href'); switch ($link->nodeValue) { case '(moderation-show)': $this->showLink = $href; break; case '(moderation-approve)': $this->approveLink = $href; break; case '(moderation-approveall)': $this->approveAllLink = $href; break; case '(moderation-reject)': $this->rejectLink = $href; break; case '(moderation-rejectall)': $this->rejectAllLink = $href; break; case '(moderation-merge)': $this->mergeLink = $href; break; case '(moderation-merged-link)': $this->mergedDiffLink = $href; case '(moderation-block)': $this->blockLink = $href; break; case '(moderation-unblock)': $this->unblockLink = $href; break; default: $this->title = $link->textContent; } } $matches = null; preg_match('/modid=([0-9]+)/', $this->showLink, $matches); $this->id = $matches[1]; }