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