18 Sep

jQuery 1.3 With PHP: cover mockup

6989_MockupCover

I’ve been sent a mockup for the book’s cover. The suggested title of the book is “jQuery 1.3 with PHP”. The working title was “PHP and jQuery”. Which do you prefer?

The book has been completed, in that all the chapters are written, and it’s in the final edit phase at the moment. This involves Packt having a technical editor try everything in the book just to iron out any kinks. It’s already been gone over by three other reviewers, and the only problem appears to have been with the File Management chapter, where the web-server was IIS on Windows. That should be solved by the time the book comes out.

I’ve learned a lot while writing this book. A major point that keeps raising its head is that I keep using colloquialisms and aphorisms (ha! “raising its head”), and those are not globally understood. Another is that I keep using British spelling, but it’s expected that most readers will be American.

From a coding point of view, I tend to write compact code with comments only appearing where something is obviously confusing, but I’ve tried to put proper comments in the book whenever any reviewer asked a question about the code.

Anyway – I expect it will be in PDF form in only a few weeks! I’m looking forward to hearing what people think of it.

On a funny note, I was working on something in work recently, and was trying to figure the best way to do it, when I suddenly remembered I’d written a whole chapter on it, so went and read what I’d written! I’ll be keeping a copy of the book on my own shelf 😉

This kind of thing is always happening to me – I would need to solve some problem (hooking an OKI B2200 printer to Linux over Samba, for example), go searching for the answer, and find that I’d written the solution for it a year or two previously…

By the way, KFM 1.4 will be released next week. It will be the last 1.x version. We (Benjamin and myself) are starting a total rewrite after that, which will become KFM 2. It’s going to be massive!

EDIT: 2009-09-18 Wow, that was quick! The book is already available to pre-book

29 Aug

goodbye Andy

bollox

During my late teens and early twenties, I lived in a series of houses with Andrew Niland. We went to the same bars, had the same friends, and were into the same things (computers, body modification, “banned” films, industrial music).

In fact, I ended up going out with and eventually marrying his ex-girlfriend, Bronwyn, after living in the same house as the two of them for more than two years.

Andy was always into piercing, and spent a lot of time at Glen’s piercing parlour, learning from him.

After learning enough from him and experimenting enough that he was confident in his abilities (it didn’t take long; Andy was always brilliant, and very quick at learning what he was interested in), Andy left Ireland and went to Canada, where he ended up working for the Sacred Art tattoo parlour in North Bay, Ontario.

By that time, we’d lost touch with each other over after an argument where we all ended up moving house (we drank a lot, were young, and seriously, don’t go out with your best friend’s ex-girlfriend while living in the same house as him because that’s a recipe for disaster).

Andy had been in court in Ontario over a really stupid law which claims that some body modification is ok, but others should be regarded as “aggravated assault”, even though it’s all done consensually.

A few weeks ago, he vanished. On August 4th, he was last seen at 6.30pm. When he was missing for a while, his apartment was searched and it was found that he’d left his wallet there. A lot of fuss was made over this online, but this was not unusual for Andy.

The police searched for him for a while, and a Facebook group kept all of us uptodate.

Yesterday, Andy was found. The police won’t confirm it’s him, but how you could not identify a guy who has distinctive piercings and huge stars tattooed on his forehead, is beyond me. Besides, people close to him have confirmed it’s him.

An autopsy is to be held on Monday. At the best, this was a camping accident. At the worst, it was murder. We’ll have to wait and see.

Update (Sep 2): Police in North Bay have said that “there is no foul play suspected“. As usual with police, they have not offered any of the other pieces of information which people would really like to know, like “what actually happened?”.

18 Jul

jQuery 1.3 With PHP: chp7, image manipulation

I’ve submitted chapter 7 of jQuery 1.3 with PHP to Packt, which involves image manipulation. The editor I build in that chapter allows you to non-destructively manipulate an image in the most commonly needed ways – resize, rotate and crop.

The idea is that when you upload an image, it’s usually not yet right to include in a website. People tend to upload massive photos (3000×2000 or so) and resize it down using the <img> attributes, which is the wrong way to do it (see here for a solution to that particular problem).

However, once you’ve resized an image down, you can’t change it back.

The solution is to make copies of the image with your manipulations applied to them. That lets you make multiple versions of the same image.

But again, there’s the problem that if you change your mind about the original image, you can replace that, but the others all need to be redone.

Yet another problem is that unless you’ve kept records, there’s no link from the new images back to the original, so if you need to make space on the server by removing files that might not be in use anymore, you can’t be certain what thumbnails are still relevant and what are not.

The solution is to not actually create copies, but to record the changes applied to the original image in the URL of your manipulated image. When the server is asked for those URLs, it runs the manipulations on the original image and gives you back the new image. Of course, we will cache the new manipulations so this doesn’t need to be done every time, but this now allows you to replace the original image, then clear the cache, forcing all the variants of it to refresh, without you needing to do it again.

What this means, is that when the manipulation is recorded in the URL, no new copy is actually created until some browser actually requests it. This means that you can periodically clear your old thumbnails, safe in the knowledge that if they were still relevant, they will be recreated from the archived originals automatically the next time they’re needed.

