Example #1
0
 /**
  * Convert node oto array
  *
  * @param \DOMNode $node
  * @param string $path
  * @return array|string|null
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function _convertNode(\DOMNode $node, $path = '')
 {
     $output = array();
     if ($node->nodeType == XML_ELEMENT_NODE) {
         if ($node->hasAttributes()) {
             $backendModel = $node->attributes->getNamedItem('backend_model');
             if ($backendModel) {
                 $this->_metadata[$path] = array('backendModel' => $backendModel->nodeValue);
             }
         }
         $nodeData = array();
         /** @var $childNode \DOMNode */
         foreach ($node->childNodes as $childNode) {
             $childrenData = $this->_convertNode($childNode, ($path ? $path . '/' : '') . $childNode->nodeName);
             if ($childrenData == null) {
                 continue;
             }
             if (is_array($childrenData)) {
                 $nodeData = array_merge($nodeData, $childrenData);
             } else {
                 $nodeData = $childrenData;
             }
         }
         if (is_array($nodeData) && empty($nodeData)) {
             $nodeData = null;
         }
         $output[$node->nodeName] = $nodeData;
     } elseif ($node->nodeType == XML_CDATA_SECTION_NODE || $node->nodeType == XML_TEXT_NODE && trim($node->nodeValue) != '') {
         return $node->nodeValue;
     }
     return $output;
 }
 /**
  * @param DOMNode $node
  * @param ProxyObject $proxy
  */
 private function process(DOMNode $node, ProxyObject $proxy)
 {
     $proxy->setName($node->nodeName);
     if ($node->hasAttributes()) {
         for ($i = 0; $i < $node->attributes->length; $i++) {
             $attribute = $node->attributes->item($i);
             $proxy->set($attribute->name, $attribute->value);
         }
     }
     if ($node->hasChildNodes()) {
         $nodeTypes = array();
         foreach ($node->childNodes as $childNode) {
             if ($childNode->nodeName === '#text') {
                 $proxy->setValue($childNode->nodeValue);
             } else {
                 $childProxy = new ProxyObject();
                 $this->process($childNode, $childProxy);
                 $nodeTypes[$childProxy->getName()][] = $childProxy;
             }
         }
         foreach ($nodeTypes as $tagName => $nodes) {
             $proxy->set($tagName, $nodes);
         }
     }
 }
Example #3
0
 /**
  * Zwraca liste atrybutow elementu, lub false jeżeli nie ma żadnego
  *
  * @param DOMNode $node
  *
  * @return array|bool
  */
 protected function getElementAttributes(DOMNode $node)
 {
     if ($node->hasAttributes()) {
         $arr = array();
         foreach ($node->attributes as $value) {
             $arr[$value->nodeName] = $value->nodeValue;
         }
         return $arr;
     }
     return false;
 }
Example #4
0
 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;
 }
Example #5
0
 /**
  * Rename DOMNode
  * @param \DOMNode $node
  * @param string $newName
  */
 public static function renameNode($node, $newName)
 {
     $newNode = $node->ownerDocument->createElement($newName);
     if ($node->hasAttributes()) {
         foreach ($node->attributes as $attribute) {
             $newNode->setAttribute($attribute->nodeName, $attribute->nodeValue);
         }
     }
     while ($node->firstChild) {
         $newNode->appendChild($node->firstChild);
     }
     $node->parentNode->replaceChild($newNode, $node);
 }
Example #6
0
 public function getParamDirect($name = "")
 {
     try {
         if (!$this->node instanceof DOMNode) {
             throw new LBoxExceptionConfig("Cannot get data from destructed config item (after calling config store()). Do get new instance from LBCManager");
         }
         if ($this->node->hasAttributes()) {
             foreach ($this->node->attributes as $attribute) {
                 if ($attribute->name == $name) {
                     return $attribute->value;
                 }
             }
         }
     } catch (Exception $e) {
         throw $e;
     }
 }
