Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        module
5
 * @package         droplet
6
 * @author          Ruud Eisinga (Ruud) John (PCWacht)
7
 * @author          WebsiteBaker Project
8
 * @copyright       2004-2009, Ryan Djurovich
9
 * @copyright       2009-2011, Website Baker Org. e.V.
10
 * @link			http://www.websitebaker2.org/
11
 * @license         http://www.gnu.org/licenses/gpl.html
12
 * @platform        WebsiteBaker 2.8.x
13
 * @requirements    PHP 5.2.2 and higher
14
 * @version         $Id: install.php 1374 2011-01-10 12:21:47Z Luisehahne $
15
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/droplets/install.php $
16
 * @lastmodified    $Date: 2011-01-10 13:21:47 +0100 (Mon, 10 Jan 2011) $
17
 *
18
 */
19

    
20
// prevent this file from being accessed directly
21
if(!defined('WB_PATH')) die(header('Location: ../../index.php'));
22

    
23
global $admin;
24

    
25
$table = TABLE_PREFIX .'mod_droplets';
26
$database->query("DROP TABLE IF EXISTS `$table`");
27

    
28
$database->query("CREATE TABLE `$table` (
29
	`id` INT NOT NULL auto_increment,
30
	`name` VARCHAR(32) NOT NULL,
31
	`code` LONGTEXT NOT NULL ,
32
	`description` TEXT NOT NULL,
33
	`modified_when` INT NOT NULL default '0',
34
	`modified_by` INT NOT NULL default '0',
35
	`active` INT NOT NULL default '0',
36
	`admin_edit` INT NOT NULL default '0',
37
	`admin_view` INT NOT NULL default '0',
38
	`show_wysiwyg` INT NOT NULL default '0',
39
	`comments` TEXT NOT NULL,
40
	PRIMARY KEY ( `id` )
41
	)"
42
);
43

    
44
//add all droplets from the droplet subdirectory
45
$folder=opendir(WB_PATH.'/modules/droplets/example/.'); 
46
$names = array();
47
while ($file = readdir($folder)) {
48
	$ext=strtolower(substr($file,-4));
49
	if ($ext==".php"){
50
		if ($file<>"index.php" ) {
51
			$names[count($names)] = $file; 
52
		}
53
	}
54
}
55
closedir($folder);
56

    
57
foreach ($names as $dropfile) {
58
	$droplet = addslashes(getDropletCodeFromFile($dropfile));
59
	if ($droplet != "") {
60
		$description = "Example Droplet";
61
		$comments = "Example Droplet";
62
		$cArray = explode("\n",$droplet);
63
		if (substr($cArray[0],0,3) == "//:") {
64
			$description = trim(substr($cArray[0],3));
65
			array_shift ( $cArray );
66
		}
67
		if (substr($cArray[0],0,3) == "//:") {
68
			$comments = trim(substr($cArray[0],3));
69
			array_shift ( $cArray );
70
		}
71
		$droplet = implode ( "\n", $cArray );
72
		$name = substr($dropfile,0,-4);
73
		$modified_when = time();
74
		$modified_by = method_exists($admin, 'get_user_id') ? $admin->get_user_id() : 1;
75
		$database->query("INSERT INTO `$table`  
76
			(name, code, description, comments, active, modified_when, modified_by) 
77
			VALUES 
78
			('$name', '$droplet', '$description', '$comments', '1', '$modified_when', '$modified_by')");
79
		
80
		// do not output anything if this script is called during fresh installation
81
		if (method_exists($admin, 'get_user_id')) echo "Droplet import: $name<br/>";
82
	}  
83
}
84

    
85
function getDropletCodeFromFile ( $dropletfile ) {
86
	$data = "";
87
	$filename = WB_PATH."/modules/droplets/example/".$dropletfile;
88
	if (file_exists($filename)) {
89
		$filehandle = fopen ($filename, "r");
90
		$data = fread ($filehandle, filesize ($filename));
91
		fclose($filehandle);
92
		// unlink($filename); doesnt work in unix
93
	}	
94
	return $data;
95
}
96
?>
(8-8/13)