Enough talk.

demo

This is, as usual, just a demo. It’s not designed to be impressive, but just to show how to do manipulations.

A permanent URL is provided, in the same manner as google maps – it updates itself as you manipulate it. To see the actual cropped, resized and rotated image, try opening that permanent URL in a different tab.

The GUI here is a means to an end (the permanent URL). In your own CMS, you might force a certain width/height for uploaded images automatically using the URL for example.

The example image I manipulated in the chapter is the IMG_0134.JPG in chp7. Try rotating, resizing, and cropping (drag your mouse on the image).

example:

Little thing to note about that URL – there’s no query indicator. Standards-compliant browsers treat the ‘?’ mark in a URL as an indication that the result should never be cached, but that would be pretty expensive for the server, so we remove that. The get.php file rebuilds the query from the $_SERVER['REQUEST_URI'] and sends out the manipulated image with caching headers.

The graphics manipulation was done using Imagick, which is a PECL extension that allows PHP to run ImageMagick functions internally.

In Fedora, you can install Imagick with yum install php-pecl-imagick. In CentOS, follow these instructions.

CentOS users might have a problem with the latest Imagick (2.2.2), so change the pecl install imagick line to pecl install imagick-2.2.1.

download the demo

Make sure to edit the images_libs.php file to point to your own image repositories. The images don’t need to be in a web-accessible directory.

I’ve a bit of work to do now, and then I’ll be applying the tricks in this chapter to our own CMS, WebME.

29 Jun

jQuery 1.3 With PHP: Calendars

