Example #1
0
 /**
  * @param \DOMDocument|\DOMElement $dom
  * @return array
  */
 private function convertXmlToArray($dom)
 {
     $result = array();
     if ($dom->hasChildNodes()) {
         $children = $dom->childNodes;
         if (1 === $children->length) {
             $child = $children->item(0);
             if ($child->nodeType == XML_TEXT_NODE) {
                 $result['_value'] = $child->nodeValue;
                 return urldecode(count($result) == 1 ? $result['_value'] : $result);
             }
         }
         $groups = array();
         foreach ($children as $child) {
             if (!isset($result[$child->nodeName])) {
                 $result[$child->nodeName] = $this->convertXmlToArray($child);
             } else {
                 if (!isset($groups[$child->nodeName])) {
                     $result[$child->nodeName] = array($result[$child->nodeName]);
                     $groups[$child->nodeName] = 1;
                 }
                 $result[$child->nodeName][] = $this->convertXmlToArray($child);
             }
         }
     }
     return $result;
 }
Example #2
0
 /**
  * If here is already data in the buffer, add a separator before starting the next.
  *
  * @return boolean
  */
 public function visitEnterSelectorSequence()
 {
     if ($this->_current === $this->_dom->documentElement && $this->_current->hasChildNodes()) {
         $this->_current->appendChild($this->_dom->createElementNs($this->_xmlns, 'text'))->appendChild($this->_dom->createCDATASection(', '));
     }
     return $this->start($this->appendElement('selector'));
 }
 /**
  * @param \DOMNode $node
  * @param $path
  * @return array|string
  */
 protected function toArrayTree(\DOMElement $node, $path)
 {
     $hasChildren = false;
     $record = [];
     $currentPath = $path . '/' . $node->nodeName;
     if ($node->hasChildNodes()) {
         foreach ($node->childNodes as $child) {
             if ($child instanceof \DOMElement) {
                 $hasChildren = true;
                 if (in_array($currentPath, $this->iterationPath) && in_array($child->nodeName, $this->iterationTag)) {
                     $record[$child->nodeName][] = $this->toArrayTree($child, $currentPath);
                 } else {
                     $record[$child->nodeName] = $this->toArrayTree($child, $currentPath);
                 }
             }
         }
     }
     if ($node->hasAttributes()) {
         $record["_attributes"] = [];
         foreach ($node->attributes as $attr) {
             $record["_attributes"][$attr->name] = $attr->value;
         }
         if (!$hasChildren) {
             $record["_value"] = $node->nodeValue;
         }
     } elseif (!$hasChildren) {
         $record = trim($node->nodeValue);
     }
     return $record;
 }
Example #4
0
 function parseParagraph(DOMDocument $slide_xml, DOMElement $paragraph)
 {
     $runs = array();
     if ($paragraph->hasChildNodes()) {
         $paragraph_nodes = $paragraph->childNodes;
         //DOMNodeList
         $i = 0;
         // running through the runs here
         foreach ($paragraph_nodes as $paragraph_node) {
             if ($paragraph_node->nodeName == "a:fld") {
                 $runs[$i]['content'] = $this->parseNodeField($slide_xml, $paragraph_node);
             }
             if ($paragraph_node->nodeName == "a:pPr") {
                 $runs['properties'] = $this->parseNodeProperties($paragraph_node);
                 continue;
             }
             if ($paragraph_node->nodeName == 'a:r') {
                 list($string, $run_parameters) = $this->parseNodeRun($slide_xml, $paragraph_node);
                 $runs[$i]['content'] = $string;
                 foreach ($run_parameters as $parameter_name => $parameter_value) {
                     $runs[$i][$parameter_name] = $parameter_value;
                 }
             }
             // remove empty runs
             if (empty($runs[$i]['content'])) {
                 unset($runs[$i]);
             }
             if (empty($runs['properties']['bullet_type'])) {
                 unset($runs['properties']['bullet_type']);
             }
             $i++;
         }
     }
     return $runs;
 }
 /**
  * Map from DOMElement to neutral field map.
  *
  * @param DOMElement $itemDataFromFeed
  * @return array map of neutral fields to values.
  */
 public function map($itemDataFromFeed)
 {
     $map = array_fill_keys([$this->fieldMap[FeedMeItemModelExtension::TitleFieldName], $this->fieldMap[FeedMeItemModelExtension::BodyFieldName], $this->fieldMap[FeedMeItemModelExtension::ExternalIDFieldName], $this->fieldMap[FeedMeItemModelExtension::LinkFieldName], $this->fieldMap[FeedMeItemModelExtension::LastPublishedFieldName]], '');
     if ($itemDataFromFeed->hasChildNodes()) {
         $this->children($itemDataFromFeed->childNodes, $map);
     }
     return $map;
 }
    /**
     * @param string $name
     * @return bool
     */
    public function getChildByName($name)
    {
        if ($this->fieldNode->hasChildNodes())
        {
            $childNodes = $this->fieldNode->childNodes;

            for ($i = 0; $i < $childNodes->length; $i++)
            {
                $childNode = $childNodes->item($i);

                if ($childNode instanceof DOMElement && $childNode->hasAttribute('name'))
                {
                    if ($childNode->getAttribute('name') == $name)
                    {
                        return $childNode->nodeValue;
                    }
                }
            }
        }

        return false;
    }
 /**
  * Class EcasPhpCASParser
  * @param \DOMElement $root XML element coming from phpCAS
  * @return array Attributes
  * @see \phpCAS
  */
 public function parse(\DOMElement $root)
 {
     phpCAS::trace('Found attribute ' . $root->nodeName);
     $result = array();
     if ($root->hasAttributes()) {
         $attrs = $root->attributes;
         foreach ($attrs as $attr) {
             if ($attr->name == 'number') {
                 continue;
             }
             phpCAS::trace('Additional attribute ' . $attr->name . ' : ' . $attr->value);
             $result['@attributes'][$attr->name] = $attr->value;
         }
     }
     if ($root->hasChildNodes()) {
         $children = $root->childNodes;
         if ($children->length == 1) {
             $child = $children->item(0);
             if ($child->nodeType == XML_TEXT_NODE) {
                 $result['_value'] = $child->nodeValue;
                 return count($result) == 1 ? $result['_value'] : $result;
             }
         }
         $groups = array();
         foreach ($children as $child) {
             $nodeName = str_replace('cas:', '', $child->nodeName);
             phpCAS::traceBegin();
             if ($nodeName == 'groups') {
                 $result['groups'] = array();
                 phpCas::traceBegin();
                 foreach ($child->childNodes as $groupChild) {
                     $result['groups'][] = $this->parse($groupChild);
                 }
                 phpCAS::traceEnd('Parsed groups');
             } elseif (!isset($result[$nodeName])) {
                 $result[$nodeName] = $this->parse($child);
             } else {
                 if (!isset($groups[$nodeName])) {
                     $result[$nodeName] = array($result[$nodeName]);
                     $groups[$nodeName] = 1;
                 }
                 $result[$nodeName][] = $this->parse($child);
             }
             phpCAS::traceEnd();
         }
     }
     return $result;
 }
