PluginProbe
Email Log / 1.1
Email Log v1.1
2.63 2.4.8 2.4.9 2.6 2.61 2.62 trunk 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.8.1 0.9 0.9.1 0.9.2 1.1 1.5 1.5.1 1.5.2 1.5.3 1.5.4 All 61 releases
email-log / email-log.php

email-log.php in Email Log 1.1, at email-log.php

729 lines 32.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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. Compatible with WPMU too.
6 Donate Link: http://sudarmuthu.com/if-you-wanna-thank-me
7 Author: Sudar
8 Version: 1.1
9 Author URI: http://sudarmuthu.com/
10 Text Domain: email-log
11 Domain Path: languages/
12
13 === RELEASE NOTES ===
14 2009-10-08 - v0.1 - Initial Release
15 2009-10-15 - v0.2 - Added compatability for MySQL 4
16 2009-10-19 - v0.3 - Added compatability for MySQL 4 (Thanks Frank)
17 2010-01-02 - v0.4 - Added german translation (Thanks Frank)
18 2012-01-01 - v0.5 - Fixed a deprecation notice
19 2012-04-29 - v0.6 - (Dev time: 2 hours)
20 - Added option to delete individual email logs
21 - Moved pages per screen option to Screen options panel
22 - Added information to the screen help tab
23 - Added Lithuanian translations
24 2012-06-23 - v0.7 - (Dev time: 1 hour)
25 - Changed Timestamp(n) MySQL datatype to Timestamp (now compatible with MySQL 5.5+)
26 - Added the ability to bulk delete checkboxes
27 2012-07-12 - v0.8 - (Dev time: 1 hour)
28 - Fixed undefined notices - http://wordpress.org/support/topic/plugin-email-log-notices-undefined-indices
29 - Added Dutch translations
30 2012-07-23 - v0.8.1 - (Dev time: 0.5 hour)
31 - Reworded most error messages and fixed lot of typos
32 2013-01-08 - v0.9 - (Dev time: 1 hour)
33 - Use blog date/time for send date instead of server time
34 - Handle cases where the headers send is an array
35 2013-01-08 - v0.9.1 - (Dev time: 0.5 hour)
36 - Moved the menu under tools (Thanks samuelaguilera)
37 2013-03-14 - v0.9.2 - (Dev time: 0.5 hour)
38 - Added support for filters which can be used while logging emails
39 2013-04-01 - v0.9.3 - (Dev time: 0.5 hour)
40 - Moved table name into a separate constants file
41 2013-04-17 - v1.0 - (Dev time: 0.5 hour)
42 - Added support for buying pro addons
43 2013-04-27 - v1.1 - (Dev time: 0.5 hour)
44 - Added more documentation
45 */
46 /* Copyright 2009 Sudar Muthu (email : sudar@sudarmuthu.com)
47
48 This program is free software; you can redistribute it and/or modify
49 it under the terms of the GNU General Public License, version 2, as
50 published by the Free Software Foundation.
51
52 This program is distributed in the hope that it will be useful,
53 but WITHOUT ANY WARRANTY; without even the implied warranty of
54 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55 GNU General Public License for more details.
56
57 You should have received a copy of the GNU General Public License
58 along with this program; if not, write to the Free Software
59 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
60 */
61
62 /**
63 * The main Plugin class
64 */
65 class EmailLog {
66
67 private $admin_page;
68 private $admin_screen;
69
70 const FILTER_NAME = 'wp_mail_log';
71
72 const TABLE_NAME = 'email_log'; /* Database table name */
73 const DB_OPTION_NAME = 'email-log-db'; /* Database option name */
74 const DB_VERSION = '0.1'; /* Database version */
75
76 /**
77 * Initalize the plugin by registering the hooks
78 */
79 function __construct() {
80
81 global $wpdb;
82
83 // Load localization domain
84 $this->translations = dirname(plugin_basename(__FILE__)) . '/languages/' ;
85 load_plugin_textdomain( 'email-log', false, $this->translations);
86
87 // Register hooks
88 add_action( 'admin_menu', array(&$this, 'register_settings_page') );
89 add_filter( 'plugin_row_meta', array( &$this, 'add_plugin_links' ), 10, 2 );
90
91 // Register Filter
92 add_filter('wp_mail', array(&$this, 'log_email'));
93 add_filter('set-screen-option', array(&$this, 'save_screen_options'), 10, 3);
94
95 $plugin = plugin_basename(__FILE__);
96 add_filter("plugin_action_links_$plugin", array(&$this, 'add_action_links'));
97
98 $this->table_name = $wpdb->prefix . self::TABLE_NAME;
99 }
100
101 /**
102 * Adds additional links in the Plugin listing. Based on http://zourbuth.com/archives/751/creating-additional-wordpress-plugin-links-row-meta/
103 */
104 function add_plugin_links($links, $file) {
105 $plugin = plugin_basename(__FILE__);
106
107 if ($file == $plugin) // only for this plugin
108 return array_merge( $links,
109 array( '<a href="http://sudarmuthu.com/out/buy-email-log-forward-email-addon" target="_blank">' . __('Buy Addons', 'email-log') . '</a>' )
110 );
111 return $links;
112 }
113
114 /**
115 * Register the settings page
116 */
117 function register_settings_page() {
118 //Save the handle to your admin page - you'll need it to create a WP_Screen object
119 $this->admin_page = add_submenu_page( 'tools.php', __('Email Log', 'email-log'), __('Email Log', 'email-log'), 'manage_options', 'email-log', array(&$this, 'settings_page') );
120
121 add_action("load-{$this->admin_page}",array(&$this,'create_settings_panel'));
122 }
123
124 /**
125 * Add settings Panel
126 */
127 function create_settings_panel() {
128
129 /**
130 * Create the WP_Screen object against your admin page handle
131 * This ensures we're working with the right admin page
132 */
133 $this->admin_screen = WP_Screen::get($this->admin_page);
134
135 /**
136 * Content specified inline
137 */
138 $this->admin_screen->add_help_tab(
139 array(
140 'title' => __('About Plugin', 'email-log'),
141 'id' => 'about_tab',
142 'content' => '<p>' . __('Email Log WordPress Plugin, allows you to log all emails that are sent through WordPress.', 'email-log') . '</p>',
143 'callback' => false
144 )
145 );
146
147 // Add help sidebar
148 $this->admin_screen->set_help_sidebar(
149 '<p><strong>' . __('More information', 'email-log') . '</strong></p>' .
150 '<p><a href = "http://sudarmuthu.com/wordpress/email-log">' . __('Plugin Homepage/support', 'email-log') . '</a></p>' .
151 '<p><a href = "http://sudarmuthu.com/blog">' . __("Plugin author's blog", 'email-log') . '</a></p>' .
152 '<p><a href = "http://sudarmuthu.com/wordpress/">' . __("Other Plugin's by Author", 'email-log') . '</a></p>'
153 );
154
155 // Add screen options
156 $this->admin_screen->add_option(
157 'per_page',
158 array(
159 'label' => __('Entries per page', 'email-log'),
160 'default' => 20,
161 'option' => 'per_page'
162 )
163 );
164 }
165
166 /**
167 * Save Screen option
168 */
169 function save_screen_options($status, $option, $value) {
170 if ( 'per_page' == $option ) return $value;
171 }
172
173 /**
174 * Get the per page option
175 */
176 private function get_per_page() {
177 $screen = get_current_screen();
178 $option = $screen->get_option('per_page', 'option');
179
180 $per_page = get_user_meta(get_current_user_id(), $option, TRUE);
181
182 if ( empty ( $per_page) || $per_page < 1 ) {
183 $per_page = $screen->get_option( 'per_page', 'default' );
184 }
185
186 return $per_page;
187 }
188
189 /**
190 * hook to add action links
191 *
192 * @param <type> $links
193 * @return <type>
194 */
195 function add_action_links( $links ) {
196 // Add a link to this plugin's settings page
197 $settings_link = '<a href="tools.php?page=email-log">' . __("Log", 'email-log') . '</a>';
198 array_unshift( $links, $settings_link );
199 return $links;
200 }
201
202 /**
203 * Adds Footer links. Based on http://striderweb.com/nerdaphernalia/2008/06/give-your-wordpress-plugin-credit/
204 */
205 function add_footer_links() {
206 $plugin_data = get_plugin_data( __FILE__ );
207 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']);
208 }
209
210 /**
211 * Dipslay the Settings page
212 *
213 * Some parts of this function is based on the wp-rattings Plugin
214 * TODO: Rewrite this using this technique http://wp.smashingmagazine.com/2011/11/03/native-admin-tables-wordpress/
215 */
216 function settings_page() {
217 global $wpdb;
218 global $text_direction;
219
220 $base_name = plugin_basename('email-log');
221 $base_page = 'tools.php?page='.$base_name;
222
223 $email_log_page = intval($this->array_get($_GET, 'emaillog_page'));
224 $emaillogs_filterid = trim(addslashes($this->array_get($_GET, 'id')));
225 $emaillogs_filter_to_email = trim(addslashes($this->array_get($_GET, 'to_email')));
226 $emaillogs_filter_subject = trim(addslashes($this->array_get($_GET, 'subject')));
227 $emaillog_sort_by = trim($this->array_get($_GET, 'by'));
228 $emaillog_sortby_text = '';
229 $emaillog_sortorder = trim($this->array_get($_GET, 'order'));
230 $emaillog_sortorder_text = '';
231 $email_log_perpage = intval($this->get_per_page());
232 $emaillog_sort_url = '';
233
234 ### Form Processing
235 if(!empty($_POST['do'])) {
236 // Decide What To Do
237 switch($_POST['do']) {
238 case __('Delete Logs', 'email-log'):
239 $delete_datalog = intval($_POST['delete_datalog']);
240 switch($delete_datalog) {
241 case 1:
242 // delete selected entries
243 $selected_ids = implode(',', $_POST['selected_ids']);
244 $delete_logs = $wpdb->query("DELETE FROM $this->table_name where id IN ($selected_ids)");
245
246 if($delete_logs) {
247 $text = '<font color="green">' . __('The selected Email Logs have been deleted.', 'email-log') . '</font>';
248 } else {
249 $text = '<font color="red">' . __('An error has occurred while deleting the selected Email logs', 'email-log') . '</font>';
250 }
251 break;
252 case 2:
253 // Delete based on condition
254 $to_email = trim(addslashes( $_POST['delete_to_email']));
255 if ('' != $to_email) {
256 $delete_logs = $wpdb->query("DELETE FROM $this->table_name where to_email = '$to_email'");
257 if($delete_logs) {
258 $text = '<font color="green">'.sprintf(__('All Email Logs for email id "%s" have been deleted.', 'email-log'), $to_email).'</font>';
259 } else {
260 $text = '<font color="red">'.sprintf(__('An error has occurred while deleting all Email Logs for email id "%s".', 'email-log'), $to_email).'</font>';
261 }
262 }
263
264 $subject = trim(addslashes( $_POST['delete_subject']));
265 if ('' != $subject) {
266 $delete_logs = $wpdb->query("DELETE FROM $this->table_name where subject = '$subject'");
267 if($delete_logs) {
268 $text .= '<font color="green">'.sprintf(__('All Email Logs with subject "%s" have been deleted.', 'email-log'), $subject).'</font>';
269 } else {
270 $text .= '<font color="red">'.sprintf(__('An error has occurred while deleting all Email Logs with subject "%s".', 'email-log'), $subject).'</font>';
271 }
272 }
273 break;
274 case 3:
275 // Delete all
276 $delete_logs = $wpdb->query("DELETE FROM $this->table_name ");
277 if ($delete_logs) {
278 $text = '<font color="green">'.__('All Email Logs were deleted.', 'email-log').'</font><br />';
279 } else {
280 $text = '<font color="red">'.__('An error has occurred while deleting all Email Logs', 'email-log').'</font>';
281 }
282 break;
283 }
284 break;
285 }
286 }
287
288 ### Form Sorting URL
289 if(!empty($emaillogs_filterid)) {
290 $emaillogs_filterid = intval($emaillogs_filterid);
291 $emaillog_sort_url .= '&amp;id='.$emaillogs_filterid;
292 }
293 if(!empty($emaillogs_filter_to_email)) {
294 $emaillog_sort_url .= '&amp;to_email='.$emaillogs_filter_to_email;
295 }
296 if(!empty($emaillogs_filter_subject)) {
297 $emaillog_sort_url .= '&amp;subject='.$emaillogs_filter_subject;
298 }
299 if(!empty($emaillog_sort_by)) {
300 $emaillog_sort_url .= '&amp;by='.$emaillog_sort_by;
301 }
302 if(!empty($emaillog_sortorder)) {
303 $emaillog_sort_url .= '&amp;order='.$emaillog_sortorder;
304 }
305
306 ### Get Order By
307 switch($emaillog_sort_by) {
308 case 'id':
309 $emaillog_sort_by = 'id';
310 $emaillog_sortby_text = __('ID', 'email-log');
311 break;
312 case 'to_email':
313 $emaillog_sort_by = 'to_email';
314 $emaillog_sortby_text = __('To Email', 'email-log');
315 break;
316 case 'subject':
317 $emaillog_sort_by = 'subject';
318 $emaillog_sortby_text = __('Subject', 'email-log');
319 break;
320 case 'date':
321 default:
322 $emaillog_sort_by = 'sent_date';
323 $emaillog_sortby_text = __('Date', 'email-log');
324 }
325
326 ### Get Sort Order
327 switch($emaillog_sortorder) {
328 case 'asc':
329 $emaillog_sortorder = 'ASC';
330 $emaillog_sortorder_text = __('Ascending', 'email-log');
331 break;
332 case 'desc':
333 default:
334 $emaillog_sortorder = 'DESC';
335 $emaillog_sortorder_text = __('Descending', 'email-log');
336 }
337
338 // Where
339 $emaillog_where = '';
340 if(!empty($emaillogs_filterid)) {
341 $emaillog_where = "AND id =$emaillogs_filterid";
342 }
343 if(!empty($emaillogs_filter_to_email)) {
344 $emaillog_where .= " AND to_email like '%$emaillogs_filter_to_email%'";
345 }
346 if(!empty($emaillogs_filter_subject)) {
347 $emaillog_where .= " AND subject like '%$emaillogs_filter_subject%'";
348 }
349
350 // Get email Logs Data
351 $total_logs = $wpdb->get_var("SELECT COUNT(id) FROM $this->table_name WHERE 1=1 $emaillog_where");
352
353 // Checking $postratings_page and $offset
354 if(empty($email_log_page) || $email_log_page == 0) { $email_log_page = 1; }
355 if(empty($offset)) { $offset = 0; }
356
357 // Determin $offset
358 $offset = ($email_log_page-1) * $email_log_perpage;
359
360 // Determine Max Number Of Logs To Display On Page
361 if(($offset + $email_log_perpage) > $total_logs) {
362 $max_on_page = $total_logs;
363 } else {
364 $max_on_page = ($offset + $email_log_perpage);
365 }
366
367 // Determine Number Of Logs To Display On Page
368 if (($offset + 1) > ($total_logs)) {
369 $display_on_page = $total_logs;
370 } else {
371 $display_on_page = ($offset + 1);
372 }
373
374 // Determing Total Amount Of Pages
375 $total_pages = ceil($total_logs / $email_log_perpage);
376
377 // Get The Logs
378 $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");
379
380 // TODO: Should move this to a seperate js file
381 ?>
382 <script type = "text/javascript">
383 jQuery('document').ready(function() {
384 jQuery('.selectall').click(function (e) {
385 if (jQuery(e.target).is(':checked')) {
386 jQuery('.select_box').attr('checked', 'checked');
387 } else {
388 jQuery('.select_box').removeAttr('checked');
389 }
390 });
391 });
392 </script>
393 <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
394 <div class="wrap">
395 <?php screen_icon(); ?>
396 <h2><?php _e( 'Email Log', 'email-log' ); ?></h2>
397
398 <p>&nbsp;</p>
399
400 <form action="<?php echo esc_url($_SERVER['PHP_SELF']); ?>" method="get">
401 <input type="hidden" name="page" value="<?php echo $base_name; ?>" />
402 <table class="widefat">
403 <tr>
404 <th><?php _e('Filter Options:', 'email-log'); ?></th>
405 <td>
406 <?php _e('ID:', 'email-log'); ?>&nbsp;<input type="text" name="id" value="<?php echo $emaillogs_filterid; ?>" size="5" maxlength="5" />
407 &nbsp;&nbsp;&nbsp;
408 <?php _e('To Email:', 'email-log'); ?>&nbsp;<input type="text" name="to_email" value="<?php echo $emaillogs_filter_to_email; ?>" size="40" maxlength="50" />
409 &nbsp;&nbsp;&nbsp;
410 <?php _e('Subject:', 'email-log'); ?>&nbsp;<input type="text" name="subject" value="<?php echo $emaillogs_filter_subject; ?>" size="40" maxlength="50" />
411 &nbsp;&nbsp;&nbsp;
412 </td>
413 </tr>
414 <tr class="alternate">
415 <th><?php _e('Sort Options:', 'email-log'); ?></th>
416 <td>
417 <select name="by" size="1">
418 <option value="id"<?php if($emaillog_sort_by == 'id') { echo ' selected="selected"'; }?>><?php _e('ID', 'email-log'); ?></option>
419 <option value="to_email"<?php if($emaillog_sort_by == 'to_email') { echo ' selected="selected"'; }?>><?php _e('To Email', 'email-log'); ?></option>
420 <option value="subject"<?php if($emaillog_sort_by == 'subject') { echo ' selected="selected"'; }?>><?php _e('Subject', 'email-log'); ?></option>
421 <option value="sent_date"<?php if($emaillog_sort_by == 'sent_date') { echo ' selected="selected"'; }?>><?php _e('Date', 'email-log'); ?></option>
422 </select>
423 &nbsp;&nbsp;&nbsp;
424 <select name="order" size="1">
425 <option value="asc"<?php if($emaillog_sortorder == 'ASC') { echo ' selected="selected"'; }?>><?php _e('Ascending', 'email-log'); ?></option>
426 <option value="desc"<?php if($emaillog_sortorder == 'DESC') { echo ' selected="selected"'; } ?>><?php _e('Descending', 'email-log'); ?></option>
427 </select>
428 </td>
429 </tr>
430 <tr>
431 <td colspan="2" align="center"><input type="submit" value="<?php _e('Filter', 'email-log'); ?>" class="button" /></td>
432 </tr>
433 </table>
434 </form>
435
436 <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>
437 <p><?php printf(__('Sorted by <strong>%s</strong> in <strong>%s</strong> order.', 'email-log'), $emaillog_sortby_text, $emaillog_sortorder_text); ?></p>
438
439 <form method="post" action="<?php echo esc_url($_SERVER['PHP_SELF']); ?>?page=<?php echo $base_name; ?>">
440 <?php
441 if($total_pages > 1) {
442 ?>
443 <br />
444 <table class="widefat">
445 <tr>
446 <td align="<?php echo ('rtl' == $text_direction) ? 'right' : 'left'; ?>" width="40%">
447 <?php
448 if($email_log_page > 1 && ((($email_log_page*$email_log_perpage)-($email_log_perpage-1)) <= $total_logs)) {
449 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>';
450 } else {
451 echo '&nbsp;';
452 }
453 ?>
454 </td>
455 <td align="center" width="20%">
456 <?php printf(__('Pages (%s): ', 'email-log'), number_format_i18n($total_pages)); ?>
457 <?php
458 if ($email_log_page >= 4) {
459 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> ... ';
460 }
461 if($email_log_page > 1) {
462 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> ';
463 }
464 for($i = $email_log_page - 2 ; $i <= $email_log_page +2; $i++) {
465 if ($i >= 1 && $i <= $total_pages) {
466 if($i == $email_log_page) {
467 echo '<strong>['.number_format_i18n($i).']</strong> ';
468 } else {
469 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> ';
470 }
471 }
472 }
473 if($email_log_page < $total_pages) {
474 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> ';
475 }
476 if (($email_log_page+2) < $total_pages) {
477 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>';
478 }
479 ?>
480 </td>
481 <td align="<?php echo ('rtl' == $text_direction) ? 'left' : 'right'; ?>" width="40%">
482 <?php
483 if($email_log_page >= 1 && ((($email_log_page*$email_log_perpage)+1) <= $total_logs)) {
484 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>';
485 } else {
486 echo '&nbsp;';
487 }
488 ?>
489 </td>
490 </tr>
491 </table>
492 <!-- </Paging> -->
493 <?php
494 }
495 ?>
496 <table class="widefat">
497 <thead>
498 <tr>
499 <td width="5%"><input type = "checkbox" name = "selectall" class = "selectall" ></td>
500 <th width="5%"><?php _e('ID', 'email-log'); ?></th>
501 <th width="20%"><?php _e('Date / Time', 'email-log'); ?></th>
502 <th width="30%"><?php _e('To', 'email-log'); ?></th>
503 <th width="40%"><?php _e('Subject', 'email-log'); ?></th>
504 </tr>
505 </thead>
506 <tbody>
507 <?php
508 if($email_logs) {
509 $i = 0;
510 foreach($email_logs as $email_log) {
511 if($i%2 == 0) {
512 $style = 'class="alternate"';
513 } else {
514 $style = '';
515 }
516 $email_id = intval($email_log->id);
517 $email_date = mysql2date(sprintf(__('%s @ %s', 'email-log'), get_option('date_format'), get_option('time_format')), $email_log->sent_date);
518 $email_to = stripslashes($email_log->to_email);
519 $email_subject = stripslashes($email_log->subject);
520 echo "<tr $style>\n";
521 echo '<td><input type = "checkbox" class = "select_box" name = "selected_ids[]" value = "' . $email_id . '"></td>'."\n";
522 echo '<td>'.$email_id.'</td>'."\n";
523 echo "<td>$email_date</td>\n";
524 echo "<td>$email_to</td>\n";
525 echo "<td>$email_subject</td>\n";
526 echo '</tr>';
527 $i++;
528 }
529 } else {
530 echo '<tr><td colspan="7" align="center"><strong>'.__('No Email Logs were found', 'email-log').'</strong></td></tr>';
531 }
532 ?>
533 </tbody>
534 <tfoot>
535 <tr>
536 <td width="5%"><input type = "checkbox" name = "selectall" class = "selectall" ></td>
537 <th width="5%"><?php _e('ID', 'email-log'); ?></th>
538 <th width="20%"><?php _e('Date / Time', 'email-log'); ?></th>
539 <th width="30%"><?php _e('To', 'email-log'); ?></th>
540 <th width="40%"><?php _e('Subject', 'email-log'); ?></th>
541 </tr>
542 </tfoot>
543 </table>
544 <?php
545 if($total_pages > 1) {
546 ?>
547 <table class="widefat">
548 <tr>
549 <td align="<?php echo ('rtl' == $text_direction) ? 'right' : 'left'; ?>" width="40%">
550 <?php
551 if($email_log_page > 1 && ((($email_log_page*$email_log_perpage)-($email_log_perpage-1)) <= $total_logs)) {
552 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>';
553 } else {
554 echo '&nbsp;';
555 }
556 ?>
557 </td>
558 <td align="center" width="20%">
559 <?php printf(__('Pages (%s): ', 'email-log'), number_format_i18n($total_pages)); ?>
560 <?php
561 if ($email_log_page >= 4) {
562 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> ... ';
563 }
564 if($email_log_page > 1) {
565 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> ';
566 }
567 for($i = $email_log_page - 2 ; $i <= $email_log_page +2; $i++) {
568 if ($i >= 1 && $i <= $total_pages) {
569 if($i == $email_log_page) {
570 echo '<strong>['.number_format_i18n($i).']</strong> ';
571 } else {
572 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> ';
573 }
574 }
575 }
576 if($email_log_page < $total_pages) {
577 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> ';
578 }
579 if (($email_log_page+2) < $total_pages) {
580 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>';
581 }
582 ?>
583 </td>
584 <td align="<?php echo ('rtl' == $text_direction) ? 'left' : 'right'; ?>" width="40%">
585 <?php
586 if($email_log_page >= 1 && ((($email_log_page*$email_log_perpage)+1) <= $total_logs)) {
587 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>';
588 } else {
589 echo '&nbsp;';
590 }
591 ?>
592 </td>
593 </tr>
594 <tr class="alternate">
595 </tr>
596 </table>
597 <!-- </Paging> -->
598 <?php
599 }
600 ?>
601
602 <!-- Delete Email Logs -->
603 <h3><?php _e('Delete Logs', 'email-log'); ?></h3>
604 <div align="center">
605 <table class="widefat">
606 <tr>
607 <td valign="top"><b><?php _e('Delete Type : ', 'email-log'); ?></b></td>
608 <td valign="top">
609 <select size="1" name="delete_datalog">
610 <option value="1"><?php _e('Selected entries', 'email-log'); ?></option>
611 <option value="2"><?php _e('Based on', 'email-log'); ?></option>
612 <option value="3"><?php _e('All Logs', 'email-log'); ?></option>
613 </select>
614 </td>
615 </tr>
616 <tr>
617 <td valign="top"><b><?php _e('Condition:', 'email-log'); ?></b></td>
618 <td valign="top">
619 <label for ="delete_to_email"><?php _e('To Email', 'email-log');?> <input type="text" name="delete_to_email" size="20" dir="ltr" /></label>
620 <?php _e('or', 'email-log');?>
621 <label for ="delete_subject"><?php _e('Subject', 'email-log');?> <input type="text" name="delete_subject" size="20" dir="ltr" /></label>
622 </td>
623 </tr>
624 <tr>
625 <td colspan="2" align="center">
626 <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'); ?>')" />
627 </td>
628 </tr>
629 </table>
630 </div>
631 </form>
632 <?php
633 echo '<h3>', __('Pro Addon', 'email-log'), '</h3>';
634 echo '<p>';
635 _e('You can <a href = "http://sudarmuthu.com/out/buy-email-log-forward-email-addon">buy the Forward email pro addon</a>, which allows you to send a copy of all the emails send from WordPress, to another email address. The addon allows you to choose whether you want to forward through to, cc or bcc fields. This can be extremely useful when you want to debug by analyzing the emails that are sent from WordPress. The cost of the addon is $15.', 'email-log');
636 echo '</p>';
637 ?>
638 </div>
639 <?php
640 // Display credits in Footer
641 add_action( 'in_admin_footer', array(&$this, 'add_footer_links'));
642 }
643
644 /**
645 * Log all email to database
646 *
647 * @global object $wpdb
648 * @param array $mail_info Information about email
649 * @return array Information about email
650 */
651 function log_email($mail_info) {
652
653 global $wpdb;
654
655 $attachment_present = (count ($mail_info['attachments']) > 0) ? "true" : "false";
656
657 // Log into the database
658 $wpdb->insert($this->table_name, array(
659 'to_email' => is_array($mail_info['to']) ? $mail_info['to'][0] : $mail_info['to'],
660 'subject' => $mail_info['subject'],
661 'message' => $mail_info['message'],
662 'headers' => is_array($mail_info['headers']) ? implode("\r\n", $mail_info['headers']) : $mail_info['headers'],
663 'attachments' => $attachment_present,
664 'sent_date' => current_time('mysql')
665 ));
666
667 // return filtered array
668 return apply_filters(self::FILTER_NAME, $mail_info);
669 }
670
671 /**
672 * Check whether a key is present. If present returns the value, else returns the default value
673 *
674 * @param <array> $array - Array whose key has to be checked
675 * @param <string> $key - key that has to be checked
676 * @param <string> $default - the default value that has to be used, if the key is not found (optional)
677 *
678 * @return <mixed> If present returns the value, else returns the default value
679 * @author Sudar
680 */
681 private function array_get($array, $key, $default = NULL) {
682 return isset($array[$key]) ? $array[$key] : $default;
683 }
684 }
685
686 /**
687 * Helper class to create and maintain tables
688 */
689 class EmailLogInit {
690
691 /**
692 * Create database table when the Plugin is installed for the first time
693 *
694 * @global object $wpdb
695 * @global string $smel_table_name Table Name
696 */
697 function on_activate() {
698
699 global $wpdb;
700 $table_name = $wpdb->prefix . EmailLog::TABLE_NAME;
701
702 if($wpdb->get_var("show tables like '{$table_name}'") != $table_name) {
703
704 $sql = "CREATE TABLE " . $table_name . " (
705 id mediumint(9) NOT NULL AUTO_INCREMENT,
706 to_email VARCHAR(100) NOT NULL,
707 subject VARCHAR(250) NOT NULL,
708 message TEXT NOT NULL,
709 headers TEXT NOT NULL,
710 attachments TEXT NOT NULL,
711 sent_date timestamp NOT NULL,
712 PRIMARY KEY (id)
713 );";
714
715 require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
716 dbDelta($sql);
717
718 add_option(EmailLog::DB_OPTION_NAME, EmailLog::DB_VERSION);
719 }
720 }
721 }
722
723 // When the Plugin installed
724 register_activation_hook(__FILE__, array('EmailLogInit', 'on_activate'));
725
726 // Start this plugin once all other plugins are fully loaded
727 add_action( 'init', 'EmailLog' ); function EmailLog() { global $EmailLog; $EmailLog = new EmailLog(); }
728 ?>
729