Index: diaporama.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/diaporama/diaporama.module,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 diaporama.module
--- diaporama.module	29 Apr 2008 19:14:38 -0000	1.1.2.1
+++ diaporama.module	4 May 2008 14:13:06 -0000
@@ -91,19 +91,20 @@ function diaporama_form(&$node, &$param)
 	);
 
 	/* 
-	 * 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){
@@ -113,7 +114,7 @@ function diaporama_form(&$node, &$param)
 	$form['width'] = array(
 		'#type' => 'textfield',
 		'#title' => t('Width'),
-		'#default_value' => $edit['width'],
+		'#default_value' => $node->width,
 		'#size' => 10,
 		'#maxlength' => 10,
 		'#description' => t("Width (px) of slideshow"),
@@ -123,7 +124,7 @@ function diaporama_form(&$node, &$param)
 	$form['height'] = array(
 		'#type' => 'textfield',
 		'#title' => t('Height'),
-		'#default_value' => $edit['height'],
+		'#default_value' => $node->height,
 		'#size' => 10,
 		'#maxlength' => 10,
 		'#description' => t("Height (px) of slideshow"),
@@ -133,7 +134,7 @@ function diaporama_form(&$node, &$param)
 	$form['transition'] = array(
 		'#type' => 'select',
 		'#title' => t('Transition'),
-		'#default_value' => $edit["transition"],
+		'#default_value' => $node->transition,
 		'#description' => t("Transition between images"),
 		'#options' => array('fade' => 'Fade','slide' => 'Slide','push' => 'Push','pop' => 'Pop','warp' => 'Warp','blur' => 'Blur')
 	);
@@ -141,7 +142,7 @@ function diaporama_form(&$node, &$param)
 	$form['speed'] = array(
 		'#type' => 'textfield',
 		'#title' => t('Speed transition'),
-		'#default_value' => $edit['speed'],
+		'#default_value' => $node->speed,
 		'#size' => 10,
 		'#maxlength' => 10,
 		'#description' => t("Speed transition in ms"),
@@ -151,7 +152,7 @@ function diaporama_form(&$node, &$param)
 	$form['timer'] = array(
 		'#type' => 'textfield',
 		'#title' => t('Time display'),
-		'#default_value' => $edit['timer'],
+		'#default_value' => $node->timer,
 		'#size' => 10,
 		'#maxlength' => 10,
 		'#description' => t("Time display in seconds, 0 = infinity"),
@@ -161,13 +162,13 @@ function diaporama_form(&$node, &$param)
 	$form['showbuttons'] = array(
 		'#type' => 'checkbox',
 		'#title' => t('Show buttons'),
-		'#default_value' => $edit['showbuttons'],
+		'#default_value' => $node->showbuttons,
 	);
 	
 	$form['alignbuttons'] = array(
 		'#type' => 'radios',
 		'#title' => t('Buttons position'),
-		'#default_value' => $edit['alignbuttons'],
+		'#default_value' => $node->alignbuttons,
 		'#options' => array(
 			'top' => t('top'),
 			'bottom' => t('bottom'),
@@ -180,23 +181,23 @@ function diaporama_form(&$node, &$param)
 	$form['showtitles'] = array(
 		'#type' => 'checkbox',
 		'#title' => t('Show image title'),
-		'#default_value' => $edit['showtitles'],
+		'#default_value' => $node->showtitles,
 	);
 	
 	$form['aligntitles'] = array(
 		'#type' => 'radios',
 		'#title' => t('Title position'),
-		'#default_value' => $edit['aligntitles'],
+		'#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('Random start'),
-		'#default_value' => $edit['randomstart'],
+		'#default_value' => $node->randomstart,
 	);
 	#
 
@@ -297,48 +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;
-  }*/
-  $top_bottom = array('top','bottom');
   
-  if(!isset($node->width) || empty($node->width))
-  	$node->width = variable_get('diaporama_width','640');
-  if(!isset($node->height) || empty($node->height))
-  	$node->height = variable_get('diaporama_height','480');
-  if(!isset($node->transition) || empty($node->transition))
-  	$node->transition = variable_get('diaporama_transition','fade');
-  if(!isset($node->speed) || empty($node->speed))
-  	$node->speed = variable_get('diaporama_speed','20');
-  if(!isset($node->timer) || empty($node->timer))
-  	$node->timer = variable_get('diaporama_timer','5');
-  if(!isset($node->showbuttons) || empty($node->showbuttons))
-  	$node->showbuttons = variable_get('diaporama_showbuttons','1');
-  if(!isset($node->alignbuttons) || empty($node->alignbuttons) || !in_array($node->alignbuttons,$top_bottom))
-  	$node->alignbuttons = variable_get('diaporama_alignbuttons','bottom');
-  if(!isset($node->aligntitles) || empty($node->aligntitles) || !in_array($node->aligntitles,$top_bottom))
-  	$node->aligntitles = variable_get('diaporama_aligntitles','bottom');
-  if(!isset($node->randomstart) || empty($node->randomstart))
-  	$node->randomstart = variable_get('diaporama_randomstart','1');
-}
 
 /**
  * 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);
 }
@@ -353,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);
   }
@@ -425,7 +395,7 @@ function diaporama_delete($node) {
  * every time a node is loaded, and allows us to do some loading of our own.
  */
 function diaporama_load($node) {
-  $diaporama = db_fetch_object(db_query('SELECT nid, width, height, transition, speed, timer, showbuttons, alignbuttons, randomstart FROM {diaporama} WHERE vid = %d', $node->vid));
+  $diaporama = db_fetch_object(db_query('SELECT nid, width, height, transition, speed, timer, showbuttons, alignbuttons, aligntitles, randomstart FROM {diaporama} WHERE vid = %d', $node->vid));
   return $diaporama;
 }
 
@@ -456,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>';
@@ -686,27 +656,43 @@ 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(t("Write in xml file diaporama_" . $node_nid . ".xml failed !"),array($node_nid=>$node->nid),"error");
@@ -718,6 +704,4 @@ function _diaporama_xml_delete($node){
 		drupal_set_message(t("The xml file diaporama_" . $node_nid . ".xml is deleted."), array($node_nid=>$node->nid));
 	else
 		drupal_set_message(t("XML file diaporama_" . $node_nid . ".xml failed deleting."), array($node_nid=>$node->nid),"error");
-}
-
-?>
+}
\ No newline at end of file
