<?php
/**
* Extension du noyau
*
* @package Utopia
* @subpackage Kernel
*/
defined('INC') or exit;
/**
* Import / Export de la langue au format XML.
*
* @package Utopia
* @subpackage Kernel
*/
class KLang_XML extends KLang {
function __construct($logFile, $configPath, $langPath) {
parent::__construct($logFile, $configPath, $langPath);
}
public function exportLangToXML($fileName, $sectionsToSave = NULL) {
$dom = new DOMDocument;
$dom -> loadXML(
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
."<!DOCTYPE lang SYSTEM \"".$this -> corePath."dtd/lang.dtd\">\n\n"
."<lang last-modified=".gmdate('Y-m-d\TH:i:s\Z').">\n"
."</lang>"
);
if ($sectionsToSave === NULL)
$sectionsToSave = array_keys($this -> strings);
ksort($sectionsToSave, SORT_STRING);
foreach ($sectionsToSave as $sectionId) {
if (isset($this -> strings[$sectionId])) {
$section = $dom -> createElement('section');
$section -> setAttribute('id', $sectionId);
$dom -> documentElement -> appendChild($section);
ksort($this -> strings, SORT_STRING);
foreach ($this -> strings[$sectionId] as $id => $value) {
$string = $dom -> createElement('string');
$string -> setAttribute('id', $id);
$string -> appendChild($dom -> createTextNode($value));
$section -> appendChild($string);
}
}
else
$this -> error(debug_backtrace(), 'SectionXFromLangNotLoaded,'.$sectionId);
}
$res = $dom -> save($this -> langPath.$fileName);
if ($res !== FALSE)
$this -> addToLog('notice', NULL, 'LangXSaved,'.$fileName);
else
$this -> error(debug_backtrace(), 'UnableToSaveLangX,'.$fileName);
return $res;
}
public function importLangFromXML($fileName, $sectionsToLoad = NULL, $ignoreOverLoading = FALSE) {
if (file_exists($this -> langPath.$fileName)) {
$dom = new DOMDocument;
$dom -> resolveExternals = TRUE;
$dom -> load($this -> langPath.$fileName);
if ($dom -> validate()) {
foreach ($dom -> getElementsByTagName('section') as $section) {
$sectionId = $section -> getAttribute('id');
if ($sectionsToLoad === NULL || in_array($sectionId, $sectionsToLoad))
if ($ignoreOverLoading || !isset($this -> strings[$sectionId])) {
$this -> strings[$sectionId] = array();
foreach ($section -> getElementsByTagName('string') as $string) {
if ($string -> firstChild)
$this -> strings[$sectionId][$string -> getAttribute('id')] = $string -> firstChild -> data;
else
$this -> strings[$sectionId][$string -> getAttribute('id')] = '';
}
}
else
$this -> error(debug_backtrace(), 'LangSectionXAlreadyLoaded,'.$sectionId);
}
return TRUE;
}
else
$this -> error(debug_backtrace(), 'LangFileXNotValid,'.$this -> langPath.$fileName);
}
else
$this -> fatalError(debug_backtrace(), 'LangFileXDoesNotExist,'.$this -> langPath.$fileName);
return FALSE;
}
}
?>