Index: filefield/filefield.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/filefield/filefield.module,v
retrieving revision 1.167
diff -u -r1.167 filefield.module
--- filefield/filefield.module 10 Mar 2009 18:40:12 -0000 1.167
+++ filefield/filefield.module 10 Mar 2009 22:43:23 -0000
@@ -266,35 +266,12 @@
* Implementation of CCK's hook_widget_settings().
*/
function filefield_widget_settings($op, $widget) {
- $return = array();
- // load our widget settings callbacks..
- $op = str_replace(' ', '_', $op);
- $function = 'filefield_widget_settings_'. $op;
- if (function_exists($function)) {
- $result = $function($widget);
- if (isset($result) && is_array($result)) {
- $return = $result;
- }
- }
-
- // sometimes widget_settings is called with widget, sometimes with field.
- // CCK needs to make up it's mind here or get with the new hook formats.
- $widget_type = isset($widget['widget_type']) ? $widget['widget_type'] : $widget['type'];
- $widget_module = isset($widget['widget_module']) ? $widget['widget_module'] : $widget['module'];
-
- // dynamically load widgets file and callbacks for other fields and widgets utilizing
- // filefield's hook_widget_settings implementation.
- module_load_include('inc', $widget_module, $widget_module .'_widget');
-
- $function = $widget_type .'_widget_settings_'. $op;
- if (function_exists($function)) {
- $result = $function($widget);
- if (isset($result) && is_array($result)) {
- $return = array_merge($return, $result);
- }
+ switch ($op) {
+ case 'form':
+ return filefield_widget_settings_form($widget);
+ case 'save':
+ return filefield_widget_settings_save($widget);
}
-
- return $return;
}
/**
@@ -393,18 +370,10 @@
return array(
'default' => array(
'label' => t('Generic files'),
- 'suitability callback' => TRUE,
- 'field types' => array('filefield','image'),
+ 'field types' => array('filefield'),
'multiple values' => CONTENT_HANDLE_CORE,
'description' => t('Displays all kinds of files with an icon and a linked file description.'),
),
- 'filefield_dynamic' => array(
- 'label' => t('Dynamic file formatters'),
- 'suitability callback' => TRUE,
- 'field types' => array('file'),
- 'multiple values' => CONTENT_HANDLE_CORE,
- 'description' => t('(experimental) An extensible formatter for filefield.'),
- ),
);
}
@@ -545,35 +514,6 @@
}
/**
- * set the default values for imagefield.
- * This seems to work for all but add a new item on unlimited values which doesn't
- * get assigned a proper default.
- */
-function filefield_default_value(&$form, &$form_state, $field, $delta) {
- $items = array();
- $field_name = $field['field_name'];
-
- switch ($field['multiple']) {
- case 0:
- $max = 1;
- break;
- case 1:
- $max = isset($form_state['item_count'][$field_name]) ? $form_state['item_count'][$field_name] : 1;
- break;
- default:
- $max = $field['multiple'];
- break;
- }
-
- for ($delta = 0; $delta < $max; $delta++) {
- $items[$delta] = array('fid' => 0, 'list' => $field['list_default'], 'data' => array('description' => ''));
- }
- return $items;
-}
-
-
-
-/**
* Implementation of hook_file_references().
*/
function filefield_file_references($file) {
Index: filefield/filefield_widget.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/filefield/filefield_widget.inc,v
retrieving revision 1.58
diff -u -r1.58 filefield_widget.inc
--- filefield/filefield_widget.inc 10 Mar 2009 18:40:12 -0000 1.58
+++ filefield/filefield_widget.inc 10 Mar 2009 22:43:24 -0000
@@ -168,12 +168,6 @@
// merge file and item data so it is available to all widgets.
$item = array_merge($item, $file);
- // if this widget is another type and leaning on filefield to do the dirty work....
- // pass it back home.
- $function = $element['#type'] .'_widget_value';
- if (function_exists($function)) {
- $item = array_merge($item, $function($element, $edit));
- }
return $item;
}
Index: imagefield/imagefield_widget.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagefield/imagefield_widget.inc,v
retrieving revision 1.23
diff -u -r1.23 imagefield_widget.inc
--- imagefield/imagefield_widget.inc 10 Mar 2009 18:40:12 -0000 1.23
+++ imagefield/imagefield_widget.inc 10 Mar 2009 22:43:24 -0000
@@ -18,8 +18,9 @@
* return values are merged with and will override filefields' widget
* settings callback's return values.
*/
-function imagefield_widget_widget_settings_form($widget) {
- $form = array();
+function imagefield_widget_settings_form($widget) {
+ $form = module_invoke('filefield', 'widget_settings', 'form', $widget);
+
$form['max_resolution'] = array(
'#type' => 'textfield',
'#title' => t('Maximum resolution for Images'),
@@ -46,7 +47,7 @@
'#default_value' => !empty($widget['file_extensions']) ? $widget['file_extensions'] : 'jpg jpeg png gif',
'#size' => 64,
'#maxlength' => 64,
- '#description' => t('Extensions a user can upload to this field. Separate extensions with a space and do not include the leading dot.'),
+ '#description' => t('Extensions a user can upload to this field. Separate extensions with a space and do not include the leading dot. Only jpg, png, and gif images are supported with this widget.'),
'#weight' => 2,
);
@@ -63,7 +64,6 @@
'#default_value' => !empty($widget['custom_alt']) ? $widget['custom_alt'] : 0,
'#description' => t('Enable user input alternate text for images.'),
);
-
$form['alt_settings']['alt'] = array(
'#type' => 'textfield',
'#title' => t('Default ALT text'),
@@ -95,39 +95,52 @@
return $form;
}
-function imagefield_widget_widget_settings_save($widget) {
- //@todo: rename custom_alt and custom_title to alt_custom and title_custom to be OCD.
- return array('max_resolution', 'min_resolution', 'alt', 'custom_alt', 'title', 'custom_title');
+/**
+ * Validate callback for the CCK widget form.
+ */
+function imagefield_widget_settings_validate($widget) {
+ // Check that only web images are specified in the callback.
+ $extensions = array_filter(explode(' ', $widget['file_extensions']));
+ $web_extensions = array('jpg', 'jpeg', 'gif', 'png');
+ if (count(array_diff($extensions, $web_extensions))) {
+ form_set_error('file_extensions', t('Only web-standard images (jpg, gif, and png) are supported through the image widget. If needing to upload other types of images, change the widget to use a standard file upload.'));
+ }
}
/**
- * @} End defgroup "Filefield widget settings callbacks."
+ * Save callback for the CCK widget form.
*/
+function imagefield_widget_settings_save($widget) {
+ // TODO: Rename custom_alt and custom_title to alt_custom and title_custom.
+ $filefield_settings = module_invoke('filefield', 'widget_settings', 'save', $widget);
+ return $filefield_settings + array('max_resolution', 'min_resolution', 'alt', 'custom_alt', 'title', 'custom_title');
+}
/**
- * @defgroup "FileField widget element callbacks.
- * @{
- *
- * The call backs are called by form elements that leverage the
- * filefield_widget_value and filefield_widget_process callbacks.
- * They will be called after the filefield callbacks and their
- * return values will be merged with the filefield callback's.
+ * Element #value_callback function.
*/
-function imagefield_widget_widget_value($element, $edit = FALSE) {
- // handle additional
+function imagefield_widget_value($element, $edit = FALSE) {
+ $item = filefield_widget_value($element, $edit);
if ($edit) {
- return array(
- 'alt' => isset($edit['alt']) ? $edit['alt'] : '',
- 'title' => isset($edit['title']) ? $edit['title'] : '',
- );
+ $item['alt'] = isset($edit['alt']) ? $edit['alt'] : '';
+ $item['title'] = isset($edit['title']) ? $edit['title'] : '';
}
- return array('alt' => '', 'title' => '');
+ else {
+ $item['alt'] = '';
+ $item['title'] = '';
+ }
+ return $item;
}
-function imagefield_widget_widget_process($element, $edit, &$form_state, $form) {
+/**
+ * Element #process callback function.
+ */
+function imagefield_widget_process($element, $edit, &$form_state, $form) {
$file = $element['#value'];
$field = content_fields($element['#field_name'], $element['#type_name']);
+ $element['#theme'] = 'imagefield_widget_item';
+
$element['data']['alt'] = array(
'#title' => t('Alternate Text'),
'#type' => 'value',
@@ -150,13 +163,6 @@
return $element;
}
-function imagefield_widget_widget_validate($element) {
-}
-
-/**
- * @} End defgroup "FileField widget element callbacks."
- */
-
/**
* FormAPI theme function. Theme the output of an image field.
*/
Index: imagefield/image_field.inc
===================================================================
RCS file: imagefield/image_field.inc
diff -N imagefield/image_field.inc
--- imagefield/image_field.inc 4 Mar 2009 05:28:23 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,119 +0,0 @@
- 'fieldset',
- '#title' => t('Default image'),
- '#element_validate' => array('_imagefield_field_settings_default_validate'),
- );
- // Present a thumbnail of the current default image.
- $form['default']['use_default_image'] = array(
- '#type' => 'checkbox',
- '#title' => t('Use default image'),
- '#default_value' => $field['use_default_image'],
- '#description' => t('Check here if you want to use a image as default.'),
- );
- if (!empty($field['default_image'])) {
- $form['default']['default_image_thumbnail'] = array(
- '#type' => 'markup',
- '#value' => theme('imagefield_image', $field['default_image'], '', '', array('width' => '150'), false),
- );
- }
- $form['default']['default_image_upload'] = array(
- '#type' => 'file',
- '#title' => t('Upload image'),
- '#description' => t('Choose a image that will be used as default.'),
- );
-
- // We set this value on 'validate' so we can get cck to add it
- // as a standard field setting.
- $form['default_image'] = array(
- '#type' => 'value',
- '#value' => $field['default_image'],
- );
- return $form;
-}
-
-function imagefield_image_field_settings_save($field) {
- return array('default_image', 'use_default_image');
-}
-
-function imagefield_image_field_settings_database_columns($field) {
- return array(
- 'title' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'default' => '', 'sortable' => true),
- 'alt' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'default' => '', 'sortable' => true),
- );
-}
-
-function imagefield_image_field_settings_filters($field) {
- return array(
- 'not null' => array(
- 'operator' => array('=' => t('Has Image')),
- 'list' => 'views_handler_operator_yesno',
- 'list-type' => 'select',
- 'handler' => 'imagefield_views_handler_filter_is_not_null',
- ),
- );
-}
-
-/**
- * Element specific validation for imagefield default value.
- *
- * Validated in a separate function from imagefield_field() to get access
- * to the $form_state variable.
- */
-function _imagefield_field_settings_default_validate($element, &$form_state) {
- // Verify the destination exists
- $dst = file_directory_path() .'/imagefield_default_images';
- if (!field_file_check_directory($dst, FILE_CREATE_DIRECTORY)) {
- form_set_error('default_image', t("The default image could not be uploaded. The destination(%d) does not exist or is not writable by the webserver.", array('%d' => dirname($dst))));
- return;
- }
-
- $validators = array(
- 'file_validate_is_image' => array(),
- );
-
- // We save the upload here because we can't know the correct path until the file is saved.
- if (!$file = file_save_upload('default_image_upload', $validators, $dst)) {
- // no upload to save we hope... or file_save_upload reported an error on its own.
- return;
- }
-
- // set new value.
- $form_state['values']['default_image'] = (array)$file;
-
- // remove old image & clean up database.
- if (file_delete(file_create_path($field['default_image']['filepath']))) {
- db_query('DELETE FROM {files} WHERE fid=%d', $field['default_image']['fid']);
- }
-}
-
-/**
- * Custom filter for imagefield NOT null.
- */
-function imagefield_views_handler_filter_is_not_null($op, $filter, $filterinfo, &$query) {
- if ($op == 'handler') {
- $query->ensure_table($filterinfo['table']);
- if ($filter['value']) {
- $qs = '%s.%s > 0';
- $query->add_where($qs, $filterinfo['table'], $filterinfo['field']);
- }
- else {
- $qs = '%s.%s = 0 OR %s.%s IS null';
- $query->add_where($qs, $filterinfo['table'], $filterinfo['field'], $filterinfo['table'], $filterinfo['field']);
- }
- }
-
-}
Index: imagefield/imagefield.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagefield/imagefield.install,v
retrieving revision 1.21
diff -u -r1.21 imagefield.install
--- imagefield/imagefield.install 4 Mar 2009 05:28:24 -0000 1.21
+++ imagefield/imagefield.install 10 Mar 2009 22:43:24 -0000
@@ -25,107 +25,101 @@
}
/**
- * Data is now stored in per-field tables.
+ * Implementation of hook_update_last_removed().
*/
-function imagefield_update_1() {
- $ret = array();
-
- include_once(drupal_get_path('module', 'content') .'/content.module');
- include_once(drupal_get_path('module', 'content') .'/content_admin.inc');
-
+function imagefield_update_last_removed() {
+ return 3;
+}
- $fields = content_fields();
+/**
+ * Upgrade to CCK 2 and Drupal 6.
+ */
+function imagefield_update_6001() {
+ // This update was moved into 6004 so that it can be run again for users
+ // who were not properly updated.
+ return array();
+}
- foreach ($fields as $field) {
- switch ($field['type']) {
- case 'file':
- $columns = array(
- 'list' => array('type' => 'int', 'not null' => TRUE, 'default' => '0'),
- );
- content_alter_db_field(array(), array(), $field, $columns);
- break;
- }
- }
- db_query('DELETE FROM {cache}');
- return $ret;
+/**
+ * Migrate fields to the new structure.
+ */
+function imagefield_update_6002() {
+ // This update was moved to 6004 so that it can be run again for users
+ // who were not properly updated.
+ return array();
}
/**
- * Schema change to enable alt and title tags.
+ * Convert image field type to filefield.
*/
-function imagefield_update_2() {
+function imagefield_update_6003() {
$ret = array();
- include_once(drupal_get_path('module', 'content') .'/content.module');
- include_once(drupal_get_path('module', 'content') .'/content_admin.inc');
-
- $fields = content_fields();
-
- foreach ($fields as $field) {
- switch ($field['type']) {
- case 'image':
- $oldcolumns = array(
- 'fid' => array('type' => 'int', 'not null' => TRUE, 'default' => '0'),
- );
- $newcolumns = array(
- 'fid' => array('type' => 'int', 'not null' => TRUE, 'default' => '0'),
- 'title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => "''", 'sortable' => TRUE),
- 'alt' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => "''", 'sortable' => TRUE),
- );
- content_alter_db_field($field, $oldcolumns, $field, $newcolumns);
- break;
- }
- drupal_set_message('altered:
'. print_r($field, true) .''); + if (drupal_get_installed_schema_version('filefield', TRUE) < 6001) { + $ret['#abort'] = array('success' => FALSE, 'query' => t('FileField must be updated to Drupal 6 before ImageField can be updated.')); + return $ret; } - db_query('DELETE FROM {cache}'); + $ret[] = update_sql("UPDATE {" . content_field_tablename() . "} SET type = 'filefield', module = 'filefield', active = 1 WHERE module = 'imagefield' OR type = 'image'"); + $ret[] = update_sql("UPDATE {" . content_instance_tablename() . "} SET widget_type = 'imagefield_widget', widget_active = 1 WHERE widget_type = 'image' OR widget_type = 'imagefield_widget'"); + content_clear_type_cache(); + return $ret; } /** - * Change default formatter key from 'default' to 'imagefield_default'. + * Migrate fields to the new structure. */ -function imagefield_update_3() { +function imagefield_update_6004(&$context) { + module_load_install('content'); + module_load_include('inc', 'imagefield', 'imagefield_file'); + module_load_include('inc', 'content', 'includes/content.admin'); + module_load_include('inc', 'content', 'includes/content.crud'); + $ret = array(); - include_once(drupal_get_path('module', 'content') .'/content.module'); - include_once(drupal_get_path('module', 'content') .'/content_admin.inc'); - $result = db_query("SELECT field_name, type_name, display_settings FROM {node_field_instance} WHERE widget_type = 'image'"); - while ($row = db_fetch_array($result)) { - $needs_update = FALSE; - $display_settings = unserialize($row['display_settings']); - foreach (_content_admin_display_contexts() as $context) { - if ($display_settings[$context]['format'] == 'default') { - $display_settings[$context]['format'] = 'imagefield_default'; - $needs_update = TRUE; + + if (!isset($context['sandbox']['progress'])) { + // Get the latest cache values and schema. + content_clear_type_cache(TRUE, TRUE); + + // Grab the list of fields to update. + $context['sandbox']['fields'] = array(); + foreach (content_types_install() as $type_name => $fields) { + foreach ($fields as $field) { + if ($field['type'] == 'filefield' && $field['widget']['type'] == 'imagefield_widget') { + // We only process a given field once. + $context['sandbox']['fields'][$field['field_name']] = $field; + } } } - if ($needs_update) { - db_query("UPDATE {node_field_instance} SET display_settings = '%s' WHERE type_name = '%s' AND field_name = '%s'", serialize($display_settings), $row['type_name'], $row['field_name']); - } - } - content_clear_type_cache(); - return $ret; -} -/** - * Upgrade to CCK 2 and Drupal 6. - */ -function imagefield_update_6001() { - // Make sure CCK's been updated first. - if ($abort = content_check_update('imagefield')) { - return $abort; - } + if (empty($context['sandbox']['fields'])) { + return $ret; + } - module_load_include('inc', 'content', 'includes/content.admin'); - module_load_include('inc', 'content', 'includes/content.crud'); + // Add/update the database fields. + foreach ($context['sandbox']['fields'] as $field) { + $db_info = content_database_info($field); + + // Convert the default value for the FID field to NULL. + db_change_field($ret, $db_info['table'], $field['field_name'] . '_fid', $field['field_name'] . '_fid', array('type' => 'int')); + $ret[] = update_sql("UPDATE " . $db_info['table'] . " SET " . $field['field_name'] . "_fid = NULL WHERE " . $field['field_name'] . "_fid = 0"); + + // Add the "data" and "list" columns to the field if not there already. + if (!db_column_exists($db_info['table'], $field['field_name'] . '_list')) { + db_add_field($ret, $db_info['table'], $field['field_name'] . '_list', array('type' => 'int', 'size' => 'tiny')); + } + if (!db_column_exists($db_info['table'], $field['field_name'] . '_data')) { + db_add_field($ret, $db_info['table'], $field['field_name'] . '_data', array('type' => 'text')); + } - $ret[] = update_sql("UPDATE {". content_instance_tablename() ."} SET widget_type = 'imagefield_widget' WHERE widget_type = 'image'"); - content_associate_fields('imagefield'); + // Set the default state of the global settings. + $field['list_field'] = '0'; + $field['list_default'] = '1'; + $field['description_field'] = '0'; - foreach (content_types_install() as $type_name => $fields) { - foreach ($fields as $field) { - // Skip non imagefields. - if ($field['type'] != 'image') continue; + // Set default state of instance settings. + $field['widget']['file_path'] = $field['widget']['image_path']; // Map 'max_number_images' parameter to CCK 'multiple'. if (!empty($field['widget']['multiple']) && isset($field['widget']['max_number_images'])) { @@ -136,80 +130,34 @@ $field['multiple'] = 0; // 0 means "Not Multiple" in CCK. } else { - $field['multiple'] == $field['widget']['max_number_images']; + $field['multiple'] = $field['widget']['max_number_images']; } } - unset($field['widget']['max_number_images']); - - // Rename image_path to file_path to help convergence with filefield.module. - $field['widget']['file_path'] = $field['widget']['image_path']; // Update format names. - $display_settings = array('teaser', 'full', '4'); - foreach ($display_settings as $context) { - switch($field['display_settings'][$context]['format']) { + $display_settings = array('teaser', 'full'); + foreach ($display_settings as $display_context) { + switch ($field['display_settings'][$display_context]['format']) { case 'imagefield_nodelink': - $field['display_settings'][$context]['format'] = 'image_nodelink'; + $field['display_settings'][$display_context]['format'] = 'image_nodelink'; break; case 'imagefield_imagelink': - $field['display_settings'][$context]['format'] = 'image_imagelink'; + $field['display_settings'][$display_context]['format'] = 'image_imagelink'; break; case 'imagefield_path': - $field['display_settings'][$context]['format'] = 'path_plain'; + $field['display_settings'][$display_context]['format'] = 'path_plain'; break; case 'imagefield_url': - $field['display_settings'][$context]['format'] = 'url_plain'; + $field['display_settings'][$display_context]['format'] = 'url_plain'; break; case 'imagefield_default': - $field['display_settings'][$context]['format'] = 'image_plain'; + $field['display_settings'][$display_context]['format'] = 'image_plain'; break; } } - // Set list options inherited from file field to behave consistently with old imagefield. - $field['list_default'] = 1; - $field['force_list_default'] = 1; - content_field_instance_update($field); } - } - - content_clear_type_cache(TRUE); - - return $ret; -} - -/** - * Migrate fields to the new structure. - */ -function imagefield_update_6002(&$context) { - include_once './'. drupal_get_path('module', 'content') .'/content.install'; - include_once './'. drupal_get_path('module', 'imagefield') .'/imagefield_file.inc'; - - $ret = array(); - - if (!isset($context['sandbox']['progress'])) { - if ($abort = content_check_update('imagefield')) { - return $abort; - } - - // Get the latest cache values and schema. - content_clear_type_cache(TRUE, TRUE); - - // Grab the list of fields to update. - $context['sandbox']['fields'] = array(); - foreach (content_types_install() as $type_name => $fields) { - foreach ($fields as $field) { - if ($field['type'] == 'image') { - // We only process a given field once. - $context['sandbox']['fields'][$field['field_name']] = $field; - } - } - } - - if (empty($context['sandbox']['fields'])) { - return $ret; - } $context['sandbox']['progress'] = 0; $context['sandbox']['total'] = count($context['sandbox']['fields']); @@ -223,12 +171,14 @@ $col_alt = $field['field_name'] .'_alt'; $col_title = $field['field_name'] .'_title'; $col_data = $field['field_name'] .'_data'; + $col_list = $field['field_name'] .'_list'; $limit = 10; $result = db_query_range("SELECT * FROM {". $table ."} WHERE vid > %d ORDER BY vid ASC", $context['sandbox']['current_node'], 0, $limit); $has_processed = FALSE; - while ($row = db_fetch_array($result)) { + // Loop through each ImageField row and convert its alt and title columns. + while ($row = db_fetch_array($result)) { // Try to unserialize the data column. if (!empty($row[$col_data])) { $data = unserialize($row[$col_data]); @@ -237,12 +187,25 @@ $data = array(); } - // Copy move the values from the columns into the array... - $data['alt'] = $row[$col_alt]; - $data['title'] = $row[$col_title]; + // Copy the values into the data array. + if (isset($row[$col_alt])) { + $data['alt'] = $row[$col_alt]; + } + if (isset($row[$col_title])) { + $data['title'] = $row[$col_title]; + } + $list = isset($row[$col_list]) ? $row[$col_list] : 1; + + // Depending on if this is multivalue or not, update based on delta. + if ($field['multiple'] > 0) { + $query = "UPDATE {". $table ."} SET $col_data = '%s', $col_list = %d WHERE vid = %d AND delta = %d"; + } + else { + $query = "UPDATE {". $table ."} SET $col_data = '%s', $col_list = %d WHERE vid = %d"; + } - // ...serialize it and store it back to the db. - db_query("UPDATE {". $table ."} SET $col_data = '%s' WHERE vid = %d", serialize($data), $row['vid']); + // Serialize it and store it back to the db. + db_query($query, serialize($data), $list, $row['vid'], $row['delta']); // Create the thumbnail for that image. $file = db_fetch_object(db_query("SELECT * FROM {files} WHERE fid = %d", $row[$col_fid])); @@ -250,6 +213,12 @@ imagefield_file_insert($file); } + // Previous updates generated a thumbnail in the wrong location, delete + // these thumbnails if present. + if (file_exists($file->filepath . '.thumb.jpg')) { + unlink($file->filepath . '.thumb.jpg'); + } + // Update our progress information. $context['sandbox']['current_node'] = $row['vid']; $has_processed = TRUE; Index: imagefield/imagefield_file.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/imagefield/imagefield_file.inc,v retrieving revision 1.8 diff -u -r1.8 imagefield_file.inc --- imagefield/imagefield_file.inc 10 Mar 2009 00:14:15 -0000 1.8 +++ imagefield/imagefield_file.inc 10 Mar 2009 22:43:24 -0000 @@ -62,5 +62,8 @@ */ function imagefield_file_admin_thumb_path($file) { $file = (object)$file; - return $file->filepath .'.thumb.jpg'; + $extension_dot = strrpos($file->filepath, '.'); + $extension = substr($file->filepath, $extension_dot + 1); + $basepath = substr($file->filepath, 0, $extension_dot); + return $basepath .'.thumb.'. $extension; } Index: imagefield/imagefield.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/imagefield/imagefield.module,v retrieving revision 1.76 diff -u -r1.76 imagefield.module --- imagefield/imagefield.module 9 Mar 2009 02:47:20 -0000 1.76 +++ imagefield/imagefield.module 10 Mar 2009 22:43:24 -0000 @@ -14,6 +14,7 @@ function imagefield_init() { // field_file hooks and callbacks. module_load_include('inc', 'imagefield', 'imagefield_file'); + module_load_include('inc', 'imagefield', 'imagefield_widget'); drupal_add_css(drupal_get_path('module', 'imagefield') .'/imagefield.css'); } @@ -90,13 +91,11 @@ $elements['imagefield_widget'] = array( // Indicate to FormAPI that this element needs processing and is not simply a render element. '#input' => TRUE, - // Specify the return structure of the element (experimental, unused in releases). - '#returns' => array('array' => array('fid' => 'int', 'title' => 'string', 'alt' => 'string')), - // Delegate element processing to Filefield. - '#process' => array('filefield_widget_process', 'imagefield_widget_widget_process'), + // Delegate element processing to FileField, then call ImageField. + '#process' => array('filefield_widget_process', 'imagefield_widget_process'), // See imagefield_widget[#process] documentation. - '#value_callback' => 'filefield_widget_value', - // Delegate to Filefield... + '#value_callback' => 'imagefield_widget_value', + // Delegate element validation to FileField, then call ImageField. '#element_validate' => array('filefield_widget_validate', 'imagefield_widget_validate'), '#description' => t('Changes made to the attachments are not permanent until you save this post.'), ); @@ -119,52 +118,6 @@ } /** - * Implementation of CCK's hook_field_info(). - * - * This is the only field callback that is not delegated to FileField. - * and is required to make sure CCK sets $field['module'] to imagefield - * so filefield functions will know how to construct function names and - * which includes to load. - */ -function imagefield_field_info() { - return array( - 'image' => array( - 'label' => t('Image'), - 'description' => t('Store an image file and optionally text for alt and title tags.'), - ), - ); -} - -/** - * Implementation of CCK's hook_field_settings. - * - * Delegated to filefield_field_settings, which will include - * imagefield_field.inc and call imagefield_image_field_settings_{$op}. - * $module_$field_type_$hook_$op. - */ -function imagefield_field_settings($op, $field) { - return filefield_field_settings($op, $field); -} - -/** - * Implementation of CCK's hook_field(). - * - * @see: function imagefield_field_settings(). - */ -function imagefield_field($op, $node, $field, &$items, $teaser, $page) { - return filefield_field($op, $node, $field, $items, $teaser, $page); -} - -/** - * implementation of CCK's hook_content_is_empty - * - * Delegated to filefield.module. - */ -function imagefield_content_is_empty($item, $field) { - return filefield_content_is_empty($item, $field); -} - -/** * Implementation of CCK's hook_widget_info(). */ function imagefield_widget_info() { @@ -172,13 +125,9 @@ return array( 'imagefield_widget' => array( 'label' => t('Image'), - 'field types' => array('image', 'filefield'), + 'field types' => array('filefield'), 'multiple values' => CONTENT_HANDLE_CORE, 'callbacks' => array('default value' => CONTENT_CALLBACK_CUSTOM), - // Callback for dynamic Filefield widgets to determine - // if this widget is appropriate for a file type. - 'suitability callback' => 'imagefield_handles_file', - // Description to use on forms to describe this widget. 'description' => t('An edit widget for image files, including a preview of the image.'), ), ); @@ -186,11 +135,16 @@ /** * Implementation of CCK's hook_widget_settings(). - * - * Delegated to filefield. */ function imagefield_widget_settings($op, $widget) { - return filefield_widget_settings($op, $widget); + switch ($op) { + case 'form': + return imagefield_widget_settings_form($widget); + case 'validate': + return imagefield_widget_settings_validate($widget); + case 'save': + return imagefield_widget_settings_save($widget); + } } /** @@ -204,32 +158,27 @@ if (empty($items[$delta])) { $items[$delta] = array('alt' => '', 'title' => ''); } - $element = filefield_widget($form, $form_state, $field, $items, $delta); - $element['#upload_validators'] += imagefield_widget_upload_validators($field); + // Start with the FileField widget as a basic start. + $element = module_invoke('filefield', 'widget', $form, $form_state, $field, $items, $delta); - return $element; -} + // Ensure that only web images are supported. + $web_extensions = array('jpg', 'jpeg', 'gif', 'png'); + $extensions = array_filter(explode(' ', $element['#upload_validators']['filefield_validate_extensions'][0])); + if (empty($extensions)) { + $extensions = $web_extensions; + } + $element['#upload_validators']['filefield_validate_extensions'][0] = implode(' ', array_intersect($extensions, $web_extensions)); -/** - * Get the upload validators for an image field. - * - * @param $field - * CCK Field - * @return - * An array suitable for passing to file_save_upload() or the FileField - * element's '#upload_validators' property. - */ -function imagefield_widget_upload_validators($field) { - $validators = array(); - $validators['filefield_validate_is_image'] = array(); + // Add validators for resolutions. if (!empty($field['widget']['max_resolution']) || !empty($field['widget']['min_resolution'])) { - $validators['filefield_validate_image_resolution'] = array( + $element['#upload_validators']['filefield_validate_image_resolution'] = array( $field['widget']['max_resolution'], $field['widget']['min_resolution'], ); } - return $validators; + + return $element; } /** @@ -240,36 +189,31 @@ $formatters = array( 'image_plain' => array( 'label' => t('Image'), - 'field types' => array('image', 'filefield'), - 'suitability callback' => 'imagefield_handles_file', + 'field types' => array('filefield'), 'css' => array($module_path .'/imagefield.css'), 'description' => t('Displays image files in their original size.'), ), 'image_nodelink' => array( 'label' => t('Image linked to node'), - 'field types' => array('image', 'filefield'), - 'suitability callback' => 'imagefield_handles_file', + 'field types' => array('filefield'), 'css' => array($module_path .'/imagefield.css'), 'description' => t('Displays image files in their original size.'), ), 'image_imagelink' => array( 'label' => t('Image linked to file'), - 'field types' => array('image', 'filefield'), - 'suitability callback' => 'imagefield_handles_file', + 'field types' => array('filefield'), 'css' => array($module_path .'/imagefield.css'), 'description' => t('Displays image files in their original size.'), ), 'path_plain' => array( 'label' => t('Path to file'), - 'field types' => array('image', 'filefield'), - 'suitability callback' => 'imagefield_handles_file', + 'field types' => array('filefield'), 'css' => array($module_path .'/imagefield.css'), 'description' => t('Displays image files in their original size.'), ), 'url_plain' => array( 'label' => t('URL to file'), - 'field types' => array('image', 'filefield'), - 'suitability callback' => 'imagefield_handles_file', + 'field types' => array('filefield'), 'css' => array($module_path .'/imagefield.css'), 'description' => t('Displays image files in their original size.'), ), @@ -318,10 +262,7 @@ } function theme_imagefield_widget_item($element) { - return '