| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: image_gallery.pages.inc,v 1.1.2.2 2010/12/22 00:09:59 joachim Exp $ 3 4 /** 5 * @file 6 * Contains menu callbacks for image_gallery pages, 7 * ie galleries not made with views module. 8 * This file is not loaded when Views is creating the gallery. 9 */ 10 11 /** 12 * Image gallery callback, displays an image gallery 13 */ 14 function image_gallery_page($type = NULL, $tid = 0) { 15 // Determine sort order. 16 $join = $where = $order = ''; 17 $args = array(); 18 switch (variable_get('image_gallery_sort_order', IMAGE_GALLERY_SORT_CREATE_DESC)) { 19 case IMAGE_GALLERY_SORT_CREATE_DESC: 20 $order = 'ORDER BY n.sticky DESC, n.created DESC'; 21 break; 22 23 case IMAGE_GALLERY_SORT_CREATE_ASC: 24 $order = 'ORDER BY n.sticky DESC, n.created ASC'; 25 break; 26 27 case IMAGE_GALLERY_SORT_FILENAME: 28 $join = "INNER JOIN {image} i ON n.nid = i.nid INNER JOIN {files} f ON i.fid = f.fid"; 29 $where = "AND f.filename = '%s'"; 30 $args[] = IMAGE_ORIGINAL; 31 $order = "ORDER BY n.sticky DESC, f.filepath ASC"; 32 break; 33 34 case IMAGE_GALLERY_SORT_TITLE: 35 $order = 'ORDER BY n.sticky DESC, n.title ASC'; 36 break; 37 } 38 39 $vid = _image_gallery_get_vid(); 40 $galleries = taxonomy_get_tree($vid, $tid, -1, 1); 41 for ($i = 0; $i < count($galleries); $i++) { 42 $galleries[$i]->count = taxonomy_term_count_nodes($galleries[$i]->tid, 'image'); 43 $tree = taxonomy_get_tree($vid, $galleries[$i]->tid, -1); 44 $descendant_tids = array_merge(array($galleries[$i]->tid), array_map('_taxonomy_get_tid_from_term', $tree)); 45 // The values of $descendant_tids should be safe for raw inclusion in the 46 // SQL since they're all loaded from integer fields in the database. 47 $sql = "SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid $join WHERE tn.tid IN (" . implode(',', $descendant_tids) . ") AND n.type = 'image' AND n.status = 1 $where $order"; 48 if ($nid = db_result(db_query(db_rewrite_sql($sql), $args))) { 49 $galleries[$i]->latest = node_load(array('nid' => $nid)); 50 } 51 } 52 53 $images = array(); 54 if ($tid) { 55 // Allow images to be sorted in a useful order. 56 $query = "SELECT n.nid FROM {term_node} t INNER JOIN {node} n ON t.nid = n.nid $join WHERE n.status = 1 AND n.type = 'image' AND t.tid = %d $where $order"; 57 $count_query = "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 "; 58 $args = array_merge(array($tid), $args); 59 $result = pager_query(db_rewrite_sql($query), variable_get('image_images_per_page', 6), 0, db_rewrite_sql($count_query), $args); 60 while ($node = db_fetch_object($result)) { 61 $images[] = node_load(array('nid' => $node->nid)); 62 } 63 64 $gallery = taxonomy_get_term($tid); 65 $parents = taxonomy_get_parents($tid); 66 67 $breadcrumb = array(); 68 $breadcrumb[] = l(t('Home'), NULL); 69 $breadcrumb[] = l(t('Image galleries'), 'image'); 70 foreach ($parents as $parent) { 71 // Add parents to breadcrumb navigation 72 $breadcrumb[] = l($parent->name, 'image/tid/' . $parent->tid); 73 } 74 drupal_set_breadcrumb($breadcrumb); 75 drupal_set_title(check_plain($gallery->name)); 76 } 77 78 return theme('image_gallery', $galleries, $images); 79 } 80 81 /** 82 * Theme a gallery page 83 */ 84 function theme_image_gallery($galleries, $images) { 85 drupal_add_css(drupal_get_path('module', 'image_gallery') . '/image_gallery.css'); 86 87 $size = image_get_sizes(IMAGE_THUMBNAIL); 88 89 $content = ''; 90 if (count($galleries)) { 91 $content .= '<ul class="galleries">'; 92 foreach ($galleries as $gallery) { 93 $content .= '<li class="clear-block">'; 94 if ($gallery->count) { 95 $content .= l(image_display($gallery->latest, IMAGE_THUMBNAIL), 'image/tid/' . $gallery->tid, array('html' => TRUE)); 96 } 97 $content .= "<h3>" . l($gallery->name, 'image/tid/' . $gallery->tid) . "</h3>\n"; 98 $content .= '<div class="description">' . check_markup($gallery->description) . "</div>\n"; 99 $content .= '<p class="count">' . format_plural($gallery->count, 'There is 1 image in this gallery.', 'There are @count images in this gallery.') . "</p>\n"; 100 if (isset($gallery->latest) && $gallery->latest->changed) { 101 $content .= '<p class="last">' . t('Last updated: %date', array('%date' => format_date($gallery->latest->changed))) . "</p>\n"; 102 } 103 $content .= "</li>\n"; 104 } 105 $content .= "</ul>\n"; 106 } 107 108 if (!empty($images)) { 109 $content .= '<ul class="images">'; 110 foreach ($images as $image) { 111 $content .= theme('image_gallery_img', $image, $size); 112 } 113 $content .= "</ul>\n"; 114 } 115 116 if ($pager = theme('pager', NULL, variable_get('image_images_per_page', 6), 0)) { 117 $content .= $pager; 118 } 119 120 if (count($images) + count($galleries) == 0) { 121 $content .= '<p class="count">' . format_plural(0, 'There is 1 image in this gallery.', 'There are @count images in this gallery.') . "</p>\n"; 122 } 123 124 return $content; 125 } 126 127 /** 128 * Theme a gallery image. 129 */ 130 function theme_image_gallery_img($image, $size) { 131 $width = $size['width']; 132 // We'll add height to keep thumbnails lined up. 133 $height = $size['height'] + 75; 134 135 $content = '<li'; 136 if ($image->sticky) { 137 $content .= ' class="sticky"'; 138 } 139 $content .= " style='height : {$height}px; width : {$width}px;'>\n"; 140 $content .= l(image_display($image, IMAGE_THUMBNAIL), 'node/' . $image->nid, array('html' => TRUE)); 141 $content .= '<h3>' . l($image->title, 'node/' . $image->nid) . '</h3>'; 142 if (variable_get('image_gallery_node_info', 0)) { 143 $content .= '<div class="author">' . t('Posted by: !name', array('!name' => theme('username', $image))) . "</div>\n"; 144 if ($image->created > 0) { 145 $content .= '<div class="date">' . format_date($image->created) . "</div>\n"; 146 } 147 } 148 $content .= "</li>\n"; 149 150 return $content; 151 } 152
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |