Back to halvin.co.uk
Aide-m�moire
This page isn't meant for public consumption but there's nothing confidential here so read away if you want.
CSS Problems
Outstanding:
- The CSS structure is a bit of a mess. I need to look at moving styles out of style="" tag attributes and into the main css file. I think it may be time to split the main css file in two - one for text styles, one for layout.
- I've added a "favourite photo" page. I think it would be nice to include the comments with the photos. On clicking either the "add comment" or "reply" button, the user would be bounced to the *actual* photo page (with ?act=add#post) where they could add a comment normally. The page should be passed with an extra $_GET of "&from=favourites" so that the user can be returned to the favourites page when he submits or cancels a comment.
- The main page and favourites are (pretty much) static. Should I be generating static pages using ob_start(), then including the generated code when a page is loaded? The load times are currently around 1.5 sec and 0.5 sec (depending on whether the page data has been loaded recently), which I think is okay. Pre-generated pages should load in less than 100ms. I should think about pre-generating a load of "random factor" snippets, too.
Fixed:
- Pages like this need more whitespace - I'm having to use <br /> tags to space things out. I should consider doing double line spacing.
- Split the blocks on the front page by year, similar to sections on the thumbnail page.
- JavaScript menu: background colour wrong for selected items--double line items look shitty.
- Add a top banner to shift the content down a little. This should make things easier to read.
- The main page and the thumbnails page are still using a table for a layout. I think it's about time to go CSS only for all layouts.
Update: It's looking good so far. I'm going to keep one little table to allow me to centre the halvin.co.uk button vertically relative to the page title. There are lots of ways of using CSS to centre vertically but they either only work for fixed-height spaces or they're full of hacks for IE. I'm going to take the pragmatic approach and use a table rather than buggering about.
- Change the front page so it's got the same layout as the thumbnails page. Maybe change the layout of the thumbanail/setname/date/setdesc blocks on that page so they're floated divs. I get five thumbnails across the content_box. I guess the main page thumbnails should be twice the width: this would give me a minimum of two columns, and three columns on higher res screens.
Update: I've removed the button so that's fixed that problem. The floated divs looked rubbish so I've stuck with the original single-column layout.
- I'm not happy about the spacing of paragraph text. Need to look at margin and padding values for H1, H2, H3, H4 and P.
Done: I've added a second CSS file for pages with a lot of paragraph text like this. It's got a higher line-height value and bigger margin-top on P and Hx blocks.
- The div class "content_box" background gradient stops too suddenly. Change to a gentle finish.

How To: In GIMP
- Paint with the background (light) colour
- Switch to Quick Mask
- Draw horizontal black-to-white gradient with white at the top.
- Select Layer > Colors > Curves
- Create curve as shown below, click OK
- Switch Quick Mask off
- Flood fill with the other (dark) colour
Microsoft Word: How to Create a numbered list within a numbered list.
This works in MS Word 2003. I have no idea if it'll work in other versions of Word because I haven't tried it. I'm going to avoid the question of whether this is a good idea or not.
First a little background: I've written an instruction manual with sections auto-numbered 1, 2, 3... and sub-sections numbered 1.1, 1.2, 1.3... and 1.1.1, 1.1.2, 1.2.3. In some of those sections I needed to add simple numbered lists for sequences that the user should follow, for example:
1. Unscrew the yellow connector.
2. Remove the end cap.
...and so on.
What I wanted to avoid was:
2.3.5.1 Unscrew the yellow connector.
2.3.5.2 Remove the end cap.
I had a hell of a job trying to get one independently-numbered list within another -- Word wanted to join the two lists and selecting "restart numbering" would reset my section numbers back to the start. After a lot of trial and error I found a way to do it:
1. Create your primary numbered list as normal.
2. Create the secondary numbered list within your numbered list. The numbering will wrong.
3. Convert the secondary list to bullets.
4. Convert back to a numbered list.
Ta-dah! The primary numbering now 'jumps' the secondary list and resumes counting after it.

PHP nl2p() function
Performs a similar function to nl2br() but returns properly paragraphed HTML code.
Add headings by starting a line with 'hx:' (no quotes) where x is a single-digit number.
function nl2p($str) {
// Convert any new line/carriage return pairs to new line.
$str = str_replace(array("\n\r", "\r\n"), "\n", $str);
$lines = explode("\n", $str);
$p_open = false;
foreach ($lines as $key => $line) {
$line = trim($line);
$heading = check_heading($line);
if ($heading != "") {
// Add a heading using <hx> tags.
// No need to check if we need to close a <p> block as we look-ahead and will already
//have closed them on the previous line.
$line = "<$heading>".substr($line, 3)."</$heading>";
} elseif ($line != "" && strtolower($line) != "<hr>") {
// If we've got to this point we'll be writing paragraph text.
// Open <p> block
if (!$p_open) {
$line = "<p>".$line;
$p_open = true;
}
// Close the <p> block if:
// The next line is blank (double new-line = new paragraph)
// The next line is an <hr> (can't have <hr> in a paragraph)
// The next line is a heading (we'll be opening <hx> tags)
// Note: if this is the last line, $lines[$key+1] isn't set, evaluates to "", and so we'll close the <p> block.
if ($lines[$key+1] == "" || strtolower($lines[$key+1]) == "<hr>" || check_heading($lines[$key+1]) != "") {
$line .= "</p>";
$p_open = false;
} else $line .= "<br />";
}
//Compile result to $rtn
if ($line != "") $rtn .= $line.chr(10);
}
return $rtn;
}
function check_heading($line) {
// If left part of the string is "hx:" where x is numeric, returns hx, else returns empty string.
// e.g. if line = "h1:This is a heading", function returns "h1"
$line = strtolower($line);
if (substr($line, 0, 1) == "h" && is_numeric(substr($line, 1, 1)) && substr($line, 2, 1) == ":") return substr($line, 0, 2);
else return "";
}
Ruby on Rails
Am I ever going to get started on Ruby? Maybe I'll dive in this summer. I think I need to mooch around Nuby on Rails a bit more. I feel like php's doing everything I need at the moment.