Archive for March, 2007

creating another plugin: reply to from admin panel

Lorelle at Wordpress blogged about a plugin (or WordPress feature) she wants: the ability to reply directly to a comment from the Admin comments page. When I spotted that, I thought I’d give it a go, because it seems like a short and sweet plugin to have. My first concept of the design is to add a Reply To link that sends you directly to the proper spot on the post page to put in the reply. This does not resolve the “backing up” problem to return to the original Admin page; I will address that in a second version. For now the problem can be worked around simply by opening the reply to link in a new tab and then closing that tab when returning to the admin page. Since all the major browsers now have tab functionality, this seems reasonable.

However, as I looked through Wordpress’ structure, I realised that the anchor, or name for the post comment section of a post is dependent on the name that the theme’s author gave it. In other words, we don’t always know what the name/id of the reply form (comment form) is for a post in a given theme. Mine is #postcomment; the popular ones seemed to be #respond or some variation of #postcomment (including a #postComment). So the first step I need to take is to guarantee that, if a comment is allowed for the post in question, a particular anchor name exists. We’ll use this snippet to do that:

function add_admin_comment_reply_anchor() {
     <a name="admin_comment_reply_anchor"></a>
}
add_action('comment_form', 'add_admin_comment_reply_anchor');

I played around directly with the wp-admin/edit-comments.php file and confirmed that this works (provided the above anchor name exists):

<a href="<?php echo get_permalink($comment->comment_post_ID); ?>#admin_comment_reply_anchor" title="<?php echo $post_title; ?>"><?php _e('Reply to Post') ?></a>

I tested this by directly editing my edit-comments.php file. Do not do this at home! This is for professionals only! :-) . My point in doing this was to be sure this approach would even work. There’s roadblocks ahead, though: testing this segment is how I realized that the theme is an issue, needing the above anchor hook. At this point, I’d like to note that it would be easy for WordPress to implement this: all they would need to do is add the automatic anchor as I did, and modify the base edit-comments.php file as above. But since we don’t have that, I’ll proceed with how to do the desired tweaking.

At this point, I looked at two existing plugins: Paged Comment Editing and Commenter Spy. I looked at Paged Comment Editing first since it seemed to be the most similar plugin: a plugin that somehow reworked the edit-comments.php. I was especially hoping to discover a useful WordPress hook to add the Reply To link.

But the more I looked through this plugin the less I liked the overall approach. The problem with it is two fold. First of all it’s directly incompatible with any other plugins that might affect edit-comments.php because it basically takes out edit-comments.php, and regenerates it itself. Second, this approach makes it a potential problem if there’s ever a security patch or even just plain upgrade from WordPress involving this file: the plugin will continue to put out the old code preserved within it. I don’t mean to come off completely criticizing this plugin because it’s very clever with how it reaches in and reworks the file. But I decided I didn’t really want to do it this way.

So it was back to Commenter Spy. This one’s not without its pitfalls either, of course. Since it uses javascript to modify the page output on the fly I had originally rejected it because it won’t work if the user has disabled javascript. However, javascript is ubiquitous enough it seems reasonable to use especially given the alternatives above. The premise of this plugin is as follows: Scan through the DOM of the given page, and do a regular expression substitution in order to sneak in the desired new link. So I put together the following snippets:

Define the desired text (and then escape it; since I’m localizing the term, I have no idea what this might become, so I protect it by escaping the text first).

        $admincommenttext = __('View Post');
        $eadmincommenttext = str_replace('/', '\/', preg_quote($admincommenttext));

Plus, define the Reply To to add in:

        $admincommentreply = __('Reply to Post');
        $eadmincommentreply = str_replace('/', '\/', preg_quote($admincommentreply));

Now define the regular expression to search on:

        $ViewPostBaseURLEscaped = "(<a[ \\n\\r]*href=\"([^\"]*)\"([^>]*)>$eadmincommenttext<\/a>)";

With these pieces in place, I can now use the following snippet of javascript:

<script type="text/javascript">
//<![CDATA[
 
        var links;
        links = document.getElementsByTagName('p');
        for (var i = 0; i < links.length; i++) {
                var curr;
                curr = links[i];
                curr.innerHTML = curr.innerHTML.replace(/<?php echo $ViewPostBaseURLEscaped; ?>/, "$1 | <a  href=\"$2#admin_comment_reply_anchor\" $3><?php echo $eadmincommentreply; ?></a>");
        }
 
