<?php
/***************************************************************************/
// This code is inserted into a sidebar
// It will need to be modified to work on another system and is provided
// here mostly for reference - MjM
//
/***************************************************************************/
$limit = 5;
// This node excluded
$ordertron = 868;
// Minimum number of hits
$tcount = 20;
// Last counted less than this number of days ago
$lastcount = 30;
// Reuse CCK Image Field thumbnails
$thmPath = "sites/botaday.com/files/imagefield_thumbs/blogimg";
$query = "SELECT n.nid FROM {node} n, {node_counter} c WHERE c.totalcount > %d AND c.nid = n.nid AND n.nid != %d ";
$query.= "AND datediff( curdate(), from_unixtime( c.timestamp ) ) < %d ";
$query.= "GROUP BY title ORDER BY c.totalcount DESC LIMIT %d";
$topres = db_query( $query, $tcount, $ordertron, $lastcount, $limit );
$topArray = array();
$nodeArray = array();
while( $topArray = db_fetch_array($topres) ) {
$nid = $topArray['nid'];
$query = "SELECT n.title, f.filepath FROM { content_type_blog } c, { files } f, { node } n ";
$query.= "WHERE ( c.field_add_img_fid = f.fid OR c.field_add_img_w_fid = f.fid ) AND n.nid = c.nid AND c.nid = %d";
$noderes = db_query( $query, $nid );
$nodeArray = db_fetch_array( $noderes );
$filePath = $nodeArray['filepath'];
$title = $nodeArray['title'];
$imgFile = basename( $nodeArray['filepath'] );
$html = "<a href='http://botaday.com/node/$nid'>";
if( file_exists( $thmPath."/".$imgFile ) && strlen( $imgFile ) > 0 ) {
$html.= "<img src='/$thmPath/$imgFile' alt='$title' title='$title' /><br>";
}
// This is for older blog posts with inline images
else {
$query = "SELECT body, title FROM { node_revisions } WHERE { nid } = %d";
$bodyres = db_query( $query, $nid );
$bodyArray = db_fetch_array( $bodyres );
$body = $bodyArray[ 'body' ];
$title = $bodyArray['title'];
$img = preg_replace( '/.*(sites\/botaday.com\/files\/blogimg\/.*)\'>.*/', '$1', $body );
// Debug - writes as comments to HTML source
//print "<!-- img = $img -->\n";
$html.= theme('imagecache', 'thm_img', $img, $title, $title) . "<br>";
}
$html.= "</a><br>\n";
// Debug
//print "<!-- html = $html -->\n";
print $html;
}
?>