function CF7DBPlugin_init($file) { require_once 'CF7DBPlugin.php'; $aPlugin = new CF7DBPlugin(); // Install the plugin // NOTE: this file gets run each time you *activate* the plugin. // So in WP when you "install" the plugin, all that does it dump its files in the plugin-templates directory // but it does not call any of its code. // So here, the plugin tracks whether or not it has run its install operation, and we ensure it is run only once // on the first activation if (!$aPlugin->isInstalled()) { $aPlugin->install(); } else { // Perform any version-upgrade activities prior to activation (e.g. database changes) $aPlugin->upgrade(); } // Add callbacks to hooks $aPlugin->addActionsAndFilters(); if (!$file) { $file = __FILE__; } // Register the Plugin Activation Hook register_activation_hook($file, array(&$aPlugin, 'activate')); // Register the Plugin Deactivation Hook register_deactivation_hook($file, array(&$aPlugin, 'deactivate')); }
/** * @param $atts array of short code attributes * @param $content string not used * @return string export link */ public function handleShortcode($atts, $content = null) { $atts = $this->decodeAttributes($atts); $params = array(); $params[] = admin_url('admin-ajax.php'); $params[] = '?action=cfdb-export'; $special = array('urlonly', 'linktext', 'role'); foreach ($atts as $key => $value) { if (!in_array($key, $special)) { $params[] = sprintf('&%s=%s', urlencode($key), urlencode($value)); } else { if ($key == 'role') { require_once 'CF7DBPlugin.php'; $plugin = new CF7DBPlugin(); $isAuth = $plugin->isUserRoleEqualOrBetterThan($value); if (!$isAuth) { // Not authorized. Print no link. return ''; } } } } $url = implode($params); if (isset($atts['urlonly']) && $atts['urlonly'] == 'true') { return $url; } $linkText = __('Export', 'contact-form-7-to-database-extension'); if (isset($atts['linktext'])) { $linkText = $atts['linktext']; } return sprintf('<a href="%s">%s</a>', $url, $linkText); }
/** * Mock WP get_options * @param $optionName * @return null */ function get_option($optionName) { $optionName = substr($optionName, strlen('CF7DBPlugin_')); $plugin = new CF7DBPlugin(); $options = $plugin->getOptionMetaData(); if (isset($options[$optionName])) { if (strpos($optionName, 'Can') === 0) { return "Anyone"; } switch ($optionName) { case 'SubmitDateTimeFormat': return 'F j, Y g:i a'; case 'date_format': return 'F j, Y'; case 'time_format': return 'g:i a'; } $count = count($options[$optionName]); if ($count == 1) { return null; } return $options[$optionName][1]; } return null; }
/** * @return array|bool associative array of the row values or false if no more row exists */ public function nextRow() { if ($this->dataIterator->nextRow()) { $row = array(); $row['submit_time'] = $this->dataIterator->row['submit_time']; $fields_with_file = null; if (isset($this->dataIterator->row['fields_with_file']) && $this->dataIterator->row['fields_with_file'] != null) { $fields_with_file = explode(',', $this->dataIterator->row['fields_with_file']); if ($this->plugin == null) { require_once 'CF7DBPlugin.php'; $this->plugin = new CF7DBPlugin(); } } foreach ($this->dataIterator->displayColumns as $aCol) { $row[$aCol] = $this->dataIterator->row[$aCol]; // If it is a file, add in the URL for it by creating a field name appended with '_URL' if ($fields_with_file && in_array($aCol, $fields_with_file)) { $row[$aCol . '_URL'] = $this->plugin->getFileUrl($row['submit_time'], $this->formName, $aCol); } } return $row; } else { return false; } }
public function saveFormData($form_id) { try { $title = get_the_title($form_id); $converter = new CFDBPostDataConverter(); $converter->addExcludeField('post_nonce_field'); $converter->addExcludeField('form-type'); $converter->addExcludeField('fms-ajax'); $converter->addExcludeField('action'); $data = $converter->convert($title); // CFDBPostDataConverter won't capture files how they are organized here if (is_array($_FILES) && !empty($_FILES)) { foreach ($_FILES as $key => $file) { if (is_array($file['tmp_name'])) { for ($idx = 0; $idx < count($file['tmp_name']); ++$idx) { if (is_uploaded_file($file['tmp_name'][$idx])) { $fileKey = $idx > 0 ? $key . $idx : $key; $data->posted_data[$fileKey] = $file['name'][$idx]; $data->uploaded_files[$fileKey] = $file['tmp_name'][$idx]; } } } } } return $this->plugin->saveFormData($data); } catch (Exception $ex) { $this->plugin->getErrorLog()->logException($ex); } return true; }
/** * @param $form_data * @return bool */ public function saveFormData($form_data) { try { $data = $this->convertData($form_data); return $this->plugin->saveFormData($data); } catch (Exception $ex) { $this->plugin->getErrorLog()->logException($ex); } return true; }
/** * Function courtesy of Mike Challis, author of Fast Secure Contact Form. * Displays Admin Panel links in FSCF plugin menu * @return void */ public function fscfMenuLinks() { $displayName = $this->plugin->getPluginDisplayName(); echo ' <p> ' . $displayName . ' | <a href="admin.php?page=' . $this->plugin->getDBPageSlug() . '">' . __('Database', 'contact-form-7-to-database-extension') . '</a> | <a href="admin.php?page=CF7DBPluginSettings">' . __('Database Options', 'contact-form-7-to-database-extension') . '</a> | <a href="admin.php?page=' . $this->plugin->getShortCodeBuilderPageSlug() . '">' . __('Build Short Code', 'contact-form-7-to-database-extension') . '</a> | <a href="http://cfdbplugin.com/">' . __('Reference', 'contact-form-7-to-database-extension') . '</a> </p> '; }
/** * @param $post_id int * @param $all_values array * @param $extra_values array * @return object */ public function saveFormData($post_id, $all_values, $extra_values) { try { $data = $this->convertData($post_id, $all_values); return $this->plugin->saveFormData($data); } catch (Exception $ex) { $this->plugin->getErrorLog()->logException($ex); } return true; }
/** * @param $dataForms array * @param $postID array * @param $post array * @param $submissionsData array * @param $dataContentEmail array * @param $nameFileByIdentifier array * @param $requiredField array * @param $fileAttach array * @return bool */ public function saveFormData($dataForms, $postID, $post, $submissionsData, $dataContentEmail, $nameFileByIdentifier, $requiredField, $fileAttach) { try { $data = $this->convertData($dataForms, $postID, $post, $submissionsData, $dataContentEmail, $nameFileByIdentifier, $requiredField, $fileAttach); return $this->plugin->saveFormData($data); } catch (Exception $ex) { $this->plugin->getErrorLog()->logException($ex); } return true; }
/** * Very Simple Signup Form * @param $form_data * @return bool */ public function saveVssfFormData($form_data) { try { $title = 'Very Simple Signup Form'; $data = $this->convertData($form_data, $title); return $this->plugin->saveFormData($data); } catch (Exception $ex) { $this->plugin->getErrorLog()->logException($ex); } return true; }
function ajax_action_submit_contact_form() { $content = file_get_contents("php://input"); if ($content) { $contactData = json_decode($content, true); $data = array('title' => '联系我们', 'posted_data' => $contactData); $data = (object) $data; require_once ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CF7DBPlugin.php'; $plugin = new CF7DBPlugin(); $plugin->saveFormData($data); } die; }
/** * @param $form array * @param $referrer array * @param $process_id string * @return bool */ public function saveFormData($form, $referrer, $process_id) { try { // debug // $this->plugin->getErrorLog()->log('$form: ' . print_r($form, true)); // $this->plugin->getErrorLog()->log('$referrer: ' . print_r($referrer, true)); // $this->plugin->getErrorLog()->log('$process_id: ' . print_r($process_id, true)); // global $processed_data; // $this->plugin->getErrorLog()->log('$processed_data: ' . print_r($processed_data, true)); $data = $this->convertData($form); return $this->plugin->saveFormData($data); } catch (Exception $ex) { $this->plugin->getErrorLog()->logException($ex); } return true; }
/** * @param $form array * @param $referrer array * @param $process_id string * @param int $entry_id * @return bool */ public function saveFormData($form, $referrer, $process_id, $entry_id) { if (!class_exists('Caldera_Forms')) { // Caldera not installed return true; } try { // debug // $this->plugin->getErrorLog()->log('$form: ' . print_r($form, true)); // $this->plugin->getErrorLog()->log('$referrer: ' . print_r($referrer, true)); // $this->plugin->getErrorLog()->log('$process_id: ' . print_r($process_id, true)); // $this->plugin->getErrorLog()->log('$entry_id: ' . print_r($entry_id, true)); $data = $this->convertData($form, $entry_id); return $this->plugin->saveFormData($data); } catch (Exception $ex) { $this->plugin->getErrorLog()->logException($ex); } return true; }
public function saveFormData($bool, $new_post, $form_params) { // $msg = '$new_post=' . print_r($new_post, true) . "\n" . // '$form_params=' . print_r($form_params, true); // $this->plugin->getErrorLog()->log($msg); try { if (is_array($new_post)) { $postedData = array(); foreach ($new_post as $key => $value) { $postedData[$key] = urldecode($value); } $title = 'Enfold'; if (is_array($form_params) && isset($form_params['heading']) && $form_params['heading']) { $title = strip_tags($form_params['heading']); } $data = (object) array('title' => $title, 'posted_data' => $postedData, 'uploaded_files' => array()); $this->plugin->saveFormData($data); } } catch (Exception $ex) { } return true; }
/** * @param int $entry_id * @param int $form_id * @return bool */ public function saveFormData($entry_id, $form_id) { global $wpdb; // Get form title $sql = "SELECT name FROM {$wpdb->prefix}frm_forms WHERE id = %d"; $sql = $wpdb->prepare($sql, $form_id); $title = $wpdb->get_var($sql); if (!$title) { return true; } // Get submission values $sql = "SELECT f.name AS 'key', m.meta_value AS 'value' FROM {$wpdb->prefix}frm_item_metas m, wp_frm_fields f WHERE m.field_id = f.id AND m.item_id = %d"; $sql = $wpdb->prepare($sql, $entry_id); $results = $wpdb->get_results($sql, ARRAY_A); if (!$results) { return true; } $postedData = array(); foreach ($results as $result) { $key = $result['key']; $value = $result['value']; if (is_serialized($value)) { $value = unserialize($value); if (is_array($value)) { $value = implode(',', $value); } else { $value = (string) $value; // shouldn't get here } } $postedData[$key] = $value; } // Save submission $data = (object) array('title' => $title, 'posted_data' => $postedData, 'uploaded_files' => array()); // todo $this->plugin->saveFormData($data); return true; }
/** * Fetch next row into variable * @return bool if next row exists */ public function nextRow() { if (!$this->results) { return false; } while (true) { if (!$this->onFirstRow) { $this->row = mysql_fetch_assoc($this->results); } $this->onFirstRow = false; if (!$this->row) { mysql_free_result($this->results); $this->results = null; return false; } // Format the date $submitTime = $this->row['Submitted']; $this->row['submit_time'] = $submitTime; $this->row['Submitted'] = $this->plugin->formatDate($submitTime); // Determine if row is filtered if ($this->rowFilter) { $match = $this->rowFilter->evaluate($this->row); if (!$match) { continue; } } $this->idx += 1; if ($this->limitStart && $this->idx < $this->limitStart) { continue; } if ($this->limitEnd && $this->idx >= $this->limitEnd) { while (mysql_fetch_array($this->results)) { } mysql_free_result($this->results); $this->results = null; $this->row = null; return false; } // Keep the unformatted submitTime if needed if ($this->submitTimeKeyName) { $this->row[$this->submitTimeKeyName] = $submitTime; } break; } if (!$this->row) { mysql_free_result($this->results); $this->results = null; } return $this->row ? true : false; }
public function getNewSubmitTime($submitTime) { global $wpdb; $table = $this->plugin->getSubmitsTableName(); $inDBSql = 'select count(submit_time) from ' . $table . ' where submit_time = %F'; while (true) { $submitTime = $submitTime + 0.0001; // Propose new submit time $inDbAlready = $wpdb->get_var($wpdb->prepare($inDBSql, $submitTime)); if (!$inDbAlready) { break; } } return $submitTime; }
/** * Generate the submit_time and submit_url so they can be added to CF7 mail * @param $posted_data array * @return array */ public function generateSubmitTimeForCF7($posted_data) { try { $time = $this->plugin->generateSubmitTime(); $posted_data['submit_time'] = $time; // No longer generating submit_url because it seems to cause CF7 to think it is // a spam submission and it drops it. // $url = get_admin_url() . sprintf('admin.php?page=%s&submit_time=%s', // // $this->getDBPageSlug(), // $time); // $posted_data['submit_url'] = $url; } catch (Exception $ex) { $this->plugin->getErrorLog()->logException($ex); } return $posted_data; }
/** * Fetch next row into variable * @return bool if next row exists */ public function nextRow() { while (true) { if (!$this->onFirstRow) { $this->row = $this->fetchRow(); } $this->onFirstRow = false; if (!$this->row) { $this->freeResult(); return false; } // Format the date if (!isset($this->row['submit_time']) && isset($this->row['Submitted']) && is_numeric($this->row['Submitted'])) { $submitTime = $this->row['Submitted']; $this->row['submit_time'] = $submitTime; $this->row['Submitted'] = $this->plugin->formatDate($submitTime); } // Determine if row is filtered if ($this->rowFilter) { $match = $this->rowFilter->evaluate($this->row); if (!$match) { continue; } } $this->idx += 1; if ($this->limitStart && $this->idx < $this->limitStart) { continue; } if ($this->limitEnd && $this->idx >= $this->limitEnd) { while ($this->row = $this->fetchRow()) { } $this->freeResult(); $this->row = null; return false; } // Keep the unformatted submitTime if needed if (isset($submitTime) && $this->submitTimeKeyName) { $this->row[$this->submitTimeKeyName] = $submitTime; } break; } if (!$this->row) { $this->freeResult(); } return $this->row ? true : false; }
<?php /* "Contact Form to Database Extension" Copyright (C) 2011 Michael Simpson (email : michael.d.simpson@gmail.com) This file is part of Contact Form to Database Extension. Contact Form to Database Extension is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Contact Form to Database Extension is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Contact Form to Database Extension. If not, see <http://www.gnu.org/licenses/>. */ if (!defined('ABSPATH') && !defined('WP_UNINSTALL_PLUGIN')) { exit; } require_once 'CF7DBPlugin.php'; $aPlugin = new CF7DBPlugin(); $aPlugin->uninstall();
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)); }
/** * @param $plugin CF7DBPlugin * @return void */ function display(&$plugin) { if ($plugin == null) { $plugin = new CF7DBPlugin(); } $forms = $plugin->getForms(); $importUrl = admin_url('admin-ajax.php') . '?action=cfdb-importcsv'; ?> <h2><?php _e('Import CSV File into Form', 'contact-form-7-to-database-extension'); ?> </h2> <form enctype="multipart/form-data" action="<?php echo $importUrl; ?> " method="post"> <table> <tbody> <tr> <td><label for="file"><?php _e('File', 'contact-form-7-to-database-extension'); ?> </label></td> <td><input type="file" name="file" id="file" size="50"></td> </tr> <tr> <td><input type="radio" name="into" id="new" value="new" checked> <?php _e('New Form', 'contact-form-7-to-database-extension'); ?> </td> <td><input type="text" name="newformname" id="newformname" size="50"/></td> </tr> <tr> <td><input type="radio" name="into" id="existing" value="into"> <?php _e('Existing Form', 'contact-form-7-to-database-extension'); ?> </td> <td> <select name="form" id="form"> <option value=""></option> <?php foreach ($forms as $formName) { echo "<option value=\"{$formName}\">{$formName}</option>"; } ?> </select> </td> </tr> </tbody> </table> <input type="submit" name="<?php _e('Import', 'contact-form-7-to-database-extension'); ?> " id="importsubmit" value="import"> </form> <script type="text/javascript"> jQuery('#file').change(function () { var val = jQuery(this).val(); val = val.substring(val.lastIndexOf('/') + 1); val = val.substring(val.lastIndexOf('\\') + 1); val = val.replace(/\.([^\.])*$/, ""); jQuery('#newformname').val(val); }); </script> <h2><?php _e('Backup Form to CSV File', 'contact-form-7-to-database-extension'); ?> </h2> <ul> <li><?php _e('Backup a form into a CSV file that can be re-imported without loss of data.', 'contact-form-7-to-database-extension'); ?> </li> <li><?php _e('Limitation: this will not export file uploads.', 'contact-form-7-to-database-extension'); ?> </li> <li><?php _e('Limitation: extremely large numbers of records in your form may cause the export operation on your server to run out of memory, thereby not giving you all the rows.', 'contact-form-7-to-database-extension'); ?> </li> </ul> <form method="get" action="<?php echo $plugin->getPluginDirUrl(); ?> export.php"> <input type="hidden" name="enc" value="CSV"/> <input type="hidden" name="bak" value="true"/> <select name="form"> <option value=""></option> <?php foreach ($forms as $formName) { echo "<option value=\"{$formName}\">{$formName}</option>"; } ?> </select> <input type="submit" name="<?php _e('Export', 'contact-form-7-to-database-extension'); ?> " value="export"> </form> <?php }
public function outputJavascript() { ?> <script type="text/javascript" language="JavaScript"> var shortCodeDocUrls = { '': 'http://cfdbplugin.com/?page_id=89', '[cfdb-html]': 'http://cfdbplugin.com/?page_id=284', '[cfdb-table]': 'http://cfdbplugin.com/?page_id=93', '[cfdb-datatable]': 'http://cfdbplugin.com/?page_id=91', '[cfdb-value]': 'http://cfdbplugin.com/?page_id=98', '[cfdb-count]': 'http://cfdbplugin.com/?page_id=278', '[cfdb-json]': 'http://cfdbplugin.com/?page_id=96', '[cfdb-export-link]': 'http://cfdbplugin.com/?page_id=419' }; function showHideOptionDivs() { var shortcode = jQuery('#shortcode_ctrl').val(); jQuery('#doc_url_tag').attr('href', shortCodeDocUrls[shortcode]); jQuery('#doc_url_tag').html(shortcode + " <?php echo htmlspecialchars(__('Documentation', 'contact-form-7-to-database-extension')); ?> "); switch (shortcode) { case "[cfdb-html]": jQuery('#show_hide_div').show(); jQuery('#limitorder_div').show(); jQuery('#html_format_div').hide(); jQuery('#dt_options_div').hide(); jQuery('#editcolumns_div').hide(); jQuery('#json_div').hide(); jQuery('#value_div').hide(); jQuery('#template_div').show(); jQuery('#url_link_div').hide(); jQuery('#headers_div').hide(); break; case "[cfdb-table]": jQuery('#show_hide_div').show(); jQuery('#limitorder_div').show(); jQuery('#html_format_div').show(); jQuery('#dt_options_div').hide(); jQuery('#editcolumns_div').hide(); jQuery('#json_div').hide(); jQuery('#value_div').hide(); jQuery('#template_div').hide(); jQuery('#url_link_div').hide(); jQuery('#headers_div').show(); break; case "[cfdb-datatable]": jQuery('#show_hide_div').show(); jQuery('#limitorder_div').show(); jQuery('#html_format_div').show(); <?php if (!$this->plugin->isEditorActive()) { ?> jQuery('#edit_mode_cntl').attr('disabled', 'disabled'); <?php } ?> jQuery('#dt_options_div').show(); jQuery('#editcolumns_div').show(); jQuery('#json_div').hide(); jQuery('#value_div').hide(); jQuery('#template_div').hide(); jQuery('#url_link_div').hide(); jQuery('#headers_div').show(); break; case "[cfdb-value]": jQuery('#show_hide_div').show(); jQuery('#limitorder_div').show(); jQuery('#html_format_div').hide(); jQuery('#dt_options_div').hide(); jQuery('#editcolumns_div').hide(); jQuery('#json_div').hide(); jQuery('#value_div').show(); jQuery('#template_div').hide(); jQuery('#url_link_div').hide(); jQuery('#headers_div').hide(); break; case "[cfdb-count]": jQuery('#show_hide_div').hide(); jQuery('#limitorder_div').hide(); jQuery('#html_format_div').hide(); jQuery('#dt_options_div').hide(); jQuery('#editcolumns_div').hide(); jQuery('#json_div').hide(); jQuery('#value_div').hide(); jQuery('#template_div').hide(); jQuery('#url_link_div').hide(); jQuery('#headers_div').hide(); break; case "[cfdb-json]": jQuery('#show_hide_div').show(); jQuery('#limitorder_div').show(); jQuery('#html_format_div').hide(); jQuery('#dt_options_div').hide(); jQuery('#editcolumns_div').hide(); jQuery('#json_div').show(); jQuery('#value_div').hide(); jQuery('#template_div').hide(); jQuery('#url_link_div').hide(); jQuery('#headers_div').show(); break; case "[cfdb-export-link]": jQuery('#show_hide_div').show(); jQuery('#limitorder_div').show(); jQuery('#html_format_div').hide(); jQuery('#dt_options_div').hide(); jQuery('#editcolumns_div').hide(); jQuery('#json_div').hide(); jQuery('#value_div').hide(); jQuery('#template_div').hide(); jQuery('#url_link_div').show(); jQuery('#headers_div').show(); break; default: jQuery('#show_hide_div').show(); jQuery('#limitorder_div').show(); jQuery('#html_format_div').hide(); jQuery('#dt_options_div').hide(); jQuery('#editcolumns_div').hide(); jQuery('#json_div').hide(); jQuery('#value_div').hide(); jQuery('#template_div').hide(); jQuery('#url_link_div').hide(); jQuery('#headers_div').hide(); break; } var exportSelected = jQuery('#export_cntl').val(); jQuery('#label_export_link').show(); jQuery('#label_gld_function').hide(); jQuery('#userpass_span_msg').show(); jQuery('#gld_userpass_span_msg').hide(); if (exportSelected) { if (exportSelected == 'RSS') { jQuery('#itemtitle_span').show(); jQuery('#csvdelim_span').hide(); } else { jQuery('#itemtitle_span').hide(); jQuery('#headers_div').show(); if (exportSelected == "GLD") { jQuery('#userpass_span_msg').hide(); jQuery('#gld_userpass_span_msg').show(); jQuery('#label_export_link').hide(); jQuery('#label_gld_function').show(); } if (exportSelected == "JSON") { jQuery('#json_div').show(); } else { jQuery('#json_div').hide(); } if (['CSVUTF8BOM', 'CSVUTF8', 'CSVSJIS'].indexOf(exportSelected) > -1) { jQuery('#csvdelim_span').show(); } else { jQuery('#csvdelim_span').hide(); } } } else { jQuery('#itemtitle_span').hide(); jQuery('#csvdelim_span').hide(); jQuery('#userpass_span_msg').show(); jQuery('#gld_userpass_span_msg').hide(); jQuery('#label_gld_script').hide(); } } function getValue(attr, value, errors) { if (value) { if (errors && value.indexOf('"') > -1) { errors.push('<?php echo htmlspecialchars(__('Error: "', 'contact-form-7-to-database-extension')); ?> ' + attr + '<?php echo htmlspecialchars(__('" should not contain double-quotes (")', 'contact-form-7-to-database-extension')); ?> '); value = value.replace('"', "'"); } return attr + '="' + value + '"'; } return ''; } function pushNameValue(attr, value, array, errors) { if (value) { if (errors && value.indexOf('"') > -1) { errors.push('<?php echo htmlspecialchars(__('Error: "', 'contact-form-7-to-database-extension')); ?> ' + attr + '<?php echo htmlspecialchars(__('" should not contain double-quotes (")', 'contact-form-7-to-database-extension')); ?> '); value = value.replace('"', "'"); } array.push(attr); array.push(value); return true; } return false; } function getValueUrl(attr, value) { if (value) { return attr + '=' + encodeURIComponent(value) } return ''; } function join(arr, delim) { if (delim == null) { delim = ' '; } var tmp = []; for (idx = 0; idx < arr.length; idx++) { if (arr[idx] != '') { tmp.push(arr[idx]); } } return tmp.join(delim); } function chopLastChar(text) { return text ? text.substr(0, text.length - 1) : text; } function createShortCodeAndExportLink() { var scElements = []; var scUrlElements = []; var scValidationErrors = []; var exportUrlElements = []; var exportValidationErrors = []; var googleScriptElements = []; var googleScriptValidationErrors = []; var shortcode = jQuery('#shortcode_ctrl').val(); if (shortcode == '') { jQuery('#shortcode_result_text').html(''); } scElements.push(chopLastChar(shortcode)); var pushErrorMessagesToAll = function (errMsg) { scValidationErrors.push(errMsg); exportValidationErrors.push(errMsg); googleScriptValidationErrors.push(errMsg); }; var formName = jQuery('#form_name_cntl').val(); var errMsg; if (!formName || Array.isArray(formName) && !formName.length) { errMsg = '<?php echo htmlspecialchars(__('Error: no form is chosen', 'contact-form-7-to-database-extension')); ?> '; jQuery('#form_validations_text').html(errMsg); pushErrorMessagesToAll(errMsg); } else { jQuery('#form_validations_text').html(''); scElements.push('form="' + formName + '"'); scUrlElements.push('form=' + encodeURIComponent(formName)); exportUrlElements.push('form=' + encodeURIComponent(formName)); googleScriptElements.push('<?php echo $this->siteUrl; ?> '); googleScriptElements.push(formName); googleScriptElements.push('<?php echo is_user_logged_in() ? wp_get_current_user()->user_login : '******'; ?> '); googleScriptElements.push('<password>'); } var pushValueToAll = function (name, val) { scElements.push(getValue(name, val, scValidationErrors)); scUrlElements.push(getValueUrl(name, val)); exportUrlElements.push(getValueUrl(name, val)); pushNameValue(name, val, googleScriptElements, googleScriptValidationErrors); }; var val; if (shortcode != '[cfdb-count]') { val = jQuery('#show_cntl').val(); pushValueToAll('show', val); val = jQuery('#hide_cntl').val(); pushValueToAll('hide', val); } val = jQuery('#role_cntl').val(); pushValueToAll('role', val); val = jQuery('#permissionmsg_cntl').val(); pushValueToAll('permissionmsg', val); val = jQuery('#trans_cntl').val(); pushValueToAll('trans', val); var handleFilterSearch = function (filterName, filter, searchName, search) { if (filter) { pushValueToAll(filterName, filter); if (search) { var errMsg = '<?php echo htmlspecialchars(__('Warning: "search" field ignored because FIELD is used (use one but not both)', 'contact-form-7-to-database-extension')); ?> '.replace('FIELD', filterName); pushErrorMessagesToAll(errMsg); } } else { pushValueToAll(searchName, search); } }; var filter = jQuery('#filter_cntl').val(); var search = jQuery('#search_cntl').val(); handleFilterSearch('filter', filter, 'search', search); var tfilter = jQuery('#tfilter_cntl').val(); var tsearch = jQuery('#tsearch_cntl').val(); handleFilterSearch('tfilter', tfilter, 'tsearch', tsearch); if (shortcode != '[cfdb-count]') { var handleLimit = function (limitName, limitRows, limitStart) { if (limitStart && !limitRows) { errMsg = '<?php echo htmlspecialchars(__('Error: "FIELD": if you provide a value for "Start Row" then you must also provide a value for "Num Rows"', 'contact-form-7-to-database-extension')); ?> '.replace('FIELD', limitName); pushErrorMessagesToAll(errMsg); } if (limitRows) { if (!/^\d+$/.test(limitRows)) { errMsg = '<?php echo htmlspecialchars(__('Error: "FIELD": "Num Rows" must be a positive integer', 'contact-form-7-to-database-extension')); ?> '.replace('FIELD', limitName); pushErrorMessagesToAll(errMsg); } else { var limitOption = ''; var limitOptionUrl = limitName + '='; if (limitStart) { if (!/^\d+$/.test(limitStart)) { errMsg = '<?php echo htmlspecialchars(__('Error: "FIELD": "Start Row" must be a positive integer', 'contact-form-7-to-database-extension')); ?> '.replace('FIELD', limitName); pushErrorMessagesToAll(errMsg); } else { limitOption += limitStart + ","; limitOptionUrl += encodeURIComponent(limitStart + ","); } } limitOption += limitRows; limitOptionUrl += limitRows; scElements.push(limitName + '="' + limitOption + '"'); scUrlElements.push(limitOptionUrl); exportUrlElements.push(limitOptionUrl); pushNameValue(limitName, limitOption, googleScriptElements, googleScriptValidationErrors); } } }; var limitRows = jQuery('#limit_rows_cntl').val(); var limitStart = jQuery('#limit_start_cntl').val(); handleLimit('limit', limitRows, limitStart); var tlimitRows = jQuery('#tlimit_rows_cntl').val(); var tlimitStart = jQuery('#tlimit_start_cntl').val(); handleLimit('tlimit', tlimitRows, tlimitStart); val = jQuery('#random_cntl').val(); scElements.push(getValue('random', val, scValidationErrors)); scUrlElements.push(getValueUrl('random', val)); pushNameValue("random", val, googleScriptElements, googleScriptValidationErrors); if (jQuery('#unbuffered_cntl').is(':checked')) { scElements.push('unbuffered="true"'); scUrlElements.push(getValueUrl('unbuffered', 'true')); exportUrlElements.push('unbuffered=true'); pushNameValue("unbuffered", "true", googleScriptElements, googleScriptValidationErrors); } var handleOrderBy = function (name, val) { if (val) { var orderByElem = getValue(name, val, scValidationErrors); var orderByElemUrl = getValueUrl(name, val); var orderByDir = jQuery('#' + name + 'dir_cntl').val(); if (orderByDir) { orderBy += ' ' + orderByDir; orderByElem = chopLastChar(orderByElem) + ' ' + orderByDir + '"'; orderByElemUrl = orderByElemUrl + encodeURIComponent(' ' + orderByDir); } scElements.push(orderByElem); scUrlElements.push(orderByElemUrl); exportUrlElements.push(orderByElemUrl); pushNameValue(name, orderBy, googleScriptElements, googleScriptValidationErrors); } }; var orderBy = jQuery('#orderby_cntl').val(); handleOrderBy('orderby', orderBy); var torderBy = jQuery('#torderby_cntl').val(); handleOrderBy('torderby', torderBy); } var scText; switch (shortcode) { case '[cfdb-html]': val = jQuery('#filelinks_cntl').val(); scElements.push(getValue('filelinks', val, scValidationErrors)); scUrlElements.push(getValueUrl('filelinks', val)); val = jQuery('#wpautop_cntl').val(); scElements.push(getValue('wpautop', val, scValidationErrors)); scUrlElements.push(getValueUrl('wpautop', val)); val = jQuery('#stripbr_cntl').val(); scElements.push(getValue('stripbr', val, scValidationErrors)); scUrlElements.push(getValueUrl('stripbr', val)); var template = jQuery('#content_cntl').val(); var content = template; var contentBefore = jQuery('#before_cntl').val(); var contentAfter = jQuery('#after_cntl').val(); if (contentBefore) { content = "<?php echo CFDBShortCodeContentParser::BEFORE_START_DELIMITER; ?> " + contentBefore + "<?php echo CFDBShortCodeContentParser::BEFORE_END_DELIMITER; ?> " + content; } if (contentAfter) { content += "<?php echo CFDBShortCodeContentParser::AFTER_START_DELIMITER; ?> " + contentAfter + "<?php echo CFDBShortCodeContentParser::AFTER_END_DELIMITER; ?> "; } scUrlElements.push('content=' + encodeURIComponent(content)); scUrlElements.push('enc=HTMLTemplate'); scText = join(scElements) + ']' + // Escape html tags for display on page content.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>') + '[/cfdb-html]'; if (template == "") { scValidationErrors.push('<?php echo htmlspecialchars(__('Error: [cfdb-html] has empty Template. It will not output anything. ', 'contact-form-7-to-database-extension')); echo htmlspecialchars(__('(Shortcode Specific option)', 'contact-form-7-to-database-extension')); ?> '); jQuery('#content_cntl').addClass('validation'); // highlight template area } else { jQuery('#content_cntl').removeClass('validation'); // remove highlight template area } break; case '[cfdb-table]': if (!jQuery('#header_cntl').is(':checked')) { scElements.push('header="false"'); scUrlElements.push(getValueUrl('header', 'false')); pushNameValue("header", "false", googleScriptElements, googleScriptValidationErrors); } val = jQuery('#headers_cntl').val(); scElements.push(getValue('headers', val, scValidationErrors)); scUrlElements.push(getValueUrl('headers', val)); val = jQuery('#id_cntl').val(); scElements.push(getValue('id', val, scValidationErrors)); scUrlElements.push(getValueUrl('id', val)); val = jQuery('#class_cntl').val(); scElements.push(getValue('class', val, scValidationErrors)); scUrlElements.push(getValueUrl('class', val)); val = jQuery('#style_cntl').val(); scElements.push(getValue('style', val, scValidationErrors)); scUrlElements.push(getValueUrl('style', val)); var contentBefore = jQuery('#before_cntl').val(); var contentAfter = jQuery('#after_cntl').val(); var content = ''; if (contentBefore) { content = "<?php echo CFDBShortCodeContentParser::BEFORE_START_DELIMITER; ?> " + contentBefore + "<?php echo CFDBShortCodeContentParser::BEFORE_END_DELIMITER; ?> " + content; } if (contentAfter) { content += "<?php echo CFDBShortCodeContentParser::AFTER_START_DELIMITER; ?> " + contentAfter + "<?php echo CFDBShortCodeContentParser::AFTER_END_DELIMITER; ?> "; } scUrlElements.push('content=' + encodeURIComponent(content)); scUrlElements.push('enc=HTML'); scText = join(scElements) + ']'; if (content) { // Escape html tags for display on page scText += content.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>') + '[/cfdb-table]'; } break; case '[cfdb-datatable]': if (!jQuery('#header_cntl').is(':checked')) { scElements.push('header="false"'); scUrlElements.push(getValueUrl('header', 'false')); } val = jQuery('#headers_cntl').val(); scElements.push(getValue('headers', val, scValidationErrors)); scUrlElements.push(getValueUrl('headers', val)); var hadHeaders = val != ''; val = jQuery('#id_cntl').val(); scElements.push(getValue('id', val, scValidationErrors)); scUrlElements.push(getValueUrl('id', val)); val = jQuery('#class_cntl').val(); scElements.push(getValue('class', val, scValidationErrors)); scUrlElements.push(getValueUrl('class', val)); val = jQuery('#style_cntl').val(); scElements.push(getValue('style', val, scValidationErrors)); scUrlElements.push(getValueUrl('style', val)); val = jQuery('#edit_mode_cntl').val(); scElements.push(getValue('edit', val, scValidationErrors)); scUrlElements.push(getValueUrl('edit', val)); if (hadHeaders && val == 'true') { scValidationErrors.push('<?php echo htmlspecialchars(__('Error: "edit=true" will not work properly when setting "headers" ', 'contact-form-7-to-database-extension')); ?> '); } val = jQuery('#dt_options_cntl').val(); scElements.push(getValue('dt_options', val, scValidationErrors)); scUrlElements.push(getValueUrl('dt_options', val)); val = jQuery('#editcolumns_cntl').val(); scElements.push(getValue('editcolumns', val, scValidationErrors)); scUrlElements.push(getValueUrl('editcolumns', val)); var contentBefore = jQuery('#before_cntl').val(); var contentAfter = jQuery('#after_cntl').val(); var content = ''; if (contentBefore) { content = "<?php echo CFDBShortCodeContentParser::BEFORE_START_DELIMITER; ?> " + contentBefore + "<?php echo CFDBShortCodeContentParser::BEFORE_END_DELIMITER; ?> " + content; } if (contentAfter) { content += "<?php echo CFDBShortCodeContentParser::AFTER_START_DELIMITER; ?> " + contentAfter + "<?php echo CFDBShortCodeContentParser::AFTER_END_DELIMITER; ?> "; } scUrlElements.push('content=' + encodeURIComponent(content)); scUrlElements.push('enc=DT'); scText = join(scElements) + ']'; if (content) { // Escape html tags for display on page scText += content.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>') + '[/cfdb-datatable]'; } break; case '[cfdb-value]': val = jQuery('#function_cntl').val(); scElements.push(getValue('function', val, scValidationErrors)); scUrlElements.push(getValueUrl('function', val)); val = jQuery('#delimiter_cntl').val(); scElements.push(getValue('delimiter', val, scValidationErrors)); scUrlElements.push(getValueUrl('delimiter', val)); var contentBefore = jQuery('#before_cntl').val(); var contentAfter = jQuery('#after_cntl').val(); var content = ''; if (contentBefore) { content = "<?php echo CFDBShortCodeContentParser::BEFORE_START_DELIMITER; ?> " + contentBefore + "<?php echo CFDBShortCodeContentParser::BEFORE_END_DELIMITER; ?> " + content; } if (contentAfter) { content += "<?php echo CFDBShortCodeContentParser::AFTER_START_DELIMITER; ?> " + contentAfter + "<?php echo CFDBShortCodeContentParser::AFTER_END_DELIMITER; ?> "; } scUrlElements.push('content=' + encodeURIComponent(content)); scUrlElements.push('enc=VALUE'); scText = join(scElements) + ']'; if (content) { // Escape html tags for display on page scText += content.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>') + '[/cfdb-value]'; } break; case '[cfdb-count]': var contentBefore = jQuery('#before_cntl').val(); var contentAfter = jQuery('#after_cntl').val(); var content = ''; if (contentBefore) { content = "<?php echo CFDBShortCodeContentParser::BEFORE_START_DELIMITER; ?> " + contentBefore + "<?php echo CFDBShortCodeContentParser::BEFORE_END_DELIMITER; ?> " + content; } if (contentAfter) { content += "<?php echo CFDBShortCodeContentParser::AFTER_START_DELIMITER; ?> " + contentAfter + "<?php echo CFDBShortCodeContentParser::AFTER_END_DELIMITER; ?> "; } scUrlElements.push('content=' + encodeURIComponent(content)); scUrlElements.push('enc=COUNT'); scText = join(scElements) + ']'; // hopLastChar(scElements.join(' ')) + ']'; if (content) { // Escape html tags for display on page scText += content.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>') + '[/cfdb-count]'; } break; case '[cfdb-json]': if (!jQuery('#header_cntl').is(':checked')) { scElements.push('header="false"'); scUrlElements.push(getValueUrl('header', 'false')); pushNameValue("header", "false", googleScriptElements, googleScriptValidationErrors); } val = jQuery('#headers_cntl').val(); scElements.push(getValue('headers', val, scValidationErrors)); scUrlElements.push(getValueUrl('headers', val)); val = jQuery('#var_cntl').val(); scElements.push(getValue('var', val, scValidationErrors)); scUrlElements.push(getValueUrl('var', val)); val = jQuery('#format_cntl').val(); scElements.push(getValue('format', val, scValidationErrors)); scUrlElements.push(getValueUrl('format', val)); var contentBefore = jQuery('#before_cntl').val(); var contentAfter = jQuery('#after_cntl').val(); var content = ''; if (contentBefore) { content = "<?php echo CFDBShortCodeContentParser::BEFORE_START_DELIMITER; ?> " + contentBefore + "<?php echo CFDBShortCodeContentParser::BEFORE_END_DELIMITER; ?> " + content; } if (contentAfter) { content += "<?php echo CFDBShortCodeContentParser::AFTER_START_DELIMITER; ?> " + contentAfter + "<?php echo CFDBShortCodeContentParser::AFTER_END_DELIMITER; ?> "; } scUrlElements.push('content=' + encodeURIComponent(content)); scUrlElements.push('enc=JSON'); scText = join(scElements) + ']'; if (content) { // Escape html tags for display on page scText += content.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>') + '[/cfdb-json]'; } break; case '[cfdb-export-link]': enc = jQuery('#enc_cntl').val(); scElements.push(getValue('enc', enc, scValidationErrors)); scUrlElements.push(getValueUrl('enc', enc)); if (['CSVUTF8BOM', 'CSVUTF8', 'CSVSJIS'].indexOf(enc) > -1) { delim = jQuery('#export_link_csv_delim').val(); if (delim != ',') { scElements.push(getValue('delimiter', delim, scValidationErrors)); scUrlElements.push(getValueUrl('delimiter', delim)); } } scElements.push(getValue('urlonly', jQuery('#urlonly_cntl').val(), scValidationErrors)); scElements.push(getValue('linktext', jQuery('#linktext_cntl').val(), scValidationErrors)); if (!jQuery('#header_cntl').is(':checked')) { scElements.push('header="false"'); scUrlElements.push(getValueUrl('header', 'false')); } val = jQuery('#headers_cntl').val(); scElements.push(getValue('headers', val, scValidationErrors)); scUrlElements.push(getValueUrl('headers', val)); scText = join(scElements) + ']'; break; default: scText = shortcode; break; } var urlBase = '<?php echo $this->plugin->getAdminUrlPrefix('admin-ajax.php'); ?> action=cfdb-export&'; if (shortcode) { // Output short code text var scUrl = urlBase + join(scUrlElements, '&'); jQuery('#shortcode_result_text').html('<a target="_cfdb_sc_results" href="' + scUrl + '">' + scText + '</a>'); // Output short code errors jQuery('#shortcode_validations_text').html(scValidationErrors.join('<br/>')); } else { // Don't report errors jQuery('#shortcode_validations_text').html(''); } // Export link or Google Spreadsheet function call var exportSelection = jQuery('#export_cntl').val(); if (exportSelection) { if (exportSelection != 'GLD') { exportUrlElements.push(getValueUrl('enc', exportSelection)); } if (exportSelection == 'RSS') { exportUrlElements.push(getValueUrl('itemtitle', jQuery('#add_itemtitle').val())); } else { if (!jQuery('#header_cntl').is(':checked')) { exportUrlElements.push(getValueUrl('header', 'false')); pushNameValue("header", "false", googleScriptElements, googleScriptValidationErrors); } val = jQuery('#headers_cntl').val(); exportUrlElements.push(getValueUrl('headers', val, scValidationErrors)); pushNameValue("headers", val, googleScriptElements, googleScriptValidationErrors); exportUrlElements.push(getValueUrl('format', jQuery('#format_cntl').val(), scValidationErrors)); } if (['CSVUTF8BOM', 'CSVUTF8', 'CSVSJIS'].indexOf(exportSelection) > -1) { delim = jQuery('#csv_delim').val(); if (delim != '') { exportUrlElements.push(getValueUrl("delimiter", delim)); } } var user = jQuery("#gld_user").val(); var pass = jQuery("#gld_pass").val(); var obfuscate = jQuery('#obfuscate_cntl').is(':checked') if (user || pass) { if (obfuscate) { var key = 'kx82XcPjq8q8S!xafx%$&7p6'; exportUrlElements.push("l=" + encodeURI(printHex(des(key, user + "/" + pass, 1)))); } else { exportUrlElements.push("username="******"password="******"<?php echo htmlspecialchars(__('Warning: the function includes your WP login information. Avoid sharing it.', 'contact-form-7-to-database-extension')); ?> "); } // Output var exportUrl = urlBase + join(exportUrlElements, '&'); if (exportSelection == 'GLD') { if (!user || !pass) { exportValidationErrors.push("<?php echo htmlspecialchars(__('Error: WP User and Password are required for the Google Spreadsheet to pull data from your WordPress site.', 'contact-form-7-to-database-extension')); ?> "); } if (exportUrl.length > 255) { exportValidationErrors.push("<?php echo htmlspecialchars(__('Because the generated URL would be too long, you must use this alternative function and add its script to your Google Spreadsheet', 'contact-form-7-to-database-extension')); ?> "); jQuery('#label_gld_script').show(); jQuery('#label_gld_function').hide(); jQuery('#export_result_text').html(formName ? ("=cfdbdata(\"" + googleScriptElements.join("\", \"") + "\")") : ""); } else { jQuery('#export_result_text').html(formName ? ("<a target='_cfdb_exp_results' href='" + exportUrl + "'>=IMPORTDATA(\"" + exportUrl + "\")</a>") : ""); } } else { jQuery('#export_result_text').html(formName ? ('<a target="_cfdb_exp_results" href="' + exportUrl + '">' + exportUrl + '</a>') : ''); } // Output export errors jQuery('#export_validations_text').html(exportValidationErrors.join('<br/>')); } else { jQuery('#export_result_text').html(''); // Don't report errors jQuery('#export_validations_text').html(''); } } var getFormFieldsUrlBase = '<?php echo $this->plugin->getFormFieldsAjaxUrlBase(); ?> '; function getFormFields() { jQuery('[id^=add]').attr('disabled', 'disabled'); jQuery('[id^=btn]').attr('disabled', 'disabled'); var formName = jQuery('#form_name_cntl').val(); var url = getFormFieldsUrlBase + encodeURIComponent(formName); jQuery.ajax({ dataType: "json", url: url, async: false, success: function (json) { var optionsHtml = '<option value=""></option>'; jQuery(json).each(function () { optionsHtml += '<option value="' + this + '">' + this + '</option>'; }); optionsHtml += '<option value="$_POST(param)">$_POST(param)</option>'; optionsHtml += '<option value="$_GET(param)">$_GET(param)</option>'; optionsHtml += '<option value="$_COOKIE(param)">$_COOKIE(param)</option>'; jQuery('[id^=add]').html(optionsHtml).removeAttr('disabled'); jQuery('[id^=btn]').removeAttr('disabled'); } }); } function validateSubmitTime() { var url = "<?php echo $this->plugin->getValidateSubmitTimeAjaxUrlBase(); ?> " + jQuery('#filter_val').val(); jQuery.get(url, function (data) { alert(data); }); } function showValidateSubmitTimeHelp(show) { if (show) { jQuery('#span_validate_submit_time').show(); } else { jQuery('#span_validate_submit_time').hide(); } } function addFieldToShow() { var value = jQuery('#show_cntl').val(); if (value) { value += ','; } jQuery('#show_cntl').val(value + jQuery('#add_show').val()); createShortCodeAndExportLink(); } function addFieldToHide() { var value = jQuery('#hide_cntl').val(); if (value) { value += ','; } jQuery('#hide_cntl').val(value + jQuery('#add_hide').val()); createShortCodeAndExportLink(); } function addFieldToOrderBy(field) { var value = jQuery('#' + field + '_cntl').val(); if (value) { value += ','; } jQuery('#' + field + '_cntl').val(value + jQuery('#add_' + field).val()); createShortCodeAndExportLink(); } function addFieldToFilter(field) { var value = jQuery('#' + field + '_cntl').val(); if (value) { value += jQuery('#' + field + '_bool').val(); } value += jQuery('#add_' + field).val() + jQuery('#' + field + '_op').val() + jQuery('#' + field + '_val').val(); jQuery('#' + field + '_cntl').val(value); createShortCodeAndExportLink(); } function addToTrans() { var value = jQuery('#trans_cntl').val(); if (value) { value += "&&"; } var field = jQuery('#add_trans').val(); if (field) { value += field; value += "=" } value += jQuery('#trans_val').val(); jQuery('#trans_cntl').val(value); createShortCodeAndExportLink(); } function addFieldToHeaders() { var col = jQuery('#add_headers').val(); var disp = jQuery('#headers_val').val(); if (!col || !disp) { return; } var value = jQuery('#headers_cntl').val(); if (value) { value += ','; } value += col + '=' + disp; jQuery('#headers_cntl').val(value); createShortCodeAndExportLink(); } function addFieldToContent() { jQuery('#content_cntl').val(jQuery('#content_cntl').val() + '${' + jQuery('#add_content').val() + '}'); } function reset() { // Form jQuery('#form_name_cntl').val(<?php echo json_encode($this->requestParams['postedForm']); ?> ); getFormFields(); // Export File jQuery('#export_cntl').val(<?php echo json_encode($this->requestParams['postedEnc']); ?> ); jQuery('#add_itemtitle').val(<?php echo json_encode($this->requestParams['postedItemtitle']); ?> ); jQuery('#csv_delim').val(<?php echo json_encode(""); ?> ); // Short Code jQuery('#shortcode_ctrl').val(<?php echo json_encode($this->requestParams['postedSC']); ?> ); jQuery('#show_cntl').val(<?php echo json_encode($this->requestParams['postedShow']); ?> ); jQuery('#hide_cntl').val(<?php echo json_encode($this->requestParams['postedHide']); ?> ); jQuery('#role_cntl').val(<?php echo json_encode($this->requestParams['postedRole']); ?> ); jQuery('#permissionmsg_cntl').val(<?php echo json_encode($this->requestParams['postedPermissionmsg']); ?> ); jQuery('#trans_cntl').val(<?php echo json_encode($this->requestParams['postedTrans']); ?> ); jQuery('#search_cntl').val(<?php echo json_encode($this->requestParams['postedSearch']); ?> ); jQuery('#filter_cntl').val(<?php echo json_encode($this->requestParams['postedFilter']); ?> ); jQuery('#tsearch_cntl').val(<?php echo json_encode($this->requestParams['postedTSearch']); ?> ); jQuery('#tfilter_cntl').val(<?php echo json_encode($this->requestParams['postedTFilter']); ?> ); jQuery('#limit_rows_cntl').val(<?php echo json_encode($this->requestParams['postedLimitNumRows']); ?> ); jQuery('#limit_start_cntl').val(<?php echo json_encode($this->requestParams['postedLimitStart']); ?> ); jQuery('#random_cntl').val(<?php echo json_encode($this->requestParams['postedRandom']); ?> ); jQuery('#unbuffered_cntl').attr("checked", false); jQuery('#orderby_cntl').val(<?php echo json_encode($this->requestParams['postedOrderby']); ?> ); jQuery('#torderby_cntl').val(<?php echo json_encode($this->requestParams['postedTOrderby']); ?> ); jQuery('#header_cntl').prop("checked", <?php echo $this->requestParams['$postedHeader'] == 'false' ? 'false' : 'true'; ?> ); // default = true jQuery('#headers_cntl').val(<?php echo json_encode($this->requestParams['postedHeaders']); ?> ); jQuery('#id_cntl').val(<?php echo json_encode($this->requestParams['postedId']); ?> ); jQuery('#class_cntl').val(<?php echo json_encode($this->requestParams['postedClass']); ?> ); jQuery('#style_cntl').val(<?php echo json_encode($this->requestParams['postedStyle']); ?> ); jQuery('#edit_mode_cntl').val(<?php echo json_encode($this->requestParams['postedEdit']); ?> ); jQuery('#dt_options_cntl').val(<?php echo json_encode($this->requestParams['postedDtOptions']); ?> ); jQuery('#editcolumns_cntl').val(<?php echo json_encode($this->requestParams['postedEditcolumns']); ?> ); jQuery('#var_cntl').val(<?php echo json_encode($this->requestParams['postedVar']); ?> ); jQuery('#format_cntl').val(<?php echo json_encode($this->requestParams['postedFormat']); ?> ); jQuery('#function_cntl').val(<?php echo json_encode($this->requestParams['postedFunction']); ?> ); jQuery('#delimiter_cntl').val(<?php echo json_encode($this->requestParams['postedDelimiter']); ?> ); jQuery('#filelinks_cntl').val(<?php echo json_encode($this->requestParams['postedFilelinks']); ?> ); jQuery('#wpautop_cntl').val(<?php echo json_encode($this->requestParams['postedWpautop']); ?> ); jQuery('#stripbr_cntl').val(<?php echo json_encode($this->requestParams['postedStripbr']); ?> ); jQuery('#content_cntl').val(<?php echo json_encode($this->requestParams['postedContent']); ?> ); jQuery('#before_cntl').val(<?php echo json_encode($this->requestParams['postedContentBefore']); ?> ); jQuery('#after_cntl').val(<?php echo json_encode($this->requestParams['postedContentAfter']); ?> ); jQuery('#enc_cntl').val(<?php echo json_encode($this->requestParams['postedEnc']); ?> ); jQuery('#urlonly_cntl').val(<?php echo json_encode($this->requestParams['postedUrlonly']); ?> ); jQuery('#linktext_cntl').val(<?php echo json_encode($this->requestParams['postedLinktext']); ?> ); showValidateSubmitTimeHelp(false); showHideOptionDivs(); createShortCodeAndExportLink(); } jQuery.ajaxSetup({ cache: false }); jQuery(document).ready(function () { reset(); showHideOptionDivs(); createShortCodeAndExportLink(); jQuery('#shortcode_ctrl').change(showHideOptionDivs); jQuery('#shortcode_ctrl').change(createShortCodeAndExportLink); jQuery('select[id$="cntl"]').change(createShortCodeAndExportLink); jQuery('input[id$="cntl"]').keyup(createShortCodeAndExportLink); jQuery('textarea[id$="cntl"]').keyup(createShortCodeAndExportLink); jQuery('#form_name_cntl').change(getFormFields); jQuery('#btn_show').click(addFieldToShow); jQuery('#btn_hide').click(addFieldToHide); jQuery('#btn_orderby').click(function () { addFieldToOrderBy('orderby'); }); jQuery('#btn_torderby').click(function () { addFieldToOrderBy('torderby'); }); jQuery('#btn_filter').click(function () { addFieldToFilter('filter'); }); jQuery('#btn_tfilter').click(function () { addFieldToFilter('tfilter'); }); jQuery('#btn_trans').click(addToTrans); jQuery('#header_cntl').click(createShortCodeAndExportLink); jQuery('#unbuffered_cntl').click(createShortCodeAndExportLink); jQuery('#edit_mode_cntl').click(createShortCodeAndExportLink); jQuery('#btn_headers').click(addFieldToHeaders); jQuery('#btn_content').click(function () { addFieldToContent(); createShortCodeAndExportLink(); }); jQuery('#btn_editcolumns').click(function () { addFieldToOrderBy('editcolumns'); }); var showHideExportLinkDelimiter = function () { var enc = jQuery('#enc_cntl').val(); if (['CSVUTF8BOM', 'CSVUTF8', 'CSVSJIS'].indexOf(enc) > -1) { jQuery('#export_link_csvdelim_span').show(); } else { jQuery('#export_link_csvdelim_span').hide(); } }; jQuery('#enc_cntl').change(function () { showHideExportLinkDelimiter(); createShortCodeAndExportLink(); }); showHideExportLinkDelimiter(); jQuery('#urlonly_cntl').click(createShortCodeAndExportLink); jQuery('#reset_button').click(reset); jQuery('#btn_validate_submit_time').click(validateSubmitTime); jQuery('#add_filter').change(function () { showValidateSubmitTimeHelp(jQuery('#add_filter').val() == "submit_time"); }); jQuery('#export_cntl').change(function () { showHideOptionDivs(); createShortCodeAndExportLink(); }); jQuery('#add_itemtitle').change(createShortCodeAndExportLink); jQuery('#csv_delim').keyup(createShortCodeAndExportLink); jQuery('#export_link_csv_delim').keyup(createShortCodeAndExportLink); jQuery('#gld_user').change(createShortCodeAndExportLink); jQuery('#gld_user').keyup(createShortCodeAndExportLink); jQuery('#gld_pass').change(createShortCodeAndExportLink); jQuery('#gld_pass').keyup(createShortCodeAndExportLink); jQuery('#obfuscate_cntl').click(createShortCodeAndExportLink); jQuery('#form_name_cntl').change(createShortCodeAndExportLink); }); </script> <?php }
/** * Format input date string * @param $time int same as returned from PHP time() * @return string formatted date according to saved options */ public function formatDate($time) { // This method gets executed in a loop. Cache some variable to avoid // repeated get_option calls to the database if (CF7DBPlugin::$checkForCustomDateFormat) { if ($this->getOption('UseCustomDateTimeFormat', 'true') == 'true') { CF7DBPlugin::$customDateFormat = $this->getOption('SubmitDateTimeFormat', 'Y-m-d H:i:s P'); } else { CF7DBPlugin::$dateFormat = get_option('date_format'); CF7DBPlugin::$timeFormat = get_option('time_format'); } // Convert time to local timezone date_default_timezone_set(get_option('timezone_string')); CF7DBPlugin::$checkForCustomDateFormat = false; } // Support Jalali dates but looking for wp-jalali plugin and // using its 'jdate' function if (!function_exists('is_plugin_active') && @file_exists(ABSPATH . 'wp-admin/includes/plugin.php')) { include_once ABSPATH . 'wp-admin/includes/plugin.php'; } if (function_exists('is_plugin_active') && is_plugin_active('wp-jalali/wp-jalali.php')) { $jDateFile = WP_PLUGIN_DIR . '/wp-jalali/inc/jalali-core.php'; if (@file_exists($jDateFile)) { include_once $jDateFile; if (function_exists('jdate')) { //return jdate('l, F j, Y'); if (CF7DBPlugin::$customDateFormat) { return jdate(CF7DBPlugin::$customDateFormat, $time); } else { return jdate(CF7DBPlugin::$dateFormat . ' ' . CF7DBPlugin::$timeFormat, $time); } } } } if (CF7DBPlugin::$customDateFormat) { return date(CF7DBPlugin::$customDateFormat, $time); } else { return date_i18n(CF7DBPlugin::$dateFormat . ' ' . CF7DBPlugin::$timeFormat, $time); } }
/** * @dataProvider dataProvider * @param $option string * @param $expected array */ public function test_export($option, $expected) { $cfdb = new CF7DBPlugin(); $actual = $cfdb->parseOption($option); $this->assertEquals($expected, $actual); }
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)); }
function display(&$plugin) { if ($plugin == null) { $plugin = new CF7DBPlugin(); } $canEdit = $plugin->canUserDoRoleOption('CanChangeSubmitData'); $this->pageHeader($plugin); global $wpdb; $tableName = $plugin->getSubmitsTableName(); $useDataTables = $plugin->getOption('UseDataTablesJS', 'true', true) == 'true'; $tableHtmlId = 'cf2dbtable'; // Identify which forms have data in the database $formsList = $plugin->getForms(); if (count($formsList) == 0) { echo htmlspecialchars(__('No form submissions in the database', 'contact-form-7-to-database-extension')); return; } $page = 1; if (isset($_REQUEST['dbpage'])) { $page = $this->getRequestParam('dbpage'); } $currSelection = null; if (isset($_REQUEST['form_name'])) { $currSelection = $this->getRequestParam('form_name'); } else { if (isset($_REQUEST['form'])) { $currSelection = $this->getRequestParam('form'); } } if ($currSelection) { $currSelection = stripslashes($currSelection); $currSelection = html_entity_decode($currSelection); } $currSelectionEscaped = htmlentities($currSelection, null, 'UTF-8'); // If there is only one form in the DB, select that by default if (!$currSelection && count($formsList) == 1) { $currSelection = $formsList[0]; // Bug fix: Need to set this so the Editor plugin can reference it $_REQUEST['form_name'] = $formsList[0]; } if ($currSelection) { // Check for delete operation if (isset($_POST['cfdbdel']) && $canEdit && wp_verify_nonce($_REQUEST['_wpnonce'])) { if (isset($_POST['submit_time'])) { $submitTime = $_POST['submit_time']; $wpdb->query($wpdb->prepare("delete from `{$tableName}` where `form_name` = '%s' and `submit_time` = %F", $currSelection, $submitTime)); } else { if (isset($_POST['all'])) { $wpdb->query($wpdb->prepare("delete from `{$tableName}` where `form_name` = '%s'", $currSelection)); } else { foreach ($_POST as $name => $value) { // checkboxes if ($value == 'row') { // Dots and spaces in variable names are converted to underscores. For example <input name="a.b" /> becomes $_REQUEST["a_b"]. // http://www.php.net/manual/en/language.variables.external.php // We are expecting a time value like '1300728460.6626' but will instead get '1300728460_6626' // so we need to put the '.' back in before going to the DB. $name = str_replace('_', '.', $name); $wpdb->query($wpdb->prepare("delete from `{$tableName}` where `form_name` = '%s' and `submit_time` = %F", $currSelection, $name)); } } } } } else { if (isset($_POST['delete_wpcf7']) && $canEdit && wp_verify_nonce($_REQUEST['_wpnonce'])) { $plugin->delete_wpcf7_fields($currSelection); $plugin->add_wpcf7_noSaveFields(); } } } // Form selection drop-down list $pluginDirUrl = $plugin->getPluginDirUrl(); ?> <table width="100%" cellspacing="20"> <tr> <td align="left" valign="top"> <form method="get" action="<?php echo $_SERVER['REQUEST_URI']; ?> " name="displayform" id="displayform"> <input type="hidden" name="page" value="<?php echo htmlspecialchars($this->getRequestParam('page')); ?> "/> <select name="form_name" id="form_name" onchange="this.form.submit();"> <option value=""><?php echo htmlspecialchars(__('* Select a form *', 'contact-form-7-to-database-extension')); ?> </option> <?php foreach ($formsList as $formName) { $selected = $formName == $currSelection ? "selected" : ""; $formNameEscaped = htmlentities($formName, null, 'UTF-8'); ?> <option value="<?php echo $formNameEscaped; ?> " <?php echo $selected; ?> ><?php echo $formNameEscaped; ?> </option> <?php } ?> </select> </form> </td> <td align="center" valign="top"> <?php if ($currSelection) { ?> <script type="text/javascript" language="Javascript"> function changeDbPage(page) { var newdiv = document.createElement('div'); newdiv.innerHTML = "<input id='dbpage' name='dbpage' type='hidden' value='" + page + "'>"; var dispForm = document.forms['displayform']; dispForm.appendChild(newdiv); dispForm.submit(); } function getSearchFieldValue() { var searchVal = ''; if (typeof jQuery == 'function') { try { searchVal = jQuery('#<?php echo $tableHtmlId; ?> _filter input').val(); } catch (e) { } } return searchVal; } function exportData(encSelect) { var enc = encSelect.options[encSelect.selectedIndex].value; var url; if (enc == 'GSS') { if (typeof jQuery == 'function') { try { jQuery("#GoogleCredentialsDialog").dialog({ autoOpen: false, title: '<?php echo htmlspecialchars(__("Google Login for Upload", 'contact-form-7-to-database-extension')); ?> ' }); jQuery("#GoogleCredentialsDialog").dialog('open'); jQuery("#guser").focus(); } catch (e) { alert('Error: ' + e.message); } } else { alert("<?php echo htmlspecialchars(__('Cannot perform operation because jQuery is not loaded in this page', 'contact-form-7-to-database-extension')); ?> "); } } else if (enc == 'GLD') { alert("<?php echo htmlspecialchars(__('You will now be navigated to the builder page where it will generate a function to place in your Google Spreadsheet', 'contact-form-7-to-database-extension')); ?> "); url = '<?php echo $plugin->getAdminUrlPrefix('admin.php'); ?> page=CF7DBPluginShortCodeBuilder&form=<?php echo urlencode($currSelection); ?> &enc=' + enc; location.href = url; } else { url = '<?php echo $plugin->getAdminUrlPrefix('admin-ajax.php'); ?> action=cfdb-export&form=<?php echo urlencode($currSelection); ?> &enc=' + enc; var searchVal = getSearchFieldValue(); if (searchVal != null && searchVal != "") { url += '&search=' + encodeURIComponent(searchVal); } location.href = url; } } function uploadGoogleSS() { var key = '3fde789a'; var guser = printHex(des(key, jQuery('#guser').attr('value'), 1)); var gpwd = printHex(des(key, jQuery('#gpwd').attr('value'), 1)); jQuery("#GoogleCredentialsDialog").dialog('close'); var form = document.createElement("form"); form.setAttribute("method", 'POST'); var url = '<?php echo $pluginDirUrl; ?> export.php?form=<?php echo urlencode($currSelection); ?> &enc=GSS'; var searchVal = getSearchFieldValue(); if (searchVal != null && searchVal != "") { url += '&search=' + encodeURI(searchVal); } form.setAttribute("action", url); var params = {guser: encodeURI(guser), gpwd: encodeURI(gpwd)}; for (var pkey in params) { var hiddenField = document.createElement("input"); hiddenField.setAttribute("type", "hidden"); hiddenField.setAttribute("name", pkey); hiddenField.setAttribute("value", params[pkey]); form.appendChild(hiddenField); } document.body.appendChild(form); form.submit(); } </script> <form name="exportcsv" action="<?php echo $_SERVER['REQUEST_URI']; ?> "> <input type="hidden" name="unbuffered" value="true"/> <select size="1" name="enc"> <option id="IQY" value="IQY"> <?php echo htmlspecialchars(__('Excel Internet Query', 'contact-form-7-to-database-extension')); ?> </option> <option id="CSVUTF8BOM" value="CSVUTF8BOM"> <?php echo htmlspecialchars(__('Excel CSV (UTF8-BOM)', 'contact-form-7-to-database-extension')); ?> </option> <option id="TSVUTF16LEBOM" value="TSVUTF16LEBOM"> <?php echo htmlspecialchars(__('Excel TSV (UTF16LE-BOM)', 'contact-form-7-to-database-extension')); ?> </option> <option id="CSVUTF8" value="CSVUTF8"> <?php echo htmlspecialchars(__('Plain CSV (UTF-8)', 'contact-form-7-to-database-extension')); ?> </option> <option id="CSVSJIS" value="CSVSJIS"> <?php echo htmlspecialchars(__('Excel CSV for Japanese (Shift-JIS)', 'contact-form-7-to-database-extension')); ?> </option> <option id="GSS" value="GSS"> <?php echo htmlspecialchars(__('Google Spreadsheet', 'contact-form-7-to-database-extension')); ?> </option> <option id="GLD" value="GLD"> <?php echo htmlspecialchars(__('Google Spreadsheet Live Data', 'contact-form-7-to-database-extension')); ?> </option> <option id="HTML" value="HTML"> <?php echo htmlspecialchars(__('HTML', 'contact-form-7-to-database-extension')); ?> </option> <option id="JSON" value="JSON"> <?php echo htmlspecialchars(__('JSON', 'contact-form-7-to-database-extension')); ?> </option> </select> <input name="exportButton" type="button" value="<?php echo htmlspecialchars(__('Export', 'contact-form-7-to-database-extension')); ?> " onclick="exportData(this.form.elements['enc'])"/> <span style="font-size: x-small;"><br /><?php echo '<a href="admin.php?page=' . $plugin->getShortCodeBuilderPageSlug() . '">' . __('Advanced Export', 'contact-form-7-to-database-extension') . '</a>'; ?> </form> <?php } ?> </td> <td align="right" valign="top"> <?php if ($currSelection && $canEdit) { ?> <form action="<?php echo $_SERVER['REQUEST_URI']; ?> " method="post"> <input name="form_name" type="hidden" value="<?php echo $currSelectionEscaped; ?> "/> <input name="all" type="hidden" value="y"/> <?php wp_nonce_field(); ?> <input name="cfdbdel" type="submit" value="<?php echo htmlspecialchars(__('Delete All This Form\'s Records', 'contact-form-7-to-database-extension')); ?> " onclick="return confirm('<?php echo htmlspecialchars(__('Are you sure you want to delete all the data for this form?', 'contact-form-7-to-database-extension')); ?> ')"/> </form> <br/> <form action="<?php echo $_SERVER['REQUEST_URI']; ?> " method="post"> <input name="form_name" type="hidden" value="<?php echo $currSelectionEscaped; ?> "/> <?php wp_nonce_field(); ?> <input name="delete_wpcf7" type="submit" value="<?php echo htmlspecialchars(__('Remove _wpcf7 columns', 'contact-form-7-to-database-extension')); ?> "/> </form> <?php } ?> </td> </tr> <?php if ($currSelection && $canEdit && $useDataTables) { ?> <tr> <td align="left" colspan="3"> <span id="edit_controls"> <a href="http://cfdbplugin.com/?page_id=459" target="_cfdbedit"><?php echo htmlspecialchars(__('Edit Data Mode', 'contact-form-7-to-database-extension')); ?> </a> </span> </td> </tr> <?php } ?> </table> <?php if ($currSelection) { // Show table of form data if ($useDataTables) { $i18nUrl = $plugin->getDataTableTranslationUrl(); // Work out the datatable menu for number or rows shown $maxVisible = $plugin->getOption('MaxVisibleRows', -1); if (!is_numeric($maxVisible)) { $maxVisible = -1; } $menuJS = $this->createDatatableLengthMenuJavascriptString($maxVisible); $sScrollX = $plugin->getOption('HorizontalScroll', 'true', true) == 'true' ? '"100%"' : '""'; ?> <script type="text/javascript" language="Javascript"> var oTable; jQuery(document).ready(function() { oTable = jQuery('#<?php echo $tableHtmlId; ?> ').dataTable({ <?php // "sDom": 'Rlfrtip', // ColReorder ?> "bJQueryUI": true, "aaSorting": [], //"sScrollY": "400", "bScrollCollapse": true, "sScrollX": <?php echo $sScrollX; ?> , "iDisplayLength": <?php echo $maxVisible; ?> , "aLengthMenu": <?php echo $menuJS; ?> <?php if ($i18nUrl) { echo ", \"oLanguage\": { \"sUrl\": \"{$i18nUrl}\" }"; } if ($canEdit) { do_action_ref_array('cfdb_edit_fnDrawCallbackJSON', array($tableHtmlId)); } ?> }); jQuery('th[id="delete_th"]').unbind('click'); <?php // Don't sort delete column ?> }); </script> <?php } if ($canEdit) { ?> <form action="<?php echo $_SERVER['REQUEST_URI']; ?> " method="post"> <input name="form_name" type="hidden" value="<?php echo $currSelectionEscaped; ?> "/> <input name="cfdbdel" type="hidden" value="rows"/> <?php wp_nonce_field(); ?> <?php } ?> <?php $exporter = new ExportToHtmlTable(); $dbRowCount = $exporter->getDBRowCount($currSelection); $maxRows = $plugin->getOption('MaxRows', '100', true); $startRow = $this->paginationDiv($plugin, $dbRowCount, $maxRows, $page); ?> <div <?php if (!$useDataTables) { echo 'style="overflow:auto; max-height:500px; max-width:500px; min-width:75px"'; } ?> > <?php // Pick up any options that the user enters in the URL. // This will include extraneous "form_name" and "page" GET params which are in the URL // for this admin page $options = array_merge($_POST, $_GET); $options['canDelete'] = $canEdit; if ($maxRows) { $options['limit'] = $startRow - 1 . ',' . $maxRows; } if ($useDataTables) { $options['id'] = $tableHtmlId; $options['class'] = ''; $options['style'] = "#{$tableHtmlId} {padding:0;} #{$tableHtmlId} td > div { max-height: 100px; min-width:75px; overflow: auto; font-size: small;}"; // don't let cells get too tall } $exporter->export($currSelection, $options); ?> </div> <?php if ($canEdit) { ?> </form> <?php } } ?> <script type="text/javascript"> (function ($) { var url = "admin.php?page=<?php echo $plugin->getDBPageSlug(); ?> &form_name=<?php echo urlencode($currSelection); ?> &submit_time="; $('td[title="Submitted"] div').each( function () { var submitTime = $(this).attr('id').split(","); $(this).html('<a target="_cfdb_entry" href="' + url + submitTime[0] + '">' + $(this).html() + '</a>'); }) })(jQuery); </script> <div style="margin-top:1em"> <?php // Footer ?> <table style="width:100%;"> <tbody> <tr> <td align="center" colspan="4"> <span style="font-size:x-small; font-style: italic;"> <?php echo htmlspecialchars(__('Did you know: This plugin captures data from these plugins:', 'contact-form-7-to-database-extension')); ?> <br/> <a target="_cf7" href="https://wordpress.org/plugins/contact-form-7/">Contact Form 7</a>, <a target="_fscf" href="https://wordpress.org/plugins/si-contact-form/">Fast Secure Contact Form</a>, <a target="_jetpack" href="https://wordpress.org/plugins/jetpack/">JetPack Contact Form</a>, <a target="_gravityforms" href="http://www.gravityforms.com">Gravity Forms</a>, <a target="_wr" href="https://wordpress.org/plugins/wr-contactform/">WR ContactForm</a>, <a target="_formidable" href="https://wordpress.org/plugins/formidable/">Formidable Forms (BETA)</a>, <a target="_quform" href="http://codecanyon.net/item/quform-wordpress-form-builder/706149/">Quform (BETA)</a>, <a target="_ninjaforms" href="https://wordpress.org/plugins/ninja-forms/">Ninja Forms (BETA)</a>, <a target="_caldera" href="https://wordpress.org/plugins/caldera-forms/">Caldera Forms (BETA)</a> <a target="_cf2" href="https://wordpress.org/plugins/cforms2/">CFormsII Forms (BETA)</a> </span> </td> </tr> <tr> <td align="center" colspan="4"> <span style="font-size:x-small; font-style: italic;"> <?php echo htmlspecialchars(__('Did you know: You can add this data to your posts and pages using these shortcodes:', 'contact-form-7-to-database-extension')); ?> <br/> <a target="_faq" href="http://cfdbplugin.com/?page_id=284">[cfdb-html]</a> <a target="_faq" href="http://cfdbplugin.com/?page_id=91">[cfdb-datatable]</a> <a target="_faq" href="http://cfdbplugin.com/?page_id=93">[cfdb-table]</a> <a target="_faq" href="http://cfdbplugin.com/?page_id=98">[cfdb-value]</a> <a target="_faq" href="http://cfdbplugin.com/?page_id=278">[cfdb-count]</a> <a target="_faq" href="http://cfdbplugin.com/?page_id=96">[cfdb-json]</a> </span> </td> </tr> <tr> <td align="center" colspan="4"> <span style="font-size:x-small; font-style: italic;"> <?php echo htmlspecialchars(__('Would you like to help translate this plugin into your language?', 'contact-form-7-to-database-extension')); ?> <a target="_i18n" href="http://cfdbplugin.com/?page_id=7"><?php echo htmlspecialchars(__('How to create a translation', 'contact-form-7-to-database-extension')); ?> </a> </span> </td> </tr> </tbody> </table> </div> <?php if ($currSelection && 'true' == $plugin->getOption('ShowQuery', 'false', true)) { ?> <div id="query" style="margin: 20px; border: dotted #d3d3d3 1pt;"> <strong><?php echo htmlspecialchars(__('Query:', 'contact-form-7-to-database-extension')); ?> </strong><br/> <pre><?php echo $exporter->getPivotQuery($currSelection); ?> </pre> </div> <?php } if ($currSelection) { ?> <div id="GoogleCredentialsDialog" style="display:none; background-color:#EEEEEE;"> <table> <tbody> <tr> <td><label for="guser">User</label></td> <td><input id="guser" type="text" size="25" value="@gmail.com"/></td> </tr> <tr> <td><label for="gpwd">Password</label></td> <td><input id="gpwd" type="password" size="25" value=""/></td> </tr> <tr> <td></td> <td> <input type="button" value="<?php echo htmlspecialchars(__('Cancel', 'contact-form-7-to-database-extension')); ?> " onclick="jQuery('#GoogleCredentialsDialog').dialog('close');"/> <input type="button" value="<?php echo htmlspecialchars(__('Upload', 'contact-form-7-to-database-extension')); ?> " onclick="uploadGoogleSS()"/> </td> </tr> </tbody> </table> </div> <script type="text/javascript" language="Javascript"> var addColumnLabelText = '<?php echo htmlspecialchars(__('Add Column', 'contact-form-7-to-database-extension')); ?> '; var deleteColumnLabelText = '<?php echo htmlspecialchars(__('Delete Column', 'contact-form-7-to-database-extension')); ?> '; </script> <?php do_action_ref_array('cfdb_edit_setup', array($plugin)); } }
/** * @param string|array $formName (if array, must be array of string) * @param bool $count * @param $submitTimes array of string submit_time values that are to be specifically queried * @return string */ public function &getPivotQuery($formName, $count = false, $submitTimes = null) { global $wpdb; $tableName = $this->plugin->getSubmitsTableName(); $formNameClause = ''; if (is_array($formName)) { $formNameClause = '`form_name` in ( \'' . implode('\', \'', $formName) . '\' )'; } else { if ($formName !== null) { $formNameClause = "`form_name` = '{$formName}'"; } } $submitTimesClause = ''; if (is_array($submitTimes) && !empty($submitTimes)) { $submitTimesClause = 'AND submit_time in ( ' . implode(', ', $submitTimes) . ' )'; } //$rows = $wpdb->get_results("SELECT DISTINCT `field_name`, `field_order` FROM `$tableName` WHERE $formNameClause ORDER BY field_order"); // Pagination bug $rows = $wpdb->get_results("SELECT DISTINCT `field_name` FROM `{$tableName}` WHERE {$formNameClause} ORDER BY field_order"); $fields = array(); foreach ($rows as $aRow) { $fields[] = $aRow->field_name; } $sql = ''; if ($count) { $sql .= 'SELECT count(*) as count FROM ('; } $sql .= "SELECT `submit_time` AS 'Submitted'"; foreach ($fields as $aCol) { $sql .= ",\n max(if(`field_name`='{$aCol}', `field_value`, null )) AS '{$aCol}'"; } if (!$count) { $sql .= ",\n GROUP_CONCAT(if(`file` is null or length(`file`) = 0, null, `field_name`)) AS 'fields_with_file'"; } $sql .= "\nFROM `{$tableName}` \nWHERE {$formNameClause} {$submitTimesClause} \nGROUP BY `submit_time` "; if ($count) { $sql .= ') form'; } else { $orderBys = array(); if ($this->options && isset($this->options['orderby'])) { $orderByStrings = explode(',', $this->options['orderby']); foreach ($orderByStrings as $anOrderBy) { $anOrderBy = trim($anOrderBy); $ascOrDesc = null; if (strtoupper(substr($anOrderBy, -5)) == ' DESC') { $ascOrDesc = " DESC"; $anOrderBy = trim(substr($anOrderBy, 0, -5)); } else { if (strtoupper(substr($anOrderBy, -4)) == ' ASC') { $ascOrDesc = " ASC"; $anOrderBy = trim(substr($anOrderBy, 0, -4)); } } if ($anOrderBy == 'Submitted') { $anOrderBy = 'submit_time'; } if (in_array($anOrderBy, $fields) || $anOrderBy == 'submit_time') { $orderBys[] = '`' . $anOrderBy . '`' . $ascOrDesc; } else { // Want to add a different collation as a different sorting mechanism // Actually doesn't work because MySQL does not allow COLLATE on a select that is a group function $collateIdx = stripos($anOrderBy, ' COLLATE'); if ($collateIdx > 0) { $collatedField = substr($anOrderBy, 0, $collateIdx); if (in_array($collatedField, $fields)) { $orderBys[] = '`' . $collatedField . '`' . substr($anOrderBy, $collateIdx) . $ascOrDesc; } } } } } if (empty($orderBys)) { $sql .= "\nORDER BY `submit_time` DESC"; } else { $sql .= "\nORDER BY "; $first = true; foreach ($orderBys as $anOrderBy) { if ($first) { $sql .= $anOrderBy; $first = false; } else { $sql .= ', ' . $anOrderBy; } } } if (empty($this->rowFilter) && $this->options && isset($this->options['limit'])) { // If no filter constraints and have a limit, add limit to the SQL $sql .= "\nLIMIT " . $this->options['limit']; } } //echo $sql; // debug return $sql; }
/** * @return bool */ public function queryPermitAllFunctions() { return $this->plugin->getOption('FunctionsInShortCodes', 'false') === 'true'; }
/** * Format input date string * @param $time int same as returned from PHP time() * @return string formatted date according to saved options */ public function formatDate($time) { // This method gets executed in a loop. Cache some variable to avoid // repeated get_option calls to the database if (CF7DBPlugin::$checkForCustomDateFormat) { if ($this->getOption('UseCustomDateTimeFormat', 'true') == 'true') { CF7DBPlugin::$customDateFormat = $this->getOption('SubmitDateTimeFormat', 'Y-m-d H:i:s P'); } else { CF7DBPlugin::$dateFormat = get_option('date_format'); CF7DBPlugin::$timeFormat = get_option('time_format'); } $this->setTimezone(); CF7DBPlugin::$checkForCustomDateFormat = false; } // Support Shamsi(Jalali) dates by looking for a plugin that can produce the correct text for the date if (!function_exists('is_plugin_active') && @file_exists(ABSPATH . 'wp-admin/includes/plugin.php')) { include_once ABSPATH . 'wp-admin/includes/plugin.php'; } if (function_exists('is_plugin_active')) { // See if wp-parsidate is active and if so, have it convert the date // using its 'parsidate' function if (is_plugin_active('wp-parsidate/wp-parsidate.php')) { if (function_exists('parsidate')) { if (CF7DBPlugin::$customDateFormat) { return parsidate(CF7DBPlugin::$customDateFormat, $time); } else { return parsidate(CF7DBPlugin::$dateFormat . ' ' . CF7DBPlugin::$timeFormat, $time); } } } else { if (is_plugin_active('wp-jalali/wp-jalali.php')) { $jDateFile = WP_PLUGIN_DIR . '/wp-jalali/inc/jalali-core.php'; if (@file_exists($jDateFile)) { include_once $jDateFile; if (function_exists('jdate')) { //return jdate('l, F j, Y'); if (CF7DBPlugin::$customDateFormat) { return jdate(CF7DBPlugin::$customDateFormat, $time); } else { return jdate(CF7DBPlugin::$dateFormat . ' ' . CF7DBPlugin::$timeFormat, $time); } } } } } } if (CF7DBPlugin::$customDateFormat) { return date(CF7DBPlugin::$customDateFormat, $time); } else { return date_i18n(CF7DBPlugin::$dateFormat . ' ' . CF7DBPlugin::$timeFormat, $time); } }