Пример #1
0
 protected function _writeXml()
 {
     // Write app/etc/modules/ file
     $templateFilepath = __DIR__ . '/template/Migrated_FromCore.xml';
     $moduleRegistrationDir = \Mage::getBaseDir('app') . '/etc/modules';
     $moduleRegistrationFilepath = $moduleRegistrationDir . '/Migrated_FromCore.xml';
     copy($templateFilepath, $moduleRegistrationFilepath);
     echo "Writing {$moduleRegistrationFilepath}\r\n";
     // Write etc/config.xml
     $directory = \Mage::getBaseDir('app') . '/code/local/Migrated/FromCore/etc';
     $filePath = $directory . "/config.xml";
     echo "Writing {$filePath}\r\n";
     mkdir($directory, 0755, true);
     $this->_configXml->asXML($filePath);
 }
Пример #2
0
 /**
  * arrayToXml
  *
  * @param  string $array        Array to convert to xml    
  * @param  string $rootNodeName Name of the root node
  * @param  string $xml          SimpleXmlElement
  * @return string $asXml        String of xml built from array
  */
 public static function arrayToXml($array, $rootNodeName = 'data', $xml = null)
 {
     if ($xml === null) {
         $xml = new SimpleXmlElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><{$rootNodeName}/>");
     }
     foreach ($array as $key => $value) {
         $key = preg_replace('/[^a-z]/i', '', $key);
         if (is_array($value) && !empty($value)) {
             $node = $xml->addChild($key);
             foreach ($value as $k => $v) {
                 if (is_numeric($v)) {
                     unset($value[$k]);
                     $node->addAttribute($k, $v);
                 }
             }
             self::arrayToXml($value, $rootNodeName, $node);
         } else {
             if (is_int($key)) {
                 $xml->addChild($value, 'true');
             } else {
                 $value = htmlentities($value);
                 $xml->addChild($key, $value);
             }
         }
     }
     return $xml->asXML();
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function export(array $data)
 {
     $countriesElement = new \SimpleXmlElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><countries/>");
     foreach ($data as $iso => $name) {
         $countryElement = $countriesElement->addChild('country');
         $countryElement->addChild('iso', $iso);
         $countryElement->addChild('name', $countryElement->ownerDocument->createCDATASection($name));
     }
     return $countriesElement->asXML();
 }
 /**
  * @return void
  */
 public function afterFeature()
 {
     $this->testsuiteTimer->stop();
     $testsuite = $this->currentTestsuite;
     $testsuite->addAttribute('tests', array_sum($this->testsuiteStats));
     $testsuite->addAttribute('failures', $this->testsuiteStats[TestResult::FAILED]);
     $testsuite->addAttribute('skipped', $this->testsuiteStats[TestResult::SKIPPED]);
     $testsuite->addAttribute('errors', $this->testsuiteStats[TestResult::PENDING]);
     $testsuite->addAttribute('time', \round($this->testsuiteTimer->getTime(), 3));
     $this->printer->write($this->xml->asXML());
 }
 public function send($method, $path = null, $data = array(), array $options = array())
 {
     $defaults = array('headers' => array('User-Agent' => 'Lava Surfboard'));
     $xml = new \SimpleXmlElement('<request method="' . $path . '"></request>');
     foreach ($data as $key => $val) {
         if ($val != null) {
             $xml->{$key} = $val;
         }
     }
     $xmlString = $xml->asXML();
     $data = str_replace("<?xml version=\"1.0\"?>\n", '<!--?xml version="1.0" encoding="utf-8"?-->', $xmlString);
     $path = '/api/2.1/xml-in';
     $response = parent::send($method, $path, $data, $options + $defaults);
     return new \SimpleXmlElement($response);
 }
Пример #6
0
 /**
  * arrayToXml
  *
  * @param  string $array        Array to convert to xml    
  * @param  string $rootNodeName Name of the root node
  * @param  string $xml          SimpleXmlElement
  * @return string $asXml        String of xml built from array
  */
 public function arrayToXml($array, $rootNodeName = 'data', $xml = null)
 {
     if ($xml === null) {
         $xml = new SimpleXmlElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><{$rootNodeName}/>");
     }
     foreach ($array as $key => $value) {
         if (is_array($value)) {
             $node = $xml->addChild($key);
             $this->arrayToXml($value, $rootNodeName, $node);
         } else {
             $value = htmlentities($value);
             $xml->addChild($key, $value);
         }
     }
     return $xml->asXML();
 }
 /**
  * Save given favourite site to xml file.
  */
 public static function saveFavouriteSites($favId, $favType, $favName, $favLink, $configFilePath)
 {
     $favourites = FavouriteSitesUtil::getFavouriteSites($configFilePath);
     if ($favType == "mixed") {
         $favType = "movie";
     }
     $favourites[$favType] = array($favId, $favName, $favLink);
     //Save to xml
     $simpleXml = new SimpleXmlElement('<?xml version="1.0" encoding="UTF-8"?><favourite></favourite>');
     foreach ($favourites as $type => $favourite) {
         $element = $simpleXml->addChild("website", $favourite[2]);
         $element->addAttribute("id", $favourite[0]);
         $element->addAttribute("name", $favourite[1]);
         $element->addAttribute("type", $type);
     }
     $fp = fopen($configFilePath, 'w');
     fwrite($fp, $simpleXml->asXML());
     fclose($fp);
 }
Пример #8
0
<?php

$xml = new SimpleXmlElement(file_get_contents('messages/en/core.xml'));
$data = array();
foreach ($xml->entry as $entry) {
    $data[(string) $entry['id']] = (string) $entry;
}
$keys = array_keys($data);
sort($keys);
$newXml = new SimpleXmlElement('<category id="core"></category>');
foreach ($keys as $key) {
    $entry = $newXml->addChild("entry", $data[$key]);
    $entry->addAttribute('id', $key);
}
$doc = new DOMDocument('1.0');
$doc->preserveWhiteSpace = false;
$doc->loadXML($newXml->asXML());
$doc->formatOutput = true;
file_put_contents('messages/en/core.xml', str_replace('  <entry', '	<entry', $doc->saveXML()));
function uploadChanges($orderUuid, $courierUuid, $itineraryListNumber)
{
    $itineraryListNumberUuid = "83b401b2-7643-11e4-90a2-8eca001235b3";
    $employeeValueUuid = "83b40086-7643-11e4-90a2-8eca001235b2";
    $oneOrderData = getOrderXmlFromMoysklad($orderUuid);
    try {
        $oneOrderXml = new SimpleXmlElement($oneOrderData);
    } catch (Exception $e) {
        echo "Возникла ошибка при загрузке данных о заказах покупателей с Moysklad. Пожалуйста, попробуйте еще раз.";
        return;
    }
    $attributeExistsListNumber = false;
    $attributeExistsEmployee = false;
    $date = new DateTime("now", new DateTimeZone("Europe/Moscow"));
    $date = $date->format('Y-m-d\\TH:i:s.uP');
    foreach ($oneOrderXml->attribute as $attribute) {
        if ($attribute["metadataUuid"] == $itineraryListNumberUuid) {
            $attribute["longValue"] = $itineraryListNumber;
            $attributeExistsListNumber = true;
        }
        if ($attribute["metadataUuid"] == $employeeValueUuid) {
            $attribute["employeeValueUuid"] = $courierUuid;
            $attributeExistsEmployee = true;
        }
    }
    if (!$attributeExistsListNumber) {
        $attribute = $oneOrderXml->addChild("attribute");
        $attribute->addAttribute("operationUuid", $orderUuid);
        $attribute->addAttribute("metadataUuid", $itineraryListNumberUuid);
        $attribute->addAttribute("longValue", $itineraryListNumber);
        $attribute->addAttribute("updated", $date);
        $attribute->addAttribute("updatedBy", $GLOBALS["login"]);
        $attribute->addAttribute("readMode", 'SELF');
        $attribute->addAttribute("changeMode", 'SELF');
    }
    if (!$attributeExistsEmployee) {
        $attribute = $oneOrderXml->addChild("attribute");
        $attribute->addAttribute("operationUuid", $orderUuid);
        $attribute->addAttribute("metadataUuid", $employeeValueUuid);
        $attribute->addAttribute("employeeValueUuid", $courierUuid);
        $attribute->addAttribute("updated", $date);
        $attribute->addAttribute("updatedBy", $GLOBALS["login"]);
        $attribute->addAttribute("readMode", 'SELF');
        $attribute->addAttribute("changeMode", 'SELF');
    }
    $result = $oneOrderXml->asXML();
    putOrderXmlToMoysklad($result);
}
Пример #10
0
<?php

$filename = "blog.xml";
if (file_exists($filename)) {
    $rawBlog = file_get_contents($filename);
} else {
    $rawBlog = <<<EOT
<?xml version="1.0" encoding="utf-8" ?>
<blog>
<title>YouCube</title>
<author>Ruby</author>
<entries><entries>
</blog>
EOT;
}
$xml = new SimpleXmlElement($rawBlog);
$entry = $xml->entries->addChild("entry");
$entry->addChild("date", $_REQUEST['date']);
$entry->addChild("body", stripslashes($_REQUEST["body"]));
if (empty($_REQUEST['image'])) {
    $entry->addChild("image", $_REQUEST['image']);
}
$file = fopen($filename, 'w');
fwrite($file, $xml->asXML());
fclose($file);
 private function createEmptyScrapers()
 {
     $simpleXml = new SimpleXmlElement('<?xml version="1.0" encoding="UTF-8"?><scrapers></scrapers>');
     $fp = fopen($this->scrapersFilePath, 'w');
     fwrite($fp, utf8_encode(html_entity_decode($simpleXml->asXML())));
     fclose($fp);
 }
Пример #12
0
 /**
  * Convert array to XML.
  *
  * @param array $array      $array to convert.
  * @param string            $root  Root node name.
  * @param \SimpleXMLElement $xml   Object for recursivity.
  *
  * @return string
  */
 public static function toXml($array, $root = 'root', $xml = null)
 {
     if (is_null($xml)) {
         $root = sprintf('<%s />', $root);
         $xml = new \SimpleXmlElement($root);
     }
     foreach ($array as $key => $value) {
         $key = is_numeric($key) ? 'row' : $key;
         $key = preg_replace('/[^a-z]/i', '', $key);
         if (is_array($value)) {
             $node = $xml->addChild($key);
             self::toXml($value, $root, $node);
         } else {
             $xml->addChild(strtolower($key), $value);
         }
     }
     return $xml->asXML();
 }
 /**
  * Based on image specification, write a very simple SVG file to disk.
  * Ignores the background spec because transparency is cool. :)
  *
  * @param array $spec Spec describing background and shapes to draw
  * @param string $format File format to write (which is obviously always svg here)
  * @param string $filename Filename to write to
  *
  * @throws Exception
  */
 public function writeSvg($spec, $format, $filename)
 {
     $svg = new SimpleXmlElement('<svg/>');
     $svg->addAttribute('xmlns', 'http://www.w3.org/2000/svg');
     $svg->addAttribute('version', '1.1');
     $svg->addAttribute('width', $spec['width']);
     $svg->addAttribute('height', $spec['height']);
     $g = $svg->addChild('g');
     foreach ($spec['draws'] as $drawSpec) {
         $shape = $g->addChild('polygon');
         $shape->addAttribute('fill', $drawSpec['fill']);
         $shape->addAttribute('points', self::shapePointsToString($drawSpec['shape']));
     }
     if (!($fh = fopen($filename, 'w'))) {
         throw new Exception("couldn't open {$filename} for writing");
     }
     fwrite($fh, $svg->asXML());
     if (!fclose($fh)) {
         throw new Exception("couldn't close {$filename}");
     }
 }
Пример #14
0
					<element id="' . $productId . '" type="sprd:product" xlink:href="http://api.spreadshirt.de/api/v1/shops/1070242/products/' . $productId . '">
					<properties>
					<property key="appearance">' . $appearanceId . '</property>
					<property key="size">' . $sizeId . '</property>
					</properties>
					</element>

					</basketItem>');
    $header = array();
    $header[] = createSprdAuthHeader("PUT", $basketItemsURL);
    $header[] = "Content-Type: application/xml";
    $ch = curl_init($basketItemsURL);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $basketItem->asXML());
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    $result = curl_exec($ch);
    curl_close($ch);
    echo json_encode("done");
    //    die();
}
if ($action == "read") {
    $basketURL = "api.spreadshirt." . $tld . "/api/v1/baskets/" . $basketId;
    $header = array();
    $header[] = createSprdAuthHeader("GET", $basketURL);
    $header[] = "Content-Type: application/xml";
    $ch = curl_init($basketURL);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
Пример #15
0
             $report_xml = new SimpleXmlElement($xml_base);
             if (simplexml_load_string($row_spiel['bericht'])) {
                 $report_xml = new SimpleXmlElement($row_spiel['bericht']);
                 if (isset($report_xml->aufstellung->spieler)) {
                     //foreach($report_xml->aufstellung->spieler as $spieler_aufstellung){
                     $i = 0;
                     while (isset($report_xml->aufstellung->spieler[$i])) {
                         $spieler_aufstellung = $report_xml->aufstellung->spieler[$i];
                         if ($spieler_aufstellung['spieler_id'] == $spieler_id) {
                             if (!isset($spieler_aufstellung['confirmed'])) {
                                 $spieler_aufstellung->addAttribute('confirmed', 'true');
                             } else {
                                 $spieler_aufstellung['confirmed'] = "true";
                             }
                             //echo $spieler_aufstellung['confirmed'];
                             $bericht_xml = $report_xml->asXML();
                             $sql_update_bericht = "UPDATE `ergebnisse_{$_POST['liga_id']}` SET `bericht` = '{$bericht_xml}' WHERE `id` = {$_POST['spiel_id']}";
                             mysql_query('SET character_set_client = utf8');
                             mysql_query('SET character_set_results = utf8');
                             mysql_query('SET character_set_connection = utf8');
                             $result_berichte = mysql_query($sql_update_bericht) or die(mysql_error());
                             break;
                         }
                         $i++;
                     }
                 }
                 //print_r($report_xml);
             }
         }
     }
 }
