use xmlTag() to manage file content

This commit is contained in:
Jean-Christian Denis 2021-09-28 00:41:10 +02:00
parent fcdfd7e3ba
commit e7abe59147
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951

View file

@ -1,15 +1,15 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief tweakStores, a plugin for Dotclear 2
# This file is part of tweakStores, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors * @subpackage Plugin
# *
# Licensed under the GPL version 2.0 license. * @author Jean-Christian Denis and Contributors
# A copy of this license is available in LICENSE file or at *
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright Jean-Christian Denis
# * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# -- END LICENSE BLOCK ------------------------------------ */
class tweakStores class tweakStores
{ {
@ -94,41 +94,41 @@ class tweakStores
return false; return false;
} }
$module = self::sanitizeModule($id, $module); $module = self::sanitizeModule($id, $module);
$rsp = new xmlTag('module');
self::$notice = []; self::$notice = [];
self::$failed = []; self::$failed = [];
$xml = ['<modules xmlns:da="http://dotaddict.org/da/">'];
# id # id
if (empty($module['id'])) { if (empty($module['id'])) {
self::$failed[] = 'unknow module'; self::$failed[] = 'unknow module';
} }
$xml[] = sprintf('<module id="%s">', html::escapeHTML($module['id'])); $rsp->id = $module['id'];
# name # name
if (empty($module['name'])) { if (empty($module['name'])) {
self::$failed[] = 'no module name set in _define.php'; self::$failed[] = 'no module name set in _define.php';
} }
$xml[] = sprintf('<name>%s</name>', html::escapeHTML($module['oname'])); $rsp->name($module['oname']);
# version # version
if (empty($module['version'])) { if (empty($module['version'])) {
self::$failed[] = 'no module version set in _define.php'; self::$failed[] = 'no module version set in _define.php';
} }
$xml[] = sprintf('<version>%s</version>', html::escapeHTML($module['version'])); $rsp->version($module['version']);
# author # author
if (empty($module['author'])) { if (empty($module['author'])) {
self::$failed[] = 'no module author set in _define.php'; self::$failed[] = 'no module author set in _define.php';
} }
$xml[] = sprintf('<author>%s</author>', html::escapeHTML($module['author'])); $rsp->author($module['author']);
# desc # desc
if (empty($module['desc'])) { if (empty($module['desc'])) {
self::$failed[] = 'no module description set in _define.php'; self::$failed[] = 'no module description set in _define.php';
} }
$xml[] = sprintf('<desc>%s</desc>', html::escapeHTML($module['desc'])); $rsp->desc($module['desc']);
# repository # repository
if (empty($module['repository'])) { if (empty($module['repository'])) {
@ -140,10 +140,10 @@ class tweakStores
if (empty($file_pattern)) { if (empty($file_pattern)) {
self::$failed[] = 'no zip file pattern set in Tweak Store configuration'; self::$failed[] = 'no zip file pattern set in Tweak Store configuration';
} }
$xml[] = sprintf('<file>%s</file>', html::escapeHTML($file_pattern)); $rsp->file($file_pattern);
# da dc_min or requires core # da dc_min or requires core
if (!empty($>module['requires']) && is_array($module['requires'])) { if (!empty($module['requires']) && is_array($module['requires'])) {
foreach ($module['requires'] as $req) { foreach ($module['requires'] as $req) {
if (!is_array($req)) { if (!is_array($req)) {
$req = [$req]; $req = [$req];
@ -157,28 +157,32 @@ class tweakStores
if (empty($module['dc_min'])) { if (empty($module['dc_min'])) {
self::$notice[] = 'no minimum dotclear version'; self::$notice[] = 'no minimum dotclear version';
} else { } else {
$xml[] = sprintf('<da:dcmin>%s</da:dcmin>', html::escapeHTML($module['dc_min'])); $rsp->insertNode(new xmlTag('da:dcmin', $module['dc_min']));
} }
# details # details
if (empty($module['details'])) { if (empty($module['details'])) {
self::$notice[] = 'no details URL'; self::$notice[] = 'no details URL';
} else {
$rsp->insertNode(new xmlTag('da:details', $module['details']));
} }
$xml[] = sprintf('<da:details>%s</da:details>', html::escapeHTML($module['details']));
# section # section
$xml[] = sprintf('<da:section>%s</da:section>', html::escapeHTML($module['section'])); if (!empty($module['section'])) {
$rsp->insertNode(new xmlTag('da:section', $module['section']));
}
# support # support
if (empty($module['support'])) { if (empty($module['support'])) {
self::$notice[] = 'no support URL'; self::$notice[] = 'no support URL';
} else {
$rsp->insertNode(new xmlTag('da:support', $module['support']));
} }
$xml[] = sprintf('<da:support>%s</da:support>', html::escapeHTML($module['support']));
$xml[] = '</module>'; $res = new xmlTag('modules', $rsp);
$xml[] = '</modules>'; $res->insertAttr('xmlns:da', 'http://dotaddict.org/da/');
return implode("\n", $xml); return $res->toXML();
} }
public static function writeXML($id, $module, $file_pattern) public static function writeXML($id, $module, $file_pattern)