summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkiz_09872006-04-15 12:30:26 (GMT)
committerkiz_09872006-04-15 12:30:26 (GMT)
commit55260521295eb3fe31c7d5ea553ffa68bca9bbfe (patch)
treeaad1d17492ef44abebfbeebb676ca41c6fbc2fca
parent30da76b6454c3e7961ae1d3a0b48f1cff44cf578 (diff)
Added gallery grid block.
Split gallery_block into separate .inc file. Added configuration of g2Image file types. #57894 - Fixed theme specific css file import.
-rw-r--r--INSTALL.txt2
-rwxr-xr-xdrupal_g2.css52
-rw-r--r--gallery.module105
-rw-r--r--gallery_base.inc47
-rw-r--r--gallery_block.inc149
-rw-r--r--gallery_settings.inc95
6 files changed, 352 insertions, 98 deletions
diff --git a/INSTALL.txt b/INSTALL.txt
index fe67bd7..a8e3663 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 b9ba2be..627712f 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 cc098a9..402f8b4 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 <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', '');;
-
- $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'] = '<center>' . $content . '</center>';
- }
- }
- 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'] = '<div id="gsSidebar" class="gcBorder1">' . join('', $result['sidebarBlocksHtml']) . '</div>';
- }
- }
- 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 599dd73..69f4410 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, '<div class="one-image">')) {
+ // Found the opening <div> for the image
+ $open_divs = 0;
+ } else if (!strncmp($value, '<div', 4)) {
+ // Found a <div> but not the main image one (eg a frame)
+ $open_divs++;
+ } else if (!strcmp($value, '</div>')) {
+ // Found a </div> 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 0000000..36b8326
--- /dev/null
+++ b/gallery_block.inc
@@ -0,0 +1,149 @@
+<?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', '');
+
+ $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:
+ 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'] = '<div id="gsSidebar" class="gcBorder1">' . join('', $result['sidebarBlocksHtml']) . '</div>';
+ }
+ }
+ 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 <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;
+ }
+}
+
+?> \ No newline at end of file
diff --git a/gallery_settings.inc b/gallery_settings.inc
index 0fb4e2d..2058a77 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);
@@ -266,6 +267,89 @@ function _gallery_block_settings($typeMap , $paramMap) {
}
/**
+ * 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;