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