-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwpresponder.php
470 lines (391 loc) · 15.1 KB
/
wpresponder.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
<?php
/*
Plugin Name: Javelin
Plugin URI: http://www.nodesman.com
Description: Gather subscribers in newsletters, follow up with automated e-mails, provide subscription to all posts in your blog or individual categories.
Version: 5.3.12
Author: Raj Sekharan
Author URI: http://www.nodesman.com/
*/
$plugindir = plugin_dir_path( __FILE__ );;
define("WPR_DIR", plugin_dir_path( __FILE__ ));
$controllerDir = WPR_DIR . "/controllers";
$modelsDir = WPR_DIR."/models";
$helpersDir = WPR_DIR."/helpers";
define("WPR_VERSION", "5.3.12");
define("WPR_PLUGIN_DIR", "$plugindir");
include_once "$controllerDir/newsletters.php";
include_once "$controllerDir/custom_fields.php";
include_once "$controllerDir/importexport.php";
include_once "$controllerDir/background_procs.php";
include_once "$controllerDir/settings.php";
include_once "$controllerDir/new-broadcast.php";
include_once "$controllerDir/queue_management.php";
include_once "$controllerDir/autoresponder.php";
include_once "$modelsDir/subscriber.php";
include_once "$modelsDir/newsletter.php";
include_once "$modelsDir/autoresponder_message.php";
include_once "$modelsDir/autoresponder.php";
include_once WPR_DIR . '/home.php';
include_once WPR_DIR . '/blog_series.php';
include_once WPR_DIR . '/forms.php';
include_once WPR_DIR . '/newmail.php';
include_once WPR_DIR . '/subscribers.php';
include_once WPR_DIR . '/htmltemplates.lib.php';
include_once WPR_DIR . '/wpr_deactivate.php';
include_once WPR_DIR . '/all_mailouts.php';
include_once WPR_DIR . '/actions.php';
include_once WPR_DIR . '/blogseries.lib.php';
include_once WPR_DIR . '/lib.php';
include_once WPR_DIR . '/conf/meta.php';
include_once WPR_DIR . '/conf/config.php';
include_once WPR_DIR . '/conf/global_constants.php';
include_once WPR_DIR . '/lib/swift_required.php';
include_once WPR_DIR . '/lib/admin_notifications.php';
include_once WPR_DIR . '/lib/global.php';
include_once WPR_DIR . '/lib/custom_fields.php';
include_once WPR_DIR . '/lib/database_integrity_checker.php';
include_once WPR_DIR . '/lib/framework.php';
include_once WPR_DIR . '/lib/database_integrity_checker.php';
include_once WPR_DIR . '/lib/mail_functions.php';
include_once WPR_DIR . '/other/cron.php';
include_once WPR_DIR . '/other/firstrun.php';
include_once WPR_DIR . '/other/queue_management.php';
include_once WPR_DIR . '/other/notifications_and_tutorials.php';
include_once WPR_DIR . '/other/background.php';
include_once WPR_DIR . '/other/install.php';
include_once WPR_DIR . '/other/blog_crons.php';
include_once WPR_DIR . '/other/maintain.php';
include_once WPR_DIR . '/widget.php';
//processes
include_once WPR_DIR . '/processes/background_process.php';
include_once WPR_DIR . '/processes/autoresponder_process.php';
include_once WPR_DIR . '/processes/broadcast_processor.php';
include_once WPR_DIR . '/conf/routes.php';
include_once WPR_DIR . '/conf/events.php';
include_once WPR_DIR . '/conf/files.php';
include_once WPR_DIR . '/conf/config.php';
include_once WPR_DIR . "/helpers/routing.php";
include_once WPR_DIR . "/helpers/paging.php";
$GLOBALS['wpr_globals'] = array();
function _wpr_nag()
{
$address = get_option("wpr_address");
if (!$address && current_user_can("manage_newsletters"))
{
add_action("admin_notices","no_address_error");
}
add_action("admin_notices","_wpr_admin_notices_show");
}
class Javelin
{
private static $instance;
private function __construct() {
add_action('admin_init',array($this, 'admin_init'));
add_action('init', array($this, 'init'),1);
add_action('plugins_loaded','_wpr_nag');
add_action('admin_menu', 'wpr_admin_menu');
add_action('admin_head', array(&$this, 'admin_head'));
add_action('widgets_init','wpr_widgets_init');
register_activation_hook(__FILE__,"wpresponder_install");
register_deactivation_hook(__FILE__,"wpresponder_deactivate");
add_filter('cron_schedules','wpr_cronschedules');
}
public function install()
{
$this->manageCapabilities();
$this->manageDatabaseStructure();
$this->updateLastPostDate();
$this->loadEmailTemplates();
$this->setNextCronScheduleTime();
$this->initializeOptions();
$this->updateNotificationEmail();
wpr_enable_tutorial();
wpr_enable_updates();
_wpr_schedule_crons_initial();
}
function admin_head() {
?>
<script>
var WPRConfig = {
ckeditor_baseHref: '<?php echo plugins_url("ckeditor/",__FILE__) ?>'
};
</script>
<?php
}
function init()
{
_wpr_load_plugin_textdomain();
_wpr_add_required_blogseries_variables();
if (_wpr_whether_optin_post_request())
_wpr_optin();
if (_wpr_whether_verify_subscription_request())
_wpr_render_verify_email_address_page();
if (_wpr_whether_confirm_subscription_request())
_wpr_render_confirm_subscription();
if (_wpr_whether_html_broadcast_view_frame_request())
_wpr_render_broadcast_view_frame();
if (Routing::is_template_html_request()) {
Routing::render_template_html();
}
if (Routing::is_admin_popup())
Routing::render_admin_screen_popup();
if (Routing::whether_file_request())
Routing::serve_file();
if ($this->whetherBroadcastCompositionScreen()) {
$this->enqueueAdminScripts();
}
if (_wpr_whether_confirmed_subscription_request())
_wpr_render_confirmed_subscription_page();
if (Routing::is_subscription_management_page_request())
_wpr_render_subscription_management_page();
_wpr_attach_cron_actions_to_functions();
_wpr_ensure_single_instance_of_cron_is_registered(); //TODO: Get rid of this and make something more appropriate
_wpr_attach_to_non_wpresponder_email_delivery_filter();
do_action("_wpr_init");
}
public function whetherBroadcastCompositionScreen()
{
return (isset($_GET['page']) && (('wpresponder/newmail.php' == $_GET['page'] || ('wpresponder/allmailouts.php' == $_GET['page'] && isset($_GET['action']) && 'edit' == $_GET['action'] ))));
}
function admin_init()
{
_wpr_initialize_admin_pages();
if (_wpr_whether_wpresponder_admin_page())
Routing::run_controller();
}
public static function getInstance()
{
if (empty(self::$instance)) {
self::$instance = new Javelin();
}
return self::$instance;
}
private function updateLastPostDate()
{
delete_option("wpr_last_post_date");
$args = array('orderby' => 'date', 'order' => 'DESC', 'numberposts' => 1, 'post_type' => 'post');
$posts = get_posts($args);
if (count($posts) > 0) {
$post = $posts[0];
$last_post_date = $post->post_date_gmt;
} else {
$last_post_date = date("Y-m-d H:i:s", time());
}
add_option("wpr_last_post_date", $last_post_date);
}
private function loadEmailTemplates()
{
//the confirm email, confirmation email and confirmed subject templates.
$confirm_subject = file_get_contents(WPR_DIR . "/templates/confirm_subject.txt");
$confirm_body = file_get_contents(WPR_DIR . '/templates/confirm_body.txt');
$confirmed_subject = file_get_contents(WPR_DIR . "/templates/confirmed_subject.txt");
$confirmed_body = file_get_contents(WPR_DIR . "/templates/confirmed_body.txt");
update_option("wpr_confirm_subject", $confirm_subject);
update_option("wpr_confirm_body", $confirm_body);
update_option("wpr_confirmed_subject", $confirmed_subject);
update_option("wpr_confirmed_body", $confirmed_body);
}
private function setNextCronScheduleTime()
{
update_option("wpr_next_cron", time() + 300);
}
private function manageCapabilities()
{
$role = get_role('administrator');
$role->add_cap('manage_newsletters');
}
private function manageDatabaseStructure()
{
$dbInitializer = DatabaseChecker::getInstance();
$dbInitializer->init();
}
private function initializeOptions()
{
$options = $GLOBALS['initial_wpr_options'];
foreach ($options as $option_name => $option_value) {
$current_value = get_option($option_name);
if (empty($current_value)) {
add_option($option_name, $option_value);
}
}
}
private function updateNotificationEmail()
{
$notificationEmail = get_option('wpr_notification_custom_email');
if (empty($notificationEmail)) {
add_option('wpr_notification_custom_email', 'admin_email');
}
}
private function enqueueAdminScripts()
{
wp_enqueue_style("wpresponder-tabber", get_bloginfo("wpurl") . "/?wpr-file=tabber.css");
wp_enqueue_style("wpr-jquery-ui");
wp_enqueue_script("wpresponder-tabber");
wp_enqueue_script("wpresponder-scripts");
wp_enqueue_script("wpresponder-ckeditor");
wp_enqueue_script("jquery");
}
}
register_activation_hook(__FILE__, array(Javelin::getInstance(), 'install'));
function no_address_error()
{
?><div class="error fade"><p><strong>You must set your address in the <a href="<?php echo admin_url( 'admin.php?page=_wpr/settings' ) ?>"> newsletter settings page</a>.</strong></p></div><?php
}
function _wpr_enqueue_admin_scripts_and_styles()
{
$url = (isset($_GET['page']))?$_GET['page']:'';
$querystring = $_SERVER['QUERY_STRING'];
if (isset($_GET['page']) && preg_match("@^_wpr/@", $_GET['page'])) {
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-tabs');
wp_enqueue_script("wpresponder-scripts");
wp_enqueue_script('post');
}
$whetherBroadcastEditPage = preg_match("@wpresponder/allmailouts.php&action=edit@", $querystring);
if (preg_match("@newmail\.php@", $url) || preg_match("@autoresponder\.php@", $url) || $whetherBroadcastEditPage == true) {
wp_enqueue_script("wpresponder-ckeditor");
wp_enqueue_script("jquery");
}
wp_enqueue_style("wpr-jquery-ui");
add_action("admin_head", "_wpr_admin_enqueue_less");
}
function _wpr_admin_enqueue_less()
{
?>
<link rel="stylesheet/less" type="text/css" href="<?php echo get_bloginfo('wpurl') ?>/?wpr-file=admin-ui.less"/>
<script type="text/javascript" src="<?php echo get_bloginfo('wpurl') ?>/?wpr-file=less.js"></script>
<?php
}
function _wpr_load_plugin_textdomain()
{
$domain = 'wpr_autoresponder';
$locale = apply_filters('plugin_locale', get_locale(), $domain);
$plugindir = dirname(plugin_basename(__FILE__));
load_textdomain($domain, WP_LANG_DIR.'/'.$plugindir.'/'.$domain.'-'.$locale.'.mo');
load_plugin_textdomain($domain, FALSE, $plugindir.'/languages/');
}
function _wpr_do_first_run_initializations()
{
_wpr_firstrunv526();
add_option("_wpr_firstrunv526", "done");
}
function _wpr_whether_first_run()
{
return get_option("_wpr_firstrun") != "done";
}
function _wpr_initialize_admin_pages()
{
_wpr_register_wpresponder_scripts();
_wpr_register_wpresponder_styles();
_wpr_enqueue_admin_scripts_and_styles();
}
function _wpr_attach_to_non_wpresponder_email_delivery_filter()
{
add_filter("wp_mail", "_wpr_non_wpr_email_sent");
}
//TODO: Refactor the contents of manage.php
function _wpr_render_subscription_management_page()
{
include "manage.php";
exit;
}
function _wpr_render_confirmed_subscription_page()
{
include "confirmed.php";
exit;
}
function _wpr_whether_confirmed_subscription_request()
{
return isset($_GET['wpr-confirm']) && $_GET['wpr-confirm'] == 2;
}
function _wpr_register_wpresponder_scripts()
{
$url = get_bloginfo("wpurl");
wp_register_script("jqueryui-full", "$url/?wpr-file=jqui.js");
wp_register_script("angularjs", "$url/?wpr-file=angular.js");
wp_register_script("wpresponder-tabber", "$url/?wpr-file=tabber.js");
wp_register_script("wpresponder-ckeditor", plugin_dir_url(__FILE__) ."ckeditor/ckeditor.js");
wp_register_script("wpresponder-scripts", get_bloginfo('wpurl').'/?wpr-file=script.js');
}
function _wpr_register_wpresponder_styles() {
wp_register_style('wpr-jquery-ui', plugin_dir_url(__FILE__).'/jqueryui.css');
}
function _wpr_whether_wpresponder_admin_page()
{
return (is_admin() && Routing::isWPRAdminPage() && !Routing::whetherLegacyURL($_GET['page'])) || (whetherActionsPage()) ;
}
function whetherActionsPage()
{
if (!isset($_GET['page']))
return false;
return 'wpresponder/actions.php' == $_GET['page'];
}
function _wpr_render_broadcast_view_frame()
{
$vb = intval($_GET['wpr-vb']);
if (isset($_GET['wpr-vb']) && $vb > 0) {
require "broadcast_html_frame.php";
exit;
}
}
function _wpr_whether_html_broadcast_view_frame_request()
{
return isset($_GET['wpr-vb']);
}
function _wpr_whether_confirm_subscription_request()
{
return isset($_GET['wpr-confirm']) && $_GET['wpr-confirm'] != 2;
}
function _wpr_render_confirm_subscription()
{
include "confirm.php";
exit;
}
function _wpr_whether_verify_subscription_request()
{
return isset($_GET['wpr-optin']) && $_GET['wpr-optin'] == 2;
}
function _wpr_render_verify_email_address_page()
{
require "verify.php";
exit;
}
function _wpr_optin()
{
require "optin.php";
exit;
}
function _wpr_whether_optin_post_request()
{
return isset($_GET['wpr-optin']) && $_GET['wpr-optin'] == 1;
}
function _wpr_add_required_blogseries_variables()
{
$activationDate = get_option("_wpr_NEWAGE_activation");
if (empty($activationDate) || !$activationDate) {
$timeNow = time();
update_option("_wpr_NEWAGE_activation", $timeNow);
}
}
function _wpr_ensure_single_instance_of_cron_is_registered()
{
/*
* The following code ensures that the WP Responder's crons are always scheduled no matter what
* Sometimes the crons go missing from cron's registry. Only the great zeus knows why that happens.
* The following code ensures that the crons are always scheduled immediately after they go missing.
* It also unenqueues duplicate crons that get enqueued when the plugin is deactivated and then reactivated.
*/
$last_run_esic = intval(_wpr_option_get("_wpr_ensure_single_instances_of_crons_last_run"));
$timeSinceLast = time() - $last_run_esic;
if ($timeSinceLast > WPR_ENSURE_SINGLE_INSTANCE_CHECK_PERIODICITY) {
do_action("_wpr_ensure_single_instances_of_crons");
$currentTime = time();
_wpr_option_set("_wpr_ensure_single_instances_of_crons_last_run", $currentTime);
}
}
function wpr_widgets_init()
{
return register_widget("WP_Subscription_Form_Widget");
}