Google Forms - Version 0.9

Version Description

No known upgrade issues.

Download this release

Release Info

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

Version 0.9

Files changed (8) hide show
  1. gforms.css +64 -0
  2. index.php +42 -0
  3. readme.txt +204 -0
  4. screenshot-1.png +0 -0
  5. screenshot-2.png +0 -0
  6. screenshot-3.png +0 -0
  7. wpgform-core.php +362 -0
  8. wpgform-options.php +309 -0
gforms.css ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* vim: set expandtab tabstop=4 shiftwidth=4: */
2
+ /**
3
+ * CSS declarations for Google Docs Forms
4
+ *
5
+ * These can be copied and modified to fit the needs of
6
+ * a theme. By default the only change is to make all of
7
+ * the fields wider than their default width and to set the
8
+ * default font.
9
+ */
10
+
11
+ body.ss-base-body {}
12
+ div.errorbox-good {}
13
+ div.ss-attribution {}
14
+ div.ss-footer {}
15
+ div.ss-form {}
16
+ div.ss-form-container {
17
+ font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
18
+ }
19
+ div.ss-form-desc {}
20
+ div.ss-form-entry {}
21
+ div.ss-form-entry>input {
22
+ background-color: #e0e0e0;
23
+ font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
24
+ }
25
+ div.ss-form-heading {}
26
+ div.ss-item {}
27
+ div.ss-legal {}
28
+ div.ss-navigate {}
29
+ div.ss-no-ignore-whitespace {
30
+ white-space: pre-wrap;
31
+ }
32
+ div.ss-required-asterisk {
33
+ color: red;
34
+ font-weight: bold;
35
+ }
36
+ div.ss-scale {}
37
+ div.ss-text {}
38
+ form#ss-form {}
39
+ h1.ss-form-title {}
40
+ hr.ss-email-break {}
41
+ input.ss-q-short {
42
+ width: 300px;
43
+ }
44
+ label.ss-q-help {}
45
+ label.ss-q-radio {}
46
+ label.ss-q-title {
47
+ font-weight: bold;
48
+ }
49
+ span.ss-powered-by {}
50
+ span.ss-terms {}
51
+ td.ss-gridnumber {}
52
+ td.ss-gridnumbers {}
53
+ td.ss-gridrow
54
+ td.ss-gridrow-leftlabel
55
+ td.ss-leftlabel {}
56
+ td.ss-rightlabel {}
57
+ td.ss-scalerow {}
58
+ td.ss-scalenumber {}
59
+ td.ss-scalenumbers {}
60
+ textarea.ss-q-long {
61
+ background-color: #e0e0e0;
62
+ font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
63
+ }
64
+ tr.ss-gridrow {}
index.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* vim: set expandtab tabstop=4 shiftwidth=4: */
3
+ /**
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.9
8
+ * Build: 0.9.$WCREV$
9
+ * Last Modified: $WCDATE$
10
+ * Author: Mike Walsh
11
+ * Author URI: http://www.michaelwalsh.org
12
+ * License: GPL
13
+ *
14
+ *
15
+ * $Id$
16
+ *
17
+ * (c) 2011 by Mike Walsh
18
+ *
19
+ * @author Mike Walsh <mike@walshcrew.com>
20
+ * @package wpGForm
21
+ * @subpackage admin
22
+ * @version $Rev$
23
+ * @lastmodified $Date$
24
+ * @lastmodifiedby $LastChangedBy$
25
+ *
26
+ */
27
+
28
+ require_once('wpgform-core.php') ;
29
+
30
+ // Use the register_activation_hook to set default values
31
+ register_activation_hook(__FILE__, 'wpgform_register_activation_hook');
32
+
33
+ // Use the init action
34
+ add_action('init', 'wpgform_init' );
35
+
36
+ // Use the admin_menu action to add options page
37
+ add_action('admin_menu', 'wpgform_admin_menu');
38
+
39
+ // Use the admin_init action to add register_setting
40
+ add_action('admin_init', 'wpgform_admin_init' );
41
+
42
+ ?>
readme.txt ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Plugin Name ===
2
+ Contributors: mpwalsh8
3
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DK4MS3AA983CC
4
+ Tags: Google Forms, Google Docs, Google, Spreadsheet, shortcode, forms
5
+ Requires at least: 3.0
6
+ Tested up to: 3.2.1
7
+ Stable tag: trunk
8
+
9
+ Embeds a published, public Google Form in a WordPress post, page, or widget.
10
+
11
+ == Description ==
12
+
13
+ Fetches a published Google Form using a `[gform form='']` WordPress shortcode, removes the Gooogle wrapper HTML and then renders it as an HTML form embedded in your blog post or page. The only required parameter is `form`, which specifies the form you'd like to retrieve. Recommended but optional, you can also pass a URL for a confirmation page. The confirmation page will override the default Google`Thank You` page and offers better integration with your WordPress site. You can also supply a customized `class` value for styling the form.
14
+
15
+ For example, suppose you want to integrate the form at `https://docs.google.com/spreadsheet/viewform?hl=en_US&pli=1&formkey=ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678#gid=0`, (not a real URL) use the following shortcode in your WordPress post or page:
16
+
17
+ [gform form='https://docs.google.com/spreadsheet/viewform?hl=en_US&pli=1&formkey=ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678#gid=0']
18
+
19
+ Currently, this plugin only supports Google Forms that are "Published as a web page" and therefore public. Private Google Forms are not supported.
20
+
21
+ [Demo](http://michaelwalsh.org/wordpress/wordpress-plugins/wpgform/)
22
+
23
+ == Installation ==
24
+
25
+ 1. Install using the WordPress Pluin Installer (search for `WordPress Google Form`) or download `WordPress Google Form`, extract the `wpgforms` folder and upload `wpgforms` to the `/wp-content/plugins/` directory.
26
+ 1. Activate the plugin through the 'Plugins' menu in WordPress.
27
+ 1. Configure `WP Goolge Forms` from the `Settings` menu as appropriate.
28
+ 1. Use the `[gform form='<full_url_to_form>']` shortcode wherever you'd like to insert the Google Form.
29
+
30
+ == Usage ==
31
+
32
+ The WordPress Google Form shortcode `gform` suupports a number of attributes that allow further control and customization of the Google Form.
33
+
34
+ `[gform form='<full_url_to_Google_Form>' confirm='<full_url_to_confirmation_page>' class='<value>' legal='on|off' br='on|off' prefix='<value>' suffix='<value>']`
35
+
36
+ * __form__: The full URL to the published Google Form. You must be able to open this URL successfully from a browser for the __gform__ shortcode to work properly.
37
+ * __confirm__: A full URL to the confirmation (e.g. _Thanks for your submission!_) page. Be default Google displays a very basic confirmation page which cannot be integrated easily with your WordPress site. The _confirm_ attribute allows the form submission to land on a page of your choosing. **It is strongly encouraged that you make use of a confirmation page.** It will make the form submission process cleaner and clearer to the end user.
38
+ * __class__: Google Forms are full of classes but the WordPress Google Form plugin does not bring their definitions into page when importing the form. The _class_ attribute allows the addition of one or more CSS classes to the DIV which wraps the Google Form. To add multiple classes, simply separate the class names with spaces.
39
+ * __legal__: By default Google Forms have a _Powered by Google Docs_ section at the bottom of the form which includes links to Google TOS and other Google information. If you do not want to see this information as part of the form, add `legal='off'` to your shortcode usage. The content remains in the form, it is simply hidden from the end user using CSS.
40
+ * __br__: For a <br> tag to be inserted between the form label and the input text box by setting the *br* attribute to *on*. This will result in the form label and the input box being stacked on top of one another.
41
+ * __prefix__: Google Forms make use 20+ CSS classes. If you use multiple forms and want to style them each differently, you can add a _prefix_ which will be added to beginning of each class name used in the Google Form.
42
+ * __suffix__: Append a character string to the end of each form label. This can also be accomplished using CSS, refer to the CSS section.
43
+
44
+ `[gform form='https://docs.google.com/spreadsheet/viewform?hl=en_US&pli=1&formkey=ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678#gid=0' confirm='http://www.example.com/thankyou/' class='mygform' legal='off' prefix='mygform-' br='on']`
45
+
46
+ == Frequently Asked Questions ==
47
+
48
+ = The default style is ugly. Can I change it? =
49
+ Yes, there are two ways to change the style (aka apearance) of the form.
50
+
51
+ 1. By adding the necessary CSS to your theme's style sheet.
52
+ 1. Through the WordPress Google Form custom CSS setting.
53
+
54
+ Google Forms include plenty of [CSS](http://en.wikipedia.org/wiki/Cascading_Style_Sheets) hooks. Refer to the **CSS** section for further details on styling the form.
55
+
56
+ = Do you have a demo running? =
57
+ Yes, see a demo here: [Demo of WordPress Google Form plugin](http://michaelwalsh.org/wordpress/wordpress-plugins/wpgform/)
58
+
59
+ Feel free to submit a response and then view other responses as well.
60
+
61
+ = Content appears, but it's not my form and it looks odd! =
62
+ You should triple-check that you've published your Form. Google provides instructions for doing this. Be sure to follow steps 1 and 2 in [Google Spreadsheets Help: Publishing to the Web](http://docs.google.com/support/bin/answer.py?hl=en&answer=47134) as the same process applies to Forms and Spreadsheets.
63
+
64
+ = Why doesn't my form look the same as it does when I use the stand alone URL? =
65
+ Google Forms can have _Themes_ which are really nothing more than CSS defitinions to change the form's appearance. None of the Google CSS is brought into WordPress, just the CSS class names and the HTML used to define the form. Refer to the **CSS** section for more information on styling your form.
66
+
67
+ = Google supports embedding forms, why isn't that sufficient? =
68
+ For many uses the simple embedding of a Google Form in an `<iframe>` may be sufficient. However, if you want your forms to take on the look and feel of your WordPress site while retaining the ability to collect information in a Google Spreadsheet, the WordPress Google Form plugin may be for you.
69
+
70
+ = I really like having a colon character after my form labels, is that possible? =
71
+ Sure. You can use the following CSS to have the colon character appear after all of your form labels.
72
+
73
+ `label.ss-q-title:after {
74
+ content: ':';
75
+ }`
76
+
77
+ == CSS ==
78
+
79
+ As of 2011-09-21, Google Forms make use of 20+ CSS class definitions. By default, the WordPress Google Form plugin includes CSS declarations for all of the classes however the bulk of them are empty. The default CSS sets the font and makes the entry boxes wider. The default CSS that ships with WordPress Google Form can optionally be turned off via the WordPress Google Form settings.
80
+
81
+ = Customizing Google Form CSS =
82
+
83
+ There are two ways to customize the Google Form CSS.
84
+
85
+ 1. The WordPress Google Form plugin includes a setting to include custom CSS and a field where custom CSS can be entered. This CSS will be preserved across themes.
86
+ 1. Add custom CSS declarations to your WordPress theme.
87
+
88
+ = Default Google Form CSS =
89
+
90
+ As of 2011-09-22, the following is are the CSS classes which Google Forms make use of. The CSS below represents the default CSS provided by WordPress Google Form. These CSS definitions can be copied and pasted into your theme CSS or the WordPress Google Form custom CSS setting and changed as desired.
91
+
92
+ 'body.ss-base-body {}
93
+ div.errorbox-good {}
94
+ div.ss-attribution {}
95
+ div.ss-footer {}
96
+ div.ss-form {}
97
+ div.ss-form-container {
98
+ font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
99
+ }
100
+ div.ss-form-desc {}
101
+ div.ss-form-entry {}
102
+ div.ss-form-entry>input {
103
+ background-color: #e0e0e0;
104
+ font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
105
+ }
106
+ div.ss-form-heading {}
107
+ div.ss-item {}
108
+ div.ss-legal {}
109
+ div.ss-navigate {}
110
+ div.ss-no-ignore-whitespace {
111
+ white-space: pre-wrap;
112
+ }
113
+ div.ss-required-asterisk {
114
+ color: red;
115
+ font-weight: bold;
116
+ }
117
+ div.ss-scale {}
118
+ div.ss-text {}
119
+ form#ss-form {}
120
+ h1.ss-form-title {}
121
+ hr.ss-email-break {}
122
+ input.ss-q-short {
123
+ width: 300px;
124
+ }
125
+ label.ss-q-help {}
126
+ label.ss-q-radio {}
127
+ label.ss-q-title {
128
+ font-weight: bold;
129
+ }
130
+ span.ss-powered-by {}
131
+ span.ss-terms {}
132
+ td.ss-gridnumber {}
133
+ td.ss-gridnumbers {}
134
+ td.ss-gridrow
135
+ td.ss-gridrow-leftlabel
136
+ td.ss-leftlabel {}
137
+ td.ss-rightlabel {}
138
+ td.ss-scalerow {}
139
+ td.ss-scalenumber {}
140
+ td.ss-scalenumbers {}
141
+ textarea.ss-q-long {
142
+ background-color: #e0e0e0;
143
+ font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
144
+ }
145
+ tr.ss-gridrow {}`
146
+
147
+ == Screenshots ==
148
+
149
+ 1. Standard Google Form
150
+ 2. Same Google Form embedded in WordPress
151
+ 3. Setting Page
152
+
153
+ == Upgrade Notice ==
154
+
155
+ No known upgrade issues.
156
+
157
+ == Changelog ==
158
+
159
+ = Version 0.9 =
160
+
161
+ * Added screenshots.
162
+
163
+ = Version 0.8 =
164
+
165
+ * Fixed formatting of CSS section in ReadMe.txt file.
166
+ * Added documention for *br* and *suffix* short code attributes.
167
+
168
+ = Version 0.7 =
169
+
170
+ * Added new shortcode attribute *br* which can be set to *on* or *off*. The *br* attribute will insert <br> tags between the labels and the input fields causing them to render on top of one another much they appear on Google Forms. The default setting is *off*.
171
+ * Fixed problem due to Javascript embedded in Google Form. It isn't necessary so it is stripped out.
172
+ * Tweaked several default CSS settings, most notably the default width of text entry fields.
173
+ * Cleaned up a bunch of debug code.
174
+
175
+ = Version 0.6 =
176
+
177
+ * Fixed problem with CSS text from Google form theme appearing as text on the embedded form. This text should have been stripped and in some cases it wasn't.
178
+ * Fixed typos in ReadMe.txt file.
179
+
180
+ = Version 0.5 =
181
+
182
+ * Fixed problem with tabs not working correctly on Settings page.
183
+ * Corrected default setting on donation link.
184
+
185
+ = Version 0.4 =
186
+
187
+ * Added support for missing Google Forms fields.
188
+ * Added more CSS styles based on new form fields.
189
+ * Added FAQs and Usage content by retrieving it from the WordPress repository.
190
+ * Removed some debug code.
191
+
192
+ = Version 0.3 =
193
+
194
+ * Added support for `<select>` and `<option>` tags.
195
+ * Fixed Plugin URI path
196
+ * Added links to demo content
197
+
198
+ = Version 0.2 =
199
+
200
+ * Cleaned up ReadMe.txt file.
201
+
202
+ = Version 0.1 =
203
+
204
+ * Initial release.
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file
screenshot-3.png ADDED
Binary file
wpgform-core.php ADDED
@@ -0,0 +1,362 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* vim: set expandtab tabstop=4 shiftwidth=4: */
3
+ /**
4
+ * GForm functions.
5
+ *
6
+ * $Id$
7
+ *
8
+ * (c) 2011 by Mike Walsh
9
+ *
10
+ * @author Mike Walsh <mike@walshcrew.com>
11
+ * @package wpGForm
12
+ * @subpackage functions
13
+ * @version $Revision$
14
+ * @lastmodified $Date$
15
+ * @lastmodifiedby $Author$
16
+ *
17
+ */
18
+
19
+ // Filesystem path to this plugin.
20
+ define('WPGFORM_PATH', WP_PLUGIN_DIR.'/'.dirname(plugin_basename(__FILE__))) ;
21
+
22
+ /**
23
+ * wpgform_init()
24
+ *
25
+ * Init actions to enable shortcodes.
26
+ *
27
+ * @return null
28
+ */
29
+ function wpgform_init()
30
+ {
31
+ $wpgform_options = get_option('wpgform_options');
32
+
33
+ if ($wpgform_options['sc_posts'] == 1)
34
+ add_shortcode('wpgform', 'wpgform_shortcode');
35
+
36
+ if ($wpgform_options['sc_widgets'] == 1)
37
+ add_filter('widget_text', 'do_shortcode');
38
+
39
+ if ($wpgform_options['default_css'] == 1)
40
+ add_action('template_redirect', 'wpgform_head');
41
+
42
+ //add_action('wp_footer', 'wpgform_footer') ;
43
+ }
44
+
45
+ /**
46
+ * wpgform_admin_menu()
47
+ *
48
+ * Adds admin menu page(s) to the Dashboard.
49
+ *
50
+ * @return null
51
+ */
52
+ function wpgform_admin_menu()
53
+ {
54
+ require_once(WPGFORM_PATH . '/wpgform-options.php') ;
55
+
56
+ $wpgform_options_page = add_options_page('WP Google Form', 'WP Google Form ',
57
+ 'manage_options', 'wpgform-options.php', 'wpgform_options_page');
58
+ add_action('admin_footer-'.$wpgform_options_page, 'wpgform_options_admin_footer');
59
+ add_action('admin_print_scripts-'.$wpgform_options_page, 'wpgform_options_print_scripts');
60
+ add_action('admin_print_styles-'.$wpgform_options_page, 'wpgform_options_print_styles');
61
+ }
62
+
63
+ /**
64
+ * wpgform_admin_init()
65
+ *
66
+ * Init actions for the Dashboard interface.
67
+ *
68
+ * @return null
69
+ */
70
+ function wpgform_admin_init()
71
+ {
72
+ register_setting('wpgform_options', 'wpgform_options') ;
73
+ }
74
+
75
+ /**
76
+ * wpgform_register_activation_hook()
77
+ *
78
+ * Adds the default options so WordPress options are
79
+ * configured to a default state upon plugin activation.
80
+ *
81
+ * @return null
82
+ */
83
+ function wpgform_register_activation_hook()
84
+ {
85
+ $default_wpgform_options = array(
86
+ 'sc_posts' => 1
87
+ ,'sc_widgets' => 1
88
+ ,'default_css' => 1
89
+ ,'custom_css' => 0
90
+ ,'custom_css_styles' => ''
91
+ ,'donation_message' => 0
92
+ ) ;
93
+
94
+ add_option('wpgform_options', $default_wpgform_options);
95
+ //add_shortcode('wpgform', 'wpgform_shortcode');
96
+ add_filter('widget_text', 'do_shortcode');
97
+ }
98
+
99
+ add_shortcode('gform', array('wpGForm', 'RenderGForm'));
100
+
101
+
102
+ /**
103
+ * wpGForm class definition
104
+ *
105
+ * @author Mike Walsh <mike@walshcrew.com>
106
+ * @access public
107
+ * @see wp_remote_get()
108
+ * @see RenderGForm()
109
+ * @see ConstructGForm()
110
+ */
111
+ class wpGForm
112
+ {
113
+ /**
114
+ * Constructor
115
+ */
116
+ function wpGForm()
117
+ {
118
+ // empty for now
119
+ }
120
+
121
+ /**
122
+ * Function ConstructGForm grabs CSV data from a URL and returns an HTML table.
123
+ *
124
+ * @param $options array Values passed from the shortcode.
125
+ * @return An HTML string if successful, false otherwise.
126
+ * @see RenderGForm
127
+ */
128
+ function ConstructGForm($options)
129
+ {
130
+ // If no URL then return as nothing useful can be done.
131
+ if (!$options['form'])
132
+ {
133
+ return false;
134
+ }
135
+ else
136
+ {
137
+ $form = $options['form'] ;
138
+ }
139
+
140
+ // Custom Confirmation URL? Optional
141
+ if (!$options['confirm'])
142
+ {
143
+ $confirm = null ;
144
+ }
145
+ else
146
+ {
147
+ $confirm = $options['confirm'] ;
148
+ }
149
+
150
+ // Custom Class? Optional
151
+ if (!$options['class'])
152
+ {
153
+ $class = null ;
154
+ }
155
+ else
156
+ {
157
+ $class = $options['class'] ;
158
+ }
159
+
160
+ // Class Prefix? Optional
161
+ if (!$options['prefix'])
162
+ {
163
+ $prefix = null ;
164
+ }
165
+ else
166
+ {
167
+ $prefix = $options['prefix'] ;
168
+ }
169
+ // Label Suffix? Optional
170
+ if (!$options['suffix'])
171
+ {
172
+ $suffix = null ;
173
+ }
174
+ else
175
+ {
176
+ $suffix = $options['suffix'] ;
177
+ }
178
+
179
+ // Breaks between labels and inputs?
180
+ $br = $options['br'] === 'on' ;
181
+
182
+ // Google Legal Stuff?
183
+ $legal = $options['legal'] !== 'off' ;
184
+
185
+ // WordPress converts all of the ampersand characters to their
186
+ // appropriate HTML entity or some variety of it. Need to undo
187
+ // that so the URL can be actually be used.
188
+
189
+ $form = str_replace(array('&#038;','&#38;','&amp;'), '&', $form) ;
190
+ $confirm = str_replace(array('&#038;','&#38;','&amp;'), '&', $confirm) ;
191
+
192
+ // Retrieve the HTML from the URL
193
+ $response = wp_remote_get($form, array('sslverify' => false)) ;
194
+
195
+ if (is_wp_error($response))
196
+ return '<div class="gform-error">Unable to retrieve Google Form.</div>' ;
197
+ else
198
+ $html = $response['body'] ;
199
+
200
+
201
+ // Need to filter the HTML retrieved from the form and strip off the stuff
202
+ // we don't want. This gets rid of the HTML wrapper from the Google page.
203
+
204
+ $allowed_tags = array(
205
+ 'a' => array('href' => array(), 'title' => array(), 'target' => array())
206
+ ,'abbr' => array('title' => array()),'acronym' => array('title' => array())
207
+ ,'code' => array()
208
+ ,'pre' => array()
209
+ ,'em' => array()
210
+ ,'strong' => array()
211
+ ,'ul' => array()
212
+ ,'ol' => array()
213
+ ,'li' => array()
214
+ ,'p' => array()
215
+ ,'br' => array()
216
+ ,'div' => array('class' => array())
217
+ ,'h1' => array('class' => array())
218
+ ,'label' => array('class' => array(), 'for' => array())
219
+ ,'input' => array('id' => array(), 'name' => array(), 'class' => array(), 'type' => array(), 'value' => array())
220
+ ,'select' => array('name' => array(), 'for' => array())
221
+ ,'option' => array('value' => array(), 'checked' => array())
222
+ ,'form' => array('id' => array(), 'class' => array(), 'action' => array(), 'method' => array(), 'target' => array(), 'onsubmit' => array())
223
+ ,'script' => array('type' => array())
224
+ ,'table' => array()
225
+ ,'tbody' => array()
226
+ ,'textarea' => array('id' => array(), 'name' => array(), 'class' => array(), 'type' => array(), 'value' => array(), 'rows' => array(), 'cols' => array())
227
+ ,'thead' => array()
228
+ ,'tr' => array('class' => array())
229
+ ,'td' => array('class' => array(), 'style' => array())
230
+ );
231
+
232
+ $html = wp_kses($html, $allowed_tags) ;
233
+
234
+ // Did we end up with anything prior to the first DIV? If so, remove it as
235
+ // it should have been removed by wp_kses() but sometimes stuff slips through!
236
+
237
+ $first_div = strpos($html, '<div') ;
238
+
239
+ // If there are no DIVs, then we have garbage and should stop now!
240
+
241
+ if ($first_div === false)
242
+ return '<div class="gform-error">Unable to retrieve Google Form.</div>' ;
243
+
244
+ // Strip off anything prior to the first DIV, we don't want it.
245
+
246
+ if ($first_div !== 0)
247
+ $html = substr($html, $first_div) ;
248
+
249
+ // The Google Forms have some Javascript embedded in them which needs to be
250
+ // stripped out. I am not sure why it is in there, it doesn't appear to do
251
+ // much of anything useful.
252
+
253
+ $html = preg_replace('#<script[^>]*>.*?</script>#is',
254
+ '<!-- Google Forms unnessary Javascript removed -->' . PHP_EOL, $html);
255
+
256
+ // Augment class names with some sort of a prefix?
257
+
258
+ if (!is_null($prefix))
259
+ $html = preg_replace('/ class="/i', " class=\"{$prefix}", $html) ;
260
+
261
+ // Augment labels with some sort of a suffix?
262
+
263
+ if (!is_null($suffix))
264
+ $html = preg_replace('/<\/label>/i', "{$suffix}</label>", $html) ;
265
+
266
+ // Insert breaks between labels and input fields?
267
+
268
+ if ($br)
269
+ $html = preg_replace('/<\/label>[\w\n]*<input/i', '</label><br/><input', $html) ;
270
+
271
+ // Hide Google Legal Stuff?
272
+
273
+ if (!$legal)
274
+ $html = preg_replace('/<div class="ss-legal"/i', '<div class="ss-legal" style="display:none;"', $html) ;
275
+
276
+ // By default Google will display it's own confirmation page which can't
277
+ // be styled and is not contained within the web site. The plugin can
278
+ // optionally add some Javascript to redirect to a different URL upon
279
+ // submission of the form.
280
+
281
+ // Redirect to a custom confirmation page instead of the Google default?
282
+
283
+ if (!is_null($confirm))
284
+ {
285
+ // Need to modify the FORM tag and add some new attributes.
286
+ $xtra_form_attrs = 'target="gform_iframe" onsubmit="submitted=true;"' ;
287
+ $html = preg_replace("/<form/i", "<form {$xtra_form_attrs}", $html) ;
288
+
289
+ // Need some extra HTML which must be inserted before the extract FORM HTML.
290
+ $xtra_html = '<script type="text/javascript">var submitted=false;</script>' ;
291
+ $xtra_html .= '<iframe name="gform_iframe" id="gform_iframe" style="display:none;" onload="if(submitted){window.location=\'' . $confirm . '\';}"></iframe>' ;
292
+ }
293
+ else
294
+ $xtra_html = '' ;
295
+
296
+ // Output custom CSS?
297
+
298
+ $wpgform_options = get_option('wpgform_options');
299
+
300
+ if ($wpgform_options['custom_css'] == 1)
301
+ $css = '<style>' . $wpgform_options['custom_css_styles'] . '</style>' ;
302
+ else
303
+ $css = '' ;
304
+
305
+ return $css . $xtra_html . $html ;
306
+ }
307
+
308
+ /**
309
+ * WordPress Shortcode handler.
310
+ *
311
+ * @return HTML
312
+ */
313
+ function RenderGForm($atts) {
314
+ $params = shortcode_atts(array(
315
+ 'form' => false, // Google Form URL
316
+ 'confirm' => false, // Optional URL to redirect to instead of Google confirmation
317
+ 'class' => 'gform', // Container element's custom class value
318
+ 'legal' => 'on', // Display Google Legal Stuff
319
+ 'br' => 'off', // Insert <br> tags between labels and inputs
320
+ 'suffix' => null, // Add suffix character(s) to all labels
321
+ 'prefix' => null // Add suffix character(s) to all labels
322
+ ), $atts) ;
323
+
324
+ return wpGForm::ConstructGForm($params) ;
325
+ }
326
+ }
327
+
328
+ /**
329
+ * wpgform_head()
330
+ *
331
+ * WordPress header actions
332
+ */
333
+ function wpgform_head()
334
+ {
335
+ // Need default gForm CSS
336
+ wp_enqueue_style('gform',
337
+ plugins_url(plugin_basename(dirname(__FILE__) . '/gforms.css'))) ;
338
+ }
339
+
340
+ /**
341
+ * wpgform_footer()
342
+ *
343
+ * WordPress footer actions
344
+ */
345
+ function wpgform_footer()
346
+ {
347
+ // Need jQuery to dink with DIV content
348
+ wp_enqueue_script('jquery') ;
349
+ ?>
350
+ <script type="text/javascript">
351
+ //
352
+ // jQuery script to decode any HTML entities found in the
353
+ // ss-section-description classes.
354
+ //
355
+ jQuery(document).ready(function($) {
356
+ alert('GForm jQuery goes here.') ;
357
+ // Placeholder to do some processing on the Google form content if/when needed.
358
+ });
359
+ </script>
360
+ <?php
361
+ }
362
+ ?>
wpgform-options.php ADDED
@@ -0,0 +1,309 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* vim: set expandtab tabstop=4 shiftwidth=4: */
3
+ /**
4
+ * GForm options.
5
+ *
6
+ * $Id$
7
+ *
8
+ * (c) 2011 by Mike Walsh
9
+ *
10
+ * @author Mike Walsh <mike@walshcrew.com>
11
+ * @package wpGForm
12
+ * @subpackage options
13
+ * @version $Revision$
14
+ * @lastmodified $Date$
15
+ * @lastmodifiedby $Author$
16
+ *
17
+ */
18
+
19
+ /**
20
+ * wpgform_options_admin_footer()
21
+ *
22
+ * Hook into Admin head when showing the options page
23
+ * so the necessary jQuery script that controls the tabs
24
+ * is executed.
25
+ *
26
+ * @return null
27
+ */
28
+ function wpgform_options_admin_footer()
29
+ {
30
+ error_log(sprintf('%s::%s', basename(__FILE__), __LINE__)) ;
31
+ ?>
32
+ <!-- Setup jQuery Tabs -->
33
+ <script type="text/javascript">
34
+ jQuery(document).ready(function() {
35
+ jQuery("#gform-tabs").tabs() ;
36
+ }) ;
37
+ </script>
38
+ <?php
39
+ error_log(sprintf('%s::%s', basename(__FILE__), __LINE__)) ;
40
+ } /* function wpgform_options_admin_footer() */
41
+
42
+ /**
43
+ * wpgform_options_print_scripts()
44
+ *
45
+ * Hook into Admin Print Scripts when showing the options page
46
+ * so the necessary scripts that controls the tabs are loaded.
47
+ *
48
+ * @return null
49
+ */
50
+ function wpgform_options_print_scripts()
51
+ {
52
+ // Need to load jQuery UI Tabs to make the page work!
53
+
54
+ wp_enqueue_script('jquery-ui-tabs') ;
55
+ }
56
+
57
+ /**
58
+ * wpgform_options_print_styles()
59
+ *
60
+ * Hook into Admin Print Styles when showing the options page
61
+ * so the necessary style sheets that control the tabs are
62
+ * loaded.
63
+ *
64
+ * @return null
65
+ */
66
+ function wpgform_options_print_styles()
67
+ {
68
+ // Need the jQuery UI CSS to make the tabs look correct.
69
+ // Load them from Google - should not be an issue since
70
+ // this plugin is all about consuming Google content!
71
+
72
+ wp_enqueue_style('xtra-jquery-ui-css', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css') ;
73
+ }
74
+
75
+ /**
76
+ * wpgform_options_page()
77
+ *
78
+ * Build and render the options page.
79
+ *
80
+ * @return null
81
+ */
82
+ function wpgform_options_page()
83
+ {
84
+ ?>
85
+ <div class="wrap">
86
+ <?php
87
+ if (function_exists(screen_icon)) screen_icon() ;
88
+ ?>
89
+ <h2><?php _e('WordPress Google Form Plugin Settings') ; ?></h2>
90
+ <?php
91
+ $wpgform_options = get_option('wpgform_options') ;
92
+ if (!$wpgform_options['donation_message'])
93
+ {
94
+ ?>
95
+ <small>Please consider making a <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DK4MS3AA983CC" target="_blank">PayPal donaton</a> if you find this plugin useful.</small>
96
+ <?php
97
+ }
98
+ ?>
99
+ <br /><br />
100
+ <div class="container">
101
+ <div id="gform-tabs">
102
+ <ul>
103
+ <li><a href="#gform-tabs-1">Options</a></li>
104
+ <li><a href="#gform-tabs-2">FAQs</a></li>
105
+ <li><a href="#gform-tabs-3">Usage</a></li>
106
+ <li><a href="#gform-tabs-4">About</a></li>
107
+ </ul>
108
+ <div id="gform-tabs-1">
109
+ <form method="post" action="options.php">
110
+ <?php settings_fields('wpgform_options') ; ?>
111
+ <?php wpgform_settings_input() ; ?>
112
+ <input type="submit" name="Submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
113
+ </form>
114
+ </div>
115
+ <div id="gform-tabs-2">
116
+ <?php
117
+ // Instead of duplicating the FAQ content in the ReadMe.txt file,
118
+ // let's simply extract it from the WordPress plugin repository!
119
+ //
120
+ // This solutution is derived from a discussion found on www.DevNetwork.net.
121
+ // See full discussion: http://www.devnetwork.net/viewtopic.php?f=38&t=102670
122
+ //
123
+
124
+ /*
125
+ // Commented regex to extract contents from <div class="main">contents</div>
126
+ // where "contents" may contain nested <div>s.
127
+ // Regex uses PCRE's recursive (?1) sub expression syntax to recurs group 1
128
+
129
+ $pattern_long = '{ # recursive regex to capture contents of "main" DIV
130
+ <div\s+class="main"\s*> # match the "main" class DIV opening tag
131
+ ( # capture "main" DIV contents into $1
132
+ (?: # non-cap group for nesting * quantifier
133
+ (?: (?!<div[^>]*>|</div>). )++ # possessively match all non-DIV tag chars
134
+ | # or
135
+ <div[^>]*>(?1)</div> # recursively match nested <div>xyz</div>
136
+ )* # loop however deep as necessary
137
+ ) # end group 1 capture
138
+ </div> # match the "main" class DIV closing tag
139
+ }six'; // single-line (dot matches all), ignore case and free spacing modes ON
140
+ */
141
+
142
+ // WordPress plugin repository places the content in DIV with a class of
143
+ // "block-content" but there are actually several DIVs that have the same class.
144
+ // We only want the first one.
145
+
146
+ $url = 'http://wordpress.org/extend/plugins/wpgform/faq/' ;
147
+ $response= wp_remote_get($url) ;
148
+
149
+ if (is_wp_error($response))
150
+ {
151
+ ?>
152
+ <div class="updated error">Unable to retrive FAQ content from WordPress plugin repository.</div>
153
+ <?php
154
+ }
155
+ else
156
+ {
157
+ ?>
158
+ <?php
159
+ $data = &$response['body'] ;
160
+ $pattern_short = '{<div\s+[^>]*?class="block-content"[^>]*>((?:(?:(?!<div[^>]*>|</div>).)++|<div[^>]*>(?1)</div>)*)</div>}si';
161
+ $matchcount = preg_match_all($pattern_short, $data, $matches);
162
+
163
+ // Did we find something?
164
+ if ($matchcount > 0)
165
+ {
166
+ // The content we want will be the first match
167
+ echo($matches[1][0]); // print 1st capture group for match number i
168
+ }
169
+ else
170
+ {
171
+ ?>
172
+ <div class="updated error">Unable to retrive FAQ content from WordPress plugin repository.</div>
173
+ <?php
174
+ }
175
+ //echo("\n</pre>");
176
+ }
177
+
178
+ ?>
179
+ </div>
180
+ <div id="gform-tabs-3">
181
+ <?php
182
+ // Instead of duplicating the FAQ content in the ReadMe.txt file,
183
+ // let's simply extract it from the WordPress plugin repository!
184
+ //
185
+ // This solutution is derived from a discussion found on www.DevNetwork.net.
186
+ // See full discussion: http://www.devnetwork.net/viewtopic.php?f=38&t=102670
187
+ //
188
+
189
+ /*
190
+ // Commented regex to extract contents from <div class="main">contents</div>
191
+ // where "contents" may contain nested <div>s.
192
+ // Regex uses PCRE's recursive (?1) sub expression syntax to recurs group 1
193
+
194
+ $pattern_long = '{ # recursive regex to capture contents of "main" DIV
195
+ <div\s+class="main"\s*> # match the "main" class DIV opening tag
196
+ ( # capture "main" DIV contents into $1
197
+ (?: # non-cap group for nesting * quantifier
198
+ (?: (?!<div[^>]*>|</div>). )++ # possessively match all non-DIV tag chars
199
+ | # or
200
+ <div[^>]*>(?1)</div> # recursively match nested <div>xyz</div>
201
+ )* # loop however deep as necessary
202
+ ) # end group 1 capture
203
+ </div> # match the "main" class DIV closing tag
204
+ }six'; // single-line (dot matches all), ignore case and free spacing modes ON
205
+ */
206
+
207
+ // WordPress plugin repository places the content in DIV with a class of
208
+ // "block-content" but there are actually several DIVs that have the same class.
209
+ // We only want the first one.
210
+
211
+ $url = 'http://wordpress.org/extend/plugins/wpgform/other_notes/' ;
212
+ $response= wp_remote_get($url) ;
213
+
214
+ if (is_wp_error($response))
215
+ {
216
+ ?>
217
+ <div class="updated error">Unable to retrive FAQ content from WordPress plugin repository.</div>
218
+ <?php
219
+ }
220
+ else
221
+ {
222
+ ?>
223
+ <?php
224
+ $data = &$response['body'] ;
225
+ $pattern_short = '{<div\s+[^>]*?class="block-content"[^>]*>((?:(?:(?!<div[^>]*>|</div>).)++|<div[^>]*>(?1)</div>)*)</div>}si';
226
+ $matchcount = preg_match_all($pattern_short, $data, $matches);
227
+
228
+ // Did we find something?
229
+ if ($matchcount > 0)
230
+ {
231
+ // The content we want will be the first match
232
+ echo($matches[1][0]); // print 1st capture group for match number i
233
+ }
234
+ else
235
+ {
236
+ ?>
237
+ <div class="updated error">Unable to retrive FAQ content from WordPress plugin repository.</div>
238
+ <?php
239
+ }
240
+ //echo("\n</pre>");
241
+ }
242
+
243
+ ?>
244
+ </div>
245
+ <div id="gform-tabs-4">
246
+ <h4>About WordPress Google Form</h4>
247
+ <p>An easy to implement integration of a Google Form with WordPress. This plugin allows you to leverage the power of Google Docs Spreadsheets and Forms to collect data while retaining the look and feel of your WordPress based web site. The forms can optionally be styled to better integrate with your WordPress theme.</p>
248
+ <p>WordPress Google Form is based on the <a href="http://codex.wordpress.org/Function_API/wp_remote_get"><b>wp_remote_get()</b></a> function for retrieving the form and <a href="http://codex.wordpress.org/Function_Reference/wp_kses"><b>wp_kses()</b></a> function for processing HTML. If you find this plugin useful and use it for commercial purposes, please consider <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DK4MS3AA983CC" target="_blank">making small donations towards this plugin</a> to help keep it up to date.</p>
249
+ </div>
250
+ </div>
251
+ </div>
252
+ <?php
253
+ }
254
+
255
+
256
+ /**
257
+ * wpgform_settings_input()
258
+ *
259
+ * Build the form content and populate with any current plugin settings.
260
+ *
261
+ * @return none
262
+ */
263
+ function wpgform_settings_input()
264
+ {
265
+ $wpgform_options = get_option('wpgform_options') ; ?>
266
+ <table class="form-table">
267
+ <tr valign="top">
268
+ <th scope="row"><label><b><i>gform</i></b> Shortcode</label></th>
269
+ <td><fieldset>
270
+ <label for="gform_sc_posts">
271
+ <input name="wpgform_options[sc_posts]" type="checkbox" id="gform_sc_posts" value="1" <?php checked('1', $wpgform_options['sc_posts']) ; ?> />
272
+ Enable shortcodes for posts and pages</label>
273
+ <br />
274
+ <label for="gform_sc_widgets">
275
+ <input name="wpgform_options[sc_widgets]" type="checkbox" id="gform_sc_widgets" value="1" <?php checked('1', $wpgform_options['sc_widgets']) ; ?> />
276
+ Enable shortcodes in text widget</label>
277
+ </fieldset></td>
278
+ </tr>
279
+ <tr valign="top">
280
+ <th scope="row"><label><b><i>gform</i></b> CSS</label></th>
281
+ <td><fieldset>
282
+ <label for="gform_default_css">
283
+ <input name="wpgform_options[default_css]" type="checkbox" id="gform_default_css" value="1" <?php checked('1', $wpgform_options['default_css']) ; ?> />
284
+ Enable default WordPress Google Form CSS</label>
285
+ <br />
286
+ <label for="gform_custom_css">
287
+ <input name="wpgform_options[custom_css]" type="checkbox" id="gform_custom_css" value="1" <?php checked('1', $wpgform_options['custom_css']) ; ?> />
288
+ Enable custom WordPress Google Form CSS</label>
289
+ </fieldset></td>
290
+ </tr>
291
+ <tr valign="top">
292
+ <th scope="row"><label>Custom GForm CSS</label><br/><small><i>Optional CSS styles to control the appearance of the Google Form.</i></small></th>
293
+ <td>
294
+ <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>
295
+ </td>
296
+ </tr>
297
+ <tr valign="top">
298
+ <th scope="row"><label>Donation Request</label></th>
299
+ <td><fieldset>
300
+ <label for="gform_donation_message">
301
+ <input name="wpgform_options[donation_message]" type="checkbox" id="gform_donation_message" value="1" <?php checked('1', $wpgform_options['donation_message']) ; ?> />
302
+ Hide the request for donation at the top of this page. Donation request will remain on the <b>About</b> tab.</label>
303
+ </fieldset></td>
304
+ </tr>
305
+ </table>
306
+ <br /><br />
307
+ <?php
308
+ }
309
+ ?>