Project

General

Profile

1 4 ryan
<?php
2
3 67 stefan
// $Id$
4 4 ryan
5
/*
6
7
 Website Baker Project <http://www.websitebaker.org/>
8 915 Ruebenwurz
 Copyright (C) 2004-2009, Ryan Djurovich
9 4 ryan
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
24
*/
25
26
// Check if user uploaded a file
27
if(!isset($_FILES['userfile'])) {
28
	header("Location: index.php");
29 286 stefan
	exit(0);
30 4 ryan
}
31
32 925 doc
// do not display notices and warnings during installation
33
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
34
35 4 ryan
// Setup admin object
36
require('../../config.php');
37
require_once(WB_PATH.'/framework/class.admin.php');
38
$admin = new admin('Addons', 'modules_install');
39
40
// Include the WB functions file
41
require_once(WB_PATH.'/framework/functions.php');
42
43
// Set temp vars
44
$temp_dir = WB_PATH.'/temp/';
45
$temp_file = $temp_dir . $_FILES['userfile']['name'];
46
$temp_unzip = WB_PATH.'/temp/unzip/';
47
48
// Try to upload the file to the temp dir
49
if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file)) {
50
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UPLOAD']);
51
}
52
53
// Include the PclZip class file (thanks to
54
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
55
56
// Remove any vars with name "module_directory"
57
unset($module_directory);
58
59
// Setup the PclZip object
60
$archive = new PclZip($temp_file);
61
// Unzip the files to the temp unzip folder
62 99 stefan
$list = $archive->extract(PCLZIP_OPT_PATH, $temp_unzip);
63 925 doc
64
// Check if uploaded file is a valid Add-On zip file
65
if (!($list && file_exists($temp_unzip . 'index.php'))) $admin->print_error($MESSAGE['GENERIC']['INVALID_ADDON_FILE']);
66
67 4 ryan
// Include the modules info file
68
require($temp_unzip.'info.php');
69 925 doc
70
// Perform Add-on requirement checks before proceeding
71
require(WB_PATH . '/framework/addon.precheck.inc.php');
72
preCheckAddon($temp_file);
73
74 4 ryan
// Delete the temp unzip directory
75
rm_full_dir($temp_unzip);
76
77
// Check if the file is valid
78
if(!isset($module_directory)) {
79
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
80
	$admin->print_error($MESSAGE['GENERIC']['INVALID']);
81
}
82
83 67 stefan
// Check if this module is already installed
84
// and compare versions if so
85
$new_module_version=$module_version;
86 68 stefan
$action="install";
87 4 ryan
if(is_dir(WB_PATH.'/modules/'.$module_directory)) {
88 67 stefan
	if(file_exists(WB_PATH.'/modules/'.$module_directory.'/info.php')) {
89
		require(WB_PATH.'/modules/'.$module_directory.'/info.php');
90
		// Version to be installed is older than currently installed version
91 925 doc
		if (versionCompare($module_version, $new_module_version, '>=')) {
92 67 stefan
			if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
93
			$admin->print_error($MESSAGE['GENERIC']['ALREADY_INSTALLED']);
94
		}
95
		$action="upgrade";
96 99 stefan
	}
97 4 ryan
}
98
99
// Check if module dir is writable
100
if(!is_writable(WB_PATH.'/modules/')) {
101
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
102
	$admin->print_error($MESSAGE['GENERIC']['BAD_PERMISSIONS']);
103
}
104
105
// Set module directory
106
$module_dir = WB_PATH.'/modules/'.$module_directory;
107
108
// Make sure the module dir exists, and chmod if needed
109
make_dir($module_dir);
110
111
// Unzip module to the module dir
112 101 stefan
$list = $archive->extract(PCLZIP_OPT_PATH, $module_dir);
113 4 ryan
if(!$list) {
114
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNZIP']);
115
}
116
117
// Delete the temp zip file
118
if(file_exists($temp_file)) { unlink($temp_file); }
119
120
// Chmod all the uploaded files
121
$dir = dir($module_dir);
122
while (false !== $entry = $dir->read()) {
123
	// Skip pointers
124 8 stefan
	if(substr($entry, 0, 1) != '.' AND $entry != '.svn' AND !is_dir($module_dir.'/'.$entry)) {
125 4 ryan
		// Chmod file
126
		change_mode($module_dir.'/'.$entry, 'file');
127
	}
128
}
129
130 67 stefan
// Run the modules install // upgrade script if there is one
131
if(file_exists(WB_PATH.'/modules/'.$module_directory.'/'.$action.'.php')) {
132
	require(WB_PATH.'/modules/'.$module_directory.'/'.$action.'.php');
133 4 ryan
}
134
135
// Print success message
136 99 stefan
if ($action=="install") {
137 209 stefan
	// Load module info into DB
138
	load_module(WB_PATH.'/modules/'.$module_directory, false);
139 114 stefan
	$admin->print_success($MESSAGE['GENERIC']['INSTALLED']);
140 99 stefan
} else if ($action=="upgrade") {
141 373 Ruebenwurz
	upgrade_module($module_directory, false);
142 68 stefan
	$admin->print_success($MESSAGE['GENERIC']['UPGRADED']);
143
}
144 4 ryan
145
// Print admin footer
146
$admin->print_footer();
147
148 170 ryan
?>