Пример #16
0
                $Veranstaltung = "SELECT *\n\t\t\t\t\t    FROM `Veranstaltungen`\n\t\t\t\t\t    WHERE `id` = '{$_GET['event_id']}'\n\t\t\t\t\t    LIMIT 1";
                mysql_query('SET character_set_client = utf8');
                mysql_query('SET character_set_results = utf8');
                mysql_query('SET character_set_connection = utf8');
                $result_Veranstaltung = mysql_query($Veranstaltung) or die(mysql_error());
                if (mysql_num_rows($result_Veranstaltung)) {
                    $i = 1;
                    if ($row_Veranstaltung = mysql_fetch_assoc($result_Veranstaltung)) {
                        $Termine_xml = new SimpleXmlElement($row_Veranstaltung['Termine']);
                        $increment_terms = $Termine_xml['count'] + 1;
                        $Termine_xml->addChild('termin');
                        $Termine_xml->termin[count($Termine_xml->termin) - 1]->addChild('termin_id', $increment_terms);
                        $Termine_xml->termin[count($Termine_xml->termin) - 1]->addChild('datetime', $DateTime);
                        $Termine_xml->termin[count($Termine_xml->termin) - 1]->addChild('teilnehmer_root');
                        $Termine_xml['count'] = $increment_terms;
                        $Termine_as_xml = $Termine_xml->asXML();
                        $update_termine = "UPDATE `Veranstaltungen` SET `Termine` = '{$Termine_as_xml}'\n\t\t\t\t\t\t\t  WHERE `id` = '{$_GET['event_id']}'";
                        mysql_query('SET character_set_client = utf8');
                        mysql_query('SET character_set_results = utf8');
                        mysql_query('SET character_set_connection = utf8');
                        $result_update_termine = mysql_query($update_termine) or die(mysql_error());
                        echo "<p style=\"color: #0fc90f;\">Termin wurde erfolgreich eingetragen.</p>";
                    }
                }
            }
        }
        if (isset($_GET['event_id'])) {
            echo <<<QQQQ
<form action="modules/insert_term.php?action=submit&event_id={$_GET['event_id']}" method="post" accept-charset="UTF-8" >
<div style="float:left">
<span style="float:left; margin-right:5px;">Datum: <input name="datepicker" id="terminpicker" type="text" /></span>
Пример #17
0
    $result = $mdb->getCollection('oneWeek')->distinct("involved.{$type}ID");
    $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"/>');
    $count = 0;
    foreach ($result as $id) {
        ++$count;
        if ($count > 50000) {
            break;
        }
        $url = $xml->addChild('url');
        $loc = $url->addChild('loc', "https://{$baseAddr}/{$type}/{$id}/");
    }
    file_put_contents("{$siteMapsDir}/{$type}s.xml", $xml->asXML());
    $locations[] = "https://{$baseAddr}/sitemaps/{$type}s.xml";
}
$killIDs = $mdb->find('oneWeek', [], ['killID' => -1], 50000);
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"/>');
foreach ($killIDs as $row) {
    $killID = $row['killID'];
    $url = $xml->addChild('url');
    $loc = $url->addChild('loc', "https://{$baseAddr}/kill/{$killID}/");
}
file_put_contents("{$siteMapsDir}/kills.xml", $xml->asXML());
$locations[] = "https://{$baseAddr}/sitemaps/kills.xml";
$xml = new SimpleXmlElement('<?xml version="1.0" encoding="UTF-8"?><sitemapindex xmlns="http://www.google.com/schemas/sitemap/0.84"/>');
foreach ($locations as $location) {
    $sitemap = $xml->addChild('sitemap');
    $sitemap->addChild('loc', $location);
}
file_put_contents("{$siteMapsDir}/sitemaps.xml", $xml->asXML());
file_get_contents("http://www.google.com/webmasters/sitemaps/ping?sitemap=https://{$baseAddr}/sitemaps/sitemaps.xml");
$redis->setex($key, 86400, true);
 public function render()
 {
     $tag = "FormXMLDrafter: render()";
     Log::debug("{$tag}");
     // convenience pointers
     $id = $this->id;
     $entityId = $this->entityId;
     $entityBP = $this->entityBlueprint;
     $formBP = $this->formBlueprint;
     $fields = $this->formFields;
     $params = $this->params;
     // encode params for inclusion in html
     $encodedParams = ParamEncoder::encode($params);
     // init xml respose
     $xml = new SimpleXmlElement("<bpXmlDraftRendering></bpXmlDraftRendering>");
     $rendering = $xml;
     $rendering->addAttribute("id", $id);
     $rendering->addAttribute("type", "form");
     $rendering->addAttribute("entitySignature", $entityBP->signature());
     if ($formBP) {
         $rendering->addAttribute("formSignature", $formBP->signature());
     }
     $rendering->addAttribute("entityId", $entityId);
     $rendering->addAttribute("params", $encodedParams);
     foreach ($fields as $f) {
         // collect data for this field
         $key = $f->getKey();
         $entityField = $entityBP->get($key);
         // add new <field> to xml response
         $fieldPtr = $rendering->addChild("field");
         $fieldPtr->addAttribute("key", $key);
         /*
         // add details for this <field>
         */
         // displayName
         $fieldPtr->addChild("displayName", $f->displayName);
         // dataType
         $fieldPtr->addChild("dataType", $f->dataType);
         // value
         // replace "&" with "&amp;" to prevent xml errors
         $f->value = str_replace("&", "&amp;", $f->value);
         switch ($f->dataType) {
             case "string":
                 if ($entityField->getEncType() != "plain") {
                     $fieldPtr->addChild("value", "********");
                 } else {
                     $fieldPtr->addChild("value", $f->value);
                 }
                 break;
             case "binary":
                 $binaryValue = !empty($f->value) ? "/blueprints/binary/" . $entityBP->getKey() . "/" . $key . "/" . $entityId : "";
                 $binaryValuePtr = $fieldPtr->addChild("value", $binaryValue);
                 $binaryValuePtr->addAttribute("mimeType", $entityField->getMimeType());
                 break;
             default:
                 $fieldPtr->addChild("value", $f->value);
         }
         // foreign value options
         if ($entityField->isForeignKey()) {
             $enumPtr = $fieldPtr->addChild("foreignOptions");
             $foreignKey = substr($entityField->getForeignKey(), strpos($entityField->getForeignKey(), ".") + 1);
             $foreignValue = substr($entityField->getForeignValue(), strpos($entityField->getForeignValue(), ".") + 1);
             $foreignTable = substr($entityField->getForeignKey(), 0, strpos($entityField->getForeignKey(), "."));
             $query = "SELECT {$foreignKey}, {$foreignValue} FROM {$foreignTable} ORDER BY {$foreignValue}";
             // TODO: include WHERE cluase from formBlueprint->field:where
             $sql = new DatabaseQuery($query);
             try {
                 $sql->doQuery();
                 $num_rows = $sql->get_num_rows();
                 for ($i = 0; $i < $num_rows; $i++) {
                     $row = $sql->get_next_row();
                     $foreignKeyResult = $row->{$foreignKey};
                     $foreignValueResult = $row->{$foreignValue};
                     // clean
                     $foreignValueResult = htmlentities($foreignValueResult);
                     $optionPtr = $enumPtr->addChild("foreignOption", $foreignValueResult);
                     $optionPtr->addAttribute("key", $foreignKeyResult);
                 }
             } catch (Exception $e) {
                 Log::error("Caught Exception: " . $e->getMessage());
             }
         }
         // enumOptions
         if ($f->dataType == "enum") {
             $enumPtr = $fieldPtr->addChild("enumOptions");
             $enumOptions = $entityField->getEnumOptions();
             foreach ($enumOptions as $e) {
                 $enumPtr->addChild("enumOption", $e);
             }
         }
         // validation errors
         if ($f->err) {
             $errPtr = $fieldPtr->addChild("validationError");
             $errPtr->addChild("message", $f->err);
         }
     }
     // END: foreach($fields as $f)
     // Return XML string
     // NOTE: using DomDocument provides more flexibility (supressing empty tags, and removing xml declaration)
     // This xml cannot contain an xml declaration, because we plan on embedding it in another xml document
     $dom = new DomDocument();
     $dom->loadXML($xml->asXML());
     $node = $dom->getElementsByTagName("bpXmlDraftRendering")->item(0);
     return $dom->saveXML($node, LIBXML_NOEMPTYTAG);
 }
