-
Notifications
You must be signed in to change notification settings - Fork 2
/
common_functions.php
389 lines (335 loc) · 14.3 KB
/
common_functions.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
<?php
/**
* Stats function to show all statistics data
* fetched using pepipost api
*/
if (!function_exists('wp_pepipost_logs')) {
function wp_pepipost_logs() {
//create the object for class, if not exits
if ( !isset($obj) )
$obj = new Logs();
?>
<div class="wrap">
<!-- Display common html strucure -->
<?php echo $obj->common_html(); ?>
<br>
<h2 id="log_head"><?php _e('Pepipost Logs', 'wp_pepipost'); ?></h2>
<form id="emailSearchForm" method="post" action="admin.php?page=wp_pepipost_logs">
<?php wp_nonce_field('wpp_from_to', 'wpp_from_to_field'); ?>
<input type="text" name="search_by_email" value="<?php echo !empty($_POST['search_by_email']) ? $_POST['search_by_email'] : ''; ?>" placeholder="Enter email to search">
<input type="hidden" name="paged" id="paged" value="<?php echo !empty($_REQUEST['paged']) ? $_REQUEST['paged'] : ''; ?>">
<input type="submit" name="search_button" value="Search" id="search_button" class="button-primary">
</form>
<script>
jQuery(document).ready(function($) {
jQuery('.pagination-links a').click(function() {
var action = jQuery(this).attr('href');
if ( action != '' ) {
//jQuery('#emailSearchForm').attr('action', action);
var paged = getParameterByName('paged');
jQuery('#paged').val(paged);
}
jQuery('#emailSearchForm').submit();
});
jQuery( "#emailSearchForm" ).submit(function( event ) {
//alert( "Handler for .submit() called." );
});
});
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
</script>
<?php
// call table here
$obj->prepare_items();
$obj->display();
?>
</div> <!-- end wrap -->
<?php
}
}// end of logs
/**
* This function outputs the plugin options page.
*/
if (!function_exists('wp_pepipost_options_page')) :
// Define the function
function wp_pepipost_options_page() {
// Load the options
global $wpp_options;
global $is_test_mail;
// Send a test mail if necessary
if (isset($_POST['wpp_action']) && $_POST['wpp_action'] == __('Send Test', 'wp_pepipost') && isset($_POST['to'])) {
$to = rtrim(trim($_POST['to']), ",");
$to = ltrim($to, ",");
if ( !filter_var($to, FILTER_VALIDATE_EMAIL) ) { ?>
<div id="login_error" class="error fade"><p>Please enter valid email address.</p></div>
<?php
} else {
check_admin_referer('test-email');
// Set up the mail variables
$subject = !empty($_POST['subject']) ? trim($_POST['subject']) : 'Pepipost: ' . __('Test mail to ', 'wp_pepipost') . $to;
if ( !empty($_POST['message']) )
$message = $_POST['message'];
else
$message = __('This is a test email generated by the WP Pepipost WordPress plugin.', 'wp_pepipost');
$error = '';
try{
// Send the test mail
$is_test_mail = true;
$result = wpp_send_email($to, $subject, $message);
//echo "<pre>";print_r($result);die;
if(!empty($result)&& isset($result['is_error']) && $result['is_error']) {
$error = isset($result['error']) ? $result['error'] : '';
$result = false;
}
} catch ( Exception $e ) {echo 'asdasdas';
$error = new WP_Error( $e->getMessage() );
$result = false;
}
// Output the response
?>
<?php if ( $result ) { ?>
<div id="message" class="updated fade"><p><strong><?php _e('Test Message Sent', 'wp_pepipost'); ?></strong></p>
<?php //var_dump($result);
?>
</div>
<?php } else {
?>
<div id="login_error" class="error fade"><p><strong><?php _e('Error while sending test message.', 'wp_pepipost'); ?></strong></p>
<?php if ( !empty($error) ) {
echo "<p><strong>$error</strong></p>";
} ?>
</div>
<?php } ?>
<?php
}
}//ends else part validations
if( isset($_REQUEST['wp_pepipost_option']) && $_REQUEST['wp_pepipost_option'] == 1 ) {
if ( !empty($_POST['mail_from']) )
update_option( 'wpp_mail_from', trim($_POST['mail_from']));
if ( !empty($_POST['mail_from_name']) )
update_option( 'wpp_mail_from_name', trim($_POST['mail_from_name']));
if ( !empty($_POST['mailer']) )
update_option( 'wpp_mailer', trim($_POST['mailer']));
if ( !empty($_POST['api_key']) )
update_option( 'wpp_api_key', trim($_POST['api_key']));
?>
<div id="message" class="updated fade"><p><strong><?php _e('Settings saved successfully', 'wp_pepipost'); ?></strong></p></div>
<?php
}
?>
<div class="wrap">
<div class="w-logo with_transparent">
<a class="w-logo-link" href="http://www.pepipost.com/">
<span class="w-logo-img">
<img class="for_transparent" src="<?php echo home_url(); ?>/wp-content/plugins/pepipost/images/Pepipost-Png1.png" alt="Pepipost: Cloud Based Triggered and Transactional Email Service">
</span>
</a>
<span class="plugin-text"><h2>Pepipost SMTP Service</h2></span>
<div id="smtp_error" class="dspln"></div>
</div> <!-- end w-logo -->
<form method="post" action="admin.php?page=wp_pepipost">
<?php wp_nonce_field('wpp_email-options', 'email_options_field'); ?>
<table class="optiontable form-table">
<tr valign="top">
<th scope="row"><label for="mail_from"><?php _e('Api Key', 'wp_pepipost'); ?></label></th>
<td><input name="api_key" type="text" id="api_key" value="<?php print(get_option('wpp_api_key')); ?>" size="40" class="regular-text" />
<span class="description"><?php _e('Enter api key here form your pepipost account.', 'wp_pepipost'); if(get_option('db_version') < 6124) { print('<br /><span style="color: red;">'); _e('<strong>Please Note:</strong> You appear to be using a version of WordPress prior to 2.3. Please ignore the From Name field and instead enter Name<email@domain.com> in this field.', 'wp_pepipost'); print('</span>'); } ?></span></td>
</tr>
</table>
<h3><?php _e('Email Settings', 'wp_pepipost'); ?></h3>
<table class="optiontable form-table">
<tr valign="top">
<th scope="row"><label for="mail_from"><?php _e('From Email', 'wp_pepipost'); ?></label></th>
<td><input name="mail_from" type="text" id="mail_from" value="<?php print(get_option('wpp_mail_from')); ?>" size="40" class="regular-text" />
<span class="description"><?php _e('Email address that emails should be sent from.', 'wp_pepipost'); if(get_option('db_version') < 6124) { print('<br /><span style="color: red;">'); _e('<strong>Please Note:</strong> You appear to be using a version of WordPress prior to 2.3. Please ignore the From Name field and instead enter Name<email@domain.com> in this field.', 'wp_pepipost'); print('</span>'); } ?></span></td>
</tr>
<tr valign="top">
<th scope="row"><label for="mail_from_name"><?php _e('From Name', 'wp_pepipost'); ?></label></th>
<td><input name="mail_from_name" type="text" id="mail_from_name" value="<?php print(get_option('wpp_mail_from_name')); ?>" size="40" class="regular-text" />
<span class="description"><?php _e('Name that emails should be sent from.', 'wp_pepipost'); ?></span></td>
</tr>
</table>
<table class="optiontable form-table">
<!--tr valign="top">
<th scope="row"><?php //_e('Mailer', 'wp_pepipost'); ?> </th>
<td><fieldset><legend class="screen-reader-text"><span><?php //_e('Mailer', 'wp_pepipost'); ?></span></legend>
<p><input id="mailer_smtp" type="radio" name="mailer" value="api" <?php //checked('api', get_option('wpp_mailer')); ?> />
<label for="mailer_smtp"><?php //_e('Send all WordPress emails via Pepipost API.', 'wp_pepipost'); ?></label></p>
<p><input id="mailer_mail" type="radio" name="mailer" value="mail" <?php //checked('mail', get_option('wpp_mailer')); ?> />
<label for="mailer_mail"><?php //_e('Use the PHP mail() function to send emails.', 'wp_pepipost'); ?></label></p>
</fieldset></td>
</tr-->
</table>
<p class="submit"><input type="submit" name="submit" id="submit-pepipost" class="button-primary" value="<?php _e('Save Changes'); ?>" /></p>
</p>
<input type="hidden" name="wp_pepipost_option" value="1">
</form>
<h3><?php _e('Send a Test Email', 'wp_pepipost'); ?></h3>
<div id="show_error" class="dspln"></div>
<form method="POST" action="admin.php?page=wp_pepipost<?php //echo plugin_basename(__FILE__); ?>">
<?php wp_nonce_field('test-email'); ?>
<table class="optiontable form-table">
<tr valign="top">
<th scope="row"><label for="to"><?php _e('To:', 'wp_pepipost'); ?></label></th>
<td><input name="to" type="email" id="to" value="" size="40" class="code" required />
<span class="description"><?php _e('Type your email address here.', 'wp_pepipost'); ?></span></td>
</tr>
<tr valign="top">
<th scope="row"><label for="to">Subject</label></th>
<td><input name="subject" type="text" id="subject" value="" size="40" class="code" required />
<span class="description">Type your email subject here.</span></td>
</tr
<tr valign="top">
<th scope="row"><label for="to">Message</label></th>
<td><textarea name="message" id="email_message" class="code" required></textarea>
<span class="description">Type your message here.</span></td>
</tr>
</table>
<p class="submit"><input type="submit" name="wpp_action" id="wpp_action" class="button-primary" value="<?php _e('Send Test', 'wp_pepipost'); ?>" /></p>
</form>
</div> <!-- end wrap -->
<?php
} // End of wp_pepipost_options_page() function definition
endif;
/**
* Stats function to show all statistics data
* fetched using pepipost api
*/
if (!function_exists('wp_pepipost_stats')) {
function wp_pepipost_stats() {
//create the object for class, if not exits
if ( !isset($obj) )
$obj = new Logs();
?>
<div class="wrap">
<!-- Display common html strucure -->
<?php echo $obj->common_html(); ?>
<br>
<h2><?php _e('Pepipost Reports', 'wp_peipost'); ?></h2>
<?php
$date = date("d M, Y");
$start_date = date('Y-m-d');
$end_date = date('Y-m-d');
$get_stats = $obj->get_stats( $start_date, $end_date );
$today_data = isset($get_stats['data']) ? $get_stats['data'] : array();
if ( isset($_POST['dateRangeFormSubmit']) && !empty($_POST['dateRangeFormSubmit']) ) {
$start_date = date('Y-m-d', strtotime($_POST['wpp_from_date']));
$end_date = date('Y-m-d', strtotime($_POST['wpp_to_date']));
} else {
$start_date = date('Y-m-01');
$end_date = date('Y-m-t');
}
$get_stats = $obj->get_stats( $start_date, $end_date );
$monthly_data = isset($get_stats['data']) ? $get_stats['data'] : array();
$monthly_sent = 0;
$monthly_bounce = 0;
$monthly_open = 0;
$monthly_click = 0;
$monthly_dropped = 0;
$monthly_invalid = 0;
if ( !empty($monthly_data) && is_array($monthly_data) ) {
foreach ( $monthly_data as $monthly ) {
$monthly_sent += $monthly['sent'];
$monthly_bounce += $monthly['bounce'];
$monthly_open += $monthly['open'];
$monthly_click += $monthly['click'];
$monthly_dropped += $monthly['dropped'];
$monthly_invalid += $monthly['invalid'];
}
}
$max_days = date('t');
$data = array();
for( $i=0; $i<$max_days; $i++ ) {
$data[] = array( 'y' => $monthly_data[$i], 'label' => $monthly_data[$i] );
}
?>
<h4>Report for <?php echo $date; ?></h4>
<script type="text/javascript">
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer",
{
animationEnabled: true,
title:{
text: ""
},
axisX: {
title: "<?php echo $date; ?>",
},
data: [
{
type: "column", //change type to bar, line, area, pie, etc
indexLabel: "{y}",
indexLabelPlacement: "outside",
indexLabelOrientation: "horizontal",
dataPoints: [
{ y: <?php echo $today_data[0]['sent']; ?>, label: "Delivered" },
{ y: <?php echo $today_data[0]['bounce']; ?>, label: "Bounced"},
{ y: <?php echo $today_data[0]['open']; ?> , label: "Opened"},
{ y: <?php echo $today_data[0]['click']; ?>, label: "Clicked" },
{ y: <?php echo $today_data[0]['dropped']; ?>, label: "Dropped" },
{ y: <?php echo $today_data[0]['invalid']; ?>, label: "Invalid"}
]
}
]
});
chart.render();
//Second chart
var chart = new CanvasJS.Chart("chartContainerSec",
{
animationEnabled: true,
title:{
text: ""
},
axisX: {
title: "<?php echo date('d M', strtotime($start_date)); echo ' - ';echo date('d M, Y', strtotime($end_date)); ?>",
},
data: [
{
type: "column", //change type to bar, line, area, pie, etc
indexLabel: "{y}",
indexLabelPlacement: "outside",
indexLabelOrientation: "horizontal",
dataPoints: [
{ y: <?php echo $monthly_sent; ?>, label: "Delivered" },
{ y: <?php echo $monthly_bounce; ?>, label: "Bounced"},
{ y: <?php echo $monthly_open; ?> , label: "Opened"},
{ y: <?php echo $monthly_click; ?>, label: "Clicked" },
{ y: <?php echo $monthly_dropped; ?>, label: "Dropped" },
{ y: <?php echo $monthly_invalid; ?>, label: "Invalid"}
]
}
]
});
chart.render();
}
</script>
<div id="chartContainer" style="height: 300px; width: 100%;"></div>
<div class="clear"></div>
<?php if ( isset($_POST['dateRangeFormSubmit']) && !empty($_POST['dateRangeFormSubmit']) ) { ?>
<script>
jQuery(document).ready(function() {
jQuery('#from_date').val( "<?php echo date( 'm/d/Y', strtotime($start_date) ); ?>" );
jQuery('#to_date').val( "<?php echo date( 'm/d/Y',strtotime($end_date) ); ?>" );
});
</script>
<?php } ?>
<div id="dateRangeDiv"><h4>From <?php echo date('d M, Y', strtotime($start_date)); ?> to <?php echo date('d M, Y', strtotime($end_date)); ?></h4>
<form id="dateRangeForm" method="post" action="admin.php?page=wp_pepipost_stats">
<?php wp_nonce_field('wpp_from_to', 'wpp_from_to_field'); ?>
<label for="from">From</label>
<input type="text" id="from_date" name="wpp_from_date">
<label for="to">to</label>
<input type="text" id="to_date" name="wpp_to_date">
<input type="hidden" name="dateRangeFormSubmit" value="1">
</form>
</div>
<div id="chartContainerSec" style="height: 300px; width: 100%;"></div>
<h3><a href="http://app1.pepipost.com/" target="_blank">For detailed statistics, please visit your Pepipost Dashboard</a>.</h3>
</div> <!-- end wrap -->
<?php
}
}// end of stats