View source
<?php
include_once dirname(__FILE__) . '/includes/galleryformatter_imagecache.inc';
function galleryformatter_widget_settings_alter(&$settings, $op, $widget) {
$widget_types = array(
'imagefield_widget',
'swfupload_widget',
'image_fupload_imagefield_widget',
'imagefield_crop_widget',
);
if (!empty($widget['type']) && in_array($widget['type'], $widget_types) || !empty($widget['widget_type']) && in_array($widget['widget_type'], $widget_types)) {
switch ($op) {
case 'form':
$options = array(
t('None'),
);
foreach (imagecache_presets() as $id => $preset) {
$options[$preset['presetname']] = $preset['presetname'];
}
$collapsed = $widget['slide_preset'] == '0' && $widget['thumb_preset'] == '0';
$settings['galleryformatter'] = array(
'#type' => 'fieldset',
'#title' => t('Gallery Formatter'),
'#collapsible' => TRUE,
'#collapsed' => $collapsed,
'#description' => t('Setting <strong>both</strong> values below will trigger the gallery behaviour.') . '<p>' . t("Don't forget to set the <strong>Number of values</strong> to either <em>Unlimitted</em> or the maximum number of images each gallery could accept.") . '</p>',
);
$settings['galleryformatter']['slide_preset'] = array(
'#type' => 'select',
'#title' => t('Select the slide preset'),
'#options' => $options,
'#default_value' => $widget['slide_preset'],
'#description' => t('Select the imagecache preset you would like to show when clicked on the thumbnail.'),
);
$settings['galleryformatter']['thumb_preset'] = array(
'#type' => 'select',
'#title' => t('Select the thumbnail preset'),
'#options' => $options,
'#default_value' => $widget['thumb_preset'],
'#description' => t('Select the imagecache preset you would like to show for the thumbnails list.'),
);
$style_options = array();
$styles = module_invoke_all('galleryformatter_styles');
foreach ($styles as $style) {
$style_options[$style] = $style;
}
ksort($style_options);
$settings['galleryformatter']['style'] = array(
'#type' => 'select',
'#title' => t('Style'),
'#options' => array(
'nostyle' => t('No style'),
) + $style_options,
'#default_value' => isset($widget['style']) ? $widget['style'] : 'default',
'#description' => t('Choose the gallery style.'),
);
$settings['galleryformatter']['link_to_full'] = array(
'#type' => 'checkbox',
'#title' => t('Link slides to the full image'),
'#default_value' => $widget['link_to_full'],
'#description' => t('If you check this on, the slides will be linked to the preset you choose in <em>Select the full image preset</em> below.'),
);
$options[0] = t('None (original image)');
$settings['galleryformatter']['link_to_full_preset'] = array(
'#type' => 'select',
'#title' => t('Select the full image preset'),
'#options' => $options,
'#default_value' => $widget['link_to_full_preset'],
'#description' => t('Select the imagecache preset you would like to show when clicked on the thumbnail.<br />If you select none, the the link will point to the original image.'),
);
$options = array();
if (module_exists('colorbox')) {
$options['colorbox'] = 'colorbox';
}
if (module_exists('thickbox')) {
$options['thickbox'] = 'thickbox';
}
if (module_exists('shadowbox')) {
$options['shadowbox'] = 'shadowbox';
}
if (module_exists('lightbox2')) {
$options['lightbox2'] = 'lightbox2';
}
$options['none'] = t('Do not use modal');
$settings['galleryformatter']['modal'] = array(
'#type' => 'select',
'#title' => t('Use jQuery modal for full image link'),
'#options' => $options,
'#default_value' => $widget['modal'],
'#description' => t("Select which jQuery modal module you'd like to display the full link image in, if any."),
);
break;
case 'save':
$settings[] = 'slide_preset';
$settings[] = 'thumb_preset';
$settings[] = 'style';
$settings[] = 'link_to_full';
$settings[] = 'link_to_full_preset';
$settings[] = 'modal';
break;
}
}
}
function galleryformatter_theme() {
return array(
'galleryformatter_formatter_galleryformatter_default' => array(
'arguments' => array(
'element' => NULL,
),
'template' => 'theme/galleryformatter',
'file' => 'includes/galleryformatter.theme.inc',
),
);
}
function galleryformatter_field_formatter_info() {
return array(
'galleryformatter_default' => array(
'label' => t('jQuery Gallery'),
'field types' => array(
'filefield',
),
'multiple values' => CONTENT_HANDLE_MODULE,
'description' => t('Display multi-value fields as an jQuery Image gallery.'),
),
);
}
function galleryformatter_get_field_settings($field_name, $content_type) {
$field = content_fields($field_name, $content_type);
return $field['widget'];
}
function galleryformatter_add_css($style) {
drupal_add_css(drupal_get_path('module', 'galleryformatter') . '/theme/galleryformatter.css');
if ($style != 'nostyle') {
$style_css = _galleryformatter_get_style_css($style);
drupal_add_css($style_css, 'module');
}
}
function _galleryformatter_get_style_css($style = 'nostyle') {
static $gallerystyles;
if ($style != 'nostyle') {
if (!isset($gallerystyles)) {
$gallerystyles = module_invoke_all('galleryformatter_styles');
}
foreach ($gallerystyles as $css_file => $gallerystyle) {
if ($style == $gallerystyle) {
return $css_file;
}
}
}
return 'nostyle';
}
function galleryformatter_galleryformatter_styles() {
$gallerystyles_directory = drupal_get_path('module', 'galleryformatter') . '/gallerystyles';
$files = file_scan_directory($gallerystyles_directory, '\\.css$');
$gallerystyles = array();
foreach ($files as $file) {
if (!strpos($file->name, '-rtl')) {
$gallerystyles[$file->filename] = drupal_ucfirst($file->name);
}
}
return $gallerystyles;
}
function galleryformatter_getimage_dimensions($presetname, $image_path) {
$transformed_path = imagecache_create_path($presetname, $image_path);
$preset = imagecache_preset_by_name($presetname);
foreach (galleryformatter_imagecache_default_presets() as $key => $value) {
$default_presets[] = $value['presetname'];
}
$default_preset = in_array($preset['presetname'], $default_presets);
if ($preset['storage'] == 1 && $default_preset) {
$ret['height'] = $preset['actions'][0]['data']['height'];
$ret['width'] = $preset['actions'][0]['data']['width'];
}
elseif (file_exists($transformed_path) || imagecache_build_derivative($preset['actions'], $image_path, $transformed_path)) {
$image = image_get_info($transformed_path);
$ret['height'] = $image['height'];
$ret['width'] = $image['width'];
}
return $ret;
}