clear_forms()

The old clear_forms() javascript function I wrote during my time at aedis a year ago has just been revamped using prototype’s new and improved $$ function (using Prototype 1.5.1_rc1.)

function clear_forms() {
	var input =  $$('input[type=text]:not([class=edit])', 'input[type=password]:not([class=edit])');
	input.each(function(self) {
		self.addClassName('defaultform');
		self.observe('focus', function() {
			this.clear_form(self);
		}.bindAsEventListener(this));
	}.bind(this));
}

Using the CSS2.1 pseudo-selector :not([class=edit]) I have managed to trim a 17 line function into 7; and it works even faster than before.

CSS Changes, Cache Updates, and GZIP

I have just finished making some style sheet changes to tradeswomen, which include fixing the width and aligning everything centre[sp].

I have also updated my cache.class file to md5 hash the file name on save, so that if anyone gains access to the cache folder, they won’t be able to access any of the files.

Finally — and this is the biggest change — I have added GZIP compression to every Javascript and CSS file that is requested from the tradeswomen.biz server. So far, results have been amazing; the home page has been compressed to ⅓ of its original size.
I have done this because of the script.aculo.us and prototype combination I use, which is a very large (bloated?) library.

<?
// apparently, the next two lines do exactly the same thing, but i don't care!
	error_reporting(E_ALL|E_STRICT);
	ini_set('error_reporting', E_ALL|E_STRICT);
	date_default_timezone_set('GMT');
	
	$file = $_SERVER['DOCUMENT_ROOT'].$_GET['file'];
	$src = $file;
 
/*------------------------------------------------------------------
 *  manage caching -- modified from CSS-SSC, shauninman.com
 *  
/*----------------------------------------------------------------*/
	$dt = filemtime($src);
	ob_start('ob_gzhandler');
 
	header("Last-Modified: ".gmdate("D, d M Y H:i:s",$dt)." GMT");
	header("ETag: ".md5($dt));
	header("Cache-Control: private");
	header("Content-Type: text/javascript");
 
	if ( isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $dt<=strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) )
	{
		header("{$_SERVER['SERVER_PROTOCOL']} 304 Not Modified"); 
	}
 
	$script = file_get_contents($src);
	$packed = $script;
	echo $packed;
	ob_flush();
	exit();

Backwards to go forewards

Today I removed all of the functions from the functions class and made them root level. This is a reversal of what I did for version 1.1, where I classed everything.

The reason for this rewind is that these main functions are all static, and are not related to any objects. Having them in a class was inefficient, and doesn’t help development time.

I was going to ‘un-class’ the tradeswomen javascript file, but decided against it because it is easier to call the methods as they currently are, all nicely bound to the class.

Transferring data from PHP

I have just finished writing a class that saves the Tradeswoman object as a string of characters, in either JSON, PHP, paths, or a query string.

For example, I have a name which has two parts: Edd and Couchman. I have an age. I have two jobs. I have a location which is both physical and online.

This class renders my details as (sorry about the long line lengths):

Paths
/name/first = Edd
/name/last = Couchman
/age = 22
/profession/0 = Student
/profession/1 = Web Developer
/location/Town = Uxbridge
/location/County = Middlesex
/location/Web = http://redheat.co.uk/
JSON
{"info":{"name":{"first":"Edd","last":"Couchman"},"age":22,"profession":["Student","Web Developer"],"location":{"Town":"Uxbridge","County":"Middlesex","Web":"http://redheat.co.uk/"}}}
PHP
a:4:{s:4:"name";a:2:{s:5:"first";s:3:"Edd";s:4:"last";s:8:"Couchman";}s:3:"age";i:22;s:10:"profession";a:2:{i:0;s:7:"Student";i:1;s:13:"Web Developer";}s:8:"location";a:3:{s:4:"Town";s:8:"Uxbridge";s:6:"County";s:9:"Middlesex";s:3:"Web";s:21:"http://redheat.co.uk/";}}
Querystring
info[name][first]=Edd&info[name][last]=Couchman&info[age]=22&info[profession][0]=Student&info[profession][1]=Web+Developer&info[location][Town]=Uxbridge&info[location][County]=Middlesex&info[location][Web]=http%3A%2F%2Fredheat.co.uk%2F

Source Code Repository

To help my examiners browse through the source code for tradeswomen, I have created a Source Code Repository that highlights and colours the examiner’s chosen file for them, and presents it in the browser.

For example, if the examiner wished to view the latest javascript file, they would go to http://stage.tradeswomen.biz/code/js/tradeswomen/2.2.2/

Source Code Repository

Knockout Type - Thin Is Always In

After reading Shaun Inman’s article at 24 ways, I decided to put my menu text on a diet. To do this, you add an invisible drop shadow to the text, using the CSS text-shadow: 0 0 0 #29333e;.

The results are pretty impressive — in Safari. Firefox doesn’t support text-shadow and so still has fat text. I found a workaround for Firefox, which involved making the menu text very slightly transparent 99.99% opaque, to be exact, but this triggered a bug for the rest of the page so I removed it.

Here is the before and after screen shot of the menu:
Before and after

email class v1

I have just finished writing version 1 of my email class, and I’ve got to say, it’s pretty darn amazing!

// send an email to developer@tradeswomen.biz (that's me!)
$email = new Email;
 
$email->to      = 'developer@tradeswomen.biz';
$email->from    = 'pmt@tradeswomen.biz'; // little joke!
$email->subject = 'Email from Me';
$email->format  = 'HTML';
$email->message = 'Whatever you want!';
	
$email->send();
unset($email);

I’m sure there are many other email classes available (including a PEAR class) but I decided it would be easier to write my own — more flexibility that way, plus higher marks in the assignment.

cache class v1

This is the cache.class.php file I have created to speed up database access for tradeswomen.

public function cache($sql)
{
	global $db;
	if ( !$sql ) return false;
	
	if ( $this->check_cache($sql) )
	{
		$results = $this->get_cache($sql);
	}
	else
	{
		$results = $db->query($sql);
		$this->set_cache($sql, $results);
	}
 
	return $results;
}
 
public function check_cache($sql)
{
	$filename = strtolower($sql);
	$file = '_cache/'.str_replace(' ','',$filename).'.txt';
	$expires = 240;
 
	if ( file_exists($file) && (filemtime($file) > (time() - $expires)) )
	{
		return true;
	}
	else
	{
		return false;
	}
}

Error 404

After reading an article at A List Apart, I have updated the 404 error page with a search box. The page now also serializes all of $_SERVER and emails it all to me.

the creation of tradeswomen.biz