Example #1
0
 /**
  * Add item index and level to class attribute
  *
  * @param  SimpleXMLElement $node The node to add the index and level to
  * @param  array            $args Callback arguments
  */
 public static function index(SimpleXMLElement $node, $args)
 {
     if ($node->getName() == 'ul') {
         // set up level
         $level = $args['level'] / 2 + 1;
         if ($level > 1) {
             $node->addAttribute('class', 'uk-nav uk-nav-navbar');
         } else {
             $node->addAttribute('class', 'uk-navbar-nav');
         }
     }
     if ($node->getName() == 'li') {
         $css = '';
         // parent
         if (isset($node->div)) {
             $css .= ' uk-parent';
             $node->addAttribute('data-uk-dropdown', '');
         }
         // add li css classes
         $node->attributes()->class = trim($node->attributes()->class . $css);
         // add a/span css classes
         $children = $node->children();
         if ($firstChild = $children[0]) {
             $firstChild->addAttribute('class', trim($firstChild->attributes()->class . $css));
         }
     }
     unset($node->attributes()->icon);
 }
 public function adapt(SimpleXMLElement $atomNode)
 {
     switch ($atomNode->getName()) {
         case AtomNS::ENTRY_ELEMENT:
             return new ActivityEntryExtension($atomNode);
             break;
             //			case ActivityNS::OBJECT_TYPE_ELEMENT:
             //				return new SimpleActivityExtension($atomNode, ActivityNS::OBJECT_TYPE_ELEMENT);
             //				break;
             //			case ActivityNS::OBJECT_ELEMENT:
             //				return new ActivityObjectExtension($atomNode, ActivityNS::OBJECT_ELEMENT);
             //				break;
         //			case ActivityNS::OBJECT_TYPE_ELEMENT:
         //				return new SimpleActivityExtension($atomNode, ActivityNS::OBJECT_TYPE_ELEMENT);
         //				break;
         //			case ActivityNS::OBJECT_ELEMENT:
         //				return new ActivityObjectExtension($atomNode, ActivityNS::OBJECT_ELEMENT);
         //				break;
         case AtomNS::AUTHOR_ELEMENT:
             return new ActivityObjectExtension($atomNode, AtomNS::AUTHOR_ELEMENT);
             break;
         default:
             throw new ExtensionFactoryException('No Adaptor Available for ' . $atomNode->getName() . ' element!');
     }
 }
 /**
  * Get ROPE data, run corresponding handler
  *
  * @param  string $request - incoming XML request
  * @return string
  * @throws Exception
  */
 public function processRopeRequest($request)
 {
     $this->_request = $request;
     try {
         $this->_request = new SimpleXMLElement(urldecode($request), LIBXML_NOCDATA);
         /**
          * Check type of request and call proper handler 
          */
         switch ($this->_request->getName()) {
             case 'tradoria_check_order':
                 $this->_orderNode = 'order';
                 $responseTag = 'tradoria_check_order_response';
                 $response = $this->_checkOrder();
                 break;
             case 'tradoria_order_process':
                 $this->_orderNode = 'cart';
                 $responseTag = 'tradoria_order_process_response';
                 $response = $this->_processOrder();
                 break;
             case 'tradoria_order_status':
                 $responseTag = 'tradoria_order_status_response';
                 $response = $this->_statusUpdate();
                 break;
             default:
                 /**
                  * Error - Unrecognized request 
                  */
                 $responseTag = 'unknown_error';
                 $response = false;
         }
     } catch (Exception $e) {
         return $this->prepareResponse(false);
     }
     return $this->prepareResponse($response, $responseTag);
 }
 /**
  * @param SimpleXMLElement $mrss
  * @param SimpleXMLElement $metadata
  * @param kMrssParameters $mrssParams
  * @return SimpleXMLElement
  */
 public function contributeMetadataObject(SimpleXMLElement $mrss, SimpleXMLElement $metadata, kMrssParameters $mrssParams = null, $currentXPath)
 {
     $currentXPath .= "/*[local-name()='" . $metadata->getName() . "']";
     $metadataObject = $mrss->addChild($metadata->getName());
     foreach ($metadata->attributes() as $attributeField => $attributeValue) {
         $metadataObject->addAttribute($attributeField, $attributeValue);
     }
     foreach ($metadata as $metadataField => $metadataValue) {
         if ($metadataValue instanceof SimpleXMLElement && count($metadataValue)) {
             $this->contributeMetadataObject($metadataObject, $metadataValue, $mrssParams, $currentXPath);
         } else {
             $metadataObject->addChild($metadataField, kString::stringToSafeXml($metadataValue));
             $itemXPath = $currentXPath . "/*[local-name()='{$metadataField}']";
             if ($mrssParams && is_array($mrssParams->getItemXpathsToExtend()) && in_array($itemXPath, $mrssParams->getItemXpathsToExtend())) {
                 $relatedEntry = entryPeer::retrieveByPK((string) $metadataValue);
                 if ($relatedEntry) {
                     $relatedItemField = $metadataObject->addChild($metadataField . '_item');
                     $recursionMrssParams = null;
                     if ($mrssParams) {
                         $recursionMrssParams = clone $mrssParams;
                         $recursionMrssParams->setItemXpathsToExtend(array());
                         // stop the recursion
                     }
                     $relatedEntryMrss = kMrssManager::getEntryMrssXml($relatedEntry, $relatedItemField, $recursionMrssParams);
                 }
             }
         }
     }
 }
