/** * 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; }
static function doExportFromPost() { // Consolidate GET and POST parameters. Allow GET to override POST. $params = array_merge($_POST, $_GET); //print_r($params); if (!isset($params['form'])) { include_once 'CFDBDie.php'; CFDBDie::wp_die(__('Error: No "form" parameter submitted', 'contact-form-7-to-database-extension')); return; } // Assumes coming from CF7DBPlugin::whatsInTheDBPage() $key = '3fde789a'; //substr($_COOKIE['PHPSESSID'], - 5); // session_id() doesn't work if (isset($params['guser'])) { $params['guser'] = mcrypt_decrypt(MCRYPT_3DES, $key, CF7DBPluginExporter::hexToStr($params['guser']), 'ecb'); } if (isset($params['gpwd'])) { $params['gpwd'] = mcrypt_decrypt(MCRYPT_3DES, $key, CF7DBPluginExporter::hexToStr($params['gpwd']), 'ecb'); } if (!isset($params['enc'])) { $params['enc'] = 'CSVUTF8'; } CF7DBPluginExporter::export($params['form'], $params['enc'], $params); }
protected function assertSecurityErrorMessage() { $showMessage = true; if (isset($this->options['role'])) { // If role is being used, but default do not show the error message $showMessage = false; } if (isset($this->options['permissionmsg'])) { $showMessage = $this->options['permissionmsg'] != 'false'; } $errMsg = $showMessage ? __('You do not have sufficient permissions to access this data.', 'contact-form-7-to-database-extension') : ''; if ($this->isFromShortCode) { echo $errMsg; } else { include_once 'CFDBDie.php'; CFDBDie::wp_die($errMsg); } }
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)); } }
public function export($formName, $options = null) { $plugin = new CF7DBPlugin(); if (!$plugin->canUserDoRoleOption('CanSeeSubmitData')) { CFDBDie::wp_die(__('You do not have sufficient permissions to access this page.', 'contact-form-7-to-database-extension')); } header('Expires: 0'); header('Cache-Control: no-store, no-cache, must-revalidate'); $pluginUrlDir = $plugin->getPluginDirUrl(); $scriptLink = $pluginUrlDir . 'CFDBGoogleSSLiveData.php'; $imageUrlDir = $pluginUrlDir . "help"; $siteUrl = get_option('home'); $userName = is_user_logged_in() ? wp_get_current_user()->user_login : '******'; ob_start(); ?> <style type="text/css"> *.popup-trigger { position: relative; z-index: 0; } *.popup-trigger:hover { background-color: transparent; z-index: 50; } *.popup-content { position: absolute!important; background-color: #ffffff; padding: 5px; border: 2px gray; visibility: hidden!important; color: black; text-decoration: none; min-width:400px; max-width:600px; overflow: auto; } *.popup-trigger:hover *.popup-content { visibility: visible!important; top: 50px!important; left: 50px!important; } </style> <?php _e('Setting up a Google Spreadsheet to pull in data from WordPress requires these manual steps:', 'contact-form-7-to-database-extension'); ?> <table cellspacing="15px" cellpadding="15px"> <tbody> <tr> <td> <div class="popup-trigger"> <a href="<?php echo $imageUrlDir; ?> /GoogleNewSS.png"> <img src="<?php echo $imageUrlDir; ?> /GoogleNewSS.png" alt="Create a new spreadsheet" height="100px" width="61px"/> <div class="popup-content"> <img src="<?php echo $imageUrlDir; ?> /GoogleNewSS.png" alt="Create a new spreadsheet" height="75%" width="75%"/> </div> </a> </div> </td> <td><p><?php _e('Log into Google Docs and create a new Google Spreadsheet', 'contact-form-7-to-database-extension'); ?> </p></td> </tr> <tr> <td> <div class="popup-trigger"> <a href="<?php echo $imageUrlDir; ?> /GoogleOpenScriptEditor.png"> <img src="<?php echo $imageUrlDir; ?> /GoogleOpenScriptEditor.png" alt="Create a new spreadsheet" height="69px" width="100px"/> <div class="popup-content"> <img src="<?php echo $imageUrlDir; ?> /GoogleOpenScriptEditor.png" alt="Create a new spreadsheet" height="75%" width="75%"/> </div> </a> </div> </td> <td><p><?php _e('Go to <strong>Tools</strong> menu -> <strong>Script Editor...', 'contact-form-7-to-database-extension'); ?> </p></td> </tr> <tr> <td> <div class="popup-trigger"> <a href="<?php echo $imageUrlDir; ?> /GoogleChooseSpreadsheet.png"> <img src="<?php echo $imageUrlDir; ?> /GoogleChooseSpreadsheet.png" alt="Choose Spreadsheet" height="69px" width="100px"/> <div class="popup-content"> <img src="<?php echo $imageUrlDir; ?> /GoogleChooseSpreadsheet.png" alt="GoogleChooseSpreadsheet Spreadsheet" height="75%" width="75%"/> </div> </a> </div> </td> <td><p><?php _e('Choose <strong>Spreadsheet</strong>', 'contact-form-7-to-database-extension'); ?> </p></td> </tr> <tr> <td> <div class="popup-trigger"> <a href="<?php echo $imageUrlDir; ?> /GooglePasteScriptEditor.png"> <img src="<?php echo $imageUrlDir; ?> /GooglePasteScriptEditor.png" alt="Paste script text" height="68px" width="100px"/> <div class="popup-content"> <img src="<?php echo $imageUrlDir; ?> /GooglePasteScriptEditor.png" alt="Paste script text" height="75%" width="75%"/> </div> </a> </div> </td> <td> <p><?php _e('Delete any text that is already there', 'contact-form-7-to-database-extension'); ?> </p> <p><?php _e('<strong>Copy</strong> the text from ', 'contact-form-7-to-database-extension'); ?> <a target="_gscript" href="<?php echo $scriptLink; ?> "><?php _e('THIS SCRIPT FILE', 'contact-form-7-to-database-extension'); ?> </a> <?php _e('and <strong>paste</strong> it into the Google script editor', 'contact-form-7-to-database-extension'); ?> </p> </td> </tr> <tr> <td> <div class="popup-trigger"> <a href="<?php echo $imageUrlDir; ?> /GoogleSaveScriptEditor.png"> <img src="<?php echo $imageUrlDir; ?> /GoogleSaveScriptEditor.png" alt="Create a new spreadsheet" height="100px" width="83px"/> <div class="popup-content"> <img src="<?php echo $imageUrlDir; ?> /GoogleSaveScriptEditor.png" alt="Create a new spreadsheet" height="75%" width="75%"/> </div> </a> </div> </td> <td> <p><?php _e('<strong>Save</strong> the script', 'contact-form-7-to-database-extension'); ?> </p> </td> </tr> <tr> <td> <div class="popup-trigger"> <a href="<?php echo $imageUrlDir; ?> /GoogleEnterFormula.png"> <img src="<?php echo $imageUrlDir; ?> /GoogleEnterFormula.png" alt="Create a new spreadsheet" height="43px" width="100px"/> <div class="popup-content"> <img src="<?php echo $imageUrlDir; ?> /GoogleEnterFormula.png" alt="Create a new spreadsheet" height="75%" width="75%"/> </div> </a> </div> </td> <td> <p><?php _e('Click on a cell A1 in the Spreadsheet (or any cell)', 'contact-form-7-to-database-extension'); ?> <br/><?php _e('Enter in the cell the formula:', 'contact-form-7-to-database-extension'); ?> <br/><span style="background-color: yellow"><code><?php echo "=cfdbdata(\"{$siteUrl}\", \"{$formName}\", \"{$userName}\", \"<password>\")"; ?> </code></span> <br/><?php _e('Replace <strong><password></strong> with your <em>WordPress</em> password', 'contact-form-7-to-database-extension'); ?> </p> <?php $scBuilderPageUrl = $siteUrl . '/wp-admin/admin.php?page=CF7DBPluginShortCodeBuilder&enc=GLD&form=' . urlencode($formName); ?> <p> <a href="<?php echo $scBuilderPageUrl; ?> " target="sc"><?php _e('Customize the output by creating a Google Spreadsheet Function call with additional options', 'contact-form-7-to-database-extension'); ?> </a> </p> </td> </tr> </tbody> </table> <span style="color:red; font-weight:bold;"> WARNING: since you are putting your login information into the Google Spreadsheet, be sure not to share the spreadsheet with others.</span> <?php $html = ob_get_contents(); ob_end_clean(); CFDBDie::wp_die($html, __('How to Set up Google Spreadsheet to pull data from WordPress', 'contact-form-7-to-database-extension'), array('response' => 200, 'back_link' => true)); }
public function ajaxFile() { require_once 'CFDBDie.php'; //if (!$this->canUserDoRoleOption('CanSeeSubmitData')) { if (!$this->canUserDoRoleOption('CanSeeSubmitDataViaShortcode')) { CFDBDie::wp_die(__('You do not have sufficient permissions to access this page.', 'contact-form-7-to-database-extension')); } $submitTime = $_REQUEST['s']; $formName = $_REQUEST['form']; $fieldName = $_REQUEST['field']; if (!$submitTime || !$formName || !$fieldName) { CFDBDie::wp_die(__('Missing form parameters', 'contact-form-7-to-database-extension')); } $fileInfo = (array) $this->getFileFromDB($submitTime, $formName, $fieldName); if ($fileInfo == null) { CFDBDie::wp_die(__('No such file.', 'contact-form-7-to-database-extension')); } require_once 'CFDBMimeTypeExtensions.php'; $mimeMap = new CFDBMimeTypeExtensions(); $mimeType = $mimeMap->get_type_by_filename($fileInfo[0]); if ($mimeType) { header('Content-Type: ' . $mimeType); header("Content-Disposition: inline; filename=\"{$fileInfo['0']}\""); } else { header("Content-Disposition: attachment; filename=\"{$fileInfo['0']}\""); } echo $fileInfo[1]; die; }
public function ajaxFile() { $this->ajaxCheckForLoginAndDoRedirect(); require_once 'CFDBDie.php'; if (!$this->canUserDoRoleOption('CanSeeSubmitData') && !$this->canUserDoRoleOption('CanSeeSubmitDataViaShortcode')) { CFDBDie::wp_die(__('You do not have sufficient permissions to access this page.', 'contact-form-7-to-database-extension')); } $submitTime = stripslashes($_REQUEST['s']); $formName = stripslashes($_REQUEST['form']); $fieldName = stripslashes($_REQUEST['field']); if (!$submitTime || !$formName || !$fieldName) { CFDBDie::wp_die(__('Missing form parameters', 'contact-form-7-to-database-extension')); } $fileInfo = (array) $this->getFileFromDB($submitTime, $formName, $fieldName); if ($fileInfo == null) { CFDBDie::wp_die(__('No such file.', 'contact-form-7-to-database-extension')); } require_once 'CFDBMimeTypeExtensions.php'; $mimeMap = new CFDBMimeTypeExtensions(); $mimeType = $mimeMap->get_type_by_filename($fileInfo[0]); if (ob_get_level()) { ob_end_clean(); // Fix bug where download files can be corrupted } ob_end_clean(); // Not sure why have to do this on some sites if ($mimeType) { header('Content-Type: ' . $mimeType); header("Content-Disposition: inline; filename=\"{$fileInfo['0']}\""); } else { header("Content-Disposition: attachment; filename=\"{$fileInfo['0']}\""); } echo $fileInfo[1]; die; }
public function export($formName, $options = null) { $plugin = new CF7DBPlugin(); if (!$plugin->canUserDoRoleOption('CanSeeSubmitData')) { CFDBDie::wp_die(__('You do not have sufficient permissions to access this page.', 'contact-form-7-to-database-extension')); } header('Expires: 0'); header('Cache-Control: no-store, no-cache, must-revalidate'); $pluginUrlDir = $plugin->getPluginDirUrl(); $scriptLink = $pluginUrlDir . 'Cf7ToDBGGoogleSS.js.php'; $imageUrlDir = $pluginUrlDir . "help"; $siteUrl = get_option('home'); $search = isset($options['search']) ? $options['search'] : ''; ob_start(); ?> <style type="text/css"> *.popup-trigger { position: relative; z-index: 0; } *.popup-trigger:hover { background-color: transparent; z-index: 50; } *.popup-content { position: absolute!important; background-color: #ffffff; padding: 5px; border: 2px gray; visibility: hidden!important; color: black; text-decoration: none; min-width:400px; max-width:600px; overflow: auto; } *.popup-trigger:hover *.popup-content { visibility: visible!important; top: 50px!important; left: 50px!important; } </style> Setting up a Google Spreadsheet to pull in data from WordPress requires these manual steps: <table cellspacing="15px" cellpadding="15px"> <tbody> <tr> <td> <div class="popup-trigger"> <a href="<?php echo $imageUrlDir; ?> /GoogleNewSS.png"> <img src="<?php echo $imageUrlDir; ?> /GoogleNewSS.png" alt="Create a new spreadsheet" height="100px" width="61px"/> <div class="popup-content"> <img src="<?php echo $imageUrlDir; ?> /GoogleNewSS.png" alt="Create a new spreadsheet"/> </div> </a> </div> </td> <td><p>Log into Google Docs and create a new Google Spreadsheet</p></td> </tr> <tr> <td> <div class="popup-trigger"> <a href="<?php echo $imageUrlDir; ?> /GoogleOpenScriptEditor.png"> <img src="<?php echo $imageUrlDir; ?> /GoogleOpenScriptEditor.png" alt="Create a new spreadsheet" height="69px" width="100px"/> <div class="popup-content"> <img src="<?php echo $imageUrlDir; ?> /GoogleOpenScriptEditor.png" alt="Create a new spreadsheet"/> </div> </a> </div> </td> <td><p>Go to <b>Tools</b> menu -> <b>Scripts</b> -> <b>Script Editor...</b></p></td> </tr> <tr> <td> <div class="popup-trigger"> <a href="<?php echo $imageUrlDir; ?> /GooglePasteScriptEditor.png"> <img src="<?php echo $imageUrlDir; ?> /GooglePasteScriptEditor.png" alt="Paste script text" height="68px" width="100px"/> <div class="popup-content"> <img src="<?php echo $imageUrlDir; ?> /GooglePasteScriptEditor.png" alt="Paste script text"/> </div> </a> </div> </td> <td> <p>Delete any text that is already there</p> <p><b>Copy</b> the text from <a target="_gscript" href="<?php echo $scriptLink; ?> ">THIS SCRIPT FILE</a> and <b>paste</b> it into the Google script editor</p> </td> </tr> <tr> <td> <div class="popup-trigger"> <a href="<?php echo $imageUrlDir; ?> /GoogleSaveScriptEditor.png"> <img src="<?php echo $imageUrlDir; ?> /GoogleSaveScriptEditor.png" alt="Create a new spreadsheet" height="100px" width="83px"/> <div class="popup-content"> <img src="<?php echo $imageUrlDir; ?> /GoogleSaveScriptEditor.png" alt="Create a new spreadsheet"/> </div> </a> </div> </td> <td> <p><b>Save</b> and <b>close</b> the script editor.</p> </td> </tr> <tr> <td> <div class="popup-trigger"> <a href="<?php echo $imageUrlDir; ?> /GoogleEnterFormula.png"> <img src="<?php echo $imageUrlDir; ?> /GoogleEnterFormula.png" alt="Create a new spreadsheet" height="43px" width="100px"/> <div class="popup-content"> <img src="<?php echo $imageUrlDir; ?> /GoogleEnterFormula.png" alt="Create a new spreadsheet"/> </div> </a> </div> </td> <td> <p>Click on a cell A1 in the Spreadsheet (or any cell)</p> <p>Enter in the cell the formula:</p> <p><code><?php echo "=CF7ToDBData(\"{$siteUrl}\", \"{$formName}\", \"{$search}\", \"user\", \"pwd\")"; ?> </code></p> <p>Replacing <b>user</b> and <b>pwd</b> with your <u>WordPress</u> site user name and password</p> </td> </tr> <tr> </tr> </tbody> </table> <span style="color:red; font-weight:bold;"> WARNING: since you are putting your login information into the Google Spreadsheet, be sure not to share the spreadsheet with others.</span> <?php $html = ob_get_contents(); ob_end_clean(); CFDBDie::wp_die($html, __('How to Set up Google Spreadsheet to pull data from WordPress', 'contact-form-7-to-database-extension'), array('response' => 200, 'back_link' => true)); }
protected function assertSecurityErrorMessage() { $errMsg = __('You do not have sufficient permissions to access this data.', 'contact-form-7-to-database-extension'); if ($this->isFromShortCode) { echo $errMsg; } else { include_once 'CFDBDie.php'; CFDBDie::wp_die($errMsg); } }