Tadpoles

Date: 6th November 2007 at 2:58 am | Filed under: actionscript, blog, flash, gallery | Author: Sam Burdge

Introducing my new pet tadpoles! Over the coming weeks I intend to train them to do things...like make tea, or write PHP. They're not very evolved yet though, just swimming around blindly.

Leave a Comment

WP Plugins and Custom Fields

Date: 5th November 2007 at 9:14 pm | Filed under: development, scripts, wordpress | Author: Sam Burdge

This article is intended to address issues involving the use of add_post_meta and delete_post_meta in WordPress plugin design. These functions can be used to add or delete custom fields for a post, useful for plugin design as the value for the custom field can be entered via a form in the write page. The add_post_meta code would look something like this:

Read on…

2 Responses to “WP Plugins and Custom Fields”

  • Comment by johnbillion
    Date: December 6th, 2007 at 5:45 pm

    Erm, have you tried update_post_meta ?

  • Comment by Sam Burdge
    Date: December 10th, 2007 at 2:20 pm

    Hi Johnbillion,
    update_post_meta is a tidier way, true. But the problem still remains that if you hook it in using add_action as stated above, there will be instances where the function is called even though the form hasn’t been submitted (i.e. the post/page hasn’t been edited), like when a comment is approved.
    Sam

Leave a Comment

JavaScript Popups

Date: 3rd November 2007 at 4:43 pm | Filed under: development, scripts | Author: Sam Burdge

Something I've noticed recently, whilst installing many different WordPress plugins on my site and on other sites is the inconsistency in JavaScript popup window code used in many plugins, allowing for the same popup to be opened numerous times or for a popup to hide in the background behind another page. The basic code to open a popup is:

window.open('http://bla.com','myWindow','status = 1, height = 300, width = 300,
resizable = 0');

However, if you add this code as the onclick for a button or anchor tag it will open a new popup each time it is clicked regardless of the fact that the window may already be open. Adding return false; will prevent this from happening, but then if the window is at the bottom of the pile clicking on the link will do nothing.

To ensure the window is brought to the front the code should be executed like this:

myPopup = window.open('http://bla.com','myWindow','status = 1, height = 300,
width = 300, resizable = 0'); myPopup.focus(); return false;

6 Responses to “JavaScript Popups”

  • Comment by c-received
    Date: November 6th, 2007 at 7:40 pm

    Hey Sam,

    In the second example the window.open object and it’s properties are being assigned to a custom window object reference. This makes the process of isolating, controlling, and recognising individual window.open objects easier. Basically, the window object reference ties the main window to the sub-window as well as creating a link between the secondary window to its main opener window.

    If you wanted to harden the function shown above some more you could do something like whats below. This ensures the creation code isn’t ran if the window already exists. You can also test and verify if a window is closed by using ‘w.closed’, err not done here.

    function openWin(url){
    var w=null;
    if(!w)w=window.open(url,….);
    else w.focus();
    return false;
    }

    Using approches like these is very bad news. Best practice is to avoid using window.open() at all.

    <a href=”#” rel=”nofollow”>
    <a href=”window.open(…)” rel=”nofollow”>

    Anyway, if you were to, ideally the event that fires this function should be attached to the link unobtrusively, however, at the end of the day it will be formed something like this…

    …onclick=”return openWin(this.href);”

    I.E 7 will put an end to developers setting certain properties by force, e.g. removing the address bar, due to accessibility and security reasons… No doubt someone will find a work around.

    cheers, c-received

  • Comment by c-received
    Date: November 6th, 2007 at 8:03 pm

    Hmmm.. muffed my code and turned it into real HTML … Should fix this soon mate, also have a look into Cross Site Scripting as it would be quite easy to do this on your site.. E.G

  • Comment by c-received
    Date: November 6th, 2007 at 8:06 pm

    a=”get”;
    b=”URL(\”";
    c=”javascript:”;
    d=”alert(’XSS’);\”)”;
    eval(a+b+c+d);

  • Comment by c-received
    Date: November 6th, 2007 at 8:07 pm

    blah blah…

  • Comment by c-received
    Date: November 6th, 2007 at 8:09 pm

    or to test this way ..
    ”;!–”=view source

  • Comment by Sam Burdge
    Date: November 6th, 2007 at 9:55 pm

    Hi c-received,
    Thanks for your detailed response. I will indeed look into Cross Site Scripting. I think you are right that using the window.open(…) method is not great. This brief article was written after I’d spent ages scanning throught the code of about 4 or 5 wp plugins that I’d installed on a clients site to fix these popup window problems.
    S

Leave a Comment

Old Artwork Made New

Date: 1st November 2007 at 12:35 am | Filed under: gallery | Author: Sam Burdge

I recently took a photograph of this old picture of mine, sketched over 12 years ago when I was studying art. The reflection in the glass picture frame (un-intentional) seemed to add an extra dimension to the image once photographed. Here's the result:

Sam Burdge - Untitled Sketch

Leave a Comment