/**
 * Updates list of Google Documents and Spreadsheets
 * 
 * Connects to Google and retrieves list of documents and spreadsheets.
 * Updates table in Wordpress database.
 * Returns data to browser in a JSON variable via http headers.
 */
function gdocs_update_list()
{
    // get Google Documents client
    $gdClient = GClient::getInstance(GDOCS_DOCUMENT);
    // initialize collector stack
    $docs = array();
    // update document list
    gdocs_update_documents($gdClient, &$docs);
    $doc_count = sizeof($docs);
    // get Google Spreadsheets client
    $gsClient = GClient::getInstance(GDOCS_SPREADSHEET);
    // update spreadsheet list
    $data = gdocs_update_sts($gdClient, $gsClient, &$docs);
    $st_count = sizeof($docs) - $doc_count;
    header('HTTP/1.0 200 OK');
    header('Content-Type: application/x-json');
    $json = array('dc' => $doc_count, 'sc' => $st_count);
    // update DB
    try {
        GDB::write($data);
    } catch (GDB_Exception $e) {
        $json['error'] = $e->getMessage();
        gdocs_error($e);
    }
    header('X-JSON: (' . json_encode($json) . ')');
    echo json_encode($docs);
}
Example #2
0
/**
 * Install plugin
 *
 * Adds configuration options
 * Creates table in Wordpress database
 */
function gdocs_install()
{
    // login credentials
    add_option('gdocs_user');
    add_option('gdocs_pwd');
    // proxy config
    add_option('gdocs_proxy_host');
    add_option('gdocs_proxy_port');
    add_option('gdocs_proxy_user');
    add_option('gdocs_proxy_pwd');
    // cache config
    add_option('gdocs_cache_expiry', 0);
    // stylesheets config
    add_option('gdocs_style_dir');
    // create table in DB to store shortcode tags
    try {
        GDB::drop();
        GDB::create();
    } catch (GDB_Exception $e) {
        gdocs_error($e);
    }
}
 /**
  * GElement constructor
  *
  * Parses shortcode attributes, assembles and formats HTML to display document/spreadsheet
  * 
  * @method	GElement	GElement()	GElement($atts)	creates and initializes new GElement object
  * @param	array		$atts		Shortcode attributes
  * @return	GElement	$obj		GElement object
  */
 public function __construct($atts)
 {
     // init variables
     $this->atts = $atts;
     $this->html = "";
     // check required attributes exist
     $this->checkRequired();
     // assemble
     $this->html .= $this->printStylesheets();
     $this->html .= $this->printScripts();
     $this->html .= $this->openTag();
     try {
         // read from cache
         $this->html .= $this->printCache();
         return;
     } catch (GElementException $e) {
         // no cache or cache expired
         $body = $this->printBody();
         $this->html .= $body;
         try {
             // write to cache
             $this->cache_session->write($body);
         } catch (GCache_Exception $e) {
             // cache not writable
             gdocs_error($e);
         }
         return;
     }
 }