/** * 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'); }
/** * @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 initFromXmlNode(DomElement $node, $itemTagName) { $this->clear(); $itemsNodes = $node->getElementsByTagName($itemTagName); foreach ($itemsNodes as $itemNode) { $this->addItem($itemNode->textContent); } }
private function injectIfNotCode($chr, \DomElement $element, $string) { if ($chr === '`') { $element->appendChild($this->document->createTextNode($string)); } else { $this->inject($element, $string); } }
public function run(\DomElement $element) { $transphporm = $element->getAttribute('transphporm'); if ($transphporm == 'remove') { $element->parentNode->removeChild($element); } else { $element->removeAttribute('transphporm'); } }
/** * This function appends expires_at and job_description_format tags into RSS * <item> tag. * * Function is applied once for each <item> in the feed and the additional data * is appended to the end of "item". * * @param DomElement $item http://php.net/manual/en/class.domelement.php * @param DomDocument $rss http://php.net/manual/en/class.domdocument.php * @param Wpjb_Model_Job $job Job currently rendered to XML * @return DomElement Modified DomElement object */ function feeds_api_rss($item, $rss, $job) { // Using default fields $item->appendChild($rss->createElement("expires_at", esc_html($job->job_expires_at))); // Using meta fields $item->appendChild($rss->createElement("job_description_format", esc_html($job->meta->job_description_format->value()))); // Make sure to return $item return $item; }
function __construct($type) { parent::__construct(); $check = $this->createElement($type); $this->domainobject = $this->createElement('domain:' . $type); if (!$this->rootNamespaces()) { $this->domainobject->setAttribute('xmlns:domain', 'urn:ietf:params:xml:ns:domain-1.0'); } $check->appendChild($this->domainobject); $this->getCommand()->appendChild($check); }
/** * Creates a parent element with the given name, with text as given. * * Adds the resulting element as a child of the given parent node. * * @param DomElement $parent Existing parent of all the new nodes. * @param string $name Name of the new parent element. * @param string $text Text of the new element. * @return DomElement The new element. */ protected function appendNewElement($parent, $name, $text = null) { $document = $this->document; $newElement = $document->createElement($name); // Use a TextNode, causes escaping of input text if ($text) { $text = $document->createTextNode($text); $newElement->appendChild($text); } $parent->appendChild($newElement); return $newElement; }
public function run($value, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { if ($pseudoMatcher->hasFunction('attr')) { $element->removeAttribute($pseudoMatcher->getFuncArgs('attr')); } else { if (strtolower($value[0]) === 'none') { $element->setAttribute('transphporm', 'remove'); } else { $element->setAttribute('transphporm', 'show'); } } }
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)); }
public function match($pseudo, \DomElement $element) { if (strpos($pseudo, 'nth-child') === 0) { $bracketMatcher = new \Transphporm\Parser\BracketMatcher($pseudo); $criteria = $bracketMatcher->match('(', ')'); $bracketMatcher = new \Transphporm\Parser\BracketMatcher($element->getNodePath()); $num = $bracketMatcher->match('[', ']'); if (is_callable([$this, $criteria])) { return $this->{$criteria}($num); } else { return $num == $criteria; } } return true; }
/** * return the document as string. * * @access public * @return string */ public function __toString() { $this->document->formatOutput = true; $this->document->preserveWhitespace = false; $title = $this->document->createElement('title', $this->getFullTitle()); $this->head->appendChild($title); if (!empty($this->favicon)) { $favicon = $this->document->createElement('link'); $favicon->setAttribute('rel', 'shortcut icon'); $favicon->setAttribute('href', $this->favicon); $this->head->appendChild($favicon); $favicon = $this->document->createElement('link'); $favicon->setAttribute('rel', 'icon'); $favicon->setAttribute('href', $this->favicon); $this->head->appendChild($favicon); } if (!empty($this->keywords)) { $keywords = $this->document->createElement('meta'); $keywords->setAttribute('name', 'keywords'); $keywords->setAttribute('content', $this->keywords); $this->head->appendChild($keywords); } $html = $this->document->getElementsByTagName('html')->item(0); $html->appendChild($this->head); $html->appendChild($this->body); return $this->document->saveXML(); }
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); } } }
/** * Test name is vaild and add node. * If not create node with ARRAY_ITEM_NAME name and * set old neme in ARRAY_KEY_ATTRIBUTE * * @param string $name * @param DomElement $element * @return DomElement */ protected function _testNodeNameAndAddNode($name, DomElement $element) { $doc = $element->ownerDocument; if (!preg_match(self::NODE_NAME_PATTERN, $name)) { if ($element instanceof DOMDocument) { $nodeName = self::ARRAY_ITEM_NAME; } else { $nodeName = rtrim($element->nodeName, 's'); } $newNode = $doc->createElement($nodeName); $newNode->setAttribute(self::ARRAY_KEY_ATTRIBUTE, $name); $element->appendChild($newNode); } else { $newNode = $doc->createElement($name); $element->appendChild($newNode); } return $newNode; }
public function addItemElement($element, $value, $attr = array()) { $element = $this->createElement($element, $this->normalizeString($value)); foreach ($attr as $key => $value) { $element->setAttribute($key, $this->normalizeString($value)); } $this->item->appendChild($element); return $this; }
/** * Function that creates service elements for WSDL2.0 * @param DomDocument $svr_name DomDocument element of the wsdl document * @param DomElement $svr_root service dom element */ public function createWsdl2Service(DomDocument $svr_dom, DomElement $svr_root) { $svr_ele = $svr_dom->createElementNS(WS_WSDL_Const::WS_WSDL2_NAMESPACE, WS_WSDL_Const::WS_WSDL_SERVICE_ATTR_NAME); $svr_ele->setAttribute(WS_WSDL_Const::WS_WSDL_SERVICE_ATTR_NAME, $this->S_name); $svr_ele->setAttribute(WS_WSDL_Const::WS_WSDL_INTERFACE_ATTR_NAME, $this->S_name . ucfirst(WS_WSDL_Const::WS_WSDL_INTERFACE_ATTR_NAME)); $svr_port = $svr_dom->createElementNS(WS_WSDL_Const::WS_WSDL2_NAMESPACE, WS_WSDL_Const::WS_WSDL_ENDPOINT_ATTR_NAME); $svr_port->setAttribute(WS_WSDL_Const::WS_WSDL_NAME_ATTR_NAME, $this->S_name); $svr_port->setAttribute(WS_WSDL_Const::WS_WSDL_BINDING_ATTR_NAME, "tns" . $this->S_name); $svr_port->setAttribute(WS_WSDL_Const::WS_WSDL_ADDRESS_ATTR_NAME, $this->endpoint); $svr_ele->appendChild($svr_port); $svr_root->appendChild($svr_ele); }
public function createInterface(DomDocument $interface_doc, DomElement $interface_root) { $interface_ele = $interface_doc->createElementNS(WS_WSDL_Const::WS_WSDL2_NAMESPACE, self::WS_WSDL2_INTERFACE_INTERFACE_ATTR_NAME); $interface_ele->setAttribute(self::WS_WSDL_INTERFACE_NAME_ATTR_NAME, $this->svr_name . ucfirst(self::WS_WSDL2_INTERFACE_INTERFACE_ATTR_NAME)); foreach ($this->operations as $name => $params) { $op = $interface_doc->createElementNS(WS_WSDL_Const::WS_WSDL2_NAMESPACE, self::WS_WSDL_INTERFACE_OPERATION_ATTR_NAME); $op->setAttribute(self::WS_WSDL_INTERFACE_NAME_ATTR_NAME, $name); $op->setAttribute(self::WS_WSDL2_INTERFACE_PATTERN_ATTR_NAME, WS_WSDL_Const::WS_WSDL2_PATTERN_ATTR_VAL); foreach (array(self::WS_WSDL_INTERFACE_INPUT_ATTR_NAME, self::WS_WSDL_INTERFACE_OUTPUT_ATTR_NAME) as $type) { $operation_ele = $interface_doc->createElementNS(WS_WSDL_Const::WS_WSDL2_NAMESPACE, $type); if ($type == self::WS_WSDL_INTERFACE_INPUT_ATTR_NAME) { $operation_ele->setAttribute(self::WS_WSDL2_INTERFACE_PATTERN_ATTR_NAME, $name); } else { $operation_ele->setAttribute(self::WS_WSDL2_INTERFACE_PATTERN_ATTR_NAME, $name . "Response"); } $op->appendChild($operation_ele); } $interface_ele->appendChild($op); } $interface_root->appendChild($interface_ele); }
/** * Function that creates portType elements for WSDL1.1 * @param DomDocument $port_doc DomDocument element of the wsdl document * @param DomElement $port_root service dom element */ public function createPortType(DomDocument $port_doc, DomElement $port_root) { $attr_name_to_postfix_map = array(WS_WSDL_Const::WS_WSDL_INPUT_ATTR_NAME => WS_WSDL_Const::WS_WSDL_OPERTION_INPUT_TAG, WS_WSDL_Const::WS_WSDL_OUTPUT_ATTR_NAME => WS_WSDL_Const::WS_WSDL_OPERTION_OUTPUT_TAG); $port_el = $port_doc->createElementNS(WS_WSDL_Const::WS_SCHEMA_WSDL_NAMESPACE, WS_WSDL_Const::WS_WSDL_PORTTYPE_ATTR_NAME); $port_el->setAttribute(WS_WSDL_Const::WS_WSDL_NAME_ATTR_NAME, $this->service_name . "PortType"); foreach ($this->operations as $name => $params) { $operation = $port_doc->createElementNS(WS_WSDL_Const::WS_SCHEMA_WSDL_NAMESPACE, WS_WSDL_Const::WS_WSDL_OPERATION_ATTR_NAME); foreach ($this->fun_mapping as $key => $value) { if ($value == $name) { $operation->setAttribute(WS_WSDL_Const::WS_WSDL_NAME_ATTR_NAME, $key); } } // be sensitive to the available directions $directions_arr = array(); // we anyway have the input message $directions_arr[] = WS_WSDL_Const::WS_WSDL_INPUT_ATTR_NAME; if (array_key_exists("output", $params)) { $directions_arr[] = WS_WSDL_Const::WS_WSDL_OUTPUT_ATTR_NAME; } foreach ($directions_arr as $type) { $sel = $port_doc->createElementNS(WS_WSDL_Const::WS_SCHEMA_WSDL_NAMESPACE, $type); foreach ($this->fun_mapping as $key => $value) { if ($value == $name) { $sel->setAttribute(WS_WSDL_Const::WS_WSDL_MESSAGE_ATTR_NAME, WS_WSDL_Const::WS_WSDL_TNS_ATTR_NAME . ":" . "{$key}" . ucfirst($attr_name_to_postfix_map[$type])); if ($this->use_wsa) { $action = NULL; if ($this->r_actions && is_array($this->r_actions) && array_key_exists($key, $this->r_actions)) { $action = $this->r_actions[$key]; $sel->setAttributeNS(WS_WSDL_Const::WS_WSDL_WSAW_NAMESPACE, WS_WSDL_Const::WS_WSDL_WSAW_PREFIX . ":" . WS_WSDL_CONST::WS_WSDL_ACTION, $action); } } } } $operation->appendChild($sel); } $port_el->appendChild($operation); } $port_root->appendChild($port_el); }
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; }
public function addItemElementSub($element, $sub) { $element = $this->createElement($element); foreach ($sub as $key => $value) { if (is_array($value)) { $subElement = $this->createElement($key); foreach ($value as $key => $value) { $subElement->setAttribute($key, $this->normalizeString($value)); } } else { $subElement = $this->createElement($key, $this->normalizeString($value)); } $element->appendChild($subElement); } $this->item->appendChild($element); return $this; }
/** * * @param array $item * @param DomElement $parentContainer * @return bool */ protected function _addChildMenu($item, $parentContainer, $root = false) { $active = false; $li = $this->_dom->createElement('li'); // Check if the item has an url and it is active if (array_key_exists('url', $item) && $this->_checkActive($item['url'])) { $active = true; } $a = $this->_dom->createElement('a'); if (!empty($item['url'])) { $a->setAttribute('href', $this->view->baseUrl($item['url'])); } else { $a->setAttribute('href', 'javascript:;'); } $a->appendChild($this->_dom->createTextNode($item['label'])); $li->appendChild($a); // If there are children in the item if (!empty($item['children'])) { $li->setAttribute('class', 'dropdown'); $a->setAttribute('class', 'dropdown-toggle'); $a->setAttribute('data-toggle', 'dropdown'); $spanArrow = $this->_dom->createElement('span'); $spanArrow->setAttribute('class', 'arrow'); $a->appendChild($spanArrow); $ulContainer = $this->_dom->createElement('ul'); $ulContainer->setAttribute('class', 'dropdown-menu'); // Attach all the children itens foreach ($item['children'] as $child) { $activeTest = $this->_addChildMenu($child, $ulContainer); if ($activeTest) { $active = $activeTest; } } if ($ulContainer->childNodes->length < 1) { return false; } $li->appendChild($ulContainer); } // Check if it's active if ($active) { $this->_setActive($li, $root); } $parentContainer->appendChild($li); return $active; }
/** * Tests GadgetHtmlRenderer->addHeadTags() */ public function testAddHeadTags() { ob_start(); $this->GadgetHtmlRenderer->renderGadget($this->gadget, $this->view); ob_end_clean(); $this->GadgetHtmlRenderer->addHeadTags($this->domElement, $this->domDocument); $tmpNodeList = $this->domElement->getElementsByTagName("style"); $tmpNodeList = $this->domElement->getElementsByTagName("script"); $script = ''; foreach ($this->GadgetHtmlRenderer->gadget->features as $feature) { $script .= $this->gadgetContext->getRegistry()->getFeatureContent($feature, $this->gadgetContext, true); } foreach ($tmpNodeList as $tmpNode) { $this->assertEquals('text/javascript', $tmpNode->getAttribute('type')); $nodeValue = substr($tmpNode->nodeValue, 0, strpos($tmpNode->nodeValue, 'gadgets.config.init(')); $this->assertEquals(trim($script), trim($nodeValue)); } }
/** * Tests GadgetHtmlRenderer->addHeadTags() */ public function testAddHeadTags() { ob_start(); $this->gadgetHtmlRenderer->renderGadget($this->gadget, $this->view); ob_end_clean(); $this->gadgetHtmlRenderer->addHeadTags($this->domElement, $this->domDocument); // TODO: currently we just test the script part $tmpNodeList = $this->domElement->getElementsByTagName("script"); $scripts = $this->gadgetHtmlRenderer->getJavaScripts(); $idx = 0; foreach ($tmpNodeList as $tmpNode) { $script = $scripts[$idx++]; if ($script['type'] == 'inline') { $this->assertEquals('text/javascript', $tmpNode->getAttribute('type')); $this->assertEquals(trim($script['content']), trim($tmpNode->nodeValue)); } else { $this->assertEquals($script['content'], $tmpNode->getAttribute('src')); } } }
public function addExtension($type, $value) { // get container if (!$this->extensionsDomElement) { // get creatives tag $this->extensionsDomElement = $this->domElement->getElementsByTagName('Extensions')->item(0); if (!$this->extensionsDomElement) { $this->extensionsDomElement = $this->domElement->ownerDocument->createElement('Extensions'); $this->domElement->firstChild->appendChild($this->extensionsDomElement); } } // Creative dom element $extensionDomElement = $this->extensionsDomElement->ownerDocument->createElement('Extension'); $this->extensionsDomElement->appendChild($extensionDomElement); // create cdata $cdata = $this->domElement->ownerDocument->createCDATASection($value); // append $extensionDomElement->setAttribute('type', $type); $extensionDomElement->appendChild($cdata); return $this; }
/** * Appends an element as a child to another element. * * @param \DomElement $element * @param \DomElement $child * @throws SoapException\AppendChildException */ public function appendChildToElement(\DomElement $element, \DomElement $child) { try { return $element->appendChild($child); } catch (\Exception $e) { throw new SoapException\AppendChildException(sprintf("Error appending element: [%s] %s", get_class($e), $e->getMessage())); } }
/** * Allocates member variables currentElement. * Parses for specific child node "required-if-fulltext" and sets the value "required" to true in case a fulltext has been uploaded. * @param DomElement $field */ private function _parseRequiredIfFulltext(DomElement $field, $currentElement) { if ($field->hasChildNodes()) { foreach ($field->getElementsByTagname('required-if-fulltext') as $fulltext) { if ($this->session->fulltext === '1') { $currentElement->setRequired(true); $this->log->debug("currentElement : " . $currentElement->getElementName() . " and its required has been set to true!"); } else { $this->log->debug("currentElement : " . $currentElement->getElementName() . " and its required hasn't been changed!"); } } } }
/** * @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; }
protected static function createPathElement(DOMDocument $xml, \DomElement $targetNode, $path) { $pathnode = $xml->createElement("path-element"); $pathtext = $xml->createTextNode($path); $pathnode->appendChild($pathtext); $targetNode->appendChild($pathnode); }
/** * @param \DomDocument $dom * @param \DomElement $parentNode * @param string $relUri1 * @param string $relUri2 * @param string $relationshipUri */ protected function createCompetencyFrameworkRelationNode(\DomDocument $dom, \DomElement $parentNode, $relUri1, $relUri2, $relationshipUri) { $relationNode = $dom->createElement('cf:Relation'); $parentNode->appendChild($relationNode); $referenceNode = $dom->createElement('cf:Reference1'); $relationNode->appendChild($referenceNode); $catalogNode = $dom->createElement('cf:Catalog', 'URI'); $referenceNode->appendChild($catalogNode); $entryNode = $dom->createElement('cf:Entry', $relUri1); $referenceNode->appendChild($entryNode); $relationshipNode = $dom->createElement('cf:Relationship', $relationshipUri); $relationNode->appendChild($relationshipNode); $referenceNode = $dom->createElement('cf:Reference2'); $relationNode->appendChild($referenceNode); $catalogNode = $dom->createElement('cf:Catalog', 'URI'); $referenceNode->appendChild($catalogNode); $entryNode = $dom->createElement('cf:Entry', $relUri2); $referenceNode->appendChild($entryNode); }
/** * Parses the state. * * @param DomElement $state * @return array */ function _parseState($state) { $parsedState = array(); $parsedTransitions = array(); $transitions = $state->get_elements_by_tagname('transition'); for ($i = 0, $count = count($transitions); $i < $count; ++$i) { $parsedTransition = array(); if ($transitions[$i]->has_attribute('event')) { $parsedTransition['event'] = $transitions[$i]->get_attribute('event'); } if ($transitions[$i]->has_attribute('nextState')) { $parsedTransition['nextState'] = $transitions[$i]->get_attribute('nextState'); } $action = $transitions[$i]->get_elements_by_tagname('action'); if (count($action)) { $parsedTransition['action'] = $this->_parseAction($action[0]); } $guard = $transitions[$i]->get_elements_by_tagname('guard'); if (count($guard)) { $parsedTransition['guard'] = $this->_parseAction($guard[0]); } $parsedTransitions[] = $parsedTransition; } if (count($parsedTransitions)) { $parsedState['transition'] = $parsedTransitions; } $entry = $state->get_elements_by_tagname('entry'); if (count($entry)) { $parsedState['entry'] = $this->_parseAction($entry[0]); } $exit = $state->get_elements_by_tagname('exit'); if (count($exit)) { $parsedState['exit'] = $this->_parseAction($exit[0]); } $activity = $state->get_elements_by_tagname('activity'); if (count($activity)) { $parsedState['activity'] = $this->_parseAction($activity[0]); } return $parsedState; }