Example #8
0
 /**
  *
  * @param DOMElement $rootNode
  * @param DOMElement $newNode
  */
 protected function _appendNodeAlphabetically(DOMElement $rootNode, DOMElement $newNode)
 {
     if ($newNode->hasChildNodes()) {
         $refNode = null;
         foreach ($rootNode->childNodes as $child) {
             if ($child instanceof DOMElement && $child->tagName > $newNode->tagName) {
                 $refNode = $child;
                 break;
             }
         }
         if ($refNode) {
             $rootNode->insertBefore($newNode, $refNode);
         } else {
             $rootNode->appendChild($newNode);
         }
     }
 }
 /**
  * Enlève les élements vide d'un noeud
  *
  * @param DOMElement $node DOMElement
  *
  * @return void
  */
 function purgeEmptyElementsNode($node)
 {
     // childNodes undefined for non-element nodes (eg text nodes)
     if ($node->childNodes) {
         // Copy childNodes array
         $childNodes = array();
         foreach ($node->childNodes as $childNode) {
             $childNodes[] = $childNode;
         }
         // Browse with the copy (recursive call)
         foreach ($childNodes as $childNode) {
             $this->purgeEmptyElementsNode($childNode);
         }
     }
     // Remove if empty
     if (!$node->hasChildNodes() && !$node->hasAttributes() && $node->nodeValue === "") {
         $node->parentNode->removeChild($node);
     }
 }
 /**
  * Get navigation html
  * 
  * @return string
  */
 public function getNavigationHtml()
 {
     $modules = Uni_Fox::getModules();
     $doc = new DOMDocument();
     $this->finalMenuTree = new DOMDocument();
     $this->finalMenuTree->formatOutput = true;
     $this->root = Uni_Data_XDOMDocument::createNode('menus', NULL, $this->finalMenuTree);
     $this->finalMenuTree->appendChild($this->root);
     $this->sourceQueue = array();
     $this->targetQueue = array();
     if (is_array($modules)) {
         foreach ($modules as $module) {
             if ($doc->load($module['path'] . DIRECTORY_SEPARATOR . 'conf' . DIRECTORY_SEPARATOR . 'config.xml')) {
                 $xPath = new DOMXPath($doc);
                 $menus = $xPath->query('/config/admin/menus');
                 if ($menus->length > 0) {
                     foreach ($menus as $menu) {
                         $this->getFinalMenuTree($menu);
                     }
                 }
             }
         }
     }
     if (isset($this->finalMenuTree) && $this->root->hasChildNodes()) {
         $this->optimizeMenuTree();
         $this->mnuDoc = new DOMDocument();
         $this->mnuDoc->formatOutput = true;
         $this->mnuRoot = Uni_Data_XDOMDocument::createNode('ul', array('class' => 'admin-nav-menu'), $this->mnuDoc);
         $this->mnuDoc->appendChild($this->mnuRoot);
         $this->createMenu($this->root);
         if (isset($this->mnuDoc)) {
             $this->menuHTML = $this->mnuDoc->saveXML($this->mnuRoot);
             return $this->menuHTML;
         }
     }
 }
