function img_assist_load_images in Image Assist 6.2
Same name and namespace in other branches
- 5.3 img_assist.module \img_assist_load_images()
- 5 img_assist.module \img_assist_load_images()
- 5.2 img_assist.module \img_assist_load_images()
- 6 img_assist.module \img_assist_load_images()
Load all images into a static array.
Related topics
File
- ./
img_assist.module, line 1949 - 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, i.*, f.* FROM {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.nid INNER JOIN {image} i ON n.nid = i.nid AND n.type = 'image' INNER JOIN {files} f ON f.fid = i.fid " . $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) 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, i.*, f.* FROM {image} i, {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.nid INNER JOIN {files} f ON f.fid = i.fid WHERE i.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) 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;
}