You are here

function imagecache_asset_formatter in Asset 5.2

Same name and namespace in other branches
  1. 5 modules/asset_imagecache.inc \imagecache_asset_formatter()
  2. 6 modules/asset_imagecache.inc \imagecache_asset_formatter()
  3. 6 inc/modules/asset_imagecache.inc \imagecache_asset_formatter()

File

modules/asset_imagecache.inc, line 21

Code

function imagecache_asset_formatter($op = 'info', $asset = NULL, $attr = array()) {
  switch ($op) {
    case 'info':
      $presets = _imagecache_get_presets();
      foreach ($presets as $id => $name) {
        $formats[$name] = array(
          'name' => $name . ' (imagecache)',
          'description' => _imagecache_asset_description($id),
          'module' => 'imagecache',
        );
      }
      return $formats;
    case 'load':
      if ($asset->type == 'file' && strpos($asset->file['filemime'], 'image/') === 0) {
        $presets = _imagecache_get_presets();
        foreach ($presets as $id => $name) {
          $formats[] = $name;
        }
      }
      return $formats;
    case 'img':
      $path = file_directory_path() . '/imagecache/' . $attr['format'] . '/' . $asset->file['filepath'];
      return $path;
    case 'render':
      $title = $attr['title'] ? $attr['title'] : $asset->title;
      $alt = $attr['alt'] ? $attr['alt'] : $asset->title;
      return theme('imagecache', $attr['format'], $asset->file['filepath'], $alt, $title);
    case 'form':
      $form['alt'] = array(
        '#type' => 'textfield',
        '#title' => t('Alt Text'),
        '#default_value' => $attr['alt'] ? $attr['alt'] : $asset->title,
        '#description' => t('Alt attribute for the image'),
      );
      $form['title'] = array(
        '#type' => 'textfield',
        '#title' => t('Title'),
        '#default_value' => $attr['title'] ? $attr['title'] : $asset->title,
        '#description' => t('Title attribute for the image'),
      );
      $form['wysiwyg'] = array(
        '#type' => 'hidden',
        '#value' => urlencode(file_create_url(file_directory_path() . '/imagecache/' . $attr['format'] . '/' . $asset->file['filepath'])),
      );
      return $form;
  }
}