diff --git a/INSTALL.txt b/INSTALL.txt index fe67bd7dad19b4c2d21a030919fc5c3672c1ce6a..a8e36636d0cb2f932564c2788abaf365cb5e1069 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -40,7 +40,7 @@ Installation Instructions if everything is OK. There is a HELP link. 7. Enable the "Gallery Block" in administer -> blocks, and optionally the "Gallery Navigation" - block. + block and the "Gallery Grid Block". Optional Steps -------------- diff --git a/drupal_g2.css b/drupal_g2.css index b9ba2beda42e86e7df6f9266314630d9ed5effe2..627712f0081d427aee587a0f6b1135196f8b6908 100755 --- a/drupal_g2.css +++ b/drupal_g2.css @@ -71,6 +71,11 @@ img.g2image_centered, div.g2image_centered { text-align: center; } +/* Neeed to centre images with frames */ +.g2image_centered table { + margin: auto; +} + .g2image_clear_images { clear: both; } @@ -101,3 +106,50 @@ margin: 4px; color: red; font-weight: bold; } + +/* Gallery Grid Block */ +.gallery-grid-block { + padding: 1px; +/* width: 500px; + display: block; + margin-left: auto; + margin-right: auto;*/ +} + +/*.gallery-grid-block .image-grid { + width: 182px; + width: 300px; +}*/ + +/*.gallery-grid-block .one-image { + float: left; + display: inline; + padding: 3px; +}*/ + +/*.gallery-grid-block .one-image { +// float: left; + width: 90px; + margin-left: auto; + margin-right: auto; + display: block; + padding: 1px; +}*/ +.gallery-grid-block .one-image { + margin: 1px; +} + +td.gallery-grid-block { + text-align:center; +} + +/* So imageframed thumbs can be centered */ +/*td.gallery-grid-block table { + margin: auto; +}*/ + +.gallery-grid-block table, +.gallery-grid-block .one-image td, +.gallery-grid-block .one-image table { + margin: auto; +} diff --git a/gallery.module b/gallery.module index cc098a9d9f036f2b5a236d893e1f59cc1e87ac6c..402f8b4879a108c3100d877d555071c6ecc294d5 100644 --- a/gallery.module +++ b/gallery.module @@ -13,16 +13,19 @@ function gallery_menu($may_cache) { $items = array(); $view_access = (user_access('access user profiles') || ($user->uid == arg(1))); if ($may_cache) { - $items[] = array('path' => 'gallery', - 'title' => t('gallery'), - 'callback' => 'gallery_page', - 'access' => user_access('access content'), - 'type' => MENU_NORMAL_ITEM); + $items[] = array( + 'path' => 'gallery', + 'title' => t('gallery'), + 'callback' => 'gallery_page', + 'access' => user_access('access content'), + 'type' => MENU_NORMAL_ITEM, + ); $items[] = array( 'path' => 'admin/user/gallery', 'title' => t('gallery'), 'callback' => 'gallery_users', 'access' => user_access('administer users'), - 'type' => MENU_LOCAL_TASK); + 'type' => MENU_LOCAL_TASK, + ); } else { // Add head info here so that it is included once only per page (almost) gallery_set_html_head(gallery_css_include()); @@ -176,95 +179,11 @@ function gallery_g2image_textarea($element) { /** * Implementation of hook_block * - * - gallery navigation block (recommended) - * - gallery imageblock (random, most viewed, etc) */ function gallery_block($op = 'list', $delta = 0, $edit = array()) { -// Modified typeMap to use current Gallery2 naming - $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'); - return $blocks; - - case 'view': - list ($success, $ret) = _gallery_init(true); - if (!$success) { - $err_msg = t('Unable to initialize embedded Gallery. You need to - configure your embedded Gallery.', - 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', '');; - - $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' - // Also fixes typo in v1.9 -- block => blocks - 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'] = '
' . $content . '
'; - } - } - if ($head) { - gallery_set_html_head($head); - } - break; - // 1 = Navigation Block - case 1: - if (arg(0) == 'gallery') { - GalleryCapabilities::set('showSidebarBlocks', false); - $result = GalleryEmbed::handleRequest(); - if (isset($result['sidebarBlocksHtml']) && !empty($result['sidebarBlocksHtml'])) { - $block['subject'] = t('Gallery Navigation'); - $block['content'] = '
' . join('', $result['sidebarBlocksHtml']) . '
'; - } - } - break; - } - $ret = GalleryEmbed::done(); - if ($ret) { - gallery_error(t('Unable to complete Gallery request'), $ret); - return; - } - return $block; - } + $path = drupal_get_path('module', 'gallery'); + require_once($path . '/gallery_block.inc'); + return _gallery_block($op, $delta, $edit); } /** diff --git a/gallery_base.inc b/gallery_base.inc index 599dd739417d67a5e4615b9e0778780e14c085d0..69f441016ef321cd75e15ba8d051cf240e790250 100644 --- a/gallery_base.inc +++ b/gallery_base.inc @@ -109,9 +109,9 @@ function gallery_css_include($css_file = 'drupal_g2.css') { } $output = theme('stylesheet_import', base_path() . drupal_get_path('module', 'gallery') . '/' . $css_file,'screen') ."\n"; - $themecss = base_path() . path_to_theme() .'/' . $css_file; + $themecss = path_to_theme() .'/' . $css_file; if (file_exists($themecss)) { - $output .= theme('stylesheet_import', $themecss,'screen') . "\n"; + $output .= theme('stylesheet_import', base_path() . $themecss,'screen') . "\n"; } return $output; } @@ -136,7 +136,7 @@ function gallery_set_html_head($info, $unique=true) { /** * Get the language for the user. If unknown, make a best guess. */ - function gallery_get_language($user) { +function gallery_get_language($user) { // Added depdev patch for language support (http://drupal.org/node/32374) // without i18 part (I seem to remember a Rewrite issue with it // Added test for no user language defined @@ -151,6 +151,47 @@ function gallery_set_html_head($info, $unique=true) { } } +/** + * Split an image block result into individual images + * (Kludge until imageblock has this option) + */ +function _gallery_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 = ''; + // Now 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; + } else if (!strncmp($value, ' but not the main image one (eg a frame) + $open_divs++; + } else if (!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; +} + + /* * -------------------------------------------------------------------------- * Error Functions diff --git a/gallery_block.inc b/gallery_block.inc new file mode 100644 index 0000000000000000000000000000000000000000..36b83267f64d3782428897f8784a52ac9169913a --- /dev/null +++ b/gallery_block.inc @@ -0,0 +1,149 @@ + 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 + configure your embedded Gallery.', + 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', ''); + + $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'] = '
' . $content . '
'; + } + } + if ($head) { + gallery_set_html_head($head); + } + break; + // 1 = Navigation Block + case 1: + if (arg(0) == 'gallery') { + GalleryCapabilities::set('showSidebarBlocks', false); + $result = GalleryEmbed::handleRequest(); + if (isset($result['sidebarBlocksHtml']) && !empty($result['sidebarBlocksHtml'])) { + $block['subject'] = t('Gallery Navigation'); + $block['content'] = '
' . join('', $result['sidebarBlocksHtml']) . '
'; + } + } + break; + // 2 = Image Grid Block + case 2: + $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', ''); + + $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 + $images = _gallery_split_imageblock($content); + $new_html = ''; + $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; + } +} + +?> \ No newline at end of file diff --git a/gallery_settings.inc b/gallery_settings.inc index 0fb4e2d8abe81b7e1f0e73784edad98bab089457..2058a77c737ae77f06a5dc581f5c68494abb1a8e 100644 --- a/gallery_settings.inc +++ b/gallery_settings.inc @@ -147,6 +147,7 @@ function _gallery_settings() { ); $form['block'] = _gallery_block_settings($typeMap , $paramMap); + $form['grid'] = _gallery_grid_block_settings($typeMap , $paramMap); $form['filter'] = _gallery_filter_settings($typeMap , $paramMap); $form['g2image'] = _gallery_g2image_settings(); $form['search'] = _gallery_search_settings($typeMap , $paramMap); @@ -265,6 +266,89 @@ function _gallery_block_settings($typeMap , $paramMap) { return $form['block']; } +/** + * Settings for gallery grid block + * + */ +function _gallery_grid_block_settings($typeMap , $paramMap) { + $form['grid'] = array( + '#type' => 'fieldset', + '#title' => t('Gallery Grid Image Block settings'), + '#description' => '', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + + $form['grid']['gallery_grid_num_cols'] = array( + '#type' => 'select', + '#title' => t('Number of columns'), + '#default_value' => variable_get('gallery_grid_num_cols', 2), + '#options' => array(1=>1, 2=>2, 3=>3, 4=>4, 5=>5), + '#description' => t('Enter the number of columns in the grid.'), + ); + + $form['grid']['gallery_grid_num_rows'] = array( + '#type' => 'select', + '#title' => t('Number of rows'), + '#default_value' => variable_get('gallery_grid_num_rows', 2), + '#options' => array(1=>1, 2=>2, 3=>3, 4=>4, 5=>5), + '#description' => t('Enter the number of rows in the grid.'), + ); + + $form['grid']['gallery_grid_block_block'] = array( + '#type' => 'select', + '#title' => 'Image types', + '#default_value' => variable_get('gallery_grid_block_block', 'randomImage'), + '#options' => $typeMap, + '#description' => 'Pick the type of images you\'d like to see in the grid.', + ); + + $form['grid']['gallery_grid_block_show'] = array( + '#type' => 'checkboxes', + '#title' => t('Image data'), + '#default_value' => variable_get('gallery_grid_block_show', array()), + '#options' => $paramMap, + '#description' => t('Choose the item metadata you\'d like to display.'), + ); + + $form['grid']['gallery_grid_maxsize'] = array( + '#type' => 'textfield', + '#title' => t('Thumbnail size'), + '#default_value' => variable_get('gallery_grid_maxsize', 90), + '#size' => 10, + '#maxlength' => 10, + '#description' => t('If you want your size to be bigger than the thumbnail size for that image as defined in your Gallery2, you must select "Full Size" above (but note that the full image will be returned and then resized by the browser, so it may take a while to download).'), + ); + + $form['grid']['gallery_grid_album_frame'] = array( + '#type' => 'textfield', + '#title' => t('Album frame'), + '#default_value' => variable_get('gallery_grid_album_frame', 'none'), + '#size' => 20, + '#maxlength' => 20, + '#description' => t('Enter a frame name like notebook, polaroid, shadow, slide, wood, etc. See your Gallery2 install for a complete list. Use "none" or blank for no frame.'), + ); + + $form['grid']['gallery_grid_item_frame'] = array( + '#type' => 'textfield', + '#title' => t('Item frame'), + '#default_value' => variable_get('gallery_grid_item_frame', 'none'), + '#size' => 20, + '#maxlength' => 20, + '#description' => t('Enter a frame name like notebook, polaroid, shadow, slide, wood, etc. See your Gallery2 install for a complete list. Use "none" or blank for no frame.'), + ); + + $form['grid']['gallery_grid_link_target'] = array( + '#type' => 'textfield', + '#title' => t('Link target'), + '#default_value' => variable_get('gallery_grid_link_target', ''), + '#size' => 20, + '#maxlength' => 20, + '#description' => t('Enter a link target (eg "_blank", "_new").'), + ); + return $form; +} + /** * Settings for gallery filter * @@ -504,6 +588,15 @@ function _gallery_g2image_settings() { '#description' => $description ); + $form['g2image']['gallery_g2image_regex'] = array( + '#type' => 'textfield', + '#title' => t('Image Types Regular Expression'), + '#default_value' => variable_get('gallery_g2image_regex', '@(jpg|jpeg|png|gif|bmp|svg|mov|mpg|mpeg)$@i'), + '#size' => 50, + '#maxlength' => 50, + '#description' => t('Images with these file extensions will be displayed in g2image'), + ); + $form['g2image']['gallery_g2image_sortby'] = array( '#type' => 'select', '#title' => t('Default Sort Order'), @@ -923,7 +1016,7 @@ function _gallery_g2image_settings_form_validate(&$form_values) { $content .= '// A copy of the license is in the root folder of this plugin.' . $cr; $content .= $cr . '// Automatically generated by gallery.module (admin/settings/gallery).' . $cr; $content .= '// DO NOT EDIT' . $cr; - $content .= '$g2ic_image_ext_regex = \'@(jpg|jpeg|png|gif|bmp|svg)$@i\';' . $cr; + $content .= '$g2ic_image_ext_regex = \'' . $form_values['gallery_g2image_regex'] . '\';' . $cr; $content .= '$g2ic_gallery2_path = \'' . $g2ic_gallery2_path . '\';' . $cr; $content .= '$g2ic_embedded_mode = TRUE;' . $cr; $content .= '$g2ic_use_full_path = ' . $g2ic_use_full_path. ';' . $cr;