Пример #19
0
            } catch (Exception $e) {
                Log::error("* Caught Exception: " . $e->getMessage());
                $failures++;
                $xmlDelete->addChild("status", "error");
                $xmlDelete->addChild("message", "Caught Exception: " . htmlentities($e->getMessage()));
                $xmlDelete->addChild("html", "Error occurred during delete.");
            }
        }
        if ($failures == 0) {
            $xml->addChild("status", "success");
            $xml->addChild("message", count($entityId) . " records were removed");
            $xml->addChild("html", count($entityId) . " records were removed");
        } else {
            $xml->addChild("status", "error");
            $xml->addChild("message", "{$failures} of the requested records could not be removed");
            $xml->addChild("html", "{$failures} of the requested records could not be removed");
        }
    } catch (Exception $e) {
        Log::error("* Caught Exception: " . $e->getMessage());
        $xml->addChild("status", "error");
        $xml->addChild("message", "Caught Exception: " . htmlentities($e->getMessage()));
        $xml->addChild("html", "Error occurred preparing for delete.");
    }
} else {
    Log::error("* Missing required parameters");
    $xml->addChild("status", "error");
    $xml->addChild("message", "Missing required parameters.");
    $xml->addChild("html", "Missing required parameters.");
}
echo $xml->asXML();
Log::debug("END: /blueprints/conduit/delete.php" . "\n");
 public function render()
 {
     $tag = "FilterXMLDrafter: render()";
     Log::debug("{$tag}");
     // convenience pointers
     $id = $this->id;
     $entityBP = $this->entityBlueprint;
     $filterBP = $this->filterBlueprint;
     $filters = $this->filters;
     $params = $this->params;
     // encode params for inclusion in html
     $encodedParams = ParamEncoder::encode($params);
     // init xml respose
     $xml = new SimpleXmlElement("<bpXmlDraftRendering />");
     $rendering = $xml;
     $rendering->addAttribute("id", $id);
     $rendering->addAttribute("type", "filter");
     $rendering->addAttribute("entitySignature", $entityBP->signature());
     if ($filterBP) {
         $rendering->addAttribute("filterSignature", $filterBP->signature());
     }
     $rendering->addAttribute("params", $encodedParams);
     foreach ($filters as $f) {
         // collect data for this field
         $key = $f->getKey();
         $type = $f->type;
         // add new <field> to xml response
         $fieldPtr = $rendering->addChild("field");
         $fieldPtr->addAttribute("key", $key);
         $fieldPtr->addChild("type", $type);
         $fieldPtr->addChild("dataType", $f->dataType);
         $fieldPtr->addChild("displayName", $f->displayName);
         // enum options
         if ($f->dataType == "enum") {
             $enumPtr = $fieldPtr->addChild("enumOptions");
             $entityField = $entityBP->get($key);
             $enumOptions = $entityField->getEnumOptions();
             foreach ($enumOptions as $e) {
                 $enumPtr->addChild("option", $e);
             }
         }
         // value
         if (!$f->isForeignKey()) {
             if ($f->hasValue()) {
                 $filterValue = $f->value;
                 // an array
                 $valuePtr = $fieldPtr->addChild("value");
                 if (array_key_exists("equals", $filterValue)) {
                     $ptr = $valuePtr->addChild("equals", $filterValue["equals"]);
                     $ptr->addAttribute("name", $key . "_equals");
                 }
                 if (array_key_exists("like", $filterValue)) {
                     $ptr = $valuePtr->addChild("like", $filterValue["like"]);
                     $ptr->addAttribute("name", $key . "_like");
                 }
                 if (array_key_exists("min", $filterValue)) {
                     $ptr = $valuePtr->addChild("min", $filterValue["min"]);
                     $ptr->addAttribute("name", $key . "_min");
                 }
                 if (array_key_exists("max", $filterValue)) {
                     $ptr = $valuePtr->addChild("max", $filterValue["max"]);
                     $ptr->addAttribute("name", $key . "_max");
                 }
             }
         } else {
             $enumPtr = $fieldPtr->addChild("foreignOptions");
             $foreignKey = substr($f->foreignKey, strpos($f->foreignKey, ".") + 1);
             $foreignValue = substr($f->foreignValue, strpos($f->foreignValue, ".") + 1);
             $foreignTable = substr($f->foreignKey, 0, strpos($f->foreignKey, "."));
             $query = "SELECT {$foreignKey}, {$foreignValue} FROM {$foreignTable}";
             // TODO: include WHERE clause from filterBlueprint->field:where
             $sql = new DatabaseQuery($query);
             try {
                 $sql->doQuery();
                 $num_rows = $sql->get_num_rows();
                 for ($i = 0; $i < $num_rows; $i++) {
                     $row = $sql->get_next_row();
                     $foreignKeyResult = $row->{$foreignKey};
                     $foreignValueResult = $row->{$foreignValue};
                     $optionPtr = $enumPtr->addChild("option");
                     $optionPtr->addAttribute("key", $foreignKeyResult);
                     $optionPtr->addChild("value", $foreignValueResult);
                 }
             } catch (Exception $e) {
                 Log::error("Caught Exception: " . $e->getMessage());
             }
         }
     }
     // END: foreach($filters as $f)
     // Return XML string
     // NOTE: using DomDocument provides more flexibility (supressing empty tags, and removing xml declaration)
     // This xml cannot contain an xml declaration, because we plan on embedding it in another xml document
     $dom = new DomDocument();
     $dom->loadXML($xml->asXML());
     $node = $dom->getElementsByTagName("bpXmlDraftRendering")->item(0);
     return $dom->saveXML($node, LIBXML_NOEMPTYTAG);
 }
