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