From 39339da27806534520ab6e0bf5c4abb71c3666c7 Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Sun, 1 Oct 2017 09:14:42 +0200 Subject: [PATCH] Added logo images to organization and project nodes --- modules/imagefield/imagefield.css | 9 + modules/imagefield/imagefield.info | 11 + modules/imagefield/imagefield.install | 353 ++++++++++++++++++ modules/imagefield/imagefield.module | 388 ++++++++++++++++++++ modules/imagefield/imagefield_file.inc | 125 +++++++ modules/imagefield/imagefield_formatter.inc | 47 +++ modules/imagefield/imagefield_widget.inc | 287 +++++++++++++++ themes/zuitedesk/css/forms.css | 2 +- themes/zuitedesk/css/global.css | 1 + themes/zuitedesk/css/suitedesk.css | 62 +++- 10 files changed, 1267 insertions(+), 18 deletions(-) create mode 100644 modules/imagefield/imagefield.css create mode 100644 modules/imagefield/imagefield.info create mode 100644 modules/imagefield/imagefield.install create mode 100644 modules/imagefield/imagefield.module create mode 100644 modules/imagefield/imagefield_file.inc create mode 100644 modules/imagefield/imagefield_formatter.inc create mode 100644 modules/imagefield/imagefield_widget.inc diff --git a/modules/imagefield/imagefield.css b/modules/imagefield/imagefield.css new file mode 100644 index 0000000..8ae2c39 --- /dev/null +++ b/modules/imagefield/imagefield.css @@ -0,0 +1,9 @@ + +.filefield-element .imagefield-preview { + min-width: 100px; + min-height: 100px; +} + +.filefield-element .imagefield-text { + max-width: 40em; /* Reflect the maxlength of the ALT attribute (80 characters). */ +} diff --git a/modules/imagefield/imagefield.info b/modules/imagefield/imagefield.info new file mode 100644 index 0000000..eebb726 --- /dev/null +++ b/modules/imagefield/imagefield.info @@ -0,0 +1,11 @@ +name = ImageField +description = Defines an image field type. +dependencies[] = content +dependencies[] = filefield +package = CCK +core = 6.x +; Information added by drupal.org packaging script on 2013-04-14 +version = "6.x-3.11" +core = "6.x" +project = "imagefield" +datestamp = "1365969012" diff --git a/modules/imagefield/imagefield.install b/modules/imagefield/imagefield.install new file mode 100644 index 0000000..06a6ed7 --- /dev/null +++ b/modules/imagefield/imagefield.install @@ -0,0 +1,353 @@ + FALSE, 'query' => t('Content module must be enabled before ImageField can be updated.')); + return $ret; + } + + 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; + } + + $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_module = 'imagefield', widget_active = 1 WHERE widget_type = 'image' OR widget_type = 'imagefield_widget'"); + content_clear_type_cache(); + + return $ret; +} + +/** + * Migrate fields to the new structure. + */ +function imagefield_update_6004(&$context) { + drupal_load('module', 'content'); + 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(); + + if (!isset($context['sandbox']['progress'])) { + // Get the latest cache values and schema. + content_clear_type_cache(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; + // Widgets are each updated individually. + $context['sandbox']['widgets'][] = $field; + } + } + } + + if (empty($context['sandbox']['fields'])) { + return $ret; + } + + // 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"); + + // Set any entries that were abandoned by poor housekeeping to NULL. + $ret[] = update_sql("UPDATE {" . $db_info['table'] . "} SET " . $field['field_name'] . "_fid = NULL WHERE " . $field['field_name'] . "_fid NOT IN (SELECT fid FROM {files})"); + + // 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')); + } + + // Set the default state of the global settings. + $field['list_field'] = '0'; + $field['list_default'] = '1'; + $field['description_field'] = '0'; + + // Map 'max_number_images' parameter to CCK 'multiple'. + if (!empty($field['widget']['multiple']) && isset($field['widget']['max_number_images'])) { + if ($field['widget']['max_number_images'] == 0) { + $field['multiple'] = 1; // 1 means "Unlimited" in CCK. + } + elseif ($field['widget']['max_number_images'] == 1) { + $field['multiple'] = 0; // 0 means "Not Multiple" in CCK. + } + else { + $field['multiple'] = $field['widget']['max_number_images']; + } + } + + // Update format names. + $display_settings = array('teaser', 'full'); + foreach ($display_settings as $display_context) { + if (isset($field['display_settings'][$display_context])) { + switch ($field['display_settings'][$display_context]['format']) { + case 'imagefield_nodelink': + $field['display_settings'][$display_context]['format'] = 'image_nodelink'; + break; + case 'imagefield_imagelink': + $field['display_settings'][$display_context]['format'] = 'image_imagelink'; + break; + case 'imagefield_path': + $field['display_settings'][$display_context]['format'] = 'path_plain'; + break; + case 'imagefield_url': + $field['display_settings'][$display_context]['format'] = 'url_plain'; + break; + case 'imagefield_default': + case 'default': + $field['display_settings'][$display_context]['format'] = 'image_plain'; + break; + } + } + } + + // Move the default_image options to the widget level. + $field['widget']['default_image'] = isset($field['default_image']) ? $field['default_image'] : NULL; + $field['widget']['use_default_image'] = isset($field['use_default_image']) ? $field['use_default_image'] : 0; + + // The default image needs to be saved in the files table. + if (isset($field['widget']['default_image']['filepath'])) { + $file = (object) $field['widget']['default_image']; + // Check if it's already in the files table. + if ($fid = db_result(db_query("SELECT fid FROM {files} WHERE filepath = '%s'", $file->filepath))) { + $field['widget']['default_image']['fid'] = $fid; + } + // Otherwise add it. + else { + $file->uid = 1; + $file->status = 1; + drupal_write_record('files', $file); + $field['widget']['default_image']['fid'] = $file->fid; + } + + // Unset the field-level definition, or it will take precedence. + unset($field['default_image']); + } + + content_field_instance_update($field); + } + + // Update each widget instance. + foreach ($context['sandbox']['widgets'] as $field) { + // Change file_path to image_path. + if (isset($field['widget']['image_path'])) { + $field['widget']['file_path'] = $field['widget']['image_path']; + } + + // Update the formatters. + foreach ($field['display_settings'] as $key => $display) { + switch ($display['format']) { + case 'default': + $field['display_settings'][$key]['format'] = 'image_plain'; + break; + case 'imagefield_nodelink': + $field['display_settings'][$key]['format'] = 'image_nodelink'; + break; + case 'imagefield_imagelink': + $field['display_settings'][$key]['format'] = 'image_imagelink'; + break; + case 'imagefield_path': + $field['display_settings'][$key]['format'] = 'path_plain'; + break; + case 'imagefield_url': + $field['display_settings'][$key]['format'] = 'url_plain'; + break; + } + } + + content_field_instance_update($field); + } + + $context['sandbox']['progress'] = 0; + $context['sandbox']['total'] = count($context['sandbox']['fields']); + $context['sandbox']['current_node'] = 0; + } + + $field = array_shift($context['sandbox']['fields']); + $db_info = content_database_info($field); + $table = $db_info['table']; + $col_fid = $field['field_name'] .'_fid'; + $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 = 100; + $result = db_query_range("SELECT * FROM {". $table ."} WHERE vid > %d ORDER BY vid ASC", $context['sandbox']['current_node'], 0, $limit); + $has_processed = FALSE; + + // 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]); + } + if (empty($data)) { + $data = array(); + } + + // 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"; + $row['delta'] = 0; + } + + // Serialize it and store it back to the db. + db_query($query, serialize($data), $list, $row['vid'], $row['delta']); + + // Update our progress information. + $context['sandbox']['current_node'] = $row['vid']; + $has_processed = TRUE; + } + + if ($has_processed) { + // Not finished, put back the field in the array. + array_unshift($context['sandbox']['fields'], $field); + } + else { + // Cleanup the old columns. + if (db_column_exists($table, $col_alt)) { + db_drop_field($ret, $table, $col_alt); + } + if (db_column_exists($table, $col_title)) { + db_drop_field($ret, $table, $col_title); + } + + // Process to next field. + $context['sandbox']['progress']++; + $context['sandbox']['current_node'] = 0; + } + + if (!empty($context['sandbox']['fields'])) { + $ret['#finished'] = $context['sandbox']['progress'] / $context['sandbox']['total']; + } + + return $ret; +} + +/** + * Delete thumbnails spread throughout the files directory. + */ +function imagefield_update_6005() { + $ret = array(); + + $result = db_query("SELECT * FROM {files} WHERE filemime LIKE 'image/%'"); + + while ($file = db_fetch_object($result)) { + // ImageField 6002 thumbnail path. + $thumb_path_a = $file->filepath . '.thumb.jpg'; + + // ImageField 6004 thumbnail path. + $extension_dot = strrpos($file->filepath, '.'); + $extension = substr($file->filepath, $extension_dot + 1); + $basepath = substr($file->filepath, 0, $extension_dot); + $thumb_path_b = $basepath .'.thumb.'. $extension; + + file_delete($thumb_path_a); + file_delete($thumb_path_b); + } + + $ret[] = array('success' => TRUE, 'query' => t('Deleted admin thumbnails distributed throughout files directory. All thumbnails are now stored in the "imagefield_thumbs" directory.')); + + return $ret; +} + +/** + * Add default values to all ImageFields. + */ +function imagefield_update_6006() { + $ret = array(); + module_load_install('content'); + foreach (content_types_install() as $type_name => $fields) { + foreach ($fields as $field) { + if ($field['type'] == 'filefield' && $field['widget']['type'] == 'imagefield_widget') { + $field['widget']['file_extensions'] = isset($field['widget']['file_extensions']) ? $field['widget']['file_extensions'] : NULL; + $field['widget']['max_filesize_per_file'] = isset($field['widget']['max_filesize_per_file']) ? $field['widget']['max_filesize_per_file'] : NULL; + $field['widget']['max_filesize_per_node'] = isset($field['widget']['max_filesize_per_node']) ? $field['widget']['max_filesize_per_node'] : NULL; + content_field_instance_update($field); + } + } + } + + return $ret; +} diff --git a/modules/imagefield/imagefield.module b/modules/imagefield/imagefield.module new file mode 100644 index 0000000..6fd0aa2 --- /dev/null +++ b/modules/imagefield/imagefield.module @@ -0,0 +1,388 @@ + array( + 'arguments' => array('file' => NULL, 'alt' => '', 'title' => '', 'attributes' => NULL, 'getsize' => TRUE), + ), + // Theme an ImageField field item. It calls imagefied_image with the proper + // item properties as arguments. + 'imagefield_item' => array( + 'arguments' => array('item' => NULL), + ), + // imagefield_widget form element type theme function. + 'imagefield_widget' => array( + 'arguments' => array('element' => NULL), + 'file' => 'imagefield_widget.inc', + ), + // Use to generate a preview (admin view) of an imagefield item for use in + // field item forms and filefield widgets. Invoked by filefield_widget_process. + 'imagefield_widget_preview' => array( + 'arguments' => array('item' => NULL), + ), + // Theme function for the field item elements. allows you to place children + // within the context of the parent. + 'imagefield_widget_item' => array( + 'arguments' => array('element' => NULL), + ), + // Generates and img tag to the admin thumbnail of an ImageField upload. + 'imagefield_admin_thumbnail' => array( + 'arguments' => array('item' => NULL), + ), + // ImageField formatter theme functions. + 'imagefield_formatter_image_plain' => array( + 'arguments' => array('element' => NULL), + 'file' => 'imagefield_formatter.inc', + ), + 'imagefield_formatter_image_nodelink' => array( + 'arguments' => array('element' => NULL), + 'file' => 'imagefield_formatter.inc', + ), + 'imagefield_formatter_image_imagelink' => array( + 'arguments' => array('element' => NULL), + 'file' => 'imagefield_formatter.inc', + ), + ); +} + +/** + * Implementation of hook_elements(). + */ +function imagefield_elements() { + $elements = array(); + + // Catch problems when this is called too early during installation or update. + if (!module_exists('filefield')) { + return $elements; + } + + // An ImageField is really just a FileField with extra processing. + $filefield_elements = module_invoke('filefield', 'elements'); + $elements['imagefield_widget'] = $filefield_elements['filefield_widget']; + $elements['imagefield_widget']['#process'][] = 'imagefield_widget_process'; + + // ImageField needs a separate value callback to save its alt and title texts. + $elements['imagefield_widget']['#value_callback'] = 'imagefield_widget_value'; + + return $elements; +} + +/** + * Implementation of hook_file_download. + */ +function imagefield_file_download($filepath) { + // Return headers for admin thumbnails if private files are enabled. + if (strpos($filepath, 'imagefield_thumbs') !== FALSE) { + $original_path = str_replace('imagefield_thumbs/', '', $filepath); + $original_full_path = file_create_path($original_path); + $thumb_full_path = file_create_path($filepath); + + // Allow access to temporary thumbnails, since they're not yet associated + // with a node. If not temporary, check access on the original file. + $status = db_result(db_query("SELECT status FROM {files} WHERE filepath = '%s'", $original_full_path)); + $access = ($status == 0 || !in_array(-1, module_invoke_all('file_download', $original_path))); + if ($access && $info = getimagesize($thumb_full_path)) { + return array( + 'Content-Type: ' . $info['mime'], + 'Content-Length: ' . filesize($thumb_full_path) + ); + } + } + + // Return headers for default images. + if (strpos($filepath, 'imagefield_default_images') !== FALSE) { + $full_path = file_create_path($filepath); + if ($info = getimagesize($full_path)) { + return array( + 'Content-Type: ' . $info['mime'], + 'Content-Length: ' . filesize($full_path) + ); + } + } +} + +/** + * Implementation of hook_nodeapi(). + * + * Add ALT and title texts to the search index. + */ +function imagefield_nodeapi($node, $op) { + if ($op == 'update index') { + static $fields; + if (!isset($fields)) { + $fields = filefield_get_field_list(); + } + + $texts = array(); + foreach ($fields as $field) { + $name = $field['field_name']; + // Check this node for ImageField alt and title data. + if (isset($node->$name) && is_array($node->$name)) { + foreach ($node->$name as $item) { + $texts[] = isset($item['data']['alt']) ? $item['data']['alt'] : ''; + $texts[] = isset($item['data']['title']) ? $item['data']['title'] : ''; + } + } + } + return implode(' ', $texts); + } +} + +/** + * Implementation of CCK's hook_widget_info(). + */ +function imagefield_widget_info() { + $module_path = drupal_get_path('module', 'imagefield'); + return array( + 'imagefield_widget' => array( + 'label' => t('Image'), + 'field types' => array('filefield'), + 'multiple values' => CONTENT_HANDLE_CORE, + 'callbacks' => array('default value' => CONTENT_CALLBACK_CUSTOM), + 'description' => t('An edit widget for image files, including a preview of the image.'), + ), + ); +} + +/** + * Implementation of CCK's hook_widget_settings(). + */ +function imagefield_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); + } +} + +/** + * Implementation of CCK's hook_widget(). + * + * Assign default properties to item and delegate to FileField. + */ +function imagefield_widget(&$form, &$form_state, $field, $items, $delta = 0) { + // Add default values to items. + // TODO: use CCK's default value callback. + if (empty($items[$delta])) { + $items[$delta] = array('alt' => '', 'title' => ''); + } + + // Start with the FileField widget as a basic start. + // Note that FileField needs to modify $form by reference. + $element = filefield_widget($form, $form_state, $field, $items, $delta); + + // Add ImageField specific validators. + $element['#upload_validators'] = array_merge($element['#upload_validators'], imagefield_widget_upload_validators($field)); + + return $element; +} + +/** + * Get the additional upload validators for an image field. + * + * @param $field + * The CCK field array. + * @return + * An array suitable for passing to file_save_upload() or the file field + * element's '#upload_validators' property. + */ +function imagefield_widget_upload_validators($field) { + $validators = array(); + + // Match the default value if no file extensions have been saved at all. + if (!isset($field['widget']['file_extensions'])) { + $field['widget']['file_extensions'] = 'png gif jpg jpeg'; + } + + // Ensure that only web images are supported. + $web_extensions = array('png', 'gif', 'jpg', 'jpeg'); + $extensions = array_filter(explode(' ', $field['widget']['file_extensions'])); + if (empty($extensions)) { + $extensions = $web_extensions; + } + $validators['filefield_validate_extensions'][0] = implode(' ', array_intersect($extensions, $web_extensions)); + + // Add the image validator as a basic safety check. + $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( + $field['widget']['max_resolution'], + $field['widget']['min_resolution'], + ); + } + + return $validators; +} + +/** + * Implementation of CCK's hook_field_formatter_info(). + */ +function imagefield_field_formatter_info() { + $module_path = drupal_get_path('module', 'imagefield'); + $formatters = array( + 'image_plain' => array( + 'label' => t('Image'), + 'field types' => array('filefield'), + 'description' => t('Displays image files in their original size.'), + ), + 'image_nodelink' => array( + 'label' => t('Image linked to node'), + 'field types' => array('filefield'), + 'description' => t('Displays image files in their original size.'), + ), + 'image_imagelink' => array( + 'label' => t('Image linked to file'), + 'field types' => array('filefield'), + 'description' => t('Displays image files in their original size.'), + ), + ); + return $formatters; +} + +/** + * Implementation of CCK's hook_default_value(). + */ +function imagefield_default_value(&$form, &$form_state, $field, $delta) { + return filefield_default_value($form, $form_state, $field, $delta); +} + +/** + * Implementation of hook_form_[form_id]_alter(). + * + * Modify the add new field form to make "Image" the default formatter. + */ +function imagefield_form_content_field_overview_form_alter(&$form, &$form_state) { + $form['#submit'][] = 'imagefield_form_content_field_overview_submit'; +} + +/** + * Submit handler to set a new field's formatter to "image_plain". + */ +function imagefield_form_content_field_overview_submit(&$form, &$form_state) { + if (isset($form_state['fields_added']['_add_new_field']) && isset($form['#type_name'])) { + $new_field = $form_state['fields_added']['_add_new_field']; + $node_type = $form['#type_name']; + $field = content_fields($new_field, $node_type); + if ($field['widget']['module'] == 'imagefield') { + foreach ($field['display_settings'] as $display_type => $display_settings) { + if ($field['display_settings'][$display_type]['format'] == 'default') { + $field['display_settings'][$display_type]['format'] = 'image_plain'; + } + } + content_field_instance_update($field); + } + } +} + +/** + * Implementation of hook_filefield_data_info(). + */ +function imagefield_filefield_data_info() { + return array( + 'alt' => array( + 'title' => t('Alt text'), + 'callback' => 'check_plain', + ), + 'title' => array( + 'title' => t('Title'), + 'callback' => 'check_plain', + ), + ); +} + +/** + * @defgroup "Theme Callbacks" + * @{ + * @see imagefield_theme(). + */ +function theme_imagefield_image($file, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) { + $file = (array) $file; + + if ($getsize) { + // Use cached width and height if available. + if (!empty($file['data']['width']) && !empty($file['data']['height'])) { + $attributes['width'] = $file['data']['width']; + $attributes['height'] = $file['data']['height']; + } + // Otherwise pull the width and height from the file. + elseif (list($width, $height, $type, $image_attributes) = @getimagesize($file['filepath'])) { + $attributes['width'] = $width; + $attributes['height'] = $height; + } + } + + if (!empty($title)) { + $attributes['title'] = $title; + } + + // Alt text should be added even if it is an empty string. + $attributes['alt'] = $alt; + + // Add a timestamp to the URL to ensure it is immediately updated after editing. + $query_string = ''; + if (isset($file['timestamp'])) { + $query_character = (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PRIVATE && variable_get('clean_url', '0') == '0') ? '&' : '?'; + $query_string = $query_character . $file['timestamp']; + } + + // Encode the path so that unusual characters are printed correctly. + $path = field_file_urlencode_path($file['filepath']); + + // Construct the URL. + $url = file_create_url($path) . $query_string; + $attributes['src'] = $url; + $attributes = drupal_attributes($attributes); + return ''; +} + +function theme_imagefield_item($item) { + return theme('imagefield_image', $item, $item['alt'], $item['title']); +} + +function theme_imagefield_widget_preview($item = NULL) { + return '
' . theme('imagefield_admin_thumbnail', $item) . '
'; +} + +function theme_imagefield_widget_item($element) { + return theme('filefield_widget_item', $element); +} + +function theme_imagefield_admin_thumbnail($item = NULL) { + if (is_null($item) || empty($item['filepath'])) { + return ''; + } + $thumb_path = imagefield_file_admin_thumb_path($item); + + // Encode the path so that unusual characters are printed correctly. + $thumb_path = field_file_urlencode_path($thumb_path); + + // Add a timestamp to the URL to ensure it is immediately updated after editing. + $query_string = ''; + if (isset($item['timestamp'])) { + $query_character = (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PRIVATE && variable_get('clean_url', '0') == '0') ? '&' : '?'; + $query_string = $query_character . $item['timestamp']; + } + + return '' . t('Image preview') . ''; +} +/** + * @} End defgroup "Theme Callbacks". + */ diff --git a/modules/imagefield/imagefield_file.inc b/modules/imagefield/imagefield_file.inc new file mode 100644 index 0000000..7db469e --- /dev/null +++ b/modules/imagefield/imagefield_file.inc @@ -0,0 +1,125 @@ +imagefield_type_name)) { + $content_types = content_types(); + foreach ($content_types as $type_name => $content_type) { + if ($type_name != $file->imagefield_type_name) { + foreach ($content_type['fields'] as $field_name => $field) { + if ($field['widget']['default_image'] && $field['widget']['default_image']['fid'] == $file->fid) { + $count++; + } + } + } + } + } + return $count ? array('imagefield' => $count) : NULL; +} + +/** + * Simple utility function to check if a file is an image. + */ +function imagefield_file_is_image($file) { + $file = (object)$file; + return in_array($file->filemime, array('image/jpg', 'image/pjpeg', 'image/jpeg', 'image/png', 'image/gif')); +} + +/** + * Given a file, return the path the image thumbnail used while editing. + */ +function imagefield_file_admin_thumb_path($file, $create_thumb = TRUE) { + $file = (object)$file; + $short_path = preg_replace('/^' . preg_quote(file_directory_path(), '/') . '/', '', $file->filepath); + $filepath = file_directory_path() . '/imagefield_thumbs' . $short_path; + + if ($create_thumb) { + imagefield_create_admin_thumb($file->filepath, $filepath); + } + + return $filepath; +} + +/** + * Create a thumbnail to be shown while editing an image. + */ +function imagefield_create_admin_thumb($source, $destination) { + if (!is_file($source)) { + return FALSE; + } + + $info = image_get_info($source); + $size = explode('x', variable_get('imagefield_thumb_size', '100x100')); + + // Check if the destination image needs to be regenerated to match a new size. + if (is_file($destination)) { + $thumb_info = image_get_info($destination); + if ($thumb_info['width'] != $size[0] && $thumb_info['height'] != $size[1] && ($info['width'] > $size[0] || $info['height'] > $size[1])) { + unlink($destination); + } + else { + return; + } + } + + // Ensure the destination directory exists and is writable. + $directories = explode('/', $destination); + array_pop($directories); // Remove the file itself. + // Get the file system directory. + $file_system = file_directory_path(); + foreach ($directories as $directory) { + $full_path = isset($full_path) ? $full_path . '/' . $directory : $directory; + // Don't check directories outside the file system path. + if (strpos($full_path, $file_system) === 0) { + field_file_check_directory($full_path, FILE_CREATE_DIRECTORY); + } + } + + // Create the thumbnail. + if ($info['width'] <= $size[0] && $info['height'] <= $size[1]) { + file_copy($source, $destination); + } + // Use ImageAPI, if installed. + elseif (module_exists('imageapi') && imageapi_default_toolkit()) { + $res = imageapi_image_open($source); + imageapi_image_scale($res, $size[0], $size[1]); + imageapi_image_close($res, $destination); + } + elseif (image_get_toolkit() && image_scale($source, $destination, $size[0], $size[1])) { + // Set permissions. This is done for us when using file_copy(). + @chmod($destination, 0664); + } + else { + drupal_set_message(t('An image thumbnail was not able to be created.'), 'error'); + } +} diff --git a/modules/imagefield/imagefield_formatter.inc b/modules/imagefield/imagefield_formatter.inc new file mode 100644 index 0000000..d92466f --- /dev/null +++ b/modules/imagefield/imagefield_formatter.inc @@ -0,0 +1,47 @@ + $class)); +} + +function theme_imagefield_formatter_image_nodelink($element) { + // Inside a view $element may contain null data. In that case, just return. + if (empty($element['#item']['fid'])) { + return ''; + } + + $node = $element['#node']; + $imagetag = theme('imagefield_formatter_image_plain', $element); + $class = 'imagefield imagefield-nodelink imagefield-'. $element['#field_name']; + return l($imagetag, 'node/'. $node->nid, array('attributes' => array('class' => $class), 'html' => TRUE)); +} + +function theme_imagefield_formatter_image_imagelink($element) { + // Inside a view $element may contain null data. In that case, just return. + if (empty($element['#item']['fid'])) { + return ''; + } + + $item = $element['#item']; + $imagetag = theme('imagefield_formatter_image_plain', $element); + $original_image_url = file_create_url($item['filepath']); + $class = 'imagefield imagefield-imagelink imagefield-'. $element['#field_name']; + return l($imagetag, $original_image_url, array('attributes' => array('class' => $class), 'html' => TRUE)); +} diff --git a/modules/imagefield/imagefield_widget.inc b/modules/imagefield/imagefield_widget.inc new file mode 100644 index 0000000..8a152cb --- /dev/null +++ b/modules/imagefield/imagefield_widget.inc @@ -0,0 +1,287 @@ + 'textfield', + '#title' => t('Maximum dimensions for images'), + '#default_value' => !empty($widget['max_resolution']) ? $widget['max_resolution'] : 0, + '#size' => 15, + '#maxlength' => 10, + '#description' => t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Set to 0 for no restriction. If a larger image is uploaded, it will be resized to reflect the given width and height.'), + '#weight' => 2.1, + ); + $form['min_resolution'] = array( + '#type' => 'textfield', + '#title' => t('Minimum dimensions for images'), + '#default_value' => !empty($widget['min_resolution']) ? $widget['min_resolution'] : 0, + '#size' => 15, + '#maxlength' => 10, + '#description' => t('The minimum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Set to 0 for no restriction. If an image that is smaller than these dimensions is uploaded it will be rejected.'), + '#weight' => 2.2, + ); + + if (!module_exists('imageapi') || imageapi_default_toolkit() == 'imageapi_gd') { + $form['max_resolution']['#description'] .= ' ' . t('Resizing images on upload will cause the loss of EXIF data in the image.'); + } + + $form['alt_settings'] = array( + '#type' => 'fieldset', + '#title' => t('ALT text settings'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#weight' => 8, + ); + $form['alt_settings']['custom_alt'] = array( + '#type' => 'checkbox', + '#title' => t('Enable custom alternate text'), + '#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'), + '#default_value' => !empty($widget['alt']) ? $widget['alt'] : '', + '#description' => t('This value will be used for alternate text by default.'), + '#suffix' => theme('token_help', array('user')), + ); + + $form['title_settings'] = array( + '#type' => 'fieldset', + '#title' => t('Title text settings'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#weight' => 8, + ); + $form['title_settings']['custom_title'] = array( + '#type' => 'checkbox', + '#title' => t('Enable custom title text'), + '#default_value' => !empty($widget['custom_title']) ? $widget['custom_title'] : 0, + '#description' => t('Enable user input title text for images.'), + ); + $form['title_settings']['title_type'] = array( + '#type' => 'select', + '#title' => t('Input type'), + '#options' => array( + 'textfield' => 'textfield', + 'textarea' => 'textarea'), + '#default_value' => !empty($widget['title_type']) ? $widget['title_type'] : 'textfield', + '#description' => t('Choose type of field to be displayed to the user.'), + ); + $form['title_settings']['title'] = array( + '#type' => 'textfield', + '#title' => t('Default Title text'), + '#default_value' => !empty($widget['title']) ? $widget['title'] : '', + '#description' => t('This value will be used as the image title by default.'), + '#suffix' => theme('token_help', array('user')), + ); + + // Default image settings. + $form['default'] = array( + '#type' => 'fieldset', + '#title' => t('Default image'), + '#element_validate' => array('_imagefield_widget_settings_default_validate'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#weight' => 10 + ); + + // Present a thumbnail of the current default image. + $form['default']['use_default_image'] = array( + '#type' => 'checkbox', + '#title' => t('Use default image'), + '#default_value' => $widget['use_default_image'], + '#description' => t('When an image is not uploaded, show a default image on display.'), + ); + + if (!empty($widget['default_image'])) { + $form['default']['default_image_thumbnail'] = array( + '#type' => 'markup', + '#value' => theme('imagefield_image', $widget['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' => $widget['default_image'], + ); + + return $form; +} + +/** + * 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_widget_settings_default_validate($element, &$form_state) { + // Skip this validation if there isn't a default file uploaded at all or if + // validation has already failed because of another error. + if (!is_uploaded_file($_FILES['files']['tmp_name']['default_image_upload']) || form_set_error()) { + return; + } + + // Verify the destination exists. + $destination = file_directory_path() .'/imagefield_default_images'; + if (!field_file_check_directory($destination, FILE_CREATE_DIRECTORY)) { + form_set_error('default_image', t('The default image could not be uploaded. The destination %destination does not exist or is not writable by the server.', array('%destination' => dirname($destination)))); + 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, $destination)) { + // No upload to save we hope... or file_save_upload() reported an error on its own. + return; + } + + // Remove the old default image if any. + $old_default = $form_state['values']['default_image']; + if (!empty($old_default['fid'])) { + // Set a flag to not count this instance in hook_file_references(). + $old_default['imagefield_type_name'] = $form_state['values']['type_name']; + field_file_delete($old_default); + } + + // Make the file permanent and store it in the form. + file_set_status($file, FILE_STATUS_PERMANENT); + $file->timestamp = time(); + $form_state['values']['default_image'] = (array)$file; + } + +/** + * Implementation of CCK's hook_widget_settings($op = 'validate'). + */ +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.')); + } + + // Check that set resolutions are valid. + foreach (array('min_resolution', 'max_resolution') as $resolution) { + if (!empty($widget[$resolution]) && !preg_match('/^[0-9]+x[0-9]+$/', $widget[$resolution])) { + form_set_error($resolution, t('Please specify a resolution in the format WIDTHxHEIGHT (e.g. 640x480).')); + } + } +} + +/** + * Implementation of CCK's hook_widget_settings($op = 'save'). + */ +function imagefield_widget_settings_save($widget) { + $filefield_settings = module_invoke('filefield', 'widget_settings', 'save', $widget); + return array_merge($filefield_settings, array('max_resolution', 'min_resolution', 'alt', 'custom_alt', 'title', 'custom_title', 'title_type', 'default_image', 'use_default_image')); +} + +/** + * Element #value_callback function. + */ +function imagefield_widget_value($element, $edit = FALSE) { + $item = filefield_widget_value($element, $edit); + if ($edit) { + $item['alt'] = isset($edit['alt']) ? $edit['alt'] : ''; + $item['title'] = isset($edit['title']) ? $edit['title'] : ''; + } + else { + $item['alt'] = ''; + $item['title'] = ''; + } + return $item; +} + +/** + * 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'; + + if (isset($element['preview']) && $element['#value']['fid'] != 0) { + $element['preview']['#value'] = theme('imagefield_widget_preview', $element['#value']); + } + + // Check if using the default alt text and replace tokens. + $default_alt = (!$field['widget']['custom_alt'] || (empty($file['status']) && empty($file['data']['alt']))); + if ($default_alt && function_exists('token_replace')) { + $field['widget']['alt'] = empty($field['widget']['alt']) ? '' : token_replace($field['widget']['alt'], 'user', $GLOBALS['user']); + } + $element['data']['alt'] = array( + '#title' => t('Alternate Text'), + '#type' => $field['widget']['custom_alt'] ? 'textfield' : 'value', + '#default_value' => $default_alt ? $field['widget']['alt'] : $file['data']['alt'], + '#description' => t('This text will be used by screen readers, search engines, or when the image cannot be loaded.'), + '#maxlength' => variable_get('imagefield_alt_length', 80), // See http://www.gawds.org/show.php?contentid=28. + '#attributes' => array('class' => 'imagefield-text'), + ); + // #value must be hard-coded if #type = 'value'. + if ($default_alt) { + $element['data']['alt']['#value'] = $field['widget']['alt']; + } + + // Check if using the default title and replace tokens. + $default_title = (!$field['widget']['custom_title'] || (empty($file['status']) && empty($file['data']['title']))); + if ($default_title && function_exists('token_replace')) { + $field['widget']['title'] = empty($field['widget']['title']) ? '' : token_replace($field['widget']['title'], 'user', $GLOBALS['user']); + } + + // If the custom title is enabled, input type defaults to textfield. + if (!empty($field['widget']['custom_title'])) { + $title_type = !empty($field['widget']['title_type']) ? $field['widget']['title_type'] : 'textfield'; + } + else { + $title_type = 'value'; + } + + $element['data']['title'] = array( + '#type' => $title_type, + '#title' => t('Title'), + '#default_value' => $default_title ? $field['widget']['title'] : $file['data']['title'], + '#description' => t('The title is used as a tool tip when the user hovers the mouse over the image.'), + '#maxlength' => variable_get('imagefield_title_length', 500), + '#attributes' => array('class' => 'imagefield-text'), + ); + // #value must be hard-coded if #type = 'value'. + if ($default_title) { + $element['data']['title']['#value'] = $field['widget']['title']; + } + + return $element; +} + +/** + * FormAPI theme function. Theme the output of an image field. + */ +function theme_imagefield_widget($element) { + drupal_add_css(drupal_get_path('module', 'imagefield') .'/imagefield.css'); + $element['#id'] .= '-upload'; // Link the label to the upload field. + return theme('form_element', $element, $element['#children']); +} diff --git a/themes/zuitedesk/css/forms.css b/themes/zuitedesk/css/forms.css index ea9e40b..e4c5195 100644 --- a/themes/zuitedesk/css/forms.css +++ b/themes/zuitedesk/css/forms.css @@ -57,7 +57,7 @@ form[id$="-list-filter"] div.container-inline .form-item { /* * Forms and fieldsets with inner tables. */ -body[class*=" section-node-"] form table.table td, +body[class*=" section-node-"] form table.table td:not(.content-multiple-drag), form[id$="-list-filter"] fieldset table.table td { border-width: 0 !important; padding: 0 1em 0 0 !important; diff --git a/themes/zuitedesk/css/global.css b/themes/zuitedesk/css/global.css index cf04fa0..efb101f 100644 --- a/themes/zuitedesk/css/global.css +++ b/themes/zuitedesk/css/global.css @@ -119,6 +119,7 @@ tr.drag-previous { .draggable > td:first-child { overflow: hidden; position: relative; + border: 0; } .draggable > td:first-child span.tabledrag-changed { position: absolute; diff --git a/themes/zuitedesk/css/suitedesk.css b/themes/zuitedesk/css/suitedesk.css index cd06bb0..f15f7a2 100644 --- a/themes/zuitedesk/css/suitedesk.css +++ b/themes/zuitedesk/css/suitedesk.css @@ -1201,6 +1201,16 @@ body.suitedesk div.field-items { padding-left: .4em; background-color: #efefef; } +div.field-type-filefield[class$="-image"] div.field-items { + padding: 8px; + text-align: center; +} +div.field-items img.imagefield[class$="_image"] { + margin: 0 auto; + max-width: 100%; + height: auto; + width: auto\9; /* IE8 */ +} @media (max-width: 889px) { div.stormfields { margin-bottom: 0; @@ -1598,6 +1608,10 @@ div.tt-new { /* * Forms and fieldsets with inner tables (SuiteDesk exceptions). */ +div[id$="-attach-items"] table.table td:not(.content-multiple-drag), +div[id$="-attached-items"] table.table td:not(.content-multiple-drag) { + float: none !important; +} /* #field-stormorganization-attached-items table.table td, #field-stormperson-attached-items table.table td, #field-stormproject-attached-items table.table td, @@ -1609,6 +1623,17 @@ div.tt-new { #field-stormnote-attached-items table.table td, #field-stormdok-attach-items table.table td { float: none; +} */ + +table[id*="_attach_values"], +table[id*="_attached_values"] { + margin-top: -0.5em; +} +table[id*="_attach_values"] thead, +table[id*="_attached_values"] thead, +#edit-field-stormorganization-image-0-upload-wrapper label, +#edit-field-stormproject-image-0-upload-wrapper label { + display: none; } /* @@ -1695,13 +1720,13 @@ fieldset.group-stormorganization-members { } fieldset.group-stormorganization-members legend { display: none; -} +} /* table#field_stormorganization_attached_values { margin-top: -0.5em; } table#field_stormorganization_attached_values thead { display: none; -} +} */ /* * "SuiteDesk Person" node form. @@ -1709,13 +1734,13 @@ table#field_stormorganization_attached_values thead { #edit-field-stormperson-name-0-value, #edit-field-stormperson-lastname-0-value { width: 100%; -} +} /* table#field_stormperson_attached_values { margin-top: -0.5em; } table#field_stormperson_attached_values thead { display: none; -} +} */ /* * "SuiteDesk Project" node form. @@ -1730,11 +1755,14 @@ fieldset.group-stormproject-subprojects legend { } #edit-field-stormproject-team-value-wrapper { margin: 1.4em 0 .4em; -} +} /* table#field_stormproject_attached_values { margin-top: -0.5em; } table#field_stormproject_attached_values thead, +form.stormproject_node_form fieldset.book-outline-form { + display: none; +} */ form.stormproject_node_form fieldset.book-outline-form { display: none; } @@ -1744,33 +1772,33 @@ form.stormproject_node_form fieldset.book-outline-form { */ #edit-durationunit-wrapper { margin-bottom: 1.2em; /* Solving field position in responsive actions */ -} +} /* table#field_stormtask_attached_values { margin-top: -0.5em; } table#field_stormtask_attached_values thead { display: none; -} +} */ /* * "SuiteDesk Ticket" node form. - */ + */ /* table#field_stormticket_attached_values { margin-top: -0.5em; } table#field_stormticket_attached_values thead { display: none; -} +} */ /* * "SuiteDesk Event" node form. - */ + */ /* table#field_stormevent_attach_values { margin-top: -0.5em; } table#field_stormevent_attach_values thead { display: none; -} +} */ #edit-field-stormevent-place-0-value-wrapper + .form-item .form-radios label { float: left; width: 7.24%; @@ -1861,13 +1889,13 @@ table#field_stormevent_attach_values thead { /* * "SuiteDesk Note" node form. - */ + */ /* table#field_stormnote_attached_values { margin-top: -0.5em; } table#field_stormnote_attached_values thead { display: none; -} +} */ /* * "SuiteDesk Idea" node form. @@ -1924,21 +1952,21 @@ table#field_stormnote_attached_values thead { #edit-access-public-wrapper, #edit-access-authorised-wrapper { margin: .5em 0; -} +} /* table#field_stormdok_attach_values { margin-top: -0.5em; } table#field_stormdok_attach_values thead { display: none; -} +} */ /* * "SuiteDesk Task & Ticket" comment form. - */ + */ /* table#field_stormtaskc_attach_values thead, table#field_stormticketc_attach_values thead { display: none; -} +} */ #edit-field-stormtaskc-title-0-value, #edit-field-stormticketc-title-0-value { width: 100%;