You are here

function img_assist_load_images in Image Assist 5.3

Same name and namespace in other branches
  1. 5 img_assist.module \img_assist_load_images()
  2. 5.2 img_assist.module \img_assist_load_images()
  3. 6.2 img_assist.module \img_assist_load_images()
  4. 6 img_assist.module \img_assist_load_images()

Load all images into a static array.

Related topics

File

./img_assist.module, line 1894
Image Assist module

Code

function img_assist_load_images($tid = NULL, $uid = NULL) {
  static $image;
  if ($tid) {
    foreach ($tid as $key => $term) {
      if ($term == 0) {
        unset($tid[$key]);
      }
    }
    $image = NULL;
  }
  $where = '';
  if ($uid > 0) {
    $image = NULL;
    $where = 'AND n.uid = ' . db_escape_string($uid);
  }
  if (!$image) {
    $result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, f.* FROM {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.nid INNER JOIN {files} f ON n.nid = f.nid AND n.type = 'image' " . $where . " ORDER BY n.changed DESC"));
    while ($node = db_fetch_object($result)) {
      $node->filepath = file_create_path($node->filepath);
      $dim = getimagesize($node->filepath, $info);
      $node->width = $dim[0];
      $node->height = $dim[1];
      $image[$node->nid][$node->filename] = $node;
      if ($tid) {
        $tid2 = array();
        foreach (taxonomy_node_get_terms($node->nid) as $term) {
          $tid2[] = $term->tid;
        }
        if (array_intersect($tid, $tid2) == $tid) {
          $img[$node->nid][$node->filename] = $node;
        }
      }
    }
    $image = $tid ? $img : $image;

    // Note: If we didn't use "LIKE 'image/%%'" here we could load other files.
    // Might be interesting to expand on this someday.
    if ($image) {
      $result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, f.* FROM {files} f, {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.nid WHERE f.nid = n.nid AND f.filemime LIKE 'image/%%' AND n.nid NOT IN (" . implode(array_keys($image), ', ') . ") " . $where . " ORDER BY n.changed DESC"));
      while ($node = db_fetch_object($result)) {
        $node->filepath = file_create_path($node->filepath);
        $dim = getimagesize($node->filepath, $info);
        $node->width = $dim[0];
        $node->height = $dim[1];
        $image[$node->nid][IMAGE_THUMBNAIL] = $node;
        $image[$node->nid][IMAGE_ORIGINAL] = $node;
        if ($tid) {
          $tid2 = array();
          foreach (taxonomy_node_get_terms($node->nid) as $term) {
            $tid2[] = $term->tid;
          }
          if (array_intersect($tid, $tid2) == $tid) {
            $img[$node->nid][IMAGE_THUMBNAIL] = $node;
            $img[$node->nid][IMAGE_ORIGINAL] = $node;
          }
        }
      }
      $image = $tid ? $img : $image;
    }
  }
  return $image;
}