fusiongrokker

Hacking BlogCFC: Part 2 - Replacing the INI file (write) with XML

In Hacking BlogCFC: Part 1 - Replacing the INI file (read) with XML I showed how you can replace the file blog.ini.cfm with an XML file (blog.xml.cfm) and modify part of the core of BlogCFC to read the data from this new XML format. The motivation for doing so was that on some ColdFusion hosts the getProfileString() and setProfileString() functions are considered a security risk and blocked.

Today I'll show you how to modify the setProperty() method of /org/camden/blog.cfc to update that XML file, completing the transparency of the change, by giving the appearance that nothing has been changed at all.

In Part 1, I had you modify setProperty() and comment out its contents. Now, go back and replace that (leaving the original arguments in place) with the following:

[viewcode] src="blog.cfc.setProperty.2.txt" showsyntax=no geshi=cfm [/viewcode]

What we're doing here is loading the XML file into memory, using Regular Expressions to find the setting tag that we want to update, and replacing it with a new one built from the name and value passed into the function. Then we write the XML file back out, and all is well.

Notice that I'm still using lcase() on the key name, because we want to ensure that the settings file remains in lower case so that our reading function can find the settings it's looking for.

That's it! Now you can run BlogCFC on a host that blocks set/getProfileString(). Happy Blogging.

Posted in ColdFusion | Community | Meta