Added language export function
authorJean-Marc Licht <siora@web-produktion.com>
Sat, 24 Mar 2012 18:44:07 +0000 (19:44 +0100)
committerJean-Marc Licht <siora@web-produktion.com>
Sat, 24 Mar 2012 18:44:07 +0000 (19:44 +0100)
wcfsetup/install/files/lib/data/language/LanguageEditor.class.php

index 0979bfcfcbe2435b1e7e1479fbe333197aa3136f..a87b94a1cbf8cf33e76d536eec1f0f529a89a6d4 100644 (file)
@@ -144,6 +144,74 @@ class LanguageEditor extends DatabaseObjectEditor {
                }
        }
        
+       /**
+        * Exports this language.
+        */
+       public function export($packageIDArray = array(), $exportCustomValues = false) {
+               $conditions = new PreparedStatementConditionBuilder();
+               
+               // bom
+               echo "\xEF\xBB\xBF";
+               
+               // header
+               echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<language xmlns=\"http://www.woltlab.com\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.woltlab.com http://www.woltlab.com/XSD/maelstrom/language.xsd\" languagecode=\"".$this->languageCode."\">\n";
+               
+               // get items
+               $items = array();
+               if (count($packageIDArray)) {
+                       // sql conditions
+                       $conditions->add("language_item.packageID IN (?)", array($packageIDArray));
+                       $conditions->add("language_item.languageID = ?", array($this->languageID));
+                       
+                       $sql = "SELECT          languageItem, " . ($exportCustomValues ? "CASE WHEN languageUseCustomValue > 0 THEN languageCustomItemValue ELSE languageItemValue END AS languageItemValue" : "languageItemValue") . ", languageCategory
+                               FROM            wcf".WCF_N."_language_item language_item
+                               LEFT JOIN       wcf".WCF_N."_language_category language_category
+                               ON              (language_category.languageCategoryID = language_item.languageCategoryID)
+                               ".$conditions;
+               }
+               else {
+                       // sql conditions
+                       $conditions->add("language_item.packageID = package_dependency.dependency");
+                       $conditions->add("package_dependency.packageID = ?", array(PACKAGE_ID));
+                       $conditions->add("language_item.languageID = ?", array($this->languageID));
+                               
+                       $sql = "SELECT          languageItem, " . ($exportCustomValues ? "CASE WHEN languageUseCustomValue > 0 THEN languageCustomItemValue ELSE languageItemValue END AS languageItemValue" : "languageItemValue") . ", languageCategory
+                               FROM            wcf".WCF_N."_package_dependency package_dependency,
+                                               wcf".WCF_N."_language_item language_item
+                               LEFT JOIN       wcf".WCF_N."_language_category language_category
+                               ON              (language_category.languageCategoryID = language_item.languageCategoryID)
+                               ".$conditions."
+                               ORDER BY        package_dependency.priority ASC";
+               }
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute($conditions->getParameters());
+               while ($row = $statement->fetchArray()) {
+                       $items[$row['languageCategory']][$row['languageItem']] = $row['languageItemValue'];
+               }
+               
+               // sort categories
+               ksort($items);
+               
+               foreach ($items as $category => $categoryItems) {
+                       // sort items
+                       ksort($categoryItems);
+                       
+                       // category header
+                       echo "\t<category name=\"".$category."\">\n";
+                       
+                       // items
+                       foreach ($categoryItems as $item => $value) {
+                               echo "\t\t<item name=\"".$item."\"><![CDATA[".StringUtil::escapeCDATA($value)."]]></item>\n";
+                       }
+                       
+                       // category footer
+                       echo "\t</category>\n";
+               }
+               
+               // footer
+               echo "</language>";
+       }
+       
        /**
         * Imports language items from an XML file into this language.
         * Updates the relevant language files automatically.