img comments: code snippet to get the last uploaded images
Last modified: April 30, 2008 - 11:29
The following code returns the last $n uploaded images for the img_comments module.
<?php
$query = '
SELECT
c.cid,
ic.filepath,
ic.filetitle,
ic.filemime
FROM
{comments} c
JOIN {img_comments} ic
ON (c.cid = ic.cid)
WHERE
c.status = 0
ORDER BY
c.timestamp DESC
';
$output = '';
$n = 3;
$num_images_found = 0;
$result = db_query($query);
global $img_comments_thumbnails_directory;
img_comments_custom_boot();
while(($num_images_found < $n) && ($file = db_fetch_object($result))) {
if($sizes = image_get_info($file->filepath)) {
$num_images_found++;
$comment = array('cid' => $file->cid);
$thumbnail_sizes = image_get_info(img_comments_thumbnail_path($comment, $file));
$output .= theme('img_comments_box'
, $file->filetitle
, theme_image(img_comments_thumbnail_path($comment, $file))
, 'img_comments_center'
, $thumbnail_sizes['width']
, $thumbnail_sizes['height']
, 'top');
}
}
return $output;
?>Modify it for your needs.
