/**
  * testOwnerAssignment method
  *
  * @access public
  * @return void
  */
 function testOwnerAssignment()
 {
     $xml = new Xml();
     $node =& $xml->createElement('hello', 'world');
     $owner =& $node->document();
     $this->assertTrue($xml === $owner);
     $children =& $node->children;
     $childOwner =& $children[0]->document();
     $this->assertTrue($xml === $childOwner);
 }
Esempio n. 2
0
 static function importXml($elem, $model)
 {
     $n = null;
     if ($elem->nodeType == Xml::$Element) {
         $n = Xml::createElement($elem->getNodeName());
         $keys = $elem->attributes();
         while ($keys->hasNext()) {
             $key = $keys->next();
             $n->set($key, $elem->get($key));
             unset($key);
         }
         $children = $elem->iterator();
         while ($children->hasNext()) {
             $n->addChild(com_wiris_util_xml_WXmlUtils::importXml($children->next(), $model));
         }
     } else {
         if ($elem->nodeType == Xml::$Document) {
             $n = com_wiris_util_xml_WXmlUtils::importXml($elem->firstElement(), $model);
         } else {
             if ($elem->nodeType == Xml::$CData) {
                 $n = Xml::createCData($elem->getNodeValue());
             } else {
                 if ($elem->nodeType == Xml::$PCData) {
                     $n = Xml::createPCData($elem->getNodeValue());
                 } else {
                     throw new HException("Unsupported node type: " . Std::string($elem->nodeType));
                 }
             }
         }
     }
     return $n;
 }
