Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
// $Id$
/**
* gallery.module : gallery_block.inc
* Block functions
*/
/**
* Implementation of hook_block
*
* 0 - gallery imageblock (random, most viewed, etc)
* 1 - gallery navigation block (recommended)
* 2 - gallery grid block
*/
function _gallery_block($op = 'list', $delta = 0, $edit = array()) {
$typeMap = array('none' => t('None'),
'randomImage' => t('Random Image'),
'recentImage' => t('Newest Image'),
'viewedImage' => t('Most Viewed Image'),
'randomAlbum' => t('Random Album'),
'recentAlbum' => t('Newest Album'),
'viewedAlbum' => t('Most Viewed Album'),
'dailyImage' => t('Picture of the Day'),
'weeklyImage' => t('Picture of the Week'),
'monthlyImage' => t('Picture of the Month'),
'dailyAlbum' => t('Album of the Day'),
'weeklyAlbum' => t('Album of the Week'),
'monthlyAlbum' => t('Album of the Month'));
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Gallery Block');
$blocks[1]['info'] = t('Gallery Navigation');
$blocks[2]['info'] = t('Gallery Grid Block');
return $blocks;
case 'view':
list ($success, $ret) = _gallery_init(true);
if (!$success) {
$err_msg = t('Unable to initialize embedded Gallery. You need to <a href="%link">
configure your embedded Gallery</a>.',
array('%link' => url('admin/settings/gallery')));
gallery_error($err_msg, $ret);
return;
}
switch ($delta) {
// 0 = Image Block
case 0:
// Allow for multiple image types
$param_blocks_array = variable_get('gallery_block_block', array('randomImage'));
$params['blocks'] = is_array($param_blocks_array) ? implode('|', $param_blocks_array) : "";
$param_show_array = variable_get('gallery_block_show', array());
$params['show'] = is_array($param_show_array) ? implode('|', $param_show_array) : "";
$params['maxSize'] = variable_get('gallery_maxsize', 160);
// Add frames and link target using g2_filter code from MichelleC
$params['albumFrame'] = variable_get('gallery_album_frame', 'none');
$params['itemFrame'] = variable_get('gallery_item_frame', 'none');
$params['linkTarget'] = variable_get('gallery_link_target', '');
kiz_0987
committed
if (variable_get('gallery_item_id', '') != '') {
$params['itemId'] = variable_get('gallery_item_id', '');
}
$block = array();
list($ret, $content, $head) = GalleryEmbed::getImageBlock($params);
if ($ret) {
gallery_error(t('Unable to get Gallery image block'), $ret);
return;
} else {
if ($content) {
// If more than one image type selected then default the subject to 'Gallery'
if (count(variable_get('gallery_block_block', 'randomImage')) > 1) {
$block['subject'] = t('Gallery');
} else {
$block['subject'] = $typeMap[$params['blocks']];
}
// TODO: This should not be hardcoded, but included in the CSS.
$block['content'] = '<center>' . $content . '</center>';
}
}
if ($head) {
gallery_set_html_head($head);
}
break;
// 1 = Navigation Block
case 1:
global $gallery_sidebar;
if ((arg(0) == 'gallery') && (isset($gallery_sidebar) && !empty($gallery_sidebar))) {
$block['subject'] = t('Gallery Navigation');
$block['content'] = '<div id="gsSidebar" class="gcBorder1">' . join('', $gallery_sidebar) . '</div>';
$num_cols = variable_get('gallery_grid_num_cols', 2);
$num_rows = variable_get('gallery_grid_num_rows', 2);
$num_images = $num_cols * $num_rows;
// Allow for multiple image types
$param_blocks_array = array_fill(0, $num_images, variable_get('gallery_grid_block_block',
'randomImage'));
$params['blocks'] = is_array($param_blocks_array) ? implode('|', $param_blocks_array) : "";
$param_show_array = variable_get('gallery_grid_block_show', array());
$params['show'] = is_array($param_show_array) ? implode('|', $param_show_array) : "";
$params['maxSize'] = variable_get('gallery_grid_maxsize', 90);
$params['albumFrame'] = variable_get('gallery_grid_album_frame', 'none');
$params['itemFrame'] = variable_get('gallery_grid_item_frame', 'none');
$params['linkTarget'] = variable_get('gallery_grid_link_target', '');
kiz_0987
committed
if (variable_get('gallery_grid_item_id', '') != '') {
$params['itemId'] = variable_get('gallery_grid_item_id', '');
}
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
$block = array();
list($ret, $content, $head) = GalleryEmbed::getImageBlock($params);
if ($ret) {
gallery_error(t('Unable to get Gallery image block'), $ret);
return;
} else {
if ($content) {
$block['subject'] = t('Gallery');
// Split the images from the html so that can put each only in a <td>
$images = _gallery_split_imageblock($content);
$new_html = '<div class="gallery-grid-block"><div class="image-grid">';
$new_html .= '<table><tr>';
$col = 0;
foreach ($images as $current_image) {
$new_html .= '<td style="text-align:center;">' . $current_image . '</td>';
$col++;
if ($col >= $num_cols) {
$col = 0;
$new_html .= '</tr><tr>';
}
}
$new_html .= '</tr></table>';
$new_html .= '</div></div>';
$block['content'] .= $new_html;
}
}
if ($head) {
gallery_set_html_head($head);
}
break;
}
$ret = GalleryEmbed::done();
if ($ret) {
gallery_error(t('Unable to complete Gallery request'), $ret);
return;
}
return $block;
}
}
?>