Project

General

Profile

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
// do not display notices and warnings during installation
20
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
21
22
// Setup admin object
23
require('../../config.php');
24
require_once(WB_PATH.'/framework/class.admin.php');
25 1457 Luisehahne
$admin = new admin('Addons', 'modules_install', false);
26
if( !$admin->checkFTAN() )
27
{
28 1467 Luisehahne
	$admin->print_header();
29 1457 Luisehahne
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
30
}
31
// After check print the header
32
$admin->print_header();
33 1352 Luisehahne
34 1457 Luisehahne
// Check if user uploaded a file
35
if(!isset($_FILES['userfile'])) {
36
	header("Location: index.php");
37
	exit(0);
38
}
39
40 1352 Luisehahne
// 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
{
51
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UPLOAD']);
52
}
53
54
// Include the PclZip class file (thanks to
55
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
56
57
// Remove any vars with name "module_directory"
58
unset($module_directory);
59
60
// Setup the PclZip object
61
$archive = new PclZip($temp_file);
62
// Unzip the files to the temp unzip folder
63
$list = $archive->extract(PCLZIP_OPT_PATH, $temp_unzip);
64
65
// Check if uploaded file is a valid Add-On zip file
66
if (!($list && file_exists($temp_unzip . 'index.php')))
67
{
68
  $admin->print_error($MESSAGE['GENERIC']['INVALID_ADDON_FILE']);
69
}
70
71
// Include the modules info file
72
require($temp_unzip.'info.php');
73
74
// Perform Add-on requirement checks before proceeding
75
require(WB_PATH . '/framework/addon.precheck.inc.php');
76
preCheckAddon($temp_file);
77
// Delete the temp unzip directory
78
rm_full_dir($temp_unzip);
79
80
// Check if the file is valid
81
if(!isset($module_directory))
82
{
83
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
84
	$admin->print_error($MESSAGE['GENERIC']['INVALID']);
85
}
86
87
// Check if this module is already installed
88
// and compare versions if so
89
$new_module_version = $module_version;
90
$action="install";
91
if(is_dir(WB_PATH.'/modules/'.$module_directory))
92
{
93
	if(file_exists(WB_PATH.'/modules/'.$module_directory.'/info.php'))
94
    {
95
		require(WB_PATH.'/modules/'.$module_directory.'/info.php');
96
		// Version to be installed is older than currently installed version
97
		if (versionCompare($module_version, $new_module_version, '>='))
98
        {
99
100
			if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
101
			$admin->print_error($MESSAGE['GENERIC']['ALREADY_INSTALLED']);
102
		}
103
104
		$action="upgrade";
105
106
	}
107
}
108
109
// Check if module dir is writable
110
if(!is_writable(WB_PATH.'/modules/'))
111
{
112
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
113
	$admin->print_error($MESSAGE['GENERIC']['BAD_PERMISSIONS']);
114
}
115
116
// Set module directory
117
$module_dir = WB_PATH.'/modules/'.$module_directory;
118
119
// Make sure the module dir exists, and chmod if needed
120
make_dir($module_dir);
121
122
// Unzip module to the module dir
123 1381 Luisehahne
if(isset($_POST['overwrite'])){
124 1361 Luisehahne
	$list = $archive->extract(PCLZIP_OPT_PATH, $module_dir, PCLZIP_OPT_REPLACE_NEWER );
125
} else {
126
	$list = $archive->extract(PCLZIP_OPT_PATH, $module_dir );
127
}
128 1352 Luisehahne
129
if(!$list)
130
{
131
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNZIP']);
132
}
133 1361 Luisehahne
/*
134 1352 Luisehahne
135 1361 Luisehahne
if ($list == 0) {
136
  $admin->print_error("ERROR : ".$archive->errorInfo(true));
137
}
138
*/
139 1352 Luisehahne
// Delete the temp zip file
140
if(file_exists($temp_file)) { unlink($temp_file); }
141
142
// Chmod all the uploaded files
143
$dir = dir($module_dir);
144
while (false !== $entry = $dir->read())
145
{
146
	// Skip pointers
147
	if(substr($entry, 0, 1) != '.' AND $entry != '.svn' AND !is_dir($module_dir.'/'.$entry))
148
    {
149
		// Chmod file
150
		change_mode($module_dir.'/'.$entry, 'file');
151
	}
152
}
153 1361 Luisehahne
/* */
154 1352 Luisehahne
// Run the modules install // upgrade script if there is one
155
if(file_exists($module_dir.'/'.$action.'.php'))
156
{
157
	require($module_dir.'/'.$action.'.php');
158
}
159 1361 Luisehahne
160 1352 Luisehahne
// Print success message
161
if ($action=="install")
162
{
163
	// Load module info into DB
164
	load_module(WB_PATH.'/modules/'.$module_directory, false);
165
	$admin->print_success($MESSAGE['GENERIC']['INSTALLED']);
166
} elseif ($action=="upgrade")
167
{
168 1381 Luisehahne
169 1361 Luisehahne
	upgrade_module($module_directory, false);
170 1352 Luisehahne
	$admin->print_success($MESSAGE['GENERIC']['UPGRADED']);
171 1361 Luisehahne
}
172 1352 Luisehahne
173
// Print admin footer
174
$admin->print_footer();
175
176 170 ryan
?>