Example #5
0
 /**
  * Unserialize SimpleXMLElement
  *
  * @param \SimpleXMLElement $element   Element to unserialize
  * @param string            $classHint Hint to which class unserialize
  *
  * @return mixed unserialized object
  */
 protected function unserializeXml(\SimpleXMLElement $element, $classHint = null)
 {
     if ($this->configValue("extractClassFrom", "tagName") == "tagName") {
         $elementClassHint = $element->getName();
     } else {
         $xsiAttrs = $element->attributes("http://www.w3.org/2001/XMLSchema-instance");
         if (!isset($xsiAttrs["type"])) {
             throw new \Exception("Element {$element->getName()} has no {http://www.w3.org/2001/XMLSchema-instance}type attribute");
         }
         $elementClassHint = $xsiAttrs["type"];
     }
     $mapperClass = $this->configValue("mapperClasses", []);
     if (isset($mapperClass[$elementClassHint])) {
         $className = $mapperClass[$elementClassHint];
     } else {
         $className = $classHint ? $classHint : rtrim($this->configValue("classesNamespace", ""), '\\') . '\\' . $elementClassHint;
     }
     if (!class_exists($className, true)) {
         throw new ClassNotFoundException("Class '{$className}' not found");
     }
     $classInstance = new $className();
     $this->checkNodes($element->attributes(), $className, $classInstance);
     $this->checkNodes($element->children(), $className, $classInstance);
     return $classInstance;
 }
 public function adapt($data, $data_is_url = false)
 {
     $domObj = new SimpleXMLElement($data, null, $data_is_url);
     $documentAdapter = $this->_adapterTable[$domObj->getName()];
     if (isset($documentAdapter)) {
         return new $documentAdapter($domObj);
     } else {
         throw new DocumentAdapterFactoryException("No document adapter available for " . $domObj->getName() . " document!!");
     }
 }
 public function adapt(SimpleXMLElement $atomNode)
 {
     switch ($atomNode->getName()) {
         case AtomNS::ENTRY_ELEMENT:
             return new ThreadingEntryExtension($atomNode);
             break;
         default:
             throw new ExtensionFactoryException('No Adaptor Available for ' . $atomNode->getName() . ' element!');
     }
 }
 /**
  * @param \SimpleXMLElement $xmlElement
  * @return \BolOpenApi\Response\ProductResponse
  * @throws \BolOpenApi\Exception
  */
 public function createProductResponse(\SimpleXMLElement $xmlElement)
 {
     if ($xmlElement->getName() != 'ProductResponse') {
         throw new Exception('Invalid XML element, expected ProductResponse but got "' . $xmlElement->getName() . '"');
     }
     $productResponse = new ProductResponse();
     $productResponse->setSessionId((string) $xmlElement->SessionId);
     $productResponse->setProduct($this->modelFactory->createProduct($xmlElement->Product));
     return $productResponse;
 }
