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