Revision 1540
Added by Dietmar almost 13 years ago
install.php | ||
---|---|---|
25 | 25 |
} |
26 | 26 |
/* -------------------------------------------------------- */ |
27 | 27 |
|
28 |
global $admin; |
|
28 |
// global $admin;
|
|
29 | 29 |
|
30 |
$sql = 'DROP TABLE IF EXISTS `'.TABLE_PREFIX.'mod_droplets` '; |
|
31 |
$database->query($sql); |
|
30 |
$msg = array(); |
|
31 |
$sql = 'DROP TABLE IF EXISTS `'.TABLE_PREFIX.'mod_droplets` '; |
|
32 |
if( !$database->query($sql) ) { |
|
33 |
$msg[] = $database->get_error(); |
|
34 |
} |
|
32 | 35 |
|
33 |
$sql = 'CREATE TABLE IF NOT EXISTS `'.TABLE_PREFIX.'mod_droplets` ( '; |
|
34 |
$sql .= '`id` INT NOT NULL auto_increment, '; |
|
35 |
$sql .= '`name` VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, '; |
|
36 |
$sql .= '`code` LONGTEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL , '; |
|
37 |
$sql .= '`description` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, '; |
|
38 |
$sql .= '`modified_when` INT NOT NULL default \'0\', '; |
|
39 |
$sql .= '`modified_by` INT NOT NULL default \'0\', '; |
|
40 |
$sql .= '`active` INT NOT NULL default \'0\', '; |
|
41 |
$sql .= '`admin_edit` INT NOT NULL default \'0\', '; |
|
42 |
$sql .= '`admin_view` INT NOT NULL default \'0\', '; |
|
43 |
$sql .= '`show_wysiwyg` INT NOT NULL default \'0\', '; |
|
44 |
$sql .= '`comments` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, '; |
|
45 |
$sql .= 'PRIMARY KEY ( `id` ) '; |
|
46 |
$sql .= ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci'; |
|
47 |
$database->query($sql); |
|
36 |
$sql = 'CREATE TABLE IF NOT EXISTS `'.TABLE_PREFIX.'mod_droplets` ( '; |
|
37 |
$sql .= '`id` INT NOT NULL auto_increment, '; |
|
38 |
$sql .= '`name` VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, '; |
|
39 |
$sql .= '`code` LONGTEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL , '; |
|
40 |
$sql .= '`description` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, '; |
|
41 |
$sql .= '`modified_when` INT NOT NULL default \'0\', '; |
|
42 |
$sql .= '`modified_by` INT NOT NULL default \'0\', '; |
|
43 |
$sql .= '`active` INT NOT NULL default \'0\', '; |
|
44 |
$sql .= '`admin_edit` INT NOT NULL default \'0\', '; |
|
45 |
$sql .= '`admin_view` INT NOT NULL default \'0\', '; |
|
46 |
$sql .= '`show_wysiwyg` INT NOT NULL default \'0\', '; |
|
47 |
$sql .= '`comments` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, '; |
|
48 |
$sql .= 'PRIMARY KEY ( `id` ) '; |
|
49 |
$sql .= ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci'; |
|
50 |
if( !$database->query($sql) ) { |
|
51 |
$msg[] = $database->get_error(); |
|
52 |
} |
|
48 | 53 |
|
49 |
//add all droplets from the droplet subdirectory |
|
50 |
$folder=opendir(WB_PATH.'/modules/droplets/example/.'); |
|
51 |
$names = array(); |
|
52 |
while ($file = readdir($folder)) { |
|
53 |
$ext=strtolower(substr($file,-4)); |
|
54 |
if ($ext==".php"){ |
|
55 |
if ($file<>"index.php" ) { |
|
56 |
$names[count($names)] = $file; |
|
54 |
//add all droplets from the droplet subdirectory |
|
55 |
$folder=opendir(WB_PATH.'/modules/droplets/example/.'); |
|
56 |
$names = array(); |
|
57 |
while ($file = readdir($folder)) { |
|
58 |
$ext=strtolower(substr($file,-4)); |
|
59 |
if ($ext==".php"){ |
|
60 |
if ($file<>"index.php" ) { |
|
61 |
$names[count($names)] = $file; |
|
62 |
} |
|
57 | 63 |
} |
58 | 64 |
} |
59 |
} |
|
60 |
closedir($folder); |
|
65 |
closedir($folder); |
|
61 | 66 |
|
62 |
foreach ($names as $dropfile) { |
|
63 |
$droplet = addslashes(getDropletCodeFromFile($dropfile)); |
|
64 |
if ($droplet != "") { |
|
65 |
$description = "Example Droplet"; |
|
66 |
$comments = "Example Droplet"; |
|
67 |
$cArray = explode("\n",$droplet); |
|
68 |
if (substr($cArray[0],0,3) == "//:") { |
|
69 |
$description = trim(substr($cArray[0],3)); |
|
70 |
array_shift ( $cArray ); |
|
67 |
foreach ($names as $dropfile) |
|
68 |
{ |
|
69 |
$droplet = addslashes(getDropletCodeFromFile($dropfile)); |
|
70 |
if ($droplet != "") |
|
71 |
{ |
|
72 |
$description = "Example Droplet"; |
|
73 |
$comments = "Example Droplet"; |
|
74 |
$cArray = explode("\n",$droplet); |
|
75 |
if (substr($cArray[0],0,3) == "//:") { |
|
76 |
$description = trim(substr($cArray[0],3)); |
|
77 |
array_shift ( $cArray ); |
|
78 |
} |
|
79 |
if (substr($cArray[0],0,3) == "//:") { |
|
80 |
$comments = trim(substr($cArray[0],3)); |
|
81 |
array_shift ( $cArray ); |
|
82 |
} |
|
83 |
$droplet = implode ( "\n", $cArray ); |
|
84 |
$name = substr($dropfile,0,-4); |
|
85 |
$modified_when = time(); |
|
86 |
$modified_by = (method_exists($admin, 'get_user_id') ? $admin->get_user_id() : 1); |
|
87 |
$sql = 'INSERT INTO `'.TABLE_PREFIX.'mod_droplets` SET '; |
|
88 |
$sql .= '`name` = \''.$name.'\', '; |
|
89 |
$sql .= '`code` = \''.$droplet.'\', '; |
|
90 |
$sql .= '`description` = \''.$description.'\', '; |
|
91 |
$sql .= '`comments` = \''.$comments.'\', '; |
|
92 |
$sql .= '`active` = 1, '; |
|
93 |
$sql .= '`modified_when` = '.$modified_when.', '; |
|
94 |
$sql .= '`modified_by` = '.$modified_by; |
|
95 |
if( !$database->query($sql) ) { |
|
96 |
$msg[] = $database->get_error(); |
|
97 |
} |
|
98 |
// do not output anything if this script is called during fresh installation |
|
99 |
// if (method_exists($admin, 'get_user_id')) echo "Droplet import: $name<br/>"; |
|
71 | 100 |
} |
72 |
if (substr($cArray[0],0,3) == "//:") { |
|
73 |
$comments = trim(substr($cArray[0],3)); |
|
74 |
array_shift ( $cArray ); |
|
101 |
} |
|
102 |
|
|
103 |
function getDropletCodeFromFile ( $dropletfile ) { |
|
104 |
$data = ''; |
|
105 |
$filename = WB_PATH."/modules/droplets/example/".$dropletfile; |
|
106 |
if (file_exists($filename)) { |
|
107 |
$filehandle = fopen ($filename, "r"); |
|
108 |
$data = fread ($filehandle, filesize ($filename)); |
|
109 |
fclose($filehandle); |
|
110 |
// unlink($filename); doesnt work in unix |
|
75 | 111 |
} |
76 |
$droplet = implode ( "\n", $cArray ); |
|
77 |
$name = substr($dropfile,0,-4); |
|
78 |
$modified_when = time(); |
|
79 |
$modified_by = (method_exists($admin, 'get_user_id') ? $admin->get_user_id() : 1); |
|
80 |
$sql = 'INSERT INTO `'.TABLE_PREFIX.'mod_droplets` SET '; |
|
81 |
$sql .= '`name` = \''.$name.'\', '; |
|
82 |
$sql .= '`code` = \''.$droplet.'\', '; |
|
83 |
$sql .= '`description` = \''.$description.'\', '; |
|
84 |
$sql .= '`comments` = \''.$comments.'\', '; |
|
85 |
$sql .= '`active` = 1, '; |
|
86 |
$sql .= '`modified_when` = '.$modified_when.', '; |
|
87 |
$sql .= '`modified_by` = '.$modified_by; |
|
88 |
$database->query($sql); |
|
89 |
|
|
90 |
// do not output anything if this script is called during fresh installation |
|
91 |
// if (method_exists($admin, 'get_user_id')) echo "Droplet import: $name<br/>"; |
|
112 |
return $data; |
|
92 | 113 |
} |
93 |
} |
|
94 |
|
|
95 |
function getDropletCodeFromFile ( $dropletfile ) { |
|
96 |
$data = ''; |
|
97 |
$filename = WB_PATH."/modules/droplets/example/".$dropletfile; |
|
98 |
if (file_exists($filename)) { |
|
99 |
$filehandle = fopen ($filename, "r"); |
|
100 |
$data = fread ($filehandle, filesize ($filename)); |
|
101 |
fclose($filehandle); |
|
102 |
// unlink($filename); doesnt work in unix |
|
103 |
} |
|
104 |
return $data; |
|
105 |
} |
Also available in: Unified diff
did some changes and fixes found by testers