A-  A  A+ RSS Feed

Deep Thoughts by Robert Felty

thoughts on wordpress, latex, cooking et alia

Posts Tagged ‘postie’

Monday, August 24th, 2009

Writing your own custom filters for postie

In version 1.3.1 of postie, it is now easy to add custom filters to the content of your posts. Best of all, by using filters, you can easily write your own plugin, which will not be affected by upgrades to postie (as opposed to modifying the postie functions directly). There are two examples now included in version 1.3.1 of postie, in the filterPostie.php file. Here is how to write your own filter.

  1. Copy the filterPostie.php into your plugins directory
  2. Change the metadata at the top of the file, such as the author and plugin name
  3. Modify the example functions to your liking, or create your own
  4. Activate the plugin

A few more details. After modifying the headers, you might have something like the following:

/* Plugin Name: My own Postie Filter Plugin
URI: http://mywebsite
Description: Adds a custom field to each post called postie
Version: 0.1 Author: Joe Bloe
Author URI: http://mywebsite.com
*/

Just as with any filter for wordpress, you have 2 parts.

  1. A function which receives an argument, makes some modifications (filtering) and returns a result
  2. A function call to add this new function to the list of filters for a certain action

As you can see in the example file, I have created two functions, filter_title, and filter_content. After creating these functions, I then “hook” them into postie using the add_filter function.

add_filter('postie_post', 'filter_title');
add_filter('postie_post', 'filter_content');

Now lets create our new function to add a custom field

function add_custom_field($post) {
  //this function appends "(via postie)" to the title (subject)
  add_post_meta($post['ID'], 'postie', 'postie');
  return ($post);
}

Finally, we let wordpress know that this function should filter any post that is sent via postie

add_filter('postie_post', 'add_custom_field');

Currently our function is really not that useful, since the key and value of our custom field are the same. However, there is really very little limit to what we can do with filters. Perhaps a more useful function would be an auto- tagger. Suppose I often write about cooking, wordpress, and latex (which I do). But when I am posting via e-mail, I frequently forget to add tags. We could write a little filter function to read the body of the post, and automatically add tags depending on the content. Here is what it might look like:

function auto_tag($post) {  
  // this function automatically inserts tags for a post  
  $my_tags=array('cooking', 'latex', 'wordpress');  
  foreach ($my_tags as $my_tag) {    
    if (stripos($post['post_content'], $my_tag)!==false)      
      array_push($post['tags_input'], $my_tag);  
  }  
  return ($post);
}
add_filter('postie_post', 'auto_tag');

I’m sure that users will come up with many other interesting filters. If you develop any you would like to share, please post them on the postie forum

Friday, August 14th, 2009

Postie 1.3.0 released

