Email Log - Version 0.1

Version Description

Download this release

Release Info

Developer sudar
Plugin Icon 128x128 Email Log
Version 0.1
Comparing to
See all releases

Version 0.1

email-log.php ADDED
@@ -0,0 +1,568 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ Plugin Name: Email Log
4
+ Plugin URI: http://sudarmuthu.com/wordpress/email-log
5
+ Description: Logs every email sent through WordPress. Compatiable with WPMU too.
6
+ Author: Sudar
7
+ Version: 0.1
8
+ Author URI: http://sudarmuthu.com/
9
+ Text Domain: email-log
10
+
11
+ === RELEASE NOTES ===
12
+ 2009-10-08 – v0.1 – Initial Release
13
+ */
14
+
15
+ global $wpdb;
16
+ global $smel_table_name;
17
+ $smel_table_name = $wpdb->prefix . "email_log";
18
+
19
+ // TODO - Should find some way to get away with these global variables.
20
+ global $smel_db_version;
21
+ $smel_db_version = "0.1";
22
+
23
+ class EmailLog {
24
+
25
+ private $table_name ; /* Database table name */
26
+ private $db_version ; /* Database version */
27
+
28
+ /**
29
+ * Initalize the plugin by registering the hooks
30
+ */
31
+ function __construct() {
32
+
33
+ global $wpdb;
34
+ global $smel_table_name;
35
+ global $smel_db_version;
36
+
37
+ // Load localization domain
38
+ load_plugin_textdomain( 'email-log', false, dirname(plugin_basename(__FILE__)) . '/languages' );
39
+
40
+ // Register hooks
41
+ add_action( 'admin_menu', array(&$this, 'register_settings_page') );
42
+
43
+ // Register Filter
44
+ add_filter('wp_mail', array(&$this, 'log_email'));
45
+
46
+ $plugin = plugin_basename(__FILE__);
47
+ add_filter("plugin_action_links_$plugin", array(&$this, 'add_action_links'));
48
+
49
+ // Initialize Variables
50
+ $this->table_name = $smel_table_name;
51
+ $this->db_version = $smel_db_version;
52
+ }
53
+
54
+ /**
55
+ * Register the settings page
56
+ */
57
+ function register_settings_page() {
58
+ add_options_page( __('Email Log', 'email-log'), __('Email Log', 'email-log'), 8, 'email-log', array(&$this, 'settings_page') );
59
+ }
60
+
61
+ /**
62
+ * hook to add action links
63
+ *
64
+ * @param <type> $links
65
+ * @return <type>
66
+ */
67
+ function add_action_links( $links ) {
68
+ // Add a link to this plugin's settings page
69
+ $settings_link = '<a href="options-general.php?page=email-log">' . __("Settings", 'email-log') . '</a>';
70
+ array_unshift( $links, $settings_link );
71
+ return $links;
72
+ }
73
+
74
+ /**
75
+ * Adds Footer links. Based on http://striderweb.com/nerdaphernalia/2008/06/give-your-wordpress-plugin-credit/
76
+ */
77
+ function add_footer_links() {
78
+ $plugin_data = get_plugin_data( __FILE__ );
79
+ printf('%1$s ' . __("plugin", 'email-log') .' | ' . __("Version", 'email-log') . ' %2$s | '. __('by', 'email-log') . ' %3$s<br />', $plugin_data['Title'], $plugin_data['Version'], $plugin_data['Author']);
80
+ }
81
+
82
+ /**
83
+ * Dipslay the Settings page
84
+ *
85
+ * Some parts of this function is based on the wp-rattings Plugin http://wordpress.org/extend/plugins/email-log/
86
+ */
87
+ function settings_page() {
88
+ global $wpdb;
89
+ global $text_direction;
90
+
91
+ $base_name = plugin_basename('email-log');
92
+ $base_page = 'admin.php?page='.$base_name;
93
+
94
+ $email_log_page = intval($_GET['emaillog_page']);
95
+ $emaillogs_filterid = trim(addslashes($_GET['id']));
96
+ $emaillogs_filter_to_email = trim(addslashes($_GET['to_email']));
97
+ $emaillogs_filter_subject = trim(addslashes($_GET['subject']));
98
+ $emaillog_sort_by = trim($_GET['by']);
99
+ $emaillog_sortby_text = '';
100
+ $emaillog_sortorder = trim($_GET['order']);
101
+ $emaillog_sortorder_text = '';
102
+ $email_log_perpage = intval($_GET['perpage']);
103
+ $emaillog_sort_url = '';
104
+
105
+ ### Form Processing
106
+ if(!empty($_POST['do'])) {
107
+ // Decide What To Do
108
+ switch($_POST['do']) {
109
+ case __('Delete Logs', 'email-log'):
110
+ $delete_datalog = intval($_POST['delete_datalog']);
111
+ switch($delete_datalog) {
112
+ case 1:
113
+ // Delete based on condition
114
+ $to_email = trim(addslashes( $_POST['delete_to_email']));
115
+ if ('' != $to_email) {
116
+ $delete_logs = $wpdb->query("DELETE FROM $this->table_name where to_email = '$to_email'");
117
+ if($delete_logs) {
118
+ $text = '<font color="green">'.sprintf(__('All Email Logs For email id %s Have Been Deleted.', 'email-log'), $to_email).'</font>';
119
+ } else {
120
+ $text = '<font color="red">'.sprintf(__('An Error Has Occured while deleting All Email Logs For email id %s.', 'email-log'), $to_email).'</font>';
121
+ }
122
+ }
123
+
124
+ $subject = trim(addslashes( $_POST['delete_subject']));
125
+ if ('' != $subject) {
126
+ $delete_logs = $wpdb->query("DELETE FROM $this->table_name where subject = '$subject'");
127
+ if($delete_logs) {
128
+ $text .= '<font color="green">'.sprintf(__('All Email Logs With Subject %s Have Been Deleted.', 'email-log'), $subject).'</font>';
129
+ } else {
130
+ $text .= '<font color="red">'.sprintf(__('An Error Has Occured While Deleting All Email Logs With Subject %s.', 'email-log'), $subject).'</font>';
131
+ }
132
+ }
133
+ break;
134
+ case 2:
135
+ // Delete all
136
+ $delete_logs = $wpdb->query("DELETE FROM $this->table_name ");
137
+ if ($delete_logs) {
138
+ $text = '<font color="green">'.__('All Email log Has Been Deleted.', 'email-log').'</font><br />';
139
+ } else {
140
+ $text = '<font color="red">'.__('An Error Has Occured While Deleting All Email Logs', 'email-log').'</font>';
141
+ }
142
+ break;
143
+ }
144
+ break;
145
+ }
146
+ }
147
+
148
+ ### Form Sorting URL
149
+ if(!empty($emaillogs_filterid)) {
150
+ $emaillogs_filterid = intval($emaillogs_filterid);
151
+ $emaillog_sort_url .= '&amp;id='.$emaillogs_filterid;
152
+ }
153
+ if(!empty($emaillogs_filter_to_email)) {
154
+ $emaillog_sort_url .= '&amp;to_email='.$emaillogs_filter_to_email;
155
+ }
156
+ if(!empty($emaillogs_filter_subject)) {
157
+ $emaillog_sort_url .= '&amp;subject='.$emaillogs_filter_subject;
158
+ }
159
+ if(!empty($emaillog_sort_by)) {
160
+ $emaillog_sort_url .= '&amp;by='.$emaillog_sort_by;
161
+ }
162
+ if(!empty($emaillog_sortorder)) {
163
+ $emaillog_sort_url .= '&amp;order='.$emaillog_sortorder;
164
+ }
165
+ if(!empty($email_log_perpage)) {
166
+ $email_log_perpage = intval($email_log_perpage);
167
+ $emaillog_sort_url .= '&amp;perpage='.$email_log_perpage;
168
+ }
169
+
170
+ ### Get Order By
171
+ switch($emaillog_sort_by) {
172
+ case 'id':
173
+ $emaillog_sort_by = 'id';
174
+ $emaillog_sortby_text = __('ID', 'email-log');
175
+ break;
176
+ case 'to_email':
177
+ $emaillog_sort_by = 'to_email';
178
+ $emaillog_sortby_text = __('To Email', 'email-log');
179
+ break;
180
+ case 'subject':
181
+ $emaillog_sort_by = 'subject';
182
+ $emaillog_sortby_text = __('Subject', 'email-log');
183
+ break;
184
+ case 'date':
185
+ default:
186
+ $emaillog_sort_by = 'sent_date';
187
+ $emaillog_sortby_text = __('Date', 'email-log');
188
+ }
189
+
190
+ ### Get Sort Order
191
+ switch($emaillog_sortorder) {
192
+ case 'asc':
193
+ $emaillog_sortorder = 'ASC';
194
+ $emaillog_sortorder_text = __('Ascending', 'email-log');
195
+ break;
196
+ case 'desc':
197
+ default:
198
+ $emaillog_sortorder = 'DESC';
199
+ $emaillog_sortorder_text = __('Descending', 'email-log');
200
+ }
201
+
202
+ // Where
203
+ $emaillog_where = '';
204
+ if(!empty($emaillogs_filterid)) {
205
+ $emaillog_where = "AND id =$emaillogs_filterid";
206
+ }
207
+ if(!empty($emaillogs_filter_to_email)) {
208
+ $emaillog_where .= " AND to_email like '%$emaillogs_filter_to_email%'";
209
+ }
210
+ if(!empty($emaillogs_filter_subject)) {
211
+ $emaillog_where .= " AND subject like '%$emaillogs_filter_subject%'";
212
+ }
213
+
214
+ // Get email Logs Data
215
+ $total_logs = $wpdb->get_var("SELECT COUNT(id) FROM $this->table_name WHERE 1=1 $emaillog_where");
216
+
217
+ // Checking $postratings_page and $offset
218
+ if(empty($email_log_page) || $email_log_page == 0) { $email_log_page = 1; }
219
+ if(empty($offset)) { $offset = 0; }
220
+ if(empty($email_log_perpage) || $email_log_perpage == 0) { $email_log_perpage = 20; }
221
+
222
+ // Determin $offset
223
+ $offset = ($email_log_page-1) * $email_log_perpage;
224
+
225
+ // Determine Max Number Of Logs To Display On Page
226
+ if(($offset + $email_log_perpage) > $total_logs) {
227
+ $max_on_page = $total_logs;
228
+ } else {
229
+ $max_on_page = ($offset + $email_log_perpage);
230
+ }
231
+
232
+ // Determine Number Of Logs To Display On Page
233
+ if (($offset + 1) > ($total_logs)) {
234
+ $display_on_page = $total_logs;
235
+ } else {
236
+ $display_on_page = ($offset + 1);
237
+ }
238
+
239
+ // Determing Total Amount Of Pages
240
+ $total_pages = ceil($total_logs / $email_log_perpage);
241
+
242
+ // Get The Logs
243
+ $email_logs = $wpdb->get_results("SELECT * FROM $this->table_name WHERE 1=1 $emaillog_where ORDER BY $emaillog_sort_by $emaillog_sortorder LIMIT $offset, $email_log_perpage");
244
+ ?>
245
+ <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
246
+ <div class="wrap">
247
+ <?php screen_icon(); ?>
248
+ <h2><?php _e( 'Email Log Settings', 'email-log' ); ?></h2>
249
+ <p><?php printf(__('Displaying <strong>%s</strong> to <strong>%s</strong> of <strong>%s</strong> Email log entries.', 'email-log'), number_format_i18n($display_on_page), number_format_i18n($max_on_page), number_format_i18n($total_logs)); ?></p>
250
+ <p><?php printf(__('Sorted by <strong>%s</strong> in <strong>%s</strong> order.', 'email-log'), $emaillog_sortby_text, $emaillog_sortorder_text); ?></p>
251
+
252
+ <?php
253
+ if($total_pages > 1) {
254
+ ?>
255
+ <br />
256
+ <table class="widefat">
257
+ <tr>
258
+ <td align="<?php echo ('rtl' == $text_direction) ? 'right' : 'left'; ?>" width="40%">
259
+ <?php
260
+ if($email_log_page > 1 && ((($email_log_page*$email_log_perpage)-($email_log_perpage-1)) <= $total_logs)) {
261
+ echo '<strong>&laquo;</strong> <a href="'.$base_page.'&amp;emaillog_page='.($email_log_page-1).$emaillog_sort_url.'" title="&laquo; '.__('Previous Page', 'email-log').'">'.__('Previous Page', 'email-log').'</a>';
262
+ } else {
263
+ echo '&nbsp;';
264
+ }
265
+ ?>
266
+ </td>
267
+ <td align="center" width="20%">
268
+ <?php printf(__('Pages (%s): ', 'email-log'), number_format_i18n($total_pages)); ?>
269
+ <?php
270
+ if ($email_log_page >= 4) {
271
+ echo '<strong><a href="'.$base_page.'&amp;emaillog_page=1'.$emaillog_sort_url.$emaillog_sort_url.'" title="'.__('Go to First Page', 'email-log').'">&laquo; '.__('First', 'email-log').'</a></strong> ... ';
272
+ }
273
+ if($email_log_page > 1) {
274
+ echo ' <strong><a href="'.$base_page.'&amp;emaillog_page='.($email_log_page-1).$emaillog_sort_url.'" title="&laquo; '.__('Go to Page', 'email-log').' '.number_format_i18n($email_log_page-1).'">&laquo;</a></strong> ';
275
+ }
276
+ for($i = $email_log_page - 2 ; $i <= $email_log_page +2; $i++) {
277
+ if ($i >= 1 && $i <= $total_pages) {
278
+ if($i == $email_log_page) {
279
+ echo '<strong>['.number_format_i18n($i).']</strong> ';
280
+ } else {
281
+ echo '<a href="'.$base_page.'&amp;emaillog_page='.($i).$emaillog_sort_url.'" title="'.__('Page', 'email-log').' '.number_format_i18n($i).'">'.number_format_i18n($i).'</a> ';
282
+ }
283
+ }
284
+ }
285
+ if($email_log_page < $total_pages) {
286
+ echo ' <strong><a href="'.$base_page.'&amp;emaillog_page='.($email_log_page+1).$emaillog_sort_url.'" title="'.__('Go to Page', 'email-log').' '.number_format_i18n($email_log_page+1).' &raquo;">&raquo;</a></strong> ';
287
+ }
288
+ if (($email_log_page+2) < $total_pages) {
289
+ echo ' ... <strong><a href="'.$base_page.'&amp;emaillog_page='.($total_pages).$emaillog_sort_url.'" title="'.__('Go to Last Page', 'email-log').'">'.__('Last', 'email-log').' &raquo;</a></strong>';
290
+ }
291
+ ?>
292
+ </td>
293
+ <td align="<?php echo ('rtl' == $text_direction) ? 'left' : 'right'; ?>" width="40%">
294
+ <?php
295
+ if($email_log_page >= 1 && ((($email_log_page*$email_log_perpage)+1) <= $total_logs)) {
296
+ echo '<a href="'.$base_page.'&amp;emaillog_page='.($email_log_page+1).$emaillog_sort_url.'" title="'.__('Next Page', 'email-log').' &raquo;">'.__('Next Page', 'email-log').'</a> <strong>&raquo;</strong>';
297
+ } else {
298
+ echo '&nbsp;';
299
+ }
300
+ ?>
301
+ </td>
302
+ </tr>
303
+ </table>
304
+ <!-- </Paging> -->
305
+ <?php
306
+ }
307
+ ?>
308
+ <table class="widefat">
309
+ <thead>
310
+ <tr>
311
+ <th width="5%"><?php _e('ID', 'email-log'); ?></th>
312
+ <th width="20%"><?php _e('Date / Time', 'email-log'); ?></th>
313
+ <th width="30%"><?php _e('To', 'email-log'); ?></th>
314
+ <th width="45%"><?php _e('Subject', 'email-log'); ?></th>
315
+ </tr>
316
+ </thead>
317
+ <tbody>
318
+ <?php
319
+ if($email_logs) {
320
+ $i = 0;
321
+ foreach($email_logs as $email_log) {
322
+ if($i%2 == 0) {
323
+ $style = 'class="alternate"';
324
+ } else {
325
+ $style = '';
326
+ }
327
+ $email_id = intval($email_log->id);
328
+ $email_date = mysql2date(sprintf(__('%s @ %s', 'email-log'), get_option('date_format'), get_option('time_format')), $email_log->sent_date);
329
+ $email_to = stripslashes($email_log->to_email);
330
+ $email_subject = stripslashes($email_log->subject);
331
+ echo "<tr $style>\n";
332
+ echo '<td>'.$email_id.'</td>'."\n";
333
+ echo "<td>$email_date</td>\n";
334
+ echo "<td>$email_to</td>\n";
335
+ echo "<td>$email_subject</td>\n";
336
+ echo '</tr>';
337
+ $i++;
338
+ }
339
+ } else {
340
+ echo '<tr><td colspan="7" align="center"><strong>'.__('No email Logs Found', 'email-log').'</strong></td></tr>';
341
+ }
342
+ ?>
343
+ </tbody>
344
+ <tfoot>
345
+ <tr>
346
+ <th width="5%"><?php _e('ID', 'email-log'); ?></th>
347
+ <th width="20%"><?php _e('Date / Time', 'email-log'); ?></th>
348
+ <th width="30%"><?php _e('To', 'email-log'); ?></th>
349
+ <th width="45%"><?php _e('Subject', 'email-log'); ?></th>
350
+ </tr>
351
+ </tfoot>
352
+ </table>
353
+ <?php
354
+ if($total_pages > 1) {
355
+ ?>
356
+ <table class="widefat">
357
+ <tr>
358
+ <td align="<?php echo ('rtl' == $text_direction) ? 'right' : 'left'; ?>" width="40%">
359
+ <?php
360
+ if($email_log_page > 1 && ((($email_log_page*$email_log_perpage)-($email_log_perpage-1)) <= $total_logs)) {
361
+ echo '<strong>&laquo;</strong> <a href="'.$base_page.'&amp;emaillog_page='.($email_log_page-1).$emaillog_sort_url.'" title="&laquo; '.__('Previous Page', 'email-log').'">'.__('Previous Page', 'email-log').'</a>';
362
+ } else {
363
+ echo '&nbsp;';
364
+ }
365
+ ?>
366
+ </td>
367
+ <td align="center" width="20%">
368
+ <?php printf(__('Pages (%s): ', 'email-log'), number_format_i18n($total_pages)); ?>
369
+ <?php
370
+ if ($email_log_page >= 4) {
371
+ echo '<strong><a href="'.$base_page.'&amp;emaillog_page=1'.$emaillog_sort_url.$emaillog_sort_url.'" title="'.__('Go to First Page', 'email-log').'">&laquo; '.__('First', 'email-log').'</a></strong> ... ';
372
+ }
373
+ if($email_log_page > 1) {
374
+ echo ' <strong><a href="'.$base_page.'&amp;emaillog_page='.($email_log_page-1).$emaillog_sort_url.'" title="&laquo; '.__('Go to Page', 'email-log').' '.number_format_i18n($email_log_page-1).'">&laquo;</a></strong> ';
375
+ }
376
+ for($i = $email_log_page - 2 ; $i <= $email_log_page +2; $i++) {
377
+ if ($i >= 1 && $i <= $total_pages) {
378
+ if($i == $email_log_page) {
379
+ echo '<strong>['.number_format_i18n($i).']</strong> ';
380
+ } else {
381
+ echo '<a href="'.$base_page.'&amp;emaillog_page='.($i).$emaillog_sort_url.'" title="'.__('Page', 'email-log').' '.number_format_i18n($i).'">'.number_format_i18n($i).'</a> ';
382
+ }
383
+ }
384
+ }
385
+ if($email_log_page < $total_pages) {
386
+ echo ' <strong><a href="'.$base_page.'&amp;emaillog_page='.($email_log_page+1).$emaillog_sort_url.'" title="'.__('Go to Page', 'email-log').' '.number_format_i18n($email_log_page+1).' &raquo;">&raquo;</a></strong> ';
387
+ }
388
+ if (($email_log_page+2) < $total_pages) {
389
+ echo ' ... <strong><a href="'.$base_page.'&amp;emaillog_page='.($total_pages).$emaillog_sort_url.'" title="'.__('Go to Last Page', 'email-log').'">'.__('Last', 'email-log').' &raquo;</a></strong>';
390
+ }
391
+ ?>
392
+ </td>
393
+ <td align="<?php echo ('rtl' == $text_direction) ? 'left' : 'right'; ?>" width="40%">
394
+ <?php
395
+ if($email_log_page >= 1 && ((($email_log_page*$email_log_perpage)+1) <= $total_logs)) {
396
+ echo '<a href="'.$base_page.'&amp;emaillog_page='.($email_log_page+1).$emaillog_sort_url.'" title="'.__('Next Page', 'email-log').' &raquo;">'.__('Next Page', 'email-log').'</a> <strong>&raquo;</strong>';
397
+ } else {
398
+ echo '&nbsp;';
399
+ }
400
+ ?>
401
+ </td>
402
+ </tr>
403
+ <tr class="alternate">
404
+ </tr>
405
+ </table>
406
+ <!-- </Paging> -->
407
+ <?php
408
+ }
409
+ ?>
410
+ <br />
411
+
412
+ <form action="<?php echo esc_url($_SERVER['PHP_SELF']); ?>" method="get">
413
+ <input type="hidden" name="page" value="<?php echo $base_name; ?>" />
414
+ <table class="widefat">
415
+ <tr>
416
+ <th><?php _e('Filter Options:', 'email-log'); ?></th>
417
+ <td>
418
+ <?php _e('ID:', 'email-log'); ?>&nbsp;<input type="text" name="id" value="<?php echo $emaillogs_filterid; ?>" size="5" maxlength="5" />
419
+ &nbsp;&nbsp;&nbsp;
420
+ <?php _e('To Email:', 'email-log'); ?>&nbsp;<input type="text" name="to_email" value="<?php echo $emaillogs_filter_to_email; ?>" size="40" maxlength="50" />
421
+ &nbsp;&nbsp;&nbsp;
422
+ <?php _e('Subject:', 'email-log'); ?>&nbsp;<input type="text" name="subject" value="<?php echo $emaillogs_filter_subject; ?>" size="40" maxlength="50" />
423
+ &nbsp;&nbsp;&nbsp;
424
+ </td>
425
+ </tr>
426
+ <tr class="alternate">
427
+ <th><?php _e('Sort Options:', 'email-log'); ?></th>
428
+ <td>
429
+ <select name="by" size="1">
430
+ <option value="id"<?php if($emaillog_sort_by == 'id') { echo ' selected="selected"'; }?>><?php _e('ID', 'email-log'); ?></option>
431
+ <option value="to_email"<?php if($emaillog_sort_by == 'to_email') { echo ' selected="selected"'; }?>><?php _e('To Email', 'email-log'); ?></option>
432
+ <option value="subject"<?php if($emaillog_sort_by == 'subject') { echo ' selected="selected"'; }?>><?php _e('Subject', 'email-log'); ?></option>
433
+ <option value="sent_date"<?php if($emaillog_sort_by == 'sent_date') { echo ' selected="selected"'; }?>><?php _e('Date', 'email-log'); ?></option>
434
+ </select>
435
+ &nbsp;&nbsp;&nbsp;
436
+ <select name="order" size="1">
437
+ <option value="asc"<?php if($emaillog_sortorder == 'ASC') { echo ' selected="selected"'; }?>><?php _e('Ascending', 'email-log'); ?></option>
438
+ <option value="desc"<?php if($emaillog_sortorder == 'DESC') { echo ' selected="selected"'; } ?>><?php _e('Descending', 'email-log'); ?></option>
439
+ </select>
440
+ &nbsp;&nbsp;&nbsp;
441
+ <select name="perpage" size="1">
442
+ <?php
443
+ for($i=10; $i <= 100; $i+=10) {
444
+ if($email_log_perpage == $i) {
445
+ echo "<option value=\"$i\" selected=\"selected\">".__('Per Page', 'email-log').": ".number_format_i18n($i)."</option>\n";
446
+ } else {
447
+ echo "<option value=\"$i\">".__('Per Page', 'email-log').": ".number_format_i18n($i)."</option>\n";
448
+ }
449
+ }
450
+ ?>
451
+ </select>
452
+ </td>
453
+ </tr>
454
+ <tr>
455
+ <td colspan="2" align="center"><input type="submit" value="<?php _e('Go', 'email-log'); ?>" class="button" /></td>
456
+ </tr>
457
+ </table>
458
+ </form>
459
+ </div>
460
+ <p>&nbsp;</p>
461
+ <!-- Delete Email Logs -->
462
+ <div class="wrap">
463
+ <h3><?php _e('Delete Logs', 'email-log'); ?></h3>
464
+ <br style="clear" />
465
+ <div align="center">
466
+ <form method="post" action="<?php echo esc_url($_SERVER['PHP_SELF']); ?>?page=<?php echo $base_name; ?>">
467
+ <table class="widefat">
468
+ <tr>
469
+ <td valign="top"><b><?php _e('Delete Type : ', 'email-log'); ?></b></td>
470
+ <td valign="top">
471
+ <select size="1" name="delete_datalog">
472
+ <option value="1"><?php _e('Based on', 'email-log'); ?></option>
473
+ <option value="2"><?php _e('All Logs', 'email-log'); ?></option>
474
+ </select>
475
+ </td>
476
+ </tr>
477
+ <tr>
478
+ <td valign="top"><b><?php _e('Condition:', 'email-log'); ?></b></td>
479
+ <td valign="top">
480
+ <label for ="delete_to_email"><?php _e('To Email', 'email-log');?> <input type="text" name="delete_to_email" size="20" dir="ltr" /></label>
481
+ <?php _e('or', 'email-log');?>
482
+ <label for ="delete_subject"><?php _e('Subject', 'email-log');?> <input type="text" name="delete_subject" size="20" dir="ltr" /></label>
483
+ </td>
484
+ </tr>
485
+ <tr>
486
+ <td colspan="2" align="center">
487
+ <input type="submit" name="do" value="<?php _e('Delete Logs', 'email-log'); ?>" class="button" onclick="return confirm('<?php _e('You Are About To Delete Email Logs.\nThis Action Is Not Reversible.\n\n Choose \\\'Cancel\\\' to stop, \\\'OK\\\' to delete.', 'email-log'); ?>')" />
488
+ </td>
489
+ </tr>
490
+ </table>
491
+ </form>
492
+ </div>
493
+ </div>
494
+ <?php
495
+ // Display credits in Footer
496
+ add_action( 'in_admin_footer', array(&$this, 'add_footer_links'));
497
+ }
498
+
499
+ /**
500
+ * Log all email to database
501
+ *
502
+ * @global object $wpdb
503
+ * @param array $mail_info Information about email
504
+ * @return array Information about email
505
+ */
506
+ function log_email($mail_info) {
507
+
508
+ global $wpdb;
509
+
510
+ // Log into the database
511
+ $wpdb->insert($this->table_name, array(
512
+ 'to_email' => $mail_info['to'],
513
+ 'subject' => $mail_info['subject'],
514
+ 'message' => $mail_info['message'],
515
+ 'headers' => $mail_info['headers'],
516
+ 'attachments' => $mail_info['attachments']
517
+ ));
518
+
519
+ // return unmodifiyed array
520
+ return $mail_info;
521
+ }
522
+
523
+ // PHP4 compatibility
524
+ function EmailLog() {
525
+ $this->__construct();
526
+ }
527
+ }
528
+
529
+ /**
530
+ * Create database table when the Plugin is installed for the first time
531
+ *
532
+ * @global object $wpdb
533
+ * @global string $smel_table_name Table Name
534
+ * @global string $smel_db_version DB Version
535
+ */
536
+ function smel_on_install() {
537
+
538
+ global $wpdb;
539
+ global $smel_table_name;
540
+ global $smel_db_version;
541
+
542
+ if($wpdb->get_var("show tables like '{$smel_table_name}'") != $smel_table_name) {
543
+
544
+ $sql = "CREATE TABLE " . $smel_table_name . " (
545
+ id mediumint(9) NOT NULL AUTO_INCREMENT,
546
+ to_email VARCHAR(100) NOT NULL,
547
+ subject VARCHAR(300) NOT NULL,
548
+ message VARCHAR(5000) NOT NULL,
549
+ headers VARCHAR(500) NOT NULL,
550
+ attachments VARCHAR(500) NOT NULL,
551
+ sent_date timestamp default CURRENT_TIMESTAMP,
552
+ UNIQUE KEY id (id)
553
+ );";
554
+
555
+ require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
556
+ dbDelta($sql);
557
+
558
+ add_option("email-log-db", $smel_db_version);
559
+ }
560
+ }
561
+
562
+ // When installed
563
+ register_activation_hook(__FILE__, 'smel_on_install');
564
+
565
+ // Start this plugin once all other plugins are fully loaded
566
+ add_action( 'init', 'EmailLog' ); function EmailLog() { global $EmailLog; $EmailLog = new EmailLog(); }
567
+
568
+ ?>
languages/email-log.pot ADDED
@@ -0,0 +1,236 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR Sudar
3
+ # This file is distributed under the same license as the PACKAGE package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: Email Log 0.1\n"
10
+ "Report-Msgid-Bugs-To: http://wordpress.org/tag/email-log\n"
11
+ "POT-Creation-Date: 2009-10-08 17:51+0000\n"
12
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
+ "Language-Team: LANGUAGE <LL@li.org>\n"
15
+ "MIME-Version: 1.0\n"
16
+ "Content-Type: text/plain; charset=CHARSET\n"
17
+ "Content-Transfer-Encoding: 8bit\n"
18
+
19
+ #. #-#-#-#-# email-log.pot (Email Log 0.1) #-#-#-#-#
20
+ #. Plugin Name of an extension
21
+ #: email-log.php:58
22
+ msgid "Email Log"
23
+ msgstr ""
24
+
25
+ #: email-log.php:69
26
+ msgid "Settings"
27
+ msgstr ""
28
+
29
+ #: email-log.php:79
30
+ msgid "plugin"
31
+ msgstr ""
32
+
33
+ #: email-log.php:79
34
+ msgid "Version"
35
+ msgstr ""
36
+
37
+ #: email-log.php:79
38
+ msgid "by"
39
+ msgstr ""
40
+
41
+ #: email-log.php:109 email-log.php:463 email-log.php:487
42
+ msgid "Delete Logs"
43
+ msgstr ""
44
+
45
+ #: email-log.php:118
46
+ #, php-format
47
+ msgid "All Email Logs For email id %s Have Been Deleted."
48
+ msgstr ""
49
+
50
+ #: email-log.php:120
51
+ #, php-format
52
+ msgid "An Error Has Occured while deleting All Email Logs For email id %s."
53
+ msgstr ""
54
+
55
+ #: email-log.php:128
56
+ #, php-format
57
+ msgid "All Email Logs With Subject %s Have Been Deleted."
58
+ msgstr ""
59
+
60
+ #: email-log.php:130
61
+ #, php-format
62
+ msgid "An Error Has Occured While Deleting All Email Logs With Subject %s."
63
+ msgstr ""
64
+
65
+ #: email-log.php:138
66
+ msgid "All Email log Has Been Deleted."
67
+ msgstr ""
68
+
69
+ #: email-log.php:140
70
+ msgid "An Error Has Occured While Deleting All Email Logs"
71
+ msgstr ""
72
+
73
+ #: email-log.php:174 email-log.php:311 email-log.php:346 email-log.php:430
74
+ msgid "ID"
75
+ msgstr ""
76
+
77
+ #: email-log.php:178 email-log.php:431 email-log.php:480
78
+ msgid "To Email"
79
+ msgstr ""
80
+
81
+ #: email-log.php:182 email-log.php:314 email-log.php:349 email-log.php:432
82
+ #: email-log.php:482
83
+ msgid "Subject"
84
+ msgstr ""
85
+
86
+ #: email-log.php:187 email-log.php:433
87
+ msgid "Date"
88
+ msgstr ""
89
+
90
+ #: email-log.php:194 email-log.php:437
91
+ msgid "Ascending"
92
+ msgstr ""
93
+
94
+ #: email-log.php:199 email-log.php:438
95
+ msgid "Descending"
96
+ msgstr ""
97
+
98
+ #: email-log.php:248
99
+ msgid "Email Log Settings"
100
+ msgstr ""
101
+
102
+ #: email-log.php:249
103
+ #, php-format
104
+ msgid ""
105
+ "Displaying <strong>%s</strong> to <strong>%s</strong> of <strong>%s</strong> "
106
+ "Email log entries."
107
+ msgstr ""
108
+
109
+ #: email-log.php:250
110
+ #, php-format
111
+ msgid "Sorted by <strong>%s</strong> in <strong>%s</strong> order."
112
+ msgstr ""
113
+
114
+ #: email-log.php:261 email-log.php:361
115
+ msgid "Previous Page"
116
+ msgstr ""
117
+
118
+ #: email-log.php:268 email-log.php:368
119
+ #, php-format
120
+ msgid "Pages (%s): "
121
+ msgstr ""
122
+
123
+ #: email-log.php:271 email-log.php:371
124
+ msgid "Go to First Page"
125
+ msgstr ""
126
+
127
+ #: email-log.php:271 email-log.php:371
128
+ msgid "First"
129
+ msgstr ""
130
+
131
+ #: email-log.php:274 email-log.php:286 email-log.php:374 email-log.php:386
132
+ msgid "Go to Page"
133
+ msgstr ""
134
+
135
+ #: email-log.php:281 email-log.php:381
136
+ msgid "Page"
137
+ msgstr ""
138
+
139
+ #: email-log.php:289 email-log.php:389
140
+ msgid "Go to Last Page"
141
+ msgstr ""
142
+
143
+ #: email-log.php:289 email-log.php:389
144
+ msgid "Last"
145
+ msgstr ""
146
+
147
+ #: email-log.php:296 email-log.php:396
148
+ msgid "Next Page"
149
+ msgstr ""
150
+
151
+ #: email-log.php:312 email-log.php:347
152
+ msgid "Date / Time"
153
+ msgstr ""
154
+
155
+ #: email-log.php:313 email-log.php:348
156
+ msgid "To"
157
+ msgstr ""
158
+
159
+ #: email-log.php:328
160
+ #, php-format
161
+ msgid "%s @ %s"
162
+ msgstr ""
163
+
164
+ #: email-log.php:340
165
+ msgid "No email Logs Found"
166
+ msgstr ""
167
+
168
+ #: email-log.php:416
169
+ msgid "Filter Options:"
170
+ msgstr ""
171
+
172
+ #: email-log.php:418
173
+ msgid "ID:"
174
+ msgstr ""
175
+
176
+ #: email-log.php:420
177
+ msgid "To Email:"
178
+ msgstr ""
179
+
180
+ #: email-log.php:422
181
+ msgid "Subject:"
182
+ msgstr ""
183
+
184
+ #: email-log.php:427
185
+ msgid "Sort Options:"
186
+ msgstr ""
187
+
188
+ #: email-log.php:445 email-log.php:447
189
+ msgid "Per Page"
190
+ msgstr ""
191
+
192
+ #: email-log.php:455
193
+ msgid "Go"
194
+ msgstr ""
195
+
196
+ #: email-log.php:469
197
+ msgid "Delete Type : "
198
+ msgstr ""
199
+
200
+ #: email-log.php:472
201
+ msgid "Based on"
202
+ msgstr ""
203
+
204
+ #: email-log.php:473
205
+ msgid "All Logs"
206
+ msgstr ""
207
+
208
+ #: email-log.php:478
209
+ msgid "Condition:"
210
+ msgstr ""
211
+
212
+ #: email-log.php:481
213
+ msgid "or"
214
+ msgstr ""
215
+
216
+ #: email-log.php:487
217
+ msgid ""
218
+ "You Are About To Delete Email Logs.\\nThis Action Is Not Reversible.\\n\\n "
219
+ "Choose \\'Cancel\\' to stop, \\'OK\\' to delete."
220
+ msgstr ""
221
+
222
+ #. Plugin URI of an extension
223
+ msgid "http://sudarmuthu.com/wordpress/email-log"
224
+ msgstr ""
225
+
226
+ #. Description of an extension
227
+ msgid "Logs every email sent through WordPress. Compatiable with WPMU too."
228
+ msgstr ""
229
+
230
+ #. Author of an extension
231
+ msgid "Sudar"
232
+ msgstr ""
233
+
234
+ #. Author URI of an extension
235
+ msgid "http://sudarmuthu.com/"
236
+ msgstr ""
readme.txt ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Email Log ===
2
+ Contributors: sudar
3
+ Tags: email, wpmu, wordpress-mu, log
4
+ Requires at least: 2.8
5
+ Tested up to: 2.8.4
6
+ Stable tag: 0.1
7
+
8
+ Logs every email sent through WordPress. Compatiable with WPMU too.
9
+
10
+ == Description ==
11
+
12
+ Logs every email sent through WordPress. Compatiable with WPMU too.
13
+
14
+ #### Viewing logged emails
15
+
16
+ The logged emails will be stored in a separate table and can be viewed from the admin interface. While viewing the logs, the emails can be filtered or sorted based on the date, to address, subject etc.
17
+
18
+ **Deleting logged emails**
19
+
20
+ In the admin interface, all the logged emails can be delete in bulk or can also be selectively deleted based on date, to address, subject.
21
+
22
+ **Cleaning up db on uninstall**
23
+
24
+ As [recommended by Ozh][1], the Plugin has uninstall hook which will clean up the database when the Plugin is uninstalled.
25
+
26
+ [1]: http://sudarmuthu.com/blog/2009/10/07/lessons-from-wordpress-plugin-competition.html
27
+
28
+ == Installation ==
29
+
30
+ #### Normal WordPress installations
31
+
32
+ Extract the zip file and just drop the contents in the wp-content/plugins/ directory of your WordPress installation and then activate the Plugin from Plugins page.
33
+
34
+ #### WordPress MU installations
35
+
36
+ Extract the zip file and just drop the contents in the wp-content/plugins/ directory or mu-plugins directory of your WordPress MU installation and then activate the Plugin from Plugins page. You can activate it site wide or just for a single blog.
37
+ == Screenshots ==
38
+ 1. The following screenshot shows how the logged emails will be displayed
39
+
40
+ 2. This screenshot shows how the email logs could be filtered or sorted.
41
+
42
+ 3. This one shows how the email logs could be deleted
43
+
44
+ == Changelog ==
45
+
46
+ ###v0.1 (2009-10-08)
47
+
48
+ * Initial Release
49
+
50
+ ==Readme Generator==
51
+
52
+ This Readme file was generated using <a href = 'http://sudarmuthu.com/wordpress/wp-readme'>wp-readme</a>, which generates readme files for WordPress Plugins.
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file
screenshot-3.png ADDED
Binary file
uninstall.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // uninstall page for Email Log Plugin to clean up db.
3
+ // Code based on this article http://jacobsantos.com/2008/general/wordpress-27-plugin-uninstall-methods/
4
+
5
+ if( !defined( 'ABSPATH') && !defined('WP_UNINSTALL_PLUGIN') )
6
+ exit();
7
+
8
+ global $wpdb;
9
+ global $smel_table_name;
10
+ $smel_table_name = $wpdb->prefix . "email_log";
11
+
12
+ if($wpdb->get_var("show tables like '{$smel_table_name}'") == $smel_table_name) {
13
+ // If table is present, drop it
14
+ $sql = "DROP TABLE $smel_table_name";
15
+ $wpdb->query($sql);
16
+ }
17
+
18
+ // Delete the option
19
+ delete_option('email-log-db');
20
+
21
+ //Sorry to see you go :(
22
+ ?>