5 * gallery.module : gallery_block.inc
10 * Implementation of hook_block
12 * 0 - gallery imageblock (random, most viewed, etc)
13 * 1 - gallery navigation block (recommended)
14 * 2 - gallery grid block
16 function _gallery_block($op = 'list', $delta = 0, $edit = array()) {
17 $typeMap = array('none' => t('None'),
18 'randomImage' => t('Random Image'),
19 'recentImage' => t('Newest Image'),
20 'viewedImage' => t('Most Viewed Image'),
21 'randomAlbum' => t('Random Album'),
22 'recentAlbum' => t('Newest Album'),
23 'viewedAlbum' => t('Most Viewed Album'),
24 'dailyImage' => t('Picture of the Day'),
25 'weeklyImage' => t('Picture of the Week'),
26 'monthlyImage' => t('Picture of the Month'),
27 'dailyAlbum' => t('Album of the Day'),
28 'weeklyAlbum' => t('Album of the Week'),
29 'monthlyAlbum' => t('Album of the Month'));
33 $blocks[0]['info'] = t('Gallery Block');
34 $blocks[1]['info'] = t('Gallery Navigation');
35 $blocks[2]['info'] = t('Gallery Grid Block');
39 if (!user_access('access gallery')) {
42 list ($success, $ret) = _gallery_init(true
);
44 $err_msg = t('Unable to initialize embedded Gallery. You need to <a href="%link">
45 configure your embedded Gallery</a>.',
46 array('%link' => url('admin/settings/gallery')));
47 gallery_error($err_msg, $ret);
53 // Allow for multiple image types
54 $param_blocks_array = variable_get('gallery_block_block', array('randomImage'));
55 $params['blocks'] = is_array($param_blocks_array) ?
implode('|', $param_blocks_array) : "";
56 $param_show_array = variable_get('gallery_block_show', array());
57 $params['show'] = is_array($param_show_array) ?
implode('|', $param_show_array) : "";
58 $params['maxSize'] = variable_get('gallery_maxsize', 160);
59 // Add frames and link target using g2_filter code from MichelleC
60 $params['albumFrame'] = variable_get('gallery_album_frame', 'none');
61 $params['itemFrame'] = variable_get('gallery_item_frame', 'none');
62 $params['linkTarget'] = variable_get('gallery_link_target', '');
63 if (variable_get('gallery_item_id', '') != '') {
64 $params['itemId'] = variable_get('gallery_item_id', '');
67 list($ret, $content, $head) = GalleryEmbed
::getImageBlock($params);
69 gallery_error(t('Unable to get Gallery image block'), $ret);
73 // If more than one image type selected then default the subject to 'Gallery'
74 if (count(variable_get('gallery_block_block', 'randomImage')) > 1) {
75 $block['subject'] = t('Gallery');
77 $block['subject'] = $typeMap[$params['blocks']];
79 // TODO: This should not be hardcoded, but included in the CSS.
80 $block['content'] = '<center>' .
$content .
'</center>';
84 gallery_set_html_head($head);
87 // 1 = Navigation Block
89 global $gallery_sidebar;
90 if ((arg(0) == 'gallery') && (isset($gallery_sidebar) && !empty($gallery_sidebar))) {
91 $block['subject'] = t('Gallery Navigation');
92 $block['content'] = '<div id="gsSidebar" class="gcBorder1">' .
join('', $gallery_sidebar) .
'</div>';
95 // 2 = Image Grid Block
97 $num_cols = variable_get('gallery_grid_num_cols', 2);
98 $num_rows = variable_get('gallery_grid_num_rows', 2);
99 $num_images = $num_cols * $num_rows;
100 // Allow for multiple image types
101 $param_blocks_array = array_fill(0, $num_images, variable_get('gallery_grid_block_block',
103 $params['blocks'] = is_array($param_blocks_array) ?
implode('|', $param_blocks_array) : "";
104 $param_show_array = variable_get('gallery_grid_block_show', array());
105 $params['show'] = is_array($param_show_array) ?
implode('|', $param_show_array) : "";
106 $params['maxSize'] = variable_get('gallery_grid_maxsize', 90);
107 $params['albumFrame'] = variable_get('gallery_grid_album_frame', 'none');
108 $params['itemFrame'] = variable_get('gallery_grid_item_frame', 'none');
109 $params['linkTarget'] = variable_get('gallery_grid_link_target', '');
110 if (variable_get('gallery_grid_item_id', '') != '') {
111 $params['itemId'] = variable_get('gallery_grid_item_id', '');
114 list($ret, $content, $head) = GalleryEmbed
::getImageBlock($params);
116 gallery_error(t('Unable to get Gallery image block'), $ret);
120 $block['subject'] = t('Gallery');
121 // Split the images from the html so that can put each only in a <td>
122 $images = _gallery_split_imageblock($content);
123 $new_html = '<div class="gallery-grid-block"><div class="image-grid">';
124 $new_html .
= '<table>';
126 foreach ($images as
$current_image) {
130 $new_html .
= '<td style="text-align:center;">' .
$current_image .
'</td>';
132 if ($col >= $num_cols) {
134 $new_html .
= '</tr>';
137 $new_html .
= '</table>';
138 $new_html .
= '</div></div>';
139 $block['content'] .
= $new_html;
143 gallery_set_html_head($head);
147 $ret = GalleryEmbed
::done();
149 gallery_error(t('Unable to complete Gallery request'), $ret);