Example #11
0
 /**
  * Allocates member variables of currentElement or can be used for subfields.
  * Parses for default values and the possibility of edit and make it public.
  * @param DOMElement $field
  * @param Publish_Model_FormElement $subfield
  * @return false if there are no child nodes
  */
 private function _parseDefaultEntry($currentElement, DOMElement $field, Publish_Model_FormElement $subfield = null)
 {
     if ($field->hasChildNodes()) {
         foreach ($field->getElementsByTagname('default') as $default) {
             if ($default->hasAttributes()) {
                 $defaultArray = array();
                 $forValue = $default->getAttribute('for');
                 if (isset($forValue)) {
                     $defaultArray['for'] = $forValue;
                 }
                 $value = $default->getAttribute('value');
                 if (isset($value)) {
                     $defaultArray['value'] = $value;
                 }
                 $edit = $default->getAttribute('edit');
                 if (isset($edit)) {
                     $defaultArray['edit'] = $edit;
                 }
                 $public = $default->getAttribute('public');
                 if (isset($public)) {
                     $defaultArray['public'] = $public;
                 }
                 if (!isset($subfield)) {
                     $currentElement->setDefaultValue($defaultArray);
                     $this->log->debug(__METHOD__ . " : " . $value);
                 } else {
                     $subfield->setDefaultValue($defaultArray);
                 }
             } else {
                 return false;
             }
         }
     }
 }
Example #12
0
 protected function find_unique_key(DOMElement $el)
 {
     if ($el->hasChildNodes()) {
         if ($el->childNodes->length) {
             foreach ($el->childNodes as $child) {
                 if ($child instanceof DOMElement) {
                     if (!in_array($child->nodeName, $this->_unique_key)) {
                         $this->_unique_key[] = $child->nodeName;
                     }
                     $this->find_unique_key($child);
                 }
             }
         }
     }
 }
Example #13
0
 protected function hasBlockChild(\DOMElement $element)
 {
     if ($element->hasChildNodes()) {
         $filter = new DOMElementFilter(new RecursiveDOMIterator($element));
         $recursive = new \RecursiveIteratorIterator($filter, \RecursiveIteratorIterator::SELF_FIRST);
         foreach ($recursive as $element) {
             if ($this->isBlockElement($element)) {
                 return TRUE;
             }
         }
     }
     return FALSE;
 }
Example #14
0
 /**
  * Search for min and max supported UPnP version
  *
  * @access protected
  * 
  * @param \DOMDocument $doc
  * @param \DOMElement $tag
  */
 protected function parseSpecVersion(DOMDocument &$doc, $tag)
 {
     if ($tag->hasChildNodes()) {
         foreach ($tag->childNodes as $node) {
             switch ($node->tagName) {
                 case 'major':
                     $this->specVersion_max = $node->textContent;
                     break;
                 case 'minor':
                     $this->specVersion_min = $node->textContent;
                     break;
             }
         }
     }
 }
