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