Example #9
0
 private function doPrettyPrintXML(SimpleXMLElement $han, $prefix = "")
 {
     if (count($han->children()) < 1) {
         return $prefix . "&lt;" . $han->getName() . $this->doWarpAttributes($han->attributes()) . "&gt;" . $han . "&lt;/" . $han->getName() . "&gt;<br />";
     }
     $ret = $prefix . "&lt;" . $han->getName() . $this->doWarpAttributes($han->attributes()) . "&gt;<br />";
     foreach ($han->children() as $key => $child) {
         $ret .= $this->doPrettyPrintXML($child, $prefix . "    ");
     }
     $ret .= $prefix . "&lt;/" . $han->getName() . "&gt;<br />";
     return $ret;
 }
Example #10
0
function xml2array($xml)
{
    $xmla = array();
    $xml = new SimpleXMLElement($xml);
    if ($xml->getName()) {
        $xmla[$xml->getName()] = array();
        foreach ($xml->children() as $child) {
            $xmla[$xml->getName()][$child->getName()] = (string) $child;
        }
    }
    return $xmla;
}
 /**
  * Prepare installed categories array
  */
 private function prepareData(\SimpleXMLElement $level)
 {
     if (strstr($level->getName(), 'level_')) {
         $attributes = $level->attributes();
         $level_number = (int) str_replace('level_', '', $level->getName());
         if (isset($this->categories_levels[$level_number])) {
             foreach ($this->categories_levels[$level_number] as $key => $category) {
                 $this->categories_levels[$level_number][$key]['tpl'] = (string) $attributes->template_name ? (string) $attributes->template_name : '';
             }
             $this->categoriesData[] = $this->categories_levels[$level_number];
         }
     }
 }
Example #12
0
 /**
  * Add SimpleXMLElement code into a SimpleXMLElement
  * @param SimpleXMLElement $append
  */
 public function appendXMLElement(\SimpleXMLElement $append)
 {
     if (strlen(trim((string) $append)) == 0) {
         $xml = $this->addChild($append->getName());
         foreach ($append->children() as $child) {
             $xml->appendXMLElement($child);
         }
     } else {
         $xml = $this->addChild($append->getName(), (string) $append);
     }
     foreach ($append->attributes() as $n => $v) {
         $xml->addAttribute($n, $v);
     }
 }
Example #13
0
 /**
  * @param SimpleXMLElement $mrss
  * @param SimpleXMLElement $metadata
  * @param kMrssParameters $mrssParams
  * @return SimpleXMLElement
  */
 public function contributeMetadataObject(SimpleXMLElement $mrss, SimpleXMLElement $metadata, kMrssParameters $mrssParams = null, $currentXPath)
 {
     $currentXPath .= "/*[local-name()='" . $metadata->getName() . "']";
     $metadataObject = $mrss->addChild($metadata->getName());
     foreach ($metadata->attributes() as $attributeField => $attributeValue) {
         $metadataObject->addAttribute($attributeField, $attributeValue);
     }
     foreach ($metadata as $metadataField => $metadataValue) {
         if ($metadataValue instanceof SimpleXMLElement && count($metadataValue)) {
             $this->contributeMetadataObject($metadataObject, $metadataValue, $mrssParams, $currentXPath);
         } else {
             $metadataObject->addChild($metadataField, kString::stringToSafeXml($metadataValue));
         }
     }
 }
 public function recreate_img_tag($tag)
 {
     // Supress SimpleXML errors
     libxml_use_internal_errors(TRUE);
     try {
         $x = new SimpleXMLElement($tag);
         // We only want to rebuild img tags
         if ($x->getName() == 'img') {
             // Get the attributes I'll use in the new tag
             $alt = (string) $x->attributes()->alt;
             $src = (string) $x->attributes()->src;
             $classes = (string) $x->attributes()->class;
             $class_segs = explode(' ', $classes);
             // All images have a source
             $img = '<img src="' . $src . '"';
             // If alt not empty, add it
             if (!empty($alt)) {
                 $img .= ' alt="' . $alt . '"';
             }
             // Only alignment classes are allowed
             $allowed_classes = array('alignleft', 'alignright', 'alignnone', 'aligncenter');
             if (in_array($class_segs[0], $allowed_classes)) {
                 $img .= ' class="' . $class_segs[0] . '"';
             }
             // Finish up the img tag
             $img .= ' />';
             return $img;
         }
     } catch (Exception $e) {
     }
     // Tag not an img, so just return it untouched
     return $tag;
 }
