Archive for May, 2004

WordPress Plugin: Wonderping

Friday, May 28th, 2004

I have come up with the following WordPress plugin for the pingWondergeeks() function that Rick King wrote back in the day.

Please note: Wondergeeks.net is a closed system. Only users of Wondergeeks need mess with this!

pingWondergeeks() in a Plugin!

<?php
/*
Plugin Name: pingWondergeeks
Plugin URI: http://gfmorris.org/archives/2004/05/28/wordpress-plugin-wonderping/
Description: Notifies wondergeeks.net when a new, public post is made.
Version: 0.1
Author: Geof F. Morris
Author URI: http://gfmorris.net/
*/

function pingWondergeeks() {
        // Rick King
        $client = new xmlrpc_client("/ping/pingme.php?name=[domain.tld]", "wondergeeks.net", 80);
        $message = new xmlrpcmsg("", array(new xmlrpcval("[domain.tld]")));
        $result = $client->send($message);
        if (!$result || $result->faultCode()) {
                return false;
        }
        return true;
}

add_filter('publish_post', 'pingWondergeeks');

?>

Per my convention, data in [brackets] should be replaced by the user.

URL to download wonderping.php. You will also need the wonderping-syndication.zip files to support Wonderpinging.

This code should be saved as wondergeeks.php and placed in /wp-content/plugins/. Before activating the plugin in the WP admin, you need to remove the pingWondergeeks() functionality from my-hacks.php.

Future work for this plugin:

  • Passing more data through the XML-RPC array, thereby eliminating the need for the post syndication file.
  • Adding a function to pass comment data on to wondergeeks.net when comments are made using the WP Plugin API’s comment_post filter, thereby eliminating the need for periodic polling of the comment syndication files.

Thanks to Rick and to Jeff McClure for their help in developing the Wonderping functionality for WP, and to Amy for developing wonderPortal back in the day.

Stripping Unwanted Referrers from Refer Database

Friday, May 28th, 2004

If you use Dean Allen’s wonderful Refer PHP script to track incoming referrers as I do, you may come across some unwanted referrers that cannot be blocked from within refer.php.

I was specifically having issues with a cached Google reference to an entry on GFMorris.com that, in a previous life, had a popup photo of my friend Samantha. Google had ’samantha.jpg’ cached, but their incoming references to the photo are, somehow, borked. Unfortunately, Google still treats this as a valid incoming referral, probably because the photo itself hasn’t been taken down.

There must be 15 or 20 people a day who hit that image through images.google.com, and well, I was getting annoyed. So I made myself take the time to learn how to write a shell script to call a .sql script. What follows is the result of that.

.sql Script to Strip Unwanted Referrers

The .sql script is pretty straightforward: connect to the database, run a nice DELETE FROM command, then quit.

CONNECT [database];
DELETE FROM refer WHERE page = '[unwanted referrer]';
quit

Per my convention, items in [brackets] should be replaced by the end-user of the script.

If I had multiple pages that I wanted stripped, I’d just have multiple DELETE FROM commands.

Shell Script to Run the .sql Script


#!/bin/csh -f

# Log in to MySQL and run striprefer.sql.

mysql -hlocalhost -u[user] -p[password] < striprefer.sql

N.B.: This assumes that striprefer.sql and the attendant shell script—which I’ve named striprefer—are in the same directory. If they are not, you will need to reference that from the user root (e.g., ./sql-scripts/striprefer.sql).

You can’t have the shell script run the SQL commands, unfortunately. I found that out the hard way.

How I Use ./striprefer

I use a cron job to run this every hour. That’s probably overkill, but as I said, I’m using these scripts to stop an annoyance, so I’ll deal with the attendant overhead.