forked from nodesman/wp-autoresponder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
customizeblogemail.php
543 lines (289 loc) · 13.7 KB
/
customizeblogemail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
<?php
include_once 'htmltemplates.lib.php';
/*
* The functions in this file add the interface that customizes the blog post
* email
*
*/
function wpr_edit_post_save($id)
{
$nonce = $_POST['wpr-blogemailoptions-nonce'];
if (wp_verify_nonce($nonce, 'wpr-blogemailoptions-nonce'))
{
delete_post_meta($id,'wpr-options');
$ncount = $_POST['wpr-newsletters-count'];
$nid = $_POST['wpr-newsletters'];
if ($ncount > 0) //if there are some newsletters at all
{
$nids = explode(",",$nid);
foreach ($nids as $nid) //for each newsleter, form an array for the options
{
//if we are disabling customization, we don't need to check the other fields.
if (isset($_POST['skipnewsletter-'.$nid]))
{
$arguments = GetDisableCompletelyForNewsletterArguments($nid);
$options[$nid]=$arguments;
}//if the disabled checkbox is enabled or the subject is left empty or if the text box and the html box both are left empty..disable customization
else if (isset($_POST['disablecustomization-'.$nid]) || (empty($_POST['subject-'.$nid])) || (strlen(trim($_POST['textbody-'.$nid]))==0 && strlen(trim(strip_tags($_POST['htmlbody-'.$nid]) )) == 0 ))
{
$activeSubscribers = (isset($_POST['skipfollowup-'.$nid]))?1:0;
$arguments = GetDisabledCustomizationArguments($nid,$activeSubscribers);
if (strlen(trim(strip_tags($_POST['htmlbody-'.$nid])))==0 && !empty($_POST['textbody-'.$nid]))
$arguments['htmlenable'] = 0;
$options[$nid]=$arguments;
}
else
{
$currentNewsletterOptions = CreateNewsletterPostValuesArray($nid);
$options[$nid] = $currentNewsletterOptions;
}
//else
}
}
else { //there are no newsletter to save options for. save an empty array
$options = array();
}
$wprmeta = serialize($options);
$wprmeta = base64_encode($wprmeta);
add_post_meta($id,"wpr-options",$wprmeta);
}
}
function CreateNewsletterPostValuesArray($newsletterId)
{
$val = array(
"nid"=> $newsletterId,
"subject"=>stripslashes($_POST['subject-'.$newsletterId]),
"textbody"=> stripslashes($_POST['textbody-'.$newsletterId]),
"htmlbody"=> ($_POST['htmlenable-'.$newsletterId] == 1)?stripslashes($_POST['htmlbody-'.$newsletterId]):"",
"disable"=> (isset($_POST['skipnewsletter-'.$newsletterId]))?1:0,
"skipactivesubscribers"=>(isset ($_POST['skipfollowup-'.$newsletterId]))?1:0,
"htmlenable"=>(isset($_POST['htmlenable-'.$newsletterId]))?1:0,
"attachimages"=>(isset($_POST['attachimages-'.$newsletterId]))?1:0,
"nocustomization"=>(isset($_POST['disablecustomization-'.$newsletterId]))?1:0,
"nopostseries"=>(isset($_POST['nopostseries-'.$newsletterId]))?1:0
);
return $val;
}
function wpresponder_meta_box_add()
{
add_meta_box('wpresponder_skip','E-Mail Subscriber Settings','wpr_add_post_block','post','normal','high');
}
function wpr_add_post_block()
{
global $post;
$post_id = $post;
if (is_object($post_id))
{
$post_id = $post_id->ID;
}
getNewsletterOptions($post_id);
}
/*
* This function generates the tabs interface for all the
* newsletters. It puts the form codes into a
*/
function getNewsletterOptions($post_id=0)
{
global $wpdb;
$query = "SELECT * FROM ".$wpdb->prefix."wpr_newsletters";
$results = $wpdb->get_results($query);
if (count($results))
{
?>
<span style="font-size: 12px; line-height: 25px;">Each of the tabs below allow you to customize the email that goes out to the blog subscribers, blog category subscribers and post series subscribers of that newsletter. The blog post will be delivered ONLY to subscribers who have subscribed to receive all posts published in the blog or the posts filed under one of the blog categories in which this blog post will be published. Ordinary newsletter subscribers will not receive this blog post at all.
</span>
<input type="hidden" name="wpr-blogemailoptions-nonce" value="<?php echo wp_create_nonce('wpr-blogemailoptions-nonce') ?>" />
<input type="hidden" name="wpr-newsletters-count" value="<?php echo count($results) ?>"/>
<input type="hidden" name="wpr-newsletters" value="<?php foreach ($results as $newsletter) { $nids[] = $newsletter-> id; }
echo implode(",",$nids); ?>"/>
<div class="tabber">
<?php
foreach ($results as $newsletter)
{
?>
<div class="tabbertab" id="wprtabs">
<?php
//Form for customizing the mailout for a single newsletter
$post = get_post($post_id);
//Unpublished posts should get an id of zero.
if ($post->post_status == 'auto-draft')
{
$post_id = 0;
}
$arguments = getArguments($post_id,$newsletter);
echo getNewsletterCustomizationFormCode($arguments,"new");
?>
</div>
<?php
}
}
else
{
?>
You haven't created any newsletters. Create atleast one before
setting blog post email settings.
<?php
}
}
function getArguments($post_id,$newsletter)
{
$post_id = (int) $post_id;
if ($post_id == 0)
$arguments = GetDefaultArguments($newsletter);
else { //get the post meta from the db
$optionsArray = get_post_meta($post_id,"wpr-options");
$arguments = unserialize(base64_decode($optionsArray[0]));
$arguments= $arguments[$newsletter->id];
}
return $arguments;
}
function GetDefaultArguments($newsletter)
{
return array("nid"=>$newsletter->id,
"subject"=>"",
"textbody"=>"",
"htmlbody"=>"",
"disable"=>0,
"nocustomization"=>1,
"htmlenable"=>1,
"attachimages"=>1,
"skipactivesubscribers"=>1,
"nopostseries"=>1
);
}
function GetDisableCompletelyForNewsletterArguments($nid)
{
return array("nid"=>$nid,
"subject"=>"",
"textbody"=>"",
"htmlbody"=>"",
"disable"=>1,
"nocustomization"=>0,
"htmlenable"=>1,
"attachimages"=>1,
"skipactivesubscribers"=>1,
"nopostseries"=>1
);
}
function GetDisabledCustomizationArguments($nid,$activeSubscribers)
{
return array("nid"=>$nid,
"subject"=>"",
"textbody"=>"",
"htmlbody"=>"",
"disable"=>0,
"nocustomization"=>1,
"nopostseries"=>1,
"htmlenable"=>1,
"attachimages"=>1,
"skipactivesubscribers"=>$activeSubscribers
);
}
/*
* This function generates the email customization for the blog post for one
* newletter
*/
function getNewsletterCustomizationFormCode($arguments,$mode="new")
{
global $wpdb;
$nid = $arguments['nid'];
$newsletter = _wpr_newsletter_get($nid);
?>
<h2><?php echo $newsletter->name; ?></h2>
<p>
<input type="checkbox" <?php if ($arguments['disable']) { echo 'checked="checked"'; } ?> autocomplete="off" onchange="toggleStatus(<?php echo $nid ?>,this.checked);" id="toggleForm-<?php echo $nid; ?>" name="skipnewsletter-<?php echo $nid; ?>" value="1" id="skipnewsletter-<?php echo $nid; ?>">
Don't deliver this blog post to blog subscribres or blog category subscribers. But use these settings for post series deliveries. </p>
<p>
<input type="checkbox" <?php if ($arguments['nopostseries']==1) { echo 'checked="checked"'; } ?> name="nopostseries-<?php echo $nid ?>" autocomplete="off" id="nopostseries">
<label for="nopostseries"> Don't use these settings while delivering email to post series subscribers. Use a default layout that uses the blog post's content.</label>
</p>
<div id="editorformitems-<?php echo $nid; ?>">
<p>
<input autocomplete="off" type="checkbox" <?php if ($arguments['skipactivesubscribers']) { echo 'checked="checked"'; } ?> name="skipfollowup-<?php echo $nid ?>" value="1" id="skipfollowup-<?php echo $nid ?>">
Don't deliver this blog post to subscribers who are receiving a follow up sequence associated with this newsletter.</p>
<p>
<fieldset style="border:1px solid #909090; padding:10px;"> <legend><input type="checkbox" <?php if ($arguments['nocustomization']) { echo 'checked="checked"'; } ?> autocomplete="off" onchange="toggleCustomization(<?php echo $nid ?>, this.checked);" name="disablecustomization-<?php echo $nid ?>" value="1" id="disablecustomization-<?php echo $nid ?>">
Disable all customization (use default layout for the email)</p></legend>
<div id="customizationsform-<?php echo $nid ?>">
<div id="form-<?php echo $nid ?>">
<p style="font-size: 17px; font-weight: bold">Subject:
<input type="text" name="subject-<?php echo $nid ?>" value="<?php echo $arguments['subject'] ?>" size="50"></p>
<p style="font-size: 17px; font-weight: bold">Text Body:</p>
<textarea style="border: 1px solid #c0c0c0;" name="textbody-<?php echo $nid ?>" rows="10" cols="80"><?php echo $arguments['textbody'] ?></textarea>
<p style="font-size: 17px; font-weight: bold">HTML Body:</p>
<?php CreateNewTemplateSwitcherButton("listOfEditors[".$nid."]","htmlbody-".$nid,$nid); ?>
<p>
<input type="checkbox" <?php if ($arguments['htmlenable']) { echo 'checked="checked"'; } ?> onchange="toggleHtmlBody(<?php echo $nid ?>,this.checked)" name="htmlenable-<?php echo $nid ?>" id="htmlenable-<?php echo $nid ?>" value="1">
Enable HTML Body</p>
<div id="htmlformitems-<?php echo $nid ?>">
<p>
<input type="checkbox" name="attachimages-<?php echo $nid ?>" <?php if ($arguments['attachimages']) { echo 'checked="checked"'; } ?> value="1">
Images in the email are attached with the email instead of being given a URL in the source code</p>
<div style="float:right; padding-bottom:20px;"><a class="button-primary" target="_blank" href="http://www.krusible.com/newsletter-design/">Get a custom Email Newsletter template</a>
</div>
<br/><br/><br/>
<div style="clear:both"></div>
<div id="editor-<?php echo $nid ?>">
<textarea id="htmlbody-<?php echo $nid ?>" name="htmlbody-<?php echo $nid ?>" rows="20" cols="80"><?php echo ($arguments['htmlenable'])?$arguments['htmlbody']:""; ?></textarea>
</div>
<input type="button" onclick="createEditor(<?php echo $nid ?>)" value="Enable WYSIWYG" name="enable"/>
<input type="button" value="Disable WYSIWYG" onclick="removeEditor(<?php echo $nid; ?>)" name="enable"/>
</div>
</div>
<script>
toggleStatus(<?php echo $nid ?>,document.getElementById("toggleForm-<?php echo $nid ?>").checked);
toggleHtmlBody(<?php echo $nid ?>,document.getElementById("htmlenable-<?php echo $nid ?>").checked);
toggleCustomization(<?php echo $nid ?>,document.getElementById("disablecustomization-<?php echo $nid ?>").checked);
</script>
<p style="font-size: 17px; font-weight: bold">Shortcodes</p>
<div style="font-size: 14px;"> Use the following codes in the Text or HTML body to replace it with the appropriate
text.
<p></p>
<ol>
<li>Post related shortcodes:<br>
<ol>
<li>[!post_url!] - Replace with the URL of this post when it is published</li>
<li>[!delivery_date!] - Date when this email was delivered</li>
<li>[!post_date!] - Date under which you file this post for publishing.</li>
</ol>
</li>
<li>Subscriber attributes and custom fields:
<ol>
<li>[!name!] - Name of the subscriber</li>
<li>[!email!] - The email address of the subscriber.</li>
<?php
$query = "SELECT * from ".$wpdb->prefix."wpr_custom_fields where nid=$nid;";
$results = $wpdb->get_results($query);
foreach ($results as $custom_fields)
{
?>
<li>[!<?php echo $custom_fields->name ?>!] - <?php echo $custom_fields->name ?></li>
<?php
}
?>
</ol>
</li>
</ol>
</div>
</div>
</p></fieldset>
</div>
</div>
<?php
}
function wpr_add_post_save($id)
{
$nonce = $_POST['wpr-nonce'];
$setting = $_POST['wpresponder_on'];
if (wp_verify_nonce($nonce, 'wpr-skip-nonce'))
{
if ($setting=="on")
{
add_post_meta($id, "_wpresponder_on","on");
}
else
{
add_post_meta($id, "_wpresponder_on","off");
}
}
}