Posts By Mike

Shashin 1.2 Now Available

Update: There were some bugs in this version, please see my post on version 1.2.3 for the latest update. Also go there for any comments or questions – I’ve turned off further comments on this post.

You can download the latest version of Shashin from wordpress.org. I had to rush this out the door, since Shashin 1.1 doesn’t work with WordPress 2.3.3. That means I didn’t do all the testing I usually do before a release. If you have any problems, please post a comment here (note I turned off comments on Post to Post Links II error: No post found with slug "shashin-wordpress-plugin", as the page was just getting way too long).

The two big new features happen to be the two most requested features: displaying groups of album thumbnails, and the ability to add or sync all your Picasa albums at once. For the album thumbnails, they are displayed in a table with a number of columns you can specify, you can choose to display either only certain albums, or all your albums with your choice of sorting preference, and you can choose whether to display the album titles and locations (if you specified a location in Picasa, Shashin will include a Google Maps link as well). Syncing all your albums at once will make using Shashin easier for those who maintain a lot of Picasa albums.

Another feature I added is smarter album syncing. Now if you move a photo from one album to another in Picasa, Shashin will preserve its original photo key when it syncs the albums. Before I made this change, the old photo key would be deleted and the picture would get a new photo key, thus breaking any Shashin tags that referred to the old key. That problem won’t happen anymore.

The biggest piece of work in this release wasn’t the new features though. It was writing a parser for the Picasa feed from scratch. I got tired of Shashin breaking every time WordPress changed its RSS tools (which seems to happen with almost every new version – that’s what broke Shashin 1.1 when WordPress 2.3.3 was released). Instead of using something big like Magpie, I instead wrote a very lean XML parser – not counting comments, the whole thing is less than 60 lines of code. It uses Snoopy to load the feed, since I can’t rely on PHP functions like fopen being configured across different servers for URL fetching (Snoopy comes with WordPress, so Shashin loads it from there). I would have loved to write the parser in PHP 5, which has a great new set of tools for XML, but a lot of sites out there are still on PHP 4 (including mine), so the parser is PHP 4 friendly.

I’ve noticed my old rss-functions-mod.php file being re-used by folks in other WordPress plugins. That code doesn’t work with the new version of WordPress (I didn’t bother to investigate why, since I was done working on the new parser anyway). If you’re someone who’s used that file in your plugin, you may want to switch to the parser that’s included with Shashin 1.2. But you’ll need to make some adjustments to your plugin, as the data that comes out of the new parser is in a different structure.

Stay tuned for version 1.3, probably in a few weeks. I’m planning to include Highslide integration! 🙂

Shashin 1.1 Incompatible with WordPress 2.3.3

WordPress 2.3.3 was released about a week ago. I haven’t upgraded yet, but I just heard from a Shashin user that Shashin isn’t working with the new version. It sounds like it actually breaks the whole site – that you’ll only get a blank page until you deactivate Shashin. I will install the new WordPress version today so I can start investigating what the problem is.

I actually have version 1.2 of Shashin almost ready. One major change is that I completely rewrote the parser for the Picasa RSS feed (so it’s no longer relying on my hacked version of the old WordPress rss-functions.php file). If I’m lucky, whatever the problem is with 1.1’s compatibility is already gone in my 1.2 code. But I’m not counting on it 😉 .

Shashin Rocks

My Shashin plugin recently made the 20+ WordPress Plugins that Rock list by Jayson Akers. I have a slew of new features I want to add, but unfortunately I’m wrapped up in other projects right now (i.e. projects that can pay the bills). But an update will be coming – give me about another month.

Managing Objects and Database Connections in PHP Sessions

If you’re not familiar with PHP sessions and how to use session variables, getting up to speed isn’t easy. What makes it difficult to learn is that it’s hard to make sense of the online resources. That includes php.net, which has a ton of little pink and yellow boxes on its pages about sessions, with caveats about important changes between PHP versions. The “right way” to use sessions has changed with successive releases of PHP, and many of the old ways are now either more trouble than they’re worth, or simply may not work at all anymore. Throw in the changes with PHP classes (if you want to store objects in sessions), and the multiple possible ways your server can be configured for handling sessions, and it gets even more confusing. So any tutorial you read that’s more than a couple years old may lead you astray.

