Urdu English
English English Deutsch Deutsch Español Español Français Français Italiano Italiano Nederlands Nederlands Português Português Русский Русский Ελληνικά Ελληνικά

Welcome to Jumi! >> Tutorial >> Google Documents into your Joomla!

You can use Google power to create and share documents. Sometimes it is easier to use Google editor than WYSIWYG Editors in Joomla!

In this example I'll show you how to use Google for creating documents and importing them to your Joomla! with Jumi component.


First of all you need to have Google account to use Google Services. If you don't have Google account yet, please follow this link: New Account

You need to have some basic skills for using Google Documents. You can take this short tour

Your host must support PHP Curl libary.

Creating sample document from template

Create new document from sample template and publish it as web page, which is stored under Share menu on top-right corner.

Copy DocID, after you will pass it to the script, which will render Document in Joomla!


Now let's write the basic script, which will retrieve document and render it. It will be stored in components/com_jumi/files folder.

<?php defined("_JEXEC") or die("Restricted access"); ?>
/* config */
$doc_url    = 'http://docs.google.com/View?docID=';
$doc_id     = 'dhczg2mw_7cq5qg2d8';
$cache_time = 30*24*60*60; // 30 days
$file_name  = 'cache/'.md5($doc_id);

// check cache
if(file_exists($file_name) and strtotime('now') - filemtime($file_name) < $cache_time) {
    echo file_get_contents($file_name);
} else {
    // retrieve document from docs.google.com
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $doc_url.$doc_id);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $document = curl_exec($ch);

    /* modify document for inclusion */
    // TODO

    // cache article
    if(strlen($wiki_content) < 3000) {
        echo '<p>Unfortunately, no content could be extracted! ';
        echo 'You can access document directly <a href="'.$doc_url.$doc_id.'" 
target="_blank">View Document</a></p>
'; } else { file_put_contents($file_name, $document); echo $document; } }

Adding Jumi application

Now you need to add new Jumi application from Joomla! backend. You can read Basic Jumi Demo article if you don't know how to do that.

I'll call it: Sample Google doc.

You'll need to pass as documentID parameter to this script.

Sample Document