Example #15
0
 /**
  * Parse the given DOMElement into containers and widgets and add them to the form
  *
  * @param DOMElement $element
  * @param One_Form_Container_Abstract $container
  */
 protected static function _parseToForm(DOMElement $element, One_Form_Container_Abstract $container)
 {
     $current = strtolower($element->localName);
     if ($current == 'constraints' || $current == 'constraint') {
         return NULL;
     }
     $widgetClass = self::identifyElement($current);
     if (is_null($widgetClass)) {
         return NULL;
     }
     if (is_object($widgetClass)) {
         $widgetClass = get_class($widgetClass);
     }
     if (preg_match('/^One_Form_Container/', $widgetClass) && $widgetClass != 'One_Form_Container_Form') {
         $attributes = array();
         $rawAttributes = $element->attributes;
         for ($i = 0; $i < $rawAttributes->length; $i++) {
             $attribute = $rawAttributes->item($i);
             $attributes[$attribute->localName] = $attribute->value;
         }
         if (false === isset($attributes['language'])) {
             $attributes['language'] = strtolower(One_Config::get('app.language'));
         }
         $subContainerId = isset($attributes['id']) ? $attributes['id'] : NULL;
         $subContainer = new $widgetClass($subContainerId, $attributes);
         // containers can contain other containers or widgets
         if ($element->hasChildNodes()) {
             foreach ($element->childNodes as $child) {
                 if ($child instanceof DOMElement) {
                     self::_parseToForm($child, $subContainer);
                 }
             }
         }
         $container->addContainer($subContainer);
     } else {
         if ($element->hasAttribute('role')) {
             // Get cache in preparation of possible option-caching
             $session = One_Repository::getSession();
             $parts = explode(':', $element->getAttribute('role'));
             if (count($parts) != 2) {
                 throw new One_Exception('You must define a valid role');
             }
             $relation = One_Repository::getRelation($parts[0]);
             $role = $relation->getRole($parts[1]);
             $relScheme = One_Repository::getScheme($role->schemeName);
             // set the name and id of the so it will be recognised as a related field
             $element->setAttribute('id', 'r__' . $element->getAttribute('role'));
             $element->setAttribute('name', 'r__' . $element->getAttribute('role'));
             if ($element->hasAttribute('optionsFrom')) {
                 $sessionCacheName = md5($relScheme->getName() . '#' . $element->getAttribute('optionsFrom'));
                 if (false === $element->hasAttribute('cacheOptions') || $element->hasAttribute('cacheOptions') && false === $session->varExists($sessionCacheName, 'One_Form_Cache')) {
                     $relView = new One_View($relScheme->getName(), $element->getAttribute('optionsFrom'));
                     $rawOptions = trim($relView->show());
                     $options = json_decode($rawOptions, 1);
                     if (false === is_array($options)) {
                         $options = array();
                     }
                     if ($element->hasAttribute('cacheOptions')) {
                         $session->set($sessionCacheName, $options, 'One_Form_Cache');
                     }
                 } else {
                     $options = $session->get($sessionCacheName, 'One_Form_Cache');
                 }
             } else {
                 if (!$element->hasAttribute('targetAttribute')) {
                     $targetAttr = $relScheme->getIdentityAttribute()->getName();
                 } else {
                     $targetAttr = $element->getAttribute('targetAttribute');
                 }
                 $sessionCacheName = md5($relScheme->getName() . '#' . $targetAttr . '#' . $element->getAttribute('publishedOnly'));
                 if (false === $element->hasAttribute('cacheOptions') || $element->hasAttribute('cacheOptions') && false === $session->varExists($sessionCacheName, 'One_Form_Cache')) {
                     $q = One_Repository::selectQuery($relScheme->getName());
                     $tparts = explode(':', $targetAttr);
                     foreach ($tparts as $tkey => $tval) {
                         if (in_array(substr($tval, 0, 1), array('(', '['))) {
                             $tparts[$tkey] = substr($tval, 1) . '+';
                         } else {
                             $tparts[$tkey] = $tval . '+';
                         }
                     }
                     $q->setOrder($tparts);
                     $results = $q->execute(false);
                     $options = array();
                     foreach ($results as $result) {
                         $idAttr = $relScheme->getIdentityAttribute()->getName();
                         $valAttr = $targetAttr;
                         $val = '';
                         foreach (explode(':', $targetAttr) as $tkey => $tval) {
                             switch (substr($tval, 0, 1)) {
                                 case '(':
                                     $tval = substr($tval, 1);
                                     $val .= '(' . $result->{$tval} . ') ';
                                     break;
                                 case '[':
                                     $tval = substr($tval, 1);
                                     $val .= '[' . $result->{$tval} . '] ';
                                     break;
                                 default:
                                     $val .= $result->{$tval} . ' ';
                                     break;
                             }
                         }
                         $options[$result->{$idAttr}] = trim($val);
                     }
                     if ($element->hasAttribute('cacheOptions')) {
                         $session->set($sessionCacheName, $options, 'One_Form_Cache');
                     }
                 } else {
                     $options = $session->get($sessionCacheName, 'One_Form_Cache');
                 }
             }
             $widget = self::determineWidget($container, $element, $widgetClass);
             if (method_exists($widget, 'setOptionsOnDetermination') && $widget->setOptionsOnDetermination()) {
                 $widget->setOptions($options);
             }
         } else {
             $widget = self::determineWidget($container, $element, $widgetClass);
         }
     }
 }
Example #16
0
 /**
  * Recupera a descrição adicionada para o elemento.
  * @param \DOMElement $node
  * @return string 
  */
 public function getDocumentation(\DOMElement $node)
 {
     $description = null;
     if (!$node->hasChildNodes()) {
         return $description;
     }
     foreach ($node->childNodes as $child) {
         if ($node->localName == 'documentation') {
             $description = $node->nodeValue;
         }
         if ($child->hasChildNodes()) {
             $description = $this->getDocumentation($child);
         }
         if (!is_null($description)) {
             break;
         }
     }
     return $description;
 }
 /**
  * convert element to wxr params
  * @param DOMElement $element
  * @param null $docu
  * @return DOMElement
  */
 public static function element_to_wxr_params(DOMElement $element, DOMDocument $docu = null)
 {
     if ($element->tagName !== 'hw:params') {
         $doc = new DOMDocument(self::XML_VERSION, self::XML_ENCODING);
         $parent = $doc->createElement('hw:params');
         if ($element->hasChildNodes()) {
             foreach ($element->childNodes as $item) {
                 $parent->appendChild($doc->importNode($item, true));
             }
         } else {
             $parent->appendChild($doc->importNode($element, true));
         }
     } else {
         $parent = $element;
     }
     return $docu instanceof DOMDocument ? $docu->importNode($parent, true) : $parent;
 }