I’m not going to try covering all the possible variations, but here’s what works for PHP 4.3.9 with a default session configuration (see the Runtime Configuration section of that page if you want to see the details), using MySQL and Apache. I’m fairly certain this all works in PHP 5 as well, but I haven’t tested it.

  • session_start: you need to call session_start() on every page (you can save yourself from repetitive coding by putting this and other page startup code in an include file). Note that by default it stays with the session id that’s automatically set when the user first starts his session – you don’t need to pass in the session id (the php.net documentation could be clearer on that point).
  • Requiring your class files: for any objects stored in session variables that you use in a page, you will need to call require_once() on their class files before your call to session_start(). This is necessary for PHP to know how to map the data in the session variable to the class (another good candidate for reuse in an include file).
  • session_register: you don’t need to use session_register() anymore. Just use the $_SESSION array to store your variables. I found a lot of online discussions from a few years ago about session_register being essential when putting objects in sessions – that doesn’t apply anymore.
  • serialize: if you just want to store your objects in sessions (not in files or database tables), you don’t need to serialize() them yourself, and you don’t have to worry about losing the object type or access to its methods.
  • mysql_connect: at first I tried putting a call to mysql_connect() in a startSession method of a database class I created, thinking I’d only need to call it once for the user’s session. That doesn’t work: the connection is lost after the http response for the page is complete. Trying to store the connection in a session variable does not magically persist it for the user. mysql_pconnect() is not the answer either, for reasons outlined in the php.net Persistent Databaase Connection page. The answer is to simply make connections as needed for each page – old connections will be reused if they’re available, so this doesn’t necessarily lead to an unnecessary proliferation of connections. You can even call mysql_connect() repeatedly on a page and it will by default re-use the connection that was initially opened on the page. This is nice if, like me, you’ve written a database class and you have a generic query method in it: you can call mysql_connect() in your query method, and not worry about how many times it’s being called by a particular page.

I should point out all of the foregoing is for garden variety purposes: managing connections for high traffic sites, security, scalability, and dealing with users who don’t accept cookies, are all beyond the scope of this post.

So, in my code I have no calls to session_register() or serialize() (as they’re not needed for storing objects in session variables), and in my database class’s query method, I call mysql_connect(). The main things to remember are requiring your class files before calling session_start(), and doing so on every page.

Shashin 1.1 Now Available

My blog has been sadly quiet for the past month, but I’m now ready to resume my blogging duties. Today I’ve just a got a brief announcement though: Shashin 1.1 is now available for download at wordpress.org. I’ve added the most requested feature – widgets. Shashin now has a widget available for each of its main functions (displaying single photos, album thumbnails, random photos, newest photos, and tables of thumbnails). And for those not using widgets, I simplified the code needed for adding Shashin to your sidebar manually.

I don’t use widgets myself – since my sidebar is just a thin sliver of nav elements across the top – but it was fun learning how they work. The widget admin forms are great because I can include things like a drop down menu listing the possible image sizes, so you don’t have to keep referring back to the FAQ. The one thing that struck me as weird while studying other widgets is that all the other widget authors seem to have something against including a submit button in their widget admin forms. That’s just bizarre and not user friendly at all – they’re just counting on you hitting “enter” after filling out the last field in form. It’s probably because the couple of tutorials that are out there have just a single text input field (where a submit button is arguably less important), so everyone just blindly followed them, even when making a longer form. I’m happy to say that my forms include nice, friendly submit buttons 🙂

Shashin 1.0

Shashin 1.0 is now available. New features include an options menu (so you don’t have to touch the code to change settings), improved random image and thumbnail display features, the ability to show the latest uploads to your albums, and UTF-8 support. Thanks to everyone who helped with the beta testing (the beta version was downloaded exactly 100 times).

Shashin is available at the WordPress plugin repository now, so you can get it there as well. The plugin repository requires a readme.txt file with an FAQ section. To avoid maintaining two sets of documentation, I rewrote my Shashin page to also follow the FAQ format.

If you’re crazy for code, you can read the PHPDoc documentation.

“Less Is More” Theme, with CSS Drop Down Menus

New design, with drop down menus

New design, with drop down menus

 

If you do a Google search for “CSS drop down menu”, you’ll find a number of examples that have been provided by well meaning folks. I wasted a lot of time with them. With only one exception, they were either:

  1. Poorly modularized, in that if I included their stylesheet and javascript files, and then dropped their menu markup inside a div in my design, my page would explode into a million pieces, or
  2. They relied on 100+ lines of javascript, which seems really unnecessary in the age of CSS (except for IE’s lack of CSS support for hovering with anything other than an anchor tag), or
  3. If I scrolled through the submenu items, the hover color on the top menu item would disappear, resulting in a goofy menu display (that’s a problem most don’t know how to solve without javascript though, including me).

