/** * Overall AJAX handler * * This is the only entry point. Checks user permissions and request parameters. * Redirects to appropriate function. */ function gdocs_ajax_handler() { /** * Data regarding current user * @global mixed object containing user data * @name $userdata */ global $userdata; get_currentuserinfo(); if ($userdata->user_level < 8) { // insufficient rights header('HTTP/1.0 403 Forbidden'); $error = 'You do not have sufficient access rights to use this plugin.'; header('X-JSON: (' . json_encode($error) . ')'); die; return NULL; } // check if action is set $action = NULL; if (isset($_POST['method'])) { $action = $_POST['method']; // execute $func = 'gdocs_' . $action; try { @$func(); } catch (Zend_Http_Client_Adapter_Exception $e) { // connnection problem , probably proxy $error = "A connection error has occurred. Are you behind a proxy?"; header('HTTP/1.0 400 Bad Request'); header('X-JSON: (' . json_encode($error) . ')'); } catch (Zend_Gdata_App_CaptchaRequiredException $e) { // google requested captcha $error = GDisplay::printCaptchaError($e); header('HTTP/1.0 400 Bad Request'); header('X-JSON: (' . json_encode($error) . ')'); } catch (Zend_Gdata_App_AuthException $e) { // google docs login problem if (!get_option('gdocs_user') || !get_option('gdocs_pwd')) { $error = "Please enter your username and password in the plugin configuration form under <em>Settings</em>."; } else { $error = "The plugin was unable to login to the Google service. Did you give us the wrong password/username?"; } header('HTTP/1.0 400 Bad Request'); header('X-JSON: (' . json_encode($error) . ')'); } catch (Zend_Gdata_App_HttpException $e) { // HTTP Error $error = "A HTTP error has occurred: " . $e->getMessage() . ". Please contact the plugin author with <a href='" . GDOCS_ADDRESS . "/cache/error.log.php'><em>error.log.php</em></a> for assistance."; header('HTTP/1.0 502 Bad Gateway'); header('X-JSON: (' . json_encode($error) . ')'); @gdocs_error($e); } catch (Exception $e) { $error = "An error has occurred: " . $e->getMessage() . ". Please contact the plugin author with <a href='" . GDOCS_ADDRESS . "/cache/error.log.php'><em>error.log.php</em></a> for assistance."; header('HTTP/1.0 400 Bad Request'); header('X-JSON: (' . json_encode($error) . ')'); @gdocs_error($e); } } else { // missing paramter $error = "Required parameters missing."; header('HTTP/1.0 400 Bad Request'); header('X-JSON: (' . json_encode($error) . ')'); die; return NULL; } die; }
/** * Prints postbox */ function gdocs_helper() { GDisplay::printHelper(GDB::read()); }
/** * Print table */ protected function printBody() { // get GData client $gClient = GClient::getInstance(GDOCS_SPREADSHEET); // get cell entry $entry = $gClient->getCell($this->atts['st_id'], $this->atts['wt_id'], $this->atts['cell_id']); if (!$entry) { throw new Exception(); } // format return GDisplay::printCell($entry); }