/[drupal]/contributions/modules/jcarousel_block/jcarousel_block.module
ViewVC logotype

Diff of /contributions/modules/jcarousel_block/jcarousel_block.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.8, Fri Sep 26 06:22:14 2008 UTC revision 1.1.2.9, Tue Oct 28 22:12:09 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: jcarousel_block.module,v 1.1.2.7 2008/09/26 06:04:19 yangyicn Exp $  // $Id: jcarousel_block.module,v 1.1.2.8 2008/09/26 06:22:14 yangyicn Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 23  function jcarousel_block_admin() { Line 23  function jcarousel_block_admin() {
23      '#type' => 'textfield',      '#type' => 'textfield',
24      '#title' => t('image field name'),      '#title' => t('image field name'),
25      '#default_value' => variable_get('jcarousel_block_imagefield_name', ''),      '#default_value' => variable_get('jcarousel_block_imagefield_name', ''),
26      '#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.'),
27      '#required' => TRUE,      '#required' => TRUE,
28    );    );
29    
30    $form['jcarousel_block_imagefield_type'] = array(    $form['jcarousel_block_imagefield_type'] = array(
 //    '#type' => 'textfield',  
 //    '#title' => t('image field 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, '),  
 //    '#required' => TRUE,  
31      '#type' => 'radios',      '#type' => 'radios',
32      '#title' => t('image source type'),      '#title' => t('image source type'),
33      '#default_value' => variable_get('jcarousel_block_imagefield_type', 'imceimage'),      '#default_value' => variable_get('jcarousel_block_imagefield_type', 'imceimage'),
34      '#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. "),
35      '#options' => array('imceimage' => 'imceimage', 'imagefield' => 'imagefield', 'directoryimage' => 'directoryimage'),      '#options' => array('imceimage' => 'imceimage', 'imagefield' => 'imagefield', 'directoryimage' => 'directoryimage'),
36      '#required' => TRUE,      '#required' => TRUE,
37    );    );
# Line 53  function jcarousel_block_admin() { Line 48  function jcarousel_block_admin() {
48      '#type' => 'textfield',      '#type' => 'textfield',
49      '#title' => t('imceimage thumbnail prefix'),      '#title' => t('imceimage thumbnail prefix'),
50      '#default_value' => variable_get('jcarousel_block_imagefield_imce_prefix', 'thumb_'),      '#default_value' => variable_get('jcarousel_block_imagefield_imce_prefix', 'thumb_'),
51      '#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.'),
52    );    );
53    
54    $form['imagefield'] = array(    $form['imagefield'] = array(
# Line 76  function jcarousel_block_admin() { Line 71  function jcarousel_block_admin() {
71      '#type' => 'textfield',      '#type' => 'textfield',
72      '#title' => t('image directory pattern'),      '#title' => t('image directory pattern'),
73      '#default_value' => variable_get('jcarousel_block_directoryimage_directory', '/pictures/$nid'),      '#default_value' => variable_get('jcarousel_block_directoryimage_directory', '/pictures/$nid'),
74      '#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.'),
75    );    );
76    
77    $form['directoryimage']['jcarousel_block_directoryimage_prefix'] = array(    $form['directoryimage']['jcarousel_block_directoryimage_prefix'] = array(
78      '#type' => 'textfield',      '#type' => 'textfield',
# Line 89  function jcarousel_block_admin() { Line 84  function jcarousel_block_admin() {
84    $form['jcarousel_block_image_rel'] = array(    $form['jcarousel_block_image_rel'] = array(
85      '#type' => 'textfield',      '#type' => 'textfield',
86      '#title' => t('rel'),      '#title' => t('rel'),
87      '#default_value' => variable_get('jcarousel_block_image_rel', 'lightbox'),      '#default_value' => variable_get('jcarousel_block_image_rel', 'lightbox[mygroup]'),
88      '#description' => t('Put \'lightbox\' here to enable lightbox, or you may enter the name for another effect.'),      '#description' => t("Put 'lightbox' here to enable lightbox, or you may enter the name for another effect."),
89    );    );
90    
91    //we don't want the user to change the jcarousel_block_block_list_title    //we don't want the user to change the jcarousel_block_block_list_title
# Line 114  function jcarousel_block_admin() { Line 109  function jcarousel_block_admin() {
109  }  }
110    
111  /**  /**
112   * implementation of hook_menu   * Implementation of hook_menu().
113   */   */
114  function jcarousel_block_menu() {  function jcarousel_block_menu() {
115    $items = array();    $items = array();
# Line 129  function jcarousel_block_menu() { Line 124  function jcarousel_block_menu() {
124    return $items;    return $items;
125  }  }
126    
   