The one exception was the CSS Express Drop Down Menu, which was the seventh or eighth one I tried. It has only one small javascript function (to patch the IE hover problem), the xhtml and css aren’t unnecessarily complicated, and the css is very well documented. It even includes special handling for the notorious IE5 for Mac. After dropping in the code, I just had to spend about 20 minutes tweaking the css for fonts, colors, and padding to fit my design, and now I’m good to go. If you’re looking for a good CSS drop down menu, this is the one to use!

Shashin – A WordPress Plugin for Displaying Picasa Photos

My Picasa plugin for WordPress is now available. I’ve been working on it for months now and I’m pleased to have it in good enough shape for others to try out. Please keep in mind I’m the only one who’s used it so far, so if you encounter any problems, please let me know, and I’ll fix it. You can get it at my Shashin page, where you’ll also find detailed instructions.

I had intended to make it available exclusively at the WordPress.org plugins site, as that’s where it would reach the widest audience. But I filled in their “add a plugin” form almost a week ago and haven’t heard anything back yet, so at least for now I’m making it available here.

“Less Is More” WordPress Theme

The new design I'm working on for toppa.com

The new design I'm working on for toppa.com

 

I’ve been busy working on a new design for toppa.com – this is a screenshot of it. My site is cluttered with a ton of links that really are more distraction than anything else. My design is inspired by the simple and clean open source “Cash” design. As you can see, I want to go even simpler (the CSS for Cash is also needlessly complicated, so I simplified that too). I’ve been using a lot more photographs in my posts over the past year, so I want to maximize the available width for pictures, but still be friendly to low-res monitors. Put all that together, and it means the sidebar has to go.

One part I still have to work on is rollover menus for the top navigation. The header area can be overlaid with a tag cloud, blogroll, etc. if someone wants to look at them. Otherwise, they’re neatly hidden away. After that I need to convert it into a WordPress theme, but I think that part will be easy.

Let me know what you think. If there’s any interest I’ll be happy to make a downloadable version – just leave me a comment.

Shashin – A WordPress Plugin for Displaying Picasa Photos – First Cut

I haven’t posted recently, but that doesn’t mean I haven’t been working on my blog.

I’ve completed a first-cut version of a plugin for displaying Picasa photos in WordPress. I just tested it with Post to Post Links II error: No post found with slug "lews-wedding" if you want to see. I named it Shashin (pronounced sha-sheen), which is Japanese for photograph. I started working on it while I was in Japan, so I thought it deserved a Japanese name, and shashin sounds cool.

The mPicasaIntegration plugin I’ve been using so far has some real drawbacks. One is that it copies down the pictures from Picasa to your web server, so you’re eating up disk space (to be fair, the author did this because he was concerned at the time about what was allowed under the Picasa user agreement, but it’s pretty clear now Google is happy to let folks re-display their Picasa images). You also can’t adjust the size – every image is 640×480. In contrast, my plugin displays the images directly from Picasa, which means once I move all my pictures from my old Coppermine installation to Picasa, I can get an account for my site with a lower disk quota, and a smaller monthly bill 😉 . Also, Shashin can display images in any of the 17 sizes supported by the Picasa API. Picasa’s on the fly scaling is pretty good – much better than the browser scaling I had to use with mPicasaIntegration.

I’ve also given it some nice display options – you can choose to have the photo link to the Picasa image, and optionally display the photo description as a caption (I eventually gave up on finding the “correct” way to caption an image in xhtml and just went with a div set to block display). Getting the xhtml to work the way I want has been driving me crazy though, due to WordPress’ autoformatting. For example, WordPress sticks a line feed and a break tag between nested divs, even if there’s no line break in my code. I set the priority of my content filter to the maximum level, to try overriding the autoformatter, which helped with some problems, but not all of them.

I’m not quite ready to share it yet, mainly because I don’t have an admin page done yet for the photo table (I’m parsing the Picasa RSS feed on demand and then syncing it to local tables). I’d also like to offer some options beyond just displaying single images…I hope to be able to invite folks to beta test in a couple weeks.

I spent a fair amount of time on the architecture of the code. It’s all OO, and I went a bit over the top with the abstraction. That made the setup time longer but is now paying off, as I can add features without having to do a whole lot more coding. I also now have a good foundation of generic functionality for building other plugins (I have another in the works for managing real estate listings, for my dad).