Example #15
0
 function __construct(SimpleXMLElement $node, $namespaces = null)
 {
     $this->__name = $node->getName();
     $this->__value = $node;
     if ($namespaces === null) {
         $namespaces = $node->getNamespaces(true);
     }
     foreach ($namespaces as $ns => $uri) {
         foreach ($node->children($uri) as $child) {
             $childName = $ns ? "{$ns}:" . $child->getName() : $child->getName();
             if (array_key_exists($childName, $this->__children) && is_array($this->__children[$childName])) {
                 $this->__children[$childName][] = new clNode($child, $namespaces);
             } else {
                 if (array_key_exists($childName, $this->__children) && get_class($this->__children[$childName]) == "clNode") {
                     $childArray = array();
                     $childArray[] = $this->__children[$childName];
                     $childArray[] = new clNode($child, $namespaces);
                     $this->__children[$childName] = $childArray;
                 } else {
                     $this->__children[$childName] = new clNode($child, $namespaces);
                 }
             }
         }
         foreach ($node->attributes($ns) as $a) {
             $a = $a->asXML();
             @(list($name, $value) = split('=', $a));
             $this->__attributes[trim($name)] = substr($value, 1, strlen($value) - 2);
         }
     }
 }
 /**
  * Prepare installed banners array
  */
 private function prepareData(\SimpleXMLElement $banner)
 {
     if ($banner->getName() != 'groups') {
         $attributes = $banner->attributes();
         $this->bannerData = array('group' => (string) $attributes->group ? serialize(explode(',', trim((string) $attributes->group))) : '', 'active' => (string) $attributes->active ? (string) $attributes->active : 0, 'active_to' => (string) $attributes->active_to ? (string) $attributes->active_to : -1, 'where_show' => (string) $attributes->where_show ? serialize(array((string) $attributes->where_show . '_0')) : serialize(array('default')), 'position' => (string) $attributes->position ? (string) $attributes->position : 0);
         $this->ci->db->insert('mod_banner', $this->bannerData);
         if (isset($banner->banner_i18n) && $this->ci->db->insert_id()) {
             foreach ($banner->banner_i18n as $banner_i18n) {
                 $attributes = $banner_i18n->attributes();
                 $this->bannerI18nData[] = array('id' => $this->ci->db->insert_id(), 'name' => (string) $attributes->name ? (string) $attributes->name : 'Banner', 'description' => (string) $attributes->description ? (string) $attributes->description : '', 'url' => (string) $attributes->url ? (string) $attributes->url : '', 'locale' => (string) $attributes->locale ? (string) $attributes->locale : 'ru', 'photo' => (string) $attributes->photo ? (string) $attributes->photo : '');
             }
         } else {
             $this->messages[] = lang('Can not install banner.', 'template_manager');
             return FALSE;
         }
     } else {
         if (isset($banner->group)) {
             foreach ($banner->group as $group) {
                 $attributes = $group->attributes();
                 $this->bannerGroupsData = array('name' => (string) $attributes->name ? (string) $attributes->name : '');
                 if ($this->bannerGroupsData) {
                     if (!isset($this->existed_banners_groups[$this->bannerGroupsData['name']])) {
                         $this->ci->db->insert('mod_banner_groups', $this->bannerGroupsData);
                     }
                 }
             }
         }
     }
 }
 /**
  * @param $simpleXmlElementObject
  * @param $ignoreXmlAttributes
  * @param  int       $recursionDepth
  * @return array
  * @throws Exception
  */
 protected static function _processXml(\SimpleXMLElement $simpleXmlElementObject, $ignoreXmlAttributes, $recursionDepth = 0)
 {
     // Keep an eye on how deeply we are involved in recursion.
     if ($recursionDepth > static::$maxRecursionDepthAllowed) {
         // XML tree is too deep. Exit now by throwing an exception.
         throw new Exception("Function _processXml exceeded the allowed recursion depth of " . static::$maxRecursionDepthAllowed);
     }
     $children = $simpleXmlElementObject->children();
     $name = $simpleXmlElementObject->getName();
     $value = static::_getXmlValue($simpleXmlElementObject);
     $attributes = (array) $simpleXmlElementObject->attributes();
     if (in_array($name, array('content', 'summary', 'rights', 'title', 'subtitle'))) {
         if (!empty($attributes) && !$ignoreXmlAttributes) {
             foreach ($attributes['@attributes'] as $k => $v) {
                 $attributes['@attributes'][$k] = static::_getXmlValue($v);
             }
             // XHTML content is parsed as XML but we always want it as a single element. HTML and text
             // are only available as the text of the element.
             $attributes['@text'] = $value ? $value : $simpleXmlElementObject->children()->asXml();
             return array($name => $attributes);
         }
         return array($name => $value);
     }
     if (!count($children)) {
         if (!empty($attributes) && !$ignoreXmlAttributes) {
             foreach ($attributes['@attributes'] as $k => $v) {
                 $attributes['@attributes'][$k] = static::_getXmlValue($v);
             }
             if (!empty($value)) {
                 $attributes['@text'] = $value;
             }
             return array($name => $attributes);
         }
         return array($name => $value);
     }
     $childArray = array();
     foreach ($children as $child) {
         $childname = $child->getName();
         $element = static::_processXml($child, $ignoreXmlAttributes, $recursionDepth + 1);
         if (array_key_exists($childname, $childArray)) {
             if (empty($subChild[$childname])) {
                 $childArray[$childname] = array($childArray[$childname]);
                 $subChild[$childname] = true;
             }
             $childArray[$childname][] = $element[$childname];
         } else {
             $childArray[$childname] = $element[$childname];
         }
     }
     if (!empty($attributes) && !$ignoreXmlAttributes) {
         foreach ($attributes['@attributes'] as $k => $v) {
             $attributes['@attributes'][$k] = static::_getXmlValue($v);
         }
         $childArray['@attributes'] = $attributes['@attributes'];
     }
     if (!empty($value)) {
         $childArray['@text'] = $value;
     }
     return array($name => $childArray);
 }
 private function prepareMenuItems(\SimpleXMLElement $item, $menu_id)
 {
     if ($item->getName() == 'item') {
         $attributes = $item->attributes();
         $url = (string) $attributes->url ? (string) $attributes->url : '';
         $this->menuItemData = array('menu_id' => $menu_id, 'item_id' => 0, 'item_type' => 'url', 'item_image' => (string) $attributes->image ? (string) $attributes->image : '', 'roles' => NULL, 'hidden' => 0, 'title' => (string) $attributes->title ? (string) $attributes->title : '', 'parent_id' => $this->menuItemParentId, 'position' => $this->menuItemPosition, 'description' => (string) $attributes->description ? (string) $attributes->description : '', 'add_data' => serialize(array('url' => $url, 'newpage' => 0)));
         $this->ci->db->insert('menus_data', $this->menuItemData);
         $item_id = $this->ci->db->insert_id();
         if ($item_id) {
             $this->menuItemPosition++;
             foreach ($item as $entity) {
                 $attributes = $entity->attributes();
                 switch ($entity->getName()) {
                     case 'menu_i18n':
                         $locale = (string) $attributes->locale ? (string) $attributes->locale : '';
                         if ($this->localesIds[$locale]) {
                             $this->menuItemI18nData[] = array('title' => (string) $attributes->title ? (string) $attributes->title : '', 'lang_id' => $this->localesIds[$locale], 'item_id' => $item_id);
                         }
                         break;
                     case 'item':
                         $this->menuItemParentId = $item_id;
                         $this->prepareMenuItems($entity, $menu_id);
                         break;
                     default:
                         break;
                 }
             }
         }
     }
 }
