Index: diaporama.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/diaporama/diaporama.module,v
retrieving revision 1.1
diff -u -p -r1.1 diaporama.module
--- diaporama.module	25 Apr 2008 16:48:56 -0000	1.1
+++ diaporama.module	4 May 2008 06:47:15 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: diaporama.module,v 1.1 2008/04/25 16:48:56 goz Exp $
+// $Id: diaporama.module,v 1.1.2.1 2008/04/29 19:14:38 goz Exp $
 
 /**
  * TODO
@@ -72,8 +72,8 @@ function diaporama_perm() {
 function diaporama_form(&$node, &$param) {
 	_diaporama_check_settings();
 	global $base_url;
-	
-  	$type = node_get_types('type', $node);
+
+  $type = node_get_types('type', $node);
 
 	$form['title'] = array(
 		'#type' => 'textfield',
@@ -89,26 +89,22 @@ function diaporama_form(&$node, &$param)
 		'#default_value' => $node->body,
 		'#required' => FALSE
 	);
-	
-	/*if (empty($edit)) {
-		$edit['vid'] = _diaporama_get_vid();
-	}*/
-	
 
 	/* 
-	 * Récupération des propriétés générales
+	 * If creating a node $node->nid will be null so fill form with default settings
 	 */
-	$edit['width'] = variable_get('diaporama_width','640');
-	$edit['height'] = variable_get('diaporama_height','480');
-	$edit['transition'] = variable_get('diaporama_transition','Fade');
-	$edit['speed'] = variable_get('diaporama_speed',20);
-	$edit['timer'] = variable_get('diaporama_timer',5);
-	$edit['showbuttons'] = variable_get('diaporama_showbuttons',1);
-	$edit['alignbuttons'] = variable_get('diaporama_alignbuttons','bottom');
-	$edit['showtitles'] = variable_get('diaporama_showtitles',1);
-	$edit['aligntitles'] = variable_get('diaporama_aligntitles','bottom');
-	$edit['randomstart'] = variable_get('diaporama_randomstart',1);
-	
+  if ($node->nid == '') {
+  	$node->width = variable_get('diaporama_width','640');
+  	$node->height = variable_get('diaporama_height','480');
+  	$node->transition = variable_get('diaporama_transition','Fade');
+  	$node->speed = variable_get('diaporama_speed',20);
+  	$node->timer = variable_get('diaporama_timer',5);
+  	$node->showbuttons = variable_get('diaporama_showbuttons',1);
+  	$node->alignbuttons = variable_get('diaporama_alignbuttons','bottom');
+  	$node->showtitles = variable_get('diaporama_showtitles',1);
+  	$node->aligntitles = variable_get('diaporama_aligntitles','bottom');
+  	$node->randomstart = variable_get('diaporama_randomstart',1);
+  }
 	
 	// récupération des données déjà existantes sur un diaporama
 	foreach(_diaporama_get_datas($node) as $key => $val){
@@ -117,65 +113,65 @@ function diaporama_form(&$node, &$param)
 	
 	$form['width'] = array(
 		'#type' => 'textfield',
-		'#title' => t('Largeur'),
-		'#default_value' => $edit['width'],
+		'#title' => t('Width'),
+		'#default_value' => $node->width,
 		'#size' => 10,
 		'#maxlength' => 10,
-		'#description' => t("Largeur (en px) du diaporama"),
+		'#description' => t("Width (px) of slideshow"),
 		'#required' => TRUE,
 	);
 	
 	$form['height'] = array(
 		'#type' => 'textfield',
-		'#title' => t('Hauteur'),
-		'#default_value' => $edit['height'],
+		'#title' => t('Height'),
+		'#default_value' => $node->height,
 		'#size' => 10,
 		'#maxlength' => 10,
-		'#description' => t("Hauteur (en px) du diaporama"),
+		'#description' => t("Height (px) of slideshow"),
 		'#required' => TRUE,
 	);
 	
 	$form['transition'] = array(
 		'#type' => 'select',
 		'#title' => t('Transition'),
-		'#default_value' => $edit["transition"],
-		'#description' => t("Transition entre les images"),
+		'#default_value' => $node->transition,
+		'#description' => t("Transition between images"),
 		'#options' => array('fade' => 'Fade','slide' => 'Slide','push' => 'Push','pop' => 'Pop','warp' => 'Warp','blur' => 'Blur')
 	);
 	
 	$form['speed'] = array(
 		'#type' => 'textfield',
-		'#title' => t('Vitesse de transition'),
-		'#default_value' => $edit['speed'],
+		'#title' => t('Speed transition'),
+		'#default_value' => $node->speed,
 		'#size' => 10,
 		'#maxlength' => 10,
-		'#description' => t("Vitesse de transition en ms"),
+		'#description' => t("Speed transition in ms"),
 		'#required' => TRUE,
 	);
 	
 	$form['timer'] = array(
 		'#type' => 'textfield',
-		'#title' => t('Délai d\'affichage'),
-		'#default_value' => $edit['timer'],
+		'#title' => t('Time display'),
+		'#default_value' => $node->timer,
 		'#size' => 10,
 		'#maxlength' => 10,
-		'#description' => t("Délai d'affichage en secondes, 0 = infini"),
+		'#description' => t("Time display in seconds, 0 = infinity"),
 		'#required' => TRUE,
 	);
 	
 	$form['showbuttons'] = array(
 		'#type' => 'checkbox',
-		'#title' => t('Afficher les boutons'),
-		'#default_value' => $edit['showbuttons'],
+		'#title' => t('Show buttons'),
+		'#default_value' => $node->showbuttons,
 	);
 	
 	$form['alignbuttons'] = array(
 		'#type' => 'radios',
-		'#title' => t('Position des boutons'),
-		'#default_value' => $edit['alignbuttons'],
+		'#title' => t('Buttons position'),
+		'#default_value' => $node->alignbuttons,
 		'#options' => array(
-			'top' => t('en haut'),
-			'bottom' => t('en bas'),
+			'top' => t('top'),
+			'bottom' => t('bottom'),
 		),
 	);
 	
@@ -184,24 +180,24 @@ function diaporama_form(&$node, &$param)
 	 */
 	$form['showtitles'] = array(
 		'#type' => 'checkbox',
-		'#title' => t('Afficher les titres des images'),
-		'#default_value' => $edit['showtitles'],
+		'#title' => t('Show image title'),
+		'#default_value' => $node->showtitles,
 	);
 	
 	$form['aligntitles'] = array(
 		'#type' => 'radios',
-		'#title' => t('Position des titres'),
-		'#default_value' => $edit['aligntitles'],
+		'#title' => t('Title position'),
+		'#default_value' => $node->aligntitles,
 		'#options' => array(
-			'top' => t('en haut'),
-			'bottom' => t('en bas'),
+			'top' => t('top'),
+			'bottom' => t('bottom'),
 		),
 	);
 	
 	$form['randomstart'] = array(
 		'#type' => 'checkbox',
-		'#title' => t('Début aléatoire'),
-		'#default_value' => $edit['randomstart'],
+		'#title' => t('Random start'),
+		'#default_value' => $node->randomstart,
 	);
 	#
 
@@ -212,7 +208,7 @@ function diaporama_form(&$node, &$param)
 			'#type' => 'item',
 			//'#collapsible' => false,
 			//'#collapsed' => TRUE,
-			'#title' => t('Sélectionner les images'),
+			'#title' => t('Select images'),
 			'#tree' => TRUE,
 		);
   			
