1
|
<?php
|
2
|
|
3
|
// $Id: install.php 1361 2010-12-29 04:45:13Z Luisehahne $
|
4
|
|
5
|
/*
|
6
|
|
7
|
Website Baker Project <http://www.websitebaker.org/>
|
8
|
Copyright (C) 2004-2009, 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
|
exit(0);
|
30
|
}
|
31
|
|
32
|
// do not display notices and warnings during installation
|
33
|
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
|
34
|
|
35
|
// Setup admin object
|
36
|
require('../../config.php');
|
37
|
require_once(WB_PATH.'/framework/class.admin.php');
|
38
|
$admin = new admin('Addons', 'templates_install');
|
39
|
|
40
|
if( !$admin->checkFTAN() )
|
41
|
{
|
42
|
$admin->print_error($MESSAGE['PAGES_NOT_SAVED'],'index.php');
|
43
|
exit();
|
44
|
}
|
45
|
|
46
|
// Include the WB functions file
|
47
|
require_once(WB_PATH.'/framework/functions.php');
|
48
|
|
49
|
// Set temp vars
|
50
|
$temp_dir = WB_PATH.'/temp/';
|
51
|
$temp_file = $temp_dir . $_FILES['userfile']['name'];
|
52
|
$temp_unzip = WB_PATH.'/temp/unzip/';
|
53
|
|
54
|
// Try to upload the file to the temp dir
|
55
|
if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file)) {
|
56
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UPLOAD']);
|
57
|
}
|
58
|
|
59
|
// Include the PclZip class file (thanks to
|
60
|
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
|
61
|
|
62
|
// Remove any vars with name "template_directory" and "theme_directory"
|
63
|
unset($template_directory);
|
64
|
unset($theme_directory);
|
65
|
|
66
|
// Setup the PclZip object
|
67
|
$archive = new PclZip($temp_file);
|
68
|
// Unzip the files to the temp unzip folder
|
69
|
$list = $archive->extract(PCLZIP_OPT_PATH, $temp_unzip);
|
70
|
|
71
|
// Check if uploaded file is a valid Add-On zip file
|
72
|
if (!($list && file_exists($temp_unzip . 'index.php'))) $admin->print_error($MESSAGE['GENERIC']['INVALID_ADDON_FILE']);
|
73
|
|
74
|
// Include the templates info file
|
75
|
require($temp_unzip.'info.php');
|
76
|
|
77
|
// Perform Add-on requirement checks before proceeding
|
78
|
require(WB_PATH . '/framework/addon.precheck.inc.php');
|
79
|
preCheckAddon($temp_file);
|
80
|
|
81
|
// Delete the temp unzip directory
|
82
|
rm_full_dir($temp_unzip);
|
83
|
|
84
|
// Check if the file is valid
|
85
|
if(!isset($template_directory)) {
|
86
|
if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
|
87
|
$admin->print_error($MESSAGE['GENERIC']['INVALID']);
|
88
|
}
|
89
|
|
90
|
// Check if this module is already installed
|
91
|
// and compare versions if so
|
92
|
$new_template_version=$template_version;
|
93
|
if(is_dir(WB_PATH.'/templates/'.$template_directory)) {
|
94
|
if(file_exists(WB_PATH.'/templates/'.$template_directory.'/info.php')) {
|
95
|
require(WB_PATH.'/templates/'.$template_directory.'/info.php');
|
96
|
// Version to be installed is older than currently installed version
|
97
|
if (versionCompare($template_version, $new_template_version, '>=')) {
|
98
|
if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
|
99
|
$admin->print_error($MESSAGE['GENERIC']['ALREADY_INSTALLED']);
|
100
|
}
|
101
|
}
|
102
|
$success_message=$MESSAGE['GENERIC']['UPGRADED'];
|
103
|
} else {
|
104
|
$success_message=$MESSAGE['GENERIC']['INSTALLED'];
|
105
|
}
|
106
|
|
107
|
// Check if template dir is writable
|
108
|
if(!is_writable(WB_PATH.'/templates/')) {
|
109
|
if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
|
110
|
$admin->print_error($MESSAGE['TEMPLATES']['BAD_PERMISSIONS']);
|
111
|
}
|
112
|
|
113
|
// Set template dir
|
114
|
$template_dir = WB_PATH.'/templates/'.$template_directory;
|
115
|
|
116
|
// Make sure the template dir exists, and chmod if needed
|
117
|
if(!file_exists($template_dir)) {
|
118
|
make_dir($template_dir);
|
119
|
} else {
|
120
|
change_mode($template_dir, 'dir');
|
121
|
}
|
122
|
|
123
|
// Unzip template to the template dir
|
124
|
$list = $archive->extract(PCLZIP_OPT_PATH, $template_dir, PCLZIP_OPT_REPLACE_NEWER);
|
125
|
if(!$list) {
|
126
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNZIP']);
|
127
|
}
|
128
|
|
129
|
// Delete the temp zip file
|
130
|
if(file_exists($temp_file)) { unlink($temp_file); }
|
131
|
|
132
|
// Chmod all the uploaded files
|
133
|
$dir = dir($template_dir);
|
134
|
while(false !== $entry = $dir->read()) {
|
135
|
// Skip pointers
|
136
|
if(substr($entry, 0, 1) != '.' AND $entry != '.svn' AND !is_dir($template_dir.'/'.$entry)) {
|
137
|
// Chmod file
|
138
|
change_mode($template_dir.'/'.$entry);
|
139
|
}
|
140
|
}
|
141
|
|
142
|
// Load template info into DB
|
143
|
load_template($template_dir);
|
144
|
|
145
|
// Print success message
|
146
|
$admin->print_success($success_message);
|
147
|
|
148
|
// Print admin footer
|
149
|
$admin->print_footer();
|
150
|
|
151
|
?>
|