Example #18
0
 private function parseBlock(\DOMElement $node, $context)
 {
     /*{{{*/
     // ---------- Set up the context to pass to children
     $text = "";
     $context['line_prefix'] = '';
     $context['line_suffix'] = '';
     if ($node->hasAttribute('indent')) {
         $context['indent'] .= $node->getAttribute('indent');
         $context['depth']++;
     }
     if ($node->hasAttribute('bullet')) {
         $context['bullet'] = $node->getAttribute('bullet');
         // If we have a bullet, add a small padding
         // to following lines
         $context['line_prefix'] = '  ';
     }
     if ($node->hasAttribute('border-left')) {
         $context['indent'] .= $node->getAttribute('border-left');
     }
     if ($node->hasAttribute('border-right')) {
         // FIXME: Not yet implemented
         $context['line_suffix'] .= $node->getAttribute('border-right');
     }
     if ($node->hasAttribute('raw')) {
         // FIXME: should this really apply to all descendants ?
         $context['raw'] = true;
     }
     // ---------- Parse children
     if ($node->hasChildNodes()) {
         $children = $node->childNodes;
         $len = $children->length;
         $first = $children->item(0);
         if ($first->nodeType == XML_ELEMENT_NODE) {
             if ($first->hasAttribute('indent')) {
                 // we need to apply ident ourselves before going deeper
                 $text .= $context['indent'] . $context['bullet'];
                 // if we are an indenting block, add a linebreak,
                 // since following nodes could end up on the same line
                 if ($node->hasAttribute('indent')) {
                     $text .= "\n";
                 }
             }
             $text .= $this->parseNode($first, $context);
         } else {
             if ($first->nodeType == XML_TEXT_NODE) {
                 $text .= $this->parseTextNode($first, $context);
             }
         }
         // Apply bullets only to first child
         $context['bullet'] = "";
         for ($i = 1; $i < $len; $i++) {
             $child = $children->item($i);
             $text .= $this->parseNode($child, $context);
         }
     } else {
         // empty block
         $text = $context['indent'] . $context['bullet'] . $context['line_prefix'] . $context['line_suffix'] . "\n";
     }
     // ---------- Apply box-model
     if ($node->hasAttribute('box')) {
         // boxify
         $text = $this->boxify($text, $node->getAttribute('box'));
     } else {
         // borders
         $text = $this->applyBorders($node, $text, $context);
     }
     $text = $this->applyLineBreaks($node, $text);
     return $text;
 }
Example #19
0
 /**
  * Converts a DOMElement to a stdClass object, where each child element is
  * a field. Attribute values are ignored.
  * @param DOMElement $element the element to convert
  * @returns Object the converted object
  */
 private static function ConvertElementToObject($element)
 {
     $result = array();
     if ($element->hasChildNodes()) {
         $numChildNodes = $element->childNodes->length;
         for ($i = 0; $i < $numChildNodes; $i++) {
             $childNode = $element->childNodes->item($i);
             if ($childNode instanceof DOMElement) {
                 $name = $childNode->tagName;
                 $value = self::ConvertElementToObject($childNode);
                 if (isset($result[$name])) {
                     if (!is_array($result[$name])) {
                         $result[$name] = array($result[$name]);
                     }
                     $result[$name][] = $value;
                 } else {
                     $result[$name] = $value;
                 }
             }
         }
     }
     if (sizeof($result) > 0) {
         return (object) $result;
     } else {
         return self::ConvertNodeValueToObject($element->nodeValue);
     }
 }
Example #20
0
 /**
  * @param DOMElement $root
  * @param bool $eagerAttributes
  * @return array|string
  */
 function ifw_xml_to_array(DOMElement $root, $eagerAttributes = false)
 {
     $result = array();
     if ($root->hasAttributes()) {
         $attrs = $root->attributes;
         foreach ($attrs as $attr) {
             $result['@attributes'][$attr->name] = $attr->value;
         }
     }
     if ($root->hasChildNodes()) {
         $children = $root->childNodes;
         if ($children->length == 1) {
             $child = $children->item(0);
             if ($child->nodeType == XML_TEXT_NODE) {
                 if (!$eagerAttributes) {
                     $result = $child->nodeValue;
                     return $result;
                 } else {
                     $result['_value'] = $child->nodeValue;
                     return count($result) == 1 ? $result['_value'] : $result;
                 }
             }
         }
         $groups = array();
         foreach ($children as $child) {
             if (!isset($result[$child->nodeName])) {
                 $result[$child->nodeName] = ifw_xml_to_array($child);
             } else {
                 if (!isset($groups[$child->nodeName])) {
                     $result[$child->nodeName] = array($result[$child->nodeName]);
                     $groups[$child->nodeName] = 1;
                 }
                 $result[$child->nodeName][] = ifw_xml_to_array($child);
             }
         }
     }
     return $result;
 }
 /**
  * Helper function for xml2array
  * @param DOMElement $element
  * @return boolean
  */
 private static function hasChildren(DOMElement &$element)
 {
     $hasChildren = false;
     if ($element->hasChildNodes()) {
         foreach ($element->childNodes as $node) {
             if ($node->nodeType == XML_ELEMENT_NODE) {
                 $hasChildren = true;
                 break;
             }
         }
     }
     return $hasChildren;
 }
