Newsletter Sign-Up - Version 2.0.1

Version Description

  • Fixed: not being able to uncheck "Use HTML 5" on form settings page
  • Added: compatibility with bbPress, you can now add a sign-up checkbox to the post new topic and post new reply forms.
  • Fixed: not being able to uncheck "add to comment form" in checkbox settings
  • Fixed: compatibility with other plugins who use a 'functions.php' file (like GDE).
Download this release

Release Info

Developer DvanKooten
Plugin Icon wp plugin Newsletter Sign-Up
Version 2.0.1
Comparing to
See all releases

Code changes from version 1.8.1 to 2.0.1

Files changed (39) hide show
  1. assets/css/admin.css +13 -0
  2. {frontend → assets}/css/newsletter-sign-up.php +0 -0
  3. {backend → assets}/img/close.png +0 -0
  4. {backend → assets}/img/email-icon.png +0 -0
  5. {backend → assets}/img/icon.png +0 -0
  6. assets/img/mailchimp-for-wp-icon.png +0 -0
  7. {backend → assets}/img/overlay.png +0 -0
  8. assets/img/recent-facebook-posts-icon.png +0 -0
  9. {backend → assets}/img/rss-icon.png +0 -0
  10. {backend → assets}/img/twitter-icon.png +0 -0
  11. backend/js/backend.js → assets/js/admin.js +0 -0
  12. backend/css/backend.css +0 -44
  13. backend/css/newsletter-sign-up-backend.css +0 -0
  14. backend/views/checkbox_settings.php +0 -99
  15. backend/views/config_helper.php +0 -76
  16. backend/views/dashboard.php +0 -108
  17. backend/views/form_settings.php +0 -89
  18. frontend/NewsletterSignUp.php +0 -566
  19. includes/NSU.php +315 -0
  20. backend/NewsletterSignUpAdmin.php → includes/NSU_Admin.php +55 -110
  21. includes/NSU_Checkbox.php +212 -0
  22. includes/NSU_Form.php +174 -0
  23. {frontend → includes}/NewsletterSignUpWidget.php +4 -2
  24. includes/functions.php +27 -0
  25. includes/views/checkbox_settings.php +57 -0
  26. includes/views/config_helper.php +68 -0
  27. includes/views/dashboard.php +102 -0
  28. includes/views/form_settings.php +93 -0
  29. includes/views/parts/navigation.php +7 -0
  30. {backend/views → includes/views/parts}/rows-aweber.php +0 -0
  31. {backend/views → includes/views/parts}/rows-mailchimp.php +5 -12
  32. {backend/views → includes/views/parts}/rows-phplist.php +0 -0
  33. {backend/views → includes/views/parts}/rows-ymlp.php +0 -0
  34. includes/views/parts/sidebar.php +44 -0
  35. newsletter-sign-up.php +6 -27
  36. readme.txt +34 -10
  37. screenshot-1.jpg +0 -0
  38. screenshot-2.jpg +0 -0
  39. screenshot-3.jpg +0 -0
