[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/image_fupload/image_fupload_imagefield/ -> image_fupload_imagefield_widget.inc (source)

   1  <?php
   2  
   3  /**
   4   * @file
   5   * Image Fupload ImageField widget hooks and callbacks.
   6   *
   7   * This file is loaded by filefield.module/imagefield.module and the callbacks it contains are
   8   * invoked by filefield.module. This happens because imagefield delegates it's
   9   * CCK hooks and callbacks to filefield in imagefield.module.
  10   *
  11   * This file is mainly based on imagefield_widget.inc (D6 3.0-rc1)
  12   */
  13   
  14  module_load_include('inc', 'imagefield', 'imagefield_widget');
  15  
  16  /**
  17   * Implementation of hook_widget_settings($op = 'form')
  18   */
  19  function image_fupload_imagefield_widget_settings_form($widget) {
  20    $form = module_invoke('imagefield', 'widget_settings_form', $widget);
  21    $node_type = str_replace("-", "_", arg(3));
  22    
  23    // warn user to only use this widget once per node type  
  24    if (!isset($widget['fupload_mode']))
  25      drupal_set_message(t("Image FUpload widget can only be used <u>once</u> per node type.<br />If this is a second field using image fupload based on the same node type, it's adviced to delete this field, reconfigure the other one and create a new one without image fupload widget."), 'warning');
  26      
  27    $form['fupload_mode'] = array(
  28      '#type' => 'radios',
  29      '#title' => t('Storage mode'),
  30      '#description' => t("First option creates one complete node per uploaded image. This is useful if you have to store a lot of other information beside the image (for example other CCK fields or several Taxonomy items per image).<br /> Second option stores multiple images per node. This is useful if you want to create simple galleries.<br /><b>Don't forget</b> to set <i>'Number of values'</i> to a sufficient value in <i>'Global settings'</i>. This will define the number of images which can be uploaded per upload session."),
  31      '#default_value' => !empty($widget['fupload_mode']) ? $widget['fupload_mode'] : '',
  32      '#options' => array('single' => t('One image per node'), 'multiple' => t('Multiple images per node')),
  33      '#weight' => -10,
  34      '#required' => TRUE,
  35    );
  36    
  37    $form['fupload_previewlist'] = array(
  38      '#type' => 'fieldset',
  39      '#title' => t('Images preview list'),
  40      '#description' => t('This feature adds the ability to show a list of all images after having uploaded them. At the same time, all title and body fields can be edited all at once.<br /> In order to use it, it has to be activated separately per !admin-permissions.', array('!admin-permissions' => l(t('user role'), 'admin/user/permissions'))),
  41      '#collapsible' => TRUE,
  42      '#weight' => 3,
  43    );
  44    $form['fupload_previewlist']['fupload_previewlist_img'] = array(
  45      '#type' => 'select',
  46      '#title' => t('Preview Image Preset'),
  47      '#description' => t("This setting is responsible for the way of displaying and handling the preview image which is generated out of the original image. ImageCache module has to be installed and a preset has to be created which can be selected right here, in order to make it work."),
  48      '#options' => _fupload_imagepreview_settings('list', $node_type), // @str_replace: returns correct node type
  49      '#default_value' => _fupload_imagepreview_settings('read', $node_type),
  50      '#required' => TRUE,
  51    );
  52    $form['fupload_previewlist']['fupload_previewlist_img_attributes'] = array(
  53      '#type' => 'textfield',
  54      '#title' => t('Image Attributes'),
  55      '#description' => t('Provide some additional attributes to be integrated in image (preview) tag, for example: class="my_custom_css"'),
  56      '#default_value' => !empty($widget['fupload_previewlist_img_attributes']) ? $widget['fupload_previewlist_img_attributes'] : '',
  57    );
  58    $form['fupload_previewlist']['field_settings'] = array(
  59      '#type' => 'fieldset',
  60      '#title' => t('Field settings'),
  61      '#collapsible' => TRUE,
  62      '#collapsed' => FALSE,
  63    );
  64    $form['fupload_previewlist']['field_settings']['fupload_previewlist_field_settings'] = array(
  65      '#type' => 'checkboxes',
  66      '#title' => t('Editable fields'),
  67      '#description' => t('Choose the fields which should be editable by the uploader. Note that depending on the storage mode, it is not possible to choose some fields.') .'<p>'.t('<strong>Important information:</strong><br /> If the body is not editable by the user, <em>"minimum number of words"</em> !setting for the body field has to be <strong>0</strong>.', array('!setting' => l(t('setting'), 'admin/content/node-type/image'))).'</p>',
  68      '#options' => _image_fupload_previewlist_captions($node_type, arg(5)), 
  69      '#default_value' => !empty($widget['fupload_previewlist_field_settings']) ? $widget['fupload_previewlist_field_settings'] : array(),
  70    );
  71    $form['fupload_previewlist_redirecturl'] = array(
  72      '#type' => 'textfield',
  73      '#title' => t('Redirect url'),
  74      '#description' => t("After having uploaded some images, the user will redirected to newly created node (multiple storage mode) or node creation page (single storage mode) by default.<br />Providing an alternative url, user will be redirected to the entered url. Syntax (Drupals url function): \"node/add\""),
  75      '#default_value' => !empty($widget['fupload_previewlist_redirecturl']) ? $widget['fupload_previewlist_redirecturl'] : '',
  76    );
  77    $form['fupload_title_replacements'] = array(
  78      '#type' => 'textfield',
  79      '#title' => t('Image title processor'),
  80      '#description' => t('All entered elements which have to be separated by a semicolon (";"), are replaced by a whitespace when the node title is created out of the original image filename.')
  81        .'<p>'. t('<em>Note:</em> The theme function "fupload_create_filename" can be overwritten to provide a customised title creation.') .'</p>',
  82      '#default_value' => !empty($widget['fupload_title_replacements']) ? $widget['fupload_title_replacements'] : '_;{;};-',
  83      '#weight' => 3,
  84      '#required' => TRUE,
  85    ); 
  86    
  87    return $form;
  88  }
  89  
  90  /**
  91   * Implementation of hook_widget_settings($op = 'save').
  92   */
  93  function image_fupload_imagefield_widget_settings_save($widget) {
  94    // elements which should be saved for this field (settings)
  95    $settings = array('fupload_mode', 'fupload_previewlist_img_attributes', 'fupload_title_replacements', 'fupload_previewlist_field_settings', 'fupload_previewlist_redirecturl');
  96    _fupload_imagepreview_settings('write', $widget['type_name'], array('fieldname' => $widget['field_name'], 'preview_preset' => $widget['fupload_previewlist_img']));
  97    
  98    return array_merge(module_invoke('imagefield', 'widget_settings_save', $widget), $settings);  
  99  }
 100  
 101  /**
 102  * Implementation of hook_widget_settings($op = 'validate').
 103   */
 104  function image_fupload_imagefield_widget_settings_validate($widget) {
 105    module_invoke('imagefield', 'widget_settings_validate', $widget);
 106    // check some dependencies
 107    if (isset($widget['fupload_mode']) && $widget['fupload_mode'] == "multiple") {
 108      $allowed_fields = array('imagefield_title', 'imagefield_alt', 'imagefield_description');
 109      foreach ($widget['fupload_previewlist_field_settings'] as $key) {
 110        if (!in_array($key, $allowed_fields))
 111          form_set_error('fupload_previewlist_field_settings_' .$key, t('It is not possible to support a "@field" field (Field settings) in current storage mode. Disable this checkbox in order to continue.', array('@field' => $widget['fupload_previewlist_field_settings'][$key])));
 112      }
 113    } 
 114    return array();
 115  }
 116  
 117  /**
 118   * @} End defgroup "FileField widget element callbacks."
 119   */
 120  
 121  /**
 122  * Helper function
 123  * Creates a list of CCK fields depending on node type
 124  */
 125   
 126  function _image_fupload_previewlist_captions($node_type, $field_name) {
 127    $options = array('node_title' => t('Title (Node)'), 'node_description' => t('Description (Node)'), 'imagefield_title' => t('Title (ImageField)'), 'imagefield_alt' => t('Alt (ImageField)'), 'imagefield_description' => t('Description (ImageField)'));
 128    if (module_exists('taxonomy')) {
 129      // also include taxonomy in list
 130      foreach (taxonomy_get_vocabularies($node_type) as $term)    
 131        $options['taxonomy_' .$term->vid] = $term->name .' (Taxonomy)';
 132    }
 133    
 134    $fields = content_types($node_type);  
 135    foreach ($fields['fields'] as $field) {
 136      if ($field['field_name'] != $field_name)
 137        $options['cck_' .$field['field_name']] = $field['widget']['label'] .' (CCK)';
 138    }
 139    return $options;
 140  }
 141   
 142  /**
 143   * FormAPI theme function. Theme the output of an image field.
 144   */
 145  function theme_image_fupload_imagefield_widget(&$element) {
 146    return theme('form_element', $element, $element['#children']);
 147  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7