Example #1
0
 /**
  * Generates and returns the HTML for the contact form page. When the form
  * is submitted, it checks for errors and initiates sending the email.
  *
  * @static
  * @access public
  * @uses DekoBoko::checkMessage()
  * @uses DekoBoko::sendMessage()
  * @uses recaptchalib::recaptcha_get_html()
  * @returns string HTML for contact form
  */
 function getContactPage($atts)
 {
     extract(shortcode_atts(array('template' => DEKOBOKO_DEFAULT_TEMPLATE), $atts));
     $status = false;
     $dekoboko_options = unserialize(get_option('dekoboko_options'));
     array_walk($dekoboko_options, array(DEKOBOKO_PLUGIN_NAME, '_stripslashes'));
     $recaptcha_options = get_option('recaptcha');
     $headers = array('name', 'email', 'subject');
     // don't try to include the recaptcha lib if it's already been included
     // by another plugin - if you have recaptcha_get_html then you'll have
     // the other functions in recaptchalib too.
     if (!function_exists('recaptcha_get_html')) {
         require_once DEKOBOKO_DIR . '/recaptcha/recaptchalib.php';
     }
     // if the form has been submitted, check to make sure it's safe to send
     if ($_POST['dekoboko_submit']) {
         $status = DekoBoko::checkMessage($recaptcha_options, $headers);
     }
     if ($status === true) {
         $status = DekoBoko::sendMessage($headers);
         if ($status === false) {
             $status = array(__("Failed call to wp_mail() - unable to send message", DEKOBOKO_L10N_NAME));
         }
     }
     $dekoboko_required = $_POST['dekoboko_required'];
     $dekoboko_optional = $_POST['dekoboko_optional'];
     if (!empty($dekoboko_required)) {
         array_walk($dekoboko_required, array('DekoBoko', '_cleanInput'), true);
     }
     if (!empty($dekoboko_optional)) {
         array_walk($dekoboko_optional, array('DekoBoko', '_cleanInput'), true);
     }
     ob_start();
     // display the success message if the message was sent
     if ($status === true) {
         echo '<div class="dekoboko_success">' . $dekoboko_options['success'] . '</div>';
     } else {
         // display any errors from a previous submission
         if (is_array($status)) {
             echo "\n" . '<div class="dekoboko_errors"><p>' . __("Sorry, there were errors in your submission. Please try again.", DEKOBOKO_L10N_NAME) . "</p>\n<ul>\n";
             foreach ($status as $error) {
                 echo "<li>{$error}</li>\n";
             }
             echo "</ul></div>\n";
         }
         $js_opts = "\n                <script type='text/javascript'>\n                var RecaptchaOptions = { theme : '" . $dekoboko_options['recaptcha_theme'] . "', lang : '" . $dekoboko_options['recaptcha_lang'] . "' };\n                </script>\n            ";
         if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") {
             $use_ssl = true;
         } else {
             $use_ssl = false;
         }
         $recaptcha_html = $js_opts . recaptcha_get_html($recaptcha_options['pubkey'], null, $use_ssl);
         require DEKOBOKO_DIR . "/display/{$template}";
     }
     $output = ob_get_contents();
     ob_end_clean();
     return $output;
 }