You are here

function _fupload_imagepreview_settings in Image FUpload 6.3

Same name and namespace in other branches
  1. 6 image_fupload_image/image_fupload_image.admin.inc \_fupload_imagepreview_settings()
  2. 6.2 image_fupload_image/image_fupload_image.admin.inc \_fupload_imagepreview_settings()

This helper function lists/read/write/delete special settings for the image previewlist depending on the node type

Parameters

string $op:

string $node_type:

array $data_write:

Return value

array or NULL

5 calls to _fupload_imagepreview_settings()
image_fupload_imagefield_content_fieldapi in image_fupload_imagefield/image_fupload_imagefield.module
Interact on changes to CCK ImageFields.
image_fupload_imagefield_widget_settings_form in image_fupload_imagefield/image_fupload_imagefield_widget.inc
Implementation of hook_widget_settings($op = 'form')
image_fupload_imagefield_widget_settings_save in image_fupload_imagefield/image_fupload_imagefield_widget.inc
Implementation of hook_widget_settings($op = 'save').
image_fupload_image_admin in image_fupload_image/image_fupload_image.admin.inc
@file
image_fupload_image_admin_submit in image_fupload_image/image_fupload_image.admin.inc

File

./image_fupload.module, line 296

Code

function _fupload_imagepreview_settings($op, $node_type, $data_write = NULL) {

  // switch to the right operation: what's up?
  switch ($op) {
    case 'list':

      // generate a list of available presets for image_preview: image module or/and imagecache
      $preview_presets_list = array();

      // image module presets
      if (module_exists('image') && $node_type == "image") {
        $image_sizes = image_get_sizes();
        foreach ($image_sizes as $key => $size) {
          $preview_presets_list['image']['0_' . $key] = t('Image size') . ': ' . $size['label'];
        }
      }

      // imagecache module presets
      if (module_exists('imagecache')) {
        $image_sizes = imagecache_presets();
        foreach ($image_sizes as $key => $size) {
          $preview_presets_list['imagecache']['1_' . $size['presetname']] = t('Image size') . ': ' . $size['presetname'];
        }
      }

      //output list
      return $preview_presets_list;
      break;
    case 'read':

      // read actual setting for this node type
      $image_node_types = variable_get('image_node_types', array());
      switch ($node_type) {
        case 'image':

          // image node type
          if (!empty($image_node_types['image']['image_selection'])) {

            // image module preset
            return '0_' . $image_node_types['image']['image_selection'];
          }
          elseif (!empty($image_node_types['image']['imagecache_preset'])) {

            // imagecache module preset
            return '1_' . $image_node_types['image']['imagecache_preset'];
          }
          else {

            // no setting saved yet?
            return '';
          }
          break;
        default:

          // node type with CCK ImageField
          // return imagecache preset
          return '1_' . $image_node_types[$node_type]['imagecache_preset'];
          break;
      }
      break;
    case 'write':
      if (isset($data_write)) {

        // is some data available?
        // write input data to database
        $image_node_types = variable_get('image_node_types', array());

        // prepare type of image preview before writing into db
        $preview_preset = explode('_', $data_write['preview_preset'], 2);
        switch ($preview_preset[0]) {
          case '0':

            // image module preset
            $preview_preset_image = $preview_preset[1];
            break;
          case '1':

            // imagecache module preset
            $preview_preset_imagecache = $preview_preset[1];
            break;
        }
        switch ($node_type) {
          case 'image':

            // image node type
            $image_node_types['image'] = array(
              'type' => 'image',
              'fieldname' => 'images',
              'image_selection' => $preview_preset_image,
              'imagecache_preset' => $preview_preset_imagecache,
            );
            break;
          default:

            // node type with CCK ImageField
            $image_node_types[$node_type] = array(
              'type' => 'cck',
              'fieldname' => $data_write['fieldname'],
              'image_selection' => $preview_preset_image,
              'imagecache_preset' => $preview_preset_imagecache,
            );
            break;
        }

        // write data to database
        variable_set('image_node_types', $image_node_types);
      }
      break;
    case 'delete':

      // delete an entry from settings variable
      $image_node_types = variable_get('image_node_types', array());
      unset($image_node_types[$node_type]);

      // write data to database
      variable_set('image_node_types', $image_node_types);
      break;
  }
}