From e127b460e9fa38aa122d3f9b1b20e4018136cd2e Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Fri, 5 Nov 2021 22:51:04 +0100 Subject: [PATCH] fix dcstore xml rendering (thanks @franck-paul) closes #4 --- dcstore.xml | 23 ++++++++++++----------- inc/lib.improve.action.dcstore.php | 18 +++++++++++++++++- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/dcstore.xml b/dcstore.xml index b464781..2e0adec 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -1,12 +1,13 @@ + - -improve -0.4 -Jean-Christian Denis and contributors -Tiny tools to fix things for module devs -https://github.com/JcDenis/improve/releases/download/v0.4/plugin-improve.zip -2.19 -https://github.com/JcDenis/improve -https://github.com/JcDenis/improve - - \ No newline at end of file + + improve + 0.4 + Jean-Christian Denis and contributors + Tiny tools to fix things for module devs + https://github.com/JcDenis/improve/releases/download/v0.4/plugin-improve.zip + 2.19 + https://github.com/JcDenis/improve + https://github.com/JcDenis/improve + + diff --git a/inc/lib.improve.action.dcstore.php b/inc/lib.improve.action.dcstore.php index 9f2b094..995d038 100644 --- a/inc/lib.improve.action.dcstore.php +++ b/inc/lib.improve.action.dcstore.php @@ -60,6 +60,8 @@ class ImproveActionDcstore extends ImproveAction return false; } + $content = $this->prettyXML($content); + try { files::putContent($this->module['sroot'] . '/dcstore.xml', $content); $this->setSuccess(__('Write dcstore.xml file.')); @@ -166,7 +168,21 @@ class ImproveActionDcstore extends ImproveAction $res = new xmlTag('modules', $rsp); $res->insertAttr('xmlns:da', 'http://dotaddict.org/da/'); - return str_replace('><', ">\n<", $res->toXML()); + return self::prettyXML($res->toXML()); + } + + private static function prettyXML(string $str): string + { + if (class_exists('DOMDocument')) { + $dom = new DOMDocument('1.0'); + $dom->preserveWhiteSpace = false; + $dom->formatOutput = true; + $dom->loadXML($str); + + return $dom->saveXML(); + } + + return str_replace('><', ">\n<", $str); } private function parseFilePattern()