/** * Debug action to examine server variables * */ function wpgform_debug() { global $wp_filter; wpgform_error_log($_POST); if (!is_admin()) { wpgform_whereami(__FILE__, __LINE__, '$_SERVER'); wpgform_preprint_r($_SERVER); wpgform_whereami(__FILE__, __LINE__, '$_ENV'); wpgform_preprint_r($_ENV); wpgform_whereami(__FILE__, __LINE__, '$_POST'); wpgform_preprint_r($_POST); wpgform_whereami(__FILE__, __LINE__, '$_GET'); wpgform_preprint_r($_GET); wpgform_whereami(__FILE__, __LINE__, 'locale'); wpgform_preprint_r(get_locale()); wpgform_preprint_r(setlocale(LC_ALL, NULL)); if (array_key_exists('init', $wp_filter)) { wpgform_whereami(__FILE__, __LINE__, '$wp_filter[\'init\']'); wpgform_preprint_r($wp_filter['init']); } if (array_key_exists('template_redirect', $wp_filter)) { wpgform_whereami(__FILE__, __LINE__, '$wp_filter[\'template_redirect\']'); wpgform_preprint_r($wp_filter['template_redirect']); } } }
/** * Function ConstructGoogleForm loads HTML from a Google Form URL, * processes it, and inserts it into a WordPress filter to output * as part of a post, page, or widget. * * @param $options array Values passed from the shortcode. * @return An HTML string if successful, false otherwise. * @see RenderGoogleForm */ static function ProcessGoogleForm() { $tabFound = false; if (WPGFORM_DEBUG) { wpgform_whereami(__FILE__, __LINE__, 'ProcessGoogleForm'); } if (WPGFORM_DEBUG) { wpgform_preprint_r($_POST); } if (!empty($_POST) && array_key_exists('wpgform-action', $_POST)) { if (WPGFORM_DEBUG) { wpgform_whereami(__FILE__, __LINE__, 'ProcessGoogleForm'); } self::$posted = true; $wpgform_options = wpgform_get_plugin_options(); if (WPGFORM_DEBUG && $wpgform_options['http_request_timeout']) { $timeout = $wpgform_options['http_request_timeout_value']; } else { $timeout = $wpgform_options['http_api_timeout']; } if (WPGFORM_DEBUG) { wpgform_whereami(__FILE__, __LINE__, 'ProcessGoogleForm'); } if (WPGFORM_DEBUG) { wpgform_preprint_r($_POST); } // Need the form ID to handle multiple forms per page if (array_key_exists('wpgform-user-email', $_POST)) { self::$wpgform_user_sendto = $_POST['wpgform-user-email']; unset($_POST['wpgform-user-email']); } // Need the form ID to handle multiple forms per page self::$wpgform_submitted_form_id = $_POST['wpgform-form-id']; unset($_POST['wpgform-form-id']); // Need the action which was saved during form construction $action = unserialize(base64_decode($_POST['wpgform-action'])); unset($_POST['wpgform-action']); $options = $_POST['wpgform-options']; unset($_POST['wpgform-options']); $options = unserialize(base64_decode($options)); if (WPGFORM_DEBUG) { wpgform_preprint_r($options); } $form = $options['form']; $uid = $options['uid']; //$body = '' ; $body = array(); // The name of the form fields are munged, they need // to be restored before the parameters can be posted $patterns = array('entry_([0-9]+)_(single|group)_', 'entry_([0-9]+)_', 'entry_([0-9]+)'); $replacements = array('entry.\\1.\\2.', 'entry.\\1.', 'entry.\\1'); foreach ($patterns as $key => $value) { $patterns[$key] = sprintf('/^%s%s/', $uid, $value); } if (WPGFORM_DEBUG) { wpgform_whereami(__FILE__, __LINE__, 'ProcessGoogleForm'); } if (WPGFORM_DEBUG) { wpgform_preprint_r($_POST); } foreach ($_POST as $key => $value) { if (WPGFORM_DEBUG) { wpgform_whereami(__FILE__, __LINE__, 'ProcessGoogleForm'); } if (WPGFORM_DEBUG) { wpgform_preprint_r($key, $value); } // Need to handle parameters passed as array values // separately because of how Python (used Google) // handles array arguments differently than PHP does. if (is_array($_POST[$key])) { if (WPGFORM_DEBUG) { wpgform_whereami(__FILE__, __LINE__, 'ProcessGoogleForm'); } $pa =& $_POST[$key]; foreach ($pa as $pv) { //$body .= preg_replace($patterns, $replacements, $key) . '=' . rawurlencode($pv) . '&' ; $formkey = preg_replace($patterns, $replacements, $key); $body[$formkey][] = $pv; } if (WPGFORM_DEBUG) { wpgform_whereami(__FILE__, __LINE__, 'ProcessGoogleForm'); } } else { if ($key === 'draftResponse') { // draftResponse is a special parameter for multi-page forms and needs // some special processing. We need to remove the escapes on double quotes, // handled embedded tabs, and encoded ampersands. $patterns = array('/\\\\"/', '/\\\\t/', '/\\\\u0026/', '/\\\\n/'); $replacements = array('"', 't', '&', '\\n'); $value = preg_replace($patterns, $replacements, $value); if (WPGFORM_DEBUG) { wpgform_whereami(__FILE__, __LINE__, 'ProcessGoogleForm'); } //$body .= preg_replace($patterns, $replacements, $key) . '=' . rawurlencode($value) . '&' ; $formkey = preg_replace($patterns, $replacements, $key); $body[$formkey] = $value; } else { if (WPGFORM_DEBUG) { wpgform_whereami(__FILE__, __LINE__, 'ProcessGoogleForm'); } //$body .= preg_replace($patterns, $replacements, $key) . '=' . rawurlencode($value) . '&' ; $formkey = preg_replace($patterns, $replacements, $key); $body[$formkey] = $value; } } } $form = str_replace($action, 'action=""', $form); // WordPress converts all of the ampersand characters to their // appropriate HTML entity or some variety of it. Need to undo // that so the URL can be actually be used. //$body = stripslashes_deep(urldecode($body)) ; //$body = stripslashes_deep($body) ; // Clean up any single quotes and newlines which are escaped $patterns = array('/%5C%27/', '/%5Cn/'); $replacements = array('%27', 'n'); foreach ($body as $key => $value) { $body[$key] = preg_replace($patterns, $replacements, stripslashes_deep($value)); } $action = str_replace(array('&', '&', '&'), '&', $action); if (WPGFORM_DEBUG) { wpgform_preprint_r($action); wpgform_preprint_r($body); } // Special processing for checkboxes! $q = http_build_query($body); $q = preg_replace('/%5B[0-9]+%5D/', '', $q); self::$response = wp_remote_post($action, array('sslverify' => false, 'body' => $q, 'timeout' => $timeout, 'user-agent' => $_SERVER['HTTP_USER_AGENT'])); if (WPGFORM_DEBUG) { wpgform_whereami(__FILE__, __LINE__, 'ProcessGoogleForm'); wpgform_preprint_r(array('action' => $action, 'sslverify' => false, 'body' => $q, 'timeout' => $timeout, 'user-agent' => $_SERVER['HTTP_USER_AGENT'])); } // Double check response from wp_remote_post() if (is_wp_error(self::$response)) { self::$post_error = true; $error_string = self::$response->get_error_message(); echo '<div id="message" class="wpgform-google-error"><p>' . $error_string . '</p></div>'; if (WPGFORM_DEBUG) { //printf('<h2>%s::%s</h2>', basename(__FILE__), __LINE__) ; //print '<pre>' ; //print_r(self::$response) ; //print '</pre>' ; wpgform_whereami(__FILE__, __LINE__, 'ProcessGoogleForm'); wpgform_preprint_r(self::$response); } return sprintf('<div class="wpgform-google-error gform-google-error">%s</div>', __('Unable to submit Google Form. Please try reloading this page.', WPGFORM_I18N_DOMAIN)); } } }