<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[2252] 2013/codebykat/post-by-email/trunk: Better logging, no more wp_die(), reschedule next cron event on manual email check</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://gsoc.trac.wordpress.org/changeset/2252">2252</a></dd>
<dt>Author</dt> <dd>codebykat</dd>
<dt>Date</dt> <dd>2013-08-30 07:01:00 +0000 (Fri, 30 Aug 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Better logging, no more wp_die(), reschedule next cron event on manual email check</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#2013codebykatpostbyemailtrunkclasspostbyemailadminphp">2013/codebykat/post-by-email/trunk/class-post-by-email-admin.php</a></li>
<li><a href="#2013codebykatpostbyemailtrunkclasspostbyemailphp">2013/codebykat/post-by-email/trunk/class-post-by-email.php</a></li>
<li><a href="#2013codebykatpostbyemailtrunkpostbyemailphp">2013/codebykat/post-by-email/trunk/post-by-email.php</a></li>
<li><a href="#2013codebykatpostbyemailtrunkreadmemd">2013/codebykat/post-by-email/trunk/readme.md</a></li>
<li><a href="#2013codebykatpostbyemailtrunkreadmetxt">2013/codebykat/post-by-email/trunk/readme.txt</a></li>
<li><a href="#2013codebykatpostbyemailtrunktestsbootstrapphp">2013/codebykat/post-by-email/trunk/tests/bootstrap.php</a></li>
<li><a href="#2013codebykatpostbyemailtrunkteststestpostbyemailphp">2013/codebykat/post-by-email/trunk/tests/test-post-by-email.php</a></li>
<li><a href="#2013codebykatpostbyemailtrunkviewsadminphp">2013/codebykat/post-by-email/trunk/views/admin.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="2013codebykatpostbyemailtrunkclasspostbyemailadminphp"></a>
<div class="modfile"><h4>Modified: 2013/codebykat/post-by-email/trunk/class-post-by-email-admin.php (2251 => 2252)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/codebykat/post-by-email/trunk/class-post-by-email-admin.php 2013-08-29 07:52:09 UTC (rev 2251)
+++ 2013/codebykat/post-by-email/trunk/class-post-by-email-admin.php    2013-08-30 07:01:00 UTC (rev 2252)
</span><span class="lines">@@ -36,6 +36,9 @@
</span><span class="cx"> 
</span><span class="cx">          // disable post by email settings on Settings->Writing page
</span><span class="cx">          add_filter( 'enable_post_by_email_configuration', '__return_false' );
</span><ins>+
+               // AJAX hook to clear the log
+               add_action( 'wp_ajax_post_by_email_clear_log', array( $this, 'clear_log') );
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  /**
</span><span class="lines">@@ -75,6 +78,10 @@
</span><span class="cx">                  $options['default_email_category'] = '';
</span><span class="cx">          }
</span><span class="cx"> 
</span><ins>+               // TODO this is a hack because validate is getting called
+               // when i call update_option from clear_log.  need to figure out why.
+               $options['log'] = $input['log'];
+
</ins><span class="cx">           return $options;
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="lines">@@ -102,4 +109,20 @@
</span><span class="cx">          include_once( plugin_dir_path( __FILE__ ) . 'views/admin.php' );
</span><span class="cx">  }
</span><span class="cx"> 
</span><ins>+       /**
+        * Clear the log file
+        *
+        * @since    0.9.9
+       */
+       public function clear_log() {
+               // TODO: check_ajax_referer()
+               if( current_user_can( 'manage_options' ) ) {
+                       $options = get_option( 'post_by_email_options' );
+                       $options['log'] = array();
+                       update_option( 'post_by_email_options', $options );
+               }
+
+               die();
+       }
+
</ins><span class="cx"> }
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="2013codebykatpostbyemailtrunkclasspostbyemailphp"></a>
<div class="modfile"><h4>Modified: 2013/codebykat/post-by-email/trunk/class-post-by-email.php (2251 => 2252)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/codebykat/post-by-email/trunk/class-post-by-email.php       2013-08-29 07:52:09 UTC (rev 2251)
+++ 2013/codebykat/post-by-email/trunk/class-post-by-email.php  2013-08-30 07:01:00 UTC (rev 2252)
</span><span class="lines">@@ -84,7 +84,7 @@
</span><span class="cx">          add_action( 'plugins_loaded', array( $this, 'load' ) );
</span><span class="cx"> 
</span><span class="cx">          // add hooks to check for mail
</span><del>-               add_action( 'wp-mail.php', array( $this, 'check_email' ) );
</del><ins>+                add_action( 'wp-mail.php', array( $this, 'manual_check_email' ) );
</ins><span class="cx">           add_action( 'post-by-email-wp-mail.php', array( $this, 'check_email' ) );
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="lines">@@ -159,6 +159,21 @@
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  /**
</span><ins>+        * Run "check_email" when not called by wp_cron
+        *
+        * @since    0.9.9
+        */
+       public function manual_check_email() {
+               // update scheduled check so next one is an hour from last manual check
+               wp_clear_scheduled_hook( 'post-by-email-wp-mail.php' );
+               wp_schedule_event( current_time( 'timestamp', 1 ) + HOUR_IN_SECONDS, 'hourly', 'post-by-email-wp-mail.php' );
+
+               self::check_email();
+
+               wp_safe_redirect( admin_url( 'tools.php?page=post-by-email' ) );
+       }
+
+       /**
</ins><span class="cx">    * Check for new messages and post them to the blog.
</span><span class="cx">   *
</span><span class="cx">   * @since    0.9.0
</span><span class="lines">@@ -170,25 +185,27 @@
</span><span class="cx"> 
</span><span class="cx">          $last_checked = get_transient( 'mailserver_last_checked' );
</span><span class="cx"> 
</span><del>-               if ( $last_checked && ! WP_DEBUG )
-                       wp_die( __( 'Slow down cowboy, no need to check for new mails so often!', 'post-by-email' ) );
</del><ins>+                $options = get_option( 'post_by_email_options' );
+               $options['last_checked'] = current_time( 'timestamp' );
+               update_option( 'post_by_email_options', $options );
</ins><span class="cx"> 
</span><ins>+               if ( $last_checked && ! WP_DEBUG ) {
+                       $log_message = __( 'Slow down cowboy, no need to check for new mails so often!', 'post-by-email' );
+                       self::save_log_message( $log_message );
+                       return;
+               }
+
</ins><span class="cx">           set_transient( 'mailserver_last_checked', true, WP_MAIL_INTERVAL );
</span><span class="cx"> 
</span><del>-               $options = get_option( 'post_by_email_options' );
-
</del><span class="cx">           // if options aren't set, there's nothing to do, move along
</span><span class="cx">          foreach( array( 'mailserver_url', 'mailserver_login', 'mailserver_pass' ) as $optname ) {
</span><span class="cx">                  if( ! $options[$optname] || $options[$optname] == $this->default_options[$optname] ) {
</span><del>-                               // TODO logging
</del><ins>+                                $log_message = __( 'Options not set; skipping.', 'post-by-email' );
+                               self::save_log_message( $log_message );
</ins><span class="cx">                           return;
</span><span class="cx">                  }
</span><span class="cx">          }
</span><span class="cx"> 
</span><del>-               $log = array();
-               $log['last_checked'] = current_time( 'timestamp' );
-               $log['messages'] = array();
-
</del><span class="cx">           $time_difference = get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
</span><span class="cx"> 
</span><span class="cx">          $phone_delim = '::';
</span><span class="lines">@@ -205,16 +222,20 @@
</span><span class="cx">                  $uids = $test['match'];
</span><span class="cx">          }
</span><span class="cx">          catch( Horde_Imap_Client_Exception $e ) {
</span><del>-                       self::save_log_and_die( __( 'An error occurred: ', 'post-by-email') . $e->getMessage(), $log );
</del><ins>+                        self::save_log_message( __( 'An error occurred: ', 'post-by-email') . $e->getMessage() );
+                       return;
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">          if( 0 === sizeof( $uids ) ) {
</span><span class="cx">                  $pop3->shutdown();
</span><del>-                       self::save_log_and_die( __( 'There doesn&#8217;t seem to be any new mail.', 'post-by-email' ), $log );
</del><ins>+                        self::save_log_message( __( 'There doesn&#8217;t seem to be any new mail.', 'post-by-email' ) );
+                       return;
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">          foreach( $uids as $id ) {
</span><ins>+                       $log_message = '';
+
</ins><span class="cx">                   $uid = new Horde_Imap_Client_Ids( $id );
</span><span class="cx"> 
</span><span class="cx">                  // get headers
</span><span class="lines">@@ -248,7 +269,7 @@
</span><span class="cx">                                  $author = trim( $author );
</span><span class="cx">                          $author = sanitize_email( $author );
</span><span class="cx">                          if ( is_email( $author ) ) {
</span><del>-                                       $log['messages'][] = '<p>' . sprintf( __( 'Author is %s', 'post-by-email' ), $author ) . '</p>';
</del><ins>+                                        $log_message .= '<p>' . sprintf( __( 'Author is %s', 'post-by-email' ), $author ) . '</p>';
</ins><span class="cx">                                   $userdata = get_user_by( 'email', $author );
</span><span class="cx">                                  if ( ! empty( $userdata ) ) {
</span><span class="cx">                                          $post_author = $userdata->ID;
</span><span class="lines">@@ -362,7 +383,7 @@
</span><span class="cx"> 
</span><span class="cx">                  $post_ID = wp_insert_post( $post_data );
</span><span class="cx">                  if ( is_wp_error( $post_ID ) )
</span><del>-                               $log['messages'][] = "\n" . $post_ID->get_error_message();
</del><ins>+                                $log_message .= "\n" . $post_ID->get_error_message();
</ins><span class="cx"> 
</span><span class="cx">                  // We couldn't post, for whatever reason. Better move forward to the next email.
</span><span class="cx">                  if ( empty( $post_ID ) )
</span><span class="lines">@@ -370,9 +391,11 @@
</span><span class="cx"> 
</span><span class="cx">                  do_action( 'publish_phone', $post_ID );
</span><span class="cx"> 
</span><del>-                       $log['messages'][] = "\n<p>" . sprintf( __( 'Author: %s', 'post-by-email' ), esc_html( $post_author ) ) . '</p>';
-                       $log['messages'][] = "\n<p>" . sprintf( __( 'Posted title: %s', 'post-by-email' ), esc_html( $post_title ) ) . '</p>';
</del><ins>+                        $log_message .= "\n<p>" . sprintf( __( 'Author: %s', 'post-by-email' ), esc_html( $post_author ) ) . '</p>';
+                       $log_message .= "\n<p>" . sprintf( __( 'Posted title: %s', 'post-by-email' ), esc_html( $post_title ) ) . '</p>';
</ins><span class="cx"> 
</span><ins>+                       self::save_log_message($log_message);
+
</ins><span class="cx">           } // end foreach
</span><span class="cx"> 
</span><span class="cx">          // delete all processed emails
</span><span class="lines">@@ -383,32 +406,32 @@
</span><span class="cx">                  ) );
</span><span class="cx">          }
</span><span class="cx">          catch ( Horde_Imap_Client_Exception $e ) {
</span><del>-                       self::save_log_and_die( __( 'An error occurred: ', 'post-by-email') . $e->getMessage(), $log );
</del><ins>+                        self::save_log_message( __( 'An error occurred: ', 'post-by-email') . $e->getMessage() );
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">          $pop3->shutdown();
</span><del>-
-               foreach( $log['messages'] as $message ) { echo $message; }
-               $options['log'] = $log;
-               update_option( 'post_by_email_options', $options );
</del><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  /**
</span><del>-        * Save a message to the log file and wp_die()
</del><ins>+         * Save a message to the log file
</ins><span class="cx">    *
</span><del>-        * @since    0.9.0
</del><ins>+         * @since    0.9.9
</ins><span class="cx">    *
</span><span class="cx">   * @param    string    $error    Error message to save to the log.
</span><span class="cx">   * @param    array     $log      The log file to save back to the plugin options.
</span><span class="cx">   */
</span><del>-       protected function save_log_and_die( $error, $log ) {
-               $log['messages'][] = $error;
</del><ins>+        protected function save_log_message( $message ) {
+               $options = get_option( 'post_by_email_options' );
</ins><span class="cx"> 
</span><del>-               $options = get_option( 'post_by_email_options' );
</del><ins>+                $log = array();
+               if( isset( $options['log'] ) ) {
+                       $log = $options['log'];
+               }
+
+               array_unshift( $log, array( 'timestamp'=>current_time( 'timestamp' ), 'message'=>$message ) );
+
</ins><span class="cx">           $options['log'] = $log;
</span><span class="cx">          update_option( 'post_by_email_options', $options );
</span><del>-
-               wp_die( $error );
</del><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  /**
</span></span></pre></div>
<a id="2013codebykatpostbyemailtrunkpostbyemailphp"></a>
<div class="modfile"><h4>Modified: 2013/codebykat/post-by-email/trunk/post-by-email.php (2251 => 2252)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/codebykat/post-by-email/trunk/post-by-email.php     2013-08-29 07:52:09 UTC (rev 2251)
+++ 2013/codebykat/post-by-email/trunk/post-by-email.php        2013-08-30 07:01:00 UTC (rev 2252)
</span><span class="lines">@@ -12,7 +12,7 @@
</span><span class="cx">  * Plugin Name: Post By Email
</span><span class="cx">  * Plugin URI:  http://codebykat.wordpress.com
</span><span class="cx">  * Description: Create new posts on your WordPress blog by sending email to a specific email address.
</span><del>- * Version:     0.9.8
</del><ins>+ * Version:     0.9.9
</ins><span class="cx">  * Author:      Kat Hagan
</span><span class="cx">  * Author URI:  http://profiles.wordpress.org/codebykat
</span><span class="cx">  * Text Domain: post-by-email
</span></span></pre></div>
<a id="2013codebykatpostbyemailtrunkreadmemd"></a>
<div class="modfile"><h4>Modified: 2013/codebykat/post-by-email/trunk/readme.md (2251 => 2252)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/codebykat/post-by-email/trunk/readme.md     2013-08-29 07:52:09 UTC (rev 2251)
+++ 2013/codebykat/post-by-email/trunk/readme.md        2013-08-30 07:01:00 UTC (rev 2252)
</span><span class="lines">@@ -36,11 +36,15 @@
</span><span class="cx"> 
</span><span class="cx"> To run the tests:
</span><span class="cx"> 
</span><del>-**1. Set up the WordPress testing library as described in [Handbook:** Automated Testing](http://make.wordpress.org/core/handbook/automated-testing/).  You can also do this [using WP-CLI](http://wp-cli.org/blog/plugin-unit-tests.html).  
</del><ins>+1. Set up the WordPress testing library as described in [Handbook: Automated Testing](http://make.wordpress.org/core/handbook/automated-testing/).  You can also do this [using WP-CLI](http://wp-cli.org/blog/plugin-unit-tests.html).  
</ins><span class="cx"> 1. From the plugin directory, run `WP_TESTS_DIR=/path/to/WordPress/test/install phpunit`
</span><span class="cx"> 
</span><span class="cx"> ## Changelog ##
</span><span class="cx"> 
</span><ins>+### 0.9.9 ###
+* Better logging, no more wp_die().
+* When email is checked manually, reschedule the next wp_cron check to an hour later.
+
</ins><span class="cx"> ### 0.9.8 ###
</span><span class="cx"> * Use wp_cron to schedule hourly mail checks.
</span><span class="cx"> 
</span></span></pre></div>
<a id="2013codebykatpostbyemailtrunkreadmetxt"></a>
<div class="modfile"><h4>Modified: 2013/codebykat/post-by-email/trunk/readme.txt (2251 => 2252)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/codebykat/post-by-email/trunk/readme.txt    2013-08-29 07:52:09 UTC (rev 2251)
+++ 2013/codebykat/post-by-email/trunk/readme.txt       2013-08-30 07:01:00 UTC (rev 2252)
</span><span class="lines">@@ -41,6 +41,10 @@
</span><span class="cx"> 
</span><span class="cx"> == Changelog ==
</span><span class="cx"> 
</span><ins>+= 0.9.9 =
+* Better logging, no more wp_die().
+* When email is checked manually, reschedule the next wp_cron check to an hour later.
+
</ins><span class="cx"> = 0.9.8 =
</span><span class="cx"> * Use wp_cron to schedule hourly mail checks.
</span><span class="cx"> 
</span></span></pre></div>
<a id="2013codebykatpostbyemailtrunktestsbootstrapphp"></a>
<div class="modfile"><h4>Modified: 2013/codebykat/post-by-email/trunk/tests/bootstrap.php (2251 => 2252)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/codebykat/post-by-email/trunk/tests/bootstrap.php   2013-08-29 07:52:09 UTC (rev 2251)
+++ 2013/codebykat/post-by-email/trunk/tests/bootstrap.php      2013-08-30 07:01:00 UTC (rev 2252)
</span><span class="lines">@@ -4,6 +4,7 @@
</span><span class="cx"> 
</span><span class="cx"> function _manually_load_plugin() {
</span><span class="cx">  require dirname( __FILE__ ) . '/../post-by-email.php';
</span><ins>+       require dirname( __FILE__ ) . '/../class-post-by-email-admin.php';
</ins><span class="cx"> }
</span><span class="cx"> tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
</span><span class="cx"> 
</span></span></pre></div>
<a id="2013codebykatpostbyemailtrunkteststestpostbyemailphp"></a>
<div class="modfile"><h4>Modified: 2013/codebykat/post-by-email/trunk/tests/test-post-by-email.php (2251 => 2252)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/codebykat/post-by-email/trunk/tests/test-post-by-email.php  2013-08-29 07:52:09 UTC (rev 2251)
+++ 2013/codebykat/post-by-email/trunk/tests/test-post-by-email.php     2013-08-30 07:01:00 UTC (rev 2252)
</span><span class="lines">@@ -7,6 +7,7 @@
</span><span class="cx">  function setUp() {
</span><span class="cx">          parent::setUp();
</span><span class="cx">          $this->plugin = Post_By_Email::get_instance();
</span><ins>+               $this->pluginAdmin = Post_By_Email_Admin::get_instance();
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  function test_plugin_activation() {
</span><span class="lines">@@ -47,4 +48,25 @@
</span><span class="cx">  function test_check_email() {
</span><span class="cx">          $this->markTestIncomplete();
</span><span class="cx">  }
</span><ins>+
+       function test_save_log_message() {
+               // testing a protected method: bad idea?
+               $this->markTestIncomplete();
+
+               // // if the log doesn't exist, it should be created
+               // $options = get_option( 'post_by_email_options' );
+               // unset($options['log']);
+               // update_option( 'post_by_email_options', $options);
+
+               // $this->plugin->save_log_message("Test message");
+
+               // $options = get_option( 'post_by_email_options' );
+               // $this->assertEquals( 1, sizeof( $options['log'] ) );
+
+               // // if the log exists already, the new message should be added to it
+               // $this->plugin->save_log_message("Test message two");
+
+               // $options = get_option( 'post_by_email_options' );
+               // $this->assertEquals( 2, sizeof( $options['log'] ) );
+       }
</ins><span class="cx"> }
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="2013codebykatpostbyemailtrunkviewsadminphp"></a>
<div class="modfile"><h4>Modified: 2013/codebykat/post-by-email/trunk/views/admin.php (2251 => 2252)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/codebykat/post-by-email/trunk/views/admin.php       2013-08-29 07:52:09 UTC (rev 2251)
+++ 2013/codebykat/post-by-email/trunk/views/admin.php  2013-08-30 07:01:00 UTC (rev 2252)
</span><span class="lines">@@ -93,13 +93,9 @@
</span><span class="cx">          <?php submit_button(); ?>
</span><span class="cx">  </form>
</span><span class="cx"> 
</span><del>-       <h2><?php _e( 'Activity Log', 'post-by-email' ) ?></h2>
</del><ins>+        <h3><?php _e( 'Activity Log', 'post-by-email' ) ?></h3>
</ins><span class="cx">   <?php
</span><span class="cx">          $options = get_option( 'post_by_email_options' );
</span><del>-               $log = null;
-               if( array_key_exists( 'log', $options) ) {
-                       $log = $options['log'];
-               }
</del><span class="cx">   ?>
</span><span class="cx">  <p>
</span><span class="cx">          <?php _e( 'Last checked for new mail:', 'post-by-email' ) ?>
</span><span class="lines">@@ -107,8 +103,8 @@
</span><span class="cx">                  $date_format = get_option( 'date_format' );
</span><span class="cx">                  $time_format = get_option( 'time_format' );
</span><span class="cx">          ?>
</span><del>-               <?php if($log) : ?>
-                       <?php echo date_i18n( "$date_format, $time_format", $log['last_checked'] ); ?>
</del><ins>+                <?php if( isset( $options['last_checked'] ) ) : ?>
+                       <?php echo date_i18n( "$date_format, $time_format", $options['last_checked'] ); ?>
</ins><span class="cx">           <?php else: ?>
</span><span class="cx">                  <?php _e( 'Never', 'post-by-email' ); ?>
</span><span class="cx">          <?php endif; ?>
</span><span class="lines">@@ -116,14 +112,53 @@
</span><span class="cx">          <?php _e( 'Next scheduled check:', 'post-by-email' ) ?>
</span><span class="cx">          <?php
</span><span class="cx">                  $next = wp_next_scheduled( 'post-by-email-wp-mail.php' );
</span><del>-                       echo get_date_from_gmt( date( 'Y-m-d H:i:s', $next ) , "$date_format, $time_format");
</del><ins>+                        echo get_date_from_gmt( date( 'Y-m-d H:i:s', $next ) , "$date_format, $time_format" );
</ins><span class="cx">           ?>
</span><span class="cx">  </p>
</span><del>-       <p><a href="<?php echo site_url('wp-mail.php'); ?>"><?php _e( 'Check now', 'post-by-email' ) ?></a></p>
-       <?php if( $log['messages'] ) : ?>
-               <h3><?php _e( 'Log Messages', 'post-by-email' ); ?></h3>
-               <?php foreach($log['messages'] as $message) : ?>
-                       <li><?php echo $message; ?></li>
-               <?php endforeach; ?>
</del><ins>+        <p>
+               <a href="<?php echo site_url( 'wp-mail.php' ); ?>" class="button-secondary">
+                       <?php _e( 'Check now', 'post-by-email' ) ?>
+               </a>
+       </p>
+
+       <?php if( isset( $options['log'] ) && $options['log'] != array() ) : ?>
+
+               <p>
+                       <a href="" id="clearLog" ><?php _e('Clear Log', 'post-by-email' ); ?></a>
+
+                       <script type="text/javascript" >
+                       jQuery('a#clearLog').click(function(e) {
+
+                               var data = {
+                                       action: 'post_by_email_clear_log'
+                               };
+
+                               jQuery.post(ajaxurl, data, function(response) {
+                                       jQuery('table#logTable').hide();
+                                       jQuery('a#clearLog').hide();
+                               });
+
+                               e.preventDefault();
+
+                       });
+                       </script>
+
+               </p>
+
+               <table id="logTable" class="widefat fixed" cellspacing="0">
+                       <thead>
+                               <tr>
+                                       <th colspan='2'><?php _e('Log Messages', 'post-by-email' ); ?></th>
+                               </tr>
+                       </thead>
+                       <tbody>
+                               <?php foreach( ($options['log']) as $entry ) : ?>
+                                       <tr class="alternate">
+                                               <td><?php echo date_i18n( "$date_format, $time_format", $entry['timestamp'] ); ?></td>
+                                               <td><?php echo $entry['message']; ?></td>
+                                       </tr>
+                               <?php endforeach; ?>
+                       </tbody>
+               </table>
</ins><span class="cx">   <?php endif; ?>
</span><span class="cx"> </div>
</span><span class="cx">\ No newline at end of file
</span></span></pre>
</div>
</div>

</body>
</html>