Example #19
0
function AddXMLElement(SimpleXMLElement $dest, SimpleXMLElement $source)
{
    $new_dest = $dest->addChild($source->getName(), $source[0]);
    foreach ($source->children() as $child) {
        AddXMLElement($new_dest, $child);
    }
}
Example #20
0
 public function getUsersFromXml(SimpleXMLElement $document, &$errors = array())
 {
     if ($document->getName() != 'users_export') {
         throw new XenForo_Exception(new XenForo_Phrase('th_provided_file_is_not_valid_users_xml_userimpex'), true);
     }
     $users = array();
     $i = 0;
     foreach ($document->users->user as $user) {
         $options = array();
         if ($user->options) {
             $options = array('show_dob_year' => (int) $user->options['show_dob_year'], 'show_dob_date' => (int) $user->options['show_dob_date'], 'content_show_signature' => (int) $user->options['content_show_signature'], 'receive_admin_email' => (int) $user->options['receive_admin_email'], 'email_on_conversation' => (int) $user->options['email_on_conversation'], 'is_discouraged' => (int) $user->options['is_discouraged'], 'default_watch_state' => (string) $user->options['default_watch_state'], 'alert_optout' => (string) $user->options['alert_optout'], 'enable_rte' => (int) $user->options['enable_rte'], 'enable_flash_uploader' => (int) $user->options['enable_flash_uploader']);
         }
         $privacy = array();
         if ($user->privacy) {
             $privacy = array('allow_view_profile' => (int) $user->privacy['allow_view_profile'], 'allow_post_profile' => (int) $user->privacy['allow_post_profile'], 'allow_send_personal_conversation' => (int) $user->privacy['allow_send_personal_conversation'], 'allow_view_identities' => (int) $user->privacy['allow_view_identities'], 'allow_receive_news_feed' => (int) $user->privacy['allow_receive_news_feed']);
         }
         $profile = array();
         $customFields = array();
         if ($user->profile) {
             $profile = array('dob_day' => (int) $user->profile['dob_day'], 'dob_month' => (int) $user->profile['dob_month'], 'dob_year' => (int) $user->profile['dob_year'], 'signature' => (string) $user->profile['signature'], 'homepage' => (string) $user->profile['homepage'], 'location' => (string) $user->profile['location'], 'occupation' => (string) $user->profile['occupation'], 'about' => (string) $user->profile['about']);
             foreach ($user->profile->custom_fields->custom_field as $customField) {
                 $customFields[(string) $customField['field_id']] = (string) $customField['field_value'];
             }
         }
         $users[$i] = array_merge(array('username' => (string) $user['username'], 'email' => (string) $user['email'], 'gender' => (string) $user['gender'], 'custom_title' => (string) $user['custom_title'], 'timezone' => (string) $user['timezone'], 'custom_fields' => $customFields), $options, $privacy, $profile);
         $i++;
     }
     return $users;
 }
