($imageblock_num > 1) ? ('['. ($id ? $id : $i+1) .']') : '')); } $gridblock_num = variable_get('gallery_block_grid_num', 1); for ($i=0; $i<$gridblock_num; $i++) { $id = variable_get('gallery_block_grid_'. $i .'_blockid', ''); $blocks['grid-'. $i]['info'] = t('Gallery Grid Block @id', array('@id' => ($gridblock_num > 1) ? ('['. ($id ? $id : $i+1) .']') : '')); } return $blocks; case 'view': if (!user_access('access gallery') || !_gallery_init(TRUE) || $_GET['q'] == 'admin/settings/gallery/install') { return; } switch ($type) { case 'navigation': // Navigation Block if ((arg(0) == 'gallery') && !empty($GLOBALS['gallery_sidebar'])) { $block['subject'] = t('Gallery Navigation'); $block['content'] = '
'. implode('', $GLOBALS['gallery_sidebar']) .'
'; } break; case 'image': // Image Block $block = _gallery_block_image_block($delta, $type_map); break; case 'grid': // Image Grid Block $block = _gallery_block_grid_block($delta, $type_map); break; } GalleryEmbed::done(); return $block; case 'configure': require_once(drupal_get_path('module', 'gallery') .'/gallery_settings.inc'); switch ($type) { case 'image': // Image Block return _gallery_settings_block_image($delta); case 'grid': // Image Grid Block return _gallery_settings_block_grid($delta); } break; case 'save': require_once(drupal_get_path('module', 'gallery') .'/gallery_settings.inc'); _gallery_settings_block_save($delta, $edit); break; } } /** * Function _gallery_block_options(). */ function _gallery_block_options(&$type_map, &$param_map) { $type_map = array( 'randomImage' => t('Random image'), 'recentImage' => t('Recent image'), 'viewedImage' => t('Viewed image'), 'randomAlbum' => t('Random album'), 'recentAlbum' => t('Recent album'), 'viewedAlbum' => t('Viewed album'), 'dailyImage' => t('Daily image'), 'weeklyImage' => t('Weekly image'), 'monthlyImage' => t('Monthly image'), 'dailyAlbum' => t('Daily album'), 'weeklyAlbum' => t('Weekly album'), 'monthlyAlbum' => t('Monthly album') ); $param_map = array( 'title' => t('Title'), 'date' => t('Date'), 'views' => t('View Count'), 'owner' => t('Item owner'), 'heading' => t('Heading') ); } /** * Function _gallery_block_image_block(). */ function _gallery_block_image_block($delta, $type_map) { $param_blocks_array = array_filter(variable_get('gallery_block_image_'. $delta .'_block_block', array('randomImage'))); $params['blocks'] = is_array($param_blocks_array) ? implode('|', $param_blocks_array) : ''; $params['itemId'] = variable_get('gallery_block_image_'. $delta .'_item_id', ''); $param_show_array = variable_get('gallery_block_image_'. $delta .'_block_show', array()); $params['show'] = is_array($param_show_array) ? implode('|', $param_show_array) : ''; if (variable_get('gallery_block_image_'. $delta .'_size_method', GALLERY_IMAGEBLOCK_SIZE_METHOD_DEFAULT) == 'maxsize') { $params['maxSize'] = variable_get('gallery_block_image_'. $delta .'_size', GALLERY_IMAGEBLOCK_SIZE_DEFAULT); } else { $params['exactSize'] = variable_get('gallery_block_image_'. $delta .'_size', GALLERY_IMAGEBLOCK_SIZE_DEFAULT); } $params['albumFrame'] = variable_get('gallery_block_image_'. $delta .'_album_frame', 'none'); $params['itemFrame'] = variable_get('gallery_block_image_'. $delta .'_item_frame', 'none'); $params['linkTarget'] = variable_get('gallery_block_image_'. $delta .'_link_target', ''); $params['link'] = variable_get('gallery_block_image_'. $delta .'_link', ''); $block = _gallery_block_get_block($params); $block['subject'] = (count($param_blocks_array) > 1) ? t('Gallery') : $type_map[$params['blocks']]; return $block; } /** * Function _gallery_block_grid_block(). */ function _gallery_block_grid_block($delta, $type_map) { $num_cols = variable_get('gallery_block_grid_'. $delta .'_num_cols', 2); $num_rows = variable_get('gallery_block_grid_'. $delta .'_num_rows', 2); $num_images = $num_cols * $num_rows; $param_blocks_array = array_fill(0, $num_images, variable_get('gallery_block_grid_'. $delta .'_block_block', 'randomImage')); $params['blocks'] = is_array($param_blocks_array) ? implode('|', $param_blocks_array) : ''; $params['itemId'] = variable_get('gallery_block_grid_'. $delta .'_item_id', ''); $param_show_array = variable_get('gallery_block_grid_'. $delta .'_block_show', array()); $params['show'] = is_array($param_show_array) ? implode('|', $param_show_array) : ''; if (variable_get('gallery_block_grid_'. $delta .'_size_method', GALLERY_GRID_SIZE_METHOD_DEFAULT) == 'maxsize') { $params['maxSize'] = variable_get('gallery_block_grid_'. $delta .'_size', GALLERY_GRID_SIZE_DEFAULT); } else { $params['exactSize'] = variable_get('gallery_block_grid_'. $delta .'_size', GALLERY_GRID_SIZE_DEFAULT); } $params['albumFrame'] = variable_get('gallery_block_grid_'. $delta .'_album_frame', 'none'); $params['itemFrame'] = variable_get('gallery_block_grid_'. $delta .'_item_frame', 'none'); $params['linkTarget'] = variable_get('gallery_block_grid_'. $delta .'_link_target', ''); $params['link'] = variable_get('gallery_block_grid_'. $delta .'_link', ''); return _gallery_block_get_block($params, array('num_cols' => $num_cols)); } /** * Function _gallery_block_get_block(). */ function _gallery_block_get_block($params, $extra = array()) { // Handle useralbum feature if (preg_match('/user(:([\d]+))?/i', $params['itemId'], $param_uid)) { require_once(drupal_get_path('module', 'gallery') .'/gallery_user.inc'); $params['itemId'] = gallery_user_useralbum(isset($param_uid[2]) ? $param_uid[2] : NULL, FALSE); } if (empty($params['itemId']) || $params['itemId'] === FALSE) { unset($params['itemId']); } gallery_debug($params, t('Block parameters')); // Get the image(s) from G2 list($ret, $content, $head) = GalleryEmbed::getImageBlock($params); if ($ret) { gallery_error(t('Error trying to get image block.'), $ret); return array(); } // Format the block content $block = array(); if ($content) { $block['subject'] = t('Gallery'); if (isset($extra['num_cols'])) { $class = isset($extra['class']) ? $extra['class'] : 'gallery-grid-block'; $block['content'] = theme('gallery_block_grid_block', $content, $extra['num_cols'], $class); } else { $class = isset($extra['class']) ? $extra['class'] : 'g2image_centered'; $block['content'] = theme('gallery_block_image_block', $content, $class); } // Add css/js to the page if ($head) { gallery_set_head($head); } } return $block; } /** * Function _gallery_block_split_imageblock(). * (split an image block result into individual images) */ function _gallery_block_split_imageblock($html) { // From http://uk.php.net/manual/en/function.preg-split.php // Split the html from image block into <...> parts $pattern = '/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/'; $html_array = preg_split($pattern, trim($html), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $ndx = 0; $images = array(); $image_html = ''; // Iterate through this array and combine again, but on a per-image basis foreach ($html_array as $value) { $value = trim($value); $image_html .= $value; if (!strcmp($value, '
')) { // Found the opening
for the image $open_divs = 0; } elseif (!strncmp($value, ' but not the main image one (eg a frame) $open_divs++; } elseif (!strcmp($value, '
')) { // Found a
but check if it's for the main image or a subcomponent (eg frame) if ($open_divs > 0) { $open_divs--; } else { // This must be the closing div for "one-image" so move to next image $images[] = $image_html; $image_html = ''; } } } return $images; } /** * Theme function : theme_gallery_block_image_block(). */ function theme_gallery_block_image_block($content, $class = 'g2image_centered') { return '
'. $content .'
'; } /** * Theme function : theme_gallery_block_grid_block(). */ function theme_gallery_block_grid_block($content, $num_cols, $class = 'gallery-grid-block') { $images = _gallery_block_split_imageblock($content); $images = array_chunk($images, $num_cols); $rows = array(); foreach ($images as $image_row) { $row = array(); foreach ($image_row as $image) { $row[] = array('data' => $image, 'style' => 'text-align:center;'); } $rows[] = $row; } $html = '
'; $html .= theme('table', array(), $rows); $html .= '
'; return $html; }