usage without cck

Pasqualle - September 7, 2008 - 12:00
Project:jcarousel block
Version:6.x-1.3
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

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()

#1

Pasqualle - September 26, 2008 - 02:48

<?php
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;
  }
}
?>

#2

Pasqualle - September 26, 2008 - 03:04
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

<?php
$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..

#3

yang_yi_cn - September 26, 2008 - 04:51

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

#4

yang_yi_cn - September 26, 2008 - 06:32
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.

#5

Pasqualle - September 26, 2008 - 13:12

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

#6

Anonymous (not verified) - October 10, 2008 - 13:13
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.