| 1 |
|
<?php |
| 2 |
|
// $Id$ |
| 3 |
|
|
| 4 |
|
/** |
| 5 |
|
* @file |
| 6 |
|
* directoryimage plugin. |
| 7 |
|
*/ |
| 8 |
|
// Implementation of jcarousel_block_PLUGIN_exists |
| 9 |
|
function jcarousel_block_direcotryimage_exists($nid) { |
| 10 |
|
return _jcarousel_block_directoryimage_load($nid); |
| 11 |
|
} |
| 12 |
|
|
| 13 |
|
// Implementation of _jcarousel_block_PLUGIN_preprocess_images |
| 14 |
|
function _jcarousel_block_direcotryimage_preprocess_images(&$variables) { |
| 15 |
|
$variables['imagefield_type'] = 'directoryimage'; |
| 16 |
|
|
| 17 |
|
$files = _jcarousel_block_directoryimage_load($variables['node']->nid); |
| 18 |
|
|
| 19 |
|
$thumb_prefix = variable_get('jcarousel_block_directoryimage_prefix', 'thumb_'); |
| 20 |
|
|
| 21 |
|
foreach ($files as $key => $file) { |
| 22 |
|
if (substr($key, 0, strlen($thumb_prefix)) == $thumb_prefix) { |
| 23 |
|
// It's a thumbnail image. |
| 24 |
|
continue; |
| 25 |
|
} |
| 26 |
|
|
| 27 |
|
$image_filepath = $files[$key]->filename; |
| 28 |
|
if (isset($files[$thumb_prefix . $key])) { |
| 29 |
|
// Thumbnail image exists. |
| 30 |
|
$thumb_filepath = $files[$thumb_prefix . $key]->filename; |
| 31 |
|
} |
| 32 |
|
else { |
| 33 |
|
// Thumbnail image does not exists, use the original image. |
| 34 |
|
$thumb_filepath = $image_filepath; |
| 35 |
|
} |
| 36 |
|
|
| 37 |
|
list($width, $height, $type, $image_attributes) = getimagesize($thumb_filepath); |
| 38 |
|
|
| 39 |
|
$formatted_image = array(); |
| 40 |
|
$formatted_image['path'] = base_path() . $image_filepath; |
| 41 |
|
$formatted_image['thumb_path'] = base_path() . $thumb_filepath; |
| 42 |
|
$formatted_image['rel'] = $variables['image_rel']; |
| 43 |
|
$formatted_image['width'] = $width; |
| 44 |
|
$formatted_image['height'] = $height; |
| 45 |
|
$formatted_image['alt'] = ''; |
| 46 |
|
$variables['images'][] = $formatted_image; |
| 47 |
|
} |
| 48 |
|
} |
| 49 |
|
|
| 50 |
|
function _jcarousel_block_directoryimage_load($nid, $show_error = false) { |
| 51 |
|
$directory = variable_get('jcarousel_block_directoryimage_directory', '/pictures/$nid'); |
| 52 |
|
$directory = str_replace('$nid', $nid, $directory); |
| 53 |
|
|
| 54 |
|
$path = file_directory_path() . $directory; |
| 55 |
|
if(!is_dir($path)) { |
| 56 |
|
if ($show_error) { |
| 57 |
|
drupal_set_message(t('Error opening directory: %path', array('%path' => $path)), 'error'); |
| 58 |
|
} |
| 59 |
|
return array(); |
| 60 |
|
} |
| 61 |
|
|
| 62 |
|
$files = file_scan_directory($path, '\.(png|jpg|gif)$', array('.', '..', 'CVS'), 0, FALSE, 'basename'); |
| 63 |
|
|
| 64 |
|
return $files; |
| 65 |
|
} |
| 66 |
|
|