@@ -257,34 +253,44 @@ function diaporama_form(&$node, &$param)
 					}
 				}else{
 					$form['galleries'][$string]['vide'] = array(
-						'#value' => t('Gallery empty')
+						'#value' => t('Empty Gallery')
 					);
 				}
 			}
 		}
 	}
-	else { // Aucune galerie n'est disponible
-		$s = 'No galleries available';
+	
+	// Récupération des toutes les images non présentes dans une gallerie
+	$result = pager_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.status=1 AND n.type='image' AND n.nid NOT IN(SELECT t.nid FROM {term_node} t) ORDER BY n.sticky DESC, n.created DESC"), variable_get('image_images_per_page', 50), 0, NULL);
+	while ($node_images = db_fetch_object($result)) {
+		$images_noGalleries[] = node_load(array('nid' => $node_images->nid));
 	}
-  
-	/*$form['vid'] = array(
-		'#type' => 'hidden',
-		'#value' => _diaporama_get_vid(),
-	);
-
-	$form['submit' ] = array(
-		'#type' => 'submit',
-		'#value' => t('Submit'),
-	);*/
-	if ($edit['tid']) {
-		$form['delete'] = array(
-			'#type' => 'submit',
-			'#value' => t('Delete'),
-		);
-		$form['tid'] = array(
-			'#type' => 'hidden',
-			'#value' => $edit['tid'],
+	
+	// Affichage de l'image
+	if(sizeof($images_noGalleries) > 0){
+		$form['galleries']['no_galleries'] = array(
+			'#type' => 'fieldset',
+			'#collapsible' => TRUE,
+			'#collapsed' => TRUE,
+			'#title' => t('Images without galleries'),
+			'#tree' => TRUE,
+			'#theme' => 'diaporama_form_gallery',
 		);
+		
+		foreach($images_noGalleries as $image){
+			$form['galleries']['no_galleries'][$image->nid] = array(
+				'#type' => 'checkbox',
+				'#title' => '<img src="' . $base_url . '/' . _image_get_thumbnail($image->nid) . '" />',
+				'#default_value' => $edit['galleries'][$image->nid],
+				//'#title' => l(image_display($image, IMAGE_THUMBNAIL), 'node/'. $image->nid, array(), NULL, NULL, FALSE, TRUE),
+			);
+			if($edit['galleries'][$image->nid])
+				$form['galleries']['no_galleries']['#collapsed'] = FALSE;
+		}
+	}
+
+	if(!$tree && sizeof($images_noGalleries) == 0) { // Aucune galerie n'est disponible
+		$s = 'No galleries available';
 	}
 	
 	return $form;
@@ -292,28 +298,17 @@ function diaporama_form(&$node, &$param)
 
 /**
  * Implementation of hook_validate().
- *
- *
- * Errors should be signaled with form_set_error().
+ * Don't need to validate because form is filled in with default values and
+ * any blank values will be picked up automatically by required = tRUE
  */
-function diaporama_validate(&$node) {
-  /*if ($node->quantity) {
-    if (!is_numeric($node->quantity)) {
-      form_set_error('quantity', t('The quantity must be a number.'));
-    }
-  }
-  else {
-    // Let an empty field mean "zero."
-    $node->quantity = 0;
-  }*/
-}
+
 
 /**
  * Implementation of hook_insert().
  *
  */
 function diaporama_insert($node) {
-  db_query("INSERT INTO {diaporama} (vid, nid, width, height, transition, speed, timer, showbuttons, alignbuttons, aligntitles, randomstart) VALUES (%d, %d, %d, %d, '%s', %d, %d, %d, '%s', %d)", $node->vid, $node->nid, $node->width, $node->height, $node->transition, $node->speed, $node->timer, $node->showbuttons, $node->alignbuttons, $node->aligntitles, $node->randomstart);
+  db_query("INSERT INTO {diaporama} (vid, nid, width, height, transition, speed, timer, showbuttons, alignbuttons, aligntitles, randomstart) VALUES (%d, %d, %d, %d, '%s', %d, %d, %d, '%s', '%s', %d)", $node->vid, $node->nid, $node->width, $node->height, $node->transition, $node->speed, $node->timer, $node->showbuttons, $node->alignbuttons, $node->aligntitles, $node->randomstart);
   _diaporama_images_save($node);
   _diaporama_xml_save($node);
 }
@@ -328,7 +323,7 @@ function diaporama_update($node) {
     diaporama_insert($node);
   }
   else {
-    db_query("UPDATE {diaporama} SET width = '%d', height = '%d', transition = '%s', speed = '%d', timer = '%d', showbuttons = '%d', alignbuttons = '%s', aligntitles = '%s', randomstart = '%d' WHERE vid = %d", array($node->width, $node->height, $node->transition, $node->speed, $node->timer, $node->showbuttons, $node->alignbuttons, $node->aligntitles, $node->randomstart, $node->vid));
+    db_query("UPDATE {diaporama} SET width = '%d', height = '%d', transition = '%s', speed = '%d', timer = '%d', showbuttons = '%d', alignbuttons = '%s', aligntitles = '%s', randomstart = '%d' WHERE vid = %d", $node->width, $node->height, $node->transition, $node->speed, $node->timer, $node->showbuttons, $node->alignbuttons, $node->aligntitles, $node->randomstart, $node->vid);
 	_diaporama_images_save($node);
 	_diaporama_xml_save($node);
   }
@@ -431,7 +426,7 @@ function diaporama_view($node, $teaser =
 function theme_diaporama_order_info($node) {
 	global $base_url;
   $output = '<div class="diaporama_order_info" style="text-align: center;">';
-  $output .= '<object type="application/x-shockwave-flash" data="' . $base_url . '/files/diaporamas/dewslider.swf?xml=' . $base_url . '/files/diaporamas/diaporama_' . $node->nid . '.xml" width="640" height="480">
+  $output .= '<object type="application/x-shockwave-flash" data="' . $base_url . '/files/diaporamas/dewslider.swf?xml=' . $base_url . '/files/diaporamas/diaporama_' . $node->nid . '.xml" width="'. $node->width .'" height="'. $node->height .'">
 <param name="movie" value="' . $base_url . '/files/diaporamas/dewslider.swf?xml=' . $base_url . '/files/diaporamas/diaporama_' . $node->nid . '.xml" />
 </object>';
   $output .= '</div>';
@@ -452,7 +447,7 @@ function diaporama_menu($may_cache) {
 			'title' => t('Diaporama'),
 			'callback' => 'drupal_get_form',
 			'callback arguments' => 'diaporama_admin_settings',
-			'description' => t('Configure properties of diaporama.'),
+			'description' => t('Configure diaporama properties.'),
 			'access' => user_access('administer diaporama'),
 			'type' => MENU_NORMAL_ITEM,
 		);
@@ -474,21 +469,21 @@ function diaporama_admin_settings(){
 	
 	$form['diaporama']['diaporama_width'] = array(
 		'#type' => 'textfield',
-		'#title' => t('Largeur'),
+		'#title' => t('Width'),
 		'#default_value' => variable_get('diaporama_width', 640),
 		'#size' => 10,
 		'#maxlength' => 10,
-		'#description' => t("Largeur (en px) du diaporama"),
+		'#description' => t("Width (px) of slideshow"),
 		'#required' => TRUE,
 	);
 	
 	$form['diaporama']['diaporama_height'] = array(
 		'#type' => 'textfield',
-		'#title' => t('Hauteur'),
+		'#title' => t('Height'),
 		'#default_value' => variable_get('diaporama_height', 480),
 		'#size' => 10,
 		'#maxlength' => 10,
-		'#description' => t("Hauteur (en px) du diaporama"),
+		'#description' => t("Height (px) of slideshow"),
 		'#required' => TRUE,
 	);
 	
@@ -496,65 +491,65 @@ function diaporama_admin_settings(){
 		'#type' => 'select',
 		'#title' => t('Transition'),
 		'#default_value' => variable_get('diaporama_transition', 'Fade'),
-		'#description' => t("Transition entre les images"),
+		'#description' => t("Transition between images"),
 		'#options' => array('Fade' => 'Fade','Slide' => 'Slide','Push' => 'Push','Pop' => 'Pop','Warp' => 'Warp','Blur' => 'Blur')
 	);
 	
 	$form['diaporama']['diaporama_speed'] = array(
 		'#type' => 'textfield',
-		'#title' => t('Vitesse de transition'),
+		'#title' => t('Speed transition'),
 		'#default_value' => variable_get('diaporama_speed', 20),
 		'#size' => 10,
 		'#maxlength' => 10,
-		'#description' => t("Vitesse de transition en ms"),
+		'#description' => t("Speed transition in ms"),
 		'#required' => TRUE,
 	);
 	
 	$form['diaporama']['diaporama_timer'] = array(
 		'#type' => 'textfield',
-		'#title' => t('Délai d\'affichage'),
+		'#title' => t('Time display'),
 		'#default_value' => variable_get('diaporama_timer', 5),
 		'#size' => 10,
 		'#maxlength' => 10,
-		'#description' => t("Délai d'affichage en secondes, 0 = infini"),
+		'#description' => t("Time display in seconds, 0 = infinity"),
 		'#required' => TRUE,
 	);
 	
 	$form['diaporama']['diaporama_showbuttons'] = array(
 		'#type' => 'checkbox',
-		'#title' => t('Afficher les boutons'),
+		'#title' => t('Show buttons'),
 		'#default_value' => variable_get('diaporama_showbuttons', 1),
 	);
 	
 	$form['diaporama']['diaporama_alignbuttons'] = array(
 		'#type' => 'radios',
-		'#title' => t('Position des boutons'),
+		'#title' => t('Buttons position'),
 		'#default_value' => variable_get('diaporama_alignbuttons', 'bottom'),
 		'#options' => array(
-			'top' => t('en haut'),
-			'bottom' => t('en bas'),
+			'top' => t('top'),
+			'bottom' => t('bottom'),
 		),
 	);
 	
 	$form['diaporama']['diaporama_showtitles'] = array(
 		'#type' => 'checkbox',
-		'#title' => t('Afficher les titres'),
+		'#title' => t('Show titles'),
 		'#default_value' => variable_get('diaporama_showtitles', 1),
 	);
 	
 	$form['diaporama']['diaporama_aligntitles'] = array(
 		'#type' => 'radios',
-		'#title' => t('Position des titres'),
+		'#title' => t('Titles position'),
 		'#default_value' => variable_get('diaporama_aligntitles', 'bottom'),
 		'#options' => array(
-			'top' => t('en haut'),
-			'bottom' => t('en bas'),
+			'top' => t('top'),
+			'bottom' => t('bottom'),
 		),
 	);
 	
 	$form['diaporama']['diaporama_randomstart'] = array(
 		'#type' => 'checkbox',
-		'#title' => t('Début aléatoire'),
+		'#title' => t('Random start'),
 		'#default_value' => variable_get('diaporama_randomstart', 1),
 	);
 	
@@ -567,14 +562,10 @@ function diaporama_admin_settings(){
 function _diaporama_check_settings() {
   // File paths
   $diaporama_path = file_create_path(variable_get('diaporama_default_path', 'diaporamas'));
-  //$temp_path = rtrim($diaporama_path, '/') .'/temp';
 
   if (!file_check_directory($diaporama_path, FILE_CREATE_DIRECTORY, 'diaporama_default_path')) {
     return false;
   }
-  //if (!file_check_directory($temp_path, FILE_CREATE_DIRECTORY, 'diaporama_default_path')) {
-  //  return false;
-  //}
 
   return true;
 }
@@ -588,10 +579,10 @@ function diaporama_help($section='') {
 
   switch ($section) {
     case "admin/help#diaporama":
-      $output = '<p>'.  t("Gestion du diaporama"). '</p>';
+      $output = '<p>'.  t("Management diaporama"). '</p>';
       break;
     case "admin/content/diaporama/add":
-      $output .= '<p><i>' . t("Sélectionnez les images qui composeront votre diaporama.") . '</i></p>';
+      $output .= '<p><i>' . t("Select images that make up your slideshow.") . '</i></p>';
       break;
   }
 
@@ -665,38 +656,52 @@ function theme_diaporama_form_gallery(&$
 	return $output;
 }
 
+
+function _diaporama_boolean($value){
+  if ($value){
+      return 'yes';
+  } else
+  {
+    return 'no';
+  }
+}
+
+
 function _diaporama_xml_save($node){
 	global $base_url;
-	
+
+  // convert boolean to yes and no
+  $node->showbuttons = _diaporama_boolean($node->showbuttons);
+  $node->showtitles = _diaporama_boolean($node->showtitles);
+  $node->randomstart = _diaporama_boolean($node->randomstart);
+
 	$file= fopen("files/diaporamas/diaporama_" . $node->nid . ".xml", "w");
-	$_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";
-	$_xml .= "<album\r\n";
-	$_xml .= "\tshowbuttons=\"" . $node->showbuttons . "\"\r\n";
-	$_xml .= "\tshowtitles=\"" . $node->showtitles . "\"\r\n";
-	$_xml .= "\trandomstart=\"" . $node->randomstart . "\"\r\n";
-	$_xml .= "\ttimer=\"" . $node->timer . "\"\r\n";
-	$_xml .= "\taligntitles=\"" . $node->aligntitles . "\"\r\n";
-	$_xml .= "\talignbuttons=\"" . $node->alignbuttons . "\"\r\n";
-	$_xml .= "\ttransition=\"" . $node->transition . "\"\r\n";
-	$_xml .= "\tspeed=\"" . $node->speed . "\">\r\n";
+	$_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
+	$_xml .= "<album\n";
+	$_xml .= "\tshowbuttons=\"" . $node->showbuttons . "\"\n";
+	$_xml .= "\tshowtitles=\"" . $node->showtitles . "\"\n";
+	$_xml .= "\trandomstart=\"" . $node->randomstart . "\"\n";
+	$_xml .= "\ttimer=\"" . $node->timer . "\"\n";
+	$_xml .= "\taligntitles=\"" . $node->aligntitles . "\"\n";
+	$_xml .= "\talignbuttons=\"" . $node->alignbuttons . "\"\n";
+	$_xml .= "\ttransition=\"" . $node->transition . "\"\n";
+	$_xml .= "\tspeed=\"" . $node->speed . "\">\n";
 	
 	$result = db_query("SELECT f.filepath, n.title, n.nid FROM {term_node} t INNER JOIN {files} f ON f.nid = t.nid INNER JOIN {node} n ON t.nid = n.nid WHERE t.tid = %d AND filename='preview'", $node->nid);
 	while ($image = db_fetch_object($result)){
-		$_xml .= "\t<img src=\"" . $base_url . "/" . $image->filepath . "\" title=\"" . $image->title . "\" url=\"?q=node/" . $image->nid . "\" />\r\n";
+		$_xml .= "<img src=\"" . $base_url . "/" . $image->filepath . "\" title=\"" . $image->title . "\" url=\"?q=node/" . $image->nid . "\" />\n";
 	}
 	
-	$_xml .= "</album>\r\n";
+	$_xml .= "</album>\n";
 
 	if(!fwrite($file, $_xml))
-		drupal_set_message("L'écriture du fichier xml diaporama_" . $node_nid . ".xml a échoué !",array($node_nid=>$node->nid),"error");
+		drupal_set_message(t("Write in xml file diaporama_" . $node_nid . ".xml failed !"),array($node_nid=>$node->nid),"error");
 	fclose($file);
 }
 
 function _diaporama_xml_delete($node){
 	if(unlink("files/diaporamas/diaporama_" . $node->nid . ".xml"))
-		drupal_set_message("Le fichier xml diaporama_" . $node_nid . ".xml a été supprimé.", array($node_nid=>$node->nid));
+		drupal_set_message(t("The xml file diaporama_" . $node_nid . ".xml is deleted."), array($node_nid=>$node->nid));
 	else
-		drupal_set_message("La suppression du fichier xml diaporama_" . $node_nid . ".xml a échoué.", array($node_nid=>$node->nid),"error");
-}
-
-?>
+		drupal_set_message(t("XML file diaporama_" . $node_nid . ".xml failed deleting."), array($node_nid=>$node->nid),"error");
+}
\ No newline at end of file
