コード例 #1
0
ファイル: Formatter.php プロジェクト: robzienert/Drake
 /**
  * Formats data into a single line to be written by the writer
  *
  * @param array $event
  * @return string
  */
 public function format($event)
 {
     if ($this->_elementMap === null) {
         $dataToInsert = $event;
     } else {
         $dataToInsert = array();
         foreach ($this->_elementMap as $elementName => $fieldKey) {
             $dataToInsert[$elementName] = $event[$fieldKey];
         }
     }
     $dom = new DOMDocument();
     $elt = $dom->appendChild(new DOMElement($this->_rootElement));
     foreach ($dataToInsert as $key => $value) {
         if ($key == "message") {
             $value = $value['message'];
             $message = $elt->appendChild(new DOMElement('email'));
             foreach (array('headers', 'body') as $messageKey) {
                 $value[$messageKey] = str_replace('=3D', '=', $value[$messageKey]);
                 $value[$messageKey] = str_replace(Zend_Mime::$qpReplaceValues, Zend_Mime::$qpKeys, $value[$messageKey]);
                 $elem = $message->appendChild(new DomElement($messageKey));
                 $elem->appendChild($dom->createCDataSection($value[$messageKey]));
             }
             $elt->appendChild($message);
         } else {
             $elt->appendChild(new DOMElement($key, $value));
         }
     }
     $dom->formatOutput = true;
     $xml = $dom->saveXML();
     $xml = preg_replace('/<\\?xml version="1.0"( encoding="[^\\"]*")?\\?>\\n/u', '', $xml);
     return $xml . PHP_EOL;
 }
コード例 #2
0
 public function saveAction()
 {
     if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) {
         try {
             $base_path = Core_Model_Directory::getBasePathTo("languages" . DS);
             $country_code = $data["country_code"];
             $translation_dir = $base_path . $country_code;
             $translation_file = $data["file"];
             $translation_datas = $data["collection"];
             ksort($translation_datas);
             if (empty($country_code)) {
                 throw new Exception($this->_("Please, choose a language."));
             }
             if (empty($translation_file)) {
                 throw new Exception($this->_("Please, choose a file."));
             }
             //android translations
             $pathinfo = pathinfo($translation_file);
             if (!empty($pathinfo["extension"]) and $pathinfo["extension"] == "xml") {
                 $base_path = $this->_xml_files[$translation_file]["base_path"];
                 $default_translation_dir = $base_path;
                 $translation_dir = $this->_xml_files[$translation_file]["user_path"] . "values-" . Core_Model_Lib_String::formatLanguageCodeForAndroid($country_code) . DS;
                 $translation_file = $this->_xml_files[$translation_file]["file_name"];
                 if (!is_dir($translation_dir)) {
                     mkdir($translation_dir);
                 }
                 $xml = new DOMDocument();
                 $xml->load($default_translation_dir . $translation_file);
                 foreach ($translation_datas as $key => $value) {
                     $modified_key = str_replace(" ", "_", strtolower(trim(current(explode("(", $key)))));
                     foreach ($xml->getElementsByTagName("string") as $node) {
                         if (empty($value) && $node->getAttribute("name") == $modified_key || stripos($node->nodeValue, '{#--') !== false) {
                             $node->parentNode->removeChild($node);
                             continue;
                         }
                         if ($node->getAttribute("name") == $modified_key) {
                             $cdata = $xml->createCDataSection(addslashes($value));
                             $node->nodeValue = "";
                             $node->appendChild($cdata);
                         }
                     }
                 }
                 $xml->save($translation_dir . $translation_file);
             } else {
                 if (!is_dir($translation_dir)) {
                     mkdir($translation_dir);
                 }
                 $ressource = fopen($translation_dir . DS . $translation_file, "w");
                 foreach ($translation_datas as $key => $value) {
                     if (empty($value)) {
                         continue;
                     }
                     $this->_putCsv($ressource, array($key, $value));
                 }
                 fclose($ressource);
                 if (!file_exists($translation_dir . DS . "default.csv")) {
                     $ressource = fopen($translation_dir . DS . "default.csv", "w");
                     $this->_putCsv($ressource, array("", ""));
                     fclose($ressource);
                 }
             }
             $data = array("success" => 1, "message" => $this->_("Language successfully saved"));
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }
コード例 #3
0
ファイル: Document.php プロジェクト: rubensworks/OpenSKOS
 public function __toString()
 {
     $doc = new DOMDocument();
     $doc->loadXML('<doc/>');
     foreach ($this->fieldnames as $fieldname) {
         foreach ($this->data[$fieldname] as $value) {
             $node = $doc->documentElement->appendChild($doc->createElement('field'));
             $htmlSafeValue = htmlspecialchars($value);
             if ($htmlSafeValue == $value) {
                 $node->appendChild($doc->createTextNode($htmlSafeValue));
             } else {
                 $node->appendChild($doc->createCDataSection($value));
             }
             $node->setAttribute('name', $fieldname);
         }
     }
     return $doc->saveXml($doc->documentElement);
 }
コード例 #4
0
 /**
  * given a value if it is null return null otherwise a DOMNode
  *
  * @param string $value
  * @param DOMDocument $doc
  * @return DOMNode | null
  */
 public function createStringNode($value, DOMDocument $doc)
 {
     return is_null($value) ? null : $doc->createCDataSection($value);
 }
コード例 #5
0
ファイル: Library.php プロジェクト: navtis/xerxes-search25
 /**
  * Serialize to XML
  *
  * @return DOMDocument
  */
 public function toXML()
 {
     if ($this->library_id == "") {
         throw new \Exception("Cannot access data, it has not been loaded");
     }
     $xml = new \DOMDocument();
     $xml->loadXML("<library />");
     $xml->documentElement->setAttribute("library_id", $this->library_id);
     $xml->documentElement->setAttribute("pz2_key", $this->pz2_key);
     foreach ($this->vars as $k => $v) {
         //$node = $xml->createElement($k, htmlentities($v));
         if (htmlentities($v) != $v) {
             $sect = $xml->createCDataSection($v);
             $node = $xml->createElement($k);
             $node->appendChild($sect);
         } else {
             $node = $xml->createElement($k, $v);
         }
         $xml->documentElement->appendChild($node);
     }
     return $xml;
 }