Ejemplo n.º 1
0
 /**
  * Save PHPExcel to file
  *
  * @param	string		$pFileName
  * @throws	Exception
  */
 public function save($pFilename = null)
 {
     parent::save($pFilename);
     $googleDocsClient = Zend_Gdata_ClientLogin::getHttpClient($this->_username, $this->_password, Zend_Gdata_Docs::AUTH_SERVICE_NAME);
     $googleDocsService = new Zend_Gdata_Docs($googleDocsClient);
     $googleDocsService->uploadFile($pFilename, basename($pFilename), null, Zend_Gdata_Docs::DOCUMENTS_LIST_FEED_URI);
     @unlink($pFilename);
 }
Ejemplo n.º 2
0
 function testUploadGdocAction()
 {
     $this->disableLayout();
     $service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
     $client = Zend_Gdata_ClientLogin::getHttpClient("*****@*****.**", "W1sedsuk0l", $service);
     $docs = new Zend_Gdata_Docs($client);
     $file = "D:auditor\\data\filesauditor\\mastermanagement\\WebSSO_Activity_Plan_08082554__3_.xls";
     chmod($file, 0755);
     $newDocumentEntry = $docs->uploadFile($file, "2_Masrter_Management_100811__4__3.pdf", null, Zend_Gdata_Docs::DOCUMENTS_LIST_FEED_URI);
     $this->render('blank', null, true);
     // 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 "<a href=\"{$alternateLink}\">\n";
 }
Ejemplo n.º 3
0
 public function export($formName, $options = null)
 {
     $this->setOptions($options);
     // Security Check
     if (!$this->isAuthorized()) {
         $this->assertSecurityErrorMessage();
         return;
     }
     // Headers
     $this->echoHeaders('Content-Type: text/html; charset=UTF-8');
     if (!CFDBCheckZendFramework::checkIncludeZend()) {
         return;
     }
     Zend_Loader::loadClass('Zend_Gdata');
     Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
     //Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');
     Zend_Loader::loadClass('Zend_Gdata_App_AuthException');
     Zend_Loader::loadClass('Zend_Http_Client');
     Zend_Loader::loadClass('Zend_Gdata_Docs');
     $guser = $options['guser'];
     $gpwd = $options['gpwd'];
     try {
         $client = Zend_Gdata_ClientLogin::getHttpClient($guser, $gpwd, Zend_Gdata_Docs::AUTH_SERVICE_NAME);
         //Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME
     } catch (Zend_Gdata_App_AuthException $ae) {
         CFDBDie::wp_die("<p>Login failed for: '{$guser}' </p><p>Error: " . $ae->getMessage() . '</p>', __('Login Failed', 'contact-form-7-to-database-extension'), array('response' => 200, 'back_link' => true));
     }
     try {
         // Generate CSV file contents into buffer
         $exporter = new ExportToCsvUtf8();
         $exporter->setOptions($options);
         $exporter->setCommonOptions();
         $exporter->setUseBom(false);
         ob_start();
         $exporter->echoCsv($formName);
         $csvFileContents = ob_get_contents();
         ob_end_clean();
         // Put the contents in a tmp file because Google upload API only reads from a file
         $tmpfname = tempnam(sys_get_temp_dir(), "{$formName}.csv");
         $handle = fopen($tmpfname, 'w');
         fwrite($handle, $csvFileContents);
         fclose($handle);
         // Upload the tmp file to Google Docs
         $docs = new Zend_Gdata_Docs($client);
         $newDocumentEntry = $docs->uploadFile($tmpfname, $formName, 'text/csv');
         unlink($tmpfname);
         // delete tmp file
         // Get the URL of the new Google doc
         $alternateLink = '';
         foreach ($newDocumentEntry->link as $link) {
             if ($link->getRel() === 'alternate') {
                 $alternateLink = $link->getHref();
                 break;
             }
         }
         //header("Location: $alternateLink");
         //$title = $newDocumentEntry->title;
         $title = __('New Google Spreadsheet', 'contact-form-7-to-database-extension');
         $output = utf8_encode("{$title}: <a target=\"_blank\" href=\"{$alternateLink}\">") . $formName . utf8_encode('</a>');
         CFDBDie::wp_die($output, $title, array('response' => 200, 'back_link' => true));
     } catch (Exception $ex) {
         CFDBDie::wp_die($ex->getMessage() . '<pre>' . $ex->getTraceAsString() . '</pre>', __('Error', 'contact-form-7-to-database-extension'), array('back_link' => true));
     }
 }
Ejemplo n.º 4
0
/**
 * 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.
 */
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 "<a href=\"$alternateLink\">\n";
  }
  echo $newDocumentEntry->title."\n";
  if ($html) {echo "</a>\n";}
}