Example #7
0
 /**
  * Transform Xml to array
  *
  * @param \DOMNode $node
  * @return array|string
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function toArray(\DOMNode $node)
 {
     $result = [];
     $attributes = [];
     // Collect data from attributes
     if ($node->hasAttributes()) {
         foreach ($node->attributes as $attribute) {
             $attributes[$attribute->name] = $attribute->value;
         }
     }
     switch ($node->nodeType) {
         case XML_TEXT_NODE:
         case XML_COMMENT_NODE:
         case XML_CDATA_SECTION_NODE:
             break;
         default:
             if ($node->localName === static::ARGUMENT_KEY) {
                 if (!isset($attributes[static::NAME_ATTRIBUTE_KEY])) {
                     throw new \InvalidArgumentException('Attribute "' . static::NAME_ATTRIBUTE_KEY . '" is absent in the attributes node.');
                 }
                 $result[$attributes[static::NAME_ATTRIBUTE_KEY]] = $this->argumentParser->parse($node);
             } else {
                 $arguments = [];
                 for ($i = 0, $iLength = $node->childNodes->length; $i < $iLength; ++$i) {
                     $itemNode = $node->childNodes->item($i);
                     if (empty($itemNode->localName)) {
                         continue;
                     }
                     if ($itemNode->nodeName === static::ARGUMENT_KEY) {
                         $arguments += $this->toArray($itemNode);
                     } else {
                         $result[$itemNode->localName][] = $this->toArray($itemNode);
                     }
                 }
                 if (!empty($arguments)) {
                     $result[static::DATA_ARGUMENTS_KEY] = $arguments;
                 }
                 if (!empty($attributes)) {
                     $result[static::DATA_ATTRIBUTES_KEY] = $attributes;
                 }
             }
             break;
     }
     return $result;
 }
Example #8
0
 /**
  * Transform Xml to array
  *
  * @param \DOMNode $source
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function toArray(\DOMNode $source)
 {
     $result = [];
     if ($source->hasAttributes()) {
         foreach ($source->attributes as $attr) {
             $result['@attributes'][$attr->name] = $attr->value;
         }
     }
     if (!$source->hasChildNodes()) {
         if (empty($result)) {
             $result = $source->nodeValue;
         }
     } else {
         if ($source->hasChildNodes()) {
             $groups = [];
             foreach ($source->childNodes as $child) {
                 if ($child->nodeType == XML_TEXT_NODE || $child->nodeType == XML_COMMENT_NODE) {
                     continue;
                 }
                 if ($this->isTextNode($child)) {
                     $result[$child->nodeName] = $this->getTextNode($child)->data;
                 } else {
                     if (in_array($child->nodeName, ['validate', 'filter', 'readonly'])) {
                         if (!isset($result[$child->nodeName])) {
                             $result[$child->nodeName] = [];
                         }
                         $result[$child->nodeName][] = $this->toArray($child);
                     } else {
                         if (isset($result[$child->nodeName])) {
                             if (!isset($groups[$child->nodeName])) {
                                 $result[$child->nodeName] = [$result[$child->nodeName]];
                                 $groups[$child->nodeName] = 1;
                             }
                             $result[$child->nodeName][] = $this->toArray($child);
                         } else {
                             $result[$child->nodeName] = $this->toArray($child);
                         }
                     }
                 }
             }
         }
     }
     return $result;
 }
  private static function children_to_array(DOMNode $node) {
    $result = array();
    if ($node->hasAttributes()) {
      foreach ($node->attributes as $name => $attribute) {
	$result[$name] = $attribute->value;
      }
    }

    if ($node->nodeType == XML_TEXT_NODE) {
      $parentName = $node->parentNode->nodeName;
      if ($parentName == 'lat_wgs84' || $parentName == 'long_wgs84') {
	return (double)(trim($node->nodeValue));
      }
      return trim($node->nodeValue);
    }

    $aChild = $node->firstChild;

    while ($aChild !== NULL) {
      $nodeName = $aChild->nodeName;

      if ($nodeName == 'category' || $nodeName == 'contents' || $nodeName == 'floor' || $nodeName == 'altname') {
	if (!array_key_exists($nodeName, $result)) {
	  $result[$nodeName] = array();
	}
	$result[$nodeName][] = self::children_to_array($aChild);
      } else {
	$result[$nodeName] = self::children_to_array($aChild);
      }
      $aChild = $aChild->nextSibling;
    }

    if (array_key_exists('#text', $result)) {
      if (count($result) == 1) {
	return $result['#text'];
      } else {
	return array_diff_key($result, array('#text' => true));
      }
    }

    return $result;

  }
Example #10
0
/** create payload for arrays
 * @param $payload_dom - DomDocument for the payload building
 * @param $sig_node - sig model
 * @param $parent_node - The parent node to add the content
 * @param $root_node - The always parent. Just to add all the namespace declaration here..
 * @param $user_arguments - The user given arguments
 * @param $prefix_i - next available prefix index 
 * @param $namespace_map - Just make sure the unique namespace is used. Newly added
    (passed by reference)
 */
