Commit 8523c605 authored by kiz_0987's avatar kiz_0987

feature: Added tpl functions for gallery image blocks (#221456)

parent af0b6836
<?php
// $Id$
/**
* @file gallery-block-grid-block.tpl.php
* Default theme implementation to display a Gallery grid block.
*
* Available variables:
* - $class: The CSS class for the block.
* - $images: An array of image HTML organized as rows and columns.
* - $content: The unprocessed image HTML from Gallery2.
* - $num_cols: The number of columns.
*
* @see template_preprocess_gallery_block_grid_block()
*/
?>
<div class="<?php print $class; ?>">
<div class="image-grid">
<table>
<tbody>
<?php foreach ($images as $image_row): ?>
<tr class="<?php print $image_row['zebra']; ?>">
<?php foreach ($image_row['data'] as $image): ?>
<td style="text-align:center;">
<?php print $image; ?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
\ No newline at end of file
<?php
// $Id$
/**
* @file gallery-block-image-block.tpl.php
* Default theme implementation to display a Gallery image block.
*
* Available variables:
* - $class: The CSS class for the block.
* - $content: The image HTML from Gallery2.
*
* @see template_preprocess_gallery_block_image_block()
*/
?>
<div class="<?php print $class; ?>">
<?php print $content; ?>
</div>
\ No newline at end of file
......@@ -44,10 +44,14 @@ function gallery_theme() {
'arguments' => array('report' => FALSE),
),
'gallery_block_image_block' => array(
'template' => 'gallery-block-image-block',
'file' => 'gallery_block.inc',
'arguments' => array('content' => NULL, 'class' => NULL),
),
'gallery_block_grid_block' => array(
'arguments' => array('images' => NULL, 'num_cols' => NULL, 'class' => NULL),
'template' => 'gallery-block-grid-block',
'file' => 'gallery_block.inc',
'arguments' => array('content' => NULL, 'num_cols' => NULL, 'class' => NULL, 'images' => NULL),
),
'gallery_search_item' => array(
'arguments' => array('item' => NULL),
......
......@@ -237,10 +237,18 @@ function _gallery_block_split_imageblock($html) {
$images = array();
$image_html = '';
$ndx = $open_divs = 0;
// Iterate through this array and combine again, but on a per-image basis
$found_image_block_class = false;
// 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="block-imageblock-ImageBlock">')) {
// Found the opening <div> for the image block (G2.3).
// We want to remove this.
$found_image_block_class = true;
} else {
$image_html .= $value;
}
if (!strcmp($value, '<div class="one-image">')) {
// Found the opening <div> for the image
$open_divs = 0;
......@@ -261,36 +269,44 @@ function _gallery_block_split_imageblock($html) {
}
}
}
// If using G2.3 there is a final <div> from <div class="block-imageblock-ImageBlock">
// that must be removed.
if ($found_image_block_class) {
unset($images[count($images)-1]);
}
return $images;
}
/**
* Theme function : theme_gallery_block_image_block().
* Template function : template_preprocess_gallery_block_image_block().
*/
function theme_gallery_block_image_block($content, $class = 'g2image_centered') {
return '<div class="'. $class .'">'. $content .'</div>';
}
function template_preprocess_gallery_block_image_block(&$variables) {
$variables['class'] = check_plain($variables['class']);
$variables['content'] = filter_xss_admin($variables['content']);
}
/**
* Theme function : theme_gallery_block_grid_block().
* Template function : template_preprocess_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();
function template_preprocess_gallery_block_grid_block(&$variables) {
$images = _gallery_block_split_imageblock($variables['content']);
$images = array_chunk($images, $variables['num_cols']);
// Filter the images
array_walk($images, 'filter_xss_admin');
// Leave the whole content in in case themes want to do more formatting,
// but filter it for security.
$variables['content'] = filter_xss_admin($variables['content']);
$variables['images'] = array();
$row = 0;
foreach ($images as $image_row) {
$row = array();
foreach ($image_row as $image) {
$row[] = array('data' => $image, 'style' => 'text-align:center;');
}
$rows[] = $row;
$variables['images'][] = array(
'data' => $image_row,
'zebra' => $row % 2 == 0 ? 'odd' : 'even',
);
$row++;
}
$html = '<div class="'. $class .'"><div class="image-grid">';
$html .= theme('table', array(), $rows);
$html .= '</div></div>';
return $html;
}
$variables['class'] = check_plain($variables['class']);
$variables['num_cols'] = check_plain($variables['num_cols']);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment