From b3c540f4d6807ba311a12669b0732bf20e94f0c0 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Fri, 27 Sep 2019 17:38:43 +0200 Subject: [PATCH] Add license support for devtools project form See #2772 --- .../acp/form/DevtoolsProjectAddForm.class.php | 6 ++ .../form/DevtoolsProjectEditForm.class.php | 24 +++++ .../DevtoolsPackageXmlWriter.class.php | 89 +++++++------------ wcfsetup/install/lang/de.xml | 1 + wcfsetup/install/lang/en.xml | 1 + 5 files changed, 66 insertions(+), 55 deletions(-) diff --git a/wcfsetup/install/files/lib/acp/form/DevtoolsProjectAddForm.class.php b/wcfsetup/install/files/lib/acp/form/DevtoolsProjectAddForm.class.php index 82187b19f4..179acca63c 100644 --- a/wcfsetup/install/files/lib/acp/form/DevtoolsProjectAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/DevtoolsProjectAddForm.class.php @@ -287,7 +287,13 @@ class DevtoolsProjectAddForm extends AbstractFormBuilderForm { UrlFormField::create('packageUrl') ->label('wcf.acp.devtools.project.packageUrl') ->description('wcf.acp.devtools.project.packageUrl.description') + ->maximumLength(255), + + TextFormField::create('license') + ->label('wcf.acp.devtools.project.license') ->maximumLength(255) + ->i18n() + ->languageItemPattern('__NONE__') ]) ->addDependency( ValueFormFieldDependency::create('mode') diff --git a/wcfsetup/install/files/lib/acp/form/DevtoolsProjectEditForm.class.php b/wcfsetup/install/files/lib/acp/form/DevtoolsProjectEditForm.class.php index a2412a65f2..595ba57e75 100644 --- a/wcfsetup/install/files/lib/acp/form/DevtoolsProjectEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/DevtoolsProjectEditForm.class.php @@ -215,6 +215,30 @@ class DevtoolsProjectEditForm extends DevtoolsProjectAddForm { $packageUrl->value($packageArchive->getPackageInfo('packageurl')); } + /** @var TextFormField $license */ + $license = $this->form->getNodeById('license'); + $xmlLicenses = $packageArchive->getPackageInfo('license'); + if ($xmlLicenses !== null) { + if (count($xmlLicenses) === 1) { + $license->value(reset($xmlLicenses)); + } + else { + $licenses = []; + foreach (LanguageFactory::getInstance()->getLanguages() as $language) { + $licenses[$language->languageID] = ''; + + if (isset($xmlLicenses[$language->languageCode])) { + $licenses[$language->languageID] = $xmlLicenses[$language->languageCode]; + } + else if (isset($xmlLicenses['default'])) { + $licenses[$language->languageID] = $xmlLicenses['default']; + } + } + + $license->value($licenses); + } + } + /** @var TextFormField $author */ $author = $this->form->getNodeById('author'); if ($packageArchive->getAuthorInfo('author') !== null) { diff --git a/wcfsetup/install/files/lib/system/devtools/package/DevtoolsPackageXmlWriter.class.php b/wcfsetup/install/files/lib/system/devtools/package/DevtoolsPackageXmlWriter.class.php index 202a1cec25..c4449c5187 100644 --- a/wcfsetup/install/files/lib/system/devtools/package/DevtoolsPackageXmlWriter.class.php +++ b/wcfsetup/install/files/lib/system/devtools/package/DevtoolsPackageXmlWriter.class.php @@ -198,88 +198,66 @@ class DevtoolsPackageXmlWriter { } /** - * Writes the `packageinformation` element. + * Writes a child of the `packageinformation` element with i18n data. + * + * @param string $information + * @param null|string $elementName is set to lowercase version of `$information` if missing */ - protected function writePackageInformation() { - $this->xmlWriter->startElement('packageinformation'); - - $this->xmlWriter->writeComment(" {$this->packageXmlData['packageIdentifier']} "); + protected function writeI18nPackageInformation($information, $elementName = null) { + if ($elementName === null) { + $elementName = strtolower($information); + } $english = LanguageFactory::getInstance()->getLanguageByCode('en'); - if (isset($this->packageXmlData['packageName_i18n'])) { + if (isset($this->packageXmlData[$information . '_i18n'])) { $defaultLanguageID = null; - if ($english !== null && isset($this->packageXmlData['packageName_i18n'][$english->languageID])) { + if ($english !== null && isset($this->packageXmlData[$information . '_i18n'][$english->languageID])) { $defaultLanguageID = $english->languageID; } else { - reset($this->packageXmlData['packageName_i18n']); - $defaultLanguageID = key($this->packageXmlData['packageName_i18n']); + reset($this->packageXmlData[$information . '_i18n']); + $defaultLanguageID = key($this->packageXmlData[$information . '_i18n']); } $this->xmlWriter->writeElement( - 'packagename', - $this->packageXmlData['packageName_i18n'][$defaultLanguageID], + $elementName, + $this->packageXmlData[$information . '_i18n'][$defaultLanguageID], [], - $this->requiresCdata($this->packageXmlData['packageName_i18n'][$defaultLanguageID]) + $this->requiresCdata($this->packageXmlData[$information . '_i18n'][$defaultLanguageID]) ); - foreach ($this->packageXmlData['packageName_i18n'] as $languageID => $packageName) { + foreach ($this->packageXmlData[$information . '_i18n'] as $languageID => $informationValue) { if ($languageID !== $defaultLanguageID) { $this->xmlWriter->writeElement( - 'packagename', - $packageName, + $elementName, + $informationValue, ['language' => LanguageFactory::getInstance()->getLanguage($languageID)->languageCode], - $this->requiresCdata($packageName) + $this->requiresCdata($informationValue) ); } } } else { $this->xmlWriter->writeElement( - 'packagename', - $this->packageXmlData['packageName'], + $elementName, + $this->packageXmlData[$information], [], - $this->requiresCdata($this->packageXmlData['packageName']) + $this->requiresCdata($this->packageXmlData[$information]) ); } + } + + /** + * Writes the `packageinformation` element. + */ + protected function writePackageInformation() { + $this->xmlWriter->startElement('packageinformation'); - if (isset($this->packageXmlData['packageDescription_i18n'])) { - $defaultLanguageID = null; - if (isset($this->packageXmlData['packageDescription_i18n'][$english->languageID])) { - $defaultLanguageID = $english->languageID; - } - else { - reset($this->packageXmlData['packageDescription_i18n']); - $defaultLanguageID = key($this->packageXmlData['packageDescription_i18n']); - } - - $this->xmlWriter->writeElement( - 'packagedescription', - $this->packageXmlData['packageDescription_i18n'][$defaultLanguageID], - [], - $this->requiresCdata($this->packageXmlData['packageDescription_i18n'][$defaultLanguageID]) - ); - - foreach ($this->packageXmlData['packageDescription_i18n'] as $languageID => $packageDescription) { - if ($languageID !== $defaultLanguageID) { - $this->xmlWriter->writeElement( - 'packagedescription', - $packageDescription, - ['language' => LanguageFactory::getInstance()->getLanguage($languageID)->languageCode], - $this->requiresCdata($packageDescription) - ); - } - } - } - else { - $this->xmlWriter->writeElement( - 'packagedescription', - $this->packageXmlData['packageDescription'], - [], - $this->requiresCdata($this->packageXmlData['packageDescription']) - ); - } + $this->xmlWriter->writeComment(" {$this->packageXmlData['packageIdentifier']} "); + + $this->writeI18nPackageInformation('packageName'); + $this->writeI18nPackageInformation('packageDescription'); if (!empty($this->packageXmlData['isApplication'])) { $this->xmlWriter->writeElement( @@ -317,6 +295,7 @@ class DevtoolsPackageXmlWriter { $this->requiresCdata($this->packageXmlData['packageUrl']) ); } + $this->writeI18nPackageInformation('license'); $this->xmlWriter->endElement(); } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 16ce850bd4..57eb66e78d 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -601,6 +601,7 @@ package.xml im angegebenen Pfad. Die Paket-Dateien wurden entweder gelöscht oder verschoben.]]> package.xml-Datei: {implode from=$missingElements item=missingElement}{$missingElement}{/implode}.]]> + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 90d8903015..e67282bdd2 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -577,6 +577,7 @@ package.xml in the given directory. The package files have either been deleted or moved.]]> package.xml file: {implode from=$missingElements item=missingElement}{$missingElement}{/implode}.]]> + -- 2.20.1