Revision 995
Added by aldus over 16 years ago
| trunk/wb/upgrade-script.php | ||
|---|---|---|
| 233 | 233 |
* - install droplets |
| 234 | 234 |
*/ |
| 235 | 235 |
echo "<br />Install droplets<br />"; |
| 236 |
$table = TABLE_PREFIX .'mod_droplets'; |
|
| 237 |
$database->query("DROP TABLE IF EXISTS `$table`");
|
|
| 238 | 236 |
|
| 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 |
); |
|
| 237 |
$result = mysql_list_tables( DB_NAME ); |
|
| 238 |
$all_tables = array(); |
|
| 239 |
for($i=0; $i < mysql_num_rows($result); $i++) $all_tables[] = mysql_table_name($result, $i); |
|
| 254 | 240 |
|
| 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); |
|
| 241 |
$file_name = (!in_array ( TABLE_PREFIX."mod_droplets", $all_tables)) ? "install.php" : "upgrade.php"; |
|
| 242 |
require_once (WB_PATH."/modules/droplets/".$file_name); |
|
| 267 | 243 |
|
| 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 | 244 |
/********************************************************** |
| 307 | 245 |
* - Reload all addons |
| 308 | 246 |
*/ |
| trunk/wb/modules/droplets/install.php | ||
|---|---|---|
| 12 | 12 |
*/ |
| 13 | 13 |
|
| 14 | 14 |
// prevent this file from being accessed directly |
| 15 |
if(!defined('WB_PATH')) die(header('Location: ../index.php'));
|
|
| 15 |
if(!defined('WB_PATH')) die(header('Location: ../../index.php'));
|
|
| 16 | 16 |
|
| 17 | 17 |
$table = TABLE_PREFIX .'mod_droplets'; |
| 18 | 18 |
$database->query("DROP TABLE IF EXISTS `$table`");
|
| ... | ... | |
| 74 | 74 |
} |
| 75 | 75 |
} |
| 76 | 76 |
|
| 77 |
|
|
| 78 | 77 |
function getDropletCodeFromFile ( $dropletfile ) {
|
| 79 | 78 |
$data = ""; |
| 80 | 79 |
$filename = WB_PATH."/modules/droplets/example/".$dropletfile; |
| trunk/wb/modules/droplets/languages/EN.php | ||
|---|---|---|
| 34 | 34 |
$DR_TEXT['ADMIN_VIEW'] = 'View-Only'; |
| 35 | 35 |
$DR_TEXT['WYSIWYG'] = 'Wysiwyg'; |
| 36 | 36 |
$DR_TEXT['HELP'] = 'Help / Readme'; |
| 37 |
$DR_TEXT['USED'] = 'This droplet is used on the following page(-s):<br />'; |
|
| 37 | 38 |
|
| 38 | 39 |
?> |
| trunk/wb/modules/droplets/upgrade.php | ||
|---|---|---|
| 12 | 12 |
* To call a droplet just use [[dropletname]]. optional parameters for a droplet can be used like [[dropletname?parameter=value¶meter2=value]] |
| 13 | 13 |
*/ |
| 14 | 14 |
|
| 15 |
if(!defined('WB_PATH')) { exit("Cannot access this file directly"); }
|
|
| 15 |
if(!defined('WB_PATH')) die(header('Location: ../../index.php'));
|
|
| 16 | 16 |
|
| 17 |
$table = TABLE_PREFIX .'mod_droplets'; |
|
| 18 |
|
|
| 19 |
$info = $database->query("SELECT * from `$table` limit 0,1" );
|
|
| 20 |
$fields = $info->fetchRow(); |
|
| 21 |
if (!array_key_exists("look_for_it", $fields)) {
|
|
| 22 |
/** |
|
| 23 |
* Call from the upgrade-script |
|
| 24 |
*/ |
|
| 25 |
|
|
| 26 |
if (function_exists('db_add_field')) {
|
|
| 27 |
db_add_field($table, "admin_edit", "INT NOT NULL default '0'"); |
|
| 28 |
db_add_field($table, "admin_view", "INT NOT NULL default '0'"); |
|
| 29 |
db_add_field($table, "show_wysiwyg", "INT NOT NULL default '0'"); |
|
| 30 |
} else {
|
|
| 31 |
/** |
|
| 32 |
* Not call by the upgrade-script |
|
| 33 |
*/ |
|
| 34 |
$database->query("ALTER TABLE `$table` (
|
|
| 35 |
`admin_edit` INT NOT NULL default '0', |
|
| 36 |
`admin_view` INT NOT NULL default '0', |
|
| 37 |
`show_wysiwyg` INT NOT NULL default '0' |
|
| 38 |
)"; |
|
| 39 |
} |
|
| 40 |
} |
|
| 17 | 41 |
?> |
Also available in: Unified diff
update upgrade-script to avoid droping droplet-tables if the modul still exists. Add an upgrade-script to the droplets.