Google Forms - Version 0.26

Version Description

No known upgrade issues.

Download this release

Release Info

Developer mpwalsh8
Plugin Icon wp plugin Google Forms
Version 0.26
Comparing to
See all releases

Code changes from version 0.25 to 0.26

Files changed (4) hide show
  1. index.php +2 -2
  2. readme.txt +7 -1
  3. wpgform-core.php +135 -17
  4. wpgform-options.php +11 -0
index.php CHANGED
@@ -4,8 +4,8 @@
4
  * Plugin Name: WordPress Google Form
5
  * Plugin URI: http://michaelwalsh.org/wordpress/wordpress-plugins/wpgform/
6
  * Description: Add Google Forms to a WordPress web site. Display a Google Form directly into your posts, pages or sidebar. Style the Google Form to match your existing theme and display a custom confirmation page after form submission.
7
- * Version: 0.25
8
- * Build: 0.25.$WCREV$
9
  * Last Modified: $WCDATE$
10
  * Author: Mike Walsh
11
  * Author URI: http://www.michaelwalsh.org
4
  * Plugin Name: WordPress Google Form
5
  * Plugin URI: http://michaelwalsh.org/wordpress/wordpress-plugins/wpgform/
6
  * Description: Add Google Forms to a WordPress web site. Display a Google Form directly into your posts, pages or sidebar. Style the Google Form to match your existing theme and display a custom confirmation page after form submission.
7
+ * Version: 0.26
8
+ * Build: 0.26.$WCREV$
9
  * Last Modified: $WCDATE$
10
  * Author: Mike Walsh
11
  * Author URI: http://www.michaelwalsh.org
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: Google Forms, Google Docs, Google, Spreadsheet, shortcode, forms
5
  Requires at least: 3.0
6
  Tested up to: 3.3.1
7
- Stable tag: 0.25
8
 
9
  Embeds a published, public Google Form in a WordPress post, page, or widget.
10
 
@@ -177,6 +177,12 @@ No known upgrade issues.
177
 
178
  == Changelog ==
179
 
 
 
 
 
 
 
180
  = Version 0.25 =
181
  * Fixed problem with checkbox processing when using the prefix attribute.
182
  * Fixed problem with hiding legal links when using the prefix attribute.
4
  Tags: Google Forms, Google Docs, Google, Spreadsheet, shortcode, forms
5
  Requires at least: 3.0
6
  Tested up to: 3.3.1
7
+ Stable tag: 0.26
8
 
9
  Embeds a published, public Google Form in a WordPress post, page, or widget.
10
 
177
 
178
  == Changelog ==
179
 
180
+ = Version 0.26 =
181
+ * Added new shortcode attribute "email='on|off'", default is 'off'.
182
+ * Changed confirmation page from a hard redirect to a Ajax load.
183
+ * Added new email format choice on the Options page, default is HTML.
184
+ * Cleaned up some dead code and comments.
185
+
186
  = Version 0.25 =
187
  * Fixed problem with checkbox processing when using the prefix attribute.
188
  * Fixed problem with hiding legal links when using the prefix attribute.
wpgform-core.php CHANGED
@@ -18,6 +18,8 @@
18
 
19
  // Filesystem path to this plugin.
20
  define('WPGFORM_PATH', WP_PLUGIN_DIR.'/'.dirname(plugin_basename(__FILE__))) ;
 
 
21
 