function wsf_create_payload_for_array(DomDocument $payload_dom, DOMNode $sig_node, DomNode $parent_node, DomNode $root_node, $user_arguments, &$prefix_i, array &$namespace_map, $mtom_on, &$attachement_map)
{
    ws_log_write(__FILE__, __LINE__, WSF_LOG_DEBUG, "Loading in to creating payload from arrays");
    if (wsf_set_nil_element($user_arguments, $parent_node, $root_node, $prefix_i, $namespace_map)) {
        return TRUE;
    }
    // here we always expect structures with childs
    if (!$sig_node->hasChildNodes()) {
        // Just take the first namespace in the map to create the xml elements in
        // the unknown structure..
        $values = array_values($namespace_map);
        $prefix = $values[0];
        wsf_create_payload_for_unknown_class_map($payload_dom, $parent_node, $user_obj, $prefix);
        return;
    }
    $classmap = NULL;
    if ($sig_node->hasAttributes()) {
        if (!is_array($user_arguments)) {
            ws_log_write(__FILE__, __LINE__, WSF_LOG_DEBUG, $payload_dom->localName . " can not be empty, note: just set to NULL to make it as NULL");
            wsf_set_nil_element(NULL, $parent_node, $root_node, $prefix_i, $namespace_map);
            return;
        }
        wsf_build_content_model($sig_node, $user_arguments, $parent_node, $payload_dom, $root_node, $classmap, $prefix_i, $namespace_map, $mtom_on, $attachement_map);
    } else {
        // this situation meets only for non-wrapped mode as doclit-bare wsdls
        $the_only_node = $sig_node->firstChild;
        //  handle simple content extension seperatly
        if ($the_only_node->attributes->getNamedItem(WSF_CONTENT_MODEL) && $the_only_node->attributes->getNamedItem(WSF_CONTENT_MODEL)->value == WSF_SIMPLE_CONTENT) {
            wsf_build_content_model($the_only_node, $user_arguments, $parent_node, $payload_dom, $root_node, $classmap, $prefix_i, $namespace_map, $mtom_on, $attachement_map);
        } else {
            $is_simple = FALSE;
            if ($the_only_node->attributes->getNamedItem(WSF_WSDL_SIMPLE) && $the_only_node->attributes->getNamedItem(WSF_WSDL_SIMPLE)->value == "yes") {
                $is_simple = TRUE;
            }
            $param_type = NULL;
            if ($the_only_node->attributes->getNamedItem(WSF_TYPE)) {
                $param_type = $the_only_node->attributes->getNamedItem(WSF_TYPE)->value;
            }
            if ($is_simple) {
                $is_list = FALSE;
                if ($the_only_node->attributes->getNamedItem(WSF_LIST) && $the_only_node->attributes->getNamedItem(WSF_LIST)->value == "yes") {
                    $is_list = TRUE;
                }
                if ($user_arguments === NULL || !is_array($user_arguments) || $is_list) {
                    $serialized_value = wsf_wsdl_serialize_php_value($param_type, $user_arguments, $the_only_node, $parent_node, $parent_node, $prefix_i, $namespace_map, $root_node);
                    $text_node = $payload_dom->createTextNode($serialized_value);
                    $parent_node->appendChild($text_node);
                } else {
                    if (is_array($user_arguments)) {
                        ws_log_write(__FILE__, __LINE__, WSF_LOG_ERROR, "Array is specified when non-array is expected for the root node\n");
                    }
                }
                wsf_set_nil_element($user_arguments, $parent_node, $root_node, $prefix_i, $namespace_map);
            }
        }
    }
}
Example #11
0
 /**
  * Parse the input DOMNode attributes into an array.
  *
  * @param \DOMNode $node xml to parse
  *
  * @return array
  */
 private function parseXmlAttributes(\DOMNode $node)
 {
     if (!$node->hasAttributes()) {
         return array();
     }
     $data = array();
     foreach ($node->attributes as $attr) {
         if (ctype_digit($attr->nodeValue)) {
             $data['@' . $attr->nodeName] = (int) $attr->nodeValue;
         } else {
             $data['@' . $attr->nodeName] = $attr->nodeValue;
         }
     }
     return $data;
 }
 private function parseNodeAttributes(DOMNode &$node)
 {
     if ($node->hasAttributes()) {
         foreach ($node->attributes as $attr) {
             if (strpos($attr->value, '${') !== false) {
                 $expressions = array();
                 preg_match_all('/(\\$\\{)(.*)(\\})/imsxU', $attr->value, $expressions);
                 for ($i = 0; $i < count($expressions[0]); $i++) {
                     $toReplace = $expressions[0][$i];
                     $expression = $expressions[2][$i];
                     $expressionResult = ExpressionParser::evaluate($expression, $this->dataContext);
                     switch (strtolower($attr->name)) {
                         case 'repeat':
                             // Can only loop if the result of the expression was an array
                             if (!is_array($expressionResult)) {
                                 throw new ExpressionException("Can't repeat on a singular var");
                             }
                             // Make sure the repeat variable doesn't show up in the cloned nodes (otherwise it would infinit recurse on this->parseNode())
                             $node->removeAttribute('repeat');
                             // Is a named var requested?
                             $variableName = $node->getAttribute('var') ? trim($node->getAttribute('var')) : false;
                             // Store the current 'Cur', index and count state, we might be in a nested repeat loop
                             $previousCount = isset($this->dataContext['Context']['Count']) ? $this->dataContext['Context']['Count'] : null;
                             $previousIndex = isset($this->dataContext['Context']['Index']) ? $this->dataContext['Context']['Index'] : null;
                             $previousCur = $this->dataContext['Cur'];
                             // For information on the loop context, see http://opensocial-resources.googlecode.com/svn/spec/0.9/OpenSocial-Templating.xml#rfc.section.10.1
                             $this->dataContext['Context']['Count'] = count($expressionResult);
                             foreach ($expressionResult as $index => $entry) {
                                 if ($variableName) {
                                     // this is cheating a little since we're not putting it on the top level scope, the variable resolver will check 'Cur' first though so myVar.Something will still resolve correctly
                                     $this->dataContext['Cur'][$variableName] = $entry;
                                 }
                                 $this->dataContext['Cur'] = $entry;
                                 $this->dataContext['Context']['Index'] = $index;
                                 // Clone this node and it's children
                                 $newNode = $node->cloneNode(true);
                                 // Append the parsed & expanded node to the parent
                                 $newNode = $node->parentNode->insertBefore($newNode, $node);
                                 // And parse it (using the global + loop context)
                                 $this->parseNode($newNode, true);
                             }
                             // Restore our previous data context state
                             $this->dataContext['Cur'] = $previousCur;
                             if ($previousCount) {
                                 $this->dataContext['Context']['Count'] = $previousCount;
                             } else {
                                 unset($this->dataContext['Context']['Count']);
                             }
                             if ($previousIndex) {
                                 $this->dataContext['Context']['Index'] = $previousIndex;
                             } else {
                                 unset($this->dataContext['Context']['Index']);
                             }
                             return $node;
                             break;
                         case 'if':
                             if (!$expressionResult) {
                                 return $node;
                             } else {
                                 $node->removeAttribute('if');
                             }
                             break;
                             // These special cases that only apply for certain tag types
                         // These special cases that only apply for certain tag types
                         case 'selected':
                             if ($node->tagName == 'option') {
                                 if ($expressionResult) {
                                     $node->setAttribute('selected', 'selected');
                                 } else {
                                     $node->removeAttribute('selected');
                                 }
                             } else {
                                 throw new ExpressionException("Can only use selected on an option tag");
                             }
                             break;
                         case 'checked':
                             if ($node->tagName == 'input') {
                                 if ($expressionResult) {
                                     $node->setAttribute('checked', 'checked');
                                 } else {
                                     $node->removeAttribute('checked');
                                 }
                             } else {
                                 throw new ExpressionException("Can only use checked on an input tag");
                             }
                             break;
                         case 'disabled':
                             $disabledTags = array('input', 'button', 'select', 'textarea');
                             if (in_array($node->tagName, $disabledTags)) {
                                 if ($expressionResult) {
                                     $node->setAttribute('disabled', 'disabled');
                                 } else {
                                     $node->removeAttribute('disabled');
                                 }
                             } else {
                                 throw new ExpressionException("Can only use disabled on input, button, select and textarea tags");
                             }
                             break;
                         default:
                             // On non os-template spec attributes, do a simple str_replace with the evaluated value
                             $stringVal = htmlentities(ExpressionParser::stringValue($expressionResult), ENT_QUOTES, 'UTF-8');
                             $newAttrVal = str_replace($toReplace, $stringVal, $attr->value);
                             $node->setAttribute($attr->name, $newAttrVal);
                             break;
                     }
                 }
             }
         }
     }
     // if a repeat attribute was found, don't recurse on it's child nodes, the repeat handling already did that
     if (isset($node->childNodes) && $node->childNodes->length > 0) {
         $removeNodes = array();
         // recursive loop to all this node's children
         foreach ($node->childNodes as $childNode) {
             if (($removeNode = $this->parseNode($childNode)) !== false) {
                 $removeNodes[] = $removeNode;
             }
         }
         if (count($removeNodes)) {
             foreach ($removeNodes as $removeNode) {
                 $removeNode->parentNode->removeChild($removeNode);
             }
         }
     }
     return false;
 }
