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
// Setup admin object
33
require('../../config.php');
34
require_once(WB_PATH.'/framework/class.admin.php');
35
$admin = new admin('Addons', 'modules_install');
36
37
// Include the WB functions file
38
require_once(WB_PATH.'/framework/functions.php');
39
40
// Set temp vars
41
$temp_dir = WB_PATH.'/temp/';
42
$temp_file = $temp_dir . $_FILES['userfile']['name'];
43
$temp_unzip = WB_PATH.'/temp/unzip/';
44
45
// Try to upload the file to the temp dir
46
if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file)) {
47
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UPLOAD']);
48
}
49
50
// Include the PclZip class file (thanks to
51
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
52
53
// Remove any vars with name "module_directory"
54
unset($module_directory);
55
56
// Setup the PclZip object
57
$archive = new PclZip($temp_file);
58
// Unzip the files to the temp unzip folder
59 99 stefan
$list = $archive->extract(PCLZIP_OPT_PATH, $temp_unzip);
60 4 ryan
// Include the modules info file
61
require($temp_unzip.'info.php');
62
// Delete the temp unzip directory
63
rm_full_dir($temp_unzip);
64
65
// Check if the file is valid
66
if(!isset($module_directory)) {
67
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
68
	$admin->print_error($MESSAGE['GENERIC']['INVALID']);
69
}
70
71 67 stefan
// Check if this module is already installed
72
// and compare versions if so
73
$new_module_version=$module_version;
74 68 stefan
$action="install";
75 4 ryan
if(is_dir(WB_PATH.'/modules/'.$module_directory)) {
76 67 stefan
	if(file_exists(WB_PATH.'/modules/'.$module_directory.'/info.php')) {
77
		require(WB_PATH.'/modules/'.$module_directory.'/info.php');
78
		// Version to be installed is older than currently installed version
79 535 doc
		if ($module_version>=$new_module_version) {
80 67 stefan
			if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
81
			$admin->print_error($MESSAGE['GENERIC']['ALREADY_INSTALLED']);
82
		}
83
		$action="upgrade";
84 99 stefan
	}
85 4 ryan
}
86
87
// Check if module dir is writable
88
if(!is_writable(WB_PATH.'/modules/')) {
89
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
90
	$admin->print_error($MESSAGE['GENERIC']['BAD_PERMISSIONS']);
91
}
92
93
// Set module directory
94
$module_dir = WB_PATH.'/modules/'.$module_directory;
95
96
// Make sure the module dir exists, and chmod if needed
97
make_dir($module_dir);
98
99
// Unzip module to the module dir
100 101 stefan
$list = $archive->extract(PCLZIP_OPT_PATH, $module_dir);
101 4 ryan
if(!$list) {
102
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNZIP']);
103
}
104
105
// Delete the temp zip file
106
if(file_exists($temp_file)) { unlink($temp_file); }
107
108
// Chmod all the uploaded files
109
$dir = dir($module_dir);
110
while (false !== $entry = $dir->read()) {
111
	// Skip pointers
112 8 stefan
	if(substr($entry, 0, 1) != '.' AND $entry != '.svn' AND !is_dir($module_dir.'/'.$entry)) {
113 4 ryan
		// Chmod file
114
		change_mode($module_dir.'/'.$entry, 'file');
115
	}
116
}
117
118 67 stefan
// Run the modules install // upgrade script if there is one
119
if(file_exists(WB_PATH.'/modules/'.$module_directory.'/'.$action.'.php')) {
120
	require(WB_PATH.'/modules/'.$module_directory.'/'.$action.'.php');
121 4 ryan
}
122
123
// Print success message
124 99 stefan
if ($action=="install") {
125 209 stefan
	// Load module info into DB
126
	load_module(WB_PATH.'/modules/'.$module_directory, false);
127 114 stefan
	$admin->print_success($MESSAGE['GENERIC']['INSTALLED']);
128 99 stefan
} else if ($action=="upgrade") {
129 373 Ruebenwurz
	upgrade_module($module_directory, false);
130 68 stefan
	$admin->print_success($MESSAGE['GENERIC']['UPGRADED']);
131
}
132 4 ryan
133
// Print admin footer
134
$admin->print_footer();
135
136 170 ryan
?>