<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Serge&#039;s Technology View &#187; embed google docs content</title>
	<atom:link href="http://blog.dragonsoft.us/tag/embed-google-docs-content/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.dragonsoft.us</link>
	<description>Talk about Technologies, Software Architecture and Management</description>
	<lastBuildDate>Tue, 20 Apr 2010 14:42:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>How to embed Google Docs document into your page</title>
		<link>http://blog.dragonsoft.us/2009/06/24/how-to-embed-google-docs-document-into-your-page/</link>
		<comments>http://blog.dragonsoft.us/2009/06/24/how-to-embed-google-docs-document-into-your-page/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 16:01:32 +0000</pubDate>
		<dc:creator>Serguei Dosyukov</dc:creator>
				<category><![CDATA[Web-design]]></category>
		<category><![CDATA[embed google docs content]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.dragonsoft.us/?p=985</guid>
		<description><![CDATA[There are plenty of presentations, documents, and spreadsheets we may want to share with the world. We can use homegrown document handling solutions, use commercial 3rd party solutions or&#8230; utilize power provided by Google Docs. When storing articles on Google Docs you are provided with the option to share them with some people only or [...]]]></description>
			<content:encoded><![CDATA[<p>There are plenty of presentations, documents, and spreadsheets we may want to share with the world.</p>
<p>We can use homegrown document handling solutions, use commercial 3rd party solutions or&#8230; utilize power provided by <a href="http://docs.google.com/" target="_blank">Google Docs</a>.</p>
<p>When storing articles on Google Docs you are provided with the option to share them with some people only or with everyone. I like to have option to link my articles from anywhere but I also like to have not just plain page, but a page embedded into my web-site pages.</p>
<p>What it means is that instead of<a href="http://docs.google.com/View?id=dgwckpgv_1t38fmc" target="_blank"> external page</a>, I want to <a href="http://www.dragonsoft.us/articles.php?id=dgwckpgv_1t38fmc" target="_blank">put it in my own box</a>.</p>
<p>There was time when it wasn&#8217;t as easy because of the additional code Google was injecting into articles, but time changed and now it is fairly easy and strait forward.</p>
<h3>Goals</h3>
<ul>
<li>Embed Google Docs document into existing page</li>
<li>PHP. This is not really a requirement per se, it is just code below is PHP.</li>
<li>Retain copyright information</li>
</ul>
<h3>Solution</h3>
<p>The following code snippet allows to get a desired result</p>
<pre class="brush: php;">// id parameter is used to pass Google Docs arcticle id
// Example: mydocview.php?id=nnnnnnnnnnnnnnnn

$id    = $_REQUEST['id'];
if ($id) {
  $started = &quot;0&quot;;
  echo('&lt;div class=&quot;googledocs&quot; &gt;Stored and managed via &lt;a title=&quot;Learn more about Google Docs&quot; href=&quot;http://docs.google.com&quot; target=&quot;_blank&quot;&gt;Google Docs &amp;copy; -- Web word processing, presentations and spreadsheets.&lt;/a&gt;&lt;/div&gt;');

  // Read document content, parse to normalize and output
  $file = fopen (&quot;http://docs.google.com/View?id=&quot; . $id, &quot;r&quot;);
  while (!feof ($file)) {
    $line = fgets ($file, 4096);

    // Parse header info out
    if ($started == &quot;0&quot;) {
      if (substr($line, 0, 5) == '&lt;body') { $started = &quot;1&quot;; }
      else { continue; }
    }

    // Parse body content until document content block is detected
    if ($started == &quot;1&quot;) {
      if (strstr($line, '&lt;div id=&quot;doc-contents&quot;&gt;')) { $started = &quot;2&quot;; }
      else { continue; }
    }

    // Output document content
    if ($started == &quot;2&quot;) {
      // Stop processing, end of content reached
      if (strstr($line, '&lt;div id=&quot;google-view-footer&quot;&gt;')) { break; }

      // Normalize image links to keep link back to google docs
      $line = str_replace('src=&quot;File?id', 'src=&quot;http://docs.google.com/File?id', $line);

      // Normalize links to other articles
      $line = str_replace('href=&quot;View?docid=', 'href=&quot;/mydocview.php?id=', $line);
      $line = str_replace('href=&quot;View?id=', 'href=&quot;/mydocview.php?id=', $line);
      $line = str_replace('href=&quot;View?docID=', 'href=&quot;/mydocview.php?id=', $line);
      $line = str_replace('href=&quot;View?', 'href=&quot;/mydocview.php?', $line);

      // Output result
      echo($line);
    }
  }
  fclose($file);
}</pre>
<p>Sample page:</p>
<pre class="brush: php;">&lt;html&gt;
&lt;head&gt;&lt;/head&gt;
&lt;body&gt;
&lt;? // Include code above here
?&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<hr/><span style="font-size: 7pt">Copyright &copy; 2010 <strong><a href="http://blog.dragonsoft.us">Serge&#039;s Technology View</a></strong>. This Feed is for personal non-commercial use only.</span>]]></content:encoded>
			<wfw:commentRss>http://blog.dragonsoft.us/2009/06/24/how-to-embed-google-docs-document-into-your-page/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