//]]>
</script>

Now, to wrap this all up and to make sure it gets added into the output HTML of the proper page (edit-comments.php), I put the above code into a function called adminCommentReplyModifyViewPostURLs and hooked it in as follows:

/* activate only on correct page */
if (basename($_SERVER['SCRIPT_FILENAME']) === 'edit-comments.php')
{
        add_action('admin_footer', 'adminCommentReplyModifyViewPostURLs');
}

In the next version of this plugin, I would like to change the Reply To link to open up an inline text area for the reply which then adds it in properly, without ever leaving the page. However, I need to dig in more deeply to see how comments are added, so I’ve left this for a future improvement. It would also mean not seeing the full content of the comment being replied to although presumably the admin of the site has already seen that in the email notification. (Perhaps a button to expand the excerpt to a full version and back?)

You might be wondering how do I do this, how do I know what filters to apply, where to look. The answer is really I don’t. I do know that I can add in actions and filters, and I peruse the WordPress Codex site’s list of hooks for anything that looks like it might do the trick. I also browse the various files in the themes and in the wp-admin directories: I actually found the the comment form hook in the theme’s comment.php file. I also look for plugins that do something similar to what I want to do, or at least knock about in the same general area. In this case, I found two, one of which gave me the bulk of my material.

Thank god for GPL ;-)

OK, at this point, I’m using it on my installation and it seems to work. It is, however still fairly rough. I’ve got the download page set up here.

del.icio.us:creating another plugin: reply to from admin panel  digg:creating another plugin: reply to from admin panel

Comments (24)

playing with the new flickr options

Yesterday, flicker gave us two new shiny toys to play with. The big one, collections, has been in demand for a long time, and as a overactive set user, I’m very pleased to see that this is now available. The smaller one allows flickrites to change the layout of their entry page. The choice is fairly limited but I am certainly not complaining.

To change the layout of my “You” page, I went thru the menus: You->Your Account. There is now a new option added to allow me to pick out which layout I wanted. The choices are small images only, small images plus sets (the original default), small images plus collections, medium images only, medium images plus sets, or medium images plus collections. Since I promptly sorted all my sets into collections, I chose the small images plus collections option which worked a treat.

To create collections, use the Organizr. The “Sets” tab is now “Sets and Collections.” It’s all pretty intuitive to use: when I choose to create a new collection, all my sets are displayed to one side, and I can drag and drop (and reorder, etc) sets into the collection.

Sets use a particular picture within the set to create its visual identification; collections use a mosaic of nine pictures to create its visual identification. I believe there are still some bugs with creating the mosaic representations. In several cases, the mosaic insisted on using pictures from one particular set within the collection, instead of a nicely distributed random set. In one case, the pictures chosen are from a set not even in the collection!

Collections are not available to free flickr accounts. This makes sense as free accounts are also limited in the number of sets they can create, as well. However, choosing different layouts is available, with the small/medium pictures + collections options omitted.

The announcement of the new features are up at Flickr’s Blog.

del.icio.us:playing with the new flickr options  digg:playing with the new flickr options

Comments (1)

tinkering with gmail

I should say I was a long time holdout in reading my email on a shell (unix) account. After all, all of the key features being touted on the new web based or GUI based mail readers were available twenty years ago in programs like MH (now nmh) and filters such as Procmail, both programmable and endlessly customizable. I could do back flips and front aerials with my mail while the current crop were oozing their way out of the primordial sludge.

But, I have grudgingly entered the present day world, as Gmail (and Thunderbird, but that’s another topic) have made pretty good gains and I’m not yet prepared to set up my own personal mail server on my own linux box just in order to keep using a text based set of programs which admittedly don’t handle some things such as pictures all that cleanly (although that also meant that I basically never got email viruses).

Gmail Account

For the first three years, Gmail was invite only. Now it’s open to all. Of course, all the good names have been taken ;-)

Security

First of all, for any kind of web browsing of a relatively personal nature, I recommend making sure the session stays within https connections. In grossly simple terms, the “s” on https means the connection is secured from eavesdropping. One simple way to do this is to log in on Gmail from this address: https://mail.google.com which should thereafter retain the secure connection. I like to be absolutely sure of this, though, so on Firefox, I use a simple Greasemonkey script called GmailSecure to enforce the https connection. (It’s also extensible to force secure connections on an array of google related items.) Sorry Opera, IE, or Safari users, I couldn’t find comparable extensions for this (though an Opera widget called Gmail Checker has a feature request for this.

