Пример #1
0
/**
 * Processes loading of this sample code through a web browser.
 */
function runWWWVersion()
{
    session_start();

    // Note that all calls to endHTML() below end script execution!

    global $_SESSION, $_GET;
    if (!isset($_SESSION['docsSampleSessionToken']) && !isset($_GET['token'])) {
        requestUserLogin('Please login to your Google Account.');
    } else {
        $client = getAuthSubHttpClient();
        $docs = new Zend_Gdata_Docs($client);

        // First we check for commands that can be submitted either though
        // POST or GET (they don't make any changes).
        if (!empty($_REQUEST['command'])) {
            switch ($_REQUEST['command']) {
                case 'retrieveAllDocuments':
                    startHTML();
                    retrieveAllDocuments($docs, true);
                    endHTML(true);
                case 'retrieveWPDocs':
                    startHTML();
                    retrieveWPDocs($docs, true);
                    endHTML(true);
                case 'retrieveSpreadsheets':
                    startHTML();
                    retrieveSpreadsheets($docs, true);
                    endHTML(true);
                case 'fullTextSearch':
                    startHTML();
                    fullTextSearch($docs, true, $_REQUEST['query']);
                    endHTML(true);
                    
            }
        }
    
        // Now we handle the potentially destructive commands, which have to
        // be submitted by POST only.
        if (!empty($_POST['command'])) {
            switch ($_POST['command']) {
                case 'uploadDocument':
                    startHTML();
                    uploadDocument($docs, true, 
                        $_FILES['uploadedFile']['name'], 
                        $_FILES['uploadedFile']['tmp_name']);
                    endHTML(true);
                case 'modifySubscription':
                    if ($_POST['mode'] == 'subscribe') {
                        startHTML();
                        endHTML(true);
                    } elseif ($_POST['mode'] == 'unsubscribe') {
                        startHTML();
                        endHTML(true);
                    } else {
                        header('HTTP/1.1 400 Bad Request');
                        startHTML();
                        echo "<h2>Invalid mode.</h2>\n";
                        echo "<p>Please check your request and try again.</p>";
                        endHTML(true);
                    }
            }
        }
    
        // Check for an invalid command. If so, display an error and exit.
        if (!empty($_REQUEST['command'])) {
            header('HTTP/1.1 400 Bad Request');
            startHTML();
            echo "<h2>Invalid command.</h2>\n";
            echo "<p>Please check your request and try again.</p>";
            endHTML(true);
        }
        // If a menu parameter is available, display a submenu.
    
        if (!empty($_REQUEST['menu'])) {
            switch ($_REQUEST['menu']) {
                case 'list':
                    startHTML();
                    displayListMenu();
                    endHTML();
                case 'query':
                    startHTML();
                    displayQueryMenu();
                    endHTML();
                case 'upload':
                    startHTML();
                    displayUploadMenu();
                    endHTML();
                case 'logout':
                    startHTML(false);
                    logout();
                    endHTML();
                default:
                    header('HTTP/1.1 400 Bad Request');
                    startHTML();
                    echo "<h2>Invalid menu selection.</h2>\n";
                    echo "<p>Please check your request and try again.</p>";
                    endHTML(true);
            }
        }
        // If we get this far, that means there's nothing to do. Display
        // the main menu.
        // If no command was issued and no menu was selected, display the
        // main menu.
        startHTML();
        displayMenu();
        endHTML();
    }
}
Пример #2
0
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
// Docs.php has yet to be updated with v3.0 features. DocsBeta.php can be used
// as a replacement for.
require_once 'DocsBeta.php';
session_start();
$authSubURL = '';
try {
    // Extract single-use token from URL or use their existing session token.
    $token = isset($_SESSION['sessionToken']) ? $_SESSION['sessionToken'] : @$_GET['token'];
    $docs = setupDocsClient($token);
    // Upload document and redirect to Google Docs on success
    if (@$_REQUEST['command'] == "uploadDocument") {
        try {
            $newDocumentEntry = uploadDocument($docs, $_FILES['uploadedFile']['tmp_name'], $_FILES['uploadedFile']['name'], $_FILES['uploadedFile']['type']);
            if ($newDocumentEntry !== null) {
                $alternateLink = '';
                foreach ($newDocumentEntry->link as $link) {
                    if ($link->getRel() === 'alternate') {
                        $alternateLink = $link->getHref();
                    }
                }
                header("Location: {$alternateLink}");
                exit;
            }
        } catch (Zend_Gdata_App_HttpException $e) {
            echo '<div class="error">' . '<b>Error processing document:</b><br>' . $e->getMessage() . "</div>";
            exit(1);
        }
    }