View source
<?php
defined('REQUEST_TIME') or define('REQUEST_TIME', $_SERVER['REQUEST_TIME']);
function imagefield_crop_init() {
module_load_include('inc', 'imagefield_crop', 'imagefield_crop_file');
module_load_include('inc', 'imagefield_crop', 'imagefield_crop_widget');
}
function imagefield_crop_widget_info() {
$module_path = drupal_get_path('module', 'imagefield_crop');
return array(
'imagefield_crop_widget' => array(
'label' => t('Image with cropping'),
'field types' => array(
'image',
'filefield',
),
'multiple values' => CONTENT_HANDLE_CORE,
'callbacks' => array(
'default value' => CONTENT_CALLBACK_CUSTOM,
),
'suitability callback' => 'imagefield_handles_file',
'description' => t('An edit widget for image files, including a crop interface.'),
),
);
}
function imagefield_crop_widget_settings($op, $widget) {
module_load_include('inc', 'imagefield_crop', 'imagefield_crop_widget');
switch ($op) {
case 'form':
return imagefield_crop_widget_settings_form($widget);
case 'validate':
return imagefield_crop_widget_settings_validate($widget);
case 'save':
return imagefield_crop_widget_settings_save($widget);
}
}
function imagefield_crop_widget(&$form, &$form_state, $field, $items, $delta = 0) {
$element = imagefield_widget($form, $form_state, $field, $items, $delta);
return $element;
}
function imagefield_crop_elements() {
$elements = array();
$elements['imagefield_crop_widget'] = array(
'#input' => TRUE,
'#process' => array(
'filefield_widget_process',
'imagefield_widget_process',
'imagefield_crop_widget_process',
),
'#value_callback' => 'imagefield_crop_widget_value',
'#element_validate' => array(
'filefield_widget_validate',
'imagefield_widget_validate',
'imagefield_crop_widget_validate',
),
'#description' => t('Changes made to the attachments are not permanent until you save this post.'),
);
return $elements;
}
function imagefield_crop_theme() {
$theme = array(
'imagefield_crop_widget' => array(
'arguments' => array(
'element' => NULL,
),
'file' => 'imagefield_crop_widget.inc',
),
'imagefield_crop_dynamic_preview' => array(
'arguments' => array(
'file' => NULL,
'resolution' => 0,
'preview_width' => 0,
),
),
'imagefield_crop_widget_preview' => array(
'arguments' => array(
'item' => NULL,
),
),
'imagefield_crop_cropbox' => array(
'arguments' => array(
'file' => NULL,
'alt' => '',
'title' => '',
'attributes' => NULL,
'getsize' => TRUE,
'id' => NULL,
),
),
'imagefield_crop_edit_crop_image_row' => array(
'arguments' => array(
'element' => NULL,
),
),
'imagefield_crop_formatter_image_uncrop_plain' => array(
'arguments' => array(
'element' => NULL,
),
'file' => 'imagefield_crop_formatter.inc',
),
'imagefield_crop_formatter_image_uncroplink' => array(
'arguments' => array(
'element' => NULL,
),
'file' => 'imagefield_crop_formatter.inc',
),
);
if (function_exists('imagecache_presets')) {
foreach (imagecache_presets() as $preset) {
$theme['imagefield_crop_formatter_' . $preset['presetname'] . '_default_uncropped'] = array(
'arguments' => array(
'element' => NULL,
'function' => 'theme_imagecache_formatter_default',
),
'function' => 'theme_imagefield_crop_formatter_uncropped',
);
$theme['imagefield_crop_formatter_' . $preset['presetname'] . '_linked_uncropped'] = array(
'arguments' => array(
'element' => NULL,
'function' => 'theme_imagecache_formatter_linked',
),
'function' => 'theme_imagefield_crop_formatter_uncropped',
);
$theme['imagefield_crop_formatter_' . $preset['presetname'] . '_imagelink_uncropped'] = array(
'arguments' => array(
'element' => NULL,
'function' => 'theme_imagecache_formatter_imagelink',
),
'function' => 'theme_imagefield_crop_formatter_uncropped',
);
$theme['imagefield_crop_formatter_' . $preset['presetname'] . '_path_uncropped'] = array(
'arguments' => array(
'element' => NULL,
'function' => 'theme_imagecache_formatter_path',
),
'function' => 'theme_imagefield_crop_formatter_uncropped',
);
$theme['imagefield_crop_formatter_' . $preset['presetname'] . '_url_uncropped'] = array(
'arguments' => array(
'element' => NULL,
'function' => 'theme_imagecache_formatter_url',
),
'function' => 'theme_imagefield_crop_formatter_uncropped',
);
}
}
return $theme;
}
function imagefield_crop_field_formatter_info() {
$formatters = array();
$formatters = array(
'image_uncrop_plain' => array(
'label' => t('Image uncropped'),
'field types' => array(
'filefield',
),
'description' => t('Displays image files uncropped (only for imagefield_crop files).'),
),
'image_uncroplink' => array(
'label' => t('Image linked to image uncropped'),
'field types' => array(
'filefield',
),
'description' => t('Links to image files uncropped (only for imagefield_crop files).'),
),
);
if (function_exists('imagecache_presets')) {
foreach (imagecache_presets() as $preset) {
$formatters[$preset['presetname'] . '_default_uncropped'] = array(
'label' => t('@preset image (uncropped)', array(
'@preset' => $preset['presetname'],
)),
'field types' => array(
'filefield',
),
);
$formatters[$preset['presetname'] . '_linked_uncropped'] = array(
'label' => t('@preset image linked to node (uncropped)', array(
'@preset' => $preset['presetname'],
)),
'field types' => array(
'filefield',
),
);
$formatters[$preset['presetname'] . '_imagelink_uncropped'] = array(
'label' => t('@preset image linked to image (uncropped)', array(
'@preset' => $preset['presetname'],
)),
'field types' => array(
'filefield',
),
);
$formatters[$preset['presetname'] . '_path_uncropped'] = array(
'label' => t('@preset file path (uncropped)', array(
'@preset' => $preset['presetname'],
)),
'field types' => array(
'filefield',
),
);
$formatters[$preset['presetname'] . '_url_uncropped'] = array(
'label' => t('@preset URL (uncropped)', array(
'@preset' => $preset['presetname'],
)),
'field types' => array(
'filefield',
),
);
}
}
return $formatters;
}
function theme_imagefield_crop_widget_preview($item = NULL) {
if (is_null($item) || empty($item['filepath'])) {
return '<!-- link to default admin thumb -->';
}
$thumb_path = imagefield_file_admin_thumb_path($item);
$query_string = '?' . variable_get('imagefield_crop_query_string', REQUEST_TIME);
return '<img src="' . file_create_url($thumb_path) . $query_string . '" />';
}
function theme_imagefield_crop_formatter_uncropped($element, $function = '') {
if ($function || ($function = _imagefield_crop_formatter_theme_function($element['#formatter']))) {
$element['#item']['filepath'] = imagefield_crop_file_admin_crop_display_path($element['#item']);
$element['#formatter'] = substr($element['#formatter'], 0, -10);
$element['#theme'] = $function ? $function : 'theme_imagecache_' . $element['#formatter'];
return $function($element);
}
}
function _imagefield_crop_formatter_theme_function($formatter) {
if (strpos($formatter, '_default_uncropped')) {
return 'theme_imagecache_formatter_default';
}
if (strpos($formatter, '_linked_uncropped')) {
return 'theme_imagecache_formatter_linked';
}
if (strpos($formatter, '_imagelink_uncropped')) {
return 'theme_imagecache_formatter_imagelink';
}
if (strpos($formatter, '_path_uncropped')) {
return 'theme_imagecache_formatter_path';
}
if (strpos($formatter, '_url_uncropped')) {
return 'theme_imagecache_formatter_url';
}
}