Example #13
0
 /**
  * Process element attributes
  *
  * @param \DOMNode $root
  * @return array
  */
 protected function processAttributes(\DOMNode $root)
 {
     $result = [];
     if ($root->hasAttributes()) {
         $attributes = $root->attributes;
         foreach ($attributes as $attribute) {
             $result[$attribute->name] = $attribute->value;
         }
         return $result;
     }
     return $result;
 }
Example #14
0
File: core.php Project: refo/kohana
	/**
	 * Recursive as_array for child nodes
	 * @param DOMNode $dom_node
	 * @return Array
	 */
	private function _as_array(DOMNode $dom_node)
	{
		// All other nodes shall be parsed normally : attributes then text value and child nodes, running through the XML tree
		$object_element = array();
		
		// Get the desired node name for this node
		$node_name = $this->meta()->key($dom_node->tagName);
			
		// Get attributes
		if ($dom_node->hasAttributes())
		{
	 		$object_element[$dom_node->nodeName]['xml_attributes'] = array();
			foreach($dom_node->attributes as $att_name => $dom_attribute)
			{
				// Get the desired name for this attribute
				$att_name = $this->meta()->key($att_name);
		
				$object_element[$node_name]['xml_attributes'][$att_name] = $dom_attribute->value;
			}
		}
	
		// Get children, run through XML tree
		if ($dom_node->hasChildNodes())
		{
			if (!$dom_node->firstChild->hasChildNodes())
			{	
				// Get text value
				$object_element[$node_name] = trim($dom_node->firstChild->nodeValue);
			}
	
			foreach($dom_node->childNodes as $dom_child)
			{
				if ($dom_child->nodeType === XML_ELEMENT_NODE)
				{
					$child = $this->_as_array($dom_child);
						
					foreach ($child as $key=>$val)
					{
						$object_element[$node_name][$key][]=$val;
					}
				}
			}
		}
		return $object_element;
	}
 /**
  * Clean Processor call
  *
  * @param DOMNode $node DomNode to process
  *
  * @return boolean
  */
 private function cleanupNode(DOMNode $node)
 {
     if ($node->nodeType == XML_COMMENT_NODE) {
         return false;
     }
     // get ns from node
     $xmlns = $node->namespaceURI;
     if (is_null($xmlns)) {
         $xmlns = 'none';
     }
     // filter class for namespace?
     if (isset($this->filterList[$xmlns])) {
         $filterCore = $this->filterList[$xmlns];
         $filter = $filterCore->getInstanceForTagName($node->localName);
         if ($node->hasAttributes()) {
             $this->processAttributes($node, $filter);
         }
         if ($node->hasChildNodes()) {
             $this->processChildNodes($node, $filter);
         }
         return true;
     } else {
         // no filter class for this xmlns, remove node if possible
         if ($node->parentNode instanceof DOMNode) {
             $node->parentNode->removeChild($node);
             return true;
         } else {
             // cannot remove this node here, thus return false
             return false;
         }
     }
 }