127  /**  /**
128   * implementation of hook_block   * Implementation of hook_block().
129   */   */
130  function jcarousel_block_block($op = 'list', $delta = 0, $edit = array()) {  function jcarousel_block_block($op = 'list', $delta = 0, $edit = array()) {
131    $blocks = array();    $blocks = array();
# Line 146  function jcarousel_block_block($op = 'li Line 140  function jcarousel_block_block($op = 'li
140      }      }
141      if (arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2)) {      if (arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2)) {
142        //$is_node = true;        //$is_node = true;
143        $node = node_load(arg(1));        $imagefield_type = variable_get('jcarousel_block_imagefield_type', 'imceimage');
144        if ($node->$field && is_array($node->$field) && count($node->$field)) { // CCK        module_load_include('inc', 'jcarousel_block', "includes/$imagefield_type");
145          $blocks['subject'] = variable_get('jcarousel_block_block_title', t('mycarousel'));  
146          $blocks['content'] = theme('jcarousel_block_block');        $jcarousel_block_PLUGIN_exists = 'jcarousel_block_'. $imagefield_type .'_exists';
147        }        if ($jcarousel_block_PLUGIN_exists(arg(1))) {
       elseif (variable_get('jcarousel_block_imagefield_type', 'imceimage') == 'directoryimage' && _jcarousel_block_directoryimage_load(arg(1))) { // directoryimage  
148          $blocks['subject'] = variable_get('jcarousel_block_block_title', t('mycarousel'));          $blocks['subject'] = variable_get('jcarousel_block_block_title', t('mycarousel'));
149          $blocks['content'] = theme('jcarousel_block_block');          $blocks['content'] = theme('jcarousel_block_block');
150        }        }
151        else {        //no image, do not show        else {
152            //no image, do not show
153        }        }
154      }      }
155      else{      else{
# Line 192  function jcarousel_block_block($op = 'li Line 186  function jcarousel_block_block($op = 'li
186  }  }
187    
188  /**  /**
189   * implementation of hook_theme   * Implementation of hook_theme().
190   */   */
191  function jcarousel_block_theme() {  function jcarousel_block_theme() {
192    return array(    return array(
# Line 206  function jcarousel_block_theme() { Line 200  function jcarousel_block_theme() {
200    
201  /* moduleName_preprocess_hook */  /* moduleName_preprocess_hook */
202  function jcarousel_block_preprocess_jcarousel_block_block(&$variables) {  function jcarousel_block_preprocess_jcarousel_block_block(&$variables) {
203    //print_r($variables);    //print_r($variables);
204    $variables['field'] = check_plain(variable_get('jcarousel_block_imagefield_name', ''));    $variables['field'] = check_plain(variable_get('jcarousel_block_imagefield_name', ''));
205    $variables['image_rel'] = check_plain(variable_get('jcarousel_block_image_rel', 'lightbox'));    $variables['image_rel'] = check_plain(variable_get('jcarousel_block_image_rel', 'lightbox'));
206    $variables['skin'] = check_plain(variable_get('jcarousel_block_skin', 'ie7'));    $variables['skin'] = check_plain(variable_get('jcarousel_block_skin', 'ie7'));
# Line 216  function jcarousel_block_preprocess_jcar Line 210  function jcarousel_block_preprocess_jcar
210    if (arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2)) {    if (arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2)) {
211      $variables['node'] = node_load(arg(1));      $variables['node'] = node_load(arg(1));
212    }    }
213    else{    else {
214      return;      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);  
215    }    }
 }  
216    
217  function _jcarousel_block_preprocess_imceimage(&$variables) {    // do imagefield type specific preprocess actions
218    $variables['imagefield_type'] = 'imceimage';    $imagefield_type = variable_get('jcarousel_block_imagefield_type', 'imceimage');
219      module_load_include('inc', 'jcarousel_block', "includes/$imagefield_type");
220    
221    $node = $variables['node'];    $_jcarousel_block_PLUGIN_preprocess_images = 'jcarousel_block_'. $imagefield_type .'_preprocess_images';
   $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;  
   }  
 }  
222    
223  function _jcarousel_block_preprocess_imagefield(&$variables) {    $_jcarousel_block_PLUGIN_preprocess_images($variables);
   $variables['imagefield_type'] = 'imagefield';  
   
   $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;  
   }  
224  }  }
   
 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;  
   }  
 }  
   

Legend:
Removed from v.1.1.2.8  
changed lines
  Added in v.1.1.2.9

  ViewVC Help
Powered by ViewVC 1.1.2