You are here

function image_gallery_page in Image 5

Same name and namespace in other branches
  1. 5.2 contrib/image_gallery/image_gallery.module \image_gallery_page()
  2. 6 contrib/image_gallery/image_gallery.pages.inc \image_gallery_page()
  3. 7 contrib/image_gallery/image_gallery.pages.inc \image_gallery_page()

Image gallery callback, displays an image gallery

1 string reference to 'image_gallery_page'
image_gallery_menu in contrib/image_gallery/image_gallery.module

File

contrib/image_gallery/image_gallery.module, line 140

Code

function image_gallery_page($type = NULL, $tid = 0) {
  $galleries = taxonomy_get_tree(_image_gallery_get_vid(), $tid, -1, 1);
  for ($i = 0; $i < count($galleries); $i++) {
    $galleries[$i]->count = taxonomy_term_count_nodes($galleries[$i]->tid, 'image');
    $tree = taxonomy_get_tree(_image_gallery_get_vid(), $galleries[$i]->tid, -1);
    $descendant_tids = array_merge(array(
      $galleries[$i]->tid,
    ), array_map('_taxonomy_get_tid_from_term', $tree));

    // The values of $descendant_tids should be safe for raw inclusion in the
    // SQL since they're all loaded from integer fields in the database.
    $sql = 'SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN (' . implode(',', $descendant_tids) . ') AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC';
    if ($nid = db_result(db_query_range(db_rewrite_sql($sql), 0, 1))) {
      $galleries[$i]->latest = node_load(array(
        'nid' => $nid,
      ));
    }
  }
  $images = array();
  if ($tid) {
    $result = pager_query(db_rewrite_sql("SELECT n.nid FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid WHERE n.status=1 AND n.type='image' AND t.tid=%d ORDER BY n.sticky DESC, n.created DESC"), variable_get('image_images_per_page', 6), 0, db_rewrite_sql("SELECT COUNT(DISTINCT(n.nid)) FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid WHERE n.status=1 AND n.type='image' AND t.tid=%d"), $tid);
    while ($node = db_fetch_object($result)) {
      $images[] = node_load(array(
        'nid' => $node->nid,
      ));
    }
    $gallery = taxonomy_get_term($tid);
    $parents = taxonomy_get_parents($tid);
    foreach ($parents as $parent) {
      $breadcrumb[] = array(
        'path' => 'image/tid/' . $parent->tid,
        'title' => $parent->name,
      );
    }
    $breadcrumb[] = array(
      'path' => 'image',
      'title' => t('Image galleries'),
    );
    $breadcrumb = array_reverse($breadcrumb);
    drupal_set_title(check_plain($gallery->name));
  }
  $breadcrumb[] = array(
    'path' => $_GET['q'],
  );
  menu_set_location($breadcrumb);
  $content = theme('image_gallery', $galleries, $images);
  return $content;
}