/**
  * @return array
  */
 public function read()
 {
     $products = [];
     while ($this->xml->read()) {
         if ($this->isProductNode()) {
             $node = $this->xml->expand();
             $products[] = $this->createProduct($node);
         }
     }
     return $products;
 }
Exemple #2
0
 /**
  * @inheritdoc
  */
 public function current()
 {
     if (!isset($this->xmlReader)) {
         throw new \RuntimeException('The resource needs to be open.');
     }
     if (!$this->xmlReader->name) {
         return false;
     }
     /** @var \DOMElement $data */
     $data = $this->xmlReader->expand();
     $data = $this->xmlKit->convertDomElementToArray($data);
     return array('value' => $data);
 }
Exemple #3
0
 /**
  * Processes given xml file by iterating over product nodes and extracting data into array
  * @param string $filePath
  * @return boolean
  */
 public function processFile($filePath)
 {
     $messageHandler = Mage::getSingleton('xmlimport/messageHandler');
     /* @var $productBuilder C4B_XmlImport_Model_Products_ProductBuilder */
     $productBuilder = Mage::getModel('xmlimport/products_productBuilder');
     $productNodePosition = 0;
     $xmlReader = new XMLReader();
     $xmlReader->open($filePath);
     $products = array();
     while ($xmlReader->read()) {
         if ($xmlReader->nodeType != XMLReader::ELEMENT || $xmlReader->name != self::XML_NODE_NAME_PRODUCT) {
             continue;
         }
         $productNodePosition++;
         $productData = $productBuilder->getProductData($xmlReader->expand());
         if (count($productBuilder->getErrors()) > 0) {
             $messageHandler->addError("Product at position {$productNodePosition} has errors:");
         }
         if ($productData == null) {
             $messageHandler->addError('Product will not be imported');
         } else {
             foreach ($productData as $productDataRow) {
                 $products[] = $productDataRow;
             }
         }
         $messageHandler->addErrorsForFile(basename($filePath), $productNodePosition, $productBuilder->getErrors());
     }
     return $products;
 }
 /**
  * Parses a specific XML file
  *
  * @param string $inputFile File to parse
  * @return \Generator
  */
 public function parse($inputFile)
 {
     $DCNamespace = 'http://purl.org/rss/1.0/modules/content/';
     $WPNamespace = 'http://wordpress.org/export/1.2/';
     $reader = new \XMLReader();
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $reader->open($inputFile);
     while ($reader->read() && $reader->name !== 'item') {
     }
     while ($reader->name == 'item') {
         $xml = simplexml_import_dom($dom->importNode($reader->expand(), true));
         $wpItems = $xml->children($WPNamespace);
         $content = $xml->children($DCNamespace)->encoded;
         $categories = [];
         $tags = [];
         foreach ($xml->category as $category) {
             if ('category' == $category->attributes()->domain) {
                 $categories[] = (string) $category;
             }
             if ('post_tag' == $category->attributes()->domain) {
                 $tags[] = (string) $category;
             }
         }
         if ($wpItems) {
             $post_type = (string) $wpItems->post_type;
             $data = ['type' => $post_type, 'post_date' => new \DateTime((string) $wpItems->post_date), 'title' => (string) $xml->title, 'content' => (string) $content, 'tags' => $tags, 'categories' => $categories];
             (yield $data);
         }
         $reader->next('item');
     }
 }
Exemple #5
0
 /**
  * Parses a MySQL dump XML file.
  *
  * @param $source
  * @return Fixture
  * @throws \TheIconic\Fixtures\Exception\InvalidParserException
  */
 public function parse($source)
 {
     $fixtureArray = [];
     $z = new \XMLReader();
     $z->open($source);
     $doc = new \DOMDocument();
     while ($z->read() && $z->name !== 'table_data') {
     }
     $tableName = $z->getAttribute('name');
     $rowNum = 0;
     while ($z->read() && $z->name !== 'row') {
     }
     while ($z->name === 'row') {
         $node = simplexml_import_dom($doc->importNode($z->expand(), true));
         $totalAttributes = $node->count();
         for ($i = 0; $i < $totalAttributes; $i++) {
             foreach ($node->field[$i]->attributes() as $attribute) {
                 $attribute = (string) $attribute;
                 $value = (string) $node->field[$i];
                 $namespaces = $node->field[$i]->getNamespaces(true);
                 if (empty($namespaces)) {
                     $fixtureArray[$tableName][$rowNum][$attribute] = $value;
                 }
             }
         }
         $rowNum++;
         $z->next('row');
     }
     if (empty($fixtureArray)) {
         throw new InvalidParserException("It was not possible to parse the XML file: {$source}");
     }
     return Fixture::create($fixtureArray);
 }
Exemple #6
0
function foo()
{
    for ($i = 0; $i < 100; $i++) {
        $reader = new XMLReader();
        $reader->xml('<?xml version="1.0" encoding="utf-8"?><id>1234567890</id>');
        while ($reader->read()) {
            $reader->expand();
        }
    }
}
Exemple #7
0
 /**
  * Return the current element, <b>FALSE</b> on error
  * @link http://php.net/manual/en/iterator.current.php
  * @link http://stackoverflow.com/a/1835324/372654
  * @return false|array|\SimpleXMLElement
  */
 public function current()
 {
     $node = $this->reader->expand();
     if ($node === false) {
         return false;
     }
     $node = $this->doc->importNode($node, true);
     if ($node === false) {
         return false;
     }
     $current = simplexml_import_dom($node);
     if ($current === false) {
         return false;
     }
     if ($this->options["asArray"]) {
         return json_decode(json_encode($current), true);
     } else {
         return $current;
     }
 }
