Index: image.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/image/image.module,v
retrieving revision 1.146.2.7
diff -u -r1.146.2.7 image.module
--- image.module	11 Jun 2005 22:12:17 -0000	1.146.2.7
+++ image.module	26 Jul 2005 15:28:13 -0000
@@ -553,7 +553,12 @@
  * Fetch a random N image(s) - optionally from a given term.
  */
 function image_get_random($count = 1, $tid = 0) {
-  $result = db_query_range(db_rewrite_sql("SELECT nid FROM {node} n WHERE n.type='image' AND n.status=1 ORDER BY RAND()"), 0, $count);
+  if ($tid != 0) {
+    $result = db_query_range(db_rewrite_sql("SELECT n.nid FROM {term_node} tn LEFT JOIN {node} n ON n.nid=tn.nid WHERE n.type='image' AND n.status=1 AND tn.tid=%d ORDER BY RAND()"), $tid, 0, $count);
+  }
+  else {
+    $result = db_query_range(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.type='image' AND n.status=1 ORDER BY RAND()"), 0, $count);
+  }
   $output = array();
   while ($nid = db_fetch_object($result)) {
     $output[] = node_load(array('nid' => $nid->nid));
@@ -562,10 +567,15 @@
 }
 
 /**
- * Fetch the latest N image(s).
+ * Fetch the latest N image(s) - optionally from a given term.
  */
 function image_get_latest($count = 1, $tid = 0) {
-  $result = db_query_range(db_rewrite_sql("SELECT nid FROM {node} n WHERE n.type='image' AND n.status=1 ORDER BY changed DESC"), 0, $count);
+  if ($tid != 0) {
+    $result = db_query_range(db_rewrite_sql("SELECT n.nid FROM {term_node} tn LEFT JOIN {node} n ON n.nid=tn.nid WHERE n.type='image' AND n.status=1 AND tn.tid=%d ORDER BY n.changed DESC"), $tid, 0, $count);
+  }
+  else {
+    $result = db_query_range(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.type='image' AND n.status=1 ORDER BY changed DESC"), 0, $count);
+  }
   $output = array();
   while ($nid = db_fetch_object($result)) {
     $output[] = node_load(array('nid' => $nid->nid));