assets/css/admin.css ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #nsu-admin { }
2
+ #nsu-main { width:65%; float:left; }
3
+ #nsu-sidebar{ width:30%; float:right; }
4
+
5
+ #nsu-sidebar > div{ margin-bottom:20px; }
6
+
7
+ #nsu-admin li.dvk-email{ padding-left:25px; background:url("../img/email-icon.png") no-repeat left center; }
8
+ #nsu-admin li.dvk-twitter{ padding-left:25px; background:url("../img/twitter-icon.png") no-repeat left center}
9
+ #nsu-admin li.mc4wp{ padding-left:25px; background:url("../img/mailchimp-for-wp-icon.png") no-repeat left center; }
10
+ #nsu-admin li.rfb{ padding-left:25px; background:url("../img/recent-facebook-posts-icon.png") no-repeat left center; }
11
+
12
+ #nsu-donate-box{ border:2px solid green; background:#CFC; padding:0 20px; }
13
+ #nsu-donate-box h3{ color:green; }
{frontend → assets}/css/newsletter-sign-up.php RENAMED
File without changes
{backend → assets}/img/close.png RENAMED
File without changes
{backend → assets}/img/email-icon.png RENAMED
File without changes
{backend → assets}/img/icon.png RENAMED
File without changes
assets/img/mailchimp-for-wp-icon.png ADDED
Binary file
{backend → assets}/img/overlay.png RENAMED
File without changes
assets/img/recent-facebook-posts-icon.png ADDED
Binary file
{backend → assets}/img/rss-icon.png RENAMED
File without changes
{backend → assets}/img/twitter-icon.png RENAMED
File without changes
backend/js/backend.js → assets/js/admin.js RENAMED
File without changes
backend/css/backend.css DELETED
@@ -1,44 +0,0 @@
1
- .dvk-box{ margin-bottom:20px; }
2
- .dvk-box h3{ font-family:sans-serif; font-weight:bold; }
3
- .dvk-box div.inside{ padding:0 10px 10px; font-size:13px; }
4
- .dvk-box p,.dvk-box ul, .dvk-box input{ margin:3px 0 7px; }
5
- .dvk-box ul{ list-style:square; margin-left:20px; }
6
- .dvk-box li{ margin:0; margin-bottom:4px; }
7
-
8
- li.dvk-rss-item{ margin-left:-16px; padding-left:25px;
9
- background:url(http://static.dannyvankooten.com/images/dvk-16x16.png) no-repeat left center; list-style:none;
10
- }
11
- li.dvk-rss{ margin-top:10px; margin-left:-16px;
12
- float:left; padding-left:25px; background:url("../img/rss-icon.png") no-repeat left center;
13
- list-style:none; }
14
- li.dvk-email{ margin:10px 0 0 10px; float:left; padding-left:25px; background:url("../img/email-icon.png") no-repeat left center;
15
- list-style:none; }
16
- li.dvk-twitter{ clear:both; margin:10px 0 0 -16px; float:left; list-style:none; padding-left:25px; background:url("../img/twitter-icon.png") no-repeat left center}
17
-
18
- .dvk-box b,.dvk-box strong{ font-weight:bold; }
19
-
20
- #ns_settings_page input[type=text]{ width:75%; }
21
-
22
- span.ns_small{
23
- font-style:italic;
24
- font-size:10px;
25
- display:block;
26
- margin:2px 0;
27
- }
28
-
29
- #dvk-avatar{
30
- vertical-align:top;
31
- margin-right:10px;
32
- display:inline-block;
33
- height:32px;
34
- width:32px;
35
- background:url(http://static.dannyvankooten.com/images/dvk-avatar.png) no-repeat;
36
- }
37
-
38
- .nsu-tip{ font-size: 11px; font-style:italic; }
39
- html,body{ height:auto !important; position:relative; }
40
- .nsu-textarea{ width:100% !important; min-height:150px; }
41
-
42
- #newsletter-sign-up-donatebox{ border:2px solid green; background:#CFC; }
43
- #newsletter-sign-up-donatebox h3{ color:green; }
44
- #newsletter-sign-up-donatebox li{ line-height:22px; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
backend/css/newsletter-sign-up-backend.css DELETED
File without changes
backend/views/checkbox_settings.php DELETED
@@ -1,99 +0,0 @@
1
- <div class="wrap" id="<?php echo $this->hook; ?>">
2
- <h2><a href="http://dannyvankooten.com/" target="_blank"><span id="dvk-avatar"></span></a>Newsletter Sign-Up :: Checkbox Settings</h2>
3
- <div class="postbox-container" style="width:65%;">
4
- <div class="metabox-holder">
5
- <div class="meta-box-sortables">
6
-
7
- <div class="postbox">
8
- <div class="handlediv" title="<?php _e('Click to toggle'); ?>"><br></div>
9
- <h3 class="hndle"><span>Checkbox Settings</span></h3>
10
- <div class="inside">
11
- <form method="post" action="options.php" id="ns_settings_page">
12
- <?php settings_fields('nsu_checkbox_group'); ?>
13
- <table class="form-table">
14
- <tr valign="top"><th scope="row">Text to show after the checkbox</th>
15
- <td><input size="50%" type="text" name="nsu_checkbox[text]" value="<?php echo $opts['text']; ?>" /></td>
16
- </tr>
17
- <tr valign="top"><th scope="row">Redirect to this url after signing up <span class="ns_small">(leave empty for no redirect)</span></th>
18
- <td><input size="50%" type="text" name="nsu_checkbox[redirect_to]" value="<?php echo $opts['redirect_to']; ?>" />
19
- <br />
20
- <p class="nsu-tip">In general, I don't recommend setting a redirect url for the sign-up checkbox. This will cause some serious confusion, since
21
- users expect to be redirected to the post they commented on.</p>
22
-
23
- </td>
24
- </tr>
25
- <tr valign="top"><th scope="row"><label for="ns_precheck_checkbox">Pre-check the checkbox?</label></th>
26
- <td><input type="checkbox" id="ns_precheck_checkbox" name="nsu_checkbox[precheck]" value="1"<?php
27
- if ($opts['precheck'] == '1') {
28
- echo ' checked';
29
- }
30
- ?> /></td>
31
- </tr>
32
- <tr valign="top">
33
- <th scope="row"><label for="do_css_reset">Do a CSS 'reset' on the checkbox.</label> <span class="ns_small">(check this if checkbox appears in a weird place)</span></th>
34
- <td><input type="checkbox" id="do_css_reset" name="nsu_checkbox[css_reset]" value="1"<?php
35
- if ($opts['css_reset'] == '1') {
36
- echo ' checked="checked"';
37
- }
38
- ?> /> </td>
39
- </tr>
40
- <tr valign="top"><th scope="row">Where to show the sign-up checkbox?</th>
41
- <td>
42
- <input type="checkbox" id="add_to_comment_form" name="nsu_checkbox[add_to_comment_form]" value="1"<?php
43
- if ($opts['add_to_comment_form'] == '1') {
44
- echo ' checked="checked"';
45
- }
46
- ?> /> <label for="add_to_comment_form">WordPress comment form</label><br />
47
- <input type="checkbox" id="add_to_reg_form" name="nsu_checkbox[add_to_registration_form]" value="1"<?php
48
- if ($opts['add_to_registration_form'] == '1') {
49
- echo ' checked="checked"';
50
- }
51
- ?> /> <label for="add_to_reg_form">WordPress registration form</label><br />
52
- <?php if ($this->bp_active == TRUE) { ?>
53
- <input type="checkbox" id="add_to_bp_form" name="nsu_checkbox[add_to_buddypress_form]" value="1"<?php
54
- if ($opts['add_to_buddypress_form'] == '1') {
55
- echo ' checked="checked"';
56
- }
57
- ?> /> <label for="add_to_bp_form">BuddyPress registration form</label><br />
58
- <?php
59
- }
60
- if (defined('MULTISITE') && MULTISITE == TRUE) {
61
- ?>
62
- <input type="checkbox" id="add_to_ms_form" name="nsu_checkbox[add_to_multisite_form]" value="1"<?php
63
- if ($opts['add_to_multisite_form'] == '1') {
64
- echo ' checked="checked"';
65
- }
66
- ?> /> <label for="add_to_ms_form">MultiSite registration form</label><br />
67
- <?php } ?>
68
- </td>
69
- </tr>
70
- <tr valign="top"><th scope="row"><label for="ns_cookie_hide">Hide the checkbox for users who used it to subscribe before?</label><span class="ns_small">(uses a cookie)</span></th>
71
- <td><input type="checkbox" id="ns_cookie_hide" name="nsu_checkbox[cookie_hide]" value="1"<?php
72
- if ($opts['cookie_hide'] == '1') {
73
- echo ' checked="checked"';
74
- }
75
- ?> /></td>
76
- </tr>
77
-
78
- </table>
79
-
80
- <p class="submit">
81
- <input type="submit" class="button-primary" style="margin:5px;" value="<?php _e('Save Changes') ?>" />
82
- </p>
83
-
84
- </form>
85
- </div>
86
- </div>
87
- </div></div></div></div>
88
- <div class="postbox-container" style="width:33%; float:right; margin-right:1%;">
89
- <div class="metabox-holder">
90
- <div class="meta-box-sortables">
91
- <?php
92
- $this->donate_box();
93
- $this->latest_posts();
94
- $this->support_box();
95
- ?>
96
- </div>
97
- </div>
98
- </div>
99
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
backend/views/config_helper.php DELETED
@@ -1,76 +0,0 @@
1
- <div class="wrap" id="<?php echo $this->hook; ?>">
2
-
3
- <?php if(isset($error)) { ?>
4
- <div id="message" class="notice error"><p>Oops, I couldn't make any sense of that. Are you sure you submitted a form snippet?</p></div>
5
- <?php } ?>
6
-
7
- <h2><a href="http://dannyvankooten.com/" target="_blank"><span id="dvk-avatar"></span></a>Newsletter Sign-Up :: Config Extractor</h2>
8
- <div class="postbox-container" style="width:65%;">
9
- <div class="metabox-holder">
10
- <div class="meta-box-sortables">
11
- <div class="postbox">
12
- <h3 class="hndle"><span>Newsletter Sign-Up :: Config Extractor</span></h3>
13
- <div class="inside">
14
-
15
-
16
- <?php if(isset($result)) { ?>
17
- <table class="form-table">
18
- <tr valign="top">
19
- <th scope="row" style="font-weight:bold;">Form action:</th>
20
- <td><?php echo $form_action; ?></td>
21
- </tr>
22
- <tr valign="top">
23
- <th scope="row" style="font-weight:bold;">Email identifier:</th>
24
- <td><?php echo $email_identifier; ?></td>
25
- </tr>
26
- <tr valign="top">
27
- <th scope="row" style="font-weight:bold;">Name identifier:</th>
28
- <td><?php echo $name_identifier; ?></td>
29
- </tr>
30
- <?php if(isset($additional_data) && count($additional_data) > 0) { ?>
31
- <tr valign="top">
32
- <th scope="row" colspan="2" style="font-weight:bold;">Additional data ( name / value):</th>
33
- </tr>
34
- <?php foreach($additional_data as $data) { ?>
35
- <tr valign="top">
36
- <td><?php echo $data[0]; ?></th>
37
- <td><?php echo $data[1]; ?></td>
38
- </tr>
39
- <?php } ?>
40
- <?php } ?>
41
- </table>
42
-
43
- <p>The above settings are there to help you, though they may not be right. Check out <a href="http://dannyvankooten.com/571/configuring-newsletter-sign-up-the-definitive-guide/">this post on my blog</a> for more information on how to manually
44
- configure Newsletter Sign-up.</p>
45
- <p>The form code below is a stripped down version of your sign-up form which will make it easier for you to extract the right values. Please also use this form when asking for support.</p>
46
- <textarea class="nsu-textarea"><?php echo $clean_form; ?></textarea>
47
-
48
- <?php } else { ?>
49
- <p>This tool was designed to help you extract the right configuration settings to make NSU work properly.</p>
50
- <p>Please copy and paste a sign-up form you would normally embed on a HTML page in the textarea below and hit the extract button. The NSU Config Tool will then try to extract the right configuration settings for you. </p>
51
- <form method="post" action="" id="ns_settings_page">
52
- <textarea name="form" class="nsu-textarea"></textarea>
53
-
54
- <p class="submit">
55
- <input type="submit" class="button-primary" style="margin:5px;" value="<?php _e('Extract') ?>" />
56
- </p>
57
-
58
-
59
- </form>
60
- <?Php } ?>
61
- </div>
62
- </div>
63
-
64
- </div></div></div></div>
65
- <div class="postbox-container" style="width:33%; float:right; margin-right:1%;">
66
- <div class="metabox-holder">
67
- <div class="meta-box-sortables">
68
- <?php
69
- $this->donate_box();
70
- $this->latest_posts();
71
- $this->support_box();
72
- ?>
73
- </div>
74
- </div>
75
- </div>
76
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
backend/views/dashboard.php DELETED
@@ -1,108 +0,0 @@
1
- <div class="wrap" id="<?php echo $this->hook; ?>">
2
- <h2><a href="http://dannyvankooten.com/" target="_blank"><span id="dvk-avatar"></span></a>Newsletter Sign-Up :: Mailinglist Settings</h2>
3
- <div class="postbox-container" style="width:65%;">
4
- <div class="metabox-holder">
5
- <div class="meta-box-sortables">
6
- <div class="postbox">
7
- <div class="handlediv" title="<?php _e('Click to toggle'); ?>"><br></div>
8
- <h3 class="hndle"><span>Mailinglist Settings</span></span></h3>
9
- <div class="inside">
10
- <form method="post" action="options.php" id="ns_settings_page">
11
- <?php settings_fields('nsu_mailinglist_group'); ?>
12
-
13
- <table class="form-table">
14
- <tr valign="top">
15
- <td colspan="2"><p>These settings are the most important since without these Newsletter Sign-Up can't do it's job. Having trouble finding
16
- the right configuration settings? Have a look at <a href="http://dannyvankooten.com/wordpress-plugins/newsletter-sign-up/">this post on my blog</a> or try the <a href="admin.php?page=newsletter-sign-up/config-helper">configuration extractor</a>.</p></td>
17
- </tr>
18
- <tr valign="top">
19
- <th scope="row">Select your mailinglist provider: </th>
20
- <td>
21
- <select name="nsu_mailinglist[provider]" id="ns_mp_provider" onchange="document.location.href = 'admin.php?page=<?php echo $this->hook; ?>&mp=' + this.value">
22
- <option value="other"<?php if ($viewed_mp == NULL || $viewed_mp == 'other')
23
- echo ' SELECTED'; ?>>-- other / advanced</option>
24
- <option value="mailchimp"<?php if ($viewed_mp == 'mailchimp')
25
- echo ' SELECTED'; ?> >MailChimp</option>
26
- <option value="ymlp"<?php if ($viewed_mp == 'ymlp')
27
- echo ' SELECTED'; ?> >YMLP</option>
28
- <option value="icontact"<?php if ($viewed_mp == 'icontact')
29
- echo ' SELECTED'; ?> >iContact</option>
30
- <option value="aweber"<?php if ($viewed_mp == 'aweber')
31
- echo ' SELECTED'; ?> >Aweber</option>
32
- <option value="phplist"<?php if ($viewed_mp == 'phplist')
33
- echo ' SELECTED'; ?> >PHPList</option>
34
- </select>
35
- </td>
36
- </tr>
37
-
38
- <?php if(isset($viewed_mp) && file_exists(dirname(__FILE__).'/rows-' . $viewed_mp . '.php')) require dirname(__FILE__). '/rows-' . $viewed_mp . '.php'; ?>
39
-
40
- <tbody class="form_rows"<?php if (isset($viewed_mp) && in_array($viewed_mp, array('mailchimp', 'ymlp')) && isset($opts['use_api']) && $opts['use_api'] == 1)
41
- echo ' style="display:none" '; ?>>
42
- <tr valign="top"><th scope="row">Newsletter form action</th>
43
- <td><input size="50%" type="text" id="ns_form_action" name="nsu_mailinglist[form_action]" value="<?php echo $opts['form_action']; ?>" /></td>
44
- </tr>
45
- <tr valign="top"><th scope="row">E-mail identifier <span class="ns_small">name attribute of input field that holds the emailadress</span></th>
46
- <td><input size="50%" type="text" name="nsu_mailinglist[email_id]" value="<?php echo $opts['email_id']; ?>"/></td>
47
- </tr>
48
- </tbody>
49
- <tbody>
50
- <tr valign="top"><th scope="row"><label for="subscribe_with_name">Subscribe with name?</label></th>
51
- <td><input type="checkbox" id="subscribe_with_name" name="nsu_mailinglist[subscribe_with_name]" value="1"<?php if($opts['subscribe_with_name'] == '1') echo ' checked'; ?> /></td>
52
- </tr>
53
- <tr class="name_dependent" valign="top"<?php if($opts['subscribe_with_name'] != 1) echo 'style="display:none;"'; ?>><th scope="row">Name identifier <span class="ns_small">name attribute of input field that holds the name</span></th>
54
- <td><input size="25%" id="ns_name_id" type="text" name="nsu_mailinglist[name_id]" value="<?php echo $opts['name_id']; ?>" /></td>
55
- </tr>
56
- </tbody>
57
- </table>
58
- <p style="margin:10px;">
59
- For some newsletter services you need to specify some additional static data, like a list ID or your account name. These fields are usually found as hidden fields in your sign-up form's HTML code.
60
- You can specify these additional fields here using name / value pairs so they will be sent along with every sign-up request.
61
- </p>
62
- <p>If you use <em>%%NAME%%</em> or <em>%%IP%%</em> in the value fields it will be replaced by respectively the actual name or IP address of the subscriber.</p>
63
- <table class="form-table">
64
- <tr valign="top">
65
- <th scope="column" style="font-weight:bold;">Name</th>
66
- <th scope="column" style="font-weight:bold;">Value</th>
67
- </tr>
68
- <?php
69
- $last_key = 0;
70
-
71
- if (isset($opts['extra_data']) && is_array($opts['extra_data'])) :
72
- foreach ($opts['extra_data'] as $key => $value) :
73
- ?>
74
- <tr valign="top">
75
- <td><input size="50%" type="text" name="nsu_mailinglist[extra_data][<?php echo $key; ?>][name]" value="<?php echo $value['name']; ?>" /></td>
76
- <td><input size="50%" type="text" name="nsu_mailinglist[extra_data][<?php echo $key; ?>][value]" value="<?php echo $value['value']; ?>" /></td>
77
- </tr>
78
- <?php
79
- $last_key = $key + 1;
80
- endforeach;
81
- endif;
82
- ?>
83
- <tr valign="top">
84
- <td><input size="50%" type="text" name="nsu_mailinglist[extra_data][<?php echo $last_key; ?>][name]" value="" /></td>
85
- <td><input size="50%" type="text" name="nsu_mailinglist[extra_data][<?php echo $last_key; ?>][value]" value="" /></td>
86
- </tr>
87
- </table>
88
- <p class="submit">
89
- <input type="submit" class="button-primary" style="margin:5px;" value="<?php _e('Save Changes') ?>" />
90
- </p>
91
- </form>
92
- <p class="nsu-tip">
93
- Having trouble finding the right configuration settings? Try the <a href="admin.php?page=newsletter-sign-up/config-helper">configuration extractor</a>, it's there to help you!
94
- </p>
95
- </div>
96
- </div></div></div></div></div>
97
- <div class="postbox-container" style="width:33%; float:right; margin-right:1%;">
98
- <div class="metabox-holder">
99
- <div class="meta-box-sortables">
100
- <?php
101
- $this->donate_box();
102
- $this->latest_posts();
103
- $this->support_box();
104
- ?>
105
- </div>
106
- </div>
107
- </div>
108
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
backend/views/form_settings.php DELETED
@@ -1,89 +0,0 @@
1
- <div class="wrap" id="<?php echo $this->hook; ?>">
2
- <h2><a href="http://dannyvankooten.com/" target="_blank"><span id="dvk-avatar"></span></a>Newsletter Sign-Up :: Form Settings</h2>
3
- <div class="postbox-container" style="width:65%;">
4
- <div class="metabox-holder">
5
- <div class="meta-box-sortables">
6
- <div class="postbox">
7
- <div class="handlediv" title="<?php _e('Click to toggle'); ?>"><br></div>
8
- <h3 class="hndle" id="nsu-form-settings"><span>Form Settings</span></h3>
9
- <div class="inside">
10
-
11
- <form method="post" action="options.php" id="ns_settings_page">
12
- <?php settings_fields('nsu_form_group'); ?>
13
- <table class="form-table">
14
- <tr valign="top">
15
- <td colspan="2"><p>Custome your Sign-up form by providing your own values for the different labels, input fields and buttons of the sign-up form. </p></td>
16
- </tr>
17
- <tr valign="top">
18
- <th scope="row">E-mail label</th>
19
- <td><input size="50%" type="text" name="nsu_form[email_label]" value="<?php echo $opts['email_label']; ?>" /></td>
20
- </tr>
21
- <tr valign="top">
22
- <th scope="row">E-mail default value</th>
23
- <td><input size="50%" type="text" name="nsu_form[email_default_value]" value="<?php echo $opts['email_default_value']; ?>" /></td>
24
- </tr>
25
- <tr valign="top" class="name_dependent" <?php if($opts['mailinglist']['subscribe_with_name'] != 1) echo 'style="display:none;"'; ?>><th scope="row">Name label <span class="ns_small">(if using subscribe with name)</span></th>
26
- <td>
27
- <input size="50%" type="text" name="nsu_form[name_label]" value="<?php echo $opts['name_label']; ?>" /><br />
28
- <input type="checkbox" id="name_required" name="nsu_form[name_required]" value="1"<?php if($opts['name_required'] == '1') { echo ' checked'; } ?> />
29
- <label for="name_required">Name is a required field?</label>
30
- </td>
31
-
32
- </tr>
33
- <tr valign="top" class="name_dependent" <?php if($opts['mailinglist']['subscribe_with_name'] != 1) echo 'style="display:none;"'; ?>>
34
- <th scope="row">Name default value</th>
35
- <td><input size="50%" type="text" name="nsu_form[name_default_value]" value="<?php echo $opts['name_default_value']; ?>" /></td>
36
-
37
- </tr>
38
- <tr valign="top"><th scope="row">Submit button value</th>
39
- <td><input size="50%" type="text" name="nsu_form[submit_button]" value="<?php echo $opts['submit_button']; ?>" /></td>
40
- </tr>
41
- <tr valign="top"><th scope="row">Text to replace the form with after a successful sign-up</th>
42
- <td>
43
- <textarea style="width:100%;" rows="5" cols="50" name="nsu_form[text_after_signup]"><?php echo $opts['text_after_signup']; ?></textarea>
44
- <p><input id="nsu_form_wpautop" name="nsu_form[wpautop]" type="checkbox" value="1" <?php if($opts['wpautop'] == 1) echo 'checked'; ?> />&nbsp;<label for="nsu_form_wpautop"><?php _e('Automatically add paragraphs'); ?></label></p>
45
- </td>
46
- </tr>
47
-
48
- <?php if($opts['mailinglist']['use_api'] == 1) { ?>
49
- <tr valign="top"><th scope="row">Redirect to this url after signing up <span class="ns_small">(leave empty for no redirect)</span></th>
50
- <td><input size="50%" type="text" name="nsu_form[redirect_to]" value="<?php echo $opts['redirect_to']; ?>" /></td>
51
- </tr>
52
- <?php } ?>
53
-
54
- <tr valign="top"><th scope="row"><label for="ns_load_form_styles">Load some default CSS</label><span class="ns_small">(check this for some default styling of the labels and input fields)</span></th>
55
- <td><input type="checkbox" id="ns_load_form_styles" name="nsu_form[load_form_css]" value="1" <?php if($opts['load_form_css'] == 1) echo 'checked'; ?> /></td>
56
- </tr>
57
- </table>
58
- <p class="submit">
59
- <input type="submit" class="button-primary" style="margin:5px;" value="<?php _e('Save Changes') ?>" />
60
- </p>
61
-
62
- <?php
63
- $tips = array(
64
- 'You can embed a sign-up form in your posts and pages by
65
- using the shortcode <b><em>[newsletter-sign-up-form]</em></b> or by calling <b><em>&lt;?php if(function_exists(\'nsu_signup_form\')) nsu_signup_form(); ?&gt;</em></b> from your template files.',
66
- 'Using Newsletter Sign-Up Widget? You can alternatively install <a target="_blank" href="http://wordpress.org/extend/plugins/wysiwyg-widgets/">WYSIWYG Widgets</a> and use the NSU form shortcode <strong>[nsu-form]</strong> to render a sign-up form in your widget area\'s. This allows
67
- easier customizing',
68
- 'When testing, make sure to test with an email address that is not already on your e-mail list.',
69
- 'Using Newsletter Sign-Up with MailChimp? Consider switching to <a href="http://dannyvankooten.com/wordpress-plugins/mailchimp-for-wordpress/">MailChimp for WordPress</a>'
70
- );
71
- $random_key = array_rand($tips);
72
- ?>
73
- <p class="nsu-tip">Tip: <?php echo $tips[$random_key]; ?></p>
74
-
75
- </form>
76
- <br style="clear:both;" />
77
- </div></div></div></div></div></div>
78
- <div class="postbox-container" style="width:33%; float:right; margin-right:1%;">
79
- <div class="metabox-holder">
80
- <div class="meta-box-sortables">
81
- <?php
82
- $this->donate_box();
83
- $this->latest_posts();
84
- $this->support_box();
85
- ?>
86
- </div>
87
- </div>
88
- </div>
89
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
frontend/NewsletterSignUp.php DELETED
@@ -1,566 +0,0 @@
1
- <?php
2
- if(!class_exists('NewsletterSignUp')) {
3
- class NewsletterSignUp {
4
-
5
- private $options = array();
6
- private $no_of_forms = 0;
7
- private $showed_checkbox = FALSE;
8
- private static $instance;
9
- private $validation_errors = array();
10
-
11
- public function __construct()
12
- {
13
- $defaults = array(
14
- 'form' => array('load_form_css' => 0, 'submit_button' => 'Sign up', 'name_label' => 'Name:', 'email_label' => "Email:", 'email_default_value' => 'Your emailaddress..', 'name_required' => 0, 'name_default_value' => 'Your name..', 'wpautop' => 0, 'text_after_signup' => 'Thanks for signing up to our newsletter. Please check your inbox to confirm your email address.', 'redirect_to' => ''),
15
- 'mailinglist' => array('provider' => '', 'use_api' => 0, 'subscribe_with_name' => 0, 'email_id' => '', 'name_id' => '', 'form_action' => ''),
16
- 'checkbox' => array('text' => 'Sign me up for the newsletter', 'redirect_to' => '', 'precheck' => 0, 'cookie_hide' => 0, 'css_reset' => 0, 'add_to_registration_form' => 0, 'add_to_comment_form' => 1, 'add_to_buddypress_form' => 0, 'add_to_multisite_form' => 0)
17
- );
18
-
19
- $this->options['form'] = array_merge($defaults['form'], (array) get_option('nsu_form'));
20
- $this->options['mailinglist'] = array_merge($defaults['mailinglist'], (array) get_option('nsu_mailinglist'));
21
- $this->options['checkbox'] = array_merge($defaults['checkbox'], (array) get_option('nsu_checkbox'));
22
- $opts = $this->options;
23
-
24
- // widget hooks
25
- add_action('widgets_init', array($this, 'register_widget'));
26
- add_action('init', array($this, 'check_for_form_submit'));
27
-
28
- // register the shortcode which can be used to output sign-up form
29
- add_shortcode('newsletter-sign-up-form', array($this,'form_shortcode'));
30
- add_shortcode('nsu-form', array($this,'form_shortcode'));
31
-
32
- // Should we load the stylesheet?
33
- if($opts['checkbox']['css_reset'] == 1 || $opts['form']['load_form_css'] == 1) {
34
- add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
35
- }
36
-
37
- // Add to comment form? If so, add necessary actions. Try to add automatically.
38
- if($opts['checkbox']['add_to_comment_form'] == 1) {
39
- add_action('thesis_hook_after_comment_box', array($this, 'output_checkbox'), 20);
40
- add_action('comment_form', array($this, 'output_checkbox'), 20);
41
- add_action('comment_approved_', array($this, 'grab_email_from_comment'), 10, 1);
42
- add_action('comment_post', array($this, 'grab_email_from_comment'), 50, 2);
43
- }
44
-
45
- // If add_to_reg_form is ticked, add corresponding actions
46
- if($opts['checkbox']['add_to_registration_form'] == 1) {
47
- add_action('register_form',array($this, 'output_checkbox'), 20);
48
- add_action('register_post',array($this, 'grab_email_from_wp_signup'), 50);
49
- }
50
-
51
- // If add_to_bp_form is ticked, add BuddyPress actions
52
- if($opts['checkbox']['add_to_buddypress_form'] == 1) {
53
- add_action('bp_before_registration_submit_buttons', array($this, 'output_checkbox'), 20);
54
- add_action('bp_complete_signup', array($this, 'grab_email_from_wp_signup'), 20);
55
- }
56
-
57
- // If running a MultiSite, add to registration form and add actions.
58
- if($opts['checkbox']['add_to_multisite_form'] == 1) {
59
- add_action('signup_extra_fields', array($this, 'output_checkbox'), 20);
60
- add_action('signup_blogform', array($this, 'add_hidden_checkbox'), 20);
61
- add_filter('add_signup_meta', array($this, 'add_checkbox_to_usermeta'));
62
- add_action('wpmu_activate_blog', array($this, 'grab_email_from_ms_blog_signup'), 20, 5);
63
- add_action('wpmu_activate_user', array($this, 'grab_email_from_ms_user_signup'), 20, 3);
64
- }
65
- }
66
-
67
- public function getOptions()
68
- {
69
- return $this->options;
70
- }
71
-
72
- /**
73
- * Registers the Newsletter Sign-Up Widget
74
- * @return type
75
- */
76
- public function register_widget()
77
- {
78
- return register_widget('NewsletterSignUpWidget');
79
- }
80
-
81
- /**
82
- * Factory method for NewsletterSignUp class. Only instantiate once.
83
- * @return NewsletterSignUp Instance of Newsletter Sign-Up class
84
- */
85
- public static function getInstance() {
86
- if(!isset(self::$instance)) self::$instance = new NewsletterSignUp();
87
-
88
- return self::$instance;
89
- }
90
-
91
- public function enqueue_styles()
92
- {
93
- $opts = $this->getOptions();
94
-
95
- // Build stylesheet url --------------
96
- $stylesheet_opts = '?';
97
-
98
- // Load CSS to reset the checkbox' position?
99
- if($opts['checkbox']['css_reset'] == 1) {
100
- $stylesheet_opts .= 'checkbox_reset=1&';
101
- }
102
-
103
- // Load CSS to reset label and input fields for the sign-up form?
104
- if($opts['form']['load_form_css'] == 1) {
105
- $stylesheet_opts .= 'form_css=1&';
106
- }
107
-
108
- wp_enqueue_style('ns_checkbox_style', plugins_url("/frontend/css/newsletter-sign-up.php{$stylesheet_opts}", dirname(__FILE__)));
109
- }
110
-
111
-
112
- /**
113
- * Check if ANY Newsletter Sign-Up form has been submitted.
114
- */
115
- public function check_for_form_submit()
116
- {
117
- $opts = $this->options['form'];
118
- $errors = array();
119
-
120
- if(isset($_POST['nsu_submit']))
121
- {
122
- $email = (isset($_POST['nsu_email'])) ? $_POST['nsu_email'] : '';
123
- $name = (isset($_POST['nsu_name'])) ? $_POST['nsu_name'] : '';
124
-
125
- if($this->options['mailinglist']['subscribe_with_name'] == 1 && $opts['name_required'] == 1 && empty($name)) {
126
- $errors['name-field'] = 'Please fill in the name field.';
127
- }
128
-
129
- if(empty($email)) {
130
- $errors['email-field'] = 'Please fill in the email address field.';
131
- } elseif(!is_email($email)) {
132
- $errors['email-field'] = 'Please enter a valid email address.';
133
- }
134
-
135
- $this->validation_errors = $errors;
136
-
137
- if(count($this->validation_errors) == 0) {
138
- $this->send_post_data($email, $name, 'form');
139
- }
140
-
141
- }
142
- return;
143
- }
144
-
145
-
146
- /**
147
- * Output the checkbox
148
- * Function can only run once.
149
- */
150
- public function output_checkbox()
151
- {
152
- $opts = $this->options['checkbox'];
153
-
154
- // If using option to hide checkbox for subscribers and cookie is set, set instance variable showed_checkbox to true so checkbox won't show.
155
- if($opts['cookie_hide'] == 1 && isset($_COOKIE['ns_subscriber'])) $this->showed_checkbox = TRUE;
156
-
157
- // User could have rendered the checkbox by manually adding 'the hook 'ns_comment_checkbox()' to their comment form
158
- // If so, abandon function.
159
- if($this->showed_checkbox) return false;
160
-
161
- ?>
162
- <p id="ns-checkbox">
163
- <input value="1" id="nsu_checkbox" type="checkbox" name="newsletter-signup-do" <?php if($opts['precheck'] == 1) echo 'checked="checked" '; ?>/>
164
- <label for="nsu_checkbox">
165
- <?php echo $opts['text']; ?>
166
- </label>
167
- </p>
168
- <?php
169
-
170
- $this->showed_checkbox = true;
171
- return true;
172
- }
173
-
174
- /**
175
- * Adds a hidden checkbox to the second page of the MultiSite sign-up form (the blog sign-up form) containing the checkbox value of the previous screen
176
- */
177
- function add_hidden_checkbox()
178
- {
179
- ?>
180
- <input type="hidden" name="newsletter-signup-do" value="<?php echo (isset($_POST['newsletter-signup-do'])) ? 1 : 0; ?>" />
181
- <?php
182
- }
183
-
184
- /**
185
- * Save the value of the checkbox to MultiSite sign-ups table
186
- */
187
- function add_checkbox_to_usermeta($meta)
188
- {
189
- $meta['newsletter-signup-do'] = (isset($_POST['newsletter-signup-do'])) ? 1 : 0;
190
- return $meta;
191
- }
192
-
193
- /**
194
- * Send the post data to the newsletter service, mimic form request
195
- */
196
- function send_post_data($email, $name = '', $type = 'checkbox')
197
- {
198
- $opts = $this->options['mailinglist'];
199
-
200
- // when not using api and no form action has been given, abandon.
201
- if(empty($opts['use_api']) && empty($opts['form_action'])) return;
202
-
203
- $post_data = array();
204
-
205
- /* Are we using API? */
206
- if($opts['use_api'] == 1) {
207
-
208
- switch($opts['provider']) {
209
-
210
- /* Send data using the YMLP API */
211
- case 'ymlp':
212
- $request_uri = "http://www.ymlp.com/api/Contacts.Add?";
213
- $request_uri .= "Key=" . $opts['ymlp_api_key'];
214
- $request_uri .= "&Username=" . $opts['ymlp_username'];
215
- $request_uri .= "&Email=" . $email;
216
- $request_uri .= "&GroupID=" . $opts['ymlp_groupid'];
217
- $request_uri .= $this->add_additional_data(array('format' => 'query_string', 'api' => 'ymlp', 'email' => $email, 'name' => $name));
218
- $result = wp_remote_get($request_uri);
219
-
220
- if(isset($_POST['_nsu_debug']) || isset($_GET['_nsu_debug'])) {
221
- var_dump($result); die();
222
- }
223
-
224
- break;
225
-
226
- /* Send data using the MailChimp API */
227
- case 'mailchimp':
228
- $request = array(
229
- 'apikey' => $opts['mc_api_key'],
230
- 'id' => $opts['mc_list_id'],
231
- 'email_address' => $email,
232
- 'double_optin' => (isset($opts['mc_no_double_optin']) && $opts['mc_no_double_optin'] == 1) ? FALSE : TRUE,
233
- 'merge_vars' => array(
234
- 'OPTIN_TIME' => date('Y-M-D H:i:s')
235
- )
236
- );
237
-
238
- if(isset($opts['mc_use_groupings']) && $opts['mc_use_groupings'] == 1 && !empty($opts['mc_groupings_name'])) {
239
- $request['merge_vars']['GROUPINGS'] = array(
240
- array( 'name' => $opts['mc_groupings_name'], 'groups' => $opts['mc_groupings_groups'] )
241
- );
242
- }
243
-
244
- /* Subscribe with name? If so, add name to merge_vars array */
245
- if(isset($opts['subscribe_with_name']) && $opts['subscribe_with_name'] == 1) {
246
- // Try to provide values for First and Lastname fields
247
- // These can be overridden, of just ignored by mailchimp.
248
- $strpos = strpos($name, ' ');
249
-
250
- $request['merge_vars']['FNAME'] = $name;
251
-
252
- if($strpos) {
253
- $request['merge_vars']['FNAME'] = substr($name, 0, $strpos);
254
- $request['merge_vars']['LNAME'] = substr($name, $strpos);
255
- } else {
256
- $request['merge_vars']['FNAME'] = $name;
257
- $request['merge_vars']['LNAME'] = '...';
258
- }
259
-
260
- $request['merge_vars'][$opts['name_id']] = $name;
261
- }
262
- // Add any set additional data to merge_vars array
263
- $request['merge_vars'] = array_merge($request['merge_vars'], $this->add_additional_data(array('email' => $email, 'name' => $name)));
264
-
265
- $result = wp_remote_post(
266
- 'http://'.substr($opts['mc_api_key'],-3).'.api.mailchimp.com/1.3/?output=php&method=listSubscribe',
267
- array( 'body' => json_encode($request))
268
- );
269
-
270
- if(isset($_POST['_nsu_debug']) || isset($_GET['_nsu_debug'])) {
271
- var_dump($result); die();
272
- }
273
-
274
- break;
275
-
276
- }
277
-
278
- } else {
279
- /* We are not using API, mimic a normal form request */
280
-
281
- $post_data = array(
282
- $opts['email_id'] => $email,
283
- );
284
-
285
- // Subscribe with name? Add to $post_data array.
286
- if($opts['subscribe_with_name'] == 1) $post_data[$opts['name_id']] = $name;
287
-
288
- // Add list specific data
289
- switch($opts['provider']) {
290
-
291
- case 'aweber':
292
- $post_data['listname'] = $opts['aweber_list_name'];
293
- $post_data['redirect'] = get_bloginfo('wpurl');
294
- $post_data['meta_message'] = '1';
295
- $post_data['meta_required'] = 'email';
296
- break;
297
-
298
- case 'phplist':
299
- $post_data['list['.$opts['phplist_list_id'].']'] = 'signup';
300
- $post_data['subscribe'] = "Subscribe";
301
- $post_data["htmlemail"] = "1";
302
- $post_data['emailconfirm'] = $email;
303
- $post_data['makeconfirmed']='0';
304
- break;
305
-
306
- }
307
-
308
- $post_data = array_merge($post_data, $this->add_additional_data(array_merge(array('email' => $email, 'name' => $name), $post_data)));
309
-
310
- $result = wp_remote_post($opts['form_action'],
311
- array( 'body' => $post_data )
312
- );
313
-
314
- if(isset($_POST['_nsu_debug']) || isset($_GET['_nsu_debug'])) {
315
- var_dump($result); die();
316
- }
317
-
318
- }
319
-
320
- // store a cookie, if preferred by site owner
321
- if($opts['cookie_hide'] == 1) @setcookie('ns_subscriber',TRUE,time() + 9999999);
322
-
323
- // Check if we should redirect to a given page
324
- if($type == 'form' && strlen($this->options['form']['redirect_to']) > 6) {
325
- wp_redirect( $this->options['form']['redirect_to']);
326
- exit;
327
- } elseif($type == 'checkbox' && strlen($this->options['checkbox']['redirect_to']) > 6) {
328
- wp_redirect( $this->options['checkbox']['redirect_to']);
329
- exit;
330
- }
331
-
332
- return true;
333
- }
334
-
335
-
336
- /**
337
- * Returns array with additional data names as key, values as value.
338
- * @param array $args, the normal form data (name, email, list variables)
339
- */
340
- function add_additional_data($args = array())
341
- {
342
- $opts = $this->options['mailinglist'];
343
- $defaults = array(
344
- 'format' => 'array',
345
- 'api' => NULL
346
- );
347
-
348
- $args = wp_parse_args( $args, $defaults );
349
-
350
- if($args['format'] == 'query_string') {
351
-
352
- $add_data = "";
353
- if(isset($opts['extra_data']) && is_array($opts['extra_data'])) {
354
- foreach($opts['extra_data'] as $key => $value) {
355
- if($args['api'] == 'ymlp') $value['name'] = str_replace('YMP','Field', $value['name']);
356
-
357
- $value['value'] = str_replace("%%NAME%%", $args['name'], $value['value']);
358
- $value['value'] = str_replace("%%IP%%", $_SERVER['REMOTE_ADDR'], $value['value']);
359
- $add_data .= "&".$value['name']."=".$value['value'];
360
- }
361
- }
362
- return $add_data;
363
- }
364
-
365
- $add_data = array();
366
- if(isset($opts['extra_data']) && is_array($opts['extra_data'])) {
367
- foreach($opts['extra_data'] as $key => $value) {
368
- $value['value'] = str_replace("%%NAME%%", $args['name'], $value['value']);
369
- $value['value'] = str_replace("%%IP%%", $_SERVER['REMOTE_ADDR'], $value['value']);
370
- $add_data[$value['name']] = $value['value'];
371
- }
372
- }
373
-
374
- return $add_data;
375
- }
376
-
377
- /**
378
- * Perform the sign-up for users that registered trough a MultiSite register form
379
- * This function differs because of the need to grab the emailadress from the user using get_userdata
380
- * @param int $user_id : the ID of the new user
381
- * @param string $password : the password, we don't actually use this
382
- * @param array $meta : the meta values that belong to this user, holds the value of our 'newsletter-sign-up' checkbox.
383
- */
384
- public function grab_email_from_ms_user_signup($user_id, $password = NULL,$meta = NULL){
385
- if(!isset($meta['newsletter-signup-do']) || $meta['newsletter-signup-do'] != 1) return;
386
- $user_info = get_userdata($user_id);
387
-
388
- $email = $user_info->user_email;
389
- $naam = $user_info->first_name;
390
-
391
- $this->send_post_data($email,$naam);
392
- }
393
-
394
- /**
395
- * Perform the sign-up for users that registered trough a MultiSite register form
396
- * This function differs because of the need to grab the emailadress from the user using get_userdata
397
- * @param int $blog_id The id of the new blow
398
- * @param int $user_id The ID of the new user
399
- * @param $a No idea, seriously.
400
- * @param $b No idea, seriously.
401
- * @param array $meta The meta values that belong to this user, holds the value of our 'newsletter-sign-up' checkbox.
402
- */
403
- public function grab_email_from_ms_blog_signup($blog_id, $user_id, $a, $b ,$meta){
404
-
405
- if(!isset($meta['newsletter-signup-do']) || $meta['newsletter-signup-do'] != 1) return;
406
- $user_info = get_userdata($user_id);
407
-
408
- $email = $user_info->user_email;
409
- $name = $user_info->first_name;
410
-
411
- $this->send_post_data($email, $name);
412
- }
413
-
414
- /**
415
- * Grab the emailadress (and name) from a regular WP or BuddyPress sign-up and then send this to mailinglist.
416
- */
417
- function grab_email_from_wp_signup()
418
- {
419
- if($_POST['newsletter-signup-do'] != 1) return;
420
-
421
- if(isset($_POST['user_email'])) {
422
-
423
- // gather emailadress from user who WordPress registered
424
- $email = $_POST['user_email'];
425
- $name = $_POST['user_login'];
426
-
427
- } elseif(isset($_POST['signup_email'])) {
428
-
429
- // gather emailadress from user who BuddyPress registered
430
- $email = $_POST['signup_email'];
431
- $name = $_POST['signup_username'];
432
-
433
- } else { return; }
434
-
435
- $this->send_post_data($email,$name);
436
- }
437
-
438
- /**
439
- * Grab the emailadress and name from comment and then send it to mailinglist.
440
- * @param int $cid : the ID of the comment
441
- * @param object $comment : the comment object, optionally
442
- */
443
- public function grab_email_from_comment($cid,$comment = NULL)
444
- {
445
- if($_POST['newsletter-signup-do'] != 1) return;
446
-
447
- $cid = (int) $cid;
448
-
449
- // get comment data
450
- if(!is_object($comment)) $comment = get_comment($cid);
451
-
452
- // if spam, abandon function
453
- if($comment->comment_karma != 0) return;
454
-
455
- $email = $comment->comment_author_email;
456
- $name = $comment->comment_author;
457
-
458
- $this->send_post_data($email, $name);
459
- }
460
-
461
- /**
462
- * The NSU form shortcode function. Calls the output_form method
463
- *
464
- * @param array $atts Not used
465
- * @param string $content Not used
466
- * @return string Form HTML-code
467
- */
468
- public function form_shortcode($atts = null,$content = null)
469
- {
470
- return $this->output_form(false);
471
- }
472
-
473
- /**
474
- * Generate the HTML for a form
475
- * @param boolean $echo Should HTML be echo'ed?
476
- * @return string The generated HTML
477
- */
478
- public function output_form($echo = true)
479
- {
480
- $errors = $this->validation_errors;
481
- $opts = $this->getOptions();
482
- $additional_fields = '';
483
- $output = '';
484
-
485
- $this->no_of_forms++;
486
- $formno = $this->no_of_forms;
487
-
488
- /* Set up form variables for API usage or normal form */
489
- if($opts['mailinglist']['use_api'] == 1) {
490
-
491
- /* Using API, send form request to ANY page */
492
- $form_action = get_site_url();
493
- $email_id = 'nsu_email';
494
- $name_id = 'nsu_name';
495
-
496
- } else {
497
-
498
- /* Using normal form request, set-up using configuration settings */
499
- $form_action = $opts['mailinglist']['form_action'];
500
- $email_id = $opts['mailinglist']['email_id'];
501
-
502
- if(!empty($opts['mailinglist']['name_id'])) {
503
- $name_id = $opts['mailinglist']['name_id'];
504
- }
505
-
506
- }
507
-
508
- /* Set up additional fields */
509
-
510
- if(isset($opts['mailinglist']['extra_data']) && is_array($opts['mailinglist']['extra_data'])) :
511
- $additional_fields = '<div class="hidden">';
512
- foreach($opts['mailinglist']['extra_data'] as $ed) :
513
- if($ed['value'] == '%%NAME%%') continue;
514
- $ed['value'] = str_replace("%%IP%%", $_SERVER['REMOTE_ADDR'], $ed['value']);
515
- $additional_fields .= "<input type=\"hidden\" name=\"{$ed['name']}\" value=\"{$ed['value']}\" />";
516
- endforeach;
517
- $additional_fields .= "</div>";
518
- endif;
519
-
520
- $email_label = $opts['form']['email_label'];
521
- $name_label = $opts['form']['name_label'];
522
-
523
- $email_value = $opts['form']['email_default_value'];
524
- $name_value = $opts['form']['name_default_value'];
525
- $submit_button = $opts['form']['submit_button'];
526
-
527
- $text_after_signup = $opts['form']['text_after_signup'];
528
- $text_after_signup = ($opts['form']['wpautop'] == 1) ? wpautop(wptexturize($text_after_signup)) : $text_after_signup;
529
-
530
-
531
-
532
- if(!isset($_POST['nsu_submit']) || count($errors) > 0) { //form has not been submitted yet
533
-
534
- $output .= "<form class=\"nsu-form\" id=\"nsu-form-$formno\" action=\"$form_action\" method=\"post\">";
535
- if($opts['mailinglist']['subscribe_with_name'] == 1) {
536
- $output .= "<p><label for=\"nsu-name-$formno\">$name_label</label><input class=\"nsu-field\" id=\"nsu-name-$formno\" type=\"text\" name=\"$name_id\" value=\"$name_value\" ";
537
- if($name_value) $output .= "onblur=\"if(!this.value) this.value = '$name_value';\" onfocus=\"if(this.value == '$name_value') this.value=''\" ";
538
- $output .= "/>";
539
- if(isset($errors['name-field'])) $output .= '<span class="nsu-error error notice">'.$errors['name-field'].'</span>';
540
- $output .= "</p>";
541
- }
542
-
543
- $output .= "<p><label for=\"nsu-email-$formno\">$email_label</label><input class=\"nsu-field\" id=\"nsu-email-$formno\" type=\"text\" name=\"$email_id\" value=\"$email_value\" ";
544
- if($email_value) $output .= "onblur=\"if(!this.value) this.value = '$email_value';\" onfocus=\"if(this.value == '$email_value') this.value = ''\" ";
545
- $output .= "/>";
546
- if(isset($errors['email-field'])) $output .= '<span class="nsu-error error notice">'.$errors['email-field'].'</span>';
547
- $output .= "</p>";
548
- $output .= $additional_fields;
549
- $output .= "<p><input type=\"submit\" id=\"nsu-submit-$formno\" class=\"nsu-submit\" name=\"nsu_submit\" value=\"$submit_button\" /></p>";
550
- $output .= "</form>";
551
-
552
- } else { // form has been submitted
553
-
554
- $output = "<p id=\"nsu-signed-up-$formno\" class=\"nsu-signed-up\">$text_after_signup</p>";
555
-
556
- }
557
-
558
- if($echo) {
559
- echo $output;
560
- }
561
-
562
- return $output;
563
-
564
- }
565
- }
566
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/NSU.php ADDED
@@ -0,0 +1,315 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class NSU {
4
+
5
+ private $options = array();
6
+ private static $instance = null;
7
+ private static $checkbox = null;
8
+ private static $form = null;
9
+
10
+ public function __construct()
11
+ {
12
+ self::$instance = $this;
13
+
14
+ $opts = $this->get_options();
15
+
16
+ // widget hooks
17
+ add_action('widgets_init', array($this, 'register_widget'));
18
+
19
+ // Should we load the stylesheet?
20
+ if($opts['checkbox']['css_reset'] == 1 || $opts['form']['load_form_css'] == 1) {
21
+ add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
22
+ }
23
+
24
+ self::checkbox();
25
+ self::form();
26
+
27
+ if(!defined("DOING_AJAX") || !DOING_AJAX) {
28
+ // regular request
29
+ if(is_admin()) {
30
+
31
+ // backend only
32
+ require_once NSU_PLUGIN_DIR . 'includes/NSU_Admin.php';
33
+ new NSU_Admin();
34
+ } else {
35
+ // frontend only
36
+ require_once NSU_PLUGIN_DIR . 'includes/functions.php';
37
+ }
38
+ }
39
+ }
40
+
41
+ public static function checkbox()
42
+ {
43
+ if(!self::$checkbox) {
44
+ require_once NSU_PLUGIN_DIR .'includes/NSU_Checkbox.php';
45
+ self::$checkbox = new NSU_Checkbox;
46
+ }
47
+
48
+ return self::$checkbox;
49
+ }
50
+
51
+ public static function form()
52
+ {
53
+ if(!self::$form) {
54
+ require_once NSU_PLUGIN_DIR . 'includes/NSU_Form.php';
55
+ self::$form = new NSU_Form;
56
+ }
57
+
58
+ return self::$form;
59
+ }
60
+
61
+
62
+ /**
63
+ * Initalize options
64
+ * @return array $options
65
+ */
66
+ public function get_options()
67
+ {
68
+ if(empty($this->options)) {
69
+ $keys = array('form', 'mailinglist', 'checkbox');
70
+
71
+ $defaults = array(
72
+ 'form' => array('load_form_css' => 0, 'use_html5' => 1, 'submit_button' => 'Sign up',
73
+ 'name_label' => 'Name:', 'email_label' => "Email:", 'email_default_value' => 'Your emailaddress..', 'name_required' => 0, 'name_default_value' => 'Your name..', 'wpautop' => 0,
74
+ 'text_after_signup' => 'Thanks for signing up to our newsletter. Please check your inbox to confirm your email address.', 'redirect_to' => '',
75
+ 'text_empty_name' => 'Please fill in the name field.', 'text_empty_email' => 'Please fill in the email field.', 'text_invalid_email' => 'Please enter a valid email address.'
76
+ ),
77
+ 'mailinglist' => array('provider' => '', 'use_api' => 0, 'subscribe_with_name' => 0, 'email_id' => '', 'name_id' => '', 'form_action' => ''),
78
+ 'checkbox' => array('text' => 'Sign me up for the newsletter', 'redirect_to' => '', 'precheck' => 0, 'cookie_hide' => 0, 'css_reset' => 0,
79
+ 'add_to_registration_form' => 0, 'add_to_comment_form' => 1, 'add_to_buddypress_form' => 0,
80
+ 'add_to_multisite_form' => 0, 'add_to_bbpress_forms' => 0
81
+ )
82
+ );
83
+
84
+ foreach($keys as $key) {
85
+ if(($option = get_option('nsu_'. $key)) == false) {
86
+ add_option('nsu_'. $key, $defaults[$key]);
87
+ }
88
+
89
+ $this->options[$key] = array_merge($defaults[$key], (array) $option);
90
+ }
91
+
92
+ }
93
+
94
+ return $this->options;
95
+ }
96
+
97
+ /**
98
+ * Registers the Newsletter Sign-Up Widget
99
+ * @return type
100
+ */
101
+ public function register_widget()
102
+ {
103
+ require_once NSU_PLUGIN_DIR . 'includes/NewsletterSignUpWidget.php';
104
+ return register_widget('NewsletterSignUpWidget');
105
+ }
106
+
107
+ /**
108
+ * Factory method for NewsletterSignUp class. Only instantiate once.
109
+ * @return NewsletterSignUp Instance of Newsletter Sign-Up class
110
+ */
111
+ public static function instance() {
112
+ if(!self::$instance) self::$instance = new NSU();
113
+
114
+ return self::$instance;
115
+ }
116
+
117
+ public function enqueue_styles()
118
+ {
119
+ $opts = $this->get_options();
120
+
121
+ // Build stylesheet url --------------
122
+ $stylesheet_opts = '?';
123
+
124
+ // Load CSS to reset the checkbox' position?
125
+ if($opts['checkbox']['css_reset'] == 1) {
126
+ $stylesheet_opts .= 'checkbox_reset=1&';
127
+ }
128
+
129
+ // Load CSS to reset label and input fields for the sign-up form?
130
+ if($opts['form']['load_form_css'] == 1) {
131
+ $stylesheet_opts .= 'form_css=1&';
132
+ }
133
+
134
+ wp_enqueue_style('ns_checkbox_style', plugins_url("/assets/css/newsletter-sign-up.php{$stylesheet_opts}", dirname(__FILE__)));
135
+ }
136
+
137
+
138
+
139
+
140
+ /**
141
+ * Send the post data to the newsletter service, mimic form request
142
+ */
143
+ function send_post_data($email, $name = '', $type = 'checkbox')
144
+ {
145
+ $opts = $this->options['mailinglist'];
146
+
147
+ // when not using api and no form action has been given, abandon.
148
+ if(empty($opts['use_api']) && empty($opts['form_action'])) return;
149
+
150
+ /* Are we using API? */
151
+ if($opts['use_api'] == 1) {
152
+
153
+ switch($opts['provider']) {
154
+
155
+ /* Send data using the YMLP API */
156
+ case 'ymlp':
157
+ $data = array(
158
+ 'key' => $opts['ymlp_api_key'],
159
+ 'username' => $opts['ymlp_username'],
160
+ 'Email' => $email,
161
+ 'GroupId' => $opts['ymlp_groupid'],
162
+ 'output' => 'JSON'
163
+ );
164
+
165
+ $data = array_merge($data, $this->add_additional_data(array('api' => 'ymlp')));
166
+ $data = http_build_query($data);
167
+ $url = 'https://www.ymlp.com/api/Contacts.Add?'.$data;
168
+
169
+ $result = wp_remote_post($url);
170
+
171
+ if(isset($_POST['_nsu_debug']) || isset($_GET['_nsu_debug'])) {
172
+ var_dump($result); die();
173
+ }
174
+
175
+ break;
176
+
177
+ /* Send data using the MailChimp API */
178
+ case 'mailchimp':
179
+ $request = array(
180
+ 'apikey' => $opts['mc_api_key'],
181
+ 'id' => $opts['mc_list_id'],
182
+ 'email_address' => $email,
183
+ 'double_optin' => (isset($opts['mc_no_double_optin']) && $opts['mc_no_double_optin'] == 1) ? FALSE : TRUE,
184
+ 'merge_vars' => array(
185
+ 'OPTIN_TIME' => date('Y-M-D H:i:s')
186
+ )
187
+ );
188
+
189
+ if(isset($opts['mc_use_groupings']) && $opts['mc_use_groupings'] == 1 && !empty($opts['mc_groupings_name'])) {
190
+ $request['merge_vars']['GROUPINGS'] = array(
191
+ array( 'name' => $opts['mc_groupings_name'], 'groups' => $opts['mc_groupings_groups'] )
192
+ );
193
+ }
194
+
195
+ /* Subscribe with name? If so, add name to merge_vars array */
196
+ if(isset($opts['subscribe_with_name']) && $opts['subscribe_with_name'] == 1) {
197
+ // Try to provide values for First and Lastname fields
198
+ // These can be overridden, of just ignored by mailchimp.
199
+ $strpos = strpos($name, ' ');
200
+
201
+ $request['merge_vars']['FNAME'] = $name;
202
+
203
+ if($strpos) {
204
+ $request['merge_vars']['FNAME'] = substr($name, 0, $strpos);
205
+ $request['merge_vars']['LNAME'] = substr($name, $strpos);
206
+ } else {
207
+ $request['merge_vars']['FNAME'] = $name;
208
+ $request['merge_vars']['LNAME'] = '...';
209
+ }
210
+
211
+ $request['merge_vars'][$opts['name_id']] = $name;
212
+ }
213
+
214
+ // Add any set additional data to merge_vars array
215
+ $request['merge_vars'] = array_merge($request['merge_vars'], $this->add_additional_data(array('email' => $email, 'name' => $name)));
216
+
217
+ $result = wp_remote_post(
218
+ 'http://'.substr($opts['mc_api_key'],-3).'.api.mailchimp.com/1.3/?output=php&method=listSubscribe',
219
+ array( 'body' => json_encode($request))
220
+ );
221
+
222
+ if(isset($_POST['_nsu_debug']) || isset($_GET['_nsu_debug'])) {
223
+ var_dump($result); die();
224
+ }
225
+
226
+ break;
227
+
228
+ }
229
+
230
+ } else {
231
+ /* We are not using API, mimic a normal form request */
232
+
233
+ $post_data = array(
234
+ $opts['email_id'] => $email,
235
+ );
236
+
237
+ // Subscribe with name? Add to $post_data array.
238
+ if($opts['subscribe_with_name'] == 1) $post_data[$opts['name_id']] = $name;
239
+
240
+ // Add list specific data
241
+ switch($opts['provider']) {
242
+
243
+ case 'aweber':
244
+ $post_data['listname'] = $opts['aweber_list_name'];
245
+ $post_data['redirect'] = get_bloginfo('wpurl');
246
+ $post_data['meta_message'] = '1';
247
+ $post_data['meta_required'] = 'email';
248
+ break;
249
+
250
+ case 'phplist':
251
+ $post_data['list['.$opts['phplist_list_id'].']'] = 'signup';
252
+ $post_data['subscribe'] = "Subscribe";
253
+ $post_data["htmlemail"] = "1";
254
+ $post_data['emailconfirm'] = $email;
255
+ $post_data['makeconfirmed']='0';
256
+ break;
257
+
258
+ }
259
+
260
+ $post_data = array_merge($post_data, $this->add_additional_data(array_merge(array('email' => $email, 'name' => $name), $post_data)));
261
+
262
+ $result = wp_remote_post($opts['form_action'],
263
+ array( 'body' => $post_data )
264
+ );
265
+
266
+ if(isset($_POST['_nsu_debug']) || isset($_GET['_nsu_debug'])) {
267
+ var_dump($result); die();
268
+ }
269
+
270
+ }
271
+
272
+ // store a cookie, if preferred by site owner
273
+ if($type == 'checkbox' && $this->options['checkbox']['cookie_hide'] == 1) @setcookie('ns_subscriber',TRUE,time() + 9999999);
274
+
275
+ // Check if we should redirect to a given page
276
+ if($type == 'form' && strlen($this->options['form']['redirect_to']) > 6) {
277
+ wp_redirect( $this->options['form']['redirect_to']);
278
+ exit;
279
+ } elseif($type == 'checkbox' && strlen($this->options['checkbox']['redirect_to']) > 6) {
280
+ wp_redirect( $this->options['checkbox']['redirect_to']);
281
+ exit;
282
+ }
283
+
284
+ return true;
285
+ }
286
+
287
+
288
+ /**
289
+ * Returns array with additional data names as key, values as value.
290
+ * @param array $args, the normal form data (name, email, list variables)
291
+ */
292
+ function add_additional_data($args = array())
293
+ {
294
+ $opts = $this->options['mailinglist'];
295
+ $defaults = array(
296
+ 'format' => 'array',
297
+ 'api' => NULL
298
+ );
299
+
300
+ $args = wp_parse_args( $args, $defaults );
301
+
302
+ $add_data = array();
303
+ if(isset($opts['extra_data']) && is_array($opts['extra_data'])) {
304
+ foreach($opts['extra_data'] as $key => $value) {