Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
write XML line by line
#1
Hi everyone, this is my first post. Thanks for this great CMS and the community behind.

(english is not my mother language so, please, forget me for my poor spelling)

I use GIT for versioning my sites and the problem are the XMLs in one big line, so I decide break it tag by tag.

In admin/inc/caching_functions.php, at the end of file after saving the data:

Code:
$xml->asXML($filem);
    
    // PATCH XML line by line
    $tmpXMLfile = file_get_contents($filem);
    $tmpNTC = "###DONT_BREAK_CDADA###";
    
    // insert between the opening TAG and CDATA, and the closing too.
    $tmpXMLfile = str_replace("><![CDATA",">$tmpNTC<![CDATA",$tmpXMLfile);
    $tmpXMLfile = str_replace("]]></","]]>$tmpNTC</",$tmpXMLfile);
    
    // insert new line (linux) between ><
    $tmpXMLfile = str_replace("><",">\n<",$tmpXMLfile);
    
    // clean DONT_BREAK_CDATA and write the file again.
    $tmpXMLfile = str_replace("$tmpNTC","",$tmpXMLfile);
    file_put_contents($filem,$tmpXMLfile);



Now, every change made with de admin panel will write XMLs TAGs separated by lines and can be follow the diffs with GIT or another version control system.

I hope this will be useful to somebody.

Best.
Reply
#2
Would you like to also post this as an issue on the GetSimple Github repository? Perhaps even fork the project and make a pull request for the change?
Reply
#3
(2015-08-12, 03:45:05)Angryboy Wrote: Would you like to also post this as an issue on the GetSimple Github repository? Perhaps even fork the project and make a pull request for the change?

Thanks, I will do soon.
Reply
#4
You could just use the aftersave hooks to post process it
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#5
Expanding on what shawn said (if almendro wants to write it as a plugin and publish it to extend):

PHP Code:
<?php
// plugins/prettify_pagecache.php
// Register the plugin
register_plugin(/*  registration details */);

// Add the page saving hook
add_action('pagecache-aftersave''prettify_pachecache');

// Define the prettifying function
function prettify_pachecache() {
 
 // get the xml file ($filem) and then run almendro's prettifying script


I still think almendro's suggestion is worth making an issue/pull request on (e.g. having a constant in gsconfig.php that enables/disables xml prettifying).
Reply
#6
Nope I'll add a filter instead
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#7
even better
Added in to core
AND added a filter

https://github.com/GetSimpleCMS/GetSimpl...ssues/1089
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#8
Nicely done!
Reply
#9
Wow, this is so fast. Thanks dudes! I'm glad to see this was happened.

Best!
Reply
#10
(2015-08-13, 04:03:26)shawn_a Wrote: even better
Added in to core
AND added a filter

https://github.com/GetSimpleCMS/GetSimpl...ssues/1089

an honor to contribute into the CORE! thanks. Big Grin
Reply
#11
Thanks for the suggestion, this would have actually saved me a ton of time last week, I had my text editor refreshing and reformatting constantly so i could read a file, was very annoying while i was testing output of something.

Always do a backup before testing a beta feature, hopefully it wont break anything but since it modifies all xml it could.
Needs testing with entities and utf-8, my tests seemed to be ok so far.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply




Users browsing this thread: 1 Guest(s)