/** * Check the status of a single link on a page * * @param BrokenExternalPageTrack $pageTrack * @param DOMNode $link */ protected function checkPageLink(BrokenExternalPageTrack $pageTrack, DOMNode $link) { $class = $link->getAttribute('class'); $href = $link->getAttribute('href'); $markedBroken = preg_match('/\\b(ss-broken)\\b/', $class); // Check link $httpCode = $this->linkChecker->checkLink($href); if ($httpCode === null) { return; } // Null link means uncheckable, such as an internal link // If this code is broken then mark as such if ($foundBroken = $this->isCodeBroken($httpCode)) { // Create broken record $brokenLink = new BrokenExternalLink(); $brokenLink->Link = $href; $brokenLink->HTTPCode = $httpCode; $brokenLink->TrackID = $pageTrack->ID; $brokenLink->StatusID = $pageTrack->StatusID; // Slight denormalisation here for performance reasons $brokenLink->write(); } // Check if we need to update CSS class, otherwise return if ($markedBroken == $foundBroken) { return; } if ($foundBroken) { $class .= ' ss-broken'; } else { $class = preg_replace('/\\s*\\b(ss-broken)\\b\\s*/', ' ', $class); } $link->setAttribute('class', trim($class)); }
/** * Draw a final layout zone on its thumbnail. * * @access private * * @param ressource $thumbnail The thumbnail ressource * @param DOMNode $node The current node zone * @param array $clip The clip rect to draw * @param int $background The background color * @param int $gridcolumn The number of columns in the grid * @param boolean $lastChild True if the current node is the last child of its parent node * * @return int The new X axis position; */ private function drawThumbnailZone(&$thumbnail, $node, $clip, $background, $gridcolumn, $lastChild = false) { $x = $clip[0]; $y = $clip[1]; $width = $clip[2]; $height = $clip[3]; if (null !== ($spansize = preg_replace('/[^0-9]+/', '', $node->getAttribute('class')))) { $width = floor($width * $spansize / $gridcolumn); } if (false !== strpos($node->getAttribute('class'), 'Child')) { $height = floor($height / 2); } if (!$node->hasChildNodes()) { $this->drawRect($thumbnail, array($x, $y, $width, $height), $background, $width == $clip[2] || strpos($node->getAttribute('class'), 'hChild'), $lastChild); return $width + 2; } foreach ($node->childNodes as $child) { if (is_a($child, 'DOMText')) { continue; } if ('clear' == $child->getAttribute('class')) { $x = $clip[0]; $y = $clip[1] + floor($height / 2) + 2; continue; } $x += $this->drawThumbnailZone($thumbnail, $child, array($x, $y, $clip[2], $height), $background, $gridcolumn, $node->isSameNode($node->parentNode->lastChild)); } return $x + $width - 2; }
public function parse(DOMNode $element) { if ($element->hasAttribute('name')) { $this->name = $element->getAttribute('name'); } if ($element->hasAttribute('type')) { $this->type = $element->getAttribute('type'); } for ($i = 0; $i < $element->childNodes->length; $i++) { $childElement = $element->childNodes->item($i); if ($childElement->parentNode !== $element) { continue; } if ($childElement instanceof DOMComment || $childElement instanceof DOMText) { continue; } switch ($childElement->nodeName) { case 'part': $this->parts[] = new Ezer_XmlVariable($childElement); break; default: throw new Ezer_XmlPersistanceElementNotMappedException($childElement->nodeName); } } }
/** * Returns the (unescaped) correctly marshalled, cell value associated to the given XML node. * * @param \DOMNode $node * @return string|int|float|bool|\DateTime|null The value associated with the cell (null when the cell has an error) */ public function extractAndFormatNodeValue($node) { // Default cell type is "n" $cellType = $node->getAttribute(self::XML_ATTRIBUTE_TYPE) ?: self::CELL_TYPE_NUMERIC; $cellStyleId = intval($node->getAttribute(self::XML_ATTRIBUTE_STYLE_ID)); $vNodeValue = $this->getVNodeValue($node); if ($vNodeValue === '' && $cellType !== self::CELL_TYPE_INLINE_STRING) { return $vNodeValue; } switch ($cellType) { case self::CELL_TYPE_INLINE_STRING: return $this->formatInlineStringCellValue($node); case self::CELL_TYPE_SHARED_STRING: return $this->formatSharedStringCellValue($vNodeValue); case self::CELL_TYPE_STR: return $this->formatStrCellValue($vNodeValue); case self::CELL_TYPE_BOOLEAN: return $this->formatBooleanCellValue($vNodeValue); case self::CELL_TYPE_NUMERIC: return $this->formatNumericCellValue($vNodeValue, $cellStyleId); case self::CELL_TYPE_DATE: return $this->formatDateCellValue($vNodeValue); default: return null; } }
function process(DOMNode $current_node) { global $filter_args, $filter_tags, $filter_mandatory, $bbcode; if ($current_node instanceof DOMElement || $current_node instanceof DOMDocument) { // Recursion. I need iterator_to_array(), because it's likely // that node list will be modified. foreach (iterator_to_array($current_node->childNodes) as $node) { process($node); } // BBCode hack is NOT allowed to exist if ($current_node->tagName === 'bbcodehack') { $value = $current_node->hasAttribute('value') ? $current_node->getAttribute('value') : NULL; $nodes = $current_node->hasAttribute('pre') ? $current_node->getAttribute('pre') : $current_node->childNodes; $nodes = $bbcode[$current_node->getAttribute('name')]['callback']($current_node->ownerDocument, $nodes, $value, array('borked' => $current_node->hasAttribute('borked'))); if (!is_array($nodes)) { $nodes = array($nodes); } foreach ($nodes as $node) { $current_node->parentNode->insertBefore($node, $current_node); } // Remove bbcodehack from DOM $current_node->parentNode->removeChild($current_node); } elseif ($current_node->tagName && !isset($filter_tags[$current_node->tagName])) { while ($current_node->hasChildNodes()) { $current_node->parentNode->insertBefore($current_node->childNodes->item(0), $current_node); } $current_node->parentNode->removeChild($current_node); } else { if ($current_node->hasAttributes()) { // I need iterator_to_array, as I modify attributes // list while iterating. foreach (iterator_to_array($current_node->attributes) as $attr) { $attribute = isset($filter_tags[$current_node->tagName][$attr->name]) ? $filter_tags[$current_node->tagName][$attr->name] : (isset($filter_args[$attr->name]) ? $filter_args[$attr->name] : NULL); if (!$attribute) { $current_node->removeAttribute($attr->name); } elseif (!is_bool($attribute)) { $value = $attribute($attr->value, $current_node); if ($value === NULL) { $current_node->removeAttribute($attr->name); } else { $current_node->setAttribute($attr->name, $value); } } } } if (isset($filter_mandatory[$current_node->tagName])) { foreach ($filter_mandatory[$current_node->tagName] as $attr => $value) { if (!$current_node->hasAttribute($attr)) { $current_node->setAttribute($attr, $value); } } } } } elseif ($current_node instanceof DOMComment) { // Unsafe because of conditional comments $current_node->parentNode->removeChild($current_node); } }
public function attr($a_name, $a_value = null) { if (func_num_args() == 0) { return $this->m_node->getAttribute($a_name); } if (func_num_args() > 1) { $this->m_node->setAttribute($a_name, $a_value); } if (func_num_args() == 1) { $this->m_node->getAttribute($a_name); } }
/** * Create a MARC Data Field * * @param \DOMNode $objNode */ public function __construct(\DOMNode $objNode = null) { if ($objNode != null) { $this->tag = $objNode->getAttribute("tag"); $this->ind1 = $objNode->getAttribute("ind1"); $this->ind2 = $objNode->getAttribute("ind2"); foreach ($objNode->getElementsByTagName("subfield") as $objSubfield) { $objMarcSubField = new SubField($objSubfield); array_push($this->_subfields, $objMarcSubField); } } }
static function append_style(DOMNode $node, $new_style) { $style = rtrim($node->getAttribute(self::$_style_attr), ";"); $style .= $new_style; $style = ltrim($style, ";"); $node->setAttribute(self::$_style_attr, $style); }
/** * Creates individual Entry objects of the appropriate type and * stores them as members of this entry based upon DOM data. * * @param \DOMNode $child The \DOMNode to process * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function takeChildFromDOM($child) { $sc = $this->lookupNamespace('sc'); $scp = $this->lookupNamespace('scp'); $id = $child->namespaceURI . ':' . $child->localName; if ($child->localName == 'group') { $id .= ':' . $child->getAttribute('name'); } switch ($id) { case "{$sc}:id": case "{$sc}:image_link": case "{$sc}:content_language": case "{$sc}:target_country": case "{$sc}:expiration_date": case "{$sc}:adult": case "{$sc}:attribute": $contentAttribute = new Attribute(); $contentAttribute->transferFromDOM($child); $this->_contentAttributes[] = $contentAttribute; break; case "{$sc}:group:tax": case "{$scp}:tax": $tax = new \Magento\Framework\Gdata\Gshopping\Extension\Tax(); $tax->transferFromDOM($child); $this->_tax[] = $tax; break; case $this->lookupNamespace('app') . ':' . 'control': $control = new \Magento\Framework\Gdata\Gshopping\Extension\Control(); $control->transferFromDOM($child); $this->setControl($control); break; default: parent::takeChildFromDOM($child); } }
private function processDataTag( DOMNode $node ) { if( $node->hasAttribute( DATA_TYPE_ATTRIBUTE_NAME ) ) { switch( $node->getAttribute( DEPENDENCY_TYPE_ATTRIBUTE_NAME ) ) { case DATA_TYPE_STREAM_VALUE: /******* nothing for now $url = $this->buildURL( MODULE_STREAM_PATH . $node->nodeValue ); if( $this->url_exists( $url ) ) { $this->xml->load( $url ); } **********/ break; case DATA_TYPE_PROCESSOR_VALUE: break; case DATA_TYPE_DYNAMICFILE_VALUE: if ( file_exists( MODULE_FILE_PATH . $node->nodeValue ) ) { ob_start(); $file = MODULE_FILE_PATH . $node->nodeValue; include $file; $this->dynamicFileOutput .= ob_get_contents(); ob_end_clean(); } break; case DATA_TYPE_STATICFILE_VALUE: if ( file_exists( MODULE_FILE_PATH . $node->nodeValue ) ) { $this->staticFileOutput .= file_get_contents( MODULE_FILE_PATH . $node->nodeValue ); } else { //echo "loading: " . MODULE_FILE_PATH . $node->nodeValue; } break; } } }
public function attr($a_name, $a_value = null) { if (is_null($a_value)) { return $this->m_node->getAttribute($a_name); } $this->m_node->setAttribute($a_name, $a_value); }
/** * Create a MARC Control Field * * @param \DOMNode $objNode */ public function __construct(\DOMNode $objNode = null) { if ($objNode != null) { $this->tag = $objNode->getAttribute("tag"); $this->value = $objNode->nodeValue; } }
/** * Constructor. * * @param \DOMNode $node The node associated with this field */ public function __construct(\DOMNode $node) { $this->node = $node; $this->name = $node->getAttribute('name'); $this->xpath = new \DOMXPath($node->ownerDocument); $this->initialize(); }
/** * Converts a node to a PHP value * * @param DOMNode $node * @return mixed */ private static function _nodeToValue($node) { $type = null; if ($node instanceof DOMElement) { $type = $node->getAttribute('type'); } switch ($type) { case 'datetime': return self::_timestampToUTC((string) $node->nodeValue); case 'date': return new DateTime((string) $node->nodeValue); case 'integer': return (int) $node->nodeValue; case 'boolean': $value = (string) $node->nodeValue; if (is_numeric($value)) { return (bool) $value; } else { return $value !== "true" ? false : true; } case 'array': case 'collection': return self::_nodeToArray($node); default: if ($node->hasChildNodes()) { return self::_nodeToArray($node); } elseif (trim($node->nodeValue) === '') { return null; } else { return $node->nodeValue; } } }
/** * Create a MARC Sub Field * * @param \DOMNode $node */ public function __construct(\DOMNode $node = null) { if ($node != null) { $this->code = $node->getAttribute("code"); $this->value = $node->nodeValue; } }
/** * @param string $name * * @return string */ public function getAttribute($name) { if ($this->node instanceof \DOMElement) { return $this->node->getAttribute($name); } return ''; }
/** * Given a child DOMNode, tries to determine how to map the data into * object instance members. If no mapping is defined, Extension_Element * objects are created and stored in an array. * * @param DOMNode $child The DOMNode needed to be handled */ protected function takeChildFromDOM($child) { if ($child->nodeType == XML_ELEMENT_NODE) { $name = 'attribute' == $child->localName ? $child->getAttribute('name') : $child->localName; $this->_taxInfo[$name] = $child->textContent; } parent::takeChildFromDOM($child); }
public function sanitize(\DOMNode $node) { if ($this->haveToTrim() && $node->hasAttribute($this->name)) { $node->setAttribute($this->name, trim($node->getAttribute($this->name))); } if ($this->repair && !$node->hasAttribute($this->name)) { $node->setAttribute($this->name, $this->repairValue); } }
function __toString() { // Skip empty text frames // if ( $this->is_text_node() && // preg_replace("/\s/", "", $this->_node->data) === "" ) // return ""; $str = "<b>" . $this->_node->nodeName . ":</b><br/>"; //$str .= spl_object_hash($this->_node) . "<br/>"; $str .= "Id: " . $this->get_id() . "<br/>"; $str .= "Class: " . get_class($this) . "<br/>"; if ($this->is_text_node()) { $tmp = htmlspecialchars($this->_node->nodeValue); $str .= "<pre>'" . mb_substr($tmp, 0, 70) . (mb_strlen($tmp) > 70 ? "..." : "") . "'</pre>"; } elseif ($css_class = $this->_node->getAttribute("class")) { $tmp = htmlspecialchars($css_class); $str .= "CSS class: '{$css_class}'<br/>"; } if ($this->_parent) { $str .= "\nParent:" . $this->_parent->_node->nodeName . " (" . spl_object_hash($this->_parent->_node) . ") " . "<br/>"; } if ($this->_prev_sibling) { $str .= "Prev: " . $this->_prev_sibling->_node->nodeName . " (" . spl_object_hash($this->_prev_sibling->_node) . ") " . "<br/>"; } if ($this->_next_sibling) { $str .= "Next: " . $this->_next_sibling->_node->nodeName . " (" . spl_object_hash($this->_next_sibling->_node) . ") " . "<br/>"; } $d = $this->get_decorator(); while ($d && $d != $d->get_decorator()) { $str .= "Decorator: " . get_class($d) . "<br/>"; $d = $d->get_decorator(); } $str .= "Position: " . pre_r($this->_position, true); $str .= "\nContaining block: " . pre_r($this->_containing_block, true); $str .= "\nMargin width: " . pre_r($this->get_margin_width(), true); $str .= "\nMargin height: " . pre_r($this->get_margin_height(), true); $str .= "\nStyle: <pre>" . $this->_style->__toString() . "</pre>"; if ($this->_decorator instanceof Block_Frame_Decorator) { $str .= "Lines:<pre>"; foreach ($this->_decorator->get_line_boxes() as $line) { foreach ($line->get_frames() as $frame) { if ($frame instanceof Text_Frame_Decorator) { $str .= "\ntext: "; $str .= "'" . htmlspecialchars($frame->get_text()) . "'"; } else { $str .= "\nBlock: " . $frame->get_node()->nodeName . " (" . spl_object_hash($frame->get_node()) . ")"; } } $str .= "\ny => " . $line->y . "\n" . "w => " . $line->w . "\n" . "h => " . $line->h . "\n" . "left => " . $line->left . "\n" . "right => " . $line->right . "\n"; } $str .= "</pre>"; } $str .= "\n"; if (php_sapi_name() === "cli") { $str = strip_tags(str_replace(array("<br/>", "<b>", "</b>"), array("\n", "", ""), $str)); } return $str; }
/** * Return the string for generating a new password for the form prompt. * @param DOMNode $form_node The form node that has the generate attribute */ protected function getGenerateText($form_node) { if ($form_node->hasAttribute("generate")) { return $form_node->getAttribute("generate"); } elseif ($this->hasHeader("generate")) { return $this->getHeader("generate"); } return null; }
/** * @return string */ public function __toString() { $reflection = new \ReflectionClass(get_class($this->context)); $className = $reflection->getShortName(); $nodeName = $this->node->nodeName; if (substr($nodeName, 0, 1) === '#') { $nodeDescription = '"' . mb_strimwidth($this->node->textContent, 0, 30, '...') . '"'; } else { $nodeDescription = '<'; $nodeDescription .= $nodeName; if (Type::is($this->node, 'DOMElement')) { $class = $this->node->getAttribute('class'); if ($class) { $nodeDescription .= ' class="' . $class . '"'; } } $nodeDescription .= '>'; } return "No rules defined for {$nodeDescription} in the context of {$className}"; }
/** * Adds class="external" & rel="nofollow" to external links. * * @param \DOMNode $node Link * @param \Title $title */ public function apply(\DOMNode $node, \Title $title) { if (!$node instanceof \DOMElement) { return; } $node->setAttribute('class', 'external'); global $wgNoFollowLinks, $wgNoFollowDomainExceptions; if ($wgNoFollowLinks && !wfMatchesDomainList($node->getAttribute('href'), $wgNoFollowDomainExceptions)) { $node->setAttribute('rel', 'nofollow'); } }
/** * Constructor. * * @param \DOMNode $node The node associated with this field */ public function __construct(\DOMNode $node) { $this->node = $node; $this->name = $node->getAttribute('name'); $this->document = new \DOMDocument('1.0', 'UTF-8'); $this->node = $this->document->importNode($this->node, true); $root = $this->document->appendChild($this->document->createElement('_root')); $root->appendChild($this->node); $this->xpath = new \DOMXPath($this->document); $this->initialize(); }
function parseNodeProperties(DOMNode $paragraph_node) { /** * pPr - text paragraph properties */ $node_properties = array(); if ($paragraph_node->hasAttributes()) { $node_properties['lvl'] = (int) $paragraph_node->getAttribute('lvl'); } $node_properties['bullet_type'] = $this->detectListType($paragraph_node); return $node_properties; }
/** * Create a Match object. * * @param DOMNode $elem A DOMNode object for a match. */ public function __construct($elem) { $this->path = $elem->getAttribute('path'); $this->content = ''; foreach ($elem->childNodes as $node) { if ($node->nodeName === 'search:highlight') { $this->content .= '<span class="highlight">' . $node->nodeValue . '</span>'; } else { $this->content .= $node->nodeValue; } } }
/** * * @param DOMNode $element * @param type $filtersJson - a json that has an array of filters ('attribute' and 'value' keys) * @return boolean */ private function domElementPassesFilter(DOMNode $element, $filtersJson) { if ($filtersJson == null || empty($filtersJson)) { return true; } foreach ($filtersJson as $filter) { $attribute = $element->getAttribute($filter["attribute"]); if ($attribute != $filter["value"]) { return false; } } return true; }
public function renderCustomElement(DOMNode $node, $parser, $context = NULL) { $mode = $node->getAttribute('data-test-mode'); if (!$mode) { $mode = 'attribute'; } switch ($mode) { case 'attribute': $markup = $node->getAttribute('data-attr'); Debug::show($markup); break; case 'nested': $markup = '<testelement>def</testelement>'; break; default: $markup = ''; break; } // recursively invoke the shortcode parser on the result, in case the element returns shortcodes // itself. return $parser->parse($markup); }
private function renderFunction(\DOMNode $entryEl, $padding, array $options) { $function = $entryEl->getAttribute('function'); $args = []; foreach ($entryEl->query('./arg') as $argEl) { $argString = $this->truncate->format($argEl->nodeValue, array_merge($this->truncate->getDefaultOptions(), ['length' => 100])); $args[] = str_replace("\n", '', $argString); } if ($options['show_args'] && $args) { return sprintf('%s%s(%s', $pad = str_repeat(' ', $padding), $function, "\n" . $pad . ' ' . implode("\n" . $pad . ' ', $args) . "\n" . $pad . '</>)'); } return sprintf('%s%s()', $pad = str_repeat(' ', $padding), $function); }
function PrintNode(DOMNode $node, $u) { if ($node->nodeName == "img" || $node->nodeName == "a") { switch ($node->nodeName) { case "img": $indirizzo = $node->getAttribute('src'); $absolute = strpos($indirizzo, "http://"); $indirizzo = $absolute === false ? $u . $indirizzo : $indirizzo; echo "<img src='" . $indirizzo . "' />"; //se img prende l'indirizzo assoluto break; case "a": $indirizzo = $node->getAttribute('href'); $absolute = strpos($indirizzo, "http://"); $indirizzo = $absolute === false ? $u . $indirizzo : $indirizzo; echo "<a href='" . $indirizzo . "' target='_blank'>" . $node->nodeValue . "</a>"; break; } } else { echo "<" . $node->nodeName . ">" . html_encode($node->nodeValue) . "</" . $node->nodeName . ">"; } }
/** * Check for a list of attributes if current node is valid * * @param DOMNode $node to check if valid * @param array $attrs to test if in $node * * @return boolean true if $node is valid for $attrs, false otherwise */ public static function isValidNodeAttrs($node, $attrs) { foreach ($attrs as $attr) { $val = ''; if (strpos($attr, '=') !== false) { list($attr, $val) = explode('=', $attr); } if (!$node->hasAttribute($attr) || !empty($val) && $node->getAttribute($attr) !== $val) { return false; } } return true; }