Example #16
0
 /**
  * Has ID attribute
  *
  * @param \DOMNode $node
  * @return bool
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 protected function hasIdAttribute(\DOMNode $node)
 {
     if (!$node->hasAttributes()) {
         return false;
     }
     foreach ($node->attributes as $name => $attribute) {
         if (in_array($name, $this->idAttributes)) {
             return true;
         }
     }
     return false;
 }
Example #17
0
 /**
  * VQNode::__construct()
  *
  * @param DOMNode $node Search/add node
  * @return null
  * @description Parses the node attributes and sets the node property
  */
 public function __construct(DOMNode $node)
 {
     $this->_content = $node->nodeValue;
     if ($node->hasAttributes()) {
         foreach ($node->attributes as $attr) {
             $name = $attr->nodeName;
             if (isset($this->{$name})) {
                 $this->{$name} = $attr->nodeValue;
             }
         }
     }
 }
Example #18
0
 /**
  * Parse node attributes
  *
  * @param \DOMNode $node
  * @return array
  */
 protected function _parseNodeAttributes(\DOMNode $node)
 {
     $result = [];
     $attributes = [];
     if ($node->hasAttributes()) {
         foreach ($node->attributes as $oAttrNode) {
             $attributes[$oAttrNode->nodeName] = $oAttrNode->nodeValue;
         }
     }
     if (count($attributes)) {
         $result = ['@attributes' => $attributes];
     }
     return $result;
 }
