public function visit(\DOMElement $node, Compiler $context) { if ($node->hasAttribute("from-exp")) { $filename = $node->getAttribute("from-exp"); } elseif ($node->hasAttribute("from")) { $filename = '"' . $node->getAttribute("from") . '"'; } else { throw new Exception("The 'from' or 'from-exp' attribute is required"); } // remove any non-element node foreach (iterator_to_array($node->childNodes) as $child) { if (!$child instanceof \DOMElement) { $child->parentNode->removeChild($child); } } $context->compileChilds($node); $code = "embed {$filename}"; if ($node->hasAttribute("ignore-missing") && $node->hasAttribute("ignore-missing") !== false) { $code .= " ignore missing"; } if ($node->hasAttribute("with")) { $code .= " with " . $node->getAttribute("with"); } if ($node->hasAttribute("only") && $node->getAttribute("only") !== "false") { $code .= " only"; } $ext = $context->createControlNode($code); $set = iterator_to_array($node->childNodes); $n = $node->ownerDocument->createTextNode("\n"); array_unshift($set, $n); array_unshift($set, $ext); $set[] = $context->createControlNode("endembed"); DOMHelper::replaceWithSet($node, $set); }
public function parse(DOMElement $element) { $this->class = $element->getAttribute('class'); if ($element->hasAttribute('args')) { $this->args[] = $element->getAttribute('args'); } 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 'args': $this->parseArgs($childElement); break; case 'targets': case 'sources': // already handled by Ezer_XmlStepUtil break; default: throw new Ezer_XmlPersistanceElementNotMappedException($childElement->nodeName); } } }
/** * Initialize an EndpointType. * * @param DOMElement|NULL $xml The XML element we should load. * @throws Exception */ public function __construct(DOMElement $xml = NULL) { if ($xml === NULL) { return; } if (!$xml->hasAttribute('Binding')) { throw new Exception('Missing Binding on ' . $xml->tagName); } $this->Binding = $xml->getAttribute('Binding'); if (!$xml->hasAttribute('Location')) { throw new Exception('Missing Location on ' . $xml->tagName); } $this->Location = $xml->getAttribute('Location'); if ($xml->hasAttribute('ResponseLocation')) { $this->ResponseLocation = $xml->getAttribute('ResponseLocation'); } foreach ($xml->attributes as $a) { if ($a->namespaceURI === NULL) { continue; /* Not namespace-qualified -- skip. */ } $fullName = '{' . $a->namespaceURI . '}' . $a->localName; $this->attributes[$fullName] = array('qualifiedName' => $a->nodeName, 'namespaceURI' => $a->namespaceURI, 'value' => $a->value); } }
/** * Create a PAOS Request element. * * @param DOMElement|NULL $xml The XML element we should load. */ public function __construct(DOMElement $xml = NULL) { if ($xml === NULL) { return; } if (!$xml->hasAttributeNS(SAML2_Const::NS_SOAP, 'mustUnderstand')) { throw new Exception('Missing soap-env:mustUnderstand attribute in <paos:Request>.'); } elseif ($xml->getAttributeNS(SAML2_Const::NS_SOAP, 'mustUnderstand') !== '1') { throw new Exception('Invalid value of soap-env:mustUnderstand attribute in <paos:Request>.'); } if (!$xml->hasAttributeNS(SAML2_Const::NS_SOAP, 'actor')) { throw new Exception('Missing soap-env:mustUnderstand attribute in <paos:Request>.'); } elseif ($xml->getAttributeNS(SAML2_Const::NS_SOAP, 'actor') !== 'http://schemas.xmlsoap.org/soap/actor/next') { throw new Exception('Invalid value of soap-env:actor attribute in <paos:Request>.'); } if (!$xml->hasAttribute('responseConsumerURL')) { throw new Exception('Missing responseConsumerURL attribute in <paos:Request>.'); } $this->responseConsumerURL = $xml->getAttribute('responseConsumerURL'); if (!$xml->hasAttribute('service')) { throw new Exception('Missing service attribute in <paos:Request>.'); } $this->service = $xml->getAttribute('service'); if ($xml->hasAttribute('messageID')) { $this->messageID = $xml->getAttribute('messageID'); } }
private function processSuite(\DOMElement $suiteEl) { $suite = new Suite($suiteEl->getAttribute('context'), new \DateTime($suiteEl->getAttribute('date')), $suiteEl->getAttribute('config-path'), [], [], $suiteEl->getAttribute('uuid')); $informations = []; foreach ($suiteEl->query('./env/*') as $envEl) { $name = $envEl->nodeName; $info = []; foreach ($envEl->attributes as $iName => $valueAttr) { $info[$iName] = $valueAttr->nodeValue; } $informations[$name] = new Information($name, $info); } $resultClasses = []; foreach ($suiteEl->query('//result') as $resultEl) { $class = $resultEl->getAttribute('class'); if (!class_exists($class)) { throw new \RuntimeException(sprintf('XML file defines a non-existing result class "%s" - maybe you are missing an extension?', $class)); } $resultClasses[$resultEl->getAttribute('key')] = $class; } $suite->setEnvInformations($informations); foreach ($suiteEl->query('./benchmark') as $benchmarkEl) { $benchmark = $suite->createBenchmark($benchmarkEl->getAttribute('class')); $this->processBenchmark($benchmark, $benchmarkEl, $resultClasses); } return $suite; }
/** * Get an elements class/id weight. Uses regular expressions to tell if this * element looks good or bad. * * @param DOMElement $e * @return number (Integer) */ public function getClassWeight($e) { if (!$this->flagIsActive(self::FLAG_WEIGHT_CLASSES)) { return 0; } $weight = 0; if (preg_match($this->regexps['negative'], $e->tagName)) { $weight -= 250; } if (preg_match($this->regexps['positive'], $e->tagName)) { $weight += 250; } /* Look for a special ID */ if ($e->hasAttribute('id') && $e->getAttribute('id') != '') { if (preg_match($this->regexps['negative'], $e->getAttribute('id'))) { $weight -= 150; } if (preg_match($this->regexps['positive'], $e->getAttribute('id'))) { $weight += 150; } } /* Look for a special classname */ if ($e->hasAttribute('class') && $e->getAttribute('class') != '') { $classes = explode(" ", $e->getAttribute('class')); foreach ($classes as $class) { if (preg_match($this->regexps['negative'], $class)) { $weight -= 25; } if (preg_match($this->regexps['positive'], $class)) { $weight += 25; } } } return $weight; }
/** * Parse given Flickr Image element * * @param DOMElement $image * @return void */ 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'); }
public function initFromXmlNode(DOMElement $node) { $this->selected = $node->getAttribute('selected') == 'true'; $this->text = trim($node->textContent); if ($node->hasAttribute('customAnswer')) { $this->customAnswer = trim($node->getAttribute('customAnswer')); } }
/** * @param string $name * @return string * @throws UnexpectedValueException */ protected function getAttribute($name) { $attribute = $this->element->getAttribute($name); if ($attribute === '') { throw new UnexpectedValueException(sprintf('Missing attribute "%s"', $name)); } return $attribute; }
/** * @param \DOMElement $element * @return int */ public function parseElement(\DOMElement $element) { if ($element->hasAttribute(CodepointAssignedParser::ATTR_CODEPOINT)) { return 1; } $first = hexdec($element->getAttribute(CodepointAssignedParser::ATTR_CODEPOINT_FIRST)); $last = hexdec($element->getAttribute(CodepointAssignedParser::ATTR_CODEPOINT_LAST)); return $last - $first + 1; }
/** * Creates a ref-mark as the first element of the given $odtElement, based * on the ID attribute of the given $docbookElement. * * @param DOMElement $docbookElement * @param DOMElement $odtElement */ protected function createRefMark(DOMElement $docbookElement, DOMElement $odtElement) { // Work around for DocBook inconsistency in using ID or id. id // would be correct, if one follows the specs here… if ($docbookElement->hasAttribute('ID') || $docbookElement->hasAttribute('id')) { $refMark = $odtElement->insertBefore($odtElement->ownerDocument->createElementNS(ezcDocumentOdt::NS_ODT_TEXT, 'text:reference-mark'), $odtElement->firstChild); $refMark->setAttributeNS(ezcDocumentOdt::NS_ODT_TEXT, 'text:name', $docbookElement->hasAttribute('ID') ? $docbookElement->getAttribute('ID') : $docbookElement->getAttribute('id')); } }
/** * @param DOMElement $element * @return Resource */ private function element2Resource(DOMElement $element) { $resource = new Resource(); $resource->id = $element->getAttribute('id'); $resource->value = $element->getAttribute('value'); foreach ($element->childNodes as $domElement) { $resource->resources[] = $this->element2Resource($domElement); } return $resource; }
/** * @param \DOMElement $element * * @return PharAlias */ private function getPharAliasFromNode(\DOMElement $element) { $parser = new VersionConstraintParser(); if ($element->hasAttribute('version')) { $version = $parser->parse($element->getAttribute('version')); } else { $version = new AnyVersionConstraint(); } return new PharAlias($element->getAttribute('name'), $version); }
public function __construct(DOMElement $node, jackalope_NodeType_NodeTypeManager $nodeTypeManager) { $this->nodeTypeManager = $nodeTypeManager; $this->declaringNodeType = $node->getAttribute('declaringNodeType'); $this->name = $node->getAttribute('name'); $this->isAutoCreated = jackalope_Helper::getBoolAttribute($node, 'isAutoCreated'); $this->isMandatory = jackalope_Helper::getBoolAttribute($node, 'mandatory'); $this->isProtected = jackalope_Helper::getBoolAttribute($node, 'isProtected'); $this->onParentVersion = PHPCR_Version_OnParentVersionAction::valueFromName($node->getAttribute('onParentVersion')); }
/** * Filter a single element * * @param DOMElement $element * @return void */ public function filterElement(DOMElement $element) { if ($element->hasAttribute('rowspan') && $element->getAttribute('rowspan') > 1) { $attributes = $element->getProperty('attributes'); $attributes['morerows'] = $element->getAttribute('rowspan') - 1; $element->setProperty('attributes', $attributes); } // @todo: Handle colspan, too - even it is quite complex to express in // docbook. }
public function match(GoogleDom $dom, \DOMElement $node) { if ($node->getAttribute('class') == 'mnr-c' && null !== $node->childNodes->item(0)) { foreach ($node->childNodes->item(0)->childNodes as $node) { if ($node instanceof \DOMElement && $node->getAttribute('class') == 'rc') { return self::RULE_MATCH_MATCHED; } } } return self::RULE_MATCH_NOMATCH; }
/** * @param \DOMElement $element * @return \int[] */ private function extractCodepoints(\DOMElement $element) { if ($element->hasAttribute(self::ATTR_CODEPOINT)) { $first = hexdec($element->getAttribute(self::ATTR_CODEPOINT)); $last = $first; } else { $first = hexdec($element->getAttribute(self::ATTR_CODEPOINT_FIRST)); $last = hexdec($element->getAttribute(self::ATTR_CODEPOINT_LAST)); } return range($first, $last); }
public function match(GoogleDom $dom, \DOMElement $node) { if ($node->getAttribute('class') == 'g') { foreach ($node->childNodes as $node) { if ($node instanceof \DOMElement && $node->getAttribute('class') == '_Zfh') { return self::RULE_MATCH_MATCHED; } } } return self::RULE_MATCH_NOMATCH; }
/** * Alters images with an invalid source. * * When the 'Restrict images to this site' filter is enabled, any images that * are not hosted on the site will be passed through this hook, most commonly to * replace the invalid image with an error indicator. * * @param DOMElement $image * An IMG node to format, parsed from the filtered text. */ function hook_filter_secure_image_alter(&$image) { // Turn an invalid image into an error indicator. $image->setAttribute('src', base_path() . 'core/misc/icons/e32700/error.svg'); $image->setAttribute('alt', t('Image removed.')); $image->setAttribute('title', t('This image has been removed. For security reasons, only images from the local domain are allowed.')); // Add a CSS class to aid in styling. $class = $image->getAttribute('class') ? trim($image->getAttribute('class')) . ' ' : ''; $class .= 'filter-image-invalid'; $image->setAttribute('class', $class); }
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); } }
/** * Convert specific cron configurations * * @param \DOMElement $jobConfig * @return array * @throws \InvalidArgumentException */ protected function convertCronConfig(\DOMElement $jobConfig) { $instanceName = $jobConfig->getAttribute('instance'); $methodName = $jobConfig->getAttribute('method'); if (!isset($instanceName)) { throw new \InvalidArgumentException('Attribute "instance" does not exist'); } if (!isset($methodName)) { throw new \InvalidArgumentException('Attribute "method" does not exist'); } return ['instance' => $instanceName, 'method' => $methodName]; }
/** * Parse font family. * @param DOMElement $node */ public function parse(DOMElement $node) { $this->UID = $node->hasAttribute(IdmlAttributes::Self) ? $node->getAttribute(IdmlAttributes::Self) : ''; $this->name = $node->hasAttribute(IdmlAttributes::Name) ? $node->getAttribute(IdmlAttributes::Name) : ''; $fontNodes = $node->getElementsByTagName('Font'); foreach ($fontNodes as $fontNode) { $font = new IdmlFont(); $font->parse($fontNode); $font->fontFamily = $this; $this->fonts[] = $font; } }
/** * Converts a DOMElement item to a Zotero_Setting object * * @param DOMElement $xml Setting data as DOMElement * @return Zotero_Setting Setting object */ public static function convertXMLToSetting(DOMElement $xml) { $libraryID = (int) $xml->getAttribute('libraryID'); $name = (string) $xml->getAttribute('name'); $setting = self::getByLibraryAndKey($libraryID, $name); if (!$setting) { $setting = new Zotero_Setting(); $setting->libraryID = $libraryID; $setting->name = $name; } $setting->value = json_decode((string) $xml->nodeValue); return $setting; }
/** * Initialize a saml:BaseID, either from scratch or from an existing \DOMElement. * * @param \DOMElement|null $xml The XML element we should load, if any. */ public function __construct(\DOMElement $xml = null) { if ($xml === null) { return; } $this->element = $xml; if ($xml->hasAttribute('NameQualifier')) { $this->NameQualifier = $xml->getAttribute('NameQualifier'); } if ($xml->hasAttribute('SPNameQualifier')) { $this->SPNameQualifier = $xml->getAttribute('SPNameQualifier'); } }
/** * Create/parse a mdrpi:RegistrationInfo element. * * @param \DOMElement|null $xml The XML element we should load. * @throws \Exception */ public function __construct(\DOMElement $xml = null) { if ($xml === null) { return; } if (!$xml->hasAttribute('registrationAuthority')) { throw new \Exception('Missing required attribute "registrationAuthority" in mdrpi:RegistrationInfo element.'); } $this->registrationAuthority = $xml->getAttribute('registrationAuthority'); if ($xml->hasAttribute('registrationInstant')) { $this->registrationInstant = Utils::xsDateTimeToTimestamp($xml->getAttribute('registrationInstant')); } $this->RegistrationPolicy = Utils::extractLocalizedStrings($xml, Common::NS_MDRPI, 'RegistrationPolicy'); }
public function visit(\DOMElement $node, Compiler $context) { $code = "use "; if ($node->hasAttribute("from")) { $code .= '"' . $node->getAttribute("from") . '"'; } else { throw new Exception("The 'from' attribute is required"); } if ($node->hasAttribute("with")) { $code .= " with " . $node->getAttribute("with"); } $pi = $context->createControlNode($code); $node->parentNode->replaceChild($pi, $node); }
private static function _getAltTag(\DOMElement $img) { if ($img->hasAttribute('alt') && $img->getAttribute('alt')) { return str_replace('-', ' ', $img->getAttribute('alt')); } $next = $img->parentNode->getElementsByTagName('span'); for ($i = 0; $i < $next->length; $i++) { $item = $next->item($i); if (in_array($item->getAttribute('class'), ['hide-text'])) { return trim($next->item($i)->nodeValue); } } return ''; }
public function applyXMLElement(\DOMElement $element) { $this->_alpha2 = $element->getAttribute('code'); $listXMLNode = $element->getElementsByTagName('iso_3166_subset'); // check if country has sub divisions if (!$listXMLNode->length) { return; } // get sub division type $this->_subDivisionName = $listXMLNode->item(0)->getAttribute('type'); foreach ($element->getElementsByTagName('iso_3166_2_entry') as $element) { $this->_list[$element->getAttribute('code')] = $element->getAttribute('name'); } }
/** * Create/parse a mdrpi:RegistrationInfo element. * * @param DOMElement|NULL $xml The XML element we should load. */ public function __construct(DOMElement $xml = NULL) { if ($xml === NULL) { return; } if (!$xml->hasAttribute('registrationAuthority')) { throw new Exception('Missing required attribute "registrationAuthority" in mdrpi:RegistrationInfo element.'); } $this->registrationAuthority = $xml->getAttribute('registrationAuthority'); if ($xml->hasAttribute('registrationInstant')) { $this->registrationInstant = SimpleSAML_Utilities::parseSAML2Time($xml->getAttribute('registrationInstant')); } $this->RegistrationPolicy = SAML2_Utils::extractLocalizedStrings($xml, SAML2_XML_mdrpi_Common::NS_MDRPI, 'RegistrationPolicy'); }
/** {@inheritdoc} */ public function parse(\DOMElement $actionElement, Rule $rule, \DOMXPath $xpath) { $action = new FilterContext(); if ($actionElement->hasAttribute('allow-keys')) { $keys = $actionElement->getAttribute('allow-keys'); $action->setMode(FilterContext::ALLOW_KEYS); } else { $keys = $actionElement->getAttribute('disallow-keys'); $action->setMode(FilterContext::DISALLOW_KEYS); } $action->setKeys(array_filter(preg_split('/\\s+/', $keys))); $rule->appendAction($action, $actionElement->getAttribute('stage')); return $action; }