Project

General

Profile

1 4 ryan
<?php
2 1392 Luisehahne
/**
3
 *
4
 * @category        admin
5
 * @package         templates
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
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL: http://svn.websitebaker2.org/branches/2.8.x/wb/admin/settings/save.php $
15
 * @lastmodified    $Date: 2011-01-10 13:21:47 +0100 (Mo, 10. Jan 2011) $
16
 *
17
 */
18 4 ryan
19
// Check if user uploaded a file
20
if(!isset($_FILES['userfile'])) {
21
	header("Location: index.php");
22 286 stefan
	exit(0);
23 4 ryan
}
24
25 925 doc
// do not display notices and warnings during installation
26
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
27
28 4 ryan
// Setup admin object
29
require('../../config.php');
30
require_once(WB_PATH.'/framework/class.admin.php');
31
$admin = new admin('Addons', 'templates_install');
32
33 1355 FrankH
if( !$admin->checkFTAN() )
34
{
35 1392 Luisehahne
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],'index.php');
36 1355 FrankH
	exit();
37
}
38
39 4 ryan
// Include the WB functions file
40
require_once(WB_PATH.'/framework/functions.php');
41
42
// Set temp vars
43
$temp_dir = WB_PATH.'/temp/';
44
$temp_file = $temp_dir . $_FILES['userfile']['name'];
45
$temp_unzip = WB_PATH.'/temp/unzip/';
46
47
// Try to upload the file to the temp dir
48
if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file)) {
49
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UPLOAD']);
50
}
51
52
// Include the PclZip class file (thanks to
53
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
54
55 944 Ruebenwurz
// Remove any vars with name "template_directory" and "theme_directory"
56 4 ryan
unset($template_directory);
57 944 Ruebenwurz
unset($theme_directory);
58 4 ryan
59
// Setup the PclZip object
60
$archive = new PclZip($temp_file);
61
// Unzip the files to the temp unzip folder
62 99 stefan
$list = $archive->extract(PCLZIP_OPT_PATH, $temp_unzip);
63 925 doc
64
// Check if uploaded file is a valid Add-On zip file
65
if (!($list && file_exists($temp_unzip . 'index.php'))) $admin->print_error($MESSAGE['GENERIC']['INVALID_ADDON_FILE']);
66
67 4 ryan
// Include the templates info file
68
require($temp_unzip.'info.php');
69 925 doc
70
// Perform Add-on requirement checks before proceeding
71
require(WB_PATH . '/framework/addon.precheck.inc.php');
72
preCheckAddon($temp_file);
73
74 4 ryan
// Delete the temp unzip directory
75
rm_full_dir($temp_unzip);
76
77
// Check if the file is valid
78
if(!isset($template_directory)) {
79
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
80
	$admin->print_error($MESSAGE['GENERIC']['INVALID']);
81
}
82
83 99 stefan
// Check if this module is already installed
84
// and compare versions if so
85
$new_template_version=$template_version;
86 4 ryan
if(is_dir(WB_PATH.'/templates/'.$template_directory)) {
87 99 stefan
	if(file_exists(WB_PATH.'/templates/'.$template_directory.'/info.php')) {
88
		require(WB_PATH.'/templates/'.$template_directory.'/info.php');
89
		// Version to be installed is older than currently installed version
90 925 doc
		if (versionCompare($template_version, $new_template_version, '>=')) {
91 99 stefan
			if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
92
			$admin->print_error($MESSAGE['GENERIC']['ALREADY_INSTALLED']);
93
		}
94
	}
95
	$success_message=$MESSAGE['GENERIC']['UPGRADED'];
96
} else {
97
	$success_message=$MESSAGE['GENERIC']['INSTALLED'];
98 4 ryan
}
99
100
// Check if template dir is writable
101
if(!is_writable(WB_PATH.'/templates/')) {
102
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
103
	$admin->print_error($MESSAGE['TEMPLATES']['BAD_PERMISSIONS']);
104
}
105
106
// Set template dir
107
$template_dir = WB_PATH.'/templates/'.$template_directory;
108
109
// Make sure the template dir exists, and chmod if needed
110
if(!file_exists($template_dir)) {
111
	make_dir($template_dir);
112
} else {
113
	change_mode($template_dir, 'dir');
114
}
115
116
// Unzip template to the template dir
117 1361 Luisehahne
$list = $archive->extract(PCLZIP_OPT_PATH, $template_dir, PCLZIP_OPT_REPLACE_NEWER);
118 4 ryan
if(!$list) {
119
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNZIP']);
120
}
121
122
// Delete the temp zip file
123
if(file_exists($temp_file)) { unlink($temp_file); }
124
125
// Chmod all the uploaded files
126
$dir = dir($template_dir);
127 198 ryan
while(false !== $entry = $dir->read()) {
128 4 ryan
	// Skip pointers
129 8 stefan
	if(substr($entry, 0, 1) != '.' AND $entry != '.svn' AND !is_dir($template_dir.'/'.$entry)) {
130 4 ryan
		// Chmod file
131
		change_mode($template_dir.'/'.$entry);
132
	}
133
}
134
135 170 ryan
// Load template info into DB
136 211 stefan
load_template($template_dir);
137 170 ryan
138 4 ryan
// Print success message
139 99 stefan
$admin->print_success($success_message);
140 4 ryan
141
// Print admin footer
142
$admin->print_footer();
143
144 239 stefan
?>