Example #19
0
 /**
  * Retrieve proper node name
  *
  * @param \DOMNode $node The configuration XML node to parse
  *
  * @return string
  */
 protected function parseNodeName($node)
 {
     $nodeName = $node->nodeName;
     if ($node->hasAttributes()) {
         $storeCodeNode = $node->attributes->getNamedItem('store_code');
         $containerNameNode = $node->attributes->getNamedItem('name');
         if ($containerNameNode) {
             $nodeName = $containerNameNode->nodeValue;
             if ($storeCodeNode) {
                 $nodeName = $nodeName . "|" . $storeCodeNode->nodeValue;
             }
         }
     }
     return $nodeName;
 }
Example #20
0
 /**
  * Check two given nodes for equal attributes.
  * @param \DOMNode $node1
  * @param \DOMNode $node2
  * @return bool
  */
 private function compareAttributes(\DOMNode $node1, \DOMNode $node2)
 {
     if ($node1->hasAttributes() === false && $node2->hasAttributes() === false) {
         return true;
     }
     if ($node1->hasAttributes() !== $node2->hasAttributes()) {
         return false;
     }
     if ($node1->attributes->length !== $node2->attributes->length) {
         return false;
     }
     /** @var $attribute \DOMNode */
     foreach ($node1->attributes as $attribute) {
         // namespace problem, localName as fix
         $compareAgainst = $node2->attributes->getNamedItem($attribute->localName);
         if ($compareAgainst === null || $attribute->nodeValue !== $compareAgainst->nodeValue) {
             return false;
         }
     }
 }
Example #21
0
 /**
  * @param DOMNode $node
  * @param array $element
  * @return void
  */
 protected function xmlLoop($node, &$element)
 {
     $subject = $node->attributes->getNamedItem('subject')->nodeValue;
     static $count = 0;
     if ($subject == 'entry.fields') {
         return $this->xmlFields($element);
     } elseif (strstr($subject, '.')) {
         $tempSubject = $this->get($subject);
         $this->assign($tempSubject, 'temporary' . ++$count);
         $subject = 'temporary' . $count;
     }
     $objectsCount = $this->count($subject);
     $objects = array();
     if ($node->attributes->getNamedItem('type') && $node->attributes->getNamedItem('type')->nodeValue == 'fields') {
         $fields = $this->get($subject);
         foreach ($fields as $field) {
             if (method_exists('SPHtml_input', $field['type'])) {
                 $method = new ReflectionMethod('SPHtml_input', $field['type']);
                 $methodArgs = array();
                 $methodParams = $method->getParameters();
                 foreach ($methodParams as $param) {
                     if (isset($field[$param->name])) {
                         $methodArgs[] = $field[$param->name];
                     } elseif ($param->isDefaultValueAvailable()) {
                         $methodArgs[] = $param->getDefaultValue();
                     } else {
                         $methodArgs[] = null;
                     }
                 }
                 $objects[] = array('label' => $field['label'], 'type' => 'field', 'content' => call_user_func_array(array('SPHtml_input', $field['type']), $methodArgs), 'args' => array('type' => $field['type']), 'adds' => array('after' => array($field['required'] ? Sobi::Txt('EX.SOAP_RESP_REQ') : Sobi::Txt('EX.SOAP_RESP_OPT')), 'before' => null));
             }
         }
     } else {
         for ($i = 0; $i < $objectsCount; $i++) {
             $row = array();
             /** @var DOMNode $cell */
             foreach ($node->childNodes as $cell) {
                 if (strstr($cell->nodeName, '#')) {
                     continue;
                 }
                 $this->xmlCell($cell, $subject, $i, $row);
             }
             $a = array();
             if ($node->hasAttributes()) {
                 /** @var DOMElement $attribute */
                 foreach ($node->attributes as $attribute) {
                     $a[$attribute->nodeName] = $attribute->nodeValue;
                 }
             }
             $objects[] = array('label' => null, 'type' => 'loop-row', 'content' => $row, 'attributes' => $a);
         }
     }
     $element['content'] = $objects;
 }
