Project

General

Profile

« Previous | Next » 

Revision 1916

Added by Dietmar over 11 years ago

! /modules/droplets/ set to version 1.3.0
installing module with sql import
make upgrade.php compatible with upgrade-scrip.php

View differences:

install.php
5 5
 * @package         droplet
6 6
 * @author          Ruud Eisinga (Ruud) John (PCWacht)
7 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/
8
 * @copyright       2009-2013, WebsiteBaker Org. e.V.
9
 * @link            http://www.websitebaker.org/
11 10
 * @license         http://www.gnu.org/licenses/gpl.html
12 11
 * @platform        WebsiteBaker 2.8.x
13 12
 * @requirements    PHP 5.2.2 and higher
14 13
 * @version         $Id$
15
 * @filesource		$HeadURL$
14
 * @filesource      $HeadURL$
16 15
 * @lastmodified    $Date$
17 16
 *
18 17
 */
19 18
/* -------------------------------------------------------- */
20 19
// Must include code to stop this file being accessed directly
21 20
if(!defined('WB_PATH')) {
22

  
23 21
	require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
24 22
	throw new IllegalFileException();
25
}
26
/* -------------------------------------------------------- */
27

  
28
	// global $admin;
29

  
23
} else {
24
	if(!function_exists('insertDropletFile')) { require('droplets.functions.php'); }
25
	$database = WbDatabase::getInstance();
26
	$sError = '';
30 27
	$msg = array();
31
	$sql  = 'DROP TABLE IF EXISTS `'.TABLE_PREFIX.'mod_droplets` ';
32
	if( !$database->query($sql) ) {
33
		$msg[] = $database->get_error();
28
	$sBaseDir = realpath(dirname(__FILE__).'/example/');
29
	$sBaseDir    = rtrim(str_replace('\\', '/', $sBaseDir), '/').'/';
30
	// Create table
31
	if($database->SqlImport(dirname(__FILE__).'/sql/mod_droplet.sql','',false)){
32
		$aDropletFiles = getDropletFromFiles($sBaseDir);
33
		$bOverwriteDroplets = true;
34
		insertDropletFile($aDropletFiles,$msg,$bOverwriteDroplets,$admin);
34 35
	}
35 36

  
36
	$sql  = 'CREATE TABLE IF NOT EXISTS `'.TABLE_PREFIX.'mod_droplets` ( ';
37
	$sql .= '`id` INT NOT NULL auto_increment, ';
38
	$sql .= '`name` VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci  NOT NULL, ';
39
	$sql .= '`code` LONGTEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci  NOT NULL , ';
40
	$sql .= '`description` TEXT  CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, ';
41
	$sql .= '`modified_when` INT NOT NULL default \'0\', ';
42
	$sql .= '`modified_by` INT NOT NULL default \'0\', ';
43
	$sql .= '`active` INT NOT NULL default \'0\', ';
44
	$sql .= '`admin_edit` INT NOT NULL default \'0\', ';
45
	$sql .= '`admin_view` INT NOT NULL default \'0\', ';
46
	$sql .= '`show_wysiwyg` INT NOT NULL default \'0\', ';
47
	$sql .= '`comments` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci  NOT NULL, ';
48
	$sql .= 'PRIMARY KEY ( `id` ) ';
49
	$sql .= ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci';
50
	if( !$database->query($sql) ) {
51
		$msg[] = $database->get_error();
52
	}
53

  
54
	//add all droplets from the droplet subdirectory
55
	$folder=opendir(WB_PATH.'/modules/droplets/example/.');
56
	$names = array();
57
	while ($file = readdir($folder)) {
58
		$ext=strtolower(substr($file,-4));
59
		if ($ext==".php"){
60
			if ($file<>"index.php" ) {
61
				$names[count($names)] = $file;
62
			}
63
		}
64
	}
65
	closedir($folder);
66

  
67
	foreach ($names as $dropfile)
68
	{
69
		$droplet = addslashes(getDropletCodeFromFile($dropfile));
70
		if ($droplet != "")
71
		{
72
			$description = "Example Droplet";
73
			$comments = "Example Droplet";
74
			$cArray = explode("\n",$droplet);
75
			if (substr($cArray[0],0,3) == "//:") {
76
				$description = trim(substr($cArray[0],3));
77
				array_shift ( $cArray );
78
			}
79
			if (substr($cArray[0],0,3) == "//:") {
80
				$comments = trim(substr($cArray[0],3));
81
				array_shift ( $cArray );
82
			}
83
			$droplet = implode ( "\n", $cArray );
84
			$name = substr($dropfile,0,-4);
85
			$modified_when = time();
86
			$modified_by = (method_exists($admin, 'get_user_id') && ($admin->get_user_id()!=null) ? $admin->get_user_id() : 1);
87
			$sql  = 'INSERT INTO `'.TABLE_PREFIX.'mod_droplets` SET ';
88
			$sql .= '`name` = \''.$name.'\', ';
89
			$sql .= '`code` = \''.$droplet.'\', ';
90
			$sql .= '`description` = \''.$description.'\', ';
91
			$sql .= '`comments` = \''.$comments.'\', ';
92
			$sql .= '`active` = 1, ';
93
			$sql .= '`modified_when` = '.$modified_when.', ';
94
			$sql .= '`modified_by` = '.$modified_by;
95
			if( !$database->query($sql) ) {
96
				$msg[] = $database->get_error();
97
			}
98
			// do not output anything if this script is called during fresh installation
99
			// if (method_exists($admin, 'get_user_id')) echo "Droplet import: $name<br/>";
100
		}
101
	}
102

  
103
	function getDropletCodeFromFile ( $dropletfile ) {
104
		$data = '';
105
		$filename = WB_PATH."/modules/droplets/example/".$dropletfile;
106
		if (file_exists($filename)) {
107
			$filehandle = fopen ($filename, "r");
108
			$data = fread ($filehandle, filesize ($filename));
109
			fclose($filehandle);
110
			// unlink($filename); doesnt work in unix
111
		}
112
		return $data;
113
	}
37
}

Also available in: Unified diff