/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // redefine fields $fileFile = $this->frm->getField('file'); $chkOverwrite = $this->frm->getField('overwrite'); // name checks if ($fileFile->isFilled(BL::err('FieldIsRequired'))) { // only xml files allowed if ($fileFile->isAllowedExtension(array('xml'), sprintf(BL::getError('ExtensionNotAllowed'), 'xml'))) { // load xml $xml = @simplexml_load_file($fileFile->getTempFileName()); // invalid xml if ($xml === false) { $fileFile->addError(BL::getError('InvalidXML')); } } } if ($this->frm->isCorrect()) { // import $statistics = BackendLocaleModel::importXML($xml, $chkOverwrite->getValue()); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_import', array('statistics' => $statistics)); // everything is imported, so redirect to the overview $this->redirect(BackendModel::createURLForAction('index') . '&report=imported&var=' . ($statistics['imported'] . '/' . $statistics['total']) . $this->filterQuery); } } }
/** * Imports the locale XML file * * @param string $filename The full path for the XML-file. * @param bool[optional] $overwriteConflicts Should we overwrite when there is a conflict? */ protected function importLocale($filename, $overwriteConflicts = false) { $filename = (string) $filename; $overwriteConflicts = (bool) $overwriteConflicts; // load the file content and execute it $content = trim(SpoonFile::getContent($filename)); // file actually has content if (!empty($content)) { // load xml $xml = @simplexml_load_file($filename); // import if it's valid xml if ($xml !== false) { // import locale require_once BACKEND_MODULES_PATH . '/locale/engine/model.php'; BackendLocaleModel::importXML($xml, $overwriteConflicts, $this->getLanguages(), $this->getInterfaceLanguages(), $this->getDefaultUserID(), gmdate('Y-m-d H:i:s')); } } }