Example #22
0
 /**
  * @param DOMNode $newValueNode
  * @param $snippet
  * @param $snippetValue
  * @internal param $snippetValues
  */
 private function replaceSnippetInAttributes(DOMNode $newValueNode, $snippet, $snippetValue)
 {
     $snippetValue = $this->sanitizeAttribute($snippetValue);
     if ($newValueNode->hasAttributes()) {
         for ($i = 0; $i < $newValueNode->attributes->length; $i++) {
             $newValueNode->attributes->item($i)->nodeValue = str_replace($snippet, $snippetValue, $newValueNode->attributes->item($i)->nodeValue);
         }
     }
 }
Example #23
0
 /**
  * Process element attributes
  *
  * @param \DOMNode $root
  * @return array
  */
 protected function _processAttributes(\DOMNode $root)
 {
     $result = [];
     if ($root->hasAttributes()) {
         $attributes = $root->attributes;
         foreach ($attributes as $attribute) {
             if ($root->nodeName == 'attribute' && $attribute->name == 'type') {
                 continue;
             }
             $result[$attribute->name] = $attribute->value;
         }
         return $result;
     }
     return $result;
 }
 /**
  * Given a DOMNode, this function will help replicate it as an
  * XMLElement object
  *
  * @since Symphony 2.5.2
  * @param XMLElement $element
  * @param DOMNode $node
  */
 private static function convertNode(XMLElement $element, DOMNode $node)
 {
     if ($node->hasAttributes()) {
         foreach ($node->attributes as $name => $attrEl) {
             $element->setAttribute($name, General::sanitize($attrEl->value));
         }
     }
     if ($node->hasChildNodes()) {
         foreach ($node->childNodes as $childNode) {
             if ($childNode instanceof DOMCdataSection) {
                 $element->setValue(General::wrapInCDATA($childNode->data));
             } elseif ($childNode instanceof DOMText) {
                 if ($childNode->isWhitespaceInElementContent() === false) {
                     $element->setValue(General::sanitize($childNode->data));
                 }
             } elseif ($childNode instanceof DOMElement) {
                 self::convert($element, $childNode);
             }
         }
     }
 }
