Google Docs as a Free and Easy CMS
Monday, May 18th, 2009CMS
A CMS is a content management system. Basically, it holds all the revisions, deals with collaborators, and puts stuff into templates so it’s nice on the eye. Good CMS’s will allow you to edit WYSIWYG too. It is, however, a pain for me to go to the work of setting up Joomla, Pligg, or WordPress for something quick and simple. And I hate to pay for software. What do you do when nothing fits just right? Invent your own system.
Google Documents
When you think of the things a CMS can do, Google Docs immediately comes to mind. Revisions, collaboration, WYSIWYG editing, and even basic publishing. The “publishing” feature only give a black and white page with not much wiggle room to turn it into a real site, although. Then I had my idea. What if PHP was to grab the published document’s URL and extricate the content, and then echo it back as if the content was hard-coded in? Some thinking, a soda, and ten lines of PHP, it was done. The script retrieves the page and discards anything before the content and everything after it. This however, removes some of the styles Google Docs puts in. If you edit the raw html of the document as Google kindly allows, you can add tags that you can refer to in your own linked stylesheet. The Google Doc must be published to work.The script is as follows, and if free to use with the comments in place:
< ?php
$docID = "dfgpnkdc_37fn6v5tfh";
//published google docID (part of publish url)
$temp = file_get_contents("http://docs.google.com/View?docID=" . $docID);
//get the page contents of the "preview" url for the doc
$temp2 = explode('<div id="doc-contents">', $temp);
//separate into the upper non-text half and lower half
$temp3 = $temp2[1];
//discard upper half
$temp4 = explode(’<br clear=”all”/>’, $temp3);
//separate into all-text and non-text, again
//don't remove this line:
echo "<!-- Google Docs CMS PHP script copyright 2009 theajblog.com, begin script generated text -->";
echo iconv ( "utf-8" , "ISO-8859-1//TRANSLIT" , $temp4[0] );
/* echo text converted utf-8 to iso-8859-1 - important. Apostrophes turn into A’s with tildes because of a character mismatch otherwise. Also, without //TRANSLIT, certain characters like a special closing quote will cause it to cut off the document there. */
?>









