Archive for plugins

notes on admin comment reply

OK, I think I’ve got a cut for the next release of Lorelle’s requested plugin. However, I have not had a chance to test this outside of my own system (where it seems to work fine), and so I would love to have any volunteers help check this out on different installations for anything I’ve overlooked.

The basic mechanics are as follows: I coded up a new link “Reply To” for each post, which you all saw in the last cut. In that one the link goes to the post page’s comment reply section, which at least cut out the intervening pages. At one point I realized the Reply To doesn’t need to be added for comments not yet approved (!) so I cleaned that up (see example).

Anyway, now the Reply To link (see example) opens up a small box with a submit button under the comment using javascript (see example). I added code to the edit-comment.php that now handles a submit query. Each “Reply To” opens up its own box/submit button for the owner’s (see example). On submission, it refreshes, staying on this comment management page (see example). Sorry, no ajaxy goodness at this step, perhaps at the next step if I can figure out how to hook into something similar as to what the approve/unapprove links are doing.

There are a few annoying points left, which I’m not entirely sure how addressable they are. For example, once you approve a post, you’ll need to refresh the page to get its Reply To link, since that part of the code is not hooked into the ajax that WP is using to do this. Ideally I’d like to tap into that, I’ll have to poke around some more. I also have a feeling I should be utilizing the Nonce security model as well.

If you’d like to test this out, please comment! I’d feel better if it were tested out on a few more sites before I release it out in the wild…

del.icio.us:notes on admin comment reply  digg:notes on admin comment reply

Comments (6)

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 (25)

that dratted flash 9 plugin for firefox…

Update:
I was asked “Why not apt?” As it turns out, the repositories still have Flash 7 listed in them. Nevertheless, this article may be a better/different way to install Flash 9, especially as it looks like it would include automatic updating, and it uses a more standard way of updating (which generally should be via apt; the tricky issue as always is when one wants something not in the repositories).

So earlier this month I installed Flash 9 for Linux on my Firefox from a HowtoForge article. Flash is one of those necessary evils*, I suppose, but it gets more difficult to ignore entirely so while I refuse to use it myself, I do install it so I can see what the heck is going on in some of the sites I visit. Not to mention that YouTube and VideoEgg both use Flash (the latter version 9 in particular).

To install it, I went to the Adobe download site. It automatically detects the incoming OS, so this step needs to be done from the Linux OS. This brings up a tar.gz file which I downloaded and saved. Using a terminal window, I unpacked it via


tar xvfz install_flash_player_9_linux.tar.gz

That gave me a new directory, which I cd’d to. I ran the installer:

sudo ./flashplayer-installer

After getting the root password, there’s some information and verbiage, until eventually it asks:

Please enter the installation path of the Mozilla, SeaMonkey, or Firefox browser...

At this point, I entered /usr/lib/firefox — more on that in a moment. After doing this, it chugged along for a few more seconds before informing me it was done. So now I fired up a Firefox window and all looked well. This was back in the first week of February.

Then about a week ago, I started noticing little oddities. Some of the places I was visiting started using something called VideoEgg, which simply would not run — it just spun in place forever as if it was downloading. I got very hit and miss behaviors, so I checked my plugins on Firefox via about:plugins. Lo and behold, it said I had version 7! Scratching my head, I went through the same process as above, checked again, and it showed 9. This kind of thing made me grumpy, especially when I spotted the same problem next time I started up Firefox. This time I kept searching on “Shockwave” in the about:plugins page and voila! I found I had both versions installed; and the behavior depended on which came up first.

I knew, from that plugin page, the relevant file name is libflashplayer.so. So I used a terminal window and looked for it using


locate libflashplayer.so

and what I found was a copy in /usr/lib/firefox/plugins as well as in ~/.mozilla/plugins. So I renamed the one in .mozilla (as having the older date) to another name, shut Firefox down, and started it up again. This time only one version of Flash (yay!) and at version 9 (yay!). It turns out that Firefox pretty much looks at four places: the global Mozilla and Firefox directories, and the local (home account) Mozilla and Firefox directories. It will find plugins in all of them (and probably a few more for all I know) so using any of these directories in the initial flashplayer-installer script will “work” but if it isn’t the same directory that the previous flash installation resides in, that double plugin situation will occur.

So, what I would recommend before installing Flash 9 is to first see where any older flash plugins are residing (via the locate command above) and either use that as the directory to give to the original flashplayer-installer script, or clean up afterwards, as I did.

And have I got a test site for Flash.. :-O


*Look at the date on that Flash article!. There are numerous other reasons to hate it as well, but the mockery it makes of accessibility issues, particularly for the visually impaired, is the number one for me.

del.icio.us:that dratted flash 9 plugin for firefox...  digg:that dratted flash 9 plugin for firefox...

Comments

wordpress security and spam

So there is yet another update to WordPress (now at 2.0.7), which I urge you to go out and get. If you have 2.0.6, you can get just the diffs to 2.0.7. If you are not up to 2.0.7, I strongly suggest you do so, as many of the updates since the 2.0 release have consisted of security fixes, not just whizz-bang features.

In the same vein, akismet is up to 1.8.1 (although their website gives an earlier version number, I had 1.8.1 after updating). If you have already installed it and are just updating it, all you have to do is unpack the new version in the same plugin directory, you are already set up with your API key and everything (their faq doesn’t make it clear what is involved in updating versus newly-installing, probably because it’s so trivial).

Plus which I use the plugin Bad Behavior for further spam killing (now at version 2.0.9). It works a charm. It’s also been pretty recently updated, so I suggest installing it if you haven’t got it, or updating it if you’re behind.

del.icio.us:wordpress security and spam  digg:wordpress security and spam

Comments

italian translation

Paolo has been kind enough to translate into Italian an article I wrote detailing how to put together a simple wordpress plugin. The translation may be found here, and I have added the text to the article itself at the end. Thank you for your hard work; I only know a little Italian but it looks good to me & I’m pleased that its available to a wider audience.

del.icio.us:italian translation  digg:italian translation

Comments (2)

« Previous entries Next Page » Next Page »

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