From acdf777bcc66987ec47e45fa85ea36146546ca1a Mon Sep 17 00:00:00 2001 From: steve-lad <72376554+steve-lad@users.noreply.github.com> Date: Tue, 6 Jul 2021 12:24:34 +0200 Subject: [PATCH] Clean up xml in cnf files Indentation was not satisfactory. Improves readability and presentation of cnf files created Thanks to @dkgroot for proposing this improvement --- module.xml | 2 +- sccpManClasses/xmlinterface.class.php | 6 +++--- sccpManTraits/helperFunctions.php | 9 +++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/module.xml b/module.xml index d600f86..3e5c4c2 100644 --- a/module.xml +++ b/module.xml @@ -1,7 +1,7 @@ sccp_manager SCCP Manager - 14.3.0.1 + 14.3.0.0 setup SCCP Connectivity Steve Lad, Alex GP diff --git a/sccpManClasses/xmlinterface.class.php b/sccpManClasses/xmlinterface.class.php index 2ce301d..7b55cf2 100644 --- a/sccpManClasses/xmlinterface.class.php +++ b/sccpManClasses/xmlinterface.class.php @@ -112,7 +112,7 @@ class xmlinterface $node->addAttribute('model', $var['vendor'] . ' ' . $var['model']); } } - $xml_work->asXml($xml_name); // Save XMLDefault1.cnf.xml + \FreePBX::Sccp_manager()->saveXml($xml_work, $xml_name); // Save XMLDefault1.cnf.xml } } @@ -347,7 +347,7 @@ class xmlinterface } } - $xml_work->asXml($xml_name); // Save + \FreePBX::Sccp_manager()->saveXml($xml_work, $xml_name); // Save return time(); } @@ -667,7 +667,7 @@ class xmlinterface } } - $xml_work->asXml($xml_name); // Save + \FreePBX::Sccp_manager()->saveXml($xml_work, $xml_name); // Save } else { die('Error Hardware template :' . $xml_template . ' not found'); } diff --git a/sccpManTraits/helperFunctions.php b/sccpManTraits/helperFunctions.php index 3531a66..2229ff3 100644 --- a/sccpManTraits/helperFunctions.php +++ b/sccpManTraits/helperFunctions.php @@ -213,6 +213,15 @@ trait helperfunctions { return false; } + // temporary helper function to save xml with proper indentation + public function saveXml($xml, $filename) { + $dom = new \DOMDocument("1.0"); + $dom->preserveWhiteSpace = false; + $dom->formatOutput = true; + $dom->loadXML($xml->asXML()); + $dom->save($filename); + } + public function initVarfromXml() { if ((array) $this->xml_data) { foreach ($this->xml_data->xpath('//page_group') as $item) {