Пример #21
0
 public static function query($command, $options)
 {
     // Validate configuration
     if (!self::getClientId() or !self::getUserId()) {
         throw new \Exception('Gracenote has not been configured');
     }
     $http = new Client();
     $xml = new \SimpleXmlElement('<QUERIES></QUERIES>');
     $xml->addChild('LANG', self::getLanguage());
     $xml->addChild('COUNTRY', self::getCountry());
     // Add auth
     $auth = $xml->addChild('AUTH');
     $auth->addChild('CLIENT', self::getClientId());
     $auth->addChild('USER', self::getUserId());
     $query = $xml->addChild('QUERY');
     $query->addAttribute('CMD', $command);
     foreach ($options as $key => $val) {
         switch ($key) {
             case 'parameters':
                 foreach ($val as $parameter => $value) {
                     $param = $query->addChild('TEXT');
                     $param->{0} = $value;
                     $param->addAttribute('TYPE', $parameter);
                 }
                 break;
             case 'options':
                 foreach ($val as $parameter => $value) {
                     $option = $query->addChild('OPTION');
                     $param = $option->addChild('PARAMETER');
                     $param->{0} = $parameter;
                     $value = $option->addChild('VALUE');
                     $value->{0} = $value;
                 }
                 break;
             default:
                 $query->addAttribute($key, $val);
                 break;
         }
     }
     $http->setOptions(array('sslverifypeer' => false));
     $http->setUri(self::getApiUrl());
     $http->setMethod('POST');
     $http->getRequest()->setContent($xml->asXML());
     $response = $http->send();
     $responseXml = simplexml_load_string($response->getBody());
     return $responseXml;
 }