Example #22
0
 /**
  * Process DOM node.
  *
  * @param DOMDocument $doc  Document node.
  * @param DOMElement $node  Element node.
  *
  * @return string  The plaintext representation.
  */
 protected function _node($doc, $node)
 {
     $out = '';
     if (!empty($this->_params['nestingLimit']) && $this->_nestingLevel > $this->_params['nestingLimit']) {
         $this->_nestingLevel--;
         return;
     }
     $this->_nestingLevel++;
     if ($node->hasChildNodes()) {
         foreach ($node->childNodes as $child) {
             if ($this->_params['callback'] && ($txt = call_user_func($this->_params['callback'], $doc, $child)) !== null) {
                 $out .= $txt;
                 continue;
             }
             if ($child instanceof DOMElement) {
                 switch (Horde_String::lower($child->tagName)) {
                     case 'h1':
                     case 'h2':
                     case 'h3':
                         $out .= "\n\n" . strtoupper($this->_node($doc, $child)) . "\n\n";
                         break;
                     case 'h4':
                     case 'h5':
                     case 'h6':
                         $out .= "\n\n" . ucwords($this->_node($doc, $child)) . "\n\n";
                         break;
                     case 'b':
                     case 'strong':
                         $out .= strtoupper($this->_node($doc, $child));
                         break;
                     case 'u':
                         $out .= '_' . $this->_node($doc, $child) . '_';
                         break;
                     case 'em':
                     case 'i':
                         $out .= '/' . $this->_node($doc, $child) . '/';
                         break;
                     case 'hr':
                         $out .= "\n-------------------------\n";
                         break;
                     case 'ol':
                     case 'ul':
                     case 'dl':
                         ++$this->_indent;
                         $out .= "\n" . $this->_node($doc, $child) . "\n";
                         --$this->_indent;
                         break;
                     case 'p':
                         if ($tmp = $this->_node($doc, $child)) {
                             if (!strspn(substr($out, -2), "\n")) {
                                 $out .= "\n";
                             }
                             if (strlen(trim($tmp))) {
                                 $out .= $tmp . "\n";
                             }
                         }
                         break;
                     case 'table':
                         if ($tmp = $this->_node($doc, $child)) {
                             $out .= "\n\n" . $tmp . "\n\n";
                         }
                         break;
                     case 'tr':
                         $out .= "\n  " . trim($this->_node($doc, $child));
                         break;
                     case 'th':
                         $out .= strtoupper($this->_node($doc, $child)) . " \t";
                         break;
                     case 'td':
                         $out .= $this->_node($doc, $child) . " \t";
                         break;
                     case 'li':
                     case 'dd':
                     case 'dt':
                         $out .= "\n" . str_repeat('  ', $this->_indent) . '* ' . $this->_node($doc, $child);
                         break;
                     case 'a':
                         $out .= $this->_node($doc, $child) . $this->_buildLinkList($doc, $child);
                         break;
                     case 'blockquote':
                         $tmp = trim(preg_replace('/\\s*\\n{3,}/', "\n\n", $this->_node($doc, $child)));
                         if (class_exists('Horde_Text_Flowed')) {
                             $flowed = new Horde_Text_Flowed($tmp, $this->_params['charset']);
                             $flowed->setMaxLength($this->_params['width']);
                             $flowed->setOptLength($this->_params['width']);
                             $tmp = $flowed->toFlowed(true);
                         }
                         if (!strspn(substr($out, -1), " \r\n\t")) {
                             $out .= "\n";
                         }
                         $out .= "\n" . rtrim($tmp) . "\n\n";
                         break;
                     case 'div':
                         $out .= $this->_node($doc, $child) . "\n";
                         break;
                     case 'br':
                         $out .= "\n";
                         break;
                     default:
                         $out .= $this->_node($doc, $child);
                         break;
                 }
             } elseif ($child instanceof DOMText) {
                 $tmp = $child->textContent;
                 $out .= strspn(substr($out, -1), " \r\n\t") ? ltrim($child->textContent) : $child->textContent;
             }
         }
     }
     if (!empty($this->_params['nestingLimit'])) {
         $this->_nestingLevel--;
     }
     return $out;
 }
Example #23
0
 /**
  * Extract constraint options.
  *
  * @param \DOMElement $constraint
  * @return array|null
  */
 protected function _extractConstraintOptions(\DOMElement $constraint)
 {
     if (!$constraint->hasChildNodes()) {
         return null;
     }
     $options = [];
     $children = $this->_collectChildren($constraint);
     /**
      * Read constructor arguments
      *
      * <constraint class="Constraint">
      *     <argument>
      *         <option name="minValue">123</option>
      *         <option name="maxValue">234</option>
      *     </argument>
      *     <argument>0</argument>
      *     <argument>
      *         <callback class="Class" method="method" />
      *     </argument>
      * </constraint>
      */
     $arguments = $this->_readArguments($children);
     if ($arguments) {
         $options['arguments'] = $arguments;
     }
     /**
      * Read constraint configurator callback
      *
      * <constraint class="Constraint">
      *     <callback class="Magento\Foo\Helper\Data" method="configureValidator"/>
      * </constraint>
      */
     $callback = $this->_readCallback($children);
     if ($callback) {
         $options['callback'] = $callback;
     }
     /**
      * Read constraint method configuration
      */
     $methods = $this->_readMethods($children);
     if ($methods) {
         $options['methods'] = $methods;
     }
     return $options;
 }
