Project

General

Profile

1
<?php
2

    
3
// $Id: install.php 519 2007-12-23 14:37:02Z Ruebenwurzel $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2008, 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
// Setup admin object
33
require('../../config.php');
34
require_once(WB_PATH.'/framework/class.admin.php');
35
$admin = new admin('Addons', 'templates_install');
36

    
37
// Include the WB functions file
38
require_once(WB_PATH.'/framework/functions.php');
39

    
40
// Set temp vars
41
$temp_dir = WB_PATH.'/temp/';
42
$temp_file = $temp_dir . $_FILES['userfile']['name'];
43
$temp_unzip = WB_PATH.'/temp/unzip/';
44

    
45
// Try to upload the file to the temp dir
46
if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file)) {
47
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UPLOAD']);
48
}
49

    
50
// Include the PclZip class file (thanks to 
51
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
52

    
53
// Remove any vars with name "template_directory"
54
unset($template_directory);
55

    
56
// Setup the PclZip object
57
$archive = new PclZip($temp_file);
58
// Unzip the files to the temp unzip folder
59
$list = $archive->extract(PCLZIP_OPT_PATH, $temp_unzip);
60
// Include the templates info file
61
require($temp_unzip.'info.php');
62
// Delete the temp unzip directory
63
rm_full_dir($temp_unzip);
64

    
65
// Check if the file is valid
66
if(!isset($template_directory)) {
67
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
68
	$admin->print_error($MESSAGE['GENERIC']['INVALID']);
69
}
70

    
71
// Check if this module is already installed
72
// and compare versions if so
73
$new_template_version=$template_version;
74
if(is_dir(WB_PATH.'/templates/'.$template_directory)) {
75
	if(file_exists(WB_PATH.'/templates/'.$template_directory.'/info.php')) {
76
		require(WB_PATH.'/templates/'.$template_directory.'/info.php');
77
		// Version to be installed is older than currently installed version
78
		if ($template_version>$new_template_version) {
79
			if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
80
			$admin->print_error($MESSAGE['GENERIC']['ALREADY_INSTALLED']);
81
		}
82
	} 
83
	$success_message=$MESSAGE['GENERIC']['UPGRADED'];
84
} else {
85
	$success_message=$MESSAGE['GENERIC']['INSTALLED'];
86
}
87

    
88
// Check if template dir is writable
89
if(!is_writable(WB_PATH.'/templates/')) {
90
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
91
	$admin->print_error($MESSAGE['TEMPLATES']['BAD_PERMISSIONS']);
92
}
93

    
94
// Set template dir
95
$template_dir = WB_PATH.'/templates/'.$template_directory;
96

    
97
// Make sure the template dir exists, and chmod if needed
98
if(!file_exists($template_dir)) {
99
	make_dir($template_dir);
100
} else {
101
	change_mode($template_dir, 'dir');
102
}
103

    
104
// Unzip template to the template dir
105
$list = $archive->extract(PCLZIP_OPT_PATH, $template_dir);
106
if(!$list) {
107
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNZIP']);
108
}
109

    
110
// Delete the temp zip file
111
if(file_exists($temp_file)) { unlink($temp_file); }
112

    
113
// Chmod all the uploaded files
114
$dir = dir($template_dir);
115
while(false !== $entry = $dir->read()) {
116
	// Skip pointers
117
	if(substr($entry, 0, 1) != '.' AND $entry != '.svn' AND !is_dir($template_dir.'/'.$entry)) {
118
		// Chmod file
119
		change_mode($template_dir.'/'.$entry);
120
	}
121
}
122

    
123
// Load template info into DB
124
load_template($template_dir);
125

    
126
// Print success message
127
$admin->print_success($success_message);
128

    
129
// Print admin footer
130
$admin->print_footer();
131

    
132
?>
(4-4/6)