I was supposed to write about Datatables for chapter 6 of jQuery 1.3 with PHP, but the website of the plugin I was going to use (http://www.datatables.net/) was down for about a week, and so I wrote about Calendars instead.

I used Red3‘s jquery-week-calendar plugin for a recent project in work, and was so impressed I really had to write about it.

In chapter 6 of the book, I’ll walk through how to build a simple calendar, including creation and editing of events, and including once-off and recurring events.

demo

The demo is a session-based calendar, which records only for the duration of your browser session. It’s for demo purposes only, obviously. If you want to use it in a larger project, you would need to adapt the PHP so that it records to a database or files or something.

Download

Here’s an image of it in use:

fig_6_0

Only four or so chapters left and then I’m done with the hard part. After that, is rewrites, then you can all throw your money at me.

14 May

iphone

Okay, I succumbed to the temptation and got one.

A number of annoyance have presented themselves already, in just the few hours that I’ve owned it.

First off, when you get the thing, it’s in a fancy box with all the bits and pieces in it. I took all of the bits out, and found a nice rectangular cardboard box which when opened, held the documentation. I took out the documentation and read through it, discarding the box. Couldn’t figure out how to install the SIM card into the machine, as the documentation did not mention it anywhere. After an hour or so of puzzling over it, I finally noticed that the documentation box, which I had discarded, had a weird little diagram on it, which when deciphered, explained how to do it. Way to go Apple – in this case, I did RTFM, but TFM didn’t have the instructions I needed.

Secondly. After going through the jumpy-hoopy thing of filling in a form and waiting 24 hours to be allowed to own the machine (for some reason) and then waiting another hour for the receptionist at the shop to finally get through to O2 to activate the SIM, I was just picking up everything and the guy said “ok, now you just need to activate it through iTunes”. Excuse me?? It’s a fucking phone! I can’t get iTunes running on any of my computers at home anyway because I don’t have anything that runs Windows or Mac! I spent hours trying to get Wine to install iTunes, but finally had to give up and do it on an old WinXP machine in the office the next day.

Then, I wanted an SSH client for the thing. There is a cool store for the iPhone called appStore, and there were a number of SSH clients in there. In order to get one of them, though, you need an account and some cash.

First off, I tried to just create an account. This went okay, up until the point where iTunes asked what my credit card number was. I don’t have a credit card, and don’t want one. After a while, I figured out that the only way to get an account for free (or at least, without giving Apple credit card details), is to apply to download an app which is specified as free – for some reason, in that case, Apple adds a “none” option to the list of payment methods.

So I had an account, but still couldn’t pay for anything. Apple claim that they accept PayPal, and even supply instructions on how to do it. Unfortunately, it falls down immediately, because step two says to click Edit Credit Card or Add Credit Card in your iTunes account page, but those links don’t exist! Maybe they exist if there is already a credit card attached to the account, but that defeats the entire purpose!

But it’s a nice phone, really.

09 May

error logger, mantisated

The plugin architecture for Mantis is not yet mature, so I’ve bypassed it in this. Instead, this script will inject issues directly into the Mantis database.

The following script will load up all errors aggregated with the last post’s script, and will add them as Mantis issues (or update existing issues if found).

<?php
$t=time();
$project_id=6;
$error_urls=array(
  'http://the.url/error_checker/?password=abcdefg&maxlines=5000&last_date_read='.($t-3600)
);

require 'config_inc.php';
$db=new PDO($g_db_type.':host='.$g_hostname.';dbname='.$g_database_name,$g_db_username,$g_db_password);
$db->query('SET NAMES utf8');

foreach($error_urls as $eu){
  echo $eu."\n";
  $errors=json_decode(file_get_contents($eu));
  foreach($errors as $err){
    $md5=addslashes($err->md5);
    $q=$db->query("select id,summary from mantis_bug_table where summary like '$md5 %' limit 1");
    $r=$q->fetch(PDO::FETCH_ASSOC);
    $cnt=(int)$err->count;
    if($r){
      $id=$r['id'];
      $cnt=preg_replace('/.* \(([0-9]*)\)/','\1',$r['summary'])+$cnt;
      $db->query("update mantis_bug_table set status=10,summary='$md5 ($cnt)' where id=$id");
      $btext=addslashes($err->log);
      $db->query("insert into mantis_bugnote_text_table values(0,'$btext')");
      $btext_id=($db->query('select last_insert_id() as id')->fetch());
      $btext_id=(int)$btext_id['id'];
      $db->query("insert into mantis_bugnote_table set bug_id=$id,bugnote_text_id=$btext_id,date_submitted=now(),last_modified=now()");
    }
    else{
      $db->query("insert into mantis_bug_table set date_submitted=now(),summary='$md5 ($cnt)',project_id=$project_id");
      $id=($db->query('select last_insert_id() as id')->fetch());
      $id=(int)$id['id'];
      $db->query("insert into mantis_bug_text_table set id=$id,description='".addslashes($err->error)."',additional_information='".addslashes($err->log)."'");
      $btext_id=($db->query('select last_insert_id() as id')->fetch());
      $btext_id=(int)$btext_id['id'];
      $db->query("update mantis_bug_table set bug_text_id=$btext_id where id=$id");
    }
    $db->query("update mantis_bug_table set last_updated=now() where id=$id");
  }
}

Note the bold lines – the first indicates what Mantis project to place the issue under. In my case, I created a new project named “httpd errors”, which had the ID 6. The second is an array of URLs pointing to where the error aggregators can be found. In this case, the Mantis injector is going to be called from cron every hour, so the URL includes a time limit looking for errors only in the previous hour (3600 seconds).

02 May

webme r95 packaged

I’ve packaged WebME revision 95, and it is available from the WebME Downloads page.

Improvements include:

  • Plugin architecture. Developer documentation
  • Sample plugins:
    • Banners: provide site-wide or page-specific banners; randomly rotate multiple banners.
    • Forms: show contact forms on your site. Can be templated – documentation to be written, but simple usage should be obvious.
    • Image Gallery: turn a directory of images into a gallery automatically.
    • Mailing List: written by Conor; accept subscriptions on your site; bulk email them.
    • Panels: lets you edit a section of HTML which is visible on every page of your site.
    • Polls: let your readers vote for stuff.
  • Some bug-fixes.

I’ve added a boat-load of new themes to the free site builder, so please feel free to create a site and try it out.

17 Apr

update on Me

Quick update of what’s happening in the world of Kae.

I’ve been busy recently with a new project in the office, making an ultra-WebME system which can be used by companies who are not web designers, to offer their clients “pre-packaged” websites. I may elaborate on that in a few weeks once the pilot study is out of the way.

I haven’t touched the KFM file manager project in ages, and recently realised that it’s because I’m just not happy with it anymore. It’s monstrously complex now, and just not flexible enough for the changes I want to build into it. So, I’m seriously thinking of rewriting it completely, or building a new file manager project to compete with it.

WebME is progressing quickly. The plugins architecture is damned easy to use, if I do say so myself. So much so that Conor wrote a mailing-list plugin before I even got to announce the plugin system. To try it out, get the Subversion copy of WebME, and also the subversion copy of the existing plugins (svn checkout http://webworks-webme.googlecode.com/svn/ww.plugins/) and create a symbolic link from ‘ww.plugins’ in the root of your WebME installation to the checked-out ww.plugins directory. Then in the /ww.admin section, go to Site Options > Plugins and try some stuff. I’ll be writing a proper tutorial on how to create a plugin. Probably today.

I started learning piano at the beginning of last month and am proud to say that I appear to be learning at a prodigious rate. This is probably because I can already play well on a number of other instruments. Last tune I learned was Ecossaise in E Flat by Beethoven (WoO 86), played here by Matt Baker:

Before that was I’ll Take You Home Kathleen, played here by Dave Seddon on steel guitar (couldn’t find a piano version that wasn’t ruined by people singing over the music 😉 ):

I’m still in quite a lot of pain since last week’s operation, but hopefully it will ease off over the weekend, as I have the next chapter of my book to submit.

08 Apr

friday and drink

Just a quick reminder to those of you that like a nice relaxing drink on Fridays – this Friday, the Irish government will be making alcohol illegal to sell, by order of the roman catholic church.

And all because some dude died a few thousand years ago.

Get your drink tomorrow.

Fucking stupid law. I mean, not only can’t you drink, but it’s also a holiday, so what are you supposed to do with yourself on that day???

I’ll be heading into the office to relax for a bit, that’s what.