Example #24
0
 /**
  * @param \DOMDocument $dom
  * @param \DOMElement  $domNode
  * @param              $keyElementsCnt
  *
  * @return int         number of moved items
  */
 public function moveCustomKeyAttributesIntoElements($dom, $domNode, $keyElementsCnt)
 {
     $attributesArr = array();
     $totalMoved = 0;
     if ($domNode->hasAttributes()) {
         foreach ($domNode->attributes as $attr) {
             if (strpos($attr->nodeName, "GUIcustom_") === 0) {
                 $elemName = str_replace("GUIcustom_", "", $attr->nodeName);
                 $elemValue = $attr->nodeValue;
                 if ($domNode->hasChildNodes()) {
                     $domNode->insertBefore(new \DOMElement($elemName, $elemValue), $domNode->childNodes->item(0));
                 } else {
                     $domNode->appendChild(new \DOMElement($elemName, $elemValue));
                 }
                 $attributesArr[] = $attr->nodeName;
                 $totalMoved++;
             }
         }
         // remove must be in new foreach, previous deletes only first one
         foreach ($attributesArr as $attrName) {
             $domNode->removeAttribute($attrName);
         }
     }
     if ($totalMoved < $keyElementsCnt && $domNode->hasChildNodes()) {
         foreach ($domNode->childNodes as $child) {
             $totalMoved += $this->moveCustomKeyAttributesIntoElements($dom, $child, $keyElementsCnt);
         }
     }
     return $totalMoved;
 }
Example #25
0
 /**
  * Returns the elements with the given tag name that can be found
  * as direct children of $node.
  *
  * getElementsByTagName returns all DOMElements with the given tag name
  * regardless where in the DOM subtree they are. This method checks whether
  * the parent node matches the given node and thus determines whether it is
  * a direct child.
  *
  * @param DOMElement $node
  * @param string     $element_name
  *
  * @return DOMElement[]
  */
 protected function getDirectElementsByTagName(DOMElement $node, $element_name)
 {
     $result = array();
     if (!$node->hasChildNodes()) {
         return $result;
     }
     $elements = $node->childNodes;
     for ($i = 0; $i < $elements->length; $i++) {
         $element = $elements->item($i);
         if ($element->nodeName != $element_name) {
             continue;
         }
         $result[] = $element;
     }
     return $result;
 }
Example #26
0
 /**
  * Extracts a live property from a DOMElement.
  *
  * This method is responsible for parsing WebDAV live properties. The
  * DOMElement $domElement must be an XML element in the DAV: namepsace. If
  * the received property is not defined in RFC 2518, null is returned.
  * 
  * @param DOMElement $domElement 
  * @return ezcWebdavLiveProperty|null
  */
 protected function extractLiveProperty(DOMElement $domElement)
 {
     $property = null;
     switch ($domElement->localName) {
         case 'creationdate':
             $property = new ezcWebdavCreationDateProperty();
             if (trim($domElement->nodeValue) !== '') {
                 $property->date = new ezcWebdavDateTime($domElement->nodeValue);
             }
             break;
         case 'displayname':
             $property = new ezcWebdavDisplayNameProperty();
             if (trim($domElement->nodeValue) !== '') {
                 $property->displayName = $domElement->nodeValue;
             }
             break;
         case 'getcontentlanguage':
             $property = new ezcWebdavGetContentLanguageProperty();
             if (trim($domElement->nodeValue) !== '') {
                 // e.g. 'de, en'
                 $property->languages = array_map('trim', explode(',', $domElement->nodeValue));
             }
             break;
         case 'getcontentlength':
             $property = new ezcWebdavGetContentLengthProperty();
             if (trim($domElement->nodeValue) !== '') {
                 $property->length = trim($domElement->nodeValue);
             }
             break;
         case 'getcontenttype':
             $property = new ezcWebdavGetContentTypeProperty();
             // @todo: Should this throw an exception, if the match fails?
             // Currently, the property stays empty and the backend needs to handle this
             if (trim($domElement->nodeValue) !== '' && preg_match(self::GETCONTENTTYPE_REGEX, $domElement->nodeValue, $matches) > 0) {
                 $property->mime = $matches['mime'];
                 if (isset($matches['charset'])) {
                     $property->charset = $matches['charset'];
                 }
             }
             break;
         case 'getetag':
             $property = new ezcWebdavGetEtagProperty();
             if (trim($domElement->nodeValue) !== '') {
                 $property->etag = $domElement->nodeValue;
             }
             break;
         case 'getlastmodified':
             $property = new ezcWebdavGetLastModifiedProperty();
             if (trim($domElement->nodeValue) !== '') {
                 $property->date = new ezcWebdavDateTime($domElement->nodeValue);
             }
             break;
         case 'resourcetype':
             $property = new ezcWebdavResourceTypeProperty();
             if (trim($domElement->nodeValue) !== '') {
                 $property->type = $domElement->nodeValue;
             }
             break;
         case 'source':
             $property = new ezcWebdavSourceProperty();
             if ($domElement->hasChildNodes()) {
                 $property->links = $this->extractLinkContent($domElement);
             }
             break;
         default:
             return null;
     }
     return $property;
 }
Example #27
0
 public static function render_xml_elements_for_filtring(DOMElement $el, $path = '', $lvl = 0)
 {
     if ("" != $path) {
         if ($lvl > 1) {
             $path .= "->" . $el->nodeName;
         } else {
             $path = $el->nodeName;
         }
         echo '<option value="' . $path . '">' . $path . '</option>';
     } else {
         $path = $el->nodeName;
     }
     foreach ($el->attributes as $attr) {
         echo '<option value="' . $path . '@' . $attr->nodeName . '">' . $path . '@' . $attr->nodeName . '</option>';
     }
     if ($el->hasChildNodes()) {
         foreach ($el->childNodes as $child) {
             if ($child instanceof DOMElement) {
                 self::render_xml_elements_for_filtring($child, $path, $lvl + 1);
             }
         }
     }
 }
 private function nodeNotEmpty(\DOMElement $element)
 {
     return $element->hasChildNodes() || $element->hasAttributes();
 }
