Project

General

Profile

1 1420 Luisehahne
<?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$
15
 * @filesource		$HeadURL$
16
 * @lastmodified    $Date$
17
 *
18
 */
19 1503 Luisehahne
/* -------------------------------------------------------- */
20
// Must include code to stop this file being accessed directly
21
if(!defined('WB_PATH')) {
22 1420 Luisehahne
23 1503 Luisehahne
	require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
24
	throw new IllegalFileException();
25
}
26
/* -------------------------------------------------------- */
27
28 1420 Luisehahne
global $admin;
29
30 1503 Luisehahne
$sql  = 'DROP TABLE IF EXISTS `'.TABLE_PREFIX.'mod_droplets` ';
31
$database->query($sql);
32 1420 Luisehahne
33 1503 Luisehahne
$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 1420 Luisehahne
49
//add all droplets from the droplet subdirectory
50 1503 Luisehahne
$folder=opendir(WB_PATH.'/modules/droplets/example/.');
51 1420 Luisehahne
$names = array();
52
while ($file = readdir($folder)) {
53
	$ext=strtolower(substr($file,-4));
54
	if ($ext==".php"){
55
		if ($file<>"index.php" ) {
56 1503 Luisehahne
			$names[count($names)] = $file;
57 1420 Luisehahne
		}
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 1533 Luisehahne
		$modified_by = (method_exists($admin, 'get_user_id') ? $admin->get_user_id() : 1);
80 1503 Luisehahne
		$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 1420 Luisehahne
90
		// do not output anything if this script is called during fresh installation
91 1533 Luisehahne
		// if (method_exists($admin, 'get_user_id')) echo "Droplet import: $name<br/>";
92 1503 Luisehahne
	}
93 1420 Luisehahne
}
94
95
function getDropletCodeFromFile ( $dropletfile ) {
96 1503 Luisehahne
	$data = '';
97 1420 Luisehahne
	$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
}