Chip's Tips for Developers

Contains coding, but not narcotic.

A couple of relieving fixes for Jerome’s Keywords 2.0 beta

September 8th, 2007 1:49:11 pm pst by Sterling Camden

Since I haven’t heard from Jerome in quite a while, I took it upon myself to fix a couple of nagging problems in the Jerome’s Keywords plugin for WordPress:

  1. When editing, moderating, or deleting comments, the tags on the post get deleted.
  2. Some users get a nasty duplicate alias SQL error due to the combination of other plugins with JK.

The download below should fix both of those.  If/when Jerome incorporates these fixes into his next version, I’ll take down this copy and point to him instead.

In the first case, I removed the action hook for ‘edit_post’.  This gets triggered when the comment count changes, and the action for it deletes all tags and re-adds them from the request.  Unfortunately, if the request doesn’t contain any tags (as in the case with editing comments) you lose your tags.  It turns out that the ‘save_post’ and ‘publish_post’ actions are sufficient for handling cases where you can edit the tags.

In the second case, it seems that the ‘posts_join’ action gets triggered more than once.  So I changed this action to build the join clause we need in a separate variable, then make sure it doesn’t already exist in $join before appending it. I made a similar change to posts_where as well.

UPDATE 9-17-2006: Found a bug in my correction for the duplicate alias error, and applied the changes to the beta 3 version.

Happy tagging!

Posted in PHP, Web, Wildly popular, WordPress | 7 Comments » RSS 2.0 | Sphere it!

Tag cloud widget for WordPress gets all standardsy on you

May 18th, 2007 10:51:08 am pst by Sterling Camden

Call me clueless, but I did not know until I found out from Jenn that the <FONT> element has been deprecated and will not validate XHTML 1.0 strict DTD.  The keywords-tagcloud widget for WordPress uses that element with a SIZE attribute to scale the tags in the cloud (extends wrists, awaiting slap).

Far be it from me to fly in the face of progressing standards, so I have just released version 2.3 of the keywords-tagcloud widget that uses a STYLE element specifying font-size instead.  You can get it by pressing the button below.

Besides averting a visit from the W3C police, using the font-size style provides much more flexibility on how the font is, um, sized.  You got pixels, percentage, etc. to choose from.  So I added a field to the widget’s control panel where you can specify what units to use.  The scaling maximum/minimum fields in Options/Jerome’s Keywords/Tag Cloud Display can be used to control the range of units to apply.  Unfortunately, these values get rounded down to the nearest integer, so “em” doesn’t work well for units.  Also, CSS units don’t provide an exact mapping for the old font size attribute, but “ex” is pretty close, so I made that the default.  However, I found that “%” with a range of 70-250 looks nicer for my theme, and you can see that on the right sidebar here.

If you do your own styling of the widget, make sure you read the upgrade notes.

Thanks, and keep on tagging!

Pingback to all previous posts on this subject for the sake of those who subscribe to comments.

Posted in CSS, PHP, Web, Wildly popular, WordPress | 24 Comments » RSS 2.0 | Sphere it!

I’m tagged! Bug fix for keywords-tagcloud widget

February 2nd, 2007 10:36:24 am pst by Sterling Camden

Aoyoyo reported an error in my keywords-tagcloud widget for WordPress. That widget requires Jerome’s Keywords version 2.0 to be installed and activated. Lazy me, I wasn’t checking for the opposite case, which results in a “Fatal error: Call to a member function on a non-object”. Here are my wrists. Slap ‘em hard.

jkwarning

Version 2.2 (download below) corrects this problem. If Jerome’s Keywords 2.0 is not activated, you now get a warning message displayed in the Presentation admin panel for the widget and also in place of the tag cloud display.

Version 2.0 of Jerome’s Keywords wraps the plugin’s API in a global object. If the plugin isn’t activated, the global is null. So, I only needed to add a simple test for is_object($JKeywords) to respond appropriately, instead of spilling my guts on your blog.

UPDATE: new version with improved font sizing here

Posted in PHP, Web, WordPress | 24 Comments » RSS 2.0 | Sphere it!

Improved caching on tag cloud widget for WordPress

January 3rd, 2007 6:09:27 pm pst by Sterling Camden

Version 2.1, for use with Jerome’s Keywords plugin version 2.

I’ve been putting off updating the tag cloud widget for some time, because Jerome had indicated that he would include it in his plugin in a future version. That hasn’t happened yet, so I wanted to add a couple of new features now:

  1. You can now control the expiration of the cached display. It still defaults to 900 seconds, but you can alter it to be anything you wish.
  2. Besides releasing the cache when the widget controls are updated, it also releases the cache when a post is edited, saved, or published.

Please let me know if you experience any difficulties, or if you have suggestions for further enhancements.

Happy tagging!

UPDATE: added error check for when Jerome’s Keywords 2.0 is not activated. Get the latest version here.

Posted in PHP, Web, Wildly popular, WordPress | 12 Comments » RSS 2.0 | Sphere it!

WordPress tag cloud widget version 2.0 for Jerome’s Keywords 2.0

September 6th, 2006 11:04:31 am pst by Sterling Camden

vapourtrailsJerome has released a 2.0 beta version of his famous Jerome’s Keywords plugin, on which my tag cloud widget is based. Some of the functions I used in my widget are no longer available, so the previous version of my widget will not work with it. Thus, I have updated the widget, which you can download below.

Jerome seems to have fixed the problems in the plugin itself that I mentioned here and here. When he releases this version from beta, I’ll remove my corrected versions. I’ll go ahead now and add updates to let people know about the beta.

tagcloudoptionsJerome also included all of my widget’s options (other than Title) in a new “Tag Cloud Display” section of the plugin’s options. So, I have removed those options from the widget option panel. Please go into “Options/Jerome’s Keywords” and update your tag cloud options there.

Note also that this version of the widget is not compatible with earlier versions of the plugin. If you need a widget for earlier versions of Jerome’s Keywords, get version 1.1 of the widget here.

UPDATE: Get the latest version with improved cache control here.

Posted in PHP, SQL, Web, Wildly popular, WordPress | 67 Comments » RSS 2.0 | Sphere it!

Magic quotes correction for Jerome’s Keywords WordPress plugin

August 4th, 2006 9:42:58 am pst by Sterling Camden

Mike Koepke reported a problem he was having with the Jerome’s Keywords plugin when he searched on a tag that contained a single quote:

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's Creek' OR jkeywords_meta.meta_value LIKE 'Wilson's Creek,%' OR jkeywords_meta.' at line 1] SELECT DISTINCT * FROM wp_posts LEFT JOIN wp_postmeta AS jkeywords_meta ON (wp_posts.ID = jkeywords_meta.post_id) WHERE 1=1 AND post_date_gmt

I was unable to reproduce the behavior on my version, but it appears from the error message that the quote is not getting “quoted“. So, I added the following line to the “keywords_postsWhere” function in jeromes-keywords.php:

$keyword = str_replace("'", "''", $keyword);

Using the simple quote-doubling escape route. This solved the problem for Mike, but it didn’t work with my version, and from the resulting error message I could see that in my version the quote was already being escaped via a backslash (\). Modifying my fix to use backslash quoting didn’t work for me, either, because then the backslash gets backslashed.

Comparing versions, I was using MySQL 3.23.54 with PHP 4.4.1. Mike is on MySQL 4.1.14 and PHP 5.0.4. Then Mike tried this out on a local server with MySQL 5.0.22 and PHP 5.14, and got the same results as I did. So we both concluded that something got broken in MySQL or PHP between my early version and Mike’s live version, but has since been fixed again. Or was there some option that needed enabling on Mike’s live server? My Google searches for an explanation of this phenomenon were fruitless.

Clusty to the rescue. Clusty lead me to this post. It turns out that PHP has a runtime option, magic_quotes_gpc, that is enabled by default. This option automagically escapes quotes, backslashes, and nulls in a GET, POST, or cookie with a backslash. Bingo.

As with most (all?) PHP options, you can query the setting of magic_quotes_gpc at runtime via (20 guesses?) get_magic_quotes_gpc(), natch. So I changed my fix as follows:

if (!get_magic_quotes_gpc()) {
$keyword = addslashes($keyword);
}

You can download the corrected version below. If Jerome would like to adopt this fix in his master version, I’ll take down my copy and point to him instead. Johannes, you might want to implement a similar test in your Jerome’s Keywords Manager plugin. Sorry to give you one more place to go after your “final destination”.

UPDATE: Jerome has released a 2.0 beta version of the plugin that appears to address this issue. Mike Koepke, can you verify? If you’re using my tag cloud widget, you’ll need version 2.0 of that as well.

Posted in PHP, SQL, Web, Wildly popular, WordPress | 7 Comments » RSS 2.0 | Sphere it!

Correction for Jerome’s Keywords plugin for WordPress

July 14th, 2006 8:31:34 am pst by Sterling Camden

I use the Jerome’s Keywords plugin for WordPress to do tagging on my blogs. I love it, but it has one problem: if you search on a tag that is contained within another tag, you get the aggregate results of both tags. That’s because Jerome uses a SQL WHERE clause containing LIKE ‘%keyword%’ to match tags that are in a comma-delimited list in the metadata value field.

I left a comment on Jerome’s blog about this issue, but it looks like it never even made it past moderation. In fact, no new comments on this post since May. Where’s Jerome?

I mentioned this problem to Johannes Jarolim, author of the Jerome’s Keywords Manager plugin. Johannes came up with the correct WHERE sub-clause (value LIKE ‘keyword,%’ OR value LIKE ‘%,keyword’ OR value LIKE ‘%,keyword,%’ OR value = ‘keyword’) and implemented that in his plugin. But alas, that did not help my widget, which relies on the ?tag=keyword link operation provided by Jerome.

So, I felt like my best alternative would be to correct Jerome’s plugin and post it here. If Jerome adopts this correction (or something equivalent) and lets me know about it, I’ll take down this download and point over to his site instead.

UPDATE: I made yet another correction to this plugin, so head on over here for the latest and greatest.

UPDATE: Jerome released a 2.0 beta of the plugin that corrects this problem. Get the whole scoop.

Posted in PHP, SQL, Wildly popular, WordPress | 12 Comments » RSS 2.0 | Sphere it!

Tag cloud sidebar widget for WordPress

June 14th, 2006 7:29:40 pm pst by Sterling Camden

On the advice of Alec Saunders, I enabled tagging in my blog using the Jerome’s Keywords plugin for WordPress 2.0. It has a lot of nice features and good documentation. It even provides a great function for generating a tag cloud, where you can render tags differently depending on their usage without much trouble. However, it doesn’t provide a sidebar widget, and you can’t just plunk PHP code into a text widget, because it isn’t executed on the server. So, I decided to write this little widget that you can download below.

Installation and configuration instructions are included in the readme.txt file enclosed.

UPDATE: I added caching to improve performance, using the default expiration of 900 seconds (15 minutes). That saves a database SELECT and quite a bit of processing. You can release the cache by saving changes to the widget in the WordPress dashboard.

UPDATE: I have corrected a couple of problems in the Jerome’s Keywords plugin itself. You can get that here.

UPDATE: Jerome released a 2.0 beta version of the plugin. To get a compatible version of the widget, go here.

Posted in PHP, Wildly popular, WordPress | 4 Comments » RSS 2.0 | Sphere it!

Better Tag Cloud