Example #21
0
 /**
  * @param  string $path  XML file path
  * @throws RuntimeException  If XML file contain errors
  */
 public function __construct($path)
 {
     libxml_use_internal_errors(TRUE);
     $this->element = simplexml_load_file((string) $path, $this->elementClassName);
     if (!$this->element) {
         $errors = array();
         foreach (libxml_get_errors() as $error) {
             $errors[] = trim($error->message);
         }
         throw new RuntimeException(implode('; ', $errors));
     }
     $docRoot = $this->getDocumentRoot();
     if ($docRoot !== $this->element->getName()) {
         throw new RuntimeException('Invalid document root, "' . $this->element->getName() . '" found instead of "' . $docRoot . '"');
     }
 }
 /**
  * Read STACK questions from a string and process it to a list of question arrays
  * @param string $xmlstr STACK questions as an XML string
  * @return array containing question arrays
  */
 protected function questionstoformfrom($xmlstr)
 {
     // Slight hack, since SimpleXMLElement does not like these names...
     $xmlstr = str_replace('<dc:', '<dc', $xmlstr);
     $xmlstr = str_replace('</dc:', '</dc', $xmlstr);
     $root = new SimpleXMLElement($xmlstr);
     $result = array();
     $errors = array();
     if ($root->getName() == 'assessmentItem') {
         list($question, $err) = $this->questiontoformfrom($root);
         $result[] = $question;
         $errors = array_merge($errors, $err);
     } else {
         if ($root->getName() == 'mathQuiz') {
             foreach ($root->assessmentItem as $assessmentitem) {
                 list($question, $err) = $this->questiontoformfrom($assessmentitem);
                 $result[] = $question;
                 $errors = array_merge($errors, $err);
             }
         }
     }
     if (!empty($errors)) {
         throw new stack_exception(implode('<br />', $errors));
     }
     return $result;
 }