postie_200x200_7After more than a month of fixing bugs and adding features, I have decided it is time to release Postie 1.3.0, the wordpress plugin which adds many features to post to your blog via e-mail. 1.3 offers many new features over the 1.2 line of postie, including better attachment handling, better language and character set support, and easier configuration. Here is a list of the new features and bug fixes from 1.3.beta to 1.3.0.

  • Features
    • Added mpeg4 to default list of videotypes
    • Added support for KOI8-R character set (cyrillic)
    • Added support for iso-8859-2 character set (eastern european)
    • Added option to include custom icons for attachments
    • Added option to send confirmation message to sender
    • Enhanced e-mails for unauthorized users
    • Added option to send unauthorized e-mail back to sender
    • Added option to only allow e-mails from a specified list of smtp
    • servers

    • Added option to use shortcode for embedding videos (works with the
    • videos plugin http://www.daburna.de/download/videos-plugin.zip

    • Better handling of comment authors (thanks to Petter for suggestion)
    • Simplified message options (now includes an advanced options section)
    • Added filter ability for post content
  • Bug fixes
    • No longer including wp-config.php
    • If tmpdir is not writable, try a different tmpdir
    • More subject encoding fixes
    • Updated image templates, which were causing problems for cron
    • Fixed in text captions
    • Fixed SQL problems when updating options
    • Fixed name clashes with other plugins
    • Fixed custom image field

I want to thank the many users who were willing to test out new features and bug fixes by trying out the development version. in particular, I want to thank Kyle and Hab at Abilene Christian University for offering me financial support to develop some additional features for their use of postie for a course at their university. I think that other postie users will enjoy some of these new features as well.

Friday, June 5th, 2009

Releasing Postie 1.3.alpha, packed with new features

Thanks to all the users who helped me test out the 1.3.testing version of postie, the wordpress plugin which allows you to post by e-mail. I now feel that it is stable enough to call it 1.3.alpha. There are probably still some bugs, but I think that the new features probably warrant giving it a try for most users. Here is a summary of the new features and fixes:

  • Now using default wordpress image and upload handling, which means:
    • No more creating special directories for postie
    • No more confusion about imagemagick
    • Can now use the gallery feature of wordpress
    • Attachments are now connected to posts in the database
    • All image resizing uses wordpress’s default settings (under media)
  • Configuration, settings and documentation improvements
    • Completely redesigned settings page (mostly thanks to Rainman)
    • Reset configuration no longer deletes mailserver settings
    • Now including help files and faq directly in settings page
  • More media features
    • Automatically turn links to youtube into an embedded player
    • Added option to embed audio files with custom templates
    • Video options are now template based
    • Image options are now solely template based, with several new default
      templates
  • Bug fixes
    • Uploading images from vodafone phones should now work
    • Correctly handling Windows-1252 encoding
    • Correctly handling non-ascii characters in subject line

I still need your help! As I mentioned there are bound to be some bugs, and I would appreciate if you give me feedback in the postie forum. Several people have also provided localizations. That is a big help. Some of the current localizations now need some updating. If you are familiar with that, I would be grateful. A .pot file is included with the postie distribution.

I have mostly stopped development on the 1.2 branch of postie. I will be adding new updates to postie in the development version.

Below is a screenshot of the new options page for postie.

Screenshot of the new postie options page, showing the video and audio templates

Screenshot of the new postie options page, showing the video and audio templates

Saturday, May 16th, 2009

2 new versions of postie released

I would like to announce 2 new versions of my popular postie plugin for wordpress, which gives users advanced options for posting to their blog via e- mail.

The first new version is 1.2.2, which has some minor bug fixes and improvements over 1.2.1. I will continue to release several more 1.2 releases over the coming weeks with bug fixes.

The second new version is 1.3.testing, which is, as the name implies, under testing. The main new feature for the 1.3 line will be the use of wordpress’s built-in attachment uploading, and image handling. This may sound trivial at first, but it actually makes a big difference. Postie has been around since 2004. Over the last 5 years, wordpress has changed dramatically. Postie has gone through several different active maintainers, and several periods of neglect. During the times of neglect, postie got sorely out of date. I am working on bringing it back up to par with wordpress.

For example, Wordpress 2.5 introduced the gallery feature, which makes it very simply to make a nice thumbnail gallery of images in a post simply by using the shortcode . However, this depends on having a link between attachments and the post. Postie currently does not do this. In fact, postie <=1.2 uses its own custom upload directories, instead of the default wordpress directories. This makes postie more difficult to install and configure, and confusing to many users. Starting with 1.3.testing, this is no longer the case. Now postie uploads files into the default wordpress uploads directory (or whatever custom directory you have specified), and it links attachments to the post, which means you can use the gallery feature.

Postie used to have a bunch of different options for image handling, and did the image handling all itself, using either GD or imagemagick. Many users got confused by the imagemagick option. Starting with 1.3.testing, postie now lets wordpress handle resizing images — the same way it does when you would use the web-based post editor. This should simplify options dramatically, and hopefully cause much less confusion.

Also in the works, though not fully documented yet, will be the ability for postie to check multiple inboxes. This could be handy if for example, you have a multi-author blog, and you want some people’s posts to automatically be posted, while others be posted in draft form, and require approval.

I very much appreciate all the feedback I get from postie users in the postie forum, including feature requests, bug reports, praise and donations. I hope that the adventurous amongst you will take the time to download 1.3.testing and let me know what you think. As it is a testing version, I will be updating it on a fairly regular basis. Once I get some feedback from users, I will release an alpha version, and then a stable version in the next month or two.

Finally, I should mention that I posted this via postie, as well as this cooking post which shows off the gallery feature of wordpress.

Sunday, March 15th, 2009

Reading iptc captions from jpegs with imagemagick

Rob and Spencer with zebras
Rob and Spencer with zebras

Once again I found myself needing to use imagemagick to do something, and was overwhelmed by the many options. After much fiddling around, I found out some options that worked for me.

In this case, I wanted to extract iptc captions from images, so that I could then insert the caption in a webpage with php. I use Picasa to edit photos and add captions. Picasa adds in the captions in the iptc information, which is the right place to add them. To extract the caption from the image above, do the following

convert robSpencer.jpg 8BIMTEXT:-

The result should be output to standard out:

8BIM#1028=”IPTC”
2#120#Caption=”Rob and Spencer with zebras”

If you want to output to a file, simply do something like:

convert robSpencer.jpg 8BIMTEXT:filename.iptc

Now it easy to extract the caption using perl, python, php or whatever you like. For perl, we could simply pipe it:

convert robSpencer.jpg 8BIMTEXT:-|perl -ne '/Caption="(.*)"/; print $1;'

And in case you are interested, I needed to do this for the postie wordpress plugin which allows you to post to your blog via e-mail. In version 1.1.5 iptc captions will be read and displayed (if they are in the image you attach).