22
  /**
23
  * wpgform_init()
@@ -53,6 +55,7 @@ function wpgform_get_default_plugin_options()
53
  ,'custom_css' => 0
54
  ,'custom_css_styles' => ''
55
  ,'donation_message' => 0
 
56
  ) ;
57
 
58
  return apply_filters('wpgform_default_plugin_options', $default_plugin_options) ;
@@ -138,6 +141,7 @@ function wpgform_register_activation_hook()
138
  ,'custom_css' => 0
139
  ,'custom_css_styles' => ''
140
  ,'donation_message' => 0
 
141
  ) ;
142
 
143
  add_option('wpgform_options', $default_wpgform_options) ;
@@ -252,6 +256,9 @@ class wpGForm
252
  // Should form be set to readonly?
253
  $readonly = $options['readonly'] === 'on' ;
254
 
 
 
 
255
  // WordPress converts all of the ampersand characters to their
256
  // appropriate HTML entity or some variety of it. Need to undo
257
  // that so the URL can be actually be used.
@@ -283,12 +290,9 @@ class wpGForm
283
 
284
  foreach ($_POST as $key => $value)
285
  {
286
- //printf('Mapping "%s" -> "%s"</h1>', $key, preg_replace($patterns, $replacements, $key)) ;
287
-
288
- // Need to handle parameters passed as array
289
- // values separately because of how Python (used
290
- // Google) handles array arguments differently than
291
- // PHP does.
292
 
293
  if (is_array($_POST[$key]))
294
  {
@@ -425,12 +429,6 @@ class wpGForm
425
  sprintf('<div class="%sss-legal" style="display:none;"', $prefix), $html) ;
426
  }
427
 
428
- // Need to fix names for checkbox items to account for how PHP
429
- // handles arrays - each name needs to have the "[]" tacked on
430
- // the end of it.
431
-
432
- //$html = preg_replace('/name="entry\.[0-9]+\.group/i', '\\1[]', $html) ;
433
-
434
  // Need to extract form action and rebuild form tag, and add hidden field
435
  // which contains the original action. This action is used to submit the
436
  // form via wp_remote_post().
@@ -462,11 +460,10 @@ class wpGForm
462
  else
463
  $css = '' ;
464
 
465
- // Output Javscript for form validation
466
  $js = sprintf('
467
  <script type="text/javascript">
468
  jQuery(document).ready(function($) {
469
- //$("form input:checkbox").wrap(\'<span></span>\').parent().css({background:"yellow", border:"3px red solid"});
470
  // Need to fix the name arguments for checkboxes
471
  // so PHP will pass them as an array correctly.
472
  $("div.%sss-form-container input:checkbox").each(function(index) {
@@ -479,22 +476,57 @@ jQuery(document).ready(function($) {
479
  ', $prefix) ;
480
 
481
  // Before closing the <script> tag, is this the confirmation
482
- // AND do we have a custom confiormation page or alert message?
483
 
484
  if ($posted && is_null($action) && !is_null($alert))
485
  $js .= PHP_EOL . 'alert("' . $alert . '") ;' ;
486
 
 
487
  if ($posted && is_null($action) && !is_null($confirm))
488
- $js .= PHP_EOL . 'window.location.replace("' . $confirm . '") ;' ;
 
 
 
489
 
490
  $js .= '
491
  });
492
  </script>
493
  ' ;
494
 
 
 
 
 
 
 
 
 
 
495
  return $js . $css . $html ;
496
  }
497
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
498
  /**
499
  * WordPress Shortcode handler.
500
  *
@@ -512,11 +544,97 @@ jQuery(document).ready(function($) {
512
  'prefix' => null, // Add suffix character(s) to all labels
513
  'readonly' => 'off', // Set all form elements to disabled
514
  'title' => 'on', // Remove the H1 element(s) from the Form
515
- 'maph1h2' => 'off' // Map H1 element(s) on the form to H2 element(s)
 
516
  ), $atts) ;
517
 
518
  return wpGForm::ConstructGForm($params) ;
519
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
520
  }
521
 
522
  /**
18
 
19
  // Filesystem path to this plugin.
20
  define('WPGFORM_PATH', WP_PLUGIN_DIR.'/'.dirname(plugin_basename(__FILE__))) ;
21
+ define('WPGFORM_EMAIL_FORMAT_HTML', 'html') ;
22
+ define('WPGFORM_EMAIL_FORMAT_PLAIN', 'plain') ;
23
 
24
  /**
25
  * wpgform_init()
55
  ,'custom_css' => 0
56
  ,'custom_css_styles' => ''
57
  ,'donation_message' => 0
58
+ ,'email_format' => WPGFORM_EMAIL_FORMAT_PLAIN
59
  ) ;
60
 
61
  return apply_filters('wpgform_default_plugin_options', $default_plugin_options) ;
141
  ,'custom_css' => 0
142
  ,'custom_css_styles' => ''
143
  ,'donation_message' => 0
144
+ ,'email_format' => WPGFORM_EMAIL_FORMAT_PLAIN
145
  ) ;
146
 
147
  add_option('wpgform_options', $default_wpgform_options) ;
256
  // Should form be set to readonly?
257
  $readonly = $options['readonly'] === 'on' ;
258
 
259
+ // Should email confirmation be sent?
260
+ $email = $options['email'] === 'on' ;
261
+
262
  // WordPress converts all of the ampersand characters to their
263
  // appropriate HTML entity or some variety of it. Need to undo
264
  // that so the URL can be actually be used.
290
 
291
  foreach ($_POST as $key => $value)
292
  {
293
+ // Need to handle parameters passed as array values
294
+ // separately because of how Python (used Google)
295
+ // handles array arguments differently than PHP does.
 
 
 
296
 
297
  if (is_array($_POST[$key]))
298
  {
429
  sprintf('<div class="%sss-legal" style="display:none;"', $prefix), $html) ;
430
  }
431
 
 
 
 
 
 
 
432
  // Need to extract form action and rebuild form tag, and add hidden field
433
  // which contains the original action. This action is used to submit the
434
  // form via wp_remote_post().
460
  else
461
  $css = '' ;
462
 
463
+ // Output Javscript for form validation, make sure any class prefix is included
464
  $js = sprintf('
465
  <script type="text/javascript">
466
  jQuery(document).ready(function($) {
 
467
  // Need to fix the name arguments for checkboxes
468
  // so PHP will pass them as an array correctly.
469
  $("div.%sss-form-container input:checkbox").each(function(index) {
476
  ', $prefix) ;
477
 
478
  // Before closing the <script> tag, is this the confirmation
479
+ // AND do we have a custom confirmation page or alert message?
480
 
481
  if ($posted && is_null($action) && !is_null($alert))
482
  $js .= PHP_EOL . 'alert("' . $alert . '") ;' ;
483
 
484
+ // Load the confirmation URL via Ajax?
485
  if ($posted && is_null($action) && !is_null($confirm))
486
+ $js .= PHP_EOL . '$("body").load("' . $confirm . '") ;' ;
487
+
488
+ //if ($posted && is_null($action) && !is_null($confirm))
489
+ //$js .= PHP_EOL . 'window.location.replace("' . $confirm . '") ;' ;
490
 
491
  $js .= '
492
  });
493
  </script>
494
  ' ;
495
 
496
+ //printf('<h3>%s::%s</h3>', basename(__FILE__), __LINE__) ;
497
+ // Send email?
498
+ if ($posted && is_null($action) && $email)
499
+ {
500
+ //printf('<h3>%s::%s</h3>', basename(__FILE__), __LINE__) ;
501
+ wpGForm::SendConfirmationEmail($wpgform_options['email_format']) ;
502
+ }
503
+ //printf('<h3>%s::%s</h3>', basename(__FILE__), __LINE__) ;
504
+
505
  return $js . $css . $html ;
506
  }
507
 
508
+ /**
509
+ * Get Page URL
510
+ *
511
+ * @return string
512
+ */
513
+ function GetPageURL()
514
+ {
515
+ $pageURL = 'http' ;
516
+
517
+ if ($_SERVER["HTTPS"] == "on") $pageURL .= 's' ;
518
+
519
+ $pageURL .= '://' ;
520
+
521
+ if ($_SERVER['SERVER_PORT'] != '80')
522
+ $pageURL .= $_SERVER['SERVER_NAME'] .
523
+ ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'] ;
524
+ else
525
+ $pageURL .= $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] ;
526
+
527
+ return $pageURL ;
528
+ }
529
+
530
  /**
531
  * WordPress Shortcode handler.
532
  *
544
  'prefix' => null, // Add suffix character(s) to all labels
545
  'readonly' => 'off', // Set all form elements to disabled
546
  'title' => 'on', // Remove the H1 element(s) from the Form
547
+ 'maph1h2' => 'off', // Map H1 element(s) on the form to H2 element(s)
548
+ 'email' => 'off' // Send an email confirmation to blog admin on submission
549
  ), $atts) ;
550
 
551
  return wpGForm::ConstructGForm($params) ;
552
  }
553
+
554
+ /**
555
+ * Send Confirmation E-mail
556
+ *
557
+ * Send an e-mail to the blog administrator informing
558
+ * them of a form submission.
559
+ *
560
+ * @param string $action - action to take, register or unregister
561
+ */
562
+ function SendConfirmationEmail($mode = WPGFORM_EMAIL_FORMAT_PLAIN)
563
+ {
564
+ if ($mode == WPGFORM_EMAIL_FORMAT_HTML)
565
+ {
566
+ $headers = 'MIME-Version: 1.0' . PHP_EOL ;
567
+ $headers .= 'Content-type: text/html; charset=iso-8859-1' . PHP_EOL ;
568
+ }
569
+ else
570
+ {
571
+ $headers = '' ;
572
+ }
573
+
574
+ $headers .= sprintf("From: %s <%s>",
575
+ get_bloginfo('name'), get_bloginfo('admin_email')) . PHP_EOL ;
576
+
577
+ $headers .= sprintf("Cc: %s", get_option('admin_email')) . PHP_EOL ;
578
+ $headers .= sprintf("Bcc: %s", get_bloginfo('admin_email')) . PHP_EOL ;
579
+ $headers .= sprintf("Reply-To: %s", get_bloginfo('admin_email')) . PHP_EOL ;
580
+ $headers .= sprintf("X-Mailer: PHP/%s", phpversion()) ;
581
+
582
+ if ($mode == WPGFORM_EMAIL_FORMAT_HTML)
583
+ {
584
+ $html = '
585
+ <html>
586
+ <head>
587
+ <title>%s</title>
588
+ </head>
589
+ <body>
590
+ <p>
591
+ Admin -
592
+ </p>
593
+ <p>
594
+ A form was submitted on your web site.
595
+ <ul>
596
+ <li>URL: %s</li>
597
+ <li>Date: %s</li>
598
+ <li>Time: %s</li>
599
+ </ul>
600
+ </p>
601
+ <p>
602
+ Thank you,<br/><br/>
603
+ %s
604
+ </p>
605
+ <p>
606
+ </p>
607
+ </body>
608
+ </html>
609
+ ' ;
610
+
611
+ $message = sprintf($html, get_bloginfo('name'),
612
+ wpGForm::GetPageUrl(), date('Y-m-d'), date('H:i'), get_bloginfo('name')) ;
613
+ }
614
+ else
615
+ {
616
+ $plain = 'Admin -' . PHP_EOL . PHP_EOL ;
617
+ $plain .= 'A form was submitted on your web site:' . PHP_EOL . PHP_EOL ;
618
+ $plain .= 'URL: %s' . PHP_EOL . 'Date: %s' . PHP_EOL . 'Time: %s' . PHP_EOL . PHP_EOL ;
619
+ $plain .= 'Thank you,' . PHP_EOL . PHP_EOL . '%s' . PHP_EOL ;
620
+
621
+ $message = sprintf($plain, wpGForm::GetPageUrl(),
622
+ date('Y-m-d'), date('H:i'), get_option('blogname')) ;
623
+ }
624
+
625
+ $to = sprintf('%s Admin <%s>, %s Admin<%s>',
626
+ get_option('blogname'), get_option('admin_email'),
627
+ get_option('blogname'), get_option('admin_email')) ;
628
+
629
+ $subject = sprintf('Form Submission from %s', get_option('blogname')) ;
630
+
631
+ //print '<pre>' ;
632
+ //var_dump($to, $subject, $message, $headers) ;
633
+ //print '</pre>' ;
634
+ $status = wp_mail($to, $subject, $message, $headers) ;
635
+
636
+ return $status ;
637
+ }
638
  }
