A-  A  A+ RSS Feed

Deep Thoughts by Robert Felty

thoughts on wordpress, latex, cooking et alia

Archive for August, 2009

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

Tuesday, August 18th, 2009

Blogging with LaTeX

The first question on reader’s mind must be — why use LaTeX to blog?

Well, I have a pretty specific instance in mind, but I can imagine that others might be interested as well. This fall I am teaching a course on computational corpus linguistics at CU Boulder. I like to have some materials online for the students, such as the syllabus, course notes, etc. I thought about setting up a simple webpage, but then I decided instead to use wordpress, because it would give me extra functionality, such as auto-generating rss feeds, and with some plugins, would allow me to notify students via e-mail when I post lecture notes or slides, or homework tips. The one drawback I could see is that it would be hard to update the syllabus throughout the semester, as I tend to change the calendar some throughout the semester. Then I thought that maybe I could hack up a quick xml-rpc solution to the problem, and about an hour later, I had it done. All I needed was the Wordpress::API perl module from CPAN.

Now I have a handy little publish script which first compiles my syllabus as pdf, then compiles it as html using plasTeX. Then I run it through tidy for formatting and hack in a few more things. Then I update the syllabus page on the course blog via xml-rpc. Finally, I rsync the pdf to the server. And with the post-notification plugin for wordpress, students will get an e-mail when the syllabus is updated.

Here are the scripts:

publish

#!/bin/bash
# this script compiles a pdf version, an html version, and then copies it to my
# webserver

# compile as pdf
pdflatex syllabus && pdflatex syllabus

# compile as html
plastex  -c syllabus.cfg syllabus
# clean up code a bit
tidy --show-body-only true --ascii-chars true  -asxhtml --input-encoding utf8 --output-encoding ascii -wrap 0 -indent --tab-size 4 syllabus/index.html > syllabus/syllabus.tmp

# add in link to pdf version in the html version
cat pdflink syllabus/syllabus.tmp > syllabus/syllabus.html

# update the syllabus page via xml-rpc
./updateSyllabusPage.pl

# upload the newest version of the pdf
rsync -avzu syllabus.pdf robfelty.com:/var/www/html/robfelty/teaching/ling5200Fall2009/ling5200Fall2009-syllabus.pdf

updateSyllabusPage.pl

#!/usr/bin/perl -w
use WordPress::API;

# get new syllabus content
my $contentFile = 'syllabus/syllabus.html';
open(CONTENT, $contentFile);

# slurp in content
$content = do {local ( $/ ); <CONTENT> };

my $w = WordPress::API->new({
   proxy => 'http://robfelty.com/teaching/ling5200Fall2009/xmlrpc.php',
   username => 'myusername',
   password => 'mypassword',
});

my $page = $w->page(3);

$page->description($content);
$page->save;

Finally, if you want to see how I customize content for pdf and html separately, you can check out the LaTeX source file

Saturday, August 15th, 2009

Salad Night

White bean, fennel, and red onion salad with honey miso dressing, paired with a lettuce, tomato and feta salad

White bean, fennel, and red onion salad with honey miso dressing, paired with a lettuce, tomato and feta salad

Last night I made 2 salads for dinner, which is quite uncommon for me. As a vegetarian, I often complain that all I get to eat is salad, but I don’t mind when the salads are filling and nutritious. That is, they have to have some protein. The first salad I made was a new recipe from the Bold Vegetarian Chef of white beans with fennel, red onion, and garlic, with a honey miso dressing. The recipe originally said to roast the fennel, red onion, and garlic (a whole head of garlic!), but I didn’t want to heat up the kitchen for an hour roasting, so I sauteéd instead, and only used 2 cloves of garlic. The dressing was quite tasty. I used golden balsamic vinegar instead of white vinegar as the recipe suggested.

The second salad was nothing too crazy — simply lettuce with fresh tomatoes out of the garden and some feta cheese, with my usual oil and vinegar dressing.

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.

Wednesday, August 12th, 2009

New Orleans sweet potato hash

New Orleans sweet potato hash

New Orleans sweet potato hash

Yesterday I tried another new recipe, this time one I threw together myself. It was kind of a “what’s in the fridge” recipe. I had some frozen okra and lima beans that had been taking up space in the freezer for several months, and I also had 2 peeled sweet potatoes that needed to be used. I sliced the sweet potatoes thinly and sauteéd them in olive oil, then added some green pepper and chopped onions we had in the fridge as well. Then I added the okra and lima beans, along with some seasoned salt, Ms. Dash, coriander, cayenne pepper, and salt. For serving I topped with freshly diced tomatoes out of the garden and avocado chunks. I decided to call it New Orleans hash mostly because of the okra.

It turned out ok, but not great. It was definitely quick and easy. Clare and I both decided (or were reminded) that we don’t care for lima beans that much. Clare also thought that it could use some vegan sour cream or some kind of sauce. We definitely like the sweet potato black bean hash recipe from the Moosewood New Classics cookbook. It would be nice to have another sweet potato dish that in the repertoire that is just as tasty, but different enough from that recipe. I think next time I might try a different kind of bean, some sort of sauce. It might be good to put in a little vegetable broth near the end, and save the okra for last as a thickener.