View source
<?php
include_once 'panopoly_images.features.inc';
function panopoly_images_init() {
drupal_add_css(drupal_get_path('module', 'panopoly_images') . '/panopoly-images.css', array(
'group' => CSS_THEME,
));
$images_loaded = libraries_load('jquery.imagesloaded');
if (empty($images_loaded['loaded'])) {
watchdog('panopoly-images', 'Panopoly Images could not find the jquery.imagesloaded library. This should get loaded by the Manual Crop module', array(), WATCHDOG_ERROR);
}
else {
drupal_add_js(drupal_get_path('module', 'panopoly_images') . '/panopoly-images.js', array(
'type' => 'file',
'group' => JS_DEFAULT,
'every_page' => TRUE,
));
}
}
function panopoly_images_media_wysiwyg_wysiwyg_allowed_view_modes_alter(&$options, $context) {
if ($context->type == 'image') {
$labels = array(
'default' => t('Original Size'),
'teaser' => t('Quarter Size'),
'preview' => t('Thumbnail'),
);
foreach ($labels as $name => $label) {
if (isset($options[$name])) {
if (is_array($options[$name])) {
$options[$name]['label'] = $label;
}
else {
$options[$name] = $label;
}
}
}
}
}
function panopoly_images_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'ctools_entity_field_content_type_formatter_styles') {
if (!empty($form['image_style']['#options'])) {
$styles_to_remove = array(
'apps_logo',
'apps_logo_small',
'apps_screenshot',
'apps_featured_screenshot',
'linkit_thumb',
'thumbnail',
'medium',
'large',
'media_thumbnail',
);
foreach ($styles_to_remove as $style_name) {
if (!empty($form['image_style']['#options'][$style_name])) {
unset($form['image_style']['#options'][$style_name]);
}
}
}
}
if (!empty($form['upload'])) {
$form['upload']['#size'] = 30;
}
if ($form_id == 'media_format_form') {
$form['preload'] = array(
'#prefix' => '<div style="display: none">',
'#suffix' => '</div>',
);
$image_path = $form['#media']->uri;
$image_formats = array(
'panopoly_image_full',
'panopoly_image_half',
'panopoly_image_quarter',
);
foreach ($image_formats as $format) {
$form['preload'][$format] = array(
'#markup' => theme('image', array(
'path' => image_style_url($format, $image_path),
)),
);
}
}
if ($form_id == 'media_format_form' && !empty($form['options']['format'])) {
$form['options']['format']['#default_value'] = 'default';
}
}
function panopoly_images_file_displays_alter(&$displays, &$file, &$view_mode) {
if (!empty($file->override['attributes']['width'])) {
$file->image_dimensions['width'] = $file->override['attributes']['width'];
}
if (!empty($file->override['attributes']['height'])) {
$file->image_dimensions['height'] = $file->override['attributes']['height'];
}
}
function panopoly_images_file_default_displays_alter(&$file_displays) {
$disable_displays = array(
'image__default__file_field_file_default',
'image__teaser__file_field_file_default',
'image__preview__file_field_file_default',
'image__preview__file_field_media_large_icon',
);
foreach ($disable_displays as $name) {
if (isset($file_displays[$name])) {
$file_displays[$name]->status = FALSE;
}
}
if (isset($file_displays['image__default__file_field_image'])) {
$file_displays['image__default__file_field_image']->settings['image_style'] = 'panopoly_image_original';
}
if (isset($file_displays['image__preview__file_field_image'])) {
$file_displays['image__preview__file_field_image']->settings['image_style'] = 'panopoly_image_thumbnail';
}
if (isset($file_displays['image__teaser__file_field_image'])) {
$file_displays['image__teaser__file_field_image']->settings['image_style'] = 'panopoly_image_quarter';
}
}
function panopoly_images_preprocess_image_style(&$variables) {
if (isset($variables['attributes']['class']) && !is_array($variables['attributes']['class'])) {
$variables['attributes']['class'] = explode(' ', $variables['attributes']['class']);
}
if (!empty($variables['attributes']['class'])) {
$img_style_names = array_keys(image_styles());
$classes = array();
foreach ($variables['attributes']['class'] as $class) {
if (!in_array(str_replace('-', '_', $class), $img_style_names)) {
$classes[] = $class;
}
}
$variables['attributes']['class'] = $classes;
}
$variables['attributes']['class'][] = str_replace('_', '-', $variables['style_name']);
}
function panopoly_images_preprocess_image(&$variables) {
if (!isset($variables['alt'])) {
$variables['alt'] = '';
}
}
function panopoly_images_entity_info_alter(&$entity_info) {
$entity_info['file']['view modes']['link'] = array(
'label' => t('Link'),
'custom settings' => TRUE,
);
}
function panopoly_images_field_widget_form_alter(&$element, &$form_state, $context) {
$widget = $context['instance']['widget'];
if (module_exists('focal_point') && in_array('image', array_filter(variable_get("focal_point_enabled_for", array(
'image',
))))) {
if (manualcrop_supported_widgets($widget['type']) && !empty($widget['settings']['manualcrop_enable'])) {
foreach (element_children($element) as $delta) {
foreach ($element[$delta]['#process'] as $index => $function) {
if (substr($function, 0, 11) == 'focal_point') {
unset($element[$delta]['#process'][$index]);
unset($element[$delta]['#widget_delta']);
if (($class_index = array_search('focal_point', $element[$delta]['#attributes']['class'])) !== FALSE) {
unset($element[$delta]['#attributes']['class'][$class_index]);
}
break;
}
}
}
}
}
}