Commit db3be4f4 authored by frjo's avatar frjo
Browse files

Issue #1931114 by hass, frjo: URLs not inserted with relative paths. Updated...

Issue #1931114 by hass, frjo: URLs not inserted with relative paths. Updated to the insert module integration.
parent 6614297d
......@@ -6,9 +6,12 @@
*
* Available variables:
* - $item: The complete item being inserted.
* - $image_path: The URL to the image.
* - $link_path: The URL to the image that Colorbox should open.
* - $url: The URL to the image.
* - $path: The URL to the image that Colorbox should open.
* - $class: A set of classes assigned to this image (if any).
* - $width: The width of the image (if known).
* - $height: The height of the image (if known).
* - $style_name: The Image style being used.
* - $gallery_id: The ID of the Colorbox gallery.
*
* Note that ALT and Title fields should not be filled in here, instead they
......@@ -19,6 +22,9 @@
* - __alt__: The ALT text, intended for use in the <img> tag.
* - __title__: The Title text, intended for use in the <img> tag.
* - __description__: A description of the image, sometimes used as a caption.
* - __filename__: The file name.
* - __[token]_or_filename__: Any of the above tokens if available, otherwise
* use the file's name. i.e. __title_or_filename__.
*/
?>
<a href="<?php print $link_path; ?>" title="__title__" class="colorbox colorbox-insert-image" rel="<?php print $gallery_id; ?>"><img typeof="foaf:Image" src="<?php print $image_path; ?>" alt="__alt__" title="__title__" class="<?php print $class; ?>" /></a>
\ No newline at end of file
<a href="<?php print $path; ?>" title="__title__" class="colorbox colorbox-insert-image" rel="<?php print $gallery_id; ?>"><img src="<?php print $url; ?>" <?php if ($width && $height): ?>width="<?php print $width; ?>" height="<?php print $height; ?>" <?php endif; ?>alt="__alt__" title="__title__" class="<?php print $class; ?>" /></a>
......@@ -32,6 +32,7 @@ function colorbox_theme() {
'widget' => NULL,
),
'template' => 'colorbox-insert-image',
'pattern' => 'colorbox_insert_image__[a-z0-9_]+',
'file' => 'colorbox.theme.inc',
),
......@@ -489,7 +490,7 @@ function colorbox_insert_styles() {
*/
function colorbox_insert_content($item, $style, $widget) {
list($item['module_name'], $item['style_name']) = explode('__', $style['name'], 2);
return theme('colorbox_insert_image', array('item' => $item, 'widget' => $widget));
return theme(array('colorbox_insert_image__' . str_replace('-', '_', $item['style_name']), 'colorbox_insert_image'), array('item' => $item, 'widget' => $widget));
}
/**
......
......@@ -151,29 +151,43 @@ function theme_colorbox_imagefield($variables) {
* Preprocess variables for the colorbox-insert-image.tpl.php file.
*/
function template_preprocess_colorbox_insert_image(&$variables) {
$class = array();
$file = file_load($variables['item']['fid']);
$variables['file'] = file_load($variables['item']['fid']);
$variables['style_name'] = $variables['item']['style_name'];
$variables['width'] = $variables['item']['width'];
$variables['height'] = $variables['item']['height'];
// Determine dimensions of the image after the image style transformations.
image_style_transform_dimensions($variables['style_name'], $variables);
$class = array();
if (!empty($variables['widget']['settings']['insert_class'])) {
$class = explode(' ', $variables['widget']['settings']['insert_class']);
}
$class[] = 'image-' . $variables['item']['style_name'];
$class[] = 'image-' . $variables['style_name'];
foreach ($class as $key => $value) {
$class[$key] = drupal_html_class($value);
}
$variables['image_path'] = image_style_url($variables['item']['style_name'], $file->uri);
$variables['class'] = implode(' ', $class);
$variables['uri'] = image_style_path($variables['style_name'], $variables['file']->uri);
$absolute = isset($variables['widget']['settings']['insert_absolute']) ? $variables['widget']['settings']['insert_absolute'] : NULL;
$variables['url'] = insert_create_url($variables['uri'], $absolute, variable_get('clean_url'));
// http://drupal.org/node/1923336
if (function_exists('image_style_path_token')) {
$token_query = array(IMAGE_DERIVATIVE_TOKEN => image_style_path_token($variables['style_name'], $variables['file']->uri));
$variables['url'] .= (strpos($variables['url'], '?') !== FALSE ? '&' : '?') . drupal_http_build_query($token_query);
}
if ($style_name = variable_get('colorbox_image_style', '')) {
$variables['link_path'] = image_style_url($style_name, $file->uri);
$variables['path'] = image_style_url($style_name, $variables['file']->uri);
}
else {
$variables['link_path'] = file_create_url($file->uri);
$variables['path'] = file_create_url($variables['file']->uri);
}
$variables['class'] = implode(' ', $class);
$variables['gallery_id'] = '';
switch (variable_get('colorbox_insert_gallery', 0)) {
case 0:
......
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