| 1 |
<?php
|
| 2 |
// $Id: node_gallery.themes.inc,v 1.15 2009/05/06 01:57:01 kmonty Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Node gallery themes.
|
| 7 |
*
|
| 8 |
*/
|
| 9 |
|
| 10 |
function theme_gallery_list($items, $account = NULL) {
|
| 11 |
$output = '<div class="gallery-list">';
|
| 12 |
$output .= node_gallery_operations('list', $account);
|
| 13 |
if (empty($items)) {
|
| 14 |
$output .= t('There are currently no galleries.');
|
| 15 |
}
|
| 16 |
else {
|
| 17 |
$output .= theme('item_list', $items, NULL, 'ul', array('class' => 'gallery-cover-list'));
|
| 18 |
}
|
| 19 |
$output .= '</div>';
|
| 20 |
|
| 21 |
return $output;
|
| 22 |
}
|
| 23 |
|
| 24 |
function template_preprocess_gallery_cover_view(&$vars) {
|
| 25 |
$gallery = $vars['gallery'];
|
| 26 |
$config = $vars['config'];
|
| 27 |
if (empty($gallery->cover)) {
|
| 28 |
$gallery->cover->filepath = $config->default_cover;
|
| 29 |
}
|
| 30 |
$gallery->cover->title = $gallery->title;
|
| 31 |
$vars['cover_image'] = theme('image_view', $config->image_size['cover'], $gallery->cover);
|
| 32 |
$vars['meta_data'] = theme('item_list', theme('gallery_meta', $gallery));
|
| 33 |
$vars['cover_operations'] = node_gallery_operations('cover', $gallery);
|
| 34 |
}
|
| 35 |
|
| 36 |
function theme_gallery_meta($gallery) {
|
| 37 |
$items[] = format_plural($gallery->image_count, '1 image', '@count images');
|
| 38 |
$items[] = t('Created at: !date', array('!date' => format_date($gallery->created, 'custom', 'Y-m-d')));
|
| 39 |
|
| 40 |
return $items;
|
| 41 |
}
|
| 42 |
|
| 43 |
function theme_gallery_image_view($type, $image, $config) {
|
| 44 |
if ($type == 'cover') {
|
| 45 |
if (empty($image)) {
|
| 46 |
$image->filepath = $config->default_cover;
|
| 47 |
}
|
| 48 |
}
|
| 49 |
|
| 50 |
return theme('imagecache', $config->image_size[$type], $image->filepath, $image->title, $image->title, array('class' => 'gallery-image-'. $type));
|
| 51 |
}
|
| 52 |
|
| 53 |
function theme_gallery_teaser($gallery, $config) {
|
| 54 |
//cover display
|
| 55 |
if ($config->teaser['gallery_display_type'] == 'cover') {
|
| 56 |
// Make sure to avoid an "Invalid argument supplied for foreach()" error
|
| 57 |
if ($gallery->images) {
|
| 58 |
$no_cover = TRUE;
|
| 59 |
foreach ($gallery->images as $image) {
|
| 60 |
if ($image->is_cover) {
|
| 61 |
$cover = $image;
|
| 62 |
$no_cover = FALSE;
|
| 63 |
break;
|
| 64 |
}
|
| 65 |
}
|
| 66 |
unset($image);
|
| 67 |
|
| 68 |
// If there is no cover image, use the first one
|
| 69 |
if ($no_cover == TRUE) {
|
| 70 |
$cover = $gallery->images[0];
|
| 71 |
}
|
| 72 |
}
|
| 73 |
$cover->filepath = empty($cover->filepath) ? $config->default_cover : $cover->filepath;
|
| 74 |
$cover->title = $gallery->title;
|
| 75 |
$image_tag = theme('image_view', $config->image_size['cover'], $cover);
|
| 76 |
return l($image_tag, 'node/'. $gallery->nid, array('html' => TRUE));
|
| 77 |
}
|
| 78 |
// Lightbox2 gallery display
|
| 79 |
elseif ($config->teaser['gallery_display_type'] == 'lightbox2_gallery' && module_exists('lightbox2')) {
|
| 80 |
// Note - There is no display num, as lightbox2 will require seeing all
|
| 81 |
// thumbs
|
| 82 |
// Make sure to avoid an "Invalid argument supplied for foreach()" error
|
| 83 |
if ($gallery->images) {
|
| 84 |
foreach ($gallery->images as $image) {
|
| 85 |
$image_tag = theme('image_view', $config->image_size['thumbnail'], $image);
|
| 86 |
$items[] = l($image_tag, imagecache_create_url($config->teaser['lightbox2_gallery'], $image->filepath), array('html' => TRUE, 'attributes' => array('rel' => 'lightshow['. $gallery->nid .']')));
|
| 87 |
}
|
| 88 |
}
|
| 89 |
return theme('item_list', $items);
|
| 90 |
}
|
| 91 |
else { // return thumbnail display
|
| 92 |
$display_num = $config->teaser['thumbnails_num'];
|
| 93 |
$i = 0;
|
| 94 |
// Make sure to avoid an "Invalid argument supplied for foreach()" error
|
| 95 |
if ($gallery->images) {
|
| 96 |
foreach ($gallery->images as $image) {
|
| 97 |
if ($i < $display_num) {
|
| 98 |
$image_tag = theme('image_view', $config->image_size['thumbnail'], $image);
|
| 99 |
$items[] = l($image_tag, 'node/'. $gallery->nid, array('html' => TRUE));
|
| 100 |
}
|
| 101 |
}
|
| 102 |
}
|
| 103 |
return theme('item_list', $items);
|
| 104 |
}
|
| 105 |
}
|
| 106 |
|
| 107 |
function theme_image_view($imagecache, $image) {
|
| 108 |
return theme('imagecache', $imagecache, $image->filepath, $image->title, $image->title);
|
| 109 |
}
|
| 110 |
|
| 111 |
function theme_gallery_edit_images_form(&$form) {
|
| 112 |
drupal_add_tabledrag('upload-attachments', 'order', 'sibling', 'upload-weight');
|
| 113 |
|
| 114 |
$header = array('', t('Delete'), t('Thumbnail'), t('Edit'), t('Weight'), t('Cover'));
|
| 115 |
foreach (element_children($form['files']) as $key) {
|
| 116 |
// Add class to group weight fields for drag and drop.
|
| 117 |
$form['files'][$key]['weight']['#attributes']['class'] = 'upload-weight';
|
| 118 |
|
| 119 |
$row = array('');
|
| 120 |
$row[] = drupal_render($form['files'][$key]['remove']);
|
| 121 |
$row[] = theme('imagecache', $form['#config']->image_size['thumbnail'],
|
| 122 |
$form['files'][$key]['filepath']['#value'], $form['files'][$key]['filename']['#value'], $form['files'][$key]['filename']['#value']);
|
| 123 |
$row[] = drupal_render($form['files'][$key]['edit_form']);
|
| 124 |
$row[] = drupal_render($form['files'][$key]['weight']);
|
| 125 |
if ($form['is_cover']) {
|
| 126 |
$row[] = drupal_render($form['is_cover'][$key]);
|
| 127 |
}
|
| 128 |
$rows[] = array('data' => $row, 'class' => 'draggable');
|
| 129 |
}
|
| 130 |
$output = theme('table', $header, $rows, array('id' => 'upload-attachments'));
|
| 131 |
$output .= drupal_render($form);
|
| 132 |
return $output;
|
| 133 |
}
|
| 134 |
|
| 135 |
function theme_gallery_images_list($gallery, $config) {
|
| 136 |
$output = '<div class="gallery-images-list">';
|
| 137 |
if (!count($gallery->images)) {
|
| 138 |
$output .= '<p>'. t('There are no photos in this gallery currently.');
|
| 139 |
if (node_gallery_user_access('edit', $gallery)) {
|
| 140 |
$output .= ' '. l('Upload Some!', 'node/'. $gallery->nid .'/upload', array('query' => 'destination=node/'. $gallery->nid));
|
| 141 |
}
|
| 142 |
$output .= '</p>';
|
| 143 |
}
|
| 144 |
elseif ($config->gallery['gallery_display'] == 'lightbox2_gallery' && module_exists('lightbox2')) {
|
| 145 |
foreach ($gallery->images as $nid => $image) {
|
| 146 |
$items[] = theme('gallery_image_lightbox2', $image, $config, $gallery);
|
| 147 |
}
|
| 148 |
$output .= theme('item_list', $items);
|
| 149 |
}
|
| 150 |
elseif ($config->gallery['gallery_display'] == 'cover') {
|
| 151 |
$no_cover = TRUE;
|
| 152 |
foreach ($gallery->images as $image) {
|
| 153 |
if ($image->is_cover) {
|
| 154 |
$cover = $image;
|
| 155 |
$no_cover = FALSE;
|
| 156 |
break;
|
| 157 |
}
|
| 158 |
}
|
| 159 |
unset($image);
|
| 160 |
|
| 161 |
// If there is no cover image, use the first one
|
| 162 |
if ($no_cover == TRUE) {
|
| 163 |
$keys = array_keys($gallery->images);
|
| 164 |
$first_key = $keys[0];
|
| 165 |
$cover = $gallery->images[$first_key];
|
| 166 |
unset($keys, $first_key);
|
| 167 |
}
|
| 168 |
|
| 169 |
$navigator = new Gallery(array('nid' => $gallery->nid));
|
| 170 |
$navigation = $navigator->get_image_navigator($cover->nid);
|
| 171 |
$cover->filepath = empty($cover->filepath) ? $config->default_cover : $cover->filepath;
|
| 172 |
$cover->title = $gallery->title;
|
| 173 |
$output .= l(theme('image_view', $config->gallery['image'], $cover), 'node/'. $navigation['next_nid'], array('html' => TRUE));
|
| 174 |
$output .= '<p>'. l(t('Continue to the Next Photo'), 'node/'. $navigation['next_nid'], array('html' => TRUE)) .'</p>';
|
| 175 |
}
|
| 176 |
else {
|
| 177 |
foreach ($gallery->images as $nid => $image) {
|
| 178 |
$items[] = theme('gallery_image_thumbnail', $image, $config);
|
| 179 |
}
|
| 180 |
unset($image);
|
| 181 |
$output .= theme('item_list', $items);
|
| 182 |
}
|
| 183 |
|
| 184 |
$output .= '</div>';
|
| 185 |
|
| 186 |
return $output;
|
| 187 |
}
|
| 188 |
|
| 189 |
function theme_gallery_image_thumbnail($image, $config) {
|
| 190 |
$output = '<div class="image-thumbnail">';
|
| 191 |
$output .= l(theme('image_view', $config->gallery['image'], $image), 'node/'. $image->nid, array('html' => TRUE));
|
| 192 |
$output .= l($image->title, 'node/'. $image->nid);
|
| 193 |
$output .= '</div>';
|
| 194 |
return $output;
|
| 195 |
}
|
| 196 |
|
| 197 |
function theme_gallery_image_lightbox2($image, $config, $gallery) {
|
| 198 |
$output = '<div class="image-thumbnail">';
|
| 199 |
$output .= l(theme('image_view', $config->gallery['image'], $image), imagecache_create_url($config->gallery['lightbox2_gallery_preset'], $image->filepath), array('html' => TRUE, 'attributes' => array('rel' => 'lightshow[hi]')));
|
| 200 |
$output .= l($image->title, 'node/'. $image->nid);
|
| 201 |
$output .= '</div>';
|
| 202 |
return $output;
|
| 203 |
}
|
| 204 |
|
| 205 |
function theme_gallery_image_navigator($navigator, $image) {
|
| 206 |
$col1 = array('data' => t("Image %current/Total %total", array('%current' => $navigator['current'], '%total' => $navigator['total'])),
|
| 207 |
'class' => 'image-navigator-left');
|
| 208 |
$col2 = array('data' => l(t('Prev'), 'node/'. $navigator['prev_nid']) .'/'. l(t('Next'), 'node/'. $navigator['next_nid']),
|
| 209 |
'class' => 'image-navigator-mid');
|
| 210 |
$col3 = array('data' => node_gallery_operations('image', $image), 'class' => 'image-navigator-right');
|
| 211 |
$rows[] = array($col1, $col2, $col3);
|
| 212 |
|
| 213 |
return theme('table', NULL, $rows, array('class' => 'image-navigator'));
|
| 214 |
}
|
| 215 |
|
| 216 |
/**
|
| 217 |
* theme_node_gallery_image()
|
| 218 |
*
|
| 219 |
* This is the code that directly calls the image node (page view) display
|
| 220 |
* We provide this theme function as a user may way to inject some custom markup
|
| 221 |
* around already determined theme functions
|
| 222 |
*/
|
| 223 |
function theme_node_gallery_image($config, $node) {
|
| 224 |
$image_view = theme('image_view', $config->image_size['preview'], $node);
|
| 225 |
if ($config->view_original == 'default') {
|
| 226 |
$output = l($image_view, file_create_url($node->filepath),
|
| 227 |
array('attributes' => array('target' => '_blank'), 'html' => TRUE));
|
| 228 |
}
|
| 229 |
elseif ($config->view_original == 'text') {
|
| 230 |
$download_text = t('Download the Original Image');
|
| 231 |
if (check_plain($config->view_original_text) != '') {
|
| 232 |
$download_text = check_plain($config->view_original_text);
|
| 233 |
}
|
| 234 |
$output = $image_view . '<div class="download-full-link">'. l($download_text, file_create_url($node->filepath),
|
| 235 |
array('attributes' => array('target' => '_blank'), 'html' => FALSE)) .'</div>';
|
| 236 |
}
|
| 237 |
elseif ($config->view_original == 'lightbox2') {
|
| 238 |
$output = l($image_view, imagecache_create_url($config->lightbox2, $node->filepath), array('attributes' => array('rel' => 'lightbox'), 'html' => TRUE));
|
| 239 |
}
|
| 240 |
else {
|
| 241 |
$output = $image_view;
|
| 242 |
}
|
| 243 |
return '<div class="image-preview">'. $output .'</div>';
|
| 244 |
}
|
| 245 |
|
| 246 |
/**
|
| 247 |
* theme_node_gallery_teaser()
|
| 248 |
*
|
| 249 |
* In the event the teaser image_view is directly called, we want to
|
| 250 |
* allow people to be able to wrap the image with custom markup
|
| 251 |
*/
|
| 252 |
function theme_node_gallery_teaser($config, $node) {
|
| 253 |
return theme('image_view', $config->teaser['image'], $node);
|
| 254 |
}
|