Text-Link-Ads is a nice service which I use to help pay the bills for running this site. They just released a new version of their WordPress plugin which I use to put their adverts on this site, so I installed it but in doing so it overwrote a couple of changes I’d made to the old plugin. I had made those changes as I like the service and I definitely like the additional income1, but I don’t like how the plugin makes the ad links less than obviously ads. So my changes in the plugin add a specific class which I can then style via CSS. Since I don’t want to have to keep redoing my customizations from scratch each time they release the plugin; I’m posting the code changes I make here.

Under function outputHtmlAds(), I changed the following line of code from:
echo "\n<ul>\n";</ul>

to:
echo "\n<ul class=\"tla_sponsor_link\">\n";</ul>

Also under function returnPostAd($postId), I changed:
return "\n\n<em>".$prefixes[$prefixIndex].":</em> $ad->before_text <a href=\"$ad->url\">$ad->text</a> $ad->after_text";

to:
return "\n\n<div class=\"tla_sponsor_link\"><em>".$prefixes[$prefixIndex].":</em> $ad->before_text <a href=\"$ad->url\">$ad->text</a> $ad->after_text</div>";

Side note: TLA, you guys should change the Our Blog to be called something else as the link doesn’t actually take users to your blog.

1 I don’t make enough from these ads to get rich mind you. Just enough to cover the costs of running CoffeeBear.net and maybe a cup of good coffee from my local coffee shop.

Dashboard Hack 0.0.3

Akismet is a popular comment, trackback, pingback spam blocker. Originally it was developed for the WordPress blogging platform; it has since been extended to work on a variety of blogging and forums systems. However the only part of it I really care about is the WordPress plugin as it is one of the ways I protect this site from spammers. Akismet works great1 but there is one thing the developers of Akismet have never seen fit to do which drives me bonkers. Which is to say the only place the Akismet plugin shows you how many comments it has in the spam moderation queue is on the spam moderation queue page. And yet they put some stats for Akismet right there on the WordPress dashboard. In ages long past, I cobbled together a small hack to display those moderation numbers, when I upgraded my site to a more current version of WordPress my hack broke.

This morning I finally fixed it. People more clever than myself could make this into a full fledged plugin, but this little hack is good enough for me. To do this:

  1. Download a copy of the Akismet plugin for WordPress
  2. Decompress the zip file
  3. Open the akismet.php file in your favorite text editor2
  4. In akismet.php, search for “function akismet_stats()”. It should be around line 510.
  5. In the akismet_stats function, under the line reading echo '<h3>'.__('Spam').'</h3>'; add the following code:
    $spam_count = akismet_spam_count();
    $link = 'edit-comments.php';
    if ($spam_count) :
    print "<strong><a href="$link?page=akismet-admin" title="Click here to see the moderation queue">Spam in moderation ($spam_count)</a></strong>\n";
    endif;
  6. Save your changes.
  7. Uploaded your edited copy of akismet.php to http://yourblog.com/wp-content/plugins/akismet/ and then follow the normal instructions for installing/activating the Akismet plugin.

With this small hack in place, when Akismet traps some comment spam in its moderation queue the WordPress dashboard will display a link under the Spam in the Latest Activity box. The link will say “Spam in moderation (x)” where x is the number of items in the spam moderation queue. Since WordPress likes to occasionally mangle the display of code in posts, I’ve created a text file with my changes to the akismet_stats function. You download that file here.

Update 2007-04-22: As to be expected, it didn’t take the spammers long to generate some sample data for me to create a screenshot of my hack.  Enjoy!

1 Particularly with the Bad Behavior anti-spam plugin added to it.
2 E.g. Kate

As part of my upgrading to the latest/greatest version of WordPress, I switched over to using the Now Reading plugin from AMM. I switched because development on AMM seems to have come to a complete halt and it was acting somewhat flaky prior to the upgrade. One of the big problems with switching over was I didn’t want to have to manually enter in all books I’d already read and rated. As Now Reading supports storing so much more data, I had to write a bit of custom SQL to import my existing info. It’s not a great solution, mostly because AMM didn’t store all of the same info (e.g. date entered, started and finished).
INSERT INTO wp_now_reading(b_added, b_started, b_finished, b_title, b_nice_title, b_author, b_nice_author, b_image, b_asin, b_status, b_rating, b_review)
SELECT amm_dateadded, amm_dateadded, amm_dateadded, amm_title,
REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(LCASE(amm_title), ',', '' ), ')', '' ), '(', '' )
, ' ', '-' ), '...', '-' ), ':', '-' )
, '!', '-' ), '?', '-' ), '&', '-' )
, '\'', '' ), '--', '-' ), amm_author, REPLACE(REPLACE(REPLACE( LCASE( amm_author ) , '.', '' ) , '&', 'and' ) , ' ', '-' ), amm_smallImageURL, amm_asin, 'read', amm_rating *2, amm_userComments
FROM wp_amm amm
WHERE amm_ProductGroup = 'Book' AND amm_asin NOT IN (SELECT b_asin FROM wp_now_reading);

This short script copied over all my books for me and got everything setup as well as could be expected given the differences in the data. Below is a list of the assumptions I made in writing this script to convert to Now Reading:

  • AMM only stores one date, so I used that for all dates on the books I copied over.
  • The above script limit itself to books and skips any already in your wp_now_reading table.
  • Now Reading has additional fields the title & author. I’m not sure what the “b_nice_author” field is used for, but the “b_nice_title” is used when you go to edit a specific book. The format of the “b_nice_” fields seems to be to replace anything other than a letter or a number with a hyphen and to have all the letters be lower case. I tried to make sure I did the same with my script, however you may need to double-check your data before running this to make sure I didn’t miss a symbol you used.
  • I marked all the books I was copying over as “read”.
  • AMM only allowed ratings of 1 – 5; while Now Reading allows 1 – 10. So when I copied the ratings over, I doubled them.

NOTE: If you have questions about this script, post them in the comments here. Keep in mind that I’m not providing full fledged support for the script and if you don’t know how to run this without asking, then you probably shouldn’t be messing with it. Also, if you’re really going to try running this script, then for god’s sake backup your database FIRST!