Blog entries tagged with "lifestream"

Contributing back to wp-lifestream

Sunday, March 8th, 2009 at 05:09pm

I have just finished sorting through the changes I have made to my install of the wp-lifestream plugin and have posted some patches to the support forum:

Hopefully they are incorporated back into the plugin.

Tagged with: , ,

Sorting in PHP is extra effort … and there is no spaceship

Monday, March 2nd, 2009 at 10:47pm

Tonight I have been hacking in PHP on wp-lifestream in order to get grouped events ordered by time. I say hacking because there is a lot of PHP I don’t know and I don’t fully know how wp-lifestream is arranged.

When I first looked into sorting the grouped events my initial thought was to do it when the group was rendered. However that involved sorting data structures, so I decided that it would be easier to perform the sort when they were retrieved from the database. This is the change I made, and I thought it had worked.

Earlier today I found that while it worked when a feed was refreshed, it didn’t work when the group was updated after an event was deleted through the interface (I uploaded one too many photos to Flickr, which I later remved). So I had to turn back to the rendering code.

A var_dump() (Perl people should think Data::Dumper) later I knew what I was dealing with: an array of associative arrays that represented each item in the group. The relevant keys being date (in seconds since epoch) and title.

If this were perl it would be an array of hashrefs and I would have sorted it like this:

@events =
    sort { $a->{'date'} <=> $b->{'date'} || lc $a->{'title'} cmp lc $b->{'title'} } 
        @events;

Not so in PHP:

  • PHP sort functions sort the array in place instead of returning a new list
  • The more advanced PHP sort functions take a callback to use instead of a block
  • I’m not using PHP 5.3 so there are no closures yet, but at least anonymous functions can be created with create_function()
  • PHP does not have a spaceship operator (<=> for numerical comparison), even though there are equivalents of cmp (strcmp, strcasecmp).

This is what I ended up with:

usort(
    $data,
    create_function('$a,$b', '
        if ( $a["date"] == $b["date"] )
        {
            return strcasecmp( $b["title"], $a["title"] );
        }
        return ( $b["date"] < $a["date"] ) ? -1 : 1;
    ')
);

To me the logic is all messed up. Because there is no <=>, it needs a == comparison first. In the usort examples this returned 0, but gave me a convenient place to call strcasecmp() for the secondary sort. But that is breaking one sort into two statements and mixing in the other sort. It works and appears to be the PHP way of doing things, but it looks wrong to me.

(And yes, create_function() takes a string. Shudder…)

Tagged with: , , , ,

My life in a stream

Thursday, February 26th, 2009 at 11:23pm

A few minutes ago I changed the home of popcorn.cx to display the output of Lifestream for WordPress, the plugin that I have been playing around with for the last week. Previously the home page was the same as the blog index except for the addition of a Flickr badge across the top.

Despite not saying anything, I have had a look at other lifestream plugins. I returned to the first one I tried because it was easy to install, it worked and it has active development. I am also planning to send in some patches for the couple of bugs that I have fixed so far.

Of the big list I initially gave, some were me not understanding the functionality correctly (the iBox stuff), some were actual bugs, some were changes to other things and some I am going to live with for now.

The changes I have made are:

  • Reverted back to an earlier version of SimplePie, the RSS parser, as I traced the problem with the Amazon wishlist back to the latest devel version. I submitted a bug report with them.
  • Modified the FeedBurner plugin to also check for ?direct=1 in the URL so the links to my own posts were not redirected through FeedBurner. (The main reason for this was because FeedBurner seems to be playing up – sometimes with feedproxy.google.com URLs and sometimes with the original feeds.feedburner.com URLs, but not the most recent posts)
  • The timezone setting for the plugin let you choose an offset from -12 to +12 (displaying adjusted time in a drop down), but that is not an offset from epoch, it is an offset from the server time. My server is in -8 while I am in +11. That is an offset of +19, yet when I chose the correct time of day it gave my -5. So all events were a day out. I tweaked the settings page to adjust the offsets based on the server zone (-4 to +20 instead) which fixed that.
  • In the rendering code I needed to apply the offset where it works out if it should display ‘Today’ or ‘Tomorrow’ instead of the actual date.
  • The code that groups all of the events for a day also needed the offset added as it was done using the SQL DATE() function which (again) uses the (MySQL) server timezone.
  • Added ordering to grouped events (so they show the same as how I added them)
  • I added LibraryThing as a feed.

I still have other changes planned, but these got me to a point where I was happy to use it on the home page.

One major change that I would like to do is to change the Flickr feed to use the Flickr API instead of just the RSS feed. A limitation of the RSS is that it is only the 20 most recent items. The other night I added 67 photos from the photo walk. Initially it was showing 40 items because the feed refreshed during the upload, but now it only shows 20 because I readded the feed and it lost the history. The API wouldn’t have that limitation: my photos page (that has been there for a while, but I don’t link to it from anywhere) uses the API to get all the photos that I have uploaded. And as you can see it also gets set information that might be good to include.

Tagged with: , , , ,

Trying out a lifestream plugin

Thursday, February 19th, 2009 at 11:11pm

As well as creating some accounts, I spend most of the evening playing around with a lifestream plugin for WordPress. Although I found a couple of different options I decided to play around with the first one I came across: Lifestream for WordPress.

Installing the plugin was pretty simple and it was jut as easy to create a new (temporary) page for it. (The redundant heading is because my theme isn’t really setup for pages)

Here are my thoughts so far (version 0.93b):

  • It automatically setup the blog feed, but as I use FeedBurner the URLs that it links to are the FeedBurner ones, not mine. It does redirect back, but it would be nice if the real URL was visible. (A list of user agents to exclude on the FeedBurner plugin is a solution for this)
  • It was nice to be able to specify my own favicon as the image for my blog feed (or any feed).
  • I might want to have more info about each post shown, tags or maybe an excerpt.
  • Adding Delicious and Flickr was straightfoward.
  • As was my Amazon wishlist after I found out that you need to get the link to the RSS feed when you are not logged in to Amazon.
  • The Amazon links end up at a 400 error page in Firefox, and doesn not work at all in IE7.
  • I would expect items that are grouped together to still be in date order, they are not.
  • I installed the iBox plugin to see what functionality that gave. It is funky, but I would probably not use it.
  • The iBox functionality does not want to turn off. No matter what the ‘Enable iBox’ option is set to, it always uses it.
  • The timezones are broken. I have told it my current time, yet right now it is saying ‘Yesterday’ for items from earlier today.
  • It was easy to add support for LibraryThing – I copied how the Amazon worked (from RSS feed) and just had to change the regex to extract the thumbnail url.
  • As well as grouping not being in order they seem to be missing items. I have LibraryThing added twice, one with grouping and the other without. On January 16 I added 19 books. When grouped only 8 books are shown, when not grouped all 19 books are shown.
  • I’m not sure if I want items grouped by “same day”. What happens if I bookmark some links in the morning and then another batch in the evening. Will they all be grouped together? I would want them in two groups – ie grouped if within 1 hour of each other.
  • I’m not sure if I like the phrasing of the labels. Instead of “Added an item to their wishlist on Amazon” I would prefer something less third person like “Item added to Amazon wishlist”.

I shall keep playing with this plugin, as well as looking at the others.

Update: A major problem now is that the two most recent posts (this one included) are not being picked up by this plugin. They are definitely in the RSS feed. Not good.

Tagged with: , , , ,