Project

General

Profile

1 989 aldus
<?php
2 991 Ruebenwurz
3
// $Id$
4
5 989 aldus
/*
6
*	@version	1.0
7
*	@author		Ruud Eisinga (Ruud) John (PCWacht)
8
*	@date		June 2009
9
*
10
*	droplets are small codeblocks that are called from anywhere in the template.
11
* 	To call a droplet just use [[dropletname]]. optional parameters for a droplet can be used like [[dropletname?parameter=value&parameter2=value]]
12
*/
13
14
// prevent this file from being accessed directly
15 995 aldus
if(!defined('WB_PATH')) die(header('Location: ../../index.php'));
16 989 aldus
17
$table = TABLE_PREFIX .'mod_droplets';
18
$database->query("DROP TABLE IF EXISTS `$table`");
19
20
$database->query("CREATE TABLE `$table` (
21
	`id` INT NOT NULL auto_increment,
22
	`name` VARCHAR(32) NOT NULL,
23
	`code` LONGTEXT NOT NULL ,
24
	`description` TEXT NOT NULL,
25
	`modified_when` INT NOT NULL default '0',
26
	`modified_by` INT NOT NULL default '0',
27
	`active` INT NOT NULL default '0',
28
	`admin_edit` INT NOT NULL default '0',
29
	`admin_view` INT NOT NULL default '0',
30
	`show_wysiwyg` INT NOT NULL default '0',
31
	`comments` TEXT NOT NULL,
32
	PRIMARY KEY ( `id` )
33
	)"
34
);
35
36
//add all droplets from the droplet subdirectory
37
$folder=opendir(WB_PATH.'/modules/droplets/example/.');
38
$names = array();
39
while ($file = readdir($folder)) {
40
	$ext=strtolower(substr($file,-4));
41
	if ($ext==".php"){
42
		if ($file<>"index.php" ) {
43
			$names[count($names)] = $file;
44
		}
45
	}
46
}
47
closedir($folder);
48
49
foreach ($names as $dropfile) {
50
	$droplet = addslashes(getDropletCodeFromFile($dropfile));
51
	if ($droplet != "") {
52
		$description = "Example Droplet";
53
		$comments = "Example Droplet";
54
		$cArray = explode("\n",$droplet);
55
		if (substr($cArray[0],0,3) == "//:") {
56
			$description = trim(substr($cArray[0],3));
57
			array_shift ( $cArray );
58
		}
59
		if (substr($cArray[0],0,3) == "//:") {
60
			$comments = trim(substr($cArray[0],3));
61
			array_shift ( $cArray );
62
		}
63
		$droplet = implode ( "\n", $cArray );
64
		$name = substr($dropfile,0,-4);
65 1072 Ruebenwurz
		$modified_when = time();
66 989 aldus
		$modified_by = method_exists($admin, 'get_user_id') ? $admin->get_user_id() : 1;
67
		$database->query("INSERT INTO `$table`
68
			(name, code, description, comments, active, modified_when, modified_by)
69
			VALUES
70
			('$name', '$droplet', '$description', '$comments', '1', '$modified_when', '$modified_by')");
71
72
		// do not output anything if this script is called during fresh installation
73
		if (method_exists($admin, 'get_user_id')) echo "Droplet import: $name<br/>";
74
	}
75
}
76
77
function getDropletCodeFromFile ( $dropletfile ) {
78
	$data = "";
79
	$filename = WB_PATH."/modules/droplets/example/".$dropletfile;
80
	if (file_exists($filename)) {
81
		$filehandle = fopen ($filename, "r");
82
		$data = fread ($filehandle, filesize ($filename));
83
		fclose($filehandle);
84
		// unlink($filename); doesnt work in unix
85
	}
86
	return $data;
87
}
88
?>