639
 
640
  /**
wpgform-options.php CHANGED
@@ -290,6 +290,17 @@ function wpgform_settings_input()
290
  <textarea class="regular-text code" name="wpgform_options[custom_css_styles]" rows="15" cols="80" id="gform_custom_css_styles"><?php echo $wpgform_options['custom_css_styles']; ?></textarea>
291
  </td>
292
  </tr>
 
 
 
 
 
 
 
 
 
 
 
293
  <tr valign="top">
294
  <th scope="row"><label>Donation Request</label></th>
295
  <td><fieldset>
290
  <textarea class="regular-text code" name="wpgform_options[custom_css_styles]" rows="15" cols="80" id="gform_custom_css_styles"><?php echo $wpgform_options['custom_css_styles']; ?></textarea>
291
  </td>
292
  </tr>
293
+ <tr valign="top">
294
+ <th scope="row"><label>Confirmation Email Format</label></th>
295
+ <td><fieldset>
296
+ <label for="gform_email_format">
297
+ <input name="wpgform_options[email_format]" type="radio" id="gform_email_format" value="<?php echo WPGFORM_EMAIL_FORMAT_HTML ;?>" <?php checked(WPGFORM_EMAIL_FORMAT_HTML, $wpgform_options['email_format']) ; ?> />
298
+ Send confirmation email (when used) in HTML format.</label>
299
+ <br/>
300
+ <input name="wpgform_options[email_format]" type="radio" id="gform_email_format" value="<?php echo WPGFORM_EMAIL_FORMAT_PLAIN ;?>" <?php checked(WPGFORM_EMAIL_FORMAT_PLAIN, $wpgform_options['email_format']) ; ?> />
301
+ Send confirmation email (when used) in Plain Text format.</label>
302
+ </fieldset></td>
303
+ </tr>
304
  <tr valign="top">
305
  <th scope="row"><label>Donation Request</label></th>
306
  <td><fieldset>