/**
     * Checks for the existence of the Zend Framework. If not found, prints out some (hopefully) helpful information
     * @return bool true if Zend is found, *but* if not found calls wp_die()
     */
    public static function checkIncludeZend()
    {
        if (!(include 'Zend/Loader.php')) {
            ob_start();
            ?>
            <h1>Missing Zend Framework</h1>
            <p>
                This function requires part of the Zend framework that interacts with Google. <br/>
                It appears that either:
            </p>
            <ol>
                <li>The Zend Framework is not on the include_path or</li>
                <li>You do not have the Zend Framework installed</li>
            </ol>
            <p>
                <code>include_path="<?php 
            echo ini_get('include_path');
            ?>
"</code><br/>
                <code>php.ini file is
                    "<?php 
            $phpInfo = CFDBCheckZendFramework::getPhpInfo();
            echo $phpInfo['Loaded Configuration File'];
            ?>
                    "</code><br/>
            </p>
            <ol>
                <li>locate the the <span style="font-weight: bold;">Zend</span> directory on your computer</li>
                <li>If found, here is one way to put it on the include path</li>
                <ol>
                    <li style="list-style: lower-roman">copy the <span style="font-weight: bold;">php.ini</span> file to your WordPress installation to
                        <span style="font-weight: bold;">[wp-dir]/wp-content/plugins/contact-form-7-to-database-extension/php.ini</span>
                    </li>
                    <li style="list-style: lower-roman">add a line to this new file:<br/>
                        <code>include_path="<?php 
            echo ini_get('include_path') . PATH_SEPARATOR . "[Zend-parent-directory]";
            ?>
"</code>
                    </li>
                </ol>
                <li>If not found, install and configure Zend version 1.11.11 (or contact or administrator or host provider)<br/>
                    See: <a target="_blank" href="http://code.google.com/apis/gdata/articles/php_client_lib.html">Getting
                        Started
                        with the Google Data PHP Client Library</a><br/>
                    To download the part of Zend 1.11.11 required, see: <a target="_blank"
                                                                   href="http://framework.zend.com/download/gdata/">Zend
                        GData</a>
                </li>
            </ol>
            <?php 
            $errorHtml = ob_get_contents();
            ob_end_clean();
            include_once 'CFDBDie.php';
            CFDBDie::wp_die($errorHtml, __('Missing Zend Framework', 'contact-form-7-to-database-extension'), array('response' => 200, 'back_link' => true));
            // Doesn't actually return because we call wp_die
            return false;
        }
        return true;
    }
Ejemplo n.º 2
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));
     }
 }