there could be an option to read images from a file directory

required changes:
configurable directory settings like /pictures/$nid and /pictures/$nid/thumb (or thumb_prefix for thumbnail images)
jcarousel_block_imagefield_type = "directory"
function _jcarousel_block_preprocess_directoryimage()

Comments

pasqualle’s picture

function _jcarousel_block_preprocess_directoryimage(&$variables) {
  $variables['imagefield_type'] = 'directoryimage';
  $node = $variables['node'];

  $directory = variable_get('jcarousel_block_directory', '/pictures/$nid');
  $thumb_prefix = variable_get('jcarousel_block_directoryimage_prefix', 'thumb_');

  $directory = str_replace('$nid', $node->nid, $directory);
  $root = file_directory_path();
  $path = $root . $directory;

  $handle = opendir($path);

  if ($handle = opendir($path)) {
    while (false !== ($file = readdir($handle))) {
      if ($file != "." && $file != ".." && substr($file, 0, strlen($thumb_prefix)) != $thumb_prefix) {
        $files[] = $file;
      }
    }
    closedir($handle);
  }

  foreach ($files as $file) {
    $thumb_filepath = '/'. $path .'/'. $thumb_prefix . $file;
    $image_filepath = '/'. $path .'/'. $file;

    if (is_file($thumb_filepath)) {
      // has thumbnail
      list($width, $height, $type, $image_attributes) = @getimagesize($thumb_filepath);
    }
    else{
      // no thumbnail, use original
      list($width, $height, $type, $image_attributes) = @getimagesize($image_filepath);
    }

    $formatted_image = array();
    $formatted_image['path'] = $image_filepath;
    $formatted_image['thumb_path'] = $thumb_filepath;
    $formatted_image['rel'] = $variables['image_rel'];
    $formatted_image['width'] = $width;
    $formatted_image['height'] = $height;
    $formatted_image['alt'] = '';
    $variables['images'][] = $formatted_image;
  }
}
pasqualle’s picture

Status: Active » Needs review

note1:
the cck dependency and the line 124

if ($node->$field && is_array($node->$field) && count($node->$field))

in jcarousel_block.module must be removed to work with directoryimage

note2:
there could be a simple plugin system like

$imagefield_type = variable_get('jcarousel_block_imagefield_type', 'imceimage');
module_load_include('inc', 'jcarousel_block', $imagefield_type);

imceimage.inc
imagefield.inc
directoryimage.inc

and all should have an equally named jcarousel_block_preprocess_image(&$variables) function, and any other function necessary.
this way it would be possible to add new types without altering the main module files..

yang_yi_cn’s picture

thanks for your contribution! I'll test it and add to the release.

yang_yi_cn’s picture

Status: Needs review » Fixed

I've added the directoryimage support. Released as 1.4.

A few questions:
1. Is the '/pictures/$nid' pattern used by any other module? How should we expect the user to upload images under this pattern?
2. About the plug-in system, I'm thinking about it. However I would need not just the jcarousel_block_preprocess_image() function, but also some other functions such as empty check, and admin settings, which might take sometime. Please create another bug for that feature, so I can close this bug here.

pasqualle’s picture

1.
a) I am not sure. It was just my first idea how to name the directory. it should be something like the pathauto settings..
b) imce, ftp or custom module.

2. agreed #313835: create a simple plugin functionality to easily swap the image system

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.