? dev
? imagefield-6.0-257620-5.patch
? imagefield-6.x-port-257620-24.patch
Index: field_file.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/imagefield/field_file.inc,v
retrieving revision 1.3
diff -u -p -r1.3 field_file.inc
--- field_file.inc 12 May 2008 17:18:07 -0000 1.3
+++ field_file.inc 28 May 2008 05:28:22 -0000
@@ -1,4 +1,5 @@
old_vid) return array();
// otherwise delete the file and return an empty array.
- if (_imagefield_file_delete($file)) return array();
+ if (field_file_delete($file)) return array();
}
- // set permanent status on files if unset.
+ // set permanent status on files if unset.
if (empty($file['status'])) {
// cast to object since core functions us objects.
$file = (object)$file;
@@ -72,16 +73,16 @@ function field_file_save($node, &$file)
/**
* Delete a field file and its database record.
*
- * @param $path
+ * @param $path
* A file object.
* @param $force
* Force File Deletion ignoring reference counting.
- * @return mixed
+ * @return mixed
* TRUE for success, Array for reference count block, or FALSE in the event of an error.
*/
function field_file_delete($file, $force = FALSE) {
$file = (object)$file;
- // If any module returns a value from the reference hook, the
+ // If any module returns a value from the reference hook, the
// file will not be deleted from Drupal, but file_delete will
// return a populated array that tests as TRUE.
if (!$force && $references = module_invoke_all('file', 'references', $file)) {
@@ -91,7 +92,7 @@ function field_file_delete($file, $force
// Let other modules clean up on delete.
module_invoke_all('file', 'delete', $file, $field);
- // Make sure the file is deleted before removing its row from the
+ // Make sure the file is deleted before removing its row from the
// database, so UIs can still find the file in the database.
if (file_delete($file->filepath)) {
db_query('DELETE FROM {files} WHERE fid = %d', $file->fid);
@@ -106,7 +107,7 @@ function field_file_delete($file, $force
*
* Check that the directory exists and is writable. Directories need to
* have execute permissions to be considered a directory by FTP servers, etc.
- *
+ *
*
* @param $directory A string containing the name of a directory path.
* @param $mode A Boolean value to indicate if the directory should be created
@@ -139,7 +140,7 @@ function field_file_check_directory(&$di
if (($mode & FILE_MODIFY_PERMISSIONS) && !@chmod($directory, 0775)) {
if ($form_item) {
form_set_error($form_item, t('The directory %directory is not writable', array('%directory' => $directory)));
- }
+ }
watchdog('file system', 'The directory %directory is not writable, because it does not have the correct permissions set.', array('%directory' => $directory), WATCHDOG_ERROR);
return FALSE;
}
Index: imagefield.install
===================================================================
RCS file: /cvs/drupal/contributions/modules/imagefield/imagefield.install,v
retrieving revision 1.6
diff -u -p -r1.6 imagefield.install
--- imagefield.install 12 May 2008 07:04:42 -0000 1.6
+++ imagefield.install 28 May 2008 05:28:22 -0000
@@ -96,7 +96,7 @@ function imagefield_update_2() {
* imagefield_nodelink => image_nodelink
* imagefield_imagelink => image_imagelink
* imagefield_path => path_plain
- * imagefield_url => url_plain
+ * imagefield_url => url_plain
*/
function imagefield_update_6100() {
include_once('./'. drupal_get_path('module', 'content') .'/content_crud.inc');
Index: imagefield.js
===================================================================
RCS file: imagefield.js
diff -N imagefield.js
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ imagefield.js 28 May 2008 05:28:26 -0000
@@ -0,0 +1,36 @@
+// $Id: imagefield.js,v 1.1.2.1 2008/04/21 06:59:13 dopry Exp $
+
+/**
+ * Auto Attach standard client side file input validation
+ */
+Drupal.imagefieldValidateAutoAttach = function() {
+ $("input[@type='file'].imagefield").change( function() {
+ $('.imagefield-js-error').remove();
+ /**
+ * add client side validation for the input[@file] accept attribute
+ */
+
+ if(this.accept.length>1){
+ v = new RegExp('\\.('+(this.accept?this.accept:'')+')$','gi');
+ if (!v.test(this.value)) {
+ var error = 'The file ' + this.value + " is not supported.\n";
+ error += "Only the following file types are supported: \n" + this.accept.replace(/\|/g, ' ');
+ alert(error);
+ // what do I prepend this to?
+ //$(this).prepend($('
'));
+ this.value = '';
+ return false;
+ }
+ }
+ /**
+ * Add filesize validation where possible
+ */
+
+ });
+}
+
+// Global killswitch
+if (Drupal.jsEnabled) {
+ $(document).ready(Drupal.imagefieldValidateAutoAttach);
+}
+
Index: imagefield.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/imagefield/imagefield.module,v
retrieving revision 1.38
diff -u -p -r1.38 imagefield.module
--- imagefield.module 12 May 2008 17:18:07 -0000 1.38
+++ imagefield.module 28 May 2008 05:28:26 -0000
@@ -73,7 +73,7 @@ function imagefield_theme() {
*/
function imagefield_elements() {
$elements = array();
- $elements['imagefield_widget_default'] = array(
+ $elements['image'] = array(
'#input' => TRUE,
'#columns' => array('fid', 'title', 'alt'),
'#process' => array('imagefield_element_process'),
@@ -98,6 +98,12 @@ function imagefield_element_process($ele
// Unset the storage to keep the form from unnecessarily rebuilding.
unset($form_state['storage'][$fieldname]);
}
+ // Change the type and theme to prevent FAPI from trying to output with the
+ // theme_image() function.
+ $element['#type'] = 'imagefield';
+ $element['#theme'] = 'imagefield';
+ $element['#tree'] = TRUE;
+
// Set an internal flag for requiredness. Prevents FAPI from interfering.
$element['#image_required'] = $element['#required'];
$element['#required'] = FALSE;
@@ -255,7 +261,7 @@ function _imagefield_widget_validate($el
}
$file = (array)$file;
$items[$file['fid']] = $file;
- }
+ }
// Sum all the items marked for deletion.
$deleted = 0;
@@ -444,7 +450,7 @@ function imagefield_field($op, $node, $f
case 'delete':
foreach ($items as $delta => $item) {
- _imagefield_file_delete($item, true);
+ field_file_delete($item, true);
}
break;
@@ -456,7 +462,7 @@ function imagefield_field($op, $node, $f
}
// Load the complete file if a filepath is not available.
if (!empty($item['fid']) && empty($item['filepath'])) {
- $items[$delta] = array_merge($item, _imagefield_file_load($item['fid']));
+ $items[$delta] = array_merge($item, field_file_load($item['fid']));
}
// Add nid so formatters can create a link to the node.
$items[$delta]['nid'] = $node->nid;
@@ -481,13 +487,13 @@ function imagefield_file($op, $file) {
// or by other fields.
case 'references':
$references = 0;
- foreach(content_fields() as $field) {
+ foreach (content_fields() as $field) {
if (!$field['type'] != 'image') continue;
$db_info = content_database_info($field);
$references += db_result(db_query("SELECT count(fid) FROM {%s} WHERE %s=%d", $db_info['table'], $db_info['columns']['fid']['column'], $item['fid']));
}
return array('imagefield' => $references);
- }
+ }
}
@@ -498,7 +504,7 @@ function imagefield_file($op, $file) {
*/
function imagefield_widget_info() {
return array(
- 'imagefield_widget_default' => array(
+ 'image' => array(
'label' => t('Image'),
'field types' => array('image'),
'multiple values' => CONTENT_HANDLE_MODULE,
@@ -535,7 +541,7 @@ function imagefield_widget_settings($op,
'#title' => t('Image path'),
'#default_value' => $widget['image_path'] ? $widget['image_path'] : '',
'#description' => t('Optional subdirectory within the "%dir" directory where images will be stored. Do not include trailing slash. You can use the following tokens in the image path.', array('%dir' => variable_get('file_directory_path', 'files'))),
- '#element_validate' => array('_imagefield_widget_settings_image_path_validate'),
+ '#element_validate' => array('_imagefield_widget_settings_image_path_validate'),
'#suffix' => theme('token_help', 'user'),
);
@@ -654,11 +660,11 @@ function imagefield_field_formatter_info
'path_plain' => array(
'label' => t('path to image'),
'field types' => array('image'),
- ),
+ ),
'url_plain' => array(
'label' => t('url to image'),
'field types' => array('image'),
- ),
+ ),
);
return $formatters;
}
@@ -668,7 +674,7 @@ function theme_imagefield_formatter_imag
$item = $element['#item'];
if (empty($item['fid']) && $field['use_default_image']) $item = $field['default_image'];
- if (empty($item['filepath'])) $item = array_merge($item, _imagefield_file_load($item['fid']));
+ if (empty($item['filepath'])) $item = array_merge($item, field_file_load($item['fid']));
$class = 'imagefield imagefield-'. $field['field_name'];
return theme('imagefield_image', $item, $item['alt'], $item['title'], array('class' => $class));
@@ -698,7 +704,7 @@ function theme_imagefield_formatter_path
$item = $element['#item'];
if (empty($item['fid']) && $field['use_default_image']) $item = $field['default_image'];
// If there is no image on the database, use default.
- if (empty($item['filepath'])) $item = array_merge($item, _imagefield_file_load($item['fid']));
+ if (empty($item['filepath'])) $item = array_merge($item, field_file_load($item['fid']));
$attributes['class'] .= ' imagefield-formatter-path';
return ''. file_create_path($item['filepath']) .'';
@@ -709,7 +715,7 @@ function theme_imagefield_formatter_url_
$item = $element['#item'];
if (empty($item['fid']) && $field['use_default_image']) $item = $field['default_image'];
// If there is no image on the database, use default.
- if (empty($item['filepath'])) $item = array_merge($item, _imagefield_file_load($item['fid']));
+ if (empty($item['filepath'])) $item = array_merge($item, field_file_load($item['fid']));
$attributes['class'] .= ' imagefield-formatter-url';
return ''. file_create_url($item['filepath']) .'';
@@ -734,7 +740,7 @@ function theme_imagefield_row($element)
/**
* FormAPI theme function. Theme the output of an image field.
*/
-function theme_imagefield_widget_default(&$element) {
+function theme_imagefield(&$element) {
$output = '';
// Always add tabledrag in case a table is created after uploads.
@@ -869,7 +875,7 @@ if (!function_exists('upload_file_downlo
* Menu-callback for JavaScript-based uploads.
*/
function imagefield_js($node_type, $fieldname) {
- $field = content_fields($fieldname, $node_typ);
+ $field = content_fields($fieldname, $node_type);
$form_state = array('values' => $_POST);
$form_state['values'][$fieldname] = isset($form_state['values'][$fieldname]) ? $form_state['values'][$fieldname] : array();
@@ -906,7 +912,6 @@ function imagefield_js($node_type, $fiel
$output = theme('status_messages') . drupal_render($form_element);
// We send the updated file attachments form.
- drupal_set_header('Content-Type: application/json; charset=utf-8');
print drupal_to_js(array('status' => true, 'data' => $output));
exit;