| 1 |
<?php
|
| 2 |
// $Id: gallery_block.inc,v 1.6.2.13 2007/09/10 18:04:08 profix898 Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* gallery.module : gallery_block.inc
|
| 6 |
* Block functions
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_block().
|
| 11 |
*
|
| 12 |
* 0 - gallery imageblock (random, most viewed, etc)
|
| 13 |
* 1 - gallery navigation block (recommended)
|
| 14 |
* 2 - gallery grid block
|
| 15 |
*/
|
| 16 |
function _gallery_block($op = 'list', $delta = 0, $edit = array()) {
|
| 17 |
$type_map = $param_map = array();
|
| 18 |
_gallery_block_options($type_map, $param_map);
|
| 19 |
|
| 20 |
list($type, $delta) = (stristr($delta, '-') !== FALSE) ? explode('-', $delta) : array('', 0);
|
| 21 |
switch ($op) {
|
| 22 |
case 'list':
|
| 23 |
$blocks['navigation']['info'] = t('Gallery Navigation');
|
| 24 |
$imageblock_num = variable_get('gallery_block_image_num', 1);
|
| 25 |
for ($i=0; $i<$imageblock_num; $i++) {
|
| 26 |
$id = variable_get('gallery_block_image_'. $i .'_blockid', '');
|
| 27 |
$blocks['image-'. $i]['info'] = t('Gallery Image Block @id',
|
| 28 |
array('@id' => ($imageblock_num > 1) ? ('['. ($id ? $id : $i+1) .']') : ''));
|
| 29 |
}
|
| 30 |
$gridblock_num = variable_get('gallery_block_grid_num', 1);
|
| 31 |
for ($i=0; $i<$gridblock_num; $i++) {
|
| 32 |
$id = variable_get('gallery_block_grid_'. $i .'_blockid', '');
|
| 33 |
$blocks['grid-'. $i]['info'] = t('Gallery Grid Block @id',
|
| 34 |
array('@id' => ($gridblock_num > 1) ? ('['. ($id ? $id : $i+1) .']') : ''));
|
| 35 |
}
|
| 36 |
return $blocks;
|
| 37 |
case 'view':
|
| 38 |
if (!user_access('access gallery') || !_gallery_init(TRUE) || $_GET['q'] == 'admin/settings/gallery/install') {
|
| 39 |
return;
|
| 40 |
}
|
| 41 |
switch ($type) {
|
| 42 |
case 'navigation': // Navigation Block
|
| 43 |
global $_gallery_sidebar_;
|
| 44 |
if ((arg(0) == 'gallery') && !empty($_gallery_sidebar_)) {
|
| 45 |
$block['subject'] = t('Gallery Navigation');
|
| 46 |
$block['content'] = '<div id="gsSidebar" class="gcBorder1">'. implode('', $_gallery_sidebar_) .'</div>';
|
| 47 |
}
|
| 48 |
break;
|
| 49 |
case 'image': // Image Block
|
| 50 |
$block = _gallery_block_image_block($delta, $type_map);
|
| 51 |
break;
|
| 52 |
case 'grid': // Image Grid Block
|
| 53 |
$block = _gallery_block_grid_block($delta, $type_map);
|
| 54 |
break;
|
| 55 |
}
|
| 56 |
GalleryEmbed::done();
|
| 57 |
return $block;
|
| 58 |
case 'configure':
|
| 59 |
require_once(drupal_get_path('module', 'gallery') .'/gallery_settings.inc');
|
| 60 |
switch ($type) {
|
| 61 |
case 'image': // Image Block
|
| 62 |
return _gallery_settings_block_image($delta);
|
| 63 |
case 'grid': // Image Grid Block
|
| 64 |
return _gallery_settings_block_grid($delta);
|
| 65 |
}
|
| 66 |
case 'save':
|
| 67 |
require_once(drupal_get_path('module', 'gallery') .'/gallery_settings.inc');
|
| 68 |
_gallery_settings_block_save($delta, $edit);
|
| 69 |
break;
|
| 70 |
}
|
| 71 |
}
|
| 72 |
|
| 73 |
/**
|
| 74 |
* Function _gallery_block_options().
|
| 75 |
*/
|
| 76 |
function _gallery_block_options(&$type_map, &$param_map) {
|
| 77 |
$type_map = array(
|
| 78 |
'randomImage' => t('Random image'),
|
| 79 |
'recentImage' => t('Recent image'),
|
| 80 |
'viewedImage' => t('Viewed image'),
|
| 81 |
'randomAlbum' => t('Random album'),
|
| 82 |
'recentAlbum' => t('Recent album'),
|
| 83 |
'viewedAlbum' => t('Viewed album'),
|
| 84 |
'dailyImage' => t('Daily image'),
|
| 85 |
'weeklyImage' => t('Weekly image'),
|
| 86 |
'monthlyImage' => t('Monthly image'),
|
| 87 |
'dailyAlbum' => t('Daily album'),
|
| 88 |
'weeklyAlbum' => t('Weekly album'),
|
| 89 |
'monthlyAlbum' => t('Monthly album'),
|
| 90 |
);
|
| 91 |
$param_map = array(
|
| 92 |
'title' => t('Title'),
|
| 93 |
'date' => t('Date'),
|
| 94 |
'views' => t('View Count'),
|
| 95 |
'owner' => t('Item owner'),
|
| 96 |
'heading' => t('Heading'),
|
| 97 |
);
|
| 98 |
}
|
| 99 |
|
| 100 |
/**
|
| 101 |
* Function _gallery_block_image_block().
|
| 102 |
*/
|
| 103 |
function _gallery_block_image_block($delta, $type_map) {
|
| 104 |
$param_blocks_array = variable_get('gallery_block_image_'. $delta .'_block_block', array('randomImage'));
|
| 105 |
$params['blocks'] = is_array($param_blocks_array) ? implode('|', $param_blocks_array) : '';
|
| 106 |
$param_itemid = variable_get('gallery_block_image_'. $delta .'_item_id', '');
|
| 107 |
if (trim($param_itemid) == '%user') {
|
| 108 |
require_once(drupal_get_path('module', 'gallery') .'/gallery_user.inc');
|
| 109 |
$param_itemid = gallery_user_useralbum(NULL, FALSE);
|
| 110 |
}
|
| 111 |
if (!empty($param_itemid)) {
|
| 112 |
$params['itemId'] = $param_itemid;
|
| 113 |
}
|
| 114 |
$param_show_array = variable_get('gallery_block_image_'. $delta .'_block_show', array());
|
| 115 |
$params['show'] = is_array($param_show_array) ? implode('|', $param_show_array) : '';
|
| 116 |
if (variable_get('gallery_block_image_'. $delta .'_size_method', GALLERY_IMAGEBLOCK_SIZE_METHOD_DEFAULT) == 'maxsize') {
|
| 117 |
$params['maxSize'] = variable_get('gallery_block_image_'. $delta .'_size', GALLERY_IMAGEBLOCK_SIZE_DEFAULT);
|
| 118 |
}
|
| 119 |
else {
|
| 120 |
$params['exactSize'] = variable_get('gallery_block_image_'. $delta .'_size', GALLERY_IMAGEBLOCK_SIZE_DEFAULT);
|
| 121 |
}
|
| 122 |
$params['albumFrame'] = variable_get('gallery_block_image_'. $delta .'_album_frame', 'none');
|
| 123 |
$params['itemFrame'] = variable_get('gallery_block_image_'. $delta .'_item_frame', 'none');
|
| 124 |
$params['linkTarget'] = variable_get('gallery_block_image_'. $delta .'_link_target', '');
|
| 125 |
$params['link'] = variable_get('gallery_block_image_'. $delta .'_link', '');
|
| 126 |
|
| 127 |
$block = array();
|
| 128 |
list($ret, $content, $head) = GalleryEmbed::getImageBlock($params);
|
| 129 |
if ($ret) {
|
| 130 |
gallery_error(t('Unable to get Gallery image block'), $ret);
|
| 131 |
return array();
|
| 132 |
}
|
| 133 |
|
| 134 |
if ($content) {
|
| 135 |
if (count($param_blocks_array) > 1) {
|
| 136 |
$block['subject'] = t('Gallery');
|
| 137 |
}
|
| 138 |
else {
|
| 139 |
$block['subject'] = $type_map[$params['blocks']];
|
| 140 |
}
|
| 141 |
$block['content'] = theme('gallery_block_image_block', $content);
|
| 142 |
}
|
| 143 |
if ($head) {
|
| 144 |
gallery_set_head($head);
|
| 145 |
}
|
| 146 |
|
| 147 |
return $block;
|
| 148 |
}
|
| 149 |
|
| 150 |
/**
|
| 151 |
* Theme function : theme_gallery_block_image_block().
|
| 152 |
*/
|
| 153 |
function theme_gallery_block_image_block($content) {
|
| 154 |
return '<div class="g2image_centered">'. $content .'</div>';
|
| 155 |
}
|
| 156 |
|
| 157 |
/**
|
| 158 |
* Function _gallery_block_grid_block().
|
| 159 |
*/
|
| 160 |
function _gallery_block_grid_block($delta, $type_map) {
|
| 161 |
$num_cols = variable_get('gallery_block_grid_'. $delta .'_num_cols', 2);
|
| 162 |
$num_rows = variable_get('gallery_block_grid_'. $delta .'_num_rows', 2);
|
| 163 |
$num_images = $num_cols * $num_rows;
|
| 164 |
|
| 165 |
$param_blocks_array = array_fill(0, $num_images, variable_get('gallery_block_grid_'. $delta .'_block_block', 'randomImage'));
|
| 166 |
$params['blocks'] = is_array($param_blocks_array) ? implode('|', $param_blocks_array) : '';
|
| 167 |
$param_itemid = variable_get('gallery_block_grid_'. $delta .'_item_id', '');
|
| 168 |
if (trim($param_itemid) == '%user') {
|
| 169 |
require_once(drupal_get_path('module', 'gallery') .'/gallery_user.inc');
|
| 170 |
$param_itemid = gallery_user_useralbum(NULL, FALSE);
|
| 171 |
}
|
| 172 |
if (!empty($param_itemid)) {
|
| 173 |
$params['itemId'] = $param_itemid;
|
| 174 |
}
|
| 175 |
$param_show_array = variable_get('gallery_block_grid_'. $delta .'_block_show', array());
|
| 176 |
$params['show'] = is_array($param_show_array) ? implode('|', $param_show_array) : '';
|
| 177 |
if (variable_get('gallery_block_grid_'. $delta .'_size_method', GALLERY_GRID_SIZE_METHOD_DEFAULT) == 'maxsize') {
|
| 178 |
$params['maxSize'] = variable_get('gallery_block_grid_'. $delta .'_size', GALLERY_GRID_SIZE_DEFAULT);
|
| 179 |
}
|
| 180 |
else {
|
| 181 |
$params['exactSize'] = variable_get('gallery_block_grid_'. $delta .'_size', GALLERY_GRID_SIZE_DEFAULT);
|
| 182 |
}
|
| 183 |
$params['albumFrame'] = variable_get('gallery_block_grid_'. $delta .'_album_frame', 'none');
|
| 184 |
$params['itemFrame'] = variable_get('gallery_block_grid_'. $delta .'_item_frame', 'none');
|
| 185 |
$params['linkTarget'] = variable_get('gallery_block_grid_'. $delta .'_link_target', '');
|
| 186 |
$params['link'] = variable_get('gallery_block_grid_'. $delta .'_link', '');
|
| 187 |
|
| 188 |
$block = array();
|
| 189 |
list($ret, $content, $head) = GalleryEmbed::getImageBlock($params);
|
| 190 |
if ($ret) {
|
| 191 |
gallery_error(t('Unable to get Gallery image block'), $ret);
|
| 192 |
return array();
|
| 193 |
}
|
| 194 |
if ($content) {
|
| 195 |
$block['subject'] = t('Gallery');
|
| 196 |
$images = _gallery_split_imageblock($content);
|
| 197 |
$images = array_chunk($images, $num_cols);
|
| 198 |
$block['content'] = theme('gallery_block_grid_block', $images);
|
| 199 |
}
|
| 200 |
if ($head) {
|
| 201 |
gallery_set_head($head);
|
| 202 |
}
|
| 203 |
|
| 204 |
return $block;
|
| 205 |
}
|
| 206 |
|
| 207 |
/**
|
| 208 |
* Theme function : theme_gallery_block_grid_block().
|
| 209 |
*/
|
| 210 |
function theme_gallery_block_grid_block($images) {
|
| 211 |
$rows = array();
|
| 212 |
foreach ($images as $image_row) {
|
| 213 |
$row = array();
|
| 214 |
foreach ($image_row as $image) {
|
| 215 |
$row[] = array('data' => $image, 'style' => 'text-align:center;');
|
| 216 |
}
|
| 217 |
$rows[] = $row;
|
| 218 |
}
|
| 219 |
|
| 220 |
$html = '<div class="gallery-grid-block"><div class="image-grid">';
|
| 221 |
$html .= theme('table', array(), $rows);
|
| 222 |
$html .= '</div></div>';
|
| 223 |
|
| 224 |
return $html;
|
| 225 |
}
|