Example #1
0
	function insert_node(DOMDocument &$doc, DOMElement &$field_elem, SimpleXMLElement $details_xml)
	{
		$travel_res_submitted_fields = dom_import_simplexml($details_xml->travel_res_submitted_fields[0]);
		//$travel_res_submitted_fields = $doc->createElement("travel_res_submitted_fields");
		$dom_sxe = $doc->importNode($travel_res_submitted_fields, true);
		$field_elem->appendChild($dom_sxe);

		if ($details_xml->travel_product[0])
		{
			$travel_res_product = dom_import_simplexml($details_xml->travel_product[0]);
			//$travel_res_submitted_fields = $doc->createElement("travel_res_submitted_fields");
			$dom_sxe = $doc->importNode($travel_res_product, true);
			$field_elem->appendChild($dom_sxe);
		}
		
		if ($details_xml->travel_lookups[0])
		{
			$travel_res_product_lookups = dom_import_simplexml($details_xml->travel_lookups[0]);
			//$travel_res_submitted_fields = $doc->createElement("travel_res_submitted_fields");
			$dom_sxe_lkp = $doc->importNode($travel_res_product_lookups, true);
			$field_elem->appendChild($dom_sxe_lkp);
		}
		
		
	}
 /**
  * Appends the "sortable" js code to the bottom of ajax-Request for the category-products loaded after
  * changing sort order.
  *
  * @param Varien_Event_Observer $observer
  */
 public function addSortableScriptOnGrid(Varien_Event_Observer $observer)
 {
     $_block = $observer->getBlock();
     $_type = $_block->getType();
     if (Mage::helper('ffuenf_categoryproductsortbackend')->isExtensionActive() && $_type == 'adminhtml/catalog_category_tab_product') {
         $content = $observer->getTransport()->getHtml();
         $dom = new DOMDocument('1.0', 'utf-8');
         $doc = new DOMDocument('1.0', 'utf-8');
         $dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'));
         foreach ($dom->getElementsByTagName('select') as $element) {
             if ($element->getAttribute('name') == 'limit') {
                 $option = $dom->createElement('option');
                 $option->appendChild($dom->createTextNode('All'));
                 $option->setAttribute('value', 0);
                 $option = $element->appendChild($option);
             }
         }
         $additionalHtml = $this->appendScript($content);
         $additionalDoc = new DOMDocument();
         $additionalDoc->loadHTML($additionalHtml);
         $additionalDocScript = $additionalDoc->getElementsByTagName('script')->item(0);
         $body = $dom->getElementsByTagName('body')->item(0);
         foreach ($body->childNodes as $child) {
             $doc->appendChild($doc->importNode($child, true));
         }
         $doc->appendChild($doc->importNode($additionalDocScript, true));
         $content = $doc->saveHTML();
         $observer->getTransport()->setHtml($content);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function processHtml($html, \DOMNode $container = null, &$replacedCount = null)
 {
     $urlRegExpr = $this->getRegExpression();
     $linkRegexp = "/<a href=\"{$urlRegExpr}\">{$urlRegExpr}<\\/a>/i";
     $document = new \DOMDocument();
     if (!$container) {
         $container = $document;
     } else {
         $container = $document->importNode($container);
     }
     return preg_replace_callback($linkRegexp, function ($matches) use($document, $container) {
         $matches = array_map('html_entity_decode', $matches);
         while ($container->hasChildNodes()) {
             $container->removeChild($container->firstChild);
         }
         $embedNodes = $this->getEmbedNodes($matches);
         if (!is_array($embedNodes)) {
             $embedNodes = [$embedNodes];
         }
         foreach ($embedNodes as $embedNode) {
             $container->appendChild($document->importNode($embedNode, true));
         }
         return $document->saveHTML($container);
     }, $html, -1, $replacedCount);
 }
Example #4
0
 /**
  * Print an xml.
  *
  * @param DOMNodeList or DOMElement $m the object to be printed.
  *
  * @return void.
  */
 public static function debugXML($m)
 {
     $out = new DOMDocument();
     $root = $out->createElement('debugxml');
     switch (get_class($m)) {
         case "DOMNodeList":
             foreach ($m as $domElement) {
                 $dom_sxe = $out->importNode($domElement, true);
                 $root->appendChild($dom_sxe);
             }
             break;
         case "DOMElement":
             $dom_sxe = $out->importNode($m, true);
             $root->appendChild($dom_sxe);
             break;
         case "XMLDom":
             $dom_sxe = $out->importNode($m->firstChild, true);
             $root->appendChild($dom_sxe);
             break;
         default:
             throw new Exception("Object type " . get_class($m) . ' can not be converted to xml.', 1);
             break;
     }
     $out->appendChild($root);
     header("Content-type:text/xml");
     echo $out->saveXML();
 }
 public function build()
 {
     $this->doc = new \DOMDocument('1.0', 'UTF-8');
     if ($this->structure) {
         $this->doc->appendChild($this->doc->importNode(dom_import_simplexml($this->structure), true));
     }
 }
Example #6
0
 public static function static__escaped_fragment_($_escaped_fragment_)
 {
     \libxml_use_internal_errors(true);
     $html = new \DOMDocument();
     $html->loadHTML(static::default_page($_escaped_fragment_ ? $_escaped_fragment_ : true));
     if ($error = \libxml_get_last_error()) {
         //new \SYSTEM\LOG\ERROR('Parse Error: '.$error->message.' line:'.$error->line.' html: '.$html->saveHTML());
         \libxml_clear_errors();
     }
     $state = \SYSTEM\PAGE\State::get(static::get_apigroup(), $_escaped_fragment_ ? $_escaped_fragment_ : static::get_default_state(), false);
     foreach ($state as $row) {
         $frag = new \DOMDocument();
         parse_str(\parse_url($row['url'], PHP_URL_QUERY), $params);
         $class = static::get_class($params);
         if ($class) {
             $frag->loadHTML(\SYSTEM\API\api::run('\\SYSTEM\\API\\verify', $class, static::get_params($params), static::get_apigroup(), true, false));
             if ($error = \libxml_get_last_error()) {
                 //new \SYSTEM\LOG\ERROR('Parse Error: '.$error->message.' line:'.$error->line.' html: '.$frag->saveHTML());
                 \libxml_clear_errors();
             }
             $html->getElementById(substr($row['div'], 1))->appendChild($html->importNode($frag->documentElement, true));
             //Load subpage css
             foreach ($row['css'] as $css) {
                 $css_frag = new \DOMDocument();
                 $css_frag->loadHTML('<link href="' . $css . '" rel="stylesheet" type="text/css">');
                 $html->getElementsByTagName('head')[0]->appendChild($html->importNode($css_frag->documentElement, true));
             }
         }
     }
     echo $html->saveHTML();
     new \SYSTEM\LOG\COUNTER("API was called sucessfully.");
     die;
 }
Example #7
0
 /**
  * @param Sitemap_URL $object 
  */
 public function add(Sitemap_URL $object)
 {
     $url = $object->create();
     // Decorate the urlset
     $object->root($this->_root);
     // Append URL to root element
     $this->_root->appendChild($this->_xml->importNode($url, TRUE));
 }
Example #8
0
 /**
  * Constructor.
  *
  * @param \DOMNode $node The node associated with this field
  */
 public function __construct(\DOMNode $node)
 {
     $this->node = $node;
     $this->name = $node->getAttribute('name');
     $this->document = new \DOMDocument('1.0', 'UTF-8');
     $this->node = $this->document->importNode($this->node, true);
     $root = $this->document->appendChild($this->document->createElement('_root'));
     $root->appendChild($this->node);
     $this->xpath = new \DOMXPath($this->document);
     $this->initialize();
 }
 public function addRole($name)
 {
     $role = new \DOMDocument('1.0', 'UTF-8');
     $role->load(__DIR__ . '/../Resources/role_template/RoleConfig.xml');
     $roles = $role->getElementsByTagName('Role');
     $roleNode = $roles->item(0);
     $roleNode->setAttribute('name', $name);
     $roleNode = $this->dom->importNode($roleNode, true);
     $this->dom->documentElement->appendChild($roleNode);
     if ($this->dom->save($this->serviceConfigurationFile) === false) {
         throw new \RuntimeException(sprintf("Could not write ServiceConfiguration to '%s'", $this->serviceConfigurationFile));
     }
 }
Example #10
0
 /**
  * @param  \DiDom\Element|\DOMNode $element
  * @return \DiDom\Element
  * @throws \InvalidArgumentException
  */
 public function appendChild($element)
 {
     if ($element instanceof Element) {
         $element = $element->getElement();
     }
     if (!$element instanceof DOMNode) {
         throw new InvalidArgumentException(sprintf('Argument 1 passed to %s must be an instance of %s\\Element or %s, %s given', __METHOD__, __NAMESPACE__, 'DOMNode', is_object($element) ? get_class($element) : gettype($element)));
     }
     $cloned = $element->cloneNode(true);
     $temp = $this->document->importNode($cloned, true);
     $this->document->appendChild($temp);
     return $this;
 }
Example #11
0
 /**
  * Tests the value being passed and decide what sort of element to create.
  *
  * @param \DOMNode $node
  * @param mixed    $val
  *
  * @return bool
  */
 private function selectNodeType(\DOMNode $node, $val)
 {
     if (is_array($val)) {
         return $this->buildXml($node, $val);
     } elseif ($val instanceof \SimpleXMLElement) {
         $child = $this->dom->importNode(dom_import_simplexml($val), true);
         $node->appendChild($child);
     } elseif ($val instanceof \Traversable) {
         $this->buildXml($node, $val);
     } elseif (is_object($val)) {
         return $this->buildXml($node, $this->serializer->normalize($val, $this->format));
     } elseif (is_numeric($val)) {
         return $this->appendText($node, (string) $val);
     } elseif (is_string($val) && $this->needsCdataWrapping($val)) {
         return $this->appendCData($node, $val);
     } elseif (is_string($val)) {
         return $this->appendText($node, $val);
     } elseif (is_bool($val)) {
         return $this->appendText($node, (int) $val);
     } elseif ($val instanceof \DOMNode) {
         $child = $this->dom->importNode($val, true);
         $node->appendChild($child);
     }
     return true;
 }
Example #12
0
 function get_properties_change_history_records_xml()
 {
     $eids = array();
     $xml_string = "";
     $sql = "select eid from view_int_prop_to_e_p_to_e\nwhere type_id in (select type_id from type where type_name like '%_history') and prop_id = 40 and int_val = " . $this->eid;
     $result = mysql_query($sql) or die("Error in RecordHistory...3lkd0skdjskfklk" . mysql_error());
     while ($row = mysql_fetch_assoc($result)) {
         $eids[] = $row['eid'];
     }
     $doc = new DOMDocument('1.0', 'UTF-8');
     $doc->formatOutput = true;
     $recs = $doc->createElement('records');
     $recs = $doc->appendChild($recs);
     foreach ($eids as $eid) {
         $type_id = RecordsSys_EntityManagementSystems::get_type_id($eid);
         $rec = new Record($eid, $type_id);
         $rec->initialize();
         $xml_string = $rec->xml_string;
         $doc2 = new DOMDocument('1.0', 'UTF-8');
         $doc2->loadXML($xml_string);
         $node = $doc->importNode($doc2->firstChild, true);
         $recs->appendChild($node);
     }
     //	$rec->glu->prop_ids_num_extra[6] = 1;
     //	$rec->glu->set_prop_ids_num_extra_by_group_id(1);
     //$rec->glu->set_prop_ids_num_extra_by_group_id(1);
     //	$xslt_file = 		$_SERVER['DOCUMENT_ROOT']."/XSLTemplates/testrecs.xsl";
     $xml_string = $doc->saveXML();
     return $xml_string;
 }
 /**
  * Get the child objects
  * and render them as document fragment
  *
  * @param \DOMDocument $dom DOMDocument
  * @return \DOMDocumentFragment
  */
 public function getChildElements(\DOMDocument $dom)
 {
     $modelChildren = $this->model->getElements();
     $documentFragment = NULL;
     foreach ($modelChildren as $key => $modelChild) {
         $child = $this->createChildElementFromModel($modelChild);
         if ($child) {
             if ($child->noWrap() === TRUE) {
                 $childNode = $child->render();
             } else {
                 $childNode = $child->render('elementWrap');
                 if ($childNode) {
                     $childNode->setAttribute('class', $child->getElementWraps());
                 }
             }
             if ($childNode) {
                 $importedNode = $dom->importNode($childNode, TRUE);
                 if (!$documentFragment) {
                     $documentFragment = $dom->createDocumentFragment();
                 }
                 $documentFragment->appendChild($importedNode);
             }
         }
     }
     return $documentFragment;
 }
Example #14
0
 public static function innerHTML($node)
 {
     $document = new DOMDocument();
     $node = $document->importNode($node, true);
     $document->appendChild($node);
     return $document->saveHTML($node);
 }
Example #15
0
 /**
  * Erstellt aus der Liste der Events ein vollständiges XML Dokument. 
  * Die Ausgabe erfolgt wahlweise als XML-Zeichenkette oder als DOMDocument-Objekt.
  * 
  * @param Array $vEventArray Liste der vevent DOMElemente
  * @param String $format "XML"|"DOMElement"
  * @return String|DOMElement
  * @throws Exception
  */
 public static function getXCal($vEventArray, $format = "XML")
 {
     // Struktur
     $xmlDocument = new DOMDocument("1.0", "UTF-8");
     $root = $xmlDocument->appendChild($xmlDocument->createElement("icalendar"));
     $vCalendar = $root->appendChild($xmlDocument->createElement("vcalendar"));
     $vCalendar->appendChild($xmlDocument->createElement("prodid", "-//Mozilla.org/NONSGML Mozilla Calendar V 1.0 //EN"));
     $vCalendar->appendChild($xmlDocument->createElement("version", "2.0"));
     // Eventliste
     foreach ($vEventArray as $i => $vEvent) {
         if (get_class($vEvent) !== "DOMElement") {
             throw new Exception("Unknown type in vEventArray at position " . $i);
         }
         $vEvent = $xmlDocument->importNode($vEvent, true);
         $vCalendar->appendChild($vEvent);
     }
     // Rückgabe
     switch ($format) {
         case "XML":
             return $xmlDocument->saveXML();
             break;
         case "DOMElement":
             return $root;
             break;
         default:
             throw new Exception("Unknown output format");
             break;
     }
 }
 /**
  * Extract the response element from the SOAP response.
  *
  * @param string $soapResponse  The SOAP response.
  * @return string  The <saml1p:Response> element, as a string.
  */
 private static function extractResponse($soapResponse)
 {
     assert('is_string($soapResponse)');
     $doc = new DOMDocument();
     if (!$doc->loadXML($soapResponse)) {
         throw new SimpleSAML_Error_Exception('Error parsing SAML 1 artifact response.');
     }
     $soapEnvelope = $doc->firstChild;
     if (!SimpleSAML_Utilities::isDOMElementOfType($soapEnvelope, 'Envelope', 'http://schemas.xmlsoap.org/soap/envelope/')) {
         throw new SimpleSAML_Error_Exception('Expected artifact response to contain a <soap:Envelope> element.');
     }
     $soapBody = SimpleSAML_Utilities::getDOMChildren($soapEnvelope, 'Body', 'http://schemas.xmlsoap.org/soap/envelope/');
     if (count($soapBody) === 0) {
         throw new SimpleSAML_Error_Exception('Couldn\'t find <soap:Body> in <soap:Envelope>.');
     }
     $soapBody = $soapBody[0];
     $responseElement = SimpleSAML_Utilities::getDOMChildren($soapBody, 'Response', 'urn:oasis:names:tc:SAML:1.0:protocol');
     if (count($responseElement) === 0) {
         throw new SimpleSAML_Error_Exception('Couldn\'t find <saml1p:Response> in <soap:Body>.');
     }
     $responseElement = $responseElement[0];
     /*
      * Save the <saml1p:Response> element. Note that we need to import it
      * into a new document, in order to preserve namespace declarations.
      */
     $newDoc = new DOMDocument();
     $newDoc->appendChild($newDoc->importNode($responseElement, TRUE));
     $responseXML = $newDoc->saveXML();
     return $responseXML;
 }
Example #17
0
 /**
  * Recursive merging of the DOMElement into the original document
  *
  * Algorithm:
  * 1. Find the same node in original document
  * 2. Extend and override original document node attributes and scalar value if found
  * 3. Append new node if original document doesn't have the same node
  *
  * @param DOMElement $node
  * @param string $parentPath path to parent node
  */
 protected function _mergeNode(DOMElement $node, $parentPath)
 {
     $path = $this->_getNodePathByParent($node, $parentPath);
     $matchedNode = $this->_getMatchedNode($path);
     /* Update matched node attributes and value */
     if ($matchedNode) {
         foreach ($node->attributes as $attribute) {
             $matchedNode->setAttribute($attribute->name, $attribute->value);
         }
         /* Merge child nodes */
         if ($node->hasChildNodes()) {
             /* override node value */
             if ($node->childNodes->length == 1 && $node->childNodes->item(0) instanceof DOMText) {
                 $matchedNode->nodeValue = $node->childNodes->item(0)->nodeValue;
             } else {
                 /* recursive merge for all child nodes */
                 foreach ($node->childNodes as $childNode) {
                     if ($childNode instanceof DOMElement) {
                         $this->_mergeNode($childNode, $path);
                     }
                 }
             }
         }
     } else {
         /* Add node as is to the document under the same parent element */
         $parentMatchedNode = $this->_getMatchedNode($parentPath);
         $newNode = $this->_dom->importNode($node, true);
         $parentMatchedNode->appendChild($newNode);
     }
 }
Example #18
0
 public function toXML()
 {
     $xml = new \DOMDocument();
     $xml->loadXML("<region />");
     $xml->documentElement->setAttribute("name", $this->name);
     $xml->documentElement->setAttribute("region_key", $this->region_key);
     foreach ($this->subregions as $subregion) {
         $import = $xml->importNode($subregion->toXML()->documentElement, true);
         $xml->documentElement->appendChild($import);
     }
     foreach ($this->targets as $target) {
         $import = $xml->importNode($target->toXML()->documentElement, true);
         $xml->documentElement->appendChild($import);
     }
     return $xml;
 }
Example #19
0
 static function response($status, $status_message, $domdocument = null)
 {
     $dom = new DomDocument('1.0', 'UTF-8');
     $results = $dom->appendChild($dom->createElement('response'));
     $results->appendChild($dom->createElement('status', $status));
     $results->appendChild($dom->createElement('status_message', $status_message));
     if (is_null($domdocument)) {
         $domdocument = new DomDocument('1.0', 'UTF-8');
         $domdocument->appendChild($domdocument->createElement('data'));
     }
     if ($domdocument->documentElement->nodeName === 'data') {
         $newdom = $domdocument;
     } else {
         $newdom = new DOMDocument('1.0', 'UTF-8');
         $data = $newdom->appendChild($newdom->createElement('data'));
         foreach ($domdocument->documentElement->childNodes as $domElement) {
             $domNode = $newdom->importNode($domElement, true);
             $data->appendChild($domNode);
         }
     }
     $import = $dom->importNode($newdom->documentElement, TRUE);
     $results->appendChild($import);
     $dom->formatOutput = true;
     echo $dom->saveXML();
 }
 /**
  * Validate and extract product data from a single node. Returns an array of product data or null if errors occured.
  * @param DOMNode $domNode
  * @return array|null
  */
 public function getProductData($domNode)
 {
     $doc = new DOMDocument('1.', 'UTF-8');
     $node = $doc->importNode($domNode, true);
     $doc->appendChild($node);
     $xmlProductNode = simplexml_import_dom($node);
     $this->_errors = array();
     if (!property_exists($xmlProductNode, 'simple_data')) {
         $this->_errors[] = 'Missing <simple_data> node.';
         return null;
     }
     $productData = $this->_extractSimpleData($xmlProductNode, $this->_extractStoreCodes($xmlProductNode));
     if ($productData == null) {
         $this->_errors[] = 'Invalid simple data.';
         return null;
     }
     $productData = $this->_afterSimpleData($productData);
     if ($productData == null) {
         return null;
     }
     $complexAttributeData = $this->_extractComplexData($xmlProductNode);
     if ($complexAttributeData === null) {
         $this->_errors[] = 'Invalid complex data.';
         return null;
     }
     $complexAttributeData = $this->_afterComplexData($complexAttributeData, $productData['default']['sku']);
     if (!is_null($complexAttributeData) && !empty($complexAttributeData)) {
         $productData['default'] = array_merge($productData['default'], $complexAttributeData);
     }
     return $this->_formatData($productData);
 }
 /**
  * @param DOMElement $item
  * @param array $captionAssets
  * @param array $remoteCaptionFileUrls
  */
 public function setCaptionAsset($item, array $captionAssets)
 {
     if (is_array($captionAssets)) {
         foreach ($captionAssets as $captionAsset) {
             /* @var $additionalAsset asset */
             $assetType = $captionAsset->getType();
             switch ($assetType) {
                 case CaptionPlugin::getAssetTypeCoreValue(CaptionAssetType::CAPTION):
                     /* @var $captionPlugin CaptionPlugin */
                     $captionPlugin = KalturaPluginManager::getPluginInstance(CaptionPlugin::PLUGIN_NAME);
                     $dummyElement = new SimpleXMLElement('<dummy/>');
                     $captionPlugin->contributeCaptionAssets($captionAsset, $dummyElement);
                     $dummyDom = dom_import_simplexml($dummyElement);
                     $captionDom = $dummyDom->getElementsByTagName('subTitle');
                     $captionDom = $this->doc->importNode($captionDom->item(0), true);
                     $captionDom = $item->appendChild($captionDom);
                     break;
                 case AttachmentPlugin::getAssetTypeCoreValue(AttachmentAssetType::ATTACHMENT):
                     /* @var $attachmentPlugin AttachmentPlugin */
                     $attachmentPlugin = KalturaPluginManager::getPluginInstance(AttachmentPlugin::PLUGIN_NAME);
                     $dummyElement = new SimpleXMLElement('<dummy/>');
                     $attachmentPlugin->contributeAttachmentAssets($captionAsset, $dummyElement);
                     $dummyDom = dom_import_simplexml($dummyElement);
                     $attachmentDom = $dummyDom->getElementsByTagName('attachment');
                     $attachmentDom = $this->doc->importNode($attachmentDom->item(0), true);
                     $attachmentDom = $item->appendChild($attachmentDom);
                     break;
             }
         }
     }
 }
Example #22
0
function wp_nav_menu_extended($args = array())
{
    $_echo = array_key_exists('echo', $args) ? $args['echo'] : true;
    $args['echo'] = false;
    $menu = wp_nav_menu($args);
    // Load menu as xml
    $menu = simplexml_load_string($menu);
    // Find current menu item with xpath selector
    if (array_key_exists('xpath', $args)) {
        $xpath = $args['xpath'];
    } else {
        $xpath = '//li[contains(@class, "current-menu-item") or contains(@class, "current_page_item")]';
    }
    $current = $menu->xpath($xpath);
    // If current item exists
    if (!empty($current)) {
        $text_node = (string) $current[0]->children();
        // Remove link
        unset($current[0]->a);
        // Create required element with text from link
        $element_name = $args['replace_a_by'] ? $args['replace_a_by'] : 'span';
        $dom = dom_import_simplexml($current[0]);
        $n = $dom->insertBefore($dom->ownerDocument->createElement($element_name, $text_node), $dom->firstChild);
        $current[0] = simplexml_import_dom($n);
    }
    $xml_doc = new DOMDocument('1.0', 'utf-8');
    $menu_x = $xml_doc->importNode(dom_import_simplexml($menu), true);
    $xml_doc->appendChild($menu_x);
    $menu = $xml_doc->saveXML($xml_doc->documentElement);
    if ($_echo) {
        echo $menu;
    } else {
        return $menu;
    }
}
 public function onRenderProductListBefore(FilterResponseEvent $event)
 {
     $app = $this->app;
     $request = $event->getRequest();
     $response = $event->getResponse();
     $id = $request->query->get('category_id');
     // category_idがない場合、レンダリングを変更しない
     if (is_null($id)) {
         return;
     }
     $CategoryContent = $app['category_content.repository.category_content']->find($id);
     // 登録がない、もしくは空で登録されている場合、レンダリングを変更しない
     if (is_null($CategoryContent) || $CategoryContent->getContent() == '') {
         return;
     }
     // 書き換えhtmlの初期化
     $html = $response->getContent();
     libxml_use_internal_errors(true);
     $dom = new \DOMDocument();
     $dom->loadHTML('<?xml encoding="UTF-8">' . $html);
     $dom->encoding = "UTF-8";
     $dom->formatOutput = true;
     // 挿入対象を取得
     $navElement = $dom->getElementById('page_navi_top');
     if (!$navElement instanceof \DOMElement) {
         return;
     }
     $template = $dom->createDocumentFragment();
     $template->appendXML(htmlspecialchars($CategoryContent->getContent()));
     $node = $dom->importNode($template, true);
     $navElement->insertBefore($node);
     $newHtml = html_entity_decode($dom->saveHTML(), ENT_NOQUOTES, 'UTF-8');
     $response->setContent($newHtml);
     $event->setResponse($response);
 }
Example #24
0
 /**
  * returns the content of this item
  *
  * @return string content
  */
 public function getContent()
 {
     if ($this->items !== false && $this->valid()) {
         try {
             // load entry page
             $client = new Zend_Http_Client($this->getLink() . '?page=all');
             $response = $client->request();
             $content = $response->getBody();
             $content = utf8_decode($content);
             // parse content
             $dom = new Zend_Dom_Query($content);
             $text = $dom->query('.article');
             $innerHTML = '';
             // convert innerHTML from DOM to string
             // taken from http://us2.php.net/domelement (patrick smith)
             $children = $text->current()->childNodes;
             foreach ($children as $child) {
                 $tmp_doc = new DOMDocument();
                 $tmp_doc->appendChild($tmp_doc->importNode($child, true));
                 if (count($tmp_doc->getElementById('comments')) > 0) {
                     continue;
                 }
                 // convert to text
                 $innerHTML .= @$tmp_doc->saveHTML();
             }
             return $innerHTML;
         } catch (Exception $e) {
             // return default content
             return current($this->items)->get_content();
         }
     }
 }
Example #25
0
 /**
  * Convert a given content into and array of nodes
  *
  * @param string|array|DOMElement|DOMText|Iterator $content
  * @param boolean $includeTextNodes
  * @param integer $limit
  * @return array
  */
 protected function _getContentNodes($content, $includeTextNodes = TRUE, $limit = 0)
 {
     $result = array();
     if ($content instanceof DOMElement) {
         $result = array($content);
     } elseif ($includeTextNodes && $this->_isNode($content)) {
         $result = array($content);
     } elseif (is_string($content)) {
         $result = $this->_getContentFragment($content, $includeTextNodes, $limit);
     } elseif ($this->_isNodeList($content)) {
         foreach ($content as $element) {
             if ($element instanceof DOMElement || $includeTextNodes && $this->_isNode($element)) {
                 $result[] = $element;
                 if ($limit > 0 && count($result) >= $limit) {
                     break;
                 }
             }
         }
     } else {
         throw new InvalidArgumentException('Invalid content parameter');
     }
     if (empty($result)) {
         throw new UnexpectedValueException('No element found');
     } else {
         //if a node is not in the current document import it
         foreach ($result as $index => $node) {
             if ($node->ownerDocument !== $this->_document) {
                 $result[$index] = $this->_document->importNode($node, TRUE);
             }
         }
     }
     return $result;
 }
Example #26
0
 /**
  * Append some XML code to the document
  * @param string Some XML code
  */
 static function appendXML($XML)
 {
     $doc = new \DOMDocument('1.0', 'utf-8');
     $doc->loadXML($XML);
     $node = self::$domDocument->importNode($doc->firstChild, true);
     end(self::$parentNodes)->appendChild($node);
 }
 public function display($supress_output = false)
 {
     if (!array_key_exists('HTTP_HOST', $_SERVER)) {
         exit("No command line usage for this page");
     }
     if (!$this->get_exists('delay_index')) {
         I2CE::raiseError("Invalid tree data request:  'request' is missing");
         return false;
     }
     $delay_index = $this->get('delay_index');
     if (!array_key_exists('tree_data', $_SESSION) || !is_array($_SESSION['tree_data']) || !array_key_exists($delay_index, $_SESSION['tree_data'])) {
         return false;
     }
     $data = $_SESSION['tree_data'][$delay_index];
     unset($_SESSION['tree_data'][$delay_index]);
     if (!is_array($data)) {
         return false;
     }
     $template = new I2CE_Template();
     $template->loadRootText("<span id='root'>");
     $root = $template->getElementById('root');
     $doc = $template->getDoc();
     I2CE_Module_TreeSelect::createTreeData($template, $root, $data);
     $tdoc = new DOMDocument();
     $tdoc->appendChild($tdoc->importNode($root, true));
     echo $tdoc->saveHTML();
     die;
 }
Example #28
0
 /**
  *
  * @param array $formData
  * @param array $extraData Data which is not included in $formData but is needed for creating the xml or other things.
  * @return Api_Models_Concept
  */
 public function setConceptData(array $formData, array $extraData = array())
 {
     $this->stripConcept();
     $this->data = array_merge($this->data, $formData);
     // Fix for multiplying of notation
     if (isset($this->data['notation']) && is_array($this->data['notation'])) {
         $this->data['notation'] = array(array_shift($this->data['notation']));
     }
     $this->setSpecialExtraData($extraData);
     $document = $this->toRDF();
     $xpath = new DOMXPath($document);
     foreach ($this->getNamespaces() as $prefix => $uri) {
         $xpath->registerNamespace($prefix, $uri);
     }
     $this->_rdfDocument = new DOMDocument('1.0', 'utf-8');
     $this->_rdfDocument->formatOutput = true;
     $this->_rdfDocument->preserveWhiteSpace = false;
     $this->_rdfDocument->appendChild($this->_rdfDocument->createElementNS(OpenSKOS_Rdf_Parser::$namespaces['rdf'], 'rdf:Description'));
     $this->_rdfDocument->documentElement->setAttribute('rdf:about', $this->getRdfDescriptionAbout($extraData));
     $rdfType = $this->_rdfDocument->createElement('rdf:type');
     $rdfType->setAttribute('rdf:resource', $this->getClass());
     $this->_rdfDocument->documentElement->appendChild($rdfType);
     $nodes = $this->getXmlNodes($xpath);
     foreach ($nodes as $node) {
         $xmlNode = $this->_rdfDocument->importNode($node, true);
         $this->_rdfDocument->documentElement->appendChild($xmlNode);
     }
     $this->data['xml'] = $this->_rdfDocument->saveXML($this->_rdfDocument->documentElement);
     return $this;
 }
Example #29
0
 /**
  * @dataProvider dataValidateSchemaFiles
  * @param string $file
  */
 public function testValidateSchema($file)
 {
     $found = false;
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $dom->load($file);
     $dbalElements = $dom->getElementsByTagNameNS("http://symfony.com/schema/dic/doctrine", "config");
     if ($dbalElements->length) {
         $dbalDom = new \DOMDocument('1.0', 'UTF-8');
         $dbalNode = $dbalDom->importNode($dbalElements->item(0));
         $dbalDom->appendChild($dbalNode);
         $ret = $dbalDom->schemaValidate(__DIR__ . "/../../Resources/config/schema/doctrine-1.0.xsd");
         $this->assertTrue($ret, "DoctrineBundle Dependency Injection XMLSchema did not validate this XML instance.");
         $found = true;
     }
     $ormElements = $dom->getElementsByTagNameNS("http://symfony.com/schema/dic/doctrine", "config");
     if ($ormElements->length) {
         $ormDom = new \DOMDocument('1.0', 'UTF-8');
         $ormNode = $ormDom->importNode($ormElements->item(0));
         $ormDom->appendChild($ormNode);
         $ret = $ormDom->schemaValidate(__DIR__ . "/../../Resources/config/schema/doctrine-1.0.xsd");
         $this->assertTrue($ret, "DoctrineBundle Dependency Injection XMLSchema did not validate this XML instance.");
         $found = true;
     }
     $this->assertTrue($found, "Neither <doctrine:orm> nor <doctrine:dbal> elements found in given XML. Are namespaces configured correctly?");
 }
Example #30
0
 public function getDom($asIs = false)
 {
     if ($asIs) {
         return $this->_dom;
     }
     if ($this->_dom instanceof \DOMDocument) {
         return $this->_dom;
     } elseif ($this->_dom instanceof \DOMNodeList || $this->_dom instanceof \DOMElement) {
         if ($this->_tempDom === null) {
             $this->_tempDom = new \DOMDocument('1.0', 'UTF-8');
             $root = $this->_tempDom->createElement('root');
             $this->_tempDom->appendChild($root);
             if ($this->_dom instanceof \DOMNodeList) {
                 foreach ($this->_dom as $domElement) {
                     $domNode = $this->_tempDom->importNode($domElement, true);
                     $root->appendChild($domNode);
                 }
             } else {
                 $domNode = $this->_tempDom->importNode($this->_dom, true);
                 $root->appendChild($domNode);
             }
         }
         return $this->_tempDom;
     }
 }