@davestewart heh - I might do that over the weekend if I can face looking at it :-) It's hard to show just how bad it is without a lot of the surrounding mess too though (it uses global state everywhere via GET params in the URL for instance - that's fun...) but I'll see if I can extract some particular gems ;-) Though I just opened a random file and saw this (indentation is direct copy'n'paste and I've no idea who or what 'jt' might be in the "helpful" comment) :
function makeNew(&$image){ // jt put & here to make it work!!!!!!!!======================= was ==== function makeNew($image)
$userid=$image->getUserID();
$title=$image->getTitle();
$ext=$image->getExt();
$sql = <<<EOS
insert into images (
userid,
title,
status,
ext,
created)
VALUES (
'$userid',
'$title',
'live',
'$ext',
unix_timestamp(now()))
EOS;
mysql_query($sql) or die(mysql_error());
$id=mysql_insert_id();
$image->setImageID($id);
return;
}
That's actually un-representively good code ;-) But it's an "exciting twist" that they're passing the $image by reference so the things they're changing affect other bits of the application without you realising how unless you've traced the path through every function. I guess it saves doing a return $image though - optimised! ;-)
Fun fun fun! ;-)
Edit: I got a little curious as to what "$image" might be (there's no docblocks or anything, natch). Grep for "makeNew" and found 30 different functions called that - but I think this is what calls it - the if ($_SESSION conditional is lovely and clear, next step figuring out what 'base_replace' might be and where that was in turn set. Repeat and rinse... ;-)
function add_uploaded_image_to_database($newitem){
require_once(CLASSES.'user.manager.class.php');
require_once(CLASSES.'imagebase.manager.class.php');
require_once(CLASSES.'imagebase.class.php');
$imanager= new ImagebaseManager;
$image = new ImageBase;
$um = new UserManager();
$user = $um->getById(Session::getSessionUser());
$im = new ImagebaseManager();
if ($_SESSION['base_replace']>0) return $this->update_image($newitem, $_SESSION['base_replace']);
$image->setTitle($newitem['title']);
$image->setExt($newitem['ext']);
$image->setUserID($user->getUserID());
$imageId=$im->makeNew($image);
echo "ID is ".$image->getImageID();
return $image->getImageID();
}
At least it actually return's something I guess... ;-)
Edit again: Just noticed the end of that function :
$imageId=$im->makeNew($image);
echo "ID is ".$image->getImageID();
return $image->getImageID();
And was thinking "why do they create the $imageId then not use it and call the ->getImageID() twice?" and realised it's because makeNew() doesn't actually return anything so imageId is null! Splendid stuff :-)