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