Example #29
0
 /**
  * "Convert" a DOMElement object into a PHP variable.
  *
  * @param  DOMElement $element
  * @return mixed
  * @since  Method available since Release 3.4.0
  */
 public static function xmlToVariable(DOMElement $element)
 {
     $variable = NULL;
     switch ($element->tagName) {
         case 'array':
             $variable = array();
             foreach ($element->getElementsByTagName('element') as $element) {
                 $value = self::xmlToVariable($element->childNodes->item(1));
                 if ($element->hasAttribute('key')) {
                     $variable[(string) $element->getAttribute('key')] = $value;
                 } else {
                     $variable[] = $value;
                 }
             }
             break;
         case 'object':
             $className = $element->getAttribute('class');
             if ($element->hasChildNodes()) {
                 $arguments = $element->childNodes->item(1)->childNodes;
                 $constructorArgs = array();
                 foreach ($arguments as $argument) {
                     if ($argument instanceof DOMElement) {
                         $constructorArgs[] = self::xmlToVariable($argument);
                     }
                 }
                 $class = new ReflectionClass($className);
                 $variable = $class->newInstanceArgs($constructorArgs);
             } else {
                 $variable = new $className();
             }
             break;
         case 'boolean':
             $variable = $element->nodeValue == 'true' ? TRUE : FALSE;
             break;
         case 'integer':
         case 'double':
         case 'string':
             $variable = $element->nodeValue;
             settype($variable, $element->tagName);
             break;
     }
     return $variable;
 }
Example #30
-1
function pmxe_render_xml_element(DOMElement $el, $shorten = false, $path = '/', $ind = 1, $lvl = 0)
{
    $path .= $el->nodeName;
    $alternativePath = $path;
    if (!$el->parentNode instanceof DOMDocument and $ind > 0) {
        $path .= "[{$ind}]";
    }
    echo '<div class="xml-element lvl-' . $lvl . ' lvl-mod4-' . $lvl % 4 . '" title="' . $path . '">';
    //if ($el->hasAttributes()){
    //echo '<div class="xml-element-xpaths">'; self::render_element_xpaths($el, $alternativePath, $ind, $lvl); echo '</div>';
    //}
    if ($el->hasChildNodes()) {
        $is_render_collapsed = $ind > 1;
        if ($el->childNodes->length > 1 or !$el->childNodes->item(0) instanceof DOMText or strlen(trim($el->childNodes->item(0)->wholeText)) > 40) {
            echo '<div class="xml-expander">' . ($is_render_collapsed ? '+' : '-') . '</div>';
        }
        echo '<div class="xml-tag opening">&lt;<span class="xml-tag-name">' . $el->nodeName . '</span>';
        pmxe_render_xml_attributes($el, $path . '/');
        echo '&gt;</div>';
        if (1 == $el->childNodes->length and $el->childNodes->item(0) instanceof DOMText) {
            pmxe_render_xml_text(trim($el->childNodes->item(0)->wholeText), $shorten, $is_render_collapsed);
        } else {
            echo '<div class="xml-content' . ($is_render_collapsed ? ' collapsed' : '') . '">';
            $indexes = array();
            foreach ($el->childNodes as $eli => $child) {
                if ($child instanceof DOMElement) {
                    empty($indexes[$child->nodeName]) and $indexes[$child->nodeName] = 0;
                    $indexes[$child->nodeName]++;
                    pmxe_render_xml_element($child, $shorten, $path . '/', $indexes[$child->nodeName], $lvl + 1);
                } elseif ($child instanceof DOMCdataSection) {
                    pmxe_render_xml_text(trim($child->wholeText), $shorten, false, true);
                } elseif ($child instanceof DOMText) {
                    if ($el->childNodes->item($eli - 1) and $el->childNodes->item($eli - 1) instanceof DOMCdataSection) {
                    } elseif ($el->childNodes->item($eli + 1) and $el->childNodes->item($eli + 1) instanceof DOMCdataSection) {
                    } else {
                        pmxe_render_xml_text(trim($child->wholeText), $shorten);
                    }
                } elseif ($child instanceof DOMComment) {
                    if (preg_match('%\\[pmxi_more:(\\d+)\\]%', $child->nodeValue, $mtch)) {
                        $no = intval($mtch[1]);
                        echo '<div class="xml-more">[ &dArr; ' . sprintf(__('<strong>%s</strong> %s more', 'wp_all_import_plugin'), $no, _n('element', 'elements', $no, 'wp_all_import_plugin')) . ' &dArr; ]</div>';
                    }
                }
            }
            echo '</div>';
        }
        echo '<div class="xml-tag closing">&lt;/<span class="xml-tag-name">' . $el->nodeName . '</span>&gt;</div>';
    } else {
        echo '<div class="xml-tag opening empty">&lt;<span class="xml-tag-name">' . $el->nodeName . '</span>';
        pmxe_render_xml_attributes($el);
        echo '/&gt;</div>';
    }
    echo '</div>';
}