Example #23
0
File: Xml.php Project: rexmac/zf2
 /**
  * Add a branch to an XML object recursively
  *
  * @param  \Zend\Config\Config      $config
  * @param  SimpleXMLElement $xml
  * @param  SimpleXMLElement $parent
  * @return void
  */
 protected function _addBranch(Config\Config $config, \SimpleXMLElement $xml, \SimpleXMLElement $parent)
 {
     $branchType = null;
     foreach ($config as $key => $value) {
         if ($branchType === null) {
             if (is_numeric($key)) {
                 $branchType = 'numeric';
                 $branchName = $xml->getName();
                 $xml = $parent;
                 unset($parent->{$branchName});
             } else {
                 $branchType = 'string';
             }
         } else {
             if ($branchType !== (is_numeric($key) ? 'numeric' : 'string')) {
                 throw new Config\Exception\RuntimeException('Mixing of string and numeric keys is not allowed');
             }
         }
         if ($branchType === 'numeric') {
             if ($value instanceof Config\Config) {
                 $child = $parent->addChild($branchName);
                 $this->_addBranch($value, $child, $parent);
             } else {
                 $parent->addChild($branchName, (string) $value);
             }
         } else {
             if ($value instanceof Config\Config) {
                 $child = $xml->addChild($key);
                 $this->_addBranch($value, $child, $xml);
             } else {
                 $xml->addChild($key, (string) $value);
             }
         }
     }
 }
Example #24
0
 /**
 	Sets the widget and complete data passed to the weeForm object.
 	Usually either $_POST or $_GET.
 
 	@param	$oWidget				The widget to validate.
 	@param	$aData					The data to check, if applicable.
 	@throw	IllegalStateException	The validator has already been attached to a form widget.
 */
 public function setFormData(SimpleXMLElement $oWidget, array $aData)
 {
     $this->oWidget === null or burn('IllegalStateException', _WT('The validator has already been attached to a form widget.'));
     $oWidget->getName() === 'widget' or burn('InvalidArgumentException', _WT('The $oWidget argument must be a widget element.'));
     $this->aData = $aData;
     $this->oWidget = $oWidget;
 }
Example #25
0
 /**
  * Get fields from form file
  *
  * @param	SimpleXMLElement	$form	Form file
  *
  * @return	mixed	Fields array on success, false otherwise
  */
 public function getFields(SimpleXMLElement $form, $table = 0)
 {
     JDeveloperLoader::importHelper("field");
     // Check if xml file contains form information
     if ($form->getName() != "form") {
         return false;
     }
     // Get fields
     $fields = array();
     foreach ($form->fieldset->children() as $_field) {
         $field = array();
         $field["id"] = 0;
         $field["name"] = (string) $_field["name"];
         $field["type"] = (string) $_field["type"];
         $field["table"] = $table;
         $field["label"] = (string) ucfirst($_field["name"]);
         $field["dbtype"] = JDeveloperHelperField::getDbType((string) $_field["type"]);
         $field["rule"] = isset($_field["validate"]) ? (string) $_field["validate"] : "";
         $field["maxlength"] = isset($_field["size"]) ? (string) $_field["size"] : "10";
         $field["params"] = array();
         $field["params"]["class"] = isset($_field["class"]) ? (string) $_field["class"] : "inputbox";
         $field["params"]["default"] = isset($_field["default"]) ? (string) $_field["default"] : "";
         $field["params"]["filter"] = isset($_field["filter"]) ? (string) $_field["filter"] : "";
         $field["params"]["readonly"] = isset($_field["readonly"]) ? "1" : "0";
         $field["params"]["frontend_list"] = "1";
         $field["params"]["frontend_item"] = "1";
         $field["params"]["listfilter"] = "0";
         $field["params"]["searchable"] = "0";
         $field["params"]["sortable"] = "0";
         $fields[] = $field;
     }
     return $fields;
 }
