function _collageformatter_render_box in Collage Formatter 7
Recursive function to render the box.
1 call to _collageformatter_render_box()
- collageformatter_render_collage in ./
collageformatter.module - Returns renderable array of collages.
File
- ./
collageformatter.module, line 721 - Main file for Collage Formatter module.
Code
function _collageformatter_render_box($box, $settings) {
$output = '';
// Check if parent dimensions changed - and change yourself.
if (array_key_exists('parent_box_orientation', $box)) {
if ($box['parent_box_orientation'] == 'vertical') {
$box['total_width'] = $box['parent_total_width'];
}
elseif ($box['parent_box_orientation'] == 'horizontal') {
$box['total_height'] = $box['parent_total_height'];
}
}
// Perform pixel check.
if ($box['pixel_check']) {
if ($box['parent_box_orientation'] == 'vertical') {
$pixels = round($box['parent_total_height'] - 0.5) - round($box['total_height'] - 0.5) - round($box['siblings_total_height'] - 0.5);
if ($pixels) {
$box['total_height'] += $pixels;
}
}
elseif ($box['parent_box_orientation'] == 'horizontal') {
$pixels = round($box['parent_total_width'] - 0.5) - round($box['total_width'] - 0.5) - round($box['siblings_total_width'] - 0.5);
if ($pixels) {
$box['total_width'] += $pixels;
}
}
}
// Ensure that children have correct parent dimensions.
if ($box['box_type'] == 'box') {
$box[1]['parent_total_height'] = $box[2]['parent_total_height'] = $box['total_height'];
$box[1]['parent_total_width'] = $box[2]['parent_total_width'] = $box['total_width'];
}
if ($box['box_type'] == 'box') {
$box_style = array(
'float: left;',
'max-width: ' . round($box['total_width'] - 0.5) . 'px;',
);
$box_style[] = 'width: ' . 100 * (round($box['total_width'] - 0.5) / round($box['parent_total_width'] - 0.5)) . '%;';
$content[] = _collageformatter_render_box($box[1], $settings);
$content[] = _collageformatter_render_box($box[2], $settings);
$output = array(
'#theme' => 'collageformatter_collage_box',
'#box' => $content,
'#box_style' => implode(' ', $box_style),
);
}
elseif ($box['box_type'] == 'image') {
$image_uri = _collageformatter_image_file_check($box, $settings);
$image_style = array(
'display: block;',
'max-width: 100%;',
'height: auto;',
'margin: 0;',
);
// TODO: use theme('image_formatter', ... ?
$image = theme('image_style', array(
'style_name' => 'collageformatter',
'path' => $image_uri,
'alt' => $box['alt'],
'title' => $box['title'],
'attributes' => array(
'style' => implode(' ', $image_style),
),
));
// Create image derivatives.
if ($settings['generate_image_derivatives']) {
$derivative_uri = image_style_path('collageformatter', $image_uri);
if (!file_exists($derivative_uri)) {
$image_style = image_style_load('collageformatter');
if (!image_style_create_derivative($image_style, $image_uri, $derivative_uri)) {
watchdog('collageformatter', 'Unable to generate the derived image located at %path.', array(
'%path' => $derivative_uri,
));
}
}
}
$attached = array();
// Process image linking and modal gallery settings.
if ($settings['image_link'] == 'content') {
$class = $settings['image_link_class'] ? array(
$settings['image_link_class'],
) : array();
$rel = $settings['image_link_rel'];
$image = l($image, $box['content_uri'], array(
'attributes' => array(
'title' => $box['title'],
'class' => $class,
'rel' => $rel,
),
'html' => TRUE,
));
}
elseif ($settings['image_link'] == 'file') {
$image_dimensions = array(
'width' => $box['width'],
'height' => $box['height'],
);
if (empty($settings['image_link_image_style'])) {
$image_url = file_create_url($box['uri']);
}
else {
$image_url = image_style_url($settings['image_link_image_style'], $box['uri']);
image_style_transform_dimensions($settings['image_link_image_style'], $image_dimensions);
}
$class = $settings['image_link_class'] ? array(
$settings['image_link_class'],
) : array();
$rel = $settings['image_link_rel'];
$attributes = array();
switch ($settings['image_link_modal']) {
case 'colorbox':
$class[] = 'colorbox';
$rel = 'colorbox-' . $settings['gallery'];
break;
case 'shadowbox':
$rel = 'shadowbox[' . $settings['gallery'] . ']';
break;
case 'fancybox':
$class[] = 'fancybox';
$attributes['data-fancybox-group'] = 'fancybox-' . $settings['gallery'];
break;
case 'photobox':
$class[] = 'photobox';
$attached = photobox_attached_resources();
$attributes['data-photobox-gallery'] = 'photobox-' . $settings['gallery'];
break;
case 'photoswipe':
$class[] = 'photoswipe';
photoswipe_load_assets();
$attributes['data-size'] = $image_dimensions['width'] . 'x' . $image_dimensions['height'];
break;
case 'lightbox2':
$rel = 'lightbox[' . $settings['gallery'] . ']';
break;
default:
}
$image = l($image, $image_url, array(
'attributes' => array(
'title' => $box['title'],
'class' => $class,
'rel' => $rel,
) + $attributes,
'html' => TRUE,
));
}
$image_wrapper_style = array(
'float: left;',
'max-width: ' . round($box['total_width'] - $settings['gap_size'] - 0.5) . 'px;',
'width: ' . 100 * (round($box['total_width'] - $settings['gap_size'] - 0.5) / round($box['parent_total_width'] - 0.5)) . '%;',
);
if ($settings['gap_size']) {
$margin_percentage = 100 * ($settings['gap_size'] / round($box['parent_total_width'] - 0.5));
$image_wrapper_style[] = 'margin: ' . $margin_percentage . '% 0 0 ' . $margin_percentage . '%;';
}
$border = '';
if ($settings['border_size']) {
$border = 'border: ' . $settings['border_size'] . 'px solid';
if ($settings['border_color']) {
$border .= ' ' . $settings['border_color'];
}
$border .= ';';
}
$output = array(
'#theme' => 'collageformatter_collage_image',
'#image' => $image,
'#image_wrapper_class' => array(
'collageformatter-collage-image-wrapper-' . $box['delta'],
),
'#image_wrapper_style' => implode(' ', $image_wrapper_style),
'#image_style' => $border,
'#attached' => $attached,
);
}
return $output;
}