Revision 994
Added by Matthias over 15 years ago
upgrade-script.php | ||
---|---|---|
230 | 230 |
|
231 | 231 |
|
232 | 232 |
/********************************************************** |
233 |
* - install droplets |
|
234 |
*/ |
|
235 |
echo "<br />Install droplets<br />"; |
|
236 |
$table = TABLE_PREFIX .'mod_droplets'; |
|
237 |
$database->query("DROP TABLE IF EXISTS `$table`"); |
|
238 |
|
|
239 |
$database->query("CREATE TABLE `$table` ( |
|
240 |
`id` INT NOT NULL auto_increment, |
|
241 |
`name` VARCHAR(32) NOT NULL, |
|
242 |
`code` LONGTEXT NOT NULL , |
|
243 |
`description` TEXT NOT NULL, |
|
244 |
`modified_when` INT NOT NULL default '0', |
|
245 |
`modified_by` INT NOT NULL default '0', |
|
246 |
`active` INT NOT NULL default '0', |
|
247 |
`admin_edit` INT NOT NULL default '0', |
|
248 |
`admin_view` INT NOT NULL default '0', |
|
249 |
`show_wysiwyg` INT NOT NULL default '0', |
|
250 |
`comments` TEXT NOT NULL, |
|
251 |
PRIMARY KEY ( `id` ) |
|
252 |
)" |
|
253 |
); |
|
254 |
|
|
255 |
//add all droplets from the droplet subdirectory |
|
256 |
$folder=opendir(WB_PATH.'/modules/droplets/example/.'); |
|
257 |
$names = array(); |
|
258 |
while ($file = readdir($folder)) { |
|
259 |
$ext=strtolower(substr($file,-4)); |
|
260 |
if ($ext==".php"){ |
|
261 |
if ($file<>"index.php" ) { |
|
262 |
$names[count($names)] = $file; |
|
263 |
} |
|
264 |
} |
|
265 |
} |
|
266 |
closedir($folder); |
|
267 |
|
|
268 |
foreach ($names as $dropfile) { |
|
269 |
$droplet = addslashes(getDropletCodeFromFile($dropfile)); |
|
270 |
if ($droplet != "") { |
|
271 |
$description = "Example Droplet"; |
|
272 |
$comments = "Example Droplet"; |
|
273 |
$cArray = explode("\n",$droplet); |
|
274 |
if (substr($cArray[0],0,3) == "//:") { |
|
275 |
$description = trim(substr($cArray[0],3)); |
|
276 |
array_shift ( $cArray ); |
|
277 |
} |
|
278 |
if (substr($cArray[0],0,3) == "//:") { |
|
279 |
$comments = trim(substr($cArray[0],3)); |
|
280 |
array_shift ( $cArray ); |
|
281 |
} |
|
282 |
$droplet = implode ( "\n", $cArray ); |
|
283 |
$name = substr($dropfile,0,-4); |
|
284 |
$modified_when = mktime(); |
|
285 |
$modified_by = method_exists($admin, 'get_user_id') ? $admin->get_user_id() : 1; |
|
286 |
echo ($database->query("INSERT INTO `$table` |
|
287 |
(name, code, description, comments, active, modified_when, modified_by) |
|
288 |
VALUES |
|
289 |
('$name', '$droplet', '$description', '$comments', '1', '$modified_when', '$modified_by')"))? "$name: $OK<br />" : "$name: $FAIL<br />"; |
|
290 |
} |
|
291 |
} |
|
292 |
|
|
293 |
|
|
294 |
function getDropletCodeFromFile ( $dropletfile ) { |
|
295 |
$data = ""; |
|
296 |
$filename = WB_PATH."/modules/droplets/example/".$dropletfile; |
|
297 |
if (file_exists($filename)) { |
|
298 |
$filehandle = fopen ($filename, "r"); |
|
299 |
$data = fread ($filehandle, filesize ($filename)); |
|
300 |
fclose($filehandle); |
|
301 |
// unlink($filename); doesnt work in unix |
|
302 |
} |
|
303 |
return $data; |
|
304 |
} |
|
305 |
|
|
306 |
/********************************************************** |
|
233 | 307 |
* - Reload all addons |
234 | 308 |
*/ |
235 | 309 |
|
Also available in: Unified diff
Added install routine for droplets to the upgrade script