1 |
1352
|
Luisehahne
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
*
|
4 |
|
|
* @category admin
|
5 |
|
|
* @package modules
|
6 |
|
|
* @author WebsiteBaker Project
|
7 |
|
|
* @copyright 2004-2009, Ryan Djurovich
|
8 |
|
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
9 |
|
|
* @link http://www.websitebaker2.org/
|
10 |
|
|
* @license http://www.gnu.org/licenses/gpl.html
|
11 |
|
|
* @platform WebsiteBaker 2.8.x
|
12 |
1374
|
Luisehahne
|
* @requirements PHP 5.2.2 and higher
|
13 |
1352
|
Luisehahne
|
* @version $Id$
|
14 |
|
|
* @filesource $HeadURL$
|
15 |
|
|
* @lastmodified $Date$
|
16 |
|
|
*
|
17 |
|
|
*/
|
18 |
|
|
|
19 |
|
|
// Check if user uploaded a file
|
20 |
|
|
if(!isset($_FILES['userfile'])) {
|
21 |
|
|
header("Location: index.php");
|
22 |
|
|
exit(0);
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
// do not display notices and warnings during installation
|
26 |
|
|
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
|
27 |
|
|
|
28 |
|
|
// Setup admin object
|
29 |
|
|
require('../../config.php');
|
30 |
|
|
require_once(WB_PATH.'/framework/class.admin.php');
|
31 |
|
|
$admin = new admin('Addons', 'modules_install');
|
32 |
|
|
|
33 |
|
|
// Include the WB functions file
|
34 |
|
|
require_once(WB_PATH.'/framework/functions.php');
|
35 |
|
|
|
36 |
|
|
// Set temp vars
|
37 |
|
|
$temp_dir = WB_PATH.'/temp/';
|
38 |
|
|
$temp_file = $temp_dir . $_FILES['userfile']['name'];
|
39 |
|
|
$temp_unzip = WB_PATH.'/temp/unzip/';
|
40 |
|
|
|
41 |
|
|
// Try to upload the file to the temp dir
|
42 |
|
|
if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file))
|
43 |
|
|
{
|
44 |
|
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UPLOAD']);
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
// Include the PclZip class file (thanks to
|
48 |
|
|
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
|
49 |
|
|
|
50 |
|
|
// Remove any vars with name "module_directory"
|
51 |
|
|
unset($module_directory);
|
52 |
|
|
|
53 |
|
|
// Setup the PclZip object
|
54 |
|
|
$archive = new PclZip($temp_file);
|
55 |
|
|
// Unzip the files to the temp unzip folder
|
56 |
|
|
$list = $archive->extract(PCLZIP_OPT_PATH, $temp_unzip);
|
57 |
|
|
|
58 |
|
|
// Check if uploaded file is a valid Add-On zip file
|
59 |
|
|
if (!($list && file_exists($temp_unzip . 'index.php')))
|
60 |
|
|
{
|
61 |
|
|
$admin->print_error($MESSAGE['GENERIC']['INVALID_ADDON_FILE']);
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
// Include the modules info file
|
65 |
|
|
require($temp_unzip.'info.php');
|
66 |
|
|
|
67 |
|
|
// Perform Add-on requirement checks before proceeding
|
68 |
|
|
require(WB_PATH . '/framework/addon.precheck.inc.php');
|
69 |
|
|
preCheckAddon($temp_file);
|
70 |
|
|
// Delete the temp unzip directory
|
71 |
|
|
rm_full_dir($temp_unzip);
|
72 |
|
|
|
73 |
|
|
// Check if the file is valid
|
74 |
|
|
if(!isset($module_directory))
|
75 |
|
|
{
|
76 |
|
|
if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
|
77 |
|
|
$admin->print_error($MESSAGE['GENERIC']['INVALID']);
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
// Check if this module is already installed
|
81 |
|
|
// and compare versions if so
|
82 |
|
|
$new_module_version = $module_version;
|
83 |
|
|
$action="install";
|
84 |
|
|
if(is_dir(WB_PATH.'/modules/'.$module_directory))
|
85 |
|
|
{
|
86 |
|
|
if(file_exists(WB_PATH.'/modules/'.$module_directory.'/info.php'))
|
87 |
|
|
{
|
88 |
|
|
require(WB_PATH.'/modules/'.$module_directory.'/info.php');
|
89 |
|
|
// Version to be installed is older than currently installed version
|
90 |
|
|
if (versionCompare($module_version, $new_module_version, '>='))
|
91 |
|
|
{
|
92 |
|
|
|
93 |
|
|
if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
|
94 |
|
|
$admin->print_error($MESSAGE['GENERIC']['ALREADY_INSTALLED']);
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
$action="upgrade";
|
98 |
|
|
|
99 |
|
|
}
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
// Check if module dir is writable
|
103 |
|
|
if(!is_writable(WB_PATH.'/modules/'))
|
104 |
|
|
{
|
105 |
|
|
if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
|
106 |
|
|
$admin->print_error($MESSAGE['GENERIC']['BAD_PERMISSIONS']);
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
// Set module directory
|
110 |
|
|
$module_dir = WB_PATH.'/modules/'.$module_directory;
|
111 |
|
|
|
112 |
|
|
// Make sure the module dir exists, and chmod if needed
|
113 |
|
|
make_dir($module_dir);
|
114 |
|
|
|
115 |
|
|
// Unzip module to the module dir
|
116 |
1361
|
Luisehahne
|
if(isset($POST['overwrite']) && intval($POST['overwrite'])==1){
|
117 |
|
|
$list = $archive->extract(PCLZIP_OPT_PATH, $module_dir, PCLZIP_OPT_REPLACE_NEWER );
|
118 |
|
|
} else {
|
119 |
|
|
$list = $archive->extract(PCLZIP_OPT_PATH, $module_dir );
|
120 |
|
|
}
|
121 |
1352
|
Luisehahne
|
|
122 |
|
|
if(!$list)
|
123 |
|
|
{
|
124 |
|
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNZIP']);
|
125 |
|
|
}
|
126 |
1361
|
Luisehahne
|
/*
|
127 |
1352
|
Luisehahne
|
|
128 |
1361
|
Luisehahne
|
if ($list == 0) {
|
129 |
|
|
$admin->print_error("ERROR : ".$archive->errorInfo(true));
|
130 |
|
|
}
|
131 |
|
|
*/
|
132 |
1352
|
Luisehahne
|
// Delete the temp zip file
|
133 |
|
|
if(file_exists($temp_file)) { unlink($temp_file); }
|
134 |
|
|
|
135 |
|
|
// Chmod all the uploaded files
|
136 |
|
|
$dir = dir($module_dir);
|
137 |
|
|
while (false !== $entry = $dir->read())
|
138 |
|
|
{
|
139 |
|
|
// Skip pointers
|
140 |
|
|
if(substr($entry, 0, 1) != '.' AND $entry != '.svn' AND !is_dir($module_dir.'/'.$entry))
|
141 |
|
|
{
|
142 |
|
|
// Chmod file
|
143 |
|
|
change_mode($module_dir.'/'.$entry, 'file');
|
144 |
|
|
}
|
145 |
|
|
}
|
146 |
1361
|
Luisehahne
|
/* */
|
147 |
1352
|
Luisehahne
|
// Run the modules install // upgrade script if there is one
|
148 |
|
|
if(file_exists($module_dir.'/'.$action.'.php'))
|
149 |
|
|
{
|
150 |
|
|
require($module_dir.'/'.$action.'.php');
|
151 |
|
|
}
|
152 |
1361
|
Luisehahne
|
|
153 |
1352
|
Luisehahne
|
// Print success message
|
154 |
|
|
if ($action=="install")
|
155 |
|
|
{
|
156 |
|
|
// Load module info into DB
|
157 |
|
|
load_module(WB_PATH.'/modules/'.$module_directory, false);
|
158 |
|
|
$admin->print_success($MESSAGE['GENERIC']['INSTALLED']);
|
159 |
|
|
} elseif ($action=="upgrade")
|
160 |
|
|
{
|
161 |
1361
|
Luisehahne
|
upgrade_module($module_directory, false);
|
162 |
1352
|
Luisehahne
|
$admin->print_success($MESSAGE['GENERIC']['UPGRADED']);
|
163 |
1361
|
Luisehahne
|
}
|
164 |
1352
|
Luisehahne
|
|
165 |
|
|
// Print admin footer
|
166 |
|
|
$admin->print_footer();
|
167 |
|
|
|
168 |
170
|
ryan
|
?>
|