Second of all, as tempting as it might be to aggregate all new items into a feed reader for convenience, do NOT use a public web accessible reader such as Bloglines or GoogleReader to do so! These subscriptions become generally searchable on either service and while the full message can not be displayed, there’s chances that the excerpt will contain enough private information that can be viewed. I came across this security hole last year, and on re-checking Bloglines, I can still find gmail feeds hosted there. I’m at a loss as to why a feed is even offered in Gmail (or at least why not make it an option in the settings and default it off for security?) but since neither Gmail nor Bloglines have taken concrete steps in addressing this issue, I’ll put this warning down. Just don’t do RSS feeds of private email, and if you do, don’t use a public RSS reader to access them — use a personal one on a particular computer for the purpose. Oh, you wanted to be able to access the feed anywhere on the net? Then use Gmail’s web interface already, that’s what it’s for.

Notifications

There’s several ways to have Gmail notifications setup. Gmail itself provides small applets for Windows/Mac. The open source community has created an equivalent for Linux called CheckGmail (which is now available with some distributions, such as Ubuntu, so check the package managers first).

Opera and Firefox have various different widgets and extensions that provide notification. I use the Firefox Gmail Manager which has its own notification system besides much more: see below. Opera’s Gmail Checker is a small and simple widget solely for this purpose. I did not find any for Safari or IE on cursory check.

Favorite Firefox <-> Gmail Extensions

As a Firefox user, I like to search around at Firefox Add-ons for useful extensions. The ones I use are:

  • Gmail Manager This is an essential script to handle multiple Gmail accounts. A small notification in the bottom tray of Firefox can be configured to display the current number of unread messages in the mailbox as well as a way to simply log into each account, with minimal switching around.

  • Gmail Skins Fun to play with; note that some of the choices result in error messages, just uninstall, reinstall and choose a different theme.

  • And of course I use the Firefox extension Greasemonkey. Saved Searches gives me dynamic folders, pretty useful. Hide Gmail Ads allows me to regain valuable real estate on my laptop where every centimeter counts.

Tips and Tricks

  • Use a draft message (start a message and then save it rather than send it anywhere) to do quick file transfers between computers. I save the item into a draft on one computer, and pull it out from my login on another computer. It’s more convenient than emailing it to myself, and few home computers have a permanent IP address for ftp transfer and the like.

  • I also use the drafts for “Notes to self” on particular emails. Sometimes I want to remind myself of things related to an email, and drafts attached to that email serve as a form of post-it notes.

  • Sort everything! Any mailing lists should be slapped with a label and archived. This way I browse mailing lists at my leisure and I’m not distracted by constant incoming email. The only thing that should be popping up in my mail account are important things that I need to attend to relatively quickly. Gmail does provide pretty good filtering and labeling and other options for incoming email.

  • Use the + feature in email addresses. The definition of mailing protocol means that addresses of the form somewhere+identifier@somedomain should be delivered t somewhere@somedomain . Not all mail providers adhere to this, but gmail does, and this can be a trick to sort incoming email from different sources. For example, when I’m forced to use my email address for something that I suspect will spam me later, I can use something like myemail+nyt@gmail.com to see. Since Gmail has reasonable filters, this is perhaps not as useful as it might have been at the start.

  • Google itself lists several pretty cool Gmail related Greasemonkey scripts here; they’re all well worth looking at.

  • There’s plenty of creative ways to divert items to Gmail: feeds can be sent via email through Feedster or Feedburner; that way I could if I chose have a daily weather forecast or my current to-do list emailed to me.

What would I like to see?

Gmail allows multiple email addresses to be forwarded to it, and to “reply” as those emails. However, those emails are still marked in the headers as originating from that particular gmail account. I would like to see it anonymized down to at least only knowing it’s routed through Gmail. Since the extra email addresses in question are verified before being added to Gmail’s list of alternate addresses, I don’t see why that can’t be offered.

Yes, a short list. Well, if it were longer, I wouldn’t be using Gmail in the first place ;-) Most of the time if I want a feature, I can find an extension of some type for it.

Miscellaneous Issues

