cvs diff -u -p -- jcarousel_block.module (in directory E:\Eclipse\workspace\PHP\jcarousel_block\) Index: jcarousel_block.module =================================================================== RCS file: /cvs/drupal/contributions/modules/jcarousel_block/jcarousel_block.module,v retrieving revision 1.1.2.8 diff -u -p -r1.1.2.8 jcarousel_block.module --- jcarousel_block.module 26 Sep 2008 06:22:14 -0000 1.1.2.8 +++ jcarousel_block.module 29 Sep 2008 16:14:26 -0000 @@ -23,7 +23,7 @@ function jcarousel_block_admin() { '#type' => 'textfield', '#title' => t('image field name'), '#default_value' => variable_get('jcarousel_block_imagefield_name', ''), - '#description' => t('The block with read the images from the field name inputted here and display them as the jcarousel sideshow. This field cannot be empty. It can be any type of cck image fields, e.g. imceimage, imagefield, filefield, etc. Currently only imceimage and imagefield supported'), + '#description' => t('The block with read the images from the field name inputted here and display them as the jcarousel sideshow. This field cannot be empty. It can be any type of cck image fields, e.g. imceimage, imagefield, filefield, etc. Currently only imceimage and imagefield supported.'), '#required' => TRUE, ); @@ -36,7 +36,7 @@ function jcarousel_block_admin() { '#type' => 'radios', '#title' => t('image source type'), '#default_value' => variable_get('jcarousel_block_imagefield_type', 'imceimage'), - '#description' => t('Put the cck image field type here, so the module knows how to setup the image path, width, height, etc., as the names of the fields can be different for imagefield, fieldfield, imcefield or any other. \'imceimage\' by default, '), + '#description' => t("Put the cck image field type here, so the module knows how to setup the image path, width, height, etc., as the names of the fields can be different for imagefield, fieldfield, imcefield or any other. 'imceimage' by default. "), '#options' => array('imceimage' => 'imceimage', 'imagefield' => 'imagefield', 'directoryimage' => 'directoryimage'), '#required' => TRUE, ); @@ -53,7 +53,7 @@ function jcarousel_block_admin() { '#type' => 'textfield', '#title' => t('imceimage thumbnail prefix'), '#default_value' => variable_get('jcarousel_block_imagefield_imce_prefix', 'thumb_'), - '#description' => t('The prefix set in imce profile, which used to generate the thumbnail '), + '#description' => t('The prefix set in imce profile, which used to generate the thumbnail.'), ); $form['imagefield'] = array( @@ -76,8 +76,8 @@ function jcarousel_block_admin() { '#type' => 'textfield', '#title' => t('image directory pattern'), '#default_value' => variable_get('jcarousel_block_directoryimage_directory', '/pictures/$nid'), - '#description' => t('Put the the directory pattern here. Should be something like /pictures/$nid. $nid is the only possible varaible.'), - ); + '#description' => t('Put the the directory pattern here. Should be something like /pictures/$nid. $nid is the only possible variable.'), + ); $form['directoryimage']['jcarousel_block_directoryimage_prefix'] = array( '#type' => 'textfield', @@ -89,8 +89,8 @@ function jcarousel_block_admin() { $form['jcarousel_block_image_rel'] = array( '#type' => 'textfield', '#title' => t('rel'), - '#default_value' => variable_get('jcarousel_block_image_rel', 'lightbox'), - '#description' => t('Put \'lightbox\' here to enable lightbox, or you may enter the name for another effect.'), + '#default_value' => variable_get('jcarousel_block_image_rel', 'lightbox[mygroup]'), + '#description' => t("Put 'lightbox' here to enable lightbox, or you may enter the name for another effect."), ); //we don't want the user to change the jcarousel_block_block_list_title @@ -114,7 +114,7 @@ function jcarousel_block_admin() { } /** - * implementation of hook_menu + * Implementation of hook_menu(). */ function jcarousel_block_menu() { $items = array(); @@ -131,7 +131,7 @@ function jcarousel_block_menu() { /** - * implementation of hook_block + * Implementation of hook_block(). */ function jcarousel_block_block($op = 'list', $delta = 0, $edit = array()) { $blocks = array(); @@ -146,16 +146,15 @@ function jcarousel_block_block($op = 'li } if (arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2)) { //$is_node = true; - $node = node_load(arg(1)); - if ($node->$field && is_array($node->$field) && count($node->$field)) { // CCK - $blocks['subject'] = variable_get('jcarousel_block_block_title', t('mycarousel')); - $blocks['content'] = theme('jcarousel_block_block'); - } - elseif (variable_get('jcarousel_block_imagefield_type', 'imceimage') == 'directoryimage' && _jcarousel_block_directoryimage_load(arg(1))) { // directoryimage + $imagefield_type = variable_get('jcarousel_block_imagefield_type', 'imceimage'); + module_load_include('inc', 'jcarousel_block', "includes/$imagefield_type"); + + if (jcarousel_block_image_exists(arg(1))) { $blocks['subject'] = variable_get('jcarousel_block_block_title', t('mycarousel')); $blocks['content'] = theme('jcarousel_block_block'); } - else { //no image, do not show + else { + //no image, do not show } } else{ @@ -192,7 +191,7 @@ function jcarousel_block_block($op = 'li } /** - * implementation of hook_theme + * Implementation of hook_theme(). */ function jcarousel_block_theme() { return array( @@ -206,7 +205,7 @@ function jcarousel_block_theme() { /* moduleName_preprocess_hook */ function jcarousel_block_preprocess_jcarousel_block_block(&$variables) { - //print_r($variables); + //print_r($variables); $variables['field'] = check_plain(variable_get('jcarousel_block_imagefield_name', '')); $variables['image_rel'] = check_plain(variable_get('jcarousel_block_image_rel', 'lightbox')); $variables['skin'] = check_plain(variable_get('jcarousel_block_skin', 'ie7')); @@ -216,140 +215,12 @@ function jcarousel_block_preprocess_jcar if (arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2)) { $variables['node'] = node_load(arg(1)); } - else{ + else { return; - } - - if (variable_get('jcarousel_block_imagefield_type', 'imceimage') == 'imceimage') { - _jcarousel_block_preprocess_imceimage($variables); - } - elseif (variable_get('jcarousel_block_imagefield_type', 'imceimage') == 'imagefield') { - _jcarousel_block_preprocess_imagefield($variables); - } - elseif (variable_get('jcarousel_block_imagefield_type', 'imceimage') == 'directoryimage') { - _jcarousel_block_preprocess_directoryimage($variables); - } -} - -function _jcarousel_block_preprocess_imceimage(&$variables) { - $variables['imagefield_type'] = 'imceimage'; - - $node = $variables['node']; - $field_name = $variables['field']; - foreach ($node->$field_name as $key => $image) { - $thumb_prefix = variable_get('jcarousel_block_imagefield_imce_prefix', 'thumb_'); - $thumb_name = $thumb_prefix . basename($image['imceimage_path']); - $thumb_path = dirname($image['imceimage_path']) ."/". $thumb_name; - $root = file_directory_path(); - - $furl = variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE ? url('system/files') : base_path() . file_directory_path(); - - $subdir = str_replace($furl, '', dirname($image['imceimage_path'])); - - $thumb_filepath = $root . $subdir .'/'. $thumb_name; - if (is_file($thumb_filepath)) { // has thumbnail - 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 - //$thumb_path = $thumb_path; - } - else{ // no thumbnail, use original - $imceimage_filepath = $root . $subdir .'/'. basename($image['imceimage_path']); - 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 - $thumb_path = $image['imceimage_path']; - } - $formatted_image = array(); - $formatted_image['path'] = $image['imceimage_path']; - $formatted_image['thumb_path'] = $thumb_path; - $formatted_image['rel'] = $variables['image_rel']; - $formatted_image['width'] = $width; - $formatted_image['height'] = $height; - $formatted_image['alt'] = $image['imceimage_alt']; - $variables['images'][] = $formatted_image; } -} -function _jcarousel_block_preprocess_imagefield(&$variables) { - $variables['imagefield_type'] = 'imagefield'; + $imagefield_type = variable_get('jcarousel_block_imagefield_type', 'imceimage'); + module_load_include('inc', 'jcarousel_block', "includes/$imagefield_type"); - $node = $variables['node']; - $field_name = $variables['field']; - foreach ($node->$field_name as $key => $image) { - $thumb_path = imagefield_file_admin_thumb_path($image); - list($width, $height, $type, $image_attributes) = @getimagesize($thumb_path); - $formatted_image = array(); - $formatted_image['path'] = '/'. $image['filepath']; - $formatted_image['thumb_path'] = '/'. $thumb_path; - $formatted_image['rel'] = $variables['image_rel']; - $formatted_image['width'] = $width; - $formatted_image['height'] = $height; - $formatted_image['alt'] = ''; // todo - $variables['images'][] = $formatted_image; - } + _jcarousel_block_preprocess_images($variables); } - -function _jcarousel_block_directoryimage_load($nid, $show_error = false) { - $files = array(); - - $directory = variable_get('jcarousel_block_directoryimage_directory', '/pictures/$nid'); - $thumb_prefix = variable_get('jcarousel_block_directoryimage_prefix', 'thumb_'); - - $directory = str_replace('$nid', $nid, $directory); - $root = file_directory_path(); - $path = $root . $directory; - if(!is_dir($path)) { - if ($show_error) { - drupal_set_message(t('Error in opening directory:'. $path), 'error'); - } - return $files; - } - - $handle = opendir($path); - - if ($handle = opendir($path)) { - while (false !== ($file = readdir($handle))) { - // need ignore more files here. TODO - if ($file != "." && $file != ".." && $file != "Thumbs.db" && substr($file, 0, strlen($thumb_prefix)) != $thumb_prefix) { - $files[] = $file; - } - } - closedir($handle); - } - return $files; -} - -function _jcarousel_block_preprocess_directoryimage(&$variables) { - $variables['imagefield_type'] = 'directoryimage'; - $node = $variables['node']; - - $files = _jcarousel_block_directoryimage_load($node->nid); - - $directory = variable_get('jcarousel_block_directoryimage_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; - - 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; - } -} -