Email Before Download - Version 0.5

Version Description

Download this release

Release Info

Developer ashokaggarwal
Plugin Icon 128x128 Email Before Download
Version 0.5
Comparing to
See all releases

Version 0.5

trunk/email-before-download.php ADDED
@@ -0,0 +1,254 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Email Before Download
4
+ Plugin URI: http://www.mandsconsulting.com/
5
+ Description: This plugin seamlessly integrates two popular plugins (Contact Form 7 and Download Monitor) to create a simple shortcode for requesting an end-user to fill out a form before providing the download URL. You can use an existing Contact Form 7 form, where you might typically request contact information like an email address, but the questions in the form are completely up to you. Once the end user completes the form, you can choose to either show a link directly to the download or send an email with the direct link to the email provided in the contact form.
6
+ Author: M&S Consulting
7
+ Version: 0.5
8
+ Author URI: http://www.mandsconsulting.com
9
+
10
+ ============================================================================================================
11
+ This software is provided "as is" and any express or implied warranties, including, but not limited to, the
12
+ implied warranties of merchantibility and fitness for a particular purpose are disclaimed. In no event shall
13
+ the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or
14
+ consequential damages(including, but not limited to, procurement of substitute goods or services; loss of
15
+ use, data, or profits; or business interruption) however caused and on any theory of liability, whether in
16
+ contract, strict liability, or tort(including negligence or otherwise) arising in any way out of the use of
17
+ this software, even if advised of the possibility of such damage.
18
+
19
+ For full license details see license.txt
20
+ ============================================================================================================
21
+ */
22
+
23
+ function emailreqtag_func($atts) {
24
+ extract(shortcode_atts(array(
25
+ 'download_id' => 'something',
26
+ 'contact_form_id' => 'something else',
27
+ ), $atts));
28
+
29
+ $dl = get_downloads('include='.$dowload_id.'&limit=5');
30
+
31
+ global $wpdb,$wp_dlm_root,$wp_dlm_db,$wp_dlm_db_taxonomies, $def_format, $dlm_url, $downloadurl, $downloadtype, $wp_dlm_db_meta;
32
+ $dl = $wpdb->get_row( "SELECT * FROM $wp_dlm_db WHERE id = ".$wpdb->escape($download_id).";" );
33
+ $d = new downloadable_file($dl);
34
+ $str = '';
35
+
36
+ $title = '';
37
+
38
+ $url = '';
39
+
40
+ if (!empty($d)) {
41
+ $date = date("jS M Y", strtotime($d->date));
42
+ $title = $d->title;
43
+ $url = $d->url;
44
+ }
45
+
46
+ $contact_form = do_shortcode("[contact-form $contact_form_id \"$title\"]");
47
+
48
+ $hf = '<input type="hidden" name="_wpcf7_download_id" value="' . $download_id. '" /></form>';
49
+
50
+ $contact_form = str_replace("</form>", $hf, $contact_form);
51
+
52
+ $wrap_in_div = get_option('email_before_download_wrap_in_div');
53
+ $div_class = '';
54
+ if(strlen(trim($wrap_in_div)) > 0 ){
55
+ $div_class = 'class="' . trim($wrap_in_div) . '"';
56
+ }
57
+ return "<br/>" . $contact_form . '<div id="wpm_download_' . $download_id . '" ' . $div_class . ' style="display:none;"> </div> ';
58
+ }
59
+ add_shortcode('emailreq', 'emailreqtag_func');
60
+ add_shortcode('email-download', 'emailreqtag_func');
61
+
62
+ function process_email_form( $cf7 ) {
63
+
64
+ if(isset( $_POST['_wpcf7_download_id'] )){
65
+ global $wpdb,$wp_dlm_root,$wp_dlm_db,$wp_dlm_db_taxonomies, $def_format, $dlm_url, $downloadurl, $downloadtype, $wp_dlm_db_meta;
66
+ $dl = $wpdb->get_row( "SELECT * FROM $wp_dlm_db WHERE id = ".$wpdb->escape($_POST['_wpcf7_download_id']).";" );
67
+ $d = new downloadable_file($dl);
68
+ $dId = $_POST['_wpcf7_download_id'];
69
+ $cf7->posted_data['your-message'] = 'The downloaded file name: ' . $d->title;
70
+ if(strpos($cf7->mail['body'], "[your-message]") === false ){
71
+ $cf7->posted_data['your-message'] = $d->title;
72
+ $cf7->mail['body'] = $cf7->mail['body'] ."\nThe downloaded file name: [your-message]";
73
+
74
+ }
75
+
76
+ $title = '';
77
+
78
+ $url = '';
79
+
80
+ if (!empty($d)) {
81
+ $title = $d->title;
82
+ $url = $d->url;
83
+ }
84
+ $target = '_blank';
85
+ $target = get_option('email_before_download_link_target');
86
+ $html_before = get_option('email_before_download_html_before_link');
87
+ $html_after = get_option('email_before_download_html_after_link');
88
+ $email_template = get_option('email_before_download_email_template');
89
+ $message = '';
90
+ if(strlen(trim($email_template)) > 0){
91
+ $message = str_replace(array('[requesting_name]', '[file_url]', '[file_name]'), array($cf7->posted_data['your-name'], $url, $title), trim($email_template));
92
+ }
93
+ else $message = '<a class="icon-button download-icon" target="' . $target . '" href="' . $url .'">' . $title . '</a>';
94
+
95
+ $innerHtml = $html_before . '<a class="icon-button download-icon" target="' . $target . '" href="' . $url .'"><span class="et-icon"><span>' . $title . '</span></span></a><br clear="both" />' . $html_after;
96
+
97
+ if(get_option('email_before_download_send_email') == 'Send Email') {
98
+ @wp_mail( $cf7->posted_data['your-email'], 'Requested URL for the file: '. $title , $message, "Content-Type: text/html\n");
99
+ $cf7->additional_settings = "on_sent_ok: \"document.getElementById('wpm_download_$dId').style.display = 'inline'; document.getElementById('wpm_download_$dId').innerHTML='The link to the file has been emailed to you.'; \"";
100
+ }
101
+ else if (get_option('email_before_download_send_email') == 'Both'){
102
+ @wp_mail( $cf7->posted_data['your-email'], 'Requested URL for the file: '. $title , $message, "Content-Type: text/html\n");
103
+ $cf7->additional_settings = "on_sent_ok: \"document.getElementById('wpm_download_$dId').style.display = 'inline'; document.getElementById('wpm_download_$dId').innerHTML='$innerHtml'; \"";
104
+ }
105
+ else $cf7->additional_settings = "on_sent_ok: \"document.getElementById('wpm_download_$dId').style.display = 'inline'; document.getElementById('wpm_download_$dId').innerHTML='$innerHtml'; \"";
106
+ }
107
+ return $cf7;
108
+ }
109
+ add_action( 'wpcf7_before_send_mail', 'process_email_form' );
110
+
111
+ add_action('admin_menu', 'ebd_plugin_menu');
112
+
113
+ function ebd_plugin_menu() {
114
+
115
+ add_options_page('Email Before Download Options', 'Email Before Download', 'manage_options', 'email-before-download', 'email_before_download_options');
116
+ add_action( 'admin_init', 'register_email_before_download_settings' );
117
+
118
+ }
119
+
120
+ add_filter( 'plugin_action_links', 'ebd_plugin_action_links', 10, 2 );
121
+
122
+ function ebd_plugin_action_links( $links, $file ) {
123
+ if ( $file != plugin_basename( __FILE__ ))
124
+ return $links;
125
+
126
+ $settings_link = '<a href="options-general.php?page=email-before-download">' . __( 'Settings', 'email-before-download' ) . '</a>';
127
+
128
+ array_unshift( $links, $settings_link );
129
+
130
+ return $links;
131
+ }
132
+
133
+ function register_email_before_download_settings() {
134
+ register_setting( 'email-before-download-group', 'email_before_download_link_target' );
135
+ register_setting( 'email-before-download-group', 'email_before_download_wrap_in_div' );
136
+ register_setting( 'email-before-download-group', 'email_before_download_html_before_link' );
137
+ register_setting( 'email-before-download-group', 'email_before_download_html_after_link' );
138
+ register_setting( 'email-before-download-group', 'email_before_download_send_email' );
139
+ register_setting( 'email-before-download-group', 'email_before_download_email_template' );
140
+
141
+ }
142
+
143
+ function email_before_download_options() {
144
+
145
+ if (!current_user_can('manage_options')) {
146
+ wp_die( __('You do not have sufficient permissions to access this page.') );
147
+ }
148
+
149
+ ?>
150
+ <style type="text/css">
151
+ .ebd th, .ebd td
152
+ {
153
+ vertical-align:top;
154
+ }
155
+ .ebd th
156
+ {
157
+ text-align: left;
158
+ padding-right:8px;
159
+ }
160
+ .ebd .alert
161
+ {
162
+ padding:8px;
163
+ font:bold 12pt Arial;
164
+ border:1px dashed red;
165
+ }
166
+ </style>
167
+
168
+ <div class="wrap">
169
+ <h2>Email Before Download Options</h2>
170
+
171
+ <form method="post" action="options.php">
172
+ <?php settings_fields( 'email-before-download-group' ); ?>
173
+ <table class="optiontable ebd">
174
+ <tr valign="top">
175
+ <th scope="row"><p>1. Delivery Format</p></th>
176
+ <td><p>
177
+ <select name="email_before_download_send_email">
178
+ <option value="Inline Link" <?php if(get_option('email_before_download_send_email') == 'Inline Link') echo 'selected="selected"'; ?> >Inline Link</option>
179
+ <option value="Send Email" <?php if(get_option('email_before_download_send_email') == 'Send Email') echo 'selected="selected"'; ?> >Send Email</option>
180
+ <option value="Both" <?php if(get_option('email_before_download_send_email') == 'Both') echo 'selected="selected"'; ?> >Both</option>
181
+ </select>
182
+ </p>
183
+ </td>
184
+ </tr>
185
+
186
+ <tr valign="top"><td colspan="2"><p class="alert">#2 through #5 only apply if you selected "Inline Link" or "Both" as the Deliver Format in #1</p></td></tr>
187
+ <tr valign="top">
188
+ <th scope="row"><p>2. Inline Link Target</p></th>
189
+ <td><p>
190
+ <select name="email_before_download_link_target">
191
+ <option value="_blank" <?php if(get_option('email_before_download_link_target') == '_blank') echo 'selected="selected"'; ?> >_blank</option>
192
+ <option value="_self" <?php if(get_option('email_before_download_link_target') == '_self') echo 'selected="selected"'; ?> >_self</option>
193
+ </select> <br />
194
+ <font size="-1"><i>If "_self" is selected link will open in the same browser window/tab, if "_blank" is selected the link will open in the new browser window/tab</i></font>
195
+ </p>
196
+ </td>
197
+ </tr>
198
+
199
+ <tr valign="top">
200
+ <th scope="row"><p>3. Inline Link Custom CSS</p></th>
201
+ <td><p><input type="text" size="40" name="email_before_download_wrap_in_div" value="<?php echo get_option('email_before_download_wrap_in_div'); ?>" />
202
+ <br /> <font size="-1"><i>CSS class used to render the div and the link (this is only used if you choose to display the link inline in #5)</i></font>
203
+ </td>
204
+ </tr>
205
+
206
+ <tr valign="top">
207
+ <th scope="row"><p>4. HTML Before Inline Link</p></th>
208
+ <td><p><input type="text" name="email_before_download_html_before_link" size="40" value="<?php echo get_option('email_before_download_html_before_link'); ?>" /><br />
209
+ <font size="-1"><i>HTML you want to be added before the link</i></font>
210
+ </p>
211
+ </td>
212
+ </tr>
213
+
214
+ <tr valign="top">
215
+ <th scope="row"><p>5. HTML After Inline Link</p></th>
216
+ <td> <p><input type="text" size="40" name="email_before_download_html_after_link" value="<?php echo get_option('email_before_download_html_after_link'); ?>" />
217
+ <br /><font size="-1"><i>HTML you want to be added after the link</i></font>
218
+ </p>
219
+ </td>
220
+ </tr>
221
+
222
+ <tr valign="top" class="alert"><td colspan="2"><p class="alert">#6 only applies if you selected "Send Email" or "Both" as the Deliver Format in #1</p></td></tr>
223
+ <tr valign="top">
224
+ <th scope="row"><p>6. Email Template</p></th>
225
+ <td><textarea cols="40" rows="10" name="email_before_download_email_template"> <?php echo get_option('email_before_download_email_template'); ?> </textarea><br />
226
+ <font size="-1"><i>You can use the following placeholders: [requesting_name], [file_url] and [file_name]. </i></font> <br />
227
+ <font size="-1"><i>The placeholders: [requesting_name], [file_url] and [file_name] are used to generate the link.
228
+ <br /> So if you, for example, don't provide the [file_url] placeholder
229
+ <br />user will not receive any link. Here is an example of the template: <br />
230
+ <b> Hello [requesting_name], <br />
231
+
232
+ Here is the download for &lt;a href="[file_url]"&gt;[file_name]&lt;/a&gt; that you requested.<br />
233
+
234
+ Sincerely,<br />
235
+
236
+ My Company name </b>
237
+ <br /> Note. If you leave this field empty, an email containing only the file URL will be sent.
238
+
239
+ </i>
240
+ </td>
241
+ </tr>
242
+
243
+ </table>
244
+
245
+ <p class="submit">
246
+ <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
247
+ </p>
248
+
249
+ </form>
250
+ </div>
251
+ <?php
252
+
253
+ }
254
+ ?>
trunk/readme.txt ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Plugin Name ===
2
+ Contributors: mandsconsulting
3
+ Donate link: http://www.mandsconsulting.com/
4
+ Tags: email, download
5
+ Requires at least: 3.x
6
+ Tested up to: 3.0.4
7
+ Stable tag: trunk
8
+
9
+ Email Before Download presents your users with a form where they submit information, like their name and email address, prior to receiving a download.
10
+
11
+ Plugin homepage: http://www.mandsconsulting.com/products/wp-email-before-download
12
+
13
+ == Description ==
14
+
15
+ Email Before Download presents your users with a form where they submit information, like their name and email address, prior to receiving a download. This plugin integrates with the popular Contact Form 7 and Download Monitor plugins, allowing you to create any form you like and manage/monitor your file downloads. Prior to installing Email Before Download, please confirm each of these dependent plugins is already installed and working independently.
16
+
17
+ As an option, you can configure Email Before Download to:
18
+
19
+ 1. Display a link to your file directly under the contact form once it is submitted. This happens dynamically, inline of your post/page.
20
+ 1. Send the user an email with a link to download your file.
21
+ 1. Both #1 and #2
22
+
23
+
24
+ Usage
25
+
26
+ Note: You can see screenshots at [http://wordpress.org/extend/plugins/email-before-download/screenshots/](http://bit.ly/g4r1w2)
27
+
28
+ 1. Create a contact form used by Email Before Download using Contact Form 7 and note the Contact Form ID
29
+ 1. Upload a file using Download Monitor and note the Download ID
30
+ 1. Navigate to the Post (or Page) you wish to include
31
+ 1. Add the following short code using the IDs collected in the first two steps
32
+ [email-download download_id="X" contact_form_id="Y"]
33
+
34
+
35
+
36
+ Plugin homepage: [http://www.mandsconsulting.com/products/wp-email-before-download](http://www.mandsconsulting.com/products/wp-email-before-download)
37
+
38
+
39
+ == Installation ==
40
+
41
+ 1. Download from http://wordpress.org/extend/plugins
42
+ 1. Upload the entire email-before-download folder to the /wp-content/plugins/ directory.
43
+ 1. Activate the plugin through the "Plugins" menu in WordPress.
44
+ 1. Locate the "Email Before Download" menu item in your WordPress Admin panel under "Settings" to configure.
45
+
46
+
47
+ == Frequently Asked Questions ==
48
+
49
+
50
+ = What if I don't use the Contact Form 7 and/or Download Monintor Plugins? =
51
+
52
+ You will not be able to use this version of Email Before Download without these dependent plugins. If you have specific reasons to avoid using the dependent plugins, please contact us and let us know the reason so we can take it into consideration.
53
+
54
+ = Anything special I need to do with my contact form? =
55
+
56
+ If you decide to configure the Email Before Download option to send the user an email with a link to the download, then you will want to name the email field "your-email" as shown in the example screenshots. Outside of that, nothing special.
57
+
58
+ = What happens after the user completes the form? =
59
+
60
+ By default, the user is presented with a link to download their file. There is also an option to email a link to the file, which can be done instead of (or in addition to) displaying the link inline.
61
+
62
+ = Are you changing any of my file or directory permissions? =
63
+
64
+ WordPress allows direct access to any files in your upload directories using a direct URL and we do not change those permissions.
65
+
66
+ = So someone can still download my files directly without providing their email? =
67
+
68
+ Users generally do not have a desire to put in the work required to determine your direct upload filenames. This plugin provides a quick way to know who is downloading information that you might feel to be more premium content like whitepapers, images, etc. from sincere users who are visiting your site, with the understanding the user can share the file itself or the URL if they wish.
69
+
70
+ = What if I don't want the user to be able to share the file? =
71
+
72
+ We can't help you prevent a user from sharing a file they have downloaded with other people. We are however working on allowing you to set some options that will make sharing links a little more difficult. Also, there is a chance you fit more into the category of needing to charge for the content which is something this plugin does not currently address.
73
+
74
+
75
+
76
+ == Screenshots ==
77
+
78
+ 1. Note the ID of a file you have uploaded to Download Monitor.
79
+ 2. Note the ID of a contact form you have created using Contact Form 7.
80
+ 3. Use the following shortcode in your page or post: [email-download download_id="X" contact_form_id="Y"].
81
+ 4. Upon installation and use of the plugin on a post/page, an end-user will see your contact form.
82
+ 5. User will be required to enter valid data in accordance with Contact Form 7 validation rules.
83
+ 6. Upon submission, user will either see a direct link below the form. (Note: there is also an option to only email the link to the user.)
84
+
85
+ == Changelog ==
86
+
87
+ = 0.5 =
88
+ * First release.
89
+
90
+ == Upgrade Notice ==
91
+
92
+ = 0.5 =
93
+ First release.
94
+
trunk/screenshot-1.png ADDED
Binary file
trunk/screenshot-2.png ADDED
Binary file
trunk/screenshot-3.png ADDED
Binary file
trunk/screenshot-4.png ADDED
Binary file
trunk/screenshot-5.png ADDED
Binary file
trunk/screenshot-6.png ADDED
Binary file