One of the most annoying consequences of Google having assimilated Blogger is the effect it had on Blogger accounts versus Gmail accounts. I have a different “identity” on Blogger that’s well established, but not connected to my Gmail. Now, both accounts were retained in the merger, but they do not play well together. If I am logged into my Gmail when I encounter a Blogger post I wish to respond to, and I log in my old Blogger account, it logs me out of Gmail. I have not found a good way around this, although I have discovered that logging back to the original Gmail account often leaves the Blogger login available on other Blogger entries that I might respond to.

del.icio.us:tinkering with gmail  digg:tinkering with gmail

Comments (1)

attention all WordPress 2.1.1 upgraders…

Better read this announcement immediately if you’ve updated to 2.1.1 within the last few days. It’s quite likely you need to go to 2.1.2 asap as the security on 2.1.1 was compromised.

This security hole does NOT apply to people still on 2.1 (but I imagine if you were planning to upgrade, you should go directly to 2.1.2…).

del.icio.us:attention all WordPress 2.1.1 upgraders...  digg:attention all WordPress 2.1.1 upgraders...

Comments

repositories and package management

Or, what to do when you want to update?

I’ve been thinking about this in light of my previous entry plus the annoyinggood comments my friend made.

There are basically three options to update an application on a Linux distro:

  1. From that distro’s official repositories
  2. From “unofficial” repositories
  3. From source files

Really, all three have their pros and cons. The safest and most prudent approach is to work from official (and, really, popular or widely used as well) repositories. This is least likely to break things and as long as the package managers (apt, rpm, yast, Synaptic Package Manager, and so on and so forth) are used, uninstallation is clean as well. But, I am left dependent on when the folks managing the repositories decide to check in new packages.

This brings me to the second option (which is a slightly fuzzy distinction here, but I’ll make it anyway). There are repositories that individuals put together, often for particular projects, although others put together more general and very useful repositories (such as treviño’s). These repositories, while they make it easier to install more complex updates to applications, may still break other things in the distro as they are usually too narrowly focused on the app to make sure the distro as a whole is okay. This is the problem I had with updating gtkpod: while I used repositories to install it, it broke several applications because of the conflicts it created by updating shared libraries (which were not backward compatible as it turned out).

The third option, to download source and compile can sometimes avoid these problems (for example, by making a private copy of some of the libraries so as to leave the older ones in place for the distro and yet make the newer items available). But the largest con with these are that it’s often difficult to uninstall these things (unless you have a good idea of what you’re doing) and it’s very easy to forget what you’ve done later on. Come a distro upgrade and there may well be two versions of something hanging about. Or, it breaks the custom install and time is required to reconcile the two again. It’s also difficult to resolve things if the compile just doesn’t work, and it’s impossibel to tweak things (eg to have two separate libraries) unless you really are unix-conversant.

Different people take different approaches. One friend is willing to wait and just use official repositories. Another is willing to go for various different things as long as its repository based. I will sometimes compile things from source partly because I can, and partly because I do use things that aren’t actually available any other way. But now and then I get tripped up by zooming a bit too quickly to the third option. For starters, I could have saved myself a little trouble with Flash 9 by using treviño’s handy repository…

Even so, one thing I noticed with new versions (eg, going from Ubuntu’s Dapper Drake to Edgy Eft) is that the newer version sometimes removes or replaces previously installed packages, even those installed from the repository. I can’t remember offhand all of the ones that were so affected, but Network Manager (the best linux app for handling wireless) was one of them. Going from Warty to Dapper, it disappeared entirely, and I threw my hands up and wrote a script. Then going to Edgy, it didn’t like my script anymore, and looking about, I realized Network Manager was now integrated into the desktop. So there’s always that. Sometimes packages are simply removed. I then have to remember what I did have so I can restore it.

To fill in these holes, one of the things I do is I keep a file (I call mine “log” simply enough) in which I detail all the things I do to my Linux installation, and from where/how. Later on, that saves me time figuring out what I did and which programs I do have. It helped me reinstall Flash 9 as well; I’d recorded where I got the instructions and what happened when I followed them.

In any installation, I note the application, the version, the relevant webpages, whether I used apt-get, whether i added repositories (and if so which) and whether I compiled from source (in which case I frequently cut and paste the entire transcript from the terminal into the log. This file is so important I back it up on a jump drive so that I can always get at it.

del.icio.us:repositories and package management  digg:repositories and package management

Comments

Bad Behavior has blocked 1096 access attempts in the last 7 days.