1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category module
|
5
|
* @package droplet
|
6
|
* @author Ruud Eisinga (Ruud) John (PCWacht)
|
7
|
* @author WebsiteBaker Project
|
8
|
* @copyright 2004-2009, Ryan Djurovich
|
9
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
10
|
* @link http://www.websitebaker2.org/
|
11
|
* @license http://www.gnu.org/licenses/gpl.html
|
12
|
* @platform WebsiteBaker 2.8.x
|
13
|
* @requirements PHP 5.2.2 and higher
|
14
|
* @version $Id: install.php 1503 2011-08-18 02:18:59Z Luisehahne $
|
15
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/droplets/install.php $
|
16
|
* @lastmodified $Date: 2011-08-18 04:18:59 +0200 (Thu, 18 Aug 2011) $
|
17
|
*
|
18
|
*/
|
19
|
/* -------------------------------------------------------- */
|
20
|
// Must include code to stop this file being accessed directly
|
21
|
if(!defined('WB_PATH')) {
|
22
|
|
23
|
require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
|
24
|
throw new IllegalFileException();
|
25
|
}
|
26
|
/* -------------------------------------------------------- */
|
27
|
|
28
|
global $admin;
|
29
|
|
30
|
$sql = 'DROP TABLE IF EXISTS `'.TABLE_PREFIX.'mod_droplets` ';
|
31
|
$database->query($sql);
|
32
|
|
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);
|
48
|
|
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;
|
57
|
}
|
58
|
}
|
59
|
}
|
60
|
closedir($folder);
|
61
|
|
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 );
|
71
|
}
|
72
|
if (substr($cArray[0],0,3) == "//:") {
|
73
|
$comments = trim(substr($cArray[0],3));
|
74
|
array_shift ( $cArray );
|
75
|
}
|
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/>";
|
92
|
}
|
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
|
}
|