Index: slideshowbox.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/slideshowbox/slideshowbox.module,v
retrieving revision 1.1
diff -u -p -r1.1 slideshowbox.module
--- slideshowbox.module	5 Dec 2006 10:58:52 -0000	1.1
+++ slideshowbox.module	3 Oct 2007 16:08:32 -0000
@@ -63,8 +63,12 @@ function slideshowbox_admin_settings() {
   // we need the version for backwards compatiblity
   $newVersion = (substr(VERSION, 0, 1) > 4 ? 1 : 0);
 
-  $form['slideshowbox_block_title'] = array(
-    '#type' => 'select',
+  $form['theme'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Theme settings'),
+  );
+  $form['theme']['slideshowbox_block_title'] = array(
+    '#type' => 'radios',
     '#title' => t('Show block title'),
     '#description' => t('Select yes if you want to show the block title.'),
     '#options' => array(
@@ -74,8 +78,30 @@ function slideshowbox_admin_settings() {
     '#default_value' => variable_get('slideshowbox_block_title', 1),
   );
 
-  $form['slideshowbox_own_style'] = array(
-    '#type' => 'select',
+  $form['theme']['slideshowbox_image_info'] = array(
+    '#type' => 'radios',
+    '#title' => t('Show image information'),
+    '#description' => t('Select whether to show or hide the title and description (if set) of each image.'),
+    '#options' => array(
+      1 => t('Show'),
+      0 => t('Hide'),
+    ),
+    '#default_value' => variable_get('slideshowbox_image_info', 1),
+  );
+
+  $form['theme']['slideshowbox_image_link'] = array(
+    '#type' => 'radios',
+    '#title' => t('Link to image node'),
+    '#description' => t('Choose whether slideshow images should link to their corresponding image nodes.'),
+    '#options' => array(
+      1 => t('Yes'),
+      0 => t('No'),
+    ),
+    '#default_value' => variable_get('slideshowbox_image_link', 1),
+  );
+
+  $form['theme']['slideshowbox_own_style'] = array(
+    '#type' => 'radios',
     '#title' => t('Use own style file'),
     '#description' => t('Select yes if you want to use your own style file.'),
     '#options' => array(
@@ -85,25 +111,30 @@ function slideshowbox_admin_settings() {
     '#default_value' => variable_get('slideshowbox_own_style', 0),
   );
 
-  $form['slideshowbox_theme'] = array(
+  $themes = file_scan_directory(drupal_get_path('module', 'slideshowbox') .'/slideshowbox/css', '.*.css', array('.', '..', 'CVS'), 0, TRUE);
+  $options_theme = array();
+  foreach ($themes as $file => $v) {
+    $dir = basename(dirname($file));
+    $options_theme[$dir] = $dir;
+  }
+  $form['theme']['slideshowbox_theme'] = array(
     '#type' => 'select',
     '#title' => t('Select a theme'),
     '#description' => t('Select a theme for the slideshow.'),
-    '#options' => array(
-      'black' => t('Black'),
-      'white' => t('White'),
-      'blue' => t('Blue'),
-      'green' => t('Green'),
-    ),
+    '#options' => $options_theme,
     '#default_value' => variable_get('slideshowbox_theme', 'black'),
   );
 
-  $form['slideshowbox_max_images'] = array(
+  $form['images'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Image configuration'),
+  );
+  $form['images']['slideshowbox_max_images'] = array(
     '#type' => 'textfield',
     '#title' => t('Max image count'),
     '#description' => t('Max count of images in a slideshow.'),
     '#default_value' => variable_get('slideshowbox_max_images', 10),
-    '#size' => 60,
+    '#size' => 4,
     '#maxlength' => 4,
     '#required' => TRUE,
     '#validate' => array('slideshowbox_form_validate' => array()),
@@ -112,7 +143,7 @@ function slideshowbox_admin_settings() {
     ),
   );
 
-  $form['slideshowbox_term'] = array(
+  $form['images']['slideshowbox_term'] = array(
     '#type' => 'select',
     '#title' => t('Image term'),
     '#description' => t('Select one term which should be use to show images.'),
@@ -120,7 +151,19 @@ function slideshowbox_admin_settings() {
     '#default_value' => variable_get('slideshowbox_term', ''),
   );
   
-  $form['slideshowbox_type'] = array(
+  $options_size = array('_original' => '_original');
+  foreach (_image_get_sizes() as $preset) {
+    $options_size[$preset['label']] = $preset['label'] .' ('. $preset['width'] .'x'. $preset['height'] .')';
+  }
+  $form['images']['slideshowbox_image_size'] = array(
+    '#type' => 'select',
+    '#title' => t('Image size'),
+    '#description' => t('Select an image size to display images in.'),
+    '#options' => $options_size,
+    '#default_value' => variable_get('slideshowbox_image_size', '_original'),
+  );
+  
+  $form['images']['slideshowbox_type'] = array(
     '#type' => 'select',
     '#title' => t('Slideshow type'),
     '#description' => t('Select the type of the slideshow. Timed = automatic image rotation. Gallery = next image through navigation.'),
@@ -132,8 +175,8 @@ function slideshowbox_admin_settings() {
     '#default_value' => variable_get('slideshowbox_type', 'timed'),
   );
 
-  $form['slideshowbox_random'] = array(
-    '#type' => 'select',
+  $form['images']['slideshowbox_random'] = array(
+    '#type' => 'radios',
     '#title' => t('Randomized'),
     '#description' => t('Select if the images should be randomized load on page entery. Standard = Yes.'),
     '#options' => array(
@@ -146,7 +189,7 @@ function slideshowbox_admin_settings() {
     ),
   );
 
-  $form['slideshowbox_sort'] = array(
+  $form['images']['slideshowbox_sort'] = array(
     '#type' => 'select',
     '#title' => t('Image sort'),
     '#description' => t(''),
@@ -162,7 +205,7 @@ function slideshowbox_admin_settings() {
     ),
   );
   
-  $form['slideshowbox_sort_order'] = array(
+  $form['images']['slideshowbox_sort_order'] = array(
     '#type' => 'select',
     '#title' => t('Image sort order'),
     '#description' => t(''),
@@ -173,25 +216,26 @@ function slideshowbox_admin_settings() {
     '#default_value' => variable_get('slideshowbox_sort_order', 'DESC'),
   );
 
-  $form['slideshowbox_width'] = array(
+  $form['size'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Slideshow size'),
+    '#description' => t('If no width and height is given, the sizes defined in the theme stylesheet will apply.'),
+  );
+  $form['size']['slideshowbox_width'] = array(
     '#type' => 'textfield',
-    '#title' => t('Box width'),
-    '#description' => t(''),
+    '#title' => t('Width'),
     '#default_value' => variable_get('slideshowbox_width', 320),
-    '#size' => 60,
+    '#size' => 4,
     '#maxlength' => 4,
-    '#required' => TRUE,
     '#validate' => array('slideshowbox_form_validate' => array()),
   );
 
-  $form['slideshowbox_height'] = array(
+  $form['size']['slideshowbox_height'] = array(
     '#type' => 'textfield',
-    '#title' => t('Box height'),
-    '#description' => t(''),
+    '#title' => t('Height'),
     '#default_value' => variable_get('slideshowbox_height', 240),
-    '#size' => 60,
+    '#size' => 4,
     '#maxlength' => 4,
-    '#required' => TRUE,
     '#validate' => array('slideshowbox_form_validate' => array()),
   );
 
@@ -216,45 +260,47 @@ function slideshowbox_settings() {
  * Use to validate the input of max image count input field
  */
 function slideshowbox_form_validate($form){
-
   $msg = t('An illegal choice has been detected. Please contact the site administrator.');
 
-  if (eregi("^[0-9]+$", $form['#value']))
-    return;
-  else
+  if (empty($form['#value'])) {
+    return TRUE;
+  }
+  
+  if (eregi("^[0-9]+$", $form['#value'])) {
+    return TRUE;
+  }
+  else {
     $msg = t('An illegal choice has been detected. Please type in only numbers.');
-
-
-  form_error($form, $msg);
-  watchdog('form', t('Illegal choice %choice in %name element.', array('%choice' => $form[$key]['#value'], '%name' => empty($form['#title']) ? $form['#parents'][0] : $form['#title'])), WATCHDOG_ERROR);
-
+    form_error($form, $msg);
+    
+    return FALSE;
+  }
 } // slideshowbox_form_validate
 
 /**
  * Block Hook
  */
 function slideshowbox_block($op='list', $delta=0) {
-  $path      = drupal_get_path('module', 'slideshowbox').'/slideshowbox/';
-  $theme     = variable_get('slideshowbox_theme', 'black');
-  $showTitle = variable_get('slideshowbox_block_title', 1);
-
   if ($op == "list") {
     $block[0]["info"] = t('Slideshow Box');
     return $block;
   }
 
   if ($op == "view") {
-    $block['subject'] = 'slideshowbox';
+    $path      = drupal_get_path('module', 'slideshowbox').'/slideshowbox/';
+    $theme     = variable_get('slideshowbox_theme', 'black');
+    $showTitle = variable_get('slideshowbox_block_title', 1);
+    
+    if ($showTitle) {
+      $block['subject'] = 'slideshowbox';
+    }
 
     // slideshow settings
     $type   = variable_get('slideshowbox_type', 'timed');
-    $width  = variable_get('slideshowbox_width', 320).'px';
-    $height = variable_get('slideshowbox_height', 240).'px';
-    $style  = "#mySlideshow { width: $width !important; height: $height !important;}";
-    $style .= !$showTitle ? ".block-slideshowbox h2 {display:none !important;}" : '';
+    $images = slideshowbox_getTermImages();
 
     // test if a term was selected
-    if(variable_get('slideshowbox_term', 0)){
+    if(variable_get('slideshowbox_term', 0) && !empty($images)){
       // include javascript files
       drupal_add_js($path.'scripts/mootools.release.64.js');
       switch($type){
@@ -275,24 +321,21 @@ function slideshowbox_block($op='list', 
       }
 
       // include css style
-      drupal_set_html_head('<style type="text/css" media="screen">'.$style.'</style>');
+      $width  = variable_get('slideshowbox_width', 0);
+      $height = variable_get('slideshowbox_height', 0);
+      if ($width && $height) {
+        drupal_set_html_head('<style type="text/css" media="screen">'. "#mySlideshow { width: {$width}px; height: {$height}px; }" .'</style>');
+      }
 
       // include all images that belong to the given term
-      drupal_set_html_head('<script type="text/javascript">countArticle = 0; var mySlideData = new Array(); '.slideshowbox_getTermImages().'</script>');
+      drupal_set_html_head('<script type="text/javascript">var ssBoxId = 0, ssBox = []; '. $images .'</script>');
 
       // insert div for images
       $block['content'] = '<div class="jdSlideshow" id="mySlideshow"></div>';
 
+      return $block;
     }
-    // if not show a warning message
-    else{
-      $block['content'] = t('Please select a term under settings first.');
-    }
-
-    return $block;
-
   }
-
 }
 
 function slideshowbox_footer($main = 0) {
@@ -300,13 +343,13 @@ function slideshowbox_footer($main = 0) 
   // start slideshow
   switch($type){
     case 'timed':
-      drupal_set_html_head('<script type="text/javascript"> function startSlideshow() { var slideshow = new timedSlideShow($(\'mySlideshow\'), mySlideData);} addLoadEvent(startSlideshow);</script>');
+      drupal_set_html_head('<script type="text/javascript">if(typeof ssBox != \'undefined\') { function startSlideshow() { var slideshow = new timedSlideShow($(\'mySlideshow\'), ssBox); } addLoadEvent(startSlideshow); }</script>');
       break;
     case 'gallery':
-      drupal_set_html_head('<script type="text/javascript"> function startSlideshow() { var slideshow = new showcaseSlideShow($(\'mySlideshow\'), mySlideData); } addLoadEvent(startSlideshow);</script>');
+      drupal_set_html_head('<script type="text/javascript">if(typeof ssBox != \'undefined\') {  function startSlideshow() { var slideshow = new showcaseSlideShow($(\'mySlideshow\'), ssBox); } addLoadEvent(startSlideshow); }</script>');
       break;
     case 'timedgallery':
-      drupal_set_html_head('<script type="text/javascript"> function startSlideshow() { var slideshow = new timedShowcaseSlideShow($(\'mySlideshow\'), mySlideData); } addLoadEvent(startSlideshow);</script>');
+      drupal_set_html_head('<script type="text/javascript">if(typeof ssBox != \'undefined\') {  function startSlideshow() { var slideshow = new timedShowcaseSlideShow($(\'mySlideshow\'), ssBox); } addLoadEvent(startSlideshow); }</script>');
       break;
   }
   
@@ -341,37 +384,46 @@ function slideshowbox_getAllTerms(){
  * Get all images to a given Term
  */
 function slideshowbox_getTermImages(){
-  $path   = 'http://'.$_SERVER['HTTP_HOST'].base_path();
   $termId = variable_get('slideshowbox_term', 0);
-  $limit  = 'LIMIT 0, '.variable_get('slideshowbox_max_images', 10);
+  $limit  = variable_get('slideshowbox_max_images', 10);
 
   // return if no Term was selected
   if (!$termId)
-    return;
+    return '';
 
   $sort = variable_get('slideshowbox_sort', '');
-  $sort = $sort ? 'n.'.$sort.' '.variable_get('slideshowbox_sort_order', 'DESC') : '';
+  $sort = $sort ? 'n.' . $sort .' '. variable_get('slideshowbox_sort_order', 'DESC') : '';
   $rand = variable_get('slideshowbox_random', 1) ? 'RAND()' : '';
   
   if($sort OR $rand)
-    $order = "ORDER BY $rand $sort ";
+    $order = "ORDER BY $rand $sort";
 
   // load all nodes they fit to the given term-Id
-  $results = db_query("SELECT n.nid
-                       FROM {node} n INNER JOIN term_node ON n.nid = term_node.nid
-                       WHERE n.type = 'image' AND term_node.tid = $termId AND n.status = 1 $order $limit");
+  $results = db_query_range("SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE n.type = 'image' AND tn.tid = %d AND n.status = 1 $order", $termId, 0, $limit);
 
   // load nodes from the result
+  $output    = '';
+  $size      = variable_get('slideshowbox_image_size', '_original');
   while ($node = db_fetch_object($results)){
-    $node    = node_load($node->nid, NULL, TRUE);
-    $image   = (object)$node->images;
-    $file    = $path.'files/'.($image->slideshow ? $image->slideshow : $image->_original);
-    $link    = $path.'node/'.$node->nid;
-    $title   = $node->title;
-    $desc    = trim(strip_tags($node->body));
-    $images .= "mySlideData[countArticle++] = new Array('$file', '$link', '$title', '$desc');";
+    $node    = node_load($node->nid);
+    $images  = (object)$node->images;
+    $file    = file_create_url(isset($images->$size) ? $images->$size : $images->_original);
+    if (variable_get('slideshowbox_image_link', 1)) {
+      $link  = url('node/'. $node->nid);
+    }
+    else {
+      $link  = '#';
+    }
+    if (variable_get('slideshowbox_image_info', 1)) {
+      $title = check_plain($node->title);
+      $desc  = check_plain(trim($node->body));
+    }
+    else {
+      $title = $desc = '';
+    }
+    $output .= "ssBox[ssBoxId++] = ['$file', '$link', '$title', '$desc'];";
   }
 
-  return $images;
+  return $output;
 
 }
