Index: trunk/CHANGELOG
===================================================================
--- trunk/CHANGELOG	(revision 993)
+++ trunk/CHANGELOG	(revision 994)
@@ -12,6 +12,7 @@
 
 ------------------------------------- 2.8.0 -------------------------------------
 15-June-2009 Matthias Gallas
++	Added install routine for droplets to the upgrade script
 #	Fixed bug in menu_link modul with wrong displayed pages tree (Thanks to thorn)
 #	Fixed small bug introduced in changeset [989]
 +	Added missing id tags and copyright notices to droplets modul
Index: trunk/wb/upgrade-script.php
===================================================================
--- trunk/wb/upgrade-script.php	(revision 993)
+++ trunk/wb/upgrade-script.php	(revision 994)
@@ -230,6 +230,80 @@
 
 
 /**********************************************************
+ *  - install droplets
+ */
+echo "<br />Install droplets<br />";
+$table = TABLE_PREFIX .'mod_droplets';
+$database->query("DROP TABLE IF EXISTS `$table`");
+
+$database->query("CREATE TABLE `$table` (
+	`id` INT NOT NULL auto_increment,
+	`name` VARCHAR(32) NOT NULL,
+	`code` LONGTEXT NOT NULL ,
+	`description` TEXT NOT NULL,
+	`modified_when` INT NOT NULL default '0',
+	`modified_by` INT NOT NULL default '0',
+	`active` INT NOT NULL default '0',
+	`admin_edit` INT NOT NULL default '0',
+	`admin_view` INT NOT NULL default '0',
+	`show_wysiwyg` INT NOT NULL default '0',
+	`comments` TEXT NOT NULL,
+	PRIMARY KEY ( `id` )
+	)"
+);
+
+//add all droplets from the droplet subdirectory
+$folder=opendir(WB_PATH.'/modules/droplets/example/.'); 
+$names = array();
+while ($file = readdir($folder)) {
+	$ext=strtolower(substr($file,-4));
+	if ($ext==".php"){
+		if ($file<>"index.php" ) {
+			$names[count($names)] = $file; 
+		}
+	}
+}
+closedir($folder);
+
+foreach ($names as $dropfile) {
+	$droplet = addslashes(getDropletCodeFromFile($dropfile));
+	if ($droplet != "") {
+		$description = "Example Droplet";
+		$comments = "Example Droplet";
+		$cArray = explode("\n",$droplet);
+		if (substr($cArray[0],0,3) == "//:") {
+			$description = trim(substr($cArray[0],3));
+			array_shift ( $cArray );
+		}
+		if (substr($cArray[0],0,3) == "//:") {
+			$comments = trim(substr($cArray[0],3));
+			array_shift ( $cArray );
+		}
+		$droplet = implode ( "\n", $cArray );
+		$name = substr($dropfile,0,-4);
+		$modified_when = mktime();
+		$modified_by = method_exists($admin, 'get_user_id') ? $admin->get_user_id() : 1;
+		echo ($database->query("INSERT INTO `$table`  
+			(name, code, description, comments, active, modified_when, modified_by) 
+			VALUES 
+			('$name', '$droplet', '$description', '$comments', '1', '$modified_when', '$modified_by')"))? "$name: $OK<br />" : "$name: $FAIL<br />";
+	}  
+}
+
+
+function getDropletCodeFromFile ( $dropletfile ) {
+	$data = "";
+	$filename = WB_PATH."/modules/droplets/example/".$dropletfile;
+	if (file_exists($filename)) {
+		$filehandle = fopen ($filename, "r");
+		$data = fread ($filehandle, filesize ($filename));
+		fclose($filehandle);
+		// unlink($filename); doesnt work in unix
+	}	
+	return $data;
+}
+
+/**********************************************************
  *  - Reload all addons
  */
 