Example #26
0
 protected function arrayToXML($data_array, \SimpleXMLElement $XML)
 {
     $consecutive_counter = 0;
     foreach ($data_array as $key => $value) {
         if (is_array($value)) {
             if (!is_numeric($key)) {
                 $subnode = $XML->addChild($key);
                 $this->arrayToXML($value, $subnode);
             } else {
                 $subnode = $XML->addChild($XML->getName() . '_' . $this->array_item_name);
                 if ($key != $consecutive_counter) {
                     $subnode->addAttribute($this->array_item_attribute, $key);
                 }
                 $this->arrayToXML($value, $subnode);
             }
         } else {
             if (!is_numeric($key)) {
                 $XML->addAttribute($key, $value);
             } else {
                 $subnode = $XML->addChild($this->array_item_name, str_replace('&', '&amp;', $value));
                 if ($key != $consecutive_counter) {
                     $subnode->addAttribute($this->array_item_attribute, $key);
                 }
             }
         }
         if (is_numeric($key)) {
             $consecutive_counter++;
         }
     }
 }
 public function adapt(SimpleXMLElement $atomNode)
 {
     switch ($atomNode->getName()) {
         case AtomNS::ENTRY_ELEMENT:
             return new MediaEntryExtension($atomNode, AtomNS::ENTRY_ELEMENT);
             break;
         case ActivityNS::OBJECT_ELEMENT:
             return new MediaEntryExtension($atomNode, ActivityNS::OBJECT_ELEMENT);
             break;
         case AtomNS::LINK_ELEMENT:
             return new MediaLinkExtension($atomNode);
             break;
         default:
             throw new ExtensionFactoryException('No Adaptor Available for ' . $atomNode->getName() . ' element!');
     }
 }
Example #28
0
 /**
  * Class constructor.  Parse the XML response from a Nirvanix method
  * call into a decorated SimpleXMLElement element.
  *
  * @param string $xml  XML response string from Nirvanix
  * @throws Zend_Service_Nirvanix_Exception
  */
 public function __construct($xml)
 {
     $this->_sxml = @simplexml_load_string($xml);
     if (!$this->_sxml instanceof SimpleXMLElement) {
         $this->_throwException("XML could not be parsed from response: {$xml}");
     }
     $name = $this->_sxml->getName();
     if ($name != 'Response') {
         $this->_throwException("Expected XML element Response, got {$name}");
     }
     $code = (int) $this->_sxml->ResponseCode;
     if ($code != 0) {
         $msg = (string) $this->_sxml->ErrorMessage;
         $this->_throwException($msg, $code);
     }
 }
 public function testResponseBuilder()
 {
     $data = $this->getFixtureData();
     $xml = new \SimpleXMLElement($this->getHelper()->buildResponse(YandexKassaHelper::STATUS_PAYMENT_REJECTED, 'foo', 'bar'));
     $this->assertEquals('checkOrderResponse', $xml->getName());
     $date = \DateTime::createFromFormat(YandexKassaHelper::DATETIME_FORMAT, $xml['performedDatetime']);
     $this->assertInstanceOf('\\DateTime', $date);
     $this->assertEquals(YandexKassaHelper::STATUS_PAYMENT_REJECTED, (string) $xml['code']);
     $this->assertEquals($data['invoiceId'], (string) $xml['invoiceId']);
     $this->assertEquals($data['shopId'], (string) $xml['shopId']);
     $this->assertEquals('foo', (string) $xml['message']);
     $this->assertEquals('bar', (string) $xml['techMessage']);
     $xml = new \SimpleXMLElement($this->getHelper()->buildResponse());
     $this->assertEquals(YandexKassaHelper::STATUS_SUCCESS, (string) $xml['code']);
     $helper = $this->getHelper();
     try {
         $helper->parseRequest(array('md5' => 'foobar', 'action' => YandexKassaHelper::ACTION_CHECK) + $this->getFixtureData());
     } catch (AuthorizationErrorException $e) {
     }
     $xml = new \SimpleXMLElement($helper->buildResponse());
     $this->assertEquals(YandexKassaHelper::STATUS_AUTHORIZATION_ERROR, (string) $xml['code']);
     $helper = $this->getHelper();
     try {
         $helper->parseRequest(array('invoiceId' => '100500'));
     } catch (BadRequestException $e) {
     }
     $xml = new \SimpleXMLElement($helper->buildResponse());
     $this->assertEquals(YandexKassaHelper::STATUS_BAD_REQUEST, (string) $xml['code']);
     $this->assertEquals('100500', (string) $xml['invoiceId']);
 }
	public static function get_cdata(SimpleXMLElement $e)
	{
		if (
			!preg_match(
				"/<{$e->getName()}[^>]*>(.*)<\/{$e->getName()}>/ism", 
				$e->asXML(), 
				$sub)
			||
			empty($sub[1])
		) {
			throw new Exception('Undefined error in '. __CLASS__);
		} else {
			$sub[1] = 
				preg_replace('/<\!\[CDATA\[(.*)\]\]>/sm', "$1", $sub[1]);
			return self::blameString($sub[1]);
		}
	}