Example #25
0
 /**
  * Find a node ID or generate and set one
  * 
  * @param DOMNode $node
  * @return string
  */
 private function get_node_id(DOMNode $node)
 {
     if ($node->hasAttributes() && $node->attributes->getNamedItem('id')) {
         $id = $node->attributes->getNamedItem('id')->nodeValue;
     } else {
         $id = "pmf_gen-" . count($this->parsedTemplates);
         $node->setAttributeNode(new DOMAttr('id', $id));
     }
     return $id;
 }
 /**
  * Manages list node
  * @uses WsdlToPhpGenerator::findSuitableParent()
  * @uses WsdlToPhpGenerator::setStructInheritance()
  * @uses DOMNode::hasAttributes()
  * @uses DOMNodeList::item()
  * @uses DOMElement::getAttribute()
  * @uses WsdlToPhpModel::getName()
  * @param string $_wsdlLocation the wsdl location
  * @param DOMNode $_domNode the node
  * @param string $_fromWsdlLocation the wsdl location imported
  * @param string $_nodeNameMatch the name the node name must match, only when it's necessary to match a certain type of nodes
  * @return void
  */
 protected function manageWsdlNodeList($_wsdlLocation = '', DOMNode $_domNode, $_fromWsdlLocation = '', $_nodeNameMatch = null)
 {
     if ($_domNode->hasAttributes()) {
         $parentNode = self::findSuitableParent($_domNode);
         if ($parentNode) {
             $parentNodeStruct = $this->getStruct($parentNode->getAttribute('name'));
             $attributes = $_domNode->attributes;
             $attributesCount = $attributes->length;
             for ($i = 0; $i < $attributesCount; $i++) {
                 $attribute = $attributes->item($i);
                 if ($attribute && stripos($attribute->nodeName, 'itemType') !== false) {
                     $nodeValue = trim($attribute->nodeValue);
                     if ($this->getStruct($nodeValue)) {
                         $this->setStructInheritance($parentNode->getAttribute('name'), 'array of ' . $this->getStruct($nodeValue)->getName());
                     }
                 }
             }
         }
     }
 }
 /**
  * @param DOMNode $node DOMNode to be tokenized.
  * @param HTMLPurifier_Token[] $tokens   Array-list of already tokenized tokens.
  * @param bool $collect  Says whether or start and close are collected, set to
  *                    false at first recursion because it's the implicit DIV
  *                    tag you're dealing with.
  * @return bool if the token needs an endtoken
  * @todo data and tagName properties don't seem to exist in DOMNode?
  */
 protected function createStartNode($node, &$tokens, $collect)
 {
     // intercept non element nodes. WE MUST catch all of them,
     // but we're not getting the character reference nodes because
     // those should have been preprocessed
     if ($node->nodeType === XML_TEXT_NODE) {
         $tokens[] = $this->factory->createText($node->data);
         return false;
     } elseif ($node->nodeType === XML_CDATA_SECTION_NODE) {
         // undo libxml's special treatment of <script> and <style> tags
         $last = end($tokens);
         $data = $node->data;
         // (note $node->tagname is already normalized)
         if ($last instanceof HTMLPurifier_Token_Start && ($last->name == 'script' || $last->name == 'style')) {
             $new_data = trim($data);
             if (substr($new_data, 0, 4) === '<!--') {
                 $data = substr($new_data, 4);
                 if (substr($data, -3) === '-->') {
                     $data = substr($data, 0, -3);
                 } else {
                     // Highly suspicious! Not sure what to do...
                 }
             }
         }
         $tokens[] = $this->factory->createText($this->parseData($data));
         return false;
     } elseif ($node->nodeType === XML_COMMENT_NODE) {
         // this is code is only invoked for comments in script/style in versions
         // of libxml pre-2.6.28 (regular comments, of course, are still
         // handled regularly)
         $tokens[] = $this->factory->createComment($node->data);
         return false;
     } elseif ($node->nodeType !== XML_ELEMENT_NODE) {
         // not-well tested: there may be other nodes we have to grab
         return false;
     }
     $attr = $node->hasAttributes() ? $this->transformAttrToAssoc($node->attributes) : array();
     // We still have to make sure that the element actually IS empty
     if (!$node->childNodes->length) {
         if ($collect) {
             $tokens[] = $this->factory->createEmpty($node->tagName, $attr);
         }
         return false;
     } else {
         if ($collect) {
             $tokens[] = $this->factory->createStart($tag_name = $node->tagName, $attr);
         }
         return true;
     }
 }
Example #28
0
 protected function getNodeValue(DOMNode $node)
 {
     if ($node->hasAttributes()) {
         return Ezer_Config::createFromNode($node);
     }
     if ($node->childNodes->length > 1 || $node->firstChild->nodeType != Ezer_Config::TEXT_NODE_TYPE) {
         return Ezer_Config::createFromNode($node);
     }
     return $this->getTextValue($node);
 }
Example #29
0
 /**
  * Get attribute values.
  * @param DOMNode $node
  * @param string $attrName
  *
  * @return array
  */
 public static function getAttributeValues(DOMNode $node, $attrName)
 {
     if ($node->hasAttributes()) {
         foreach ($node->attributes as $attr) {
             if ($attr->name == $attrName) {
                 return preg_split('/\\s+/', trim($attr->value));
             }
         }
     }
     return array();
 }
Example #30
0
 /**
  * This helper function is used by `XMLElement::convertFromDOMDocument`
  * to recursively convert `DOMNode` into an `XMLElement` structure
  *
  * @since Symphony 2.4
  * @param XMLElement $root
  * @param DOMNOde $node
  * @return XMLElement
  */
 private static function convert(XMLElement $root = null, DOMNode $node)
 {
     $el = new XMLElement($node->tagName);
     if ($node->hasAttributes()) {
         foreach ($node->attributes as $name => $attrEl) {
             $el->setAttribute($name, General::sanitize($attrEl->value));
         }
     }
     if ($node->hasChildNodes()) {
         foreach ($node->childNodes as $childNode) {
             if ($childNode instanceof DOMText) {
                 if ($childNode->isWhitespaceInElementContent() === false) {
                     $el->setValue(General::sanitize($childNode->data));
                 }
             } elseif ($childNode instanceof DOMElement) {
                 self::convert($el, $childNode);
             }
         }
     }
     if (is_null($root)) {
         return $el;
     } else {
         $root->appendChild($el);
     }
 }