Exemple #8
0
 /**
  * Method to expand the current reader node into a SimpleXML node for more detailed reading
  * and manipulation.
  *
  * @return  SimpleXMLElement
  *
  * @since   3.0
  * @throws  RuntimeException
  */
 protected function expandToSimpleXml()
 {
     // Whizbang!  And now we have a SimpleXMLElement element from the current stream node. **MAGIC** :-)
     $el = simplexml_import_dom($this->_node->importNode($this->stream->expand(), true), 'SimpleXMLElement');
     // Let's take care of some sanity checking.
     if (!$el instanceof SimpleXMLElement) {
         // @codeCoverageIgnoreStart
         throw new RuntimeException('Unable to expand node to SimpleXML element.');
         // @codeCoverageIgnoreEnd
     }
     return $el;
 }
 /**
  *  Generator to read each specified element in turn and return it as a nice object
  *
  *  @param   string  $elementType  The element type that we want to return
  *  @return  \Generator  \DateTime => \GpxReader\GpxElement
  **/
 public function getElements($elementType)
 {
     while ($this->gpxReader->read()) {
         if ($this->gpxReader->nodeType == \XMLREADER::ELEMENT && $this->gpxReader->name == $elementType) {
             $doc = new \DOMDocument('1.0', 'UTF-8');
             $xml = simplexml_import_dom($doc->importNode($this->gpxReader->expand(), true));
             $gpxAttributes = $this->readAttributes($this->gpxReader);
             $gpxElement = $this->readChildren($xml);
             $gpxElement->position = $gpxAttributes;
             (yield $gpxElement->timestamp => $gpxElement);
         }
     }
 }
 /**
  * Decorated method
  *
  * @throws BadMethodCallException
  * @return string
  */
 public function readString()
 {
     // Compatibility libxml 20620 (2.6.20) or later - LIBXML_VERSION  / LIBXML_DOTTED_VERSION
     if (method_exists($this->reader, 'readString')) {
         return $this->reader->readString();
     }
     if (0 === $this->reader->nodeType) {
         return '';
     }
     if (false === ($node = $this->reader->expand())) {
         throw new BadMethodCallException('Unable to expand node.');
     }
     return $node->textContent;
 }
 public function importXML($file)
 {
     global $opt;
     $xr = new XMLReader();
     if (!$xr->open($file)) {
         $xr->close();
         return;
     }
     $xr->read();
     if ($xr->nodeType != XMLReader::ELEMENT) {
         echo 'error: First element expected, aborted' . "\n";
         return;
     }
     if ($xr->name != 'gkxml') {
         echo 'error: First element not valid, aborted' . "\n";
         return;
     }
     $startupdate = $xr->getAttribute('date');
     if ($startupdate == '') {
         echo 'error: Date attribute not valid, aborted' . "\n";
         return;
     }
     while ($xr->read() && !($xr->name == 'geokret' || $xr->name == 'moves')) {
     }
     $nRecordsCount = 0;
     do {
         if ($xr->nodeType == XMLReader::ELEMENT) {
             $element = $xr->expand();
             switch ($xr->name) {
                 case 'geokret':
                     $this->importGeoKret($element);
                     break;
                 case 'moves':
                     $this->importMove($element);
                     break;
             }
             $nRecordsCount++;
         }
     } while ($xr->next());
     $xr->close();
     setSysConfig('geokrety_lastupdate', date($opt['db']['dateformat'], strtotime($startupdate)));
 }
 function importXML($file)
 {
     global $opt;
     $xr = new XMLReader();
     if (!$xr->open($file)) {
         $xr->close();
         return;
     }
     $xr->read();
     if ($xr->nodeType != XMLReader::ELEMENT) {
         echo 'error: First element expected, aborted' . "\n";
         return;
     }
     if ($xr->name != 'gkxml') {
         echo 'error: First element not valid, aborted' . "\n";
         return;
     }
     $startupdate = $xr->getAttribute('date');
     if ($startupdate == '') {
         echo 'error: Date attribute not valid, aborted' . "\n";
         return;
     }
     while ($xr->read() && !($xr->name == 'geokret' || $xr->name == 'moves')) {
     }
     $nRecordsCount = 0;
     do {
         if ($xr->nodeType == XMLReader::ELEMENT) {
             $element = $xr->expand();
             switch ($xr->name) {
                 case 'geokret':
                     $this->importGeoKret($element);
                     break;
                 case 'moves':
                     $this->importMove($element);
                     break;
             }
             $nRecordsCount++;
         }
     } while ($xr->next());
     $xr->close();
     sql("UPDATE sysconfig SET value = '" . sql_escape($startupdate) . "' WHERE name='geokrety_lastupdate'");
 }
 /**
  * @param OutputInterface $output
  * @param \SplFileInfo    $feed
  * @param string          $filterExpression
  *
  * @return array<array, integer>
  */
 protected function inspect(OutputInterface $output, \SplFileInfo $feed, $filterExpression)
 {
     $options = LIBXML_NOENT | LIBXML_NONET | LIBXML_COMPACT | LIBXML_PARSEHUGE | LIBXML_NOERROR | LIBXML_NOWARNING;
     $this->reader = new \XMLReader($options);
     $this->reader->open($feed->getPathname());
     $this->reader->setParserProperty(\XMLReader::SUBST_ENTITIES, true);
     libxml_clear_errors();
     libxml_use_internal_errors(true);
     libxml_disable_entity_loader(true);
     $total = 0;
     $results = [];
     $output->writeln(sprintf('Reading <comment>%s</comment>', $feed->getFilename()));
     if ($filterExpression) {
         $output->writeln(sprintf('Filtering nodes with expression "<info>%s</info>"', $filterExpression));
     }
     $progress = new ProgressBar($output);
     $progress->start();
     // go through the whole thing
     while ($this->reader->read()) {
         if ($this->reader->nodeType === \XMLReader::ELEMENT && $this->reader->name === 'listing') {
             $progress->advance();
             ++$total;
             $node = $this->reader->expand();
             $doc = new \DOMDocument();
             $doc->appendChild($node);
             $xpath = new \DOMXPath($doc);
             $xpath->registerNamespace('x', $doc->lookupNamespaceUri($doc->namespaceURI));
             $query = $xpath->evaluate($filterExpression, $node);
             $result = $query instanceof \DOMNodeList ? $query->length : !empty($query);
             if ($result) {
                 $results[] = $node;
             }
         }
     }
     $progress->finish();
     $output->writeln('');
     return [$results, $total];
 }
 private function getArguments(XMLReader $xmlReader)
 {
     $valueList = array();
     $nodeList = $xmlReader->expand();
     foreach ($nodeList->childNodes as $node) {
         switch ($node->nodeName) {
             case 'ref':
                 $valueList[] = new IoCArgumentValue(IoCArgumentValue::VALUETYPE_REF, trim($node->nodeValue));
                 break;
             case 'eval':
                 $valueList[] = new IoCArgumentValue(IoCArgumentValue::VALUETYPE_EVAL, trim($node->nodeValue));
                 break;
             case 'value':
                 $valueList[] = new IoCArgumentValue(IoCArgumentValue::VALUETYPE_VALUE, $node->nodeValue);
                 break;
             case '#text':
                 if (!trim($node->nodeValue)) {
                     continue;
                 }
         }
     }
     return $valueList;
 }
        while ($paragraph->read()) {

            $node_loc = $paragraph->localName;
            // look for elements
            if ($paragraph->nodeType == XMLREADER::ELEMENT && $paragraph->name === 'w:r') {
                $node = trim($paragraph->readInnerXML());
                //echo $node;
                // add <br> tags
                if (strstr($node, '<w:br '))
                    $text .= '<br>';

                // look for formatting tags                    
                $formatting['bold'] = (strstr($node, '<w:b/>')) ? (($formatting['bold'] == 'closed') ? 'open' : $formatting['bold']) : (($formatting['bold'] == 'opened') ? 'close' : $formatting['bold']);
                $formatting['italic'] = (strstr($node, '<w:i/>')) ? (($formatting['italic'] == 'closed') ? 'open' : $formatting['italic']) : (($formatting['italic'] == 'opened') ? 'close' : $formatting['italic']);
                $formatting['underline'] = (strstr($node, '<w:u ')) ? (($formatting['underline'] == 'closed') ? 'open' : $formatting['underline']) : (($formatting['underline'] == 'opened') ? 'close' : $formatting['underline']);
                $str = $paragraph->expand()->textContent;
                // build text string of doc
                $text .= (($formatting['bold'] == 'open') ? '<strong>' : '') .
                        (($formatting['italic'] == 'open') ? '<em>' : '') .
                        (($formatting['underline'] == 'open') ? '<u>' : '') .
                        //htmlentities(iconv('UTF-8', 'ASCII//TRANSLIT',$paragraph->expand()->textContent)).
                        htmlentities($str, ENT_QUOTES, "utf-8") .
                        (($formatting['underline'] == 'close') ? '</u>' : '') .
                        (($formatting['italic'] == 'close') ? '</em>' : '') .
                        (($formatting['bold'] == 'close') ? '</strong>' : '');

                // reset formatting variables
                foreach ($formatting as $key => $format) {
                    if ($format == 'open')
                        $formatting[$key] = 'opened';
                    if ($format == 'close')
 function transform($out_stream = 'php://stdout')
 {
     $this->indices = false;
     if (!is_readable($this->file)) {
         error_log("unreadable file: " . $this->file);
         return false;
     }
     if (!($out = fopen($out_stream, "w"))) {
         error_log("unwritable file: " . $out_stream);
         return false;
     }
     $import_name = get_class($this);
     if (count($this->invalids) > 0) {
         $header = "<?xml version='1.0'?>\r\n<relationshipCollection name='{$import_name}' invalid='" . implode(',', $this->invalids) . "'>\r\n";
     } else {
         $header = "<?xml version='1.0'?>\r\n<relationshipCollection name='{$import_name}'>\r\n";
     }
     fwrite($out, $header);
     $reader = new XMLReader();
     $reader->open($this->file, null, 1 << 19);
     $this->indices = false;
     $c = 0;
     $found_row = false;
     while (!$found_row && $reader->read() || $found_row && $reader->next()) {
         if (!$reader->nodeType == XMLReader::ELEMENT || !($reader->name == 'Row')) {
             continue;
         }
         $found_row = true;
         if (is_array($this->indices) && $this->skip > 0) {
             $this->skip--;
             continue;
         }
         $row = $reader->expand();
         if (!is_array($this->indices)) {
             $this->do_indices($row);
         } else {
             fwrite($out, $this->transform_row($row));
             $c++;
             error_log("Transformed record {$c}");
             if ($this->max > 0 && $c >= $this->max) {
                 break;
             }
         }
         $reader->next();
     }
     $footer = "\r\n</relationshipCollection> \r\n";
     fwrite($out, $footer);
 }
<?php

if ($argc != 3) {
    print "Usage: createInitialTargetReviewer.php <fileTranslator> <fileReviewer>";
} else {
    $fileTranslator = $argv[1];
    $fileReviewer = $argv[2];
    $reader = new XMLReader();
    $reader->open($fileTranslator);
    while ($reader->read()) {
        if ($reader->name === 'finalTargetText') {
            $dom = $reader->expand();
            $finalTargets = $dom->getElementsByTagName('segment');
            $translations = array();
            foreach ($finalTargets as $target) {
                array_push($translations, $target->nodeValue);
            }
            break;
        }
    }
    $doc = new DOMDocument();
    $doc->load($fileReviewer);
    $domAttribute = $doc->createAttribute('review');
    $domAttribute->value = 'true';
    $doc->getElementsByTagName("Languages")->item(0)->appendChild($domAttribute);
    $segments = $doc->getElementsByTagName("initialTargetText")->item(0)->getElementsByTagName('segment');
    $count = 0;
    foreach ($segments as $segment) {
        $segment->nodeValue = $translations[$count];
        $count = $count + 1;
    }
Exemple #18
0
 /**
  * @param string $fileName
  * @return \DOMNode[]
  */
 private function getCellElementsFromSheetXmlFile($fileName)
 {
     $cellElements = [];
     $resourcePath = $this->getGeneratedResourcePath($fileName);
     $pathToStylesXmlFile = $resourcePath . '#xl/worksheets/sheet1.xml';
     $xmlReader = new \XMLReader();
     $xmlReader->open('zip://' . $pathToStylesXmlFile);
     while ($xmlReader->read()) {
         if ($xmlReader->nodeType === \XMLReader::ELEMENT && $xmlReader->name === 'c') {
             $cellElements[] = $xmlReader->expand();
         }
     }
     return $cellElements;
 }
<?php

$output = array();
$concepts = array();
$codeLists = array();
$keyFamilies = array();
$reader = new XMLReader();
$reader->open('xml-schema/KeyFamily.xml');
while ($reader->read()) {
    switch ($reader->nodeType) {
        case XMLREADER::ELEMENT:
            if ($reader->localName == "Concept") {
                $node = $reader->expand();
                $agencyID = $node->getAttribute('agencyID');
                $id = $node->getAttribute('id');
                $Name = $node->getELementsByTagName('Name')->item(0)->textContent;
                $concepts[$agencyID][$id]['label'] = $Name;
            } else {
                if ($reader->localName == "Dimension") {
                    $node = $reader->expand();
                    $dom = new DomDocument();
                    $n = $dom->importNode($node, true);
                    $dom->appendChild($n);
                    $concepts[$node->getAttribute('conceptAgency')][$node->getAttribute('conceptRef')]['codeLists'][] = $node->getAttribute('codelist');
                    $concepts[$node->getAttribute('conceptAgency')][$node->getAttribute('conceptRef')]['codeLists'] = array_unique($concepts[$node->getAttribute('conceptAgency')][$node->getAttribute('conceptRef')]['codeLists']);
                } else {
                    if ($reader->localName == "CodeList") {
                        $node = $reader->expand();
                        $id = $node->getAttribute('id');
                        $Name = $node->getELementsByTagName('Name')->item(0)->textContent;
                        $codeLists[$id]['label'] = $Name;
Exemple #20
0
                         $reader->read();
                         if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'type') {
                             $typesId = $reader->getAttribute('id');
                             $sql = "INSERT INTO content_types (content_id, type_id)\n                    VALUES ('{$contentId}','{$typesId}')";
                             mysql_query($sql);
                         }
                     }
                 }
             }
         }
     }
 }
 if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'content') {
     $contentId = $reader->getAttribute('id') . "\n";
     $doc = new DOMDocument('1.0', 'UTF-8');
     $xml = simplexml_import_dom($doc->importNode($reader->expand(), true));
     while ($reader->read() && $reader->nodeType !== XMLReader::END_ELEMENT) {
         $typesId = $xml->types_list->type->attributes()->id;
     }
     $sql = "INSERT INTO content_types (content_id, type_id)\n                            VALUES ('{$contentId}','{$typesId}')";
     mysql_query($sql);
 }
 //content_persons
 if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'content') {
     $contentId = $reader->getAttribute('id');
     while ($reader->nodeType !== XMLReader::END_ELEMENT) {
         $reader->read();
         if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'actors_list') {
             while ($reader->nodeType !== XMLReader::END_ELEMENT) {
                 $reader->read();
                 if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'person') {
 /**
  * Short description of method getCapiDescriptor
  *
  * @access public
  * @author firstname and lastname of author, <*****@*****.**>
  * @return CapiDescriptor
  */
 public function getCapiDescriptor()
 {
     if ($this->isValidated) {
         $xml = new XMLReader();
         $xml->open($this->filepath);
         //        	echo '$xml->nodeType | $xml->name|$xml->value|$xml->localName <br/>' ;
         $capiDecriptor = new CapiDescriptor(__METHOD__);
         //debug
         //				echo $xml->nodeType . '|' . $xml->name . '|' . $xml->value . '|' . $xml->localName . '<br/>';
         if (RDFLIST_COMLPIANT) {
             while ($xml->read()) {
                 if ($xml->localName == 'list' && $xml->nodeType == XMLREADER::ELEMENT) {
                     $listDom = $xml->expand();
                     $capiDecriptor->list->add($this->getListDescriptor($listDom));
                     while ($xml->next('list')) {
                         $listDom = $xml->expand();
                         $capiDecriptor->list->add($this->getListDescriptor($listDom));
                     }
                     break;
                 }
             }
         } else {
             while ($xml->read()) {
                 if (($xml->localName == 'itemGroup' || $xml->localName == 'tank') && $xml->nodeType == XMLREADER::ELEMENT) {
                     $itemGroupDom = $xml->expand();
                     //sic... itemgroup tagname is also used in references...
                     if (!$itemGroupDom->hasAttribute('ref')) {
                         $capiDecriptor->itemGroup->add($this->getItemGroupDescriptor($itemGroupDom));
                     }
                 }
             }
         }
     } else {
         $this->importError = 'Could not import non valid file';
     }
     return $capiDecriptor;
 }
Exemple #22
0
    /**
     * @access public
     * Chargement des données de configuration dans le fichier XML
     */
    public function config_xml_data()
    {
        $pathxml = $this->pluginDir() . 'config.xml';
        if (file_exists($pathxml)) {
            try {
                $xml = new XMLReader();
                $xml->open($pathxml, "UTF-8");
                // Configuration d'analyse XML
                //$xml->setParserProperty(XMLReader::VALIDATE, true);
                //if($xml->isValid()){
                while ($xml->read()) {
                    if ($xml->nodeType == XMLREADER::ELEMENT && $xml->localName == "infos") {
                        $v = $xml->expand();
                        $v = new SimpleXMLElement('<infos>' . $xml->readInnerXML() . '</infos>', 0, false);
                        //echo ReflectionObject::export($v);
                        //echo ReflectionObject::export($v['attr']);
                        $r = '';
                        if ($v->version) {
                            $r .= '<table class="table table-bordered table-condensed table-hover">
								<tr>
									<td>Création:</td>
									<td>' . $v->version->date_create . '</td>
								</tr>
								<tr>
									<td>Update:</td>
									<td>' . $v->version->date_update . '</td>
								</tr>
								<tr>
									<td>Version:</td>
									<td>' . $v->version->number . ' ' . $v->version->phase . '</td>
								</tr>';
                            if ($v->version->support->forum['href'] != false) {
                                $r .= '<tr>
									<td>Support:</td>
									<td><a class="targetblank" href="' . $v->version->support->forum['href'] . '">' . $v->version->support->forum . '</a></td>
								</tr>';
                            }
                            if ($v->version->support->ticket['href'] != false) {
                                $r .= '<tr>
									<td>Tickets:</td>
									<td><a class="targetblank" href="' . $v->version->support->ticket['href'] . '"><span class="fa fa-bullhorn"></span> Signaler un bug</a></td>
								</tr>';
                            }
                            if ($v->version->support->svn['href'] != false) {
                                $r .= '<tr>
									<td class="small-icon">SVN:</td>
									<td><a class="targetblank" href="' . $v->version->support->svn['href'] . '"><span class="icon fa fa-svn"></span></a></td>
								</tr>';
                            }
                            if ($v->version->support->git['href'] != false) {
                                $r .= '<tr>
									<td>GIT:</td>
									<td><a class="targetblank" href="' . $v->version->support->git['href'] . '"><span class="fa fa-github fa fa-large"></span></a></td>
								</tr>';
                            }
                            $r .= '</table>';
                        }
                        if ($v->authors) {
                            $r .= '<table class="table table-bordered table-condensed table-hover">
								<thead>
									<tr>
										<th>Author</th>
										<th>Website</th>
									</tr>
								</thead>
								<tbody>';
                            foreach ($v->authors->author as $row) {
                                $r .= '<tr>';
                                $r .= '<td>' . $row->name . '</td>';
                                $r .= '<td><ul class="list-unstyled">';
                                $t = '';
                                foreach ($row->link->children() as $link) {
                                    $r .= '<li><a class="targetblank" ';
                                    $r .= 'href="' . $link->attributes()->href . '">' . $link->attributes()->href . '</a></li>';
                                }
                                $r .= '</ul></td>';
                                $r .= '</tr>';
                            }
                            $r .= '</tbody></table>';
                        }
                        return $r;
                    }
                }
                //}
            } catch (Exception $e) {
                magixglobal_model_system::magixlog('An error has occured :', $e);
            }
        }
    }
 protected function import($file, $ignore_ids = false)
 {
     $reader = new XMLReader();
     $reader->open($file, null, 1 << 19);
     $save_ids = array();
     $count = 0;
     $exec = array('max_execution_time' => 20 * 60, 'memory_limit' => 256 * 1048576);
     $importer = new I2CE_FormRelationship_Importer();
     if (array_key_exists('HTTP_HOST', $_SERVER)) {
         $importer->setMessageCallback(array($this, 'pushMessage'));
     }
     $defaults = array('ignoreids' => $ignore_ids ? '1' : '0', 'nomatching' => '', 'invalid' => '');
     $next = false;
     while ($next || $reader->read()) {
         $next = false;
         if ($reader->nodeType != XMLReader::ELEMENT) {
             continue;
         }
         switch ($reader->name) {
             case 'relationshipCollection':
                 foreach ($defaults as $key => $val) {
                     if (($v = $reader->getAttribute($key)) !== null) {
                         $defaults[$key] = $v;
                     }
                 }
                 while ($reader->read()) {
                     //skip to a relationship sub-element
                     if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'relationship') {
                         break;
                     }
                 }
                 //break;  - purposefully do not break as we want to get process any relationship under a relationshipCollection
             //break;  - purposefully do not break as we want to get process any relationship under a relationshipCollection
             case 'relationship':
                 I2CE::longExecution($exec);
                 $node = $reader->expand();
                 $doc = new DOMDocument();
                 $i_node = $doc->importNode($node, true);
                 foreach ($defaults as $k => $v) {
                     $i_node->setAttribute($k, $v);
                 }
                 $new_ids = $importer->loadFromXML($i_node);
                 $save_ids = array_merge($save_ids, $new_ids);
                 if (array_key_exists('HTTP_HOST', $_SERVER) && count($new_ids) > 0) {
                     $this->pushMessage("Imported records with ids:\n" . implode(",", $new_ids));
                 }
                 $count++;
                 $reader->next();
                 $next = true;
                 break;
             default:
                 if (array_key_exists('HTTP_HOST', $_SERVER)) {
                     $this->pushError("Unrecognized data type: " . $reader->name);
                 }
                 break;
         }
     }
     $summary = "Import Summary:  (processed {$count} relationships)\n";
     foreach ($save_ids as $save_id => $msg) {
         $summary .= str_replace("\n", "\n  - ", $msg) . "\n";
     }
     I2CE::raiseMessage($summary);
     $this->pushMessage($summary);
     return true;
 }
Exemple #24
0
 /**
  * Retrieves items from an OAI-enabled url.
  *
  * @param  JTable  $harvest  The harvesting details.
  */
 public function onJHarvestRetrieve($harvest)
 {
     $params = new \Joomla\Registry\Registry();
     $params->loadString($harvest->params);
     if ($params->get('discovery.type') != 'oai') {
         return;
     }
     $resumptionToken = null;
     $http = JHttpFactory::getHttp();
     $metadataPrefix = $params->get('discovery.plugin.metadata');
     do {
         $queries = array();
         if ($resumptionToken) {
             $queries['resumptionToken'] = $resumptionToken;
             // take a break to avoid any timeout issues.
             if (($sleep = $params->get('follow_on', self::FOLLOW_ON)) != 0) {
                 sleep($sleep);
             }
         } else {
             $queries['metadataPrefix'] = $metadataPrefix;
             if ($harvest->harvested != JFactory::getDbo()->getNullDate()) {
                 $queries['from'] = JFactory::getDate($harvest->harvested)->format('Y-m-d\\TH:i:s\\Z');
             }
             if ($set = $params->get('set')) {
                 $queries['set'] = $set;
             }
             $queries['until'] = $harvest->now->format('Y-m-d\\TH:i:s\\Z');
         }
         $url = new JUri($params->get('discovery.url'));
         $url->setQuery($queries);
         $url->setVar('verb', 'ListRecords');
         JHarvestHelper::log('Retrieving ' . (string) $url . ' for harvest...', JLog::DEBUG);
         $response = $http->get($url);
         $reader = new XMLReader();
         $reader->xml($response->body);
         $prefix = null;
         $identifier = null;
         $resumptionToken = null;
         // empty the resumptionToken to force a reload per page.
         while ($reader->read()) {
             if ($reader->nodeType == XMLReader::ELEMENT) {
                 $doc = new DOMDocument();
                 $doc->appendChild($doc->importNode($reader->expand(), true));
                 $node = simplexml_load_string($doc->saveXML());
                 $attributes = (array) $node->attributes();
                 if (isset($attributes['@attributes'])) {
                     $attributes = $attributes['@attributes'];
                 }
                 switch ($reader->name) {
                     case "record":
                         try {
                             $this->cache($harvest, $node);
                         } catch (Exception $e) {
                             JHarvestHelper::log($e->getMessage(), JLog::ERROR);
                         }
                         break;
                     case 'responseDate':
                         // only get the response date if fresh harvest.
                         if (!$resumptionToken) {
                             $this->harvested = JFactory::getDate($node);
                         }
                         break;
                     case 'request':
                         $prefix = JArrayHelper::getValue($attributes, 'metadataPrefix', null, 'string');
                         break;
                     case 'error':
                         if (JArrayHelper::getValue($attributes, 'code', null, 'string') !== "noRecordsMatch") {
                             throw new Exception((string) $node, 500);
                         }
                         break;
                     case 'resumptionToken':
                         $resumptionToken = (string) $node;
                         break;
                     default:
                         break;
                 }
             }
         }
     } while ($resumptionToken);
 }
 /**
  * Get the value of the CreateDateAndTime node from the XML in the given file.
  * If the node doesn't exist in the file, will return null.
  * @param string $filename path to XML file
  * @return string|null
  */
 protected function _getDateTimeFromFeed($filename)
 {
     $reader = new XMLReader();
     $reader->open($filename);
     // the following 2 variables prevent the edge case where we get a large file
     // with a node depth < 2
     $elementsRead = 0;
     $maxElements = 2;
     // the date/time node is at depth 2
     $targetDepth = 2;
     // navigate to within the message header
     while ($reader->depth < $targetDepth && $elementsRead <= $maxElements && $reader->read()) {
         // ignore whitespace
         if ($reader->nodeType !== XMLReader::ELEMENT) {
             continue;
         }
     }
     $dateNode = null;
     // at this point we should be at the depth where the creation date is.
     // if we stopped on the node, then grab it
     if ($reader->localName === 'CreateDateAndTime') {
         $dateNode = $reader->expand();
     } elseif ($reader->next('CreateDateAndTime')) {
         // otherwise go to the next instance of it
         $dateNode = $reader->expand();
     }
     return $dateNode ? $dateNode->nodeValue : null;
 }
 /**
  * @param string $liftFilePath
  * @param LexiconProjectModel $projectModel
  * @param LiftMergeRule $mergeRule
  * @param boolean $skipSameModTime
  * @param boolean $deleteMatchingEntry
  * @return \Api\Model\Languageforge\Lexicon\LiftImport
  */
 public function merge($liftFilePath, $projectModel, $mergeRule = LiftMergeRule::CREATE_DUPLICATES, $skipSameModTime = true, $deleteMatchingEntry = false)
 {
     ini_set('max_execution_time', 180);
     // Sufficient time to import webster.  TODO Make this async CP 2014-10
     $entryList = new LexEntryListModel($projectModel);
     $entryList->read();
     $hasExistingData = $entryList->count != 0;
     if (!$hasExistingData) {
         $projectModel->config->clearAllInputSystems();
         // save and clear input systems
         $savedInputSystems = $projectModel->inputSystems->getArrayCopy();
         $projectModel->inputSystems->exchangeArray(array());
     }
     $reader = new \XMLReader();
     $reader->open($liftFilePath);
     $this->liftDecoder = new LiftDecoder($projectModel);
     $this->stats = new LiftImportStats($entryList->count);
     $this->report = new ImportErrorReport();
     $this->liftImportNodeError = new LiftImportNodeError(LiftImportNodeError::FILE, basename($liftFilePath));
     $liftRangeDecoder = new LiftRangeDecoder($projectModel);
     $liftRangeFiles = array();
     // Keys: filenames. Values: parsed files.
     $liftRanges = array();
     // Keys: @id attributes of <range> elements. Values: parsed <range> elements.
     $liftFolderPath = dirname($liftFilePath);
     while ($reader->read()) {
         // Read LIFT ranges in the header of the LIFT file
         if ($reader->nodeType == \XMLReader::ELEMENT && $reader->localName == 'range') {
             $node = $reader->expand();
             $rangeId = $node->attributes->getNamedItem('id')->textContent;
             $rangeHref = $node->attributes->getNamedItem('href')->textContent;
             $hrefPath = parse_url($rangeHref, PHP_URL_PATH);
             $rangeFilename = basename($hrefPath);
             $rangeImportNodeError = new LiftRangeImportNodeError(LiftRangeImportNodeError::FILE, $rangeFilename);
             if (!array_key_exists($rangeFilename, $liftRangeFiles)) {
                 // Haven't parsed the .lift-ranges file yet. We'll assume it is alongside the .lift file.
                 $rangeFilePath = $liftFolderPath . "/" . $rangeFilename;
                 if (file_exists($rangeFilePath)) {
                     $sxeNode = simplexml_load_file($rangeFilePath);
                     $parsedRanges = $liftRangeDecoder->decode($sxeNode);
                     $liftRanges = array_merge($liftRanges, $parsedRanges);
                     $liftRangeFiles[] = $rangeFilename;
                 } else {
                     // Range file was NOT found in alongside the .lift file
                     $rangeImportNodeError->addRangeFileNotFound(basename($liftFilePath));
                 }
             }
             // pull out the referenced range
             if (isset($liftRanges[$rangeId])) {
                 $range = $liftRanges[$rangeId];
             } else {
                 $range = null;
                 if (file_exists($rangeFilePath)) {
                     // Range was NOT found in referenced .lift-ranges file after parsing it
                     $rangeImportNodeError->addRangeNotFound($rangeId);
                 }
             }
             // Range elements defined in LIFT file override any values defined in .lift-ranges file.
             if ($node->hasChildNodes()) {
                 $rangeNode = self::domNode_to_sxeNode($node);
                 $range = $liftRangeDecoder->readRange($rangeNode, $range);
                 $liftRanges[$rangeId] = $range;
             }
             if ($rangeImportNodeError->hasErrors()) {
                 $this->liftImportNodeError->addSubnodeError($rangeImportNodeError);
             }
         }
         // Read the custom 'fields' spec in the header of the LIFT file
         if ($reader->nodeType == \XMLReader::ELEMENT && $reader->localName == 'fields') {
             $isInFieldsSectionOfLift = true;
             $this->liftDecoder->liftFields = array();
             while ($isInFieldsSectionOfLift && $reader->read()) {
                 if ($reader->nodeType == \XMLReader::ELEMENT && $reader->localName == 'field') {
                     $node = $reader->expand();
                     $sxeNode = self::domNode_to_sxeNode($node);
                     $LiftFieldTag = (string) $sxeNode['tag'];
                     $liftField = array();
                     foreach ($sxeNode as $element) {
                         if ($element->getName() === 'form') {
                             $inputSystemTag = (string) $element['lang'];
                             $liftField[$inputSystemTag] = (string) $element->text;
                         }
                     }
                     $this->liftDecoder->liftFields[$LiftFieldTag] = $liftField;
                 } elseif ($reader->nodeType == \XMLReader::END_ELEMENT && $reader->localName == 'fields') {
                     $isInFieldsSectionOfLift = false;
                 }
             }
         }
         // Read an entry node
         if ($reader->nodeType == \XMLReader::ELEMENT && $reader->localName == 'entry') {
             $this->stats->importEntries++;
             $node = $reader->expand();
             $sxeNode = self::domNode_to_sxeNode($node);
             $guid = $reader->getAttribute('guid');
             $existingEntry = $entryList->searchEntriesFor('guid', $guid);
             if ($existingEntry) {
                 $entry = new LexEntryModel($projectModel, $existingEntry['id']);
                 $dateModified = $reader->getAttribute('dateModified');
                 if (self::differentModTime($dateModified, $entry->authorInfo->modifiedDate) || !$skipSameModTime) {
                     if ($mergeRule == LiftMergeRule::CREATE_DUPLICATES) {
                         $entry = new LexEntryModel($projectModel);
                         $this->readEntryWithErrorReport($sxeNode, $entry, $mergeRule);
                         $entry->guid = '';
                         $entry->write();
                         $this->stats->entriesDuplicated++;
                     } else {
                         if (isset($sxeNode->{'lexical-unit'})) {
                             $this->readEntryWithErrorReport($sxeNode, $entry, $mergeRule);
                             $entry->write();
                             $this->stats->entriesMerged++;
                         } elseif (isset($sxeNode->attributes()->dateDeleted) && $deleteMatchingEntry) {
                             LexEntryModel::remove($projectModel, $existingEntry['id']);
                             $this->stats->entriesDeleted++;
                         }
                     }
                 } else {
                     // skip because same mod time and skip enabled
                     if (!isset($sxeNode->{'lexical-unit'}) && isset($sxeNode->attributes()->dateDeleted) && $deleteMatchingEntry) {
                         LexEntryModel::remove($projectModel, $existingEntry['id']);
                         $this->stats->entriesDeleted++;
                     }
                 }
             } else {
                 if (isset($sxeNode->{'lexical-unit'})) {
                     $entry = new LexEntryModel($projectModel);
                     $this->readEntryWithErrorReport($sxeNode, $entry, $mergeRule);
                     $entry->write();
                     $this->stats->newEntries++;
                 }
             }
         }
     }
     $reader->close();
     // put back saved input systems if none found in the imported data
     if (!$hasExistingData && $projectModel->inputSystems->count() <= 0) {
         $projectModel->inputSystems->exchangeArray($savedInputSystems);
     }
     // add lift ranges
     if ($mergeRule != LiftMergeRule::IMPORT_LOSES) {
         foreach ($liftRanges as $liftRangeCode => $liftRange) {
             // add everything except semantic domains
             if (strpos($liftRangeCode, 'semantic-domain') === false) {
                 self::rangeToOptionList($projectModel, $liftRangeCode, LexiconConfigObj::flexOptionlistName($liftRangeCode), $liftRange);
             }
         }
     }
     $this->report->nodeErrors[] = $this->liftImportNodeError;
     if ($this->report->hasError()) {
         error_log($this->report->toString());
     }
     return $this;
 }
Exemple #27
0
<?php

$z = new XMLReader();
$z->open('names.xml');
$doc = new DOMDocument();
// move to the first <product /> node
while ($z->read() && $z->name !== 'name') {
}
// now that we're at the right depth, hop to the next <product/> until the end of the tree
while ($z->name === 'name') {
    echo $z->name . "<br>";
    // either one should work
    //$node = new SimpleXMLElement($z->readOuterXML());
    $node = simplexml_import_dom($doc->importNode($z->expand(), true));
    // now you can use $node without going insane about parsing
    echo $node->fname . " " . $node->lname . "<br>";
    $z->next('name');
}
 public function handleMessage(Import $import, Message $message, Channel $channel)
 {
     if (!$import->getTmpFileName()) {
         $this->log->error("Import w/o tmp file name: {$message->content}.");
         $channel->ack($message);
         return;
     }
     if (!file_exists($import->getTmpFileName())) {
         $this->log->error("Tmp file name '{$import->getTmpFileName()}' does not exist.");
         $channel->ack($message);
         return;
     }
     $this->log->info("Got " . $message->content);
     // TODO: error handling
     $handle = fopen($import->getTmpFileName(), "r+");
     while (fread($handle, 3) === "") {
         fseek($handle, -3, SEEK_CUR);
         fwrite($handle, "   ");
         $this->log->info("Removed BOM in file '{$import->getTmpFileName()}'.");
     }
     fseek($handle, 0, SEEK_SET);
     $data = fread($handle, 1024);
     if (($sp = strpos($data, "<?xml")) !== false) {
         if (($ep = strpos($data, "?>")) !== false) {
             $newData = substr($data, $sp, $ep - $sp + 2) . str_repeat(" ", $sp) . substr($data, $ep + 2);
             fseek($handle, 0, SEEK_SET);
             fwrite($handle, $newData);
         }
     }
     fclose($handle);
     $eshopId = $import->getEshop()->getId();
     $reader = new \XMLReader();
     $reader->open($import->getTmpFileName());
     while ($reader->read()) {
         if (strtoupper($reader->name) !== "SHOPITEM") {
             continue;
         }
         $item = @$reader->expand();
         if ($item === false) {
             $this->log->error("XMLReader error: " . json_encode(libxml_get_last_error()));
             break;
         }
         $reader->next();
         $product = new Product();
         $product->setEshopId($eshopId);
         foreach ($item->childNodes as $child) {
             /** @var \DOMNode $child */
             if ($child->nodeType !== XML_ELEMENT_NODE) {
                 continue;
             }
             $textContent = trim($child->textContent);
             if (empty($textContent)) {
                 $textContent = null;
             }
             switch ($name = strtoupper($child->nodeName)) {
                 case "ITEM_GROUP_ID":
                     $product->setItemGroupId($textContent);
                     break;
                 case "ITEM_ID":
                     $product->setItemId($textContent);
                     break;
                 case "PRODUCTNAME":
                     $product->setName($textContent);
                     break;
                 case "PRODUCT":
                     $product->setLongName($textContent);
                     break;
                 case "DESCRIPTION":
                     $product->setDescription($textContent);
                     break;
                 case "URL":
                     // TODO: normalize URL
                     $product->setUrl($textContent);
                     break;
                 case "PRICE_VAT":
                     $product->setPrice(floatval(preg_replace("/[^0-9.]+/", "", str_replace(",", ".", $textContent))));
                     break;
                 case "DELIVERY_DATE":
                     $product->setDeliveryDate(intval(preg_replace("/[^0-9]+/", "", $textContent)));
                     break;
                 case "IMGURL":
                 case "IMGURL_ALTERNATIVE":
                     // TODO: normalize URL
                     $image = new Image();
                     $image->setUrl($textContent);
                     $product->addImage($image);
                     break;
                 case "EAN":
                     $product->setEan($textContent);
                     break;
                 case "ISBN":
                     $product->setIsbn($textContent);
                     break;
                 case "PRODUCTNO":
                     $product->setProductno($textContent);
                     break;
                 case "MANUFACTURER":
                     $product->setManufacturer($textContent);
                     break;
                 case "BRAND":
                     $product->setBrand($textContent);
                     break;
                 case "CATEGORYTEXT":
                     if (!empty($textContent)) {
                         $product->addCategoryText($textContent);
                     }
                     break;
                 case "ITEM_TYPE":
                     try {
                         $product->setItemType(ProductItemTypeEnum::fromXML($textContent));
                     } catch (\InvalidArgumentException $e) {
                         $this->log->warning("Got exception while assigning ITEM_TYPE: " . $e->getMessage());
                     }
                     break;
                 case "EXTRA_MESSAGE":
                     try {
                         $product->addExtraMessage(ProductExtraMessageEnum::fromXML($textContent));
                     } catch (\InvalidArgumentException $e) {
                         $this->log->warning("Got exception while assigning EXTRA_MESSAGE: " . $e->getMessage());
                     }
                     break;
             }
         }
         if ($product->getUrl() === null) {
             $this->log->warning("Skipping product without URL: " . ProductMeta::toJson($product));
             continue;
         }
         if ($product->getName() === null) {
             if ($product->getLongName() === null) {
                 $this->log->warning("Skipping product without PRODUCT/PRODUCTNAME: " . ProductMeta::toJson($product));
                 continue;
             } else {
                 $product->setName($product->getLongName());
             }
         }
         if ($product->getItemId() === null) {
             $product->setItemId($product->getUrl());
         }
         if ($product->getItemGroupId() === null) {
             $product->setItemGroupId($product->getItemId());
         }
         for (;;) {
             $existing = $this->productRepository->findOneFromEshop($product);
             if (!$existing) {
                 $this->fillCategoryIds($product);
                 $ret = $this->productRepository->insert($product);
                 if (isset($ret["ok"]) && $ret["ok"]) {
                     $this->changeProducer->publish(Change::create()->setProduct($product), RoutingKeys::CHANGE_PRODUCT_CREATE);
                     break;
                 }
             } else {
                 $this->mergeProducts($product, $existing);
                 $this->fillCategoryIds($product);
                 $ret = $this->productRepository->update(["_id" => $existing->getId(), "v" => $existing->getV()], ProductMeta::toArray($product));
                 if (isset($ret["ok"]) && $ret["ok"] && isset($ret["updatedExisting"]) && $ret["updatedExisting"]) {
                     $this->changeProducer->publish(Change::create()->setProduct($product), RoutingKeys::CHANGE_PRODUCT_UPDATE);
                     break;
                 }
             }
         }
     }
     // TODO: delete products not present in feed
     $reader->close();
     libxml_clear_errors();
     unlink($import->getTmpFileName());
     $channel->ack($message);
 }
 /**
  * Get a list of offers to be added or remove. Write the offers to the database.
  * @param boolean $archive
  * @param string &$log
  * @param array &$count_arr
  * @return null|int|array
  * @throws Exception 
  */
 private function GetOffersPartial($archive, &$log, &$count_arr)
 {
     Errors::LogSynchroStep('WebServiceVirgo - GetOffersPartial() start...');
     if (!$this->WS()) {
         Errors::LogSynchroStep('WebServiceVirgo - NO WEBSERVICE');
         return null;
     }
     try {
         $log .= "archive=" . (int) $archive . "\n";
         $time_start = microtime_float();
         if ($this->_sid == "") {
             return;
         }
         $params = array('sid' => $this->_sid);
         if ($archive) {
             $result = $this->WS()->getSC()->__soapCall("GetOffersArchive", array($params));
             $buf = $result->GetOffersArchiveResult->OffersZip;
             $status = $result->GetOffersArchiveResult->Status;
             $msg = $result->GetOffersArchiveResult->Message;
         } else {
             $result = $this->WS()->getSC()->__soapCall("GetOffers", array($params));
             $buf = $result->GetOffersResult->OffersZip;
             $status = $result->GetOffersResult->Status;
             $msg = $result->GetOffersResult->Message;
         }
         $time_end = microtime_float();
         $time = $time_end - $time_start;
         if ($this->_DEBUG) {
             echo "SOAP Call execution time: {$time} seconds<br>";
         }
         if ($status != 0) {
             throw new Exception($msg);
         }
         $zip_file = $archive ? self::TMP_ZIP_ARCH_FILE : self::TMP_ZIP_FILE;
         $f = fopen($zip_file, "w");
         fwrite($f, $buf);
         fclose($f);
         $time_end2 = microtime_float();
         $time = $time_end2 - $time_end;
         if ($this->_DEBUG) {
             echo "Save ZIP execution time: {$time} seconds<br>";
         }
         //unzip XML file with offers
         $contents = "";
         $zip = new ZipArchive();
         if ($zip->open($zip_file)) {
             $fp = $zip->getStream('xml.xml');
             if (!$fp) {
                 exit("failed reading xml file (" . getcwd() . "), probably invalid permissions to folder\n");
             }
             $contents = '';
             while (!feof($fp)) {
                 $contents .= fread($fp, 1024);
             }
             fclose($fp);
             $zip->close();
             $xml_file = $archive ? self::TMP_XML_OFE_ARCH_FILE : self::TMP_XML_OFE_FILE;
             file_put_contents($xml_file, $contents);
             if (file_exists($zip_file)) {
                 unlink($zip_file);
             }
         }
         $time_end3 = microtime_float();
         $time = $time_end3 - $time_end2;
         if ($this->_DEBUG) {
             echo "Save XML execution time: {$time} seconds<br>";
         }
         $times = array("read_props" => 0, "save" => 0, "del_props" => 0, "rooms" => 0, "del_offers" => 0, "rooms_del" => 0, "photos" => 0);
         $prevOfferId = "0";
         $content = file_get_contents($xml_file);
         //$content = preg_replace("/<UwagiOpis>([^\<\>]*)\<\/UwagiOpis>/m", "<UwagiOpis><![CDATA[$1]]></UwagiOpis>", $content);
         //$content = preg_replace("/<UwagiNieruchomosc>([^\<\>]*)\<\/UwagiNieruchomosc>/m", "<UwagiNieruchomosc><![CDATA[$1]]></UwagiNieruchomosc>", $content);
         $fp = fopen($xml_file, 'w');
         fwrite($fp, $content);
         fclose($fp);
         //open and read XML file
         $xml2 = new XMLReader();
         $xml2->open($xml_file);
         $domdoc = new DOMDocument();
         $ids_do_usuniecia_dodania = array();
         $all_agents_ids = array();
         $all_dept_ids = array();
         $blokuj_agentow = true;
         $blokuj_oddzialy = true;
         $time_end4 = microtime_float();
         $time = $time_end4 - $time_end3;
         if ($this->_DEBUG) {
             echo "Load XML execution time: {$time} seconds<br>";
         }
         $xml2->read();
         while ($xml2->name) {
             //Departments
             if ($xml2->name == "Oddzial") {
                 if ($blokuj_oddzialy) {
                     $blokuj_oddzialy = false;
                 }
                 $node = simplexml_import_dom($domdoc->importNode($xml2->expand(), true));
                 if (count($node) > 0) {
                     $log .= "oddzial=" . $node["ID"] . " - " . $node->Nazwa . "\n";
                     $dep = new Department($node["ID"], $node->Nazwa, $node->Nazwa2, $node->Adres, $node->Miasto, $node->Kod, $node->Nip, $node->Wojewodztwo, $node->Www, $node->Telefon, $node->Email, $node->Fax, $node->Uwagi, $node->Naglowek, $node->Stopka, $node->PlikLogo, $node->ZdjecieWWW, $node->Subdomena, $node->Firma);
                     array_push($all_dept_ids, (int) $node["ID"]);
                     Departments::AddEditDepartment($dep);
                     echo DataBase::GetDbInstance()->LastError();
                 }
             }
             //Agents
             if ($xml2->name == "Agent") {
                 if ($blokuj_agentow) {
                     $blokuj_agentow = false;
                 }
                 $node = simplexml_import_dom($domdoc->importNode($xml2->expand(), true));
                 if (count($node) > 0) {
                     $log .= "agent=" . $node["ID"] . " - " . $node->Nazwa . "\n";
                     $kod_pracownika = 0;
                     if (is_numeric($node->KodPracownika)) {
                         $kod_pracownika = (int) $node->KodPracownika;
                     }
                     $agent = new Agent($node["ID"], $node->Nazwa, $node->Telefon, $node->Komorka, $node->Email, $node->Oddzial, $node->JabberLogin, $node->NrLicencji, $node->OdpowiedzialnyNazwa, $node->OdpowiedzialnyNrLicencji, $node->Komunikator, $node->PlikFoto, $kod_pracownika, $node->DzialFunkcja);
                     array_push($all_agents_ids, (int) $node["ID"]);
                     Agents::AddEditAgent($agent);
                     echo DataBase::GetDbInstance()->LastError();
                 }
             }
             //Offers
             if ($xml2->name == "Oferty") {
                 $node = simplexml_import_dom($domdoc->importNode($xml2->expand(), true));
                 if (count($node) > 0) {
                     foreach ($node->children() as $nodeOferta) {
                         $count_arr["suma"]++;
                         $log .= "oferta=" . $nodeOferta["ID"] . " - " . $nodeOferta["Symbol"] . "\n";
                         //read major properties
                         $rent = strtolower($nodeOferta["Wynajem"]) == "true" ? 1 : 0;
                         $orig = strtolower($nodeOferta["Pierwotny"]) == "true" ? 1 : 0;
                         $przedmiot = $nodeOferta["Przedmiot"];
                         if ($przedmiot == "Biurowiec") {
                             $przedmiot = "Obiekt";
                         }
                         $first_page = strtolower($nodeOferta->PierwszaStrona) == "true" ? 1 : 0;
                         $zamiana = $nodeOferta->Zamiana ? 1 : 0;
                         $loc_as_commune = strtolower($nodeOferta["LokalizacjaJakoGmina"]) == "true" ? 1 : 0;
                         $has_swfs = 0;
                         $has_movs = 0;
                         $has_maps = 0;
                         $has_projs = 0;
                         $has_pans = 0;
                         $has_photos = 0;
                         if (isset($nodeOferta->Zdjecia)) {
                             foreach ($nodeOferta->Zdjecia->children() as $zd) {
                                 switch ($zd->typ) {
                                     case "Zdjecie":
                                         $has_photos = 1;
                                         break;
                                     case "Rzut":
                                         $has_projs = 1;
                                         break;
                                     case "Mapa":
                                         $has_maps = 1;
                                         break;
                                     case "SWF":
                                         $has_swfs = 1;
                                         break;
                                     case "Filmy":
                                         $has_movs = 1;
                                         break;
                                     case "Panorama":
                                         $has_pans = 1;
                                         break;
                                 }
                             }
                         }
                         $attr_arr = array("Link" => null, "ZeroProwizji" => 0);
                         if (isset($nodeOferta->Atrybuty)) {
                             foreach ($nodeOferta->Atrybuty->children() as $at) {
                                 if ($at["opis"] == "Link") {
                                     $attr_arr["Link"] = (string) $at;
                                 }
                                 if ($at["opis"] == "ZeroProwizji") {
                                     $attr_arr["ZeroProwizji"] = (string) $at;
                                 }
                             }
                         }
                         $offer = new Offer($nodeOferta["Jezyk"], CheckNumeric($nodeOferta["ID"]), $nodeOferta["Status"], $przedmiot, $rent, $nodeOferta["Symbol"], $orig, $nodeOferta["Wojewodztwo"], $nodeOferta["Powiat"], $nodeOferta["Lokalizacja"], $nodeOferta["Dzielnica"], $nodeOferta["Rejon"], $nodeOferta["Ulica"], $nodeOferta["Pietro"], CheckNumeric($nodeOferta["Cena"]), CheckNumeric($nodeOferta["CenaM2"]), $nodeOferta["IloscPokoi"], CheckNumeric($nodeOferta["PowierzchniaCalkowita"]), CheckNumeric($nodeOferta["MapSzerokoscGeogr"]), CheckNumeric($nodeOferta["MapDlugoscGeogr"]), $nodeOferta["TechnologiaBudowlana"], $nodeOferta["MaterialKonstrukcyjny"], $nodeOferta["StanWybudowania"], $nodeOferta["RodzajBudynku"], $nodeOferta["Agent"], $nodeOferta["DataWprowadzenia"], $nodeOferta["DataWprowadzenia"], 0, empty_to_null($nodeOferta->Kraj), $nodeOferta->IloscPieter, $nodeOferta->RokBudowy, empty_to_null($nodeOferta->RodzajDomu), $first_page, empty_to_null($nodeOferta->RodzajObiektu), empty_to_null($nodeOferta->SposobPrzyjecia), $nodeOferta->IloscOdslonWWW, null, empty_to_null($nodeOferta->StatusWlasnosci), empty_to_null($nodeOferta->UmeblowanieLista), $nodeOferta->PowierzchniaDzialki, $zamiana, empty_to_null(html_entity_decode($nodeOferta->UwagiOpis)), empty_to_null(html_entity_decode($nodeOferta->UwagiNieruchomosc)), empty_to_null($attr_arr["Link"]), $attr_arr["ZeroProwizji"], $nodeOferta["DataWaznosci"], $has_swfs, $has_movs, $has_photos, $has_pans, $has_maps, $has_projs, $loc_as_commune);
                         $photosNode = null;
                         $roomsNode = null;
                         $modDate = null;
                         $attributesNode = null;
                         $ts = microtime_float();
                         //properties that are in offers directly
                         $pomin = OffersHelper::$props_arr;
                         //atributes that are in offers directly
                         $pomin_attr = array("Link", "ZeroProwizji");
                         //read other properties
                         foreach ($nodeOferta->children() as $propNode) {
                             $pname = $propNode->getName();
                             if ($pname == "StanPrawnyDom" || $pname == "StanPrawnyGruntu" || $pname == "StanPrawnyLokal" || $pname == "StanPrawnyLokalLista") {
                                 $offer->setStanPrawny($propNode);
                             }
                             if (in_array($pname, $pomin) === false) {
                                 if ($pname == "Zdjecia") {
                                     $photosNode = $propNode;
                                 } else {
                                     if ($pname == "DataAktualizacji") {
                                         $modDate = $propNode;
                                     } else {
                                         if ($pname == "Pomieszczenia") {
                                             $roomsNode = $propNode;
                                         } else {
                                             if ($pname == "Atrybuty") {
                                                 $attributesNode = $propNode;
                                                 $set = array();
                                                 foreach ($propNode->children() as $listNode) {
                                                     if (array_search($listNode['opis'], $pomin_attr) === false) {
                                                         $set[count($set)] = $listNode['opis'] . "#|#" . $listNode;
                                                     }
                                                 }
                                                 $offer->__set($pname, $set);
                                             } else {
                                                 if ($propNode['iset'] == true) {
                                                     $set = array();
                                                     foreach ($propNode->children() as $listNode) {
                                                         $set[count($set)] = $listNode;
                                                     }
                                                     $offer->__set($pname, $set);
                                                 } else {
                                                     $offer->__set($pname, $propNode);
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         if ($nodeOferta['NrLokalu']) {
                             $offer->__set('NrLokalu', $nodeOferta['NrLokalu']);
                         }
                         $times["read_props"] += microtime_float() - $ts;
                         $ts = microtime_float();
                         //save offer object to database
                         if ($modDate != null) {
                             $offer->SetModificationDate($modDate);
                         }
                         $ret = Offers::AddEditOffer($offer);
                         if ($ret == "A") {
                             $count_arr["dodane"]++;
                         } else {
                             if ($ret == "E") {
                                 $count_arr["zmodyfikowane"]++;
                             }
                         }
                         echo DataBase::GetDbInstance()->LastError();
                         $times["save"] += microtime_float() - $ts;
                         $ts = microtime_float();
                         //delete unuse properties from offer
                         $addedProperties = array();
                         foreach ($nodeOferta->children() as $propNode) {
                             $pname = $propNode->getName();
                             if ($pname == "StanPrawnyDom" || $pname == "StanPrawnyGruntu" || $pname == "StanPrawnyLokal" || $pname == "StanPrawnyLokalLista") {
                                 $pname = "StanPrawny";
                             }
                             if (in_array($pname, $pomin) === false) {
                                 if ($pname != "Zdjecia" && $pname != "Pomieszczenia" && $pname != "Atrybuty" && $pname != "DataAktualizacji" || $propNode['iset'] == true) {
                                     $prop = Properties::GetPropertyName($pname);
                                     if ($prop != null) {
                                         $addedProperties[count($addedProperties)] = $prop->GetID();
                                     }
                                 }
                             }
                         }
                         if ($nodeOferta['NrLokalu']) {
                             $addedProperties[] = Properties::GetPropertyName('NrLokalu')->GetID();
                         }
                         if ($attributesNode != null) {
                             $addedProperties[] = Properties::GetPropertyName($attributesNode->getName())->GetID();
                         }
                         Offers::DeleteUnUseProperties($offer->GetId(), $offer->GetIdLng(), $addedProperties);
                         $times["del_props"] += microtime_float() - $ts;
                         $ts = microtime_float();
                         //photos
                         $addedPhotos = array();
                         if ($photosNode != null) {
                             foreach ($photosNode->children() as $photoNode) {
                                 $intro = strtolower($photoNode->intro) == "true" ? 1 : 0;
                                 $photo = new OfferPhoto($photoNode['ID'], $offer->GetId(), null, $photoNode->plik, $photoNode->opis, $photoNode->lp, $photoNode->typ, $intro, $photoNode['fotoID'], (string) $photoNode->LinkFilmYouTube, (string) $photoNode->LinkMiniaturkaYouTube);
                                 OfferPhotos::AddEditPhoto($photo);
                                 echo DataBase::GetDbInstance()->LastError();
                                 $addedPhotos[count($addedPhotos)] = $photo->GetId();
                             }
                         }
                         OfferPhotos::DeleteUnUsePhotos($offer->GetId(), $addedPhotos, 0);
                         $times["photos"] += microtime_float() - $ts;
                         $ts = microtime_float();
                         //rooms
                         if ($roomsNode != null) {
                             if ($prevOfferId != $offer->GetId() . "") {
                                 OfferRooms::DeleteRooms($offer->GetId(), null);
                             }
                             $times["rooms_del"] += microtime_float() - $ts;
                             foreach ($roomsNode->children() as $roomNode) {
                                 $room = new OfferRoom(0, $offer->GetId(), $offer->GetIdLng(), $roomNode['Rodzaj'], $roomNode->Lp, $roomNode->Powierzchnia, $roomNode->Poziom, $roomNode->Typ, CheckNumeric($roomNode->Wysokosc), $roomNode->RodzajKuchni, CheckNumeric($roomNode->Ilosc), $roomNode->Glazura, $roomNode->WidokZOkna, $roomNode->Opis, $roomNode->StanPodlogi, $roomNode->RodzajPomieszczenia);
                                 //sets of properties
                                 $_floors = array();
                                 if ($roomNode->Podlogi) {
                                     foreach ($roomNode->Podlogi->children() as $listNode) {
                                         $_floors[count($_floors)] = $listNode;
                                     }
                                 }
                                 $room->SetFloors($_floors);
                                 $_windowsExhibition = array();
                                 if ($roomNode->WystawaOkien) {
                                     foreach ($roomNode->WystawaOkien->children() as $listNode) {
                                         $_windowsExhibition[count($_windowsExhibition)] = $listNode;
                                     }
                                 }
                                 $room->SetWindowsExhibition($_windowsExhibition);
                                 $_walls = array();
                                 if ($roomNode->Sciany) {
                                     foreach ($roomNode->Sciany->children() as $listNode) {
                                         $_walls[count($_walls)] = $listNode;
                                     }
                                 }
                                 $room->SetWalls($_walls);
                                 $_equipment = array();
                                 if ($roomNode->Wyposazenie) {
                                     foreach ($roomNode->Wyposazenie->children() as $listNode) {
                                         $_equipment[count($_equipment)] = $listNode;
                                     }
                                 }
                                 $room->SetEquipment($_equipment);
                                 OfferRooms::AddRoom($room);
                                 echo DataBase::GetDbInstance()->LastError();
                             }
                         }
                         $times["rooms"] += microtime_float() - $ts;
                         $prevOfferId = $offer->GetId() . "";
                     }
                 }
             }
             //Deleted offers
             if ($xml2->name == "Usuniete") {
                 $node = simplexml_import_dom($domdoc->importNode($xml2->expand(), true));
                 foreach ($node->children() as $doUsuniecia) {
                     array_push($ids_do_usuniecia_dodania, (int) $doUsuniecia["ID"]);
                 }
             }
             $xml2->read();
         }
         //Delete redundant departments
         if (!$blokuj_oddzialy) {
             Departments::DeleteRedundantDepartments($all_dept_ids);
         }
         //Delete redundant agents
         if (!$blokuj_agentow) {
             Agents::DeleteRedundantAgents($all_agents_ids);
         }
         $ts = microtime_float();
         $time_end5 = microtime_float();
         $time = $time_end5 - $time_end4;
         $times["del_offers"] += microtime_float() - $ts;
         if ($this->_DEBUG) {
             echo "Saving data to db execution time: {$time} seconds<br>";
             var_dump($times);
         }
         $xml2->close();
         Errors::LogSynchroStep('WebServiceVirgo - GetOffersPartial() done');
         return $ids_do_usuniecia_dodania;
     } catch (Exception $ex) {
         Errors::LogError("WebServiceVirgo:GetOffers", $ex->getMessage() . "; " . $ex->getTraceAsString());
         return 0;
     }
 }
Exemple #30
0
 /**
  * Verifies offers
  * @return int[]
  */
 public static function VerifyOffers()
 {
     $list = array();
     $xml = new XMLReader();
     $domdoc = new DOMDocument();
     $xml->open(WebServiceVirgo::TMP_XML_OFELIST_FILE);
     Errors::LogSynchroStep('Offers - VerifyOffers() - step 1');
     $xml->read();
     while ($xml->name) {
         if ($xml->name == 'Oferta') {
             $node = simplexml_import_dom($domdoc->importNode($xml->expand(), true));
             $list[] = (int) $node["ID"];
         }
         $xml->read();
     }
     Errors::LogSynchroStep('Offers - VerifyOffers() - step 2');
     $db = DataBase::GetDbInstance();
     $query = "SELECT DISTINCT(id) FROM #S#offers o";
     $result = $db->ExecuteQuery($query);
     $ofrs = new Offers();
     //delete wrong offers
     $localOffs = array();
     $flippedList = array_flip($list);
     while ($row = $db->FetchArray($result)) {
         if (!isset($flippedList[$row[0]])) {
             $ofrs->DeleteOffer($row[0]);
         } else {
             $localOffs[] = $row[0];
         }
     }
     //detect missing offers
     $braki = array();
     $flippedLocalOffs = array_flip($localOffs);
     foreach ($list as $id) {
         if (!isset($flippedLocalOffs[$id])) {
             $braki[] = $id;
         }
     }
     Errors::LogSynchroStep('Offers - VerifyOffers() - step 3');
     return $braki;
 }