Esempio n. 3
0
 private function _makeContent($fileName)
 {
     $this->out(sprintf(__('Creating package request for: %s', true), basename($fileName)));
     $name = $this->_removeExtension($fileName);
     $doc = new Xml(null, array(), $this->adeptNs);
     $packageElement = $doc->createElement('package', null, null);
     $packageElement->addNamespace("", $this->adeptNs);
     $xmlSourceDoc = $this->_useXmlSource($fileName);
     if ($this->useXmlSource && $xmlSourceDoc == null) {
         $this->out(__('An Error occured with the XML Source', true));
         $this->errors++;
         $this->failedFiles .= basename($fileName) . "\n";
         return null;
     }
     if ($this->hasResource) {
         $packageElement->createElement('resource', $xmlSourceDoc->children[0]->child('resource')->children[0]->value, null);
     }
     if ($this->hasVoucher) {
         $packageElement->createElement('voucher', $xmlSourceDoc->children[0]->child('voucher')->children[0]->value, null);
     }
     if ($this->hasResourceItem) {
         $packageElement->createElement('resourceItem', $xmlSourceDoc->children[0]->child('resourceItem')->children[0]->value, null);
     }
     if ($this->hasLocation) {
         $packageElement->createElement('location', $xmlSourceDoc->children[0]->child('locaton')->children[0]->value, null);
     }
     if ($this->hasSrc) {
         $packageElement->createElement('src', $xmlSourceDoc->children[0]->child('src')->children[0]->value, null);
     }
     if ($this->hasMetadata || $this->hasDefaultMetadata) {
         $metadataElement = $packageElement->createElement('metadata', null, null);
         $metadataElement->addNamespace($this->dublinCorePrefix, $this->dublinCoreNs);
         if (!$this->title == "") {
             $metadataElement->createElement('dc:title', $this->title, null);
         } elseif ($this->title == "" && !$this->titleDefault == "") {
             $metadataaElement->createElement('dc:title', $this->titleDefault, null);
         }
         if (!$this->description == "") {
             $metadataElement->createElement('dc:description', $this->description, null);
         } elseif ($this->description == "" && !$this->descriptionDefault == "") {
             $metadataaElement->createElement('dc:description', $this->descriptionDefault, null);
         }
         if (!$this->language == "") {
             $metadataElement->createElement('dc:language', $this->language, null);
         } elseif ($this->language == "" && !$this->languageDefault == "") {
             $metadataaElement->createElement('dc:language', $this->languageDefault, null);
         }
         if (!$this->creator == "") {
             $metadataElement->createElement('dc:creator', $this->creator, null);
         } elseif ($this->creator == "" && !$this->creatorDefault == "") {
             $metadataaElement->createElement('dc:creator', $this->creatorDefault, null);
         }
         if (!$this->publisher == "") {
             $metadataElement->createElement('dc:publisher', $this->publisher, null);
         } elseif ($this->publisher == "" && !$this->publisherDefault == "") {
             $metadataaElement->createElement('dc:publisher', $this->publisherDefault, null);
         }
         if (!$this->format == "") {
             $metadataElement->createElement('dc:format', $this->format, null);
         } elseif ($this->format == "" && !$this->formatDefault == "") {
             $metadataaElement->createElement('dc:format', $this->formatDefault, null);
         }
     }
     if ($this->hasPermissions) {
         $packageElement->append($xmlSourceDoc->children[0]->child('permissions'));
     }
     if ($this->hasDataPath && $this->useDataPath) {
         $packageElement->createElement('dataPath', $xmlSourceDoc->children[0]->child('dataPath')->children[0]->value);
     } else {
         $file = '';
         if ($this->hasFileName) {
             if (is_file($xmlSourceDoc->children[0]->child('fileName')->children[0]->value)) {
                 $file = new File($xmlSourceDoc->children[0]->child('fileName')->children[0]->value);
             } elseif (is_file(dirname($fileName) . "/" . basename($xmlSourceDoc->children[0]->child('fileName')->children[0]->value))) {
                 $file = new File(dirname($fileName) . "/" . basename($xmlSourceDoc->children[0]->child('fileName')->children[0]->value));
             }
         }
         if (is_object($file)) {
             $packageElement->createElement('fileName', $file->name, null);
             $packageElement->createElement('data', base64_encode($file->read()));
         }
     }
     if ($this->hasThumbnailLocation) {
         $packageElement->createElement('thumbnailLocation', $xmlSourceDoc->children[0]->child('thumbnailLocation')->children[0]->value);
     }
     if ($this->thumbPNG || $this->thumbJPEG || $this->thumbJPG || $this->thumbGIF) {
         $thumbnailName = $this->_getThumbnail($fileName);
         if ($thumbnailName != null) {
             $file = new File(dirname($fileName) . "/" . $thumbnailName);
             if ($file) {
                 if ($this->verbose) {
                     $this->out(sprintf(__('Found thumbnail file', true), $thumbnailName));
                 }
                 $packageElement->createElement('thumbnailData', base64_encode($file->read()));
             }
         } else {
             $this->out(__('Cannot find thumbnail file', true));
         }
     } elseif ($xmlSourceDoc->children[0]->child('thumbnailName') != null) {
         $file = '';
         if (is_file($xmlSourceDoc->children[0]->child('thumbnailName')->children[0]->value)) {
             $file = new File($xmlSourceDoc->children[0]->child('thumbnailName')->children[0]->value);
         } elseif (is_file(dirname($fileName) . "/" . basename($xmlSourceDoc->children[0]->child('thumbnailName')->children[0]->value))) {
             $file = new File(dirname($fileName) . "/" . basename($xmlSourceDoc->children[0]->child('thumbnailName')->children[0]->value));
         }
         if (is_object($file)) {
             $packageElement->createElement('thumbnailData', base64_encode($file->read()));
         }
     }
     $packageElement->createElement('expiration', date("c", mktime() + 36000));
     $packageElement->createElement('nonce', base64_encode(mt_rand(20000000, 30000000000)));
     $hmacElement = $packageElement->createElement('hmac');
     $hmacElement->createTextNode(base64_encode($this->_createHmac($this->password, $packageElement)));
     $requestContent = $packageElement->toString(array('cdata' => false));
     if ($this->verbose) {
         $this->out(__("Package Request:", true));
         $this->out($requestContent);
     }
     return $requestContent;
 }
 static function __start_element_handler($parser, $name, $attribs)
 {
     $node = Xml::createElement($name);
     while (list($k, $v) = each($attribs)) {
         $node->set($k, $v);
     }
     Xml::$build->addChild($node);
     Xml::$build = $node;
 }
