Project

General

Profile

« Previous | Next » 

Revision 1296

Added by Dietmar over 14 years ago

update headerinfo in module droplets

View differences:

install.php
1
<?php
2

  
3
// $Id$
4

  
5
/*
6
*	@version	1.0
7
*	@author		Ruud Eisinga (Ruud) John (PCWacht)
8
*	@date		June 2009
9
*
10
*	droplets are small codeblocks that are called from anywhere in the template. 
11
* 	To call a droplet just use [[dropletname]]. optional parameters for a droplet can be used like [[dropletname?parameter=value&parameter2=value]]
12
*/
13

  
14
// prevent this file from being accessed directly
15
if(!defined('WB_PATH')) die(header('Location: ../../index.php'));
16

  
17
global $admin;
18

  
19
$table = TABLE_PREFIX .'mod_droplets';
20
$database->query("DROP TABLE IF EXISTS `$table`");
21

  
22
$database->query("CREATE TABLE `$table` (
23
	`id` INT NOT NULL auto_increment,
24
	`name` VARCHAR(32) NOT NULL,
25
	`code` LONGTEXT NOT NULL ,
26
	`description` TEXT NOT NULL,
27
	`modified_when` INT NOT NULL default '0',
28
	`modified_by` INT NOT NULL default '0',
29
	`active` INT NOT NULL default '0',
30
	`admin_edit` INT NOT NULL default '0',
31
	`admin_view` INT NOT NULL default '0',
32
	`show_wysiwyg` INT NOT NULL default '0',
33
	`comments` TEXT NOT NULL,
34
	PRIMARY KEY ( `id` )
35
	)"
36
);
37

  
38
//add all droplets from the droplet subdirectory
39
$folder=opendir(WB_PATH.'/modules/droplets/example/.'); 
40
$names = array();
41
while ($file = readdir($folder)) {
42
	$ext=strtolower(substr($file,-4));
43
	if ($ext==".php"){
44
		if ($file<>"index.php" ) {
45
			$names[count($names)] = $file; 
46
		}
47
	}
48
}
49
closedir($folder);
50

  
51
foreach ($names as $dropfile) {
52
	$droplet = addslashes(getDropletCodeFromFile($dropfile));
53
	if ($droplet != "") {
54
		$description = "Example Droplet";
55
		$comments = "Example Droplet";
56
		$cArray = explode("\n",$droplet);
57
		if (substr($cArray[0],0,3) == "//:") {
58
			$description = trim(substr($cArray[0],3));
59
			array_shift ( $cArray );
60
		}
61
		if (substr($cArray[0],0,3) == "//:") {
62
			$comments = trim(substr($cArray[0],3));
63
			array_shift ( $cArray );
64
		}
65
		$droplet = implode ( "\n", $cArray );
66
		$name = substr($dropfile,0,-4);
67
		$modified_when = time();
68
		$modified_by = method_exists($admin, 'get_user_id') ? $admin->get_user_id() : 1;
69
		$database->query("INSERT INTO `$table`  
70
			(name, code, description, comments, active, modified_when, modified_by) 
71
			VALUES 
72
			('$name', '$droplet', '$description', '$comments', '1', '$modified_when', '$modified_by')");
73
		
74
		// do not output anything if this script is called during fresh installation
75
		if (method_exists($admin, 'get_user_id')) echo "Droplet import: $name<br/>";
76
	}  
77
}
78

  
79
function getDropletCodeFromFile ( $dropletfile ) {
80
	$data = "";
81
	$filename = WB_PATH."/modules/droplets/example/".$dropletfile;
82
	if (file_exists($filename)) {
83
		$filehandle = fopen ($filename, "r");
84
		$data = fread ($filehandle, filesize ($filename));
85
		fclose($filehandle);
86
		// unlink($filename); doesnt work in unix
87
	}	
88
	return $data;
89
}
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-2010, 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 4.4.9 and higher
14
 * @version         $Id$
15
 * @filesource		$HeadURL$
16
 * @lastmodified    $Date$
17
 *
18
 */
19

  
20
// prevent this file from being accessed directly
21
if(!defined('WB_PATH')) die(header('Location: ../../index.php'));
22

  
23
global $admin;
24

  
25
$table = TABLE_PREFIX .'mod_droplets';
26
$database->query("DROP TABLE IF EXISTS `$table`");
27

  
28
$database->query("CREATE TABLE `$table` (
29
	`id` INT NOT NULL auto_increment,
30
	`name` VARCHAR(32) NOT NULL,
31
	`code` LONGTEXT NOT NULL ,
32
	`description` TEXT NOT NULL,
33
	`modified_when` INT NOT NULL default '0',
34
	`modified_by` INT NOT NULL default '0',
35
	`active` INT NOT NULL default '0',
36
	`admin_edit` INT NOT NULL default '0',
37
	`admin_view` INT NOT NULL default '0',
38
	`show_wysiwyg` INT NOT NULL default '0',
39
	`comments` TEXT NOT NULL,
40
	PRIMARY KEY ( `id` )
41
	)"
42
);
43

  
44
//add all droplets from the droplet subdirectory
45
$folder=opendir(WB_PATH.'/modules/droplets/example/.'); 
46
$names = array();
47
while ($file = readdir($folder)) {
48
	$ext=strtolower(substr($file,-4));
49
	if ($ext==".php"){
50
		if ($file<>"index.php" ) {
51
			$names[count($names)] = $file; 
52
		}
53
	}
54
}
55
closedir($folder);
56

  
57
foreach ($names as $dropfile) {
58
	$droplet = addslashes(getDropletCodeFromFile($dropfile));
59
	if ($droplet != "") {
60
		$description = "Example Droplet";
61
		$comments = "Example Droplet";
62
		$cArray = explode("\n",$droplet);
63
		if (substr($cArray[0],0,3) == "//:") {
64
			$description = trim(substr($cArray[0],3));
65
			array_shift ( $cArray );
66
		}
67
		if (substr($cArray[0],0,3) == "//:") {
68
			$comments = trim(substr($cArray[0],3));
69
			array_shift ( $cArray );
70
		}
71
		$droplet = implode ( "\n", $cArray );
72
		$name = substr($dropfile,0,-4);
73
		$modified_when = time();
74
		$modified_by = method_exists($admin, 'get_user_id') ? $admin->get_user_id() : 1;
75
		$database->query("INSERT INTO `$table`  
76
			(name, code, description, comments, active, modified_when, modified_by) 
77
			VALUES 
78
			('$name', '$droplet', '$description', '$comments', '1', '$modified_when', '$modified_by')");
79
		
80
		// do not output anything if this script is called during fresh installation
81
		if (method_exists($admin, 'get_user_id')) echo "Droplet import: $name<br/>";
82
	}  
83
}
84

  
85
function getDropletCodeFromFile ( $dropletfile ) {
86
	$data = "";
87
	$filename = WB_PATH."/modules/droplets/example/".$dropletfile;
88
	if (file_exists($filename)) {
89
		$filehandle = fopen ($filename, "r");
90
		$data = fread ($filehandle, filesize ($filename));
91
		fclose($filehandle);
92
		// unlink($filename); doesnt work in unix
93
	}	
94
	return $data;
95
}
90 96
?>
91 97

  

Also available in: Unified diff