Sorry, I was too busy celebrating my birthday last night.
First off all it might not be a wise idea to not use `md5`. NNF allows any symbols for names. This means I could make my name something like `../malware.php?ignore=` and the visitor’s browser will not load `/avatar/name.png` but `/malware.php?ignore=.png`. I would have broken out of the avatar directory and can make the browser load any file on your server.
Not cool. And that is ignoring the fact some symbols simply aren’t allowed in filenames or URLs, those will all give errors too.
Now for not showing any image if none exists on the server, here is some code. This is 100% untested, so if I have forgotten a semi-colon or something don’t put too much blame on me. You should get a pretty good idea of what I am doing here so you can fix any small issues yourself.
%
/* Put this in theme.php, inside the `theme_custom` function. */
foreach ($template->query('.nnf_reply-author, #nnf_post-author') as $node) {
// The file we want, md5 of the user name and the PNG extension:
$filename = md5(trim($node->nodeValue)) . '.png';
// The avatar directory on the server, I am assuming in the forum root:
$avatardir = FORUM_ROOT . DIRECTORY_SEPARATOR . 'avatar' . DIRECTORY_SEPARATOR;
// Test if the file exists in the directory:
if (file_exists ($avatardir . $filename)) {
$value = '<img src="/avatar/' . $filename . '" alt="" /> '
. $node->nodeValue;
$node->nodeValue = '';
$frag = $node->ownerDocument->createDocumentFragment();
if (!@$frag->appendXML($value) || !@$node->appendChild($frag)) {
throw new Exception("Invalid HTML");
}
}
}
%