Esempio n. 5
0
 /**
  * Builds the complete xml document.
  * @return string
  * @access private
  */
 protected function buildXML()
 {
     $hp = new Xml('1.0', 'utf-8');
     $hp->formatOutput = true;
     // begin hp items
     $hpitems = $hp->createElement('hotPadsItems');
     $hpitems->setAttribute("version", '2.1');
     $comm = $hp->createComment('Generated at ' . gmdate(DATE_RFC822));
     $hpitems->appendChild($comm);
     if (is_array($this->properties)) {
         foreach ($this->properties as $prop) {
             $noerrors = $this->validate($prop);
             if ($noerrors === true) {
                 // Build listing
                 $listing = $hp->createElement('Listing');
                 // Listing attributes
                 $listing->setAttribute("id", $prop->id);
                 $listing->setAttribute("type", $prop->type);
                 $listing->setAttribute("propertyType", $prop->property_type);
                 // Property details
                 $listing->appendChild($this->hpTextNode('name', false, $hp, $prop));
                 $listing->appendChild($this->hpTextNode('unit', false, $hp, $prop));
                 $listing->appendChild($this->hpTextNode('street', false, $hp, $prop));
                 $listing->appendChild($this->hpTextNode('city', false, $hp, $prop));
                 $listing->appendChild($this->hpTextNode('state', false, $hp, $prop));
                 $listing->appendChild($this->hpTextNode('zip', false, $hp, $prop));
                 $listing->appendChild($this->hpTextNode('country', false, $hp, $prop));
                 // Contact details
                 $listing->appendChild($this->hpTextNode('contactName', 'contact_name', $hp, $prop));
                 $listing->appendChild($this->hpTextNode('contactEmail', 'contact_email', $hp, $prop));
                 $listing->appendChild($this->hpTextNode('contactPhone', 'contact_phone', $hp, $prop));
                 $listing->appendChild($this->hpTextNode('contactFax', 'contact_fax', $hp, $prop));
                 // Descriptions and urls
                 $listing->appendChild($this->hpTextNode('previewMessage', 'preview_message', $hp, $prop));
                 $listing->appendChild($this->hpTextNode('description', false, $hp, $prop));
                 $listing->appendChild($this->hpTextNode('terms', false, $hp, $prop));
                 $listing->appendChild($this->hpTextNode('website', 'website_url', $hp, $prop));
                 $listing->appendChild($this->hpTextNode('virtualTourUrl', 'vr_url', $hp, $prop));
                 // Photos
                 if ($prop->photos) {
                     foreach ($prop->photos as $img) {
                         $photo = $hp->createElement('ListingPhoto');
                         $photo->setAttribute("source", $img['source']);
                         $listing->appendChild($photo);
                     }
                 }
                 // Additional data
                 $listing->appendChild($this->hpTextNode('price', false, $hp, $prop));
                 $listing->appendChild($this->hpTextNode('pricingFrequency', 'price_freq', $hp, $prop));
                 $listing->appendChild($this->hpTextNode('HOA-Fee', 'hoa_maint', $hp, $prop));
                 $listing->appendChild($this->hpTextNode('numBedrooms', 'bedrooms', $hp, $prop));
                 $listing->appendChild($this->hpTextNode('numFullBaths', 'full_bath', $hp, $prop));
                 $listing->appendChild($this->hpTextNode('numHalfBaths', 'half_bath', $hp, $prop));
                 $listing->appendChild($this->hpTextNode('squareFeet', 'sqft', $hp, $prop));
                 $hpitems->appendChild($listing);
             }
         }
         $hp->appendChild($hpitems);
         return $hp->saveXML();
     }
 }