Пример #22
0
 public function saveSettings()
 {
     if (count($this->userSettings) > 0) {
         $xml = new SimpleXmlElement('<settings host="' . $this->host . '" user="******" />');
         foreach ($this->userSettings as $key => $values) {
             list($name, $scope) = $this->getSettingNameScope($key);
             foreach ($values as $object => $value) {
                 if (is_array($value)) {
                     $value = serialize($value);
                     $setSerialized = true;
                 } else {
                     $setSerialized = false;
                 }
                 $settingXml = $xml->addChild($name, $value);
                 if ($setSerialized) {
                     $settingXml['serialized'] = true;
                 }
                 if ($scope) {
                     $settingXml['scope'] = $scope;
                 }
                 if ($object) {
                     $settingXml['object'] = $object;
                 }
             }
         }
     } elseif (is_file($this->configPath . $this->host . '.' . $this->user . '.xml')) {
         unlink($this->configPath . $this->host . '.' . $this->user . '.xml');
     }
     $xml->asXML($this->configPath . $this->host . '.' . $this->user . '.xml');
 }
Пример #23
0
foreach ($types as $type) {
    $result = $mdb->getCollection('oneWeek')->distinct("involved.{$type}ID");
    $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"/>');
    $count = 0;
    foreach ($result as $id) {
        ++$count;
        if ($count > 50000) {
            break;
        }
        $url = $xml->addChild('url');
        $loc = $url->addChild('loc', "https://{$baseAddr}/{$type}/{$id}/");
    }
    file_put_contents("{$baseDir}/public/sitemaps/{$type}s.xml", $xml->asXML());
    $locations[] = "https://{$baseAddr}/sitemaps/{$type}s.xml";
}
$killIDs = $mdb->find('oneWeek', [], ['killID' => -1], 50000);
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"/>');
foreach ($killIDs as $row) {
    $killID = $row['killID'];
    $url = $xml->addChild('url');
    $loc = $url->addChild('loc', "https://{$baseAddr}/kill/{$killID}/");
}
file_put_contents("{$baseDir}/public/sitemaps/kills.xml", $xml->asXML());
$locations[] = "https://{$baseAddr}/sitemaps/kills.xml";
$xml = new SimpleXmlElement('<?xml version="1.0" encoding="UTF-8"?><sitemapindex xmlns="http://www.google.com/schemas/sitemap/0.84"/>');
foreach ($locations as $location) {
    $sitemap = $xml->addChild('sitemap');
    $sitemap->addChild('loc', $location);
}
file_put_contents("{$baseDir}/public/sitemaps/sitemaps.xml", $xml->asXML());
file_get_contents("http://www.google.com/webmasters/sitemaps/ping?sitemap=https://{$baseAddr}/sitemaps/sitemaps.xml");
Пример #24
0
 /**
  * arrayToXml
  *
  * @param  string $array        Array to convert to xml
  * @param  string $rootNodeName Name of the root node
  * @param  string $xml          SimpleXmlElement
  * @return string $asXml        String of xml built from array
  */
 public static function arrayToXml($array, $rootNodeName = 'data', $xml = null, $charset = null)
 {
     if ($xml === null) {
         $xml = new SimpleXmlElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><{$rootNodeName}/>");
     }
     foreach ($array as $key => $value) {
         $key = preg_replace('/[^a-z]/i', '', $key);
         if (is_array($value) && !empty($value)) {
             $node = $xml->addChild($key);
             foreach ($value as $k => $v) {
                 if (is_numeric($v)) {
                     unset($value[$k]);
                     $node->addAttribute($k, $v);
                 }
             }
             self::arrayToXml($value, $rootNodeName, $node, $charset);
         } else {
             if (is_int($key)) {
                 $xml->addChild($value, 'true');
             } else {
                 $charset = $charset ? $charset : 'utf-8';
                 if (strcasecmp($charset, 'utf-8') !== 0 && strcasecmp($charset, 'utf8') !== 0) {
                     $value = iconv($charset, 'UTF-8', $value);
                 }
                 $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
                 $xml->addChild($key, $value);
             }
         }
     }
     return $xml->asXML();
 }
 /**
  * Create playlist xml document and save to file.
  * @param $file     Ruta al archivo
  * @param $playlist Playlist.
  */
 private function savePlaylist($file, Playlist $playlist)
 {
     //Save to xml
     $simpleXml = new SimpleXmlElement('<?xml version="1.0" encoding="UTF-8"?><playlist name="' . utf8_encode($playlist->getName()) . '" description="' . utf8_encode($playlist->getDescription()) . '"></playlist>');
     $count = 1;
     foreach ($playlist->getPlaylistLinks() as $key => $playlistLink) {
         $element = $simpleXml->addChild("xfile");
         $element->addAttribute("key", $playlistLink->getKey());
         if ($playlistLink->getType() != null) {
             $element->addAttribute("type", $playlistLink->getType());
         } else {
             $element->addAttribute("type", $count);
             ++$count;
         }
         if ($playlistLink->getThumbnail() != null) {
             $element->addAttribute("thumbnail", $playlistLink->getThumbnail());
         }
         if ($playlistLink->getTitle() != null) {
             $element->addChild("title", "<![CDATA[" . $playlistLink->getTitle() . "]]>");
         }
         if ($playlistLink->getDescription() != null) {
             $element->addChild("description", "<![CDATA[" . $playlistLink->getDescription() . "]]>");
         }
         if ($playlistLink->getLink() != null) {
             $element->addChild("link", "<![CDATA[" . $playlistLink->getLink() . "]]>");
         }
         if ($playlistLink->getFormat() != null) {
             $element->addChild("format", "<![CDATA[" . $playlistLink->getFormat() . "]]>");
         }
         if ($playlistLink->getLanguage() != null) {
             $element->addChild("language", "<![CDATA[" . $playlistLink->getLanguage() . "]]>");
         }
         if (count($playlistLink->getIds()) > 0) {
             $elementId = $element->addChild("part");
             foreach ($playlistLink->getIds() as $order => $idValue) {
                 $temp = $elementId->addChild("id", $idValue);
                 $temp->addAttribute("order", $order);
             }
         }
     }
     $fp = fopen($file, 'w');
     fwrite($fp, html_entity_decode($this->xmlpp($simpleXml->asXML(), false)));
     fclose($fp);
 }