Monday, December 10, 2007

So I made a small adjustment to /modules/node/node.module and it serves to display an attachment in the body of the story and the teaser. It only works if the mime type of the attachment is JPEG, GIF or PNG. So here goes:

Put this code into the node.module file at about line 1015 or so (right after the $content = drupal_render($node->content) stuff is.

//CORE HACK - BY Rob - If there is an attachment that is an image, then I will put it in.
$querystr="SELECT filepath from files WHERE status=1 AND (filemime='image/jpeg' OR filemime='image/gif' OR filemime='image/png') AND fid in (SELECT fid FROM upload WHERE nid='".$node->nid."')";
$result=db_query($querystr);
$thisarray=db_fetch_array($result);
if ($teaser) {
$imgwidth='150px';
}
else {
$imgwidth='300px';
}
if($thisarray['filepath']) {
$thisimg="
";
}

Then don't forget to prepend $thisimg to $content and $teaser in the subsequent code.

if ($teaser) {
$node->teaser = $thisimg.$content;
unset($node->body);
}
else {
$node->body = $thisimg.$content;
unset($node->teaser);
}

and then the css needs something like this:

#storypic { padding:15px; width:300px; float:right; border: thin solid #FFFFFF; background-color: #FFFFFF; }