<!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>[2303] 2013/codebykat/post-by-email/trunk: support categories and tags via shortcode</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/2303">2303</a></dd>
<dt>Author</dt> <dd>codebykat</dd>
<dt>Date</dt> <dd>2013-09-13 01:26:50 +0000 (Fri, 13 Sep 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>support categories and tags via shortcode</pre>

<h3>Modified Paths</h3>
<ul>
<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>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="2013codebykatpostbyemailtrunkclasspostbyemailphp"></a>
<div class="modfile"><h4>Modified: 2013/codebykat/post-by-email/trunk/class-post-by-email.php (2302 => 2303)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/codebykat/post-by-email/trunk/class-post-by-email.php       2013-09-12 22:35:01 UTC (rev 2302)
+++ 2013/codebykat/post-by-email/trunk/class-post-by-email.php  2013-09-13 01:26:50 UTC (rev 2303)
</span><span class="lines">@@ -24,7 +24,7 @@
</span><span class="cx">   *
</span><span class="cx">   * @var     string
</span><span class="cx">   */
</span><del>-       protected $version = '1.0.1';
</del><ins>+        protected $version = '1.0.2';
</ins><span class="cx"> 
</span><span class="cx">  /**
</span><span class="cx">   * Unique identifier for the plugin.
</span><span class="lines">@@ -315,12 +315,37 @@
</span><span class="cx">                  if ( '' == $post_title )
</span><span class="cx">                          $post_title = $subject;
</span><span class="cx"> 
</span><del>-                       /* category */
-                       $post_category = array( $options['default_email_category'] );
</del><span class="cx"> 
</span><ins>+                       /* categories */
</ins><span class="cx"> 
</span><ins>+                       $shortcode_categories = $this->find_shortcode( 'category', $post_content );
+                       $post_category = array();
+                       if ( empty( $shortcode_categories ) ) {
+                               $post_category[] = $options['default_email_category'];
+                       }
+                       foreach ( $shortcode_categories as $cat ) {
+                               if ( is_numeric( $cat ) ) {
+                                       $post_category[] = $cat;
+                               } elseif ( get_category_by_slug( $cat ) ) {
+                                       $term = get_category_by_slug( $cat );
+                                       $post_category[] = $term->term_id;
+                               } else {  // create new category
+                                       $new_category = wp_insert_term( $cat, 'category' );
+                                       if( $new_category ) {
+                                               $post_category[] = $new_category['term_id'];
+                                       }
+                               }
+                       }
+
+                       /* get tags from shortcode */
+                       $tags_input = $this->find_shortcode( 'tag', $post_content );
+
+
+                       $post_content = $this->filter_valid_shortcodes( $post_content );
+
+
</ins><span class="cx">                   /* create the post */
</span><del>-                       $post_data = compact( 'post_content', 'post_title', 'post_date', 'post_date_gmt', 'post_author', 'post_category', 'post_status' );
</del><ins>+                        $post_data = compact( 'post_content', 'post_title', 'post_date', 'post_date_gmt', 'post_author', 'post_category', 'post_status', 'tags_input' );
</ins><span class="cx">                   $post_data = wp_slash( $post_data );
</span><span class="cx"> 
</span><span class="cx">                  $post_ID = wp_insert_post( $post_data );
</span><span class="lines">@@ -604,6 +629,40 @@
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  /**
</span><ins>+        * Look for a shortcode and return its arguments.
+        *
+        * @since    1.0.2
+        *
+        * @param    string    $shortcode    Shortcode to look for
+        *
+        * @param    string    $text         Text to search within
+        *
+        * @return   array     $args         Shortcode arguments
+        */
+       protected function find_shortcode( $shortcode, $text ) {
+               if ( preg_match( "/\[$shortcode\s(.*?)\]/i", $text, $matches ) ) {
+                       return explode( ' ', $matches[1] );
+               }
+               return array();
+       }
+
+       /**
+        * Filter shortcodes out of the message content.
+        *
+        * @since    1.0.2
+        *
+        * @param    string    $text         Text to search within
+        *
+        * @return   string    $text         Filtered text
+        */
+       protected function filter_valid_shortcodes( $text ) {
+               foreach ( array( 'tag', 'category' ) as $shortcode ) {
+                       $text = preg_replace( "/\[$shortcode\s(.*?)\]/i", '', $text );        
+               }
+               return $text;
+       }
+
+       /**
</ins><span class="cx">    * Save an error message to the log file.
</span><span class="cx">   *
</span><span class="cx">   * @since    0.9.9
</span></span></pre></div>
<a id="2013codebykatpostbyemailtrunkpostbyemailphp"></a>
<div class="modfile"><h4>Modified: 2013/codebykat/post-by-email/trunk/post-by-email.php (2302 => 2303)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/codebykat/post-by-email/trunk/post-by-email.php     2013-09-12 22:35:01 UTC (rev 2302)
+++ 2013/codebykat/post-by-email/trunk/post-by-email.php        2013-09-13 01:26:50 UTC (rev 2303)
</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:     1.0.1
</del><ins>+ * Version:     1.0.2
</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 (2302 => 2303)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/codebykat/post-by-email/trunk/readme.md     2013-09-12 22:35:01 UTC (rev 2302)
+++ 2013/codebykat/post-by-email/trunk/readme.md        2013-09-13 01:26:50 UTC (rev 2303)
</span><span class="lines">@@ -18,6 +18,11 @@
</span><span class="cx"> 
</span><span class="cx"> Once an email has been successfully posted to the blog, it will either be marked as read (IMAP servers only) or deleted from the mailbox.
</span><span class="cx"> 
</span><ins>+You can set categories and tags on your posts by including shortcodes in your email.  These should be space-separated.  Use slugs for tags and either slugs or IDs for categories.  Terms that do not yet exist will be created.  Examples:
+`[category posted-by-email another-category]`
+`[tag cool-stuff]`
+`[category 14]`
+
</ins><span class="cx"> Updates on the project can be found on the [Make WordPress Core blog](http://make.wordpress.org/core/tag/post-by-email/).
</span><span class="cx"> 
</span><span class="cx"> ## Installation ##
</span><span class="lines">@@ -39,6 +44,9 @@
</span><span class="cx"> 
</span><span class="cx"> ## Changelog ##
</span><span class="cx"> 
</span><ins>+### 1.0.2 ###
+* Support shortcodes to specify categories and tags.
+
</ins><span class="cx"> ### 1.0.1 ###
</span><span class="cx"> * Added tabs and additional options to options panel.
</span><span class="cx"> * Admin banners for notices & errors.
</span></span></pre></div>
<a id="2013codebykatpostbyemailtrunkreadmetxt"></a>
<div class="modfile"><h4>Modified: 2013/codebykat/post-by-email/trunk/readme.txt (2302 => 2303)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/codebykat/post-by-email/trunk/readme.txt    2013-09-12 22:35:01 UTC (rev 2302)
+++ 2013/codebykat/post-by-email/trunk/readme.txt       2013-09-13 01:26:50 UTC (rev 2303)
</span><span class="lines">@@ -18,6 +18,11 @@
</span><span class="cx"> 
</span><span class="cx"> Once an email has been successfully posted to the blog, it will either be marked as read (IMAP servers only) or deleted from the mailbox.
</span><span class="cx"> 
</span><ins>+You can set categories and tags on your posts by including shortcodes in your email.  These should be space-separated.  Use slugs for tags and either slugs or IDs for categories.  Terms that do not yet exist will be created.  Examples:
+`[category posted-by-email another-category]`
+`[tag cool-stuff]`
+`[category 14]`
+
</ins><span class="cx"> Updates on the project can be found on the [Make WordPress Core blog](http://make.wordpress.org/core/tag/post-by-email/).
</span><span class="cx"> 
</span><span class="cx"> == Installation ==
</span><span class="lines">@@ -39,6 +44,9 @@
</span><span class="cx"> 
</span><span class="cx"> == Changelog ==
</span><span class="cx"> 
</span><ins>+= 1.0.2 =
+* Support shortcodes to specify categories and tags.
+
</ins><span class="cx"> = 1.0.1 =
</span><span class="cx"> * Added tabs and additional options to options panel.
</span><span class="cx"> * Admin banners for notices & errors.
</span></span></pre>
</div>
</div>

</body>
</html>