From 06f945f27840b53e57795dadbc38e76f7e11ab1c Mon Sep 17 00:00:00 2001
From: Horus3
Date: Mon, 24 Feb 2014 16:42:14 +0100
Subject: init
---
zend/demos/Zend/Gdata/Docs.php | 940 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 940 insertions(+)
create mode 100755 zend/demos/Zend/Gdata/Docs.php
(limited to 'zend/demos/Zend/Gdata/Docs.php')
diff --git a/zend/demos/Zend/Gdata/Docs.php b/zend/demos/Zend/Gdata/Docs.php
new file mode 100755
index 0000000..2d61ecc
--- /dev/null
+++ b/zend/demos/Zend/Gdata/Docs.php
@@ -0,0 +1,940 @@
+= 5.2.11
+ *
+ * You can run this sample both from the command line (CLI) and also
+ * from a web browser. When running through a web browser, only
+ * AuthSub and outputting a list of documents is demonstrated. When
+ * running via CLI, all functionality except AuthSub is available and dependent
+ * upon the command line options passed. Run this script without any
+ * command line options to see usage, eg:
+ * /usr/local/bin/php -f Docs.php
+ *
+ * More information on the Command Line Interface is available at:
+ * http://www.php.net/features.commandline
+ *
+ * NOTE: You must ensure that Zend Framework is in your PHP include
+ * path. You can do this via php.ini settings, or by modifying the
+ * argument to set_include_path in the code below.
+ *
+ * NOTE: As this is sample code, not all of the functions do full error
+ * handling.
+ */
+
+/**
+ * @see Zend_Loader
+ */
+require_once 'Zend/Loader.php';
+
+/**
+ * @see Zend_Gdata
+ */
+Zend_Loader::loadClass('Zend_Gdata');
+
+/**
+ * @see Zend_Gdata_AuthSub
+ */
+Zend_Loader::loadClass('Zend_Gdata_AuthSub');
+
+/**
+ * @see Zend_Gdata_ClientLogin
+ */
+Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
+
+/**
+ * @see Zend_Gdata_Docs
+ */
+Zend_Loader::loadClass('Zend_Gdata_Docs');
+
+/**
+ * Returns a HTTP client object with the appropriate headers for communicating
+ * with Google using the ClientLogin credentials supplied.
+ *
+ * @param string $user The username, in e-mail address format, to authenticate
+ * @param string $pass The password for the user specified
+ * @return Zend_Http_Client
+ */
+function getClientLoginHttpClient($user, $pass)
+{
+ $service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
+ $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
+ return $client;
+}
+
+// ************************ BEGIN CLI SPECIFIC CODE ************************
+
+/**
+ * Display list of valid commands.
+ *
+ * @param string $executable The name of the current script. This is usually available as $argv[0].
+ * @return void
+ */
+function displayHelp($executable)
+{
+ echo "Usage: php {$executable} Before using this demo, you must set an application password
+ to protect your account. You will also need to set your
+ Google Apps credentials in order to communicate with the Google
+ Apps servers. To continue, open this file in a text editor and fill
+ out the information in the configuration section. Authentication with the Google Apps servers failed. Please open this file in a text editor and make
+ sure your credentials are correct. Welcome to the Google Documents List API demo page. Please select
+ from one of the following three options to see a list of commands. Tip: You can also run this demo from the command line if your system
+ has PHP CLI support enabled. Logout successful. Please check your request and try again. Please check your request and try again. Please check your request and try again.\n";}
+
+ // Iterate over the document entries in the feed and display each document's
+ // title.
+ foreach ($feed->entries as $entry) {
+
+ if ($html) {
+ // Find the URL of the HTML view of the document.
+ $alternateLink = '';
+ foreach ($entry->link as $link) {
+ if ($link->getRel() === 'alternate') {
+ $alternateLink = $link->getHref();
+ }
+ }
+ // Make the title link to the document on docs.google.com.
+ echo "
\n";}
+}
+
+/**
+ * Obtain a list of all of a user's docs.google.com documents and print the
+ * titles to the command line.
+ *
+ * @param Zend_Gdata_Docs $client The service object to use for communicating with the Google
+ * Documents server.
+ * @param boolean $html True if output should be formatted for display in a web browser.
+ * @return void
+ */
+function retrieveAllDocuments($client, $html)
+{
+ if ($html) {echo "Your documents
\n";}
+
+ $feed = $client->getDocumentListFeed();
+
+ printDocumentsFeed($feed, $html);
+}
+
+/**
+ * Obtain a list of all of a user's docs.google.com word processing
+ * documents and print the titles to the command line.
+ *
+ * @param Zend_Gdata_Docs $client The service object to use for communicating with the Google
+ * Documents server.
+ * @param boolean $html True if output should be formatted for display in a web browser.
+ * @return void
+ */
+function retrieveWPDocs($client, $html)
+{
+ if ($html) {echo "Your word processing documents
\n";}
+
+ $feed = $client->getDocumentListFeed(
+ 'http://docs.google.com/feeds/documents/private/full/-/document');
+
+ printDocumentsFeed($feed, $html);
+}
+
+/**
+ * Obtain a list of all of a user's docs.google.com spreadsheets
+ * documents and print the titles to the command line.
+ *
+ * @param Zend_Gdata_Docs $client The service object to use for communicating with the Google
+ * Documents server.
+ * @param boolean $html True if output should be formatted for display in a web browser.
+ * @return void
+ */
+function retrieveSpreadsheets($client, $html)
+{
+ if ($html) {echo "Your spreadsheets
\n";}
+
+ $feed = $client->getDocumentListFeed(
+ 'http://docs.google.com/feeds/documents/private/full/-/spreadsheet');
+
+ printDocumentsFeed($feed, $html);
+}
+
+/**
+ * Obtain a list of all of a user's docs.google.com documents
+ * which match the specified search criteria and print the titles to the
+ * command line.
+ *
+ * @param Zend_Gdata_Docs $client The service object to use for communicating with the Google
+ * Documents server.
+ * @param boolean $html True if output should be formatted for display in a web browser.
+ * @param string $query The search query to use
+ * @return void
+ */
+function fullTextSearch($client, $html, $query)
+{
+ if ($html) {echo "Documents containing $query
\n";}
+
+ $feed = $client->getDocumentListFeed(
+ 'http://docs.google.com/feeds/documents/private/full?q=' . $query);
+
+ printDocumentsFeed($feed, $html);
+}
+
+/**
+ * Upload the specified document
+ *
+ * @param Zend_Gdata_Docs $docs The service object to use for communicating with
+ * the Google Documents server.
+ * @param boolean $html True if output should be formatted for display in
+ * a web browser.
+ * @param string $originalFileName The name of the file to be uploaded. The mime type
+ * of the file is determined from the extension on
+ * this file name. For example, test.csv is uploaded
+ * as a comma seperated volume and converted into a
+ * spreadsheet.
+ * @param string $temporaryFileLocation (optional) The file in which the data for the
+ * document is stored. This is used when the file has
+ * been uploaded from the client's machine to the
+ * server and is stored in a temporary file which
+ * does not have an extension. If this parameter is
+ * null, the file is read from the originalFileName.
+ * @return void
+ */
+function uploadDocument($docs, $html, $originalFileName,
+ $temporaryFileLocation) {
+ $fileToUpload = $originalFileName;
+ if ($temporaryFileLocation) {
+ $fileToUpload = $temporaryFileLocation;
+ }
+
+ // Upload the file and convert it into a Google Document. The original
+ // file name is used as the title of the document and the mime type
+ // is determined based on the extension on the original file name.
+ $newDocumentEntry = $docs->uploadFile($fileToUpload, $originalFileName,
+ null, Zend_Gdata_Docs::DOCUMENTS_LIST_FEED_URI);
+
+ echo "New Document Title: ";
+
+ if ($html) {
+ // Find the URL of the HTML view of this document.
+ $alternateLink = '';
+ foreach ($newDocumentEntry->link as $link) {
+ if ($link->getRel() === 'alternate') {
+ $alternateLink = $link->getHref();
+ }
+ }
+ // Make the title link to the document on docs.google.com.
+ echo "\n";
+ }
+ echo $newDocumentEntry->title."\n";
+ if ($html) {echo "\n";}
+}
+
+// ************************ BEGIN WWW SPECIFIC CODE ************************
+
+/**
+ * Writes the HTML prologue for this app.
+ *
+ * NOTE: We would normally keep the HTML/CSS markup separate from the business
+ * logic above, but have decided to include it here for simplicity of
+ * having a single-file sample.
+ *
+ *
+ * @param boolean $displayMenu (optional) If set to true, a navigation menu is displayed at the top
+ * of the page. Default is true.
+ * @return void
+ */
+function startHTML($displayMenu = true)
+{
+?>
+
+
+
+
+
+
+ Almost there...
+ Google Docs Authentication Failed
+ Main Menu
+
+Logout
+
+Invalid command.
\n";
+ echo "Invalid menu selection.
\n";
+ echo "List Documents Menu
+
+
+
+
+
+
+
+Query the Documents List Feed
+
+
+
+
+Upload a document
+
+
+
+Service Error Encountered
" . htmlspecialchars($e->__toString()) . ""; + endHTML(true); + } +} -- cgit v1.2.3