| 1 |
|
<?php |
| 2 |
|
// $Id$ |
| 3 |
|
|
| 4 |
|
/** |
| 5 |
|
* @file |
| 6 |
|
* imceimage plugin. |
| 7 |
|
*/ |
| 8 |
|
|
| 9 |
|
// Implementation of jcarousel_block_PLUGIN_exists |
| 10 |
|
function jcarousel_block_imceimage_exists($nid) { |
| 11 |
|
$field = variable_get('jcarousel_block_imagefield_name', 'imceimage'); |
| 12 |
|
$field_type = variable_get('jcarousel_block_imagefield_type', 'imceimage'); |
| 13 |
|
|
| 14 |
|
$node = node_load($nid); |
| 15 |
|
if (!$node) { |
| 16 |
|
return false; |
| 17 |
|
} |
| 18 |
|
else if (!$node->$field) { |
| 19 |
|
return false; |
| 20 |
|
} |
| 21 |
|
else if (!is_array($node->$field)) { |
| 22 |
|
return false; |
| 23 |
|
} |
| 24 |
|
else if (!count($node->$field)) { |
| 25 |
|
return false; |
| 26 |
|
} |
| 27 |
|
else { |
| 28 |
|
$field_content = $node->$field; |
| 29 |
|
if (!$field_content[0]['imceimage_path']) { |
| 30 |
|
return false; |
| 31 |
|
} |
| 32 |
|
} |
| 33 |
|
|
| 34 |
|
return true; |
| 35 |
|
} |
| 36 |
|
|
| 37 |
|
// Implementation of _jcarousel_block_PLUGIN_preprocess_images |
| 38 |
|
function _jcarousel_block_imceimage_preprocess_images(&$variables) { |
| 39 |
|
$variables['imagefield_type'] = 'imceimage'; |
| 40 |
|
|
| 41 |
|
$node = $variables['node']; |
| 42 |
|
$field_name = $variables['field']; |
| 43 |
|
foreach ($node->$field_name as $key => $image) { |
| 44 |
|
$thumb_prefix = variable_get('jcarousel_block_imagefield_imce_prefix', 'thumb_'); |
| 45 |
|
$thumb_name = $thumb_prefix . basename($image['imceimage_path']); |
| 46 |
|
$thumb_path = dirname($image['imceimage_path']) ."/". $thumb_name; |
| 47 |
|
$root = file_directory_path(); |
| 48 |
|
|
| 49 |
|
$furl = variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE ? url('system/files') : base_path() . file_directory_path(); |
| 50 |
|
|
| 51 |
|
$subdir = str_replace($furl, '', dirname($image['imceimage_path'])); |
| 52 |
|
|
| 53 |
|
$thumb_filepath = $root . $subdir .'/'. $thumb_name; |
| 54 |
|
if (is_file($thumb_filepath)) { // has thumbnail |
| 55 |
|
list($width, $height, $type, $image_attributes) = @getimagesize($thumb_filepath); //use the filepath instead of url for getimagesize(), because sometimes there is problem with open imagefile from a url |
| 56 |
|
//$thumb_path = $thumb_path; |
| 57 |
|
} |
| 58 |
|
else{ // no thumbnail, use original |
| 59 |
|
$imceimage_filepath = $root . $subdir .'/'. basename($image['imceimage_path']); |
| 60 |
|
list($width, $height, $type, $image_attributes) = @getimagesize($imceimage_filepath); //use the filepath instead of url getimagesize(), because sometimes there is problem with open imagefile from a url |
| 61 |
|
$thumb_path = $image['imceimage_path']; |
| 62 |
|
} |
| 63 |
|
$formatted_image = array(); |
| 64 |
|
$formatted_image['path'] = $image['imceimage_path']; |
| 65 |
|
$formatted_image['thumb_path'] = $thumb_path; |
| 66 |
|
$formatted_image['rel'] = $variables['image_rel']; |
| 67 |
|
$formatted_image['width'] = $width; |
| 68 |
|
$formatted_image['height'] = $height; |
| 69 |
|
$formatted_image['alt'] = $image['imceimage_alt']; |
| 70 |
|
$variables['images'][] = $formatted_image; |
| 71 |
|
} |
| 72 |
|
} |