Created
September 19, 2012 23:48
-
-
Save timwis/3753084 to your computer and use it in GitHub Desktop.
GDriveCMS allows you to use Google Docs' familiar interface for adding content to a mobile-optimized web page. Simply create a Google Document with whatever content you want, publish it to the web (in the File menu), and render it through this script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* GDriveCRM | |
Created by Tim Wisniewski (timwis.com) | |
GDriveCMS allows you to use Google Docs' familiar interface for adding content to a mobile-optimized web page. | |
Simply create a Google Document with whatever content you want, publish it to the web (in the File menu), | |
and render it through this script. | |
1. Create a document in Google Drive (Google Docs) | |
2. Go to File > Publish to the web | |
3. Click Start Publishing & check Automatically republish | |
4. Grab the document link (URL) in that dialog | |
5. Go to this page with ?url=DOCUMENTLINK in the URL | |
ex. http://dev.timwis.com/gdrivecms/?url=https://docs.google.com/document/pub?id=1Ewf7USaYnkqrp9moUNMipuy_THA-U_p8k44F2MzIWlQ | |
(Please excuse the DomDocument usage. I'd have used a better DOM Parsing library but I wanted to keep this very light-weight.) | |
*/ | |
function remove_tags($tags, $attr = FALSE) { | |
$tags_to_remove = array(); | |
foreach($tags as $tag) { // seems silly, but you have to iterate twice for it to work w/DomDocument | |
if( !$attr || !$tag->hasAttribute($attr)) | |
$tags_to_remove []= $tag; | |
} | |
foreach($tags_to_remove as $tag) { | |
$tag->parentNode->removeChild($tag); | |
} | |
} | |
$title = ''; | |
$body = ''; | |
if(isset($_GET['url'])) { | |
$doc = new DomDocument(); | |
$doc->loadHTMLFile($_GET['url']); | |
$title = $doc->getElementsByTagName('title')->item(0)->nodeValue; | |
$anchors = $doc->getElementsByTagName('a'); | |
remove_tags($anchors, 'href'); // google docs inserts anchors into headers | |
$body = $doc->saveXML($doc->getElementById('contents')); | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title><?php echo $title; ?></title> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.1.1/css/bootstrap.min.css" rel="stylesheet"> | |
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.1.1/css/bootstrap-responsive.min.css" rel="stylesheet"> | |
</head> | |
<body> | |
<?php echo $body; ?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment