= 5.1.4
*
* 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;
}
/**
* 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: ";
$Save_Title = $newDocumentEntry->title;
$ExportURL = $newDocumentEntry->content->getSrc();
if ($html) {
// Find the URL of the HTML view of this document.
$alternateLink = '';
//var_dump($newDocumentEntry);
foreach ($newDocumentEntry->link as $link) {
//echo $link->getHref() . "
";
if ($link->getRel() === 'alternate') {
$OriginalLink = $link->getHref();
}
}
}
$Save_File = explode(".",$originalFileName);
$Save_Extension = $Save_File[1];
// echo $Save_Extension;
if($Save_Extension=='ppt')
{
$ExportURLPDF = $ExportURL . "&exportFormat=pdf&format=pdf";
$ExportURLPNG = $ExportURL . "&exportFormat=png&format=png";
$ExportURLSWF = $ExportURL . "&exportFormat=swf&format=swf";
$ExportURLTXT = $ExportURL . "&exportFormat=txt&format=txt";
?>
| Native File | PDF Export | PNG Export | SWF Export | TXT Export |
| Native File | PDF Export | PNG Export | SWF Export | TXT Export | HTML Export |
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.
Logout successful.
Invalid mode.\n"; echo "Please check your request and try again.
"; 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 "Please check your request and try again.
"; endHTML(true); } // If a menu parameter is available, display a submenu. if (!empty($_REQUEST['menu'])) { switch ($_REQUEST['menu']) { case 'logout': startHTML(false); logout(); endHTML(); default: header('HTTP/1.1 400 Bad Request'); startHTML(); echo "Please check your request and try again.
"; 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(); displayUploadMenu(); endHTML(); } } /** * Display the menu for running in a web browser. * * @return void */ function displayUploadMenu() { ?>This will convert uploaded .doc, .docx, .ppt to PDF + other format(s).
Service Error Encountered\n"; echo "" . htmlspecialchars($e->__toString()) . ""; endHTML(true); } }