Project

General

Profile

1
<?php
2
/**
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: install.php 1467 2011-07-02 00:06:53Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/templates/install.php $
15
 * @lastmodified    $Date: 2011-07-02 02:06:53 +0200 (Sat, 02 Jul 2011) $
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
// suppress to print the header, so no new FTAN will be set
26
$admin = new admin('Addons', 'templates_install', false);
27
if( !$admin->checkFTAN() )
28
{
29
	$admin->print_header();
30
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
31
}
32
// After check print the header
33
$admin->print_header();
34

    
35
// Check if user uploaded a file
36
if(!isset($_FILES['userfile'])) {
37
	header("Location: index.php");
38
	exit(0);
39
}
40

    
41
// Include the WB functions file
42
require_once(WB_PATH.'/framework/functions.php');
43

    
44
// Set temp vars
45
$temp_dir = WB_PATH.'/temp/';
46
$temp_file = $temp_dir . $_FILES['userfile']['name'];
47
$temp_unzip = WB_PATH.'/temp/unzip/';
48

    
49
// Try to upload the file to the temp dir
50
if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file)) {
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 "template_directory" and "theme_directory"
58
unset($template_directory);
59
unset($theme_directory);
60

    
61
// Setup the PclZip object
62
$archive = new PclZip($temp_file);
63
// Unzip the files to the temp unzip folder
64
$list = $archive->extract(PCLZIP_OPT_PATH, $temp_unzip);
65

    
66
// Check if uploaded file is a valid Add-On zip file
67
if (!($list && file_exists($temp_unzip . 'index.php'))) $admin->print_error($MESSAGE['GENERIC']['INVALID_ADDON_FILE']);
68

    
69
// Include the templates info file
70
require($temp_unzip.'info.php');
71

    
72
// Perform Add-on requirement checks before proceeding
73
require(WB_PATH . '/framework/addon.precheck.inc.php');
74
preCheckAddon($temp_file);
75

    
76
// Delete the temp unzip directory
77
rm_full_dir($temp_unzip);
78

    
79
// Check if the file is valid
80
if(!isset($template_directory)) {
81
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
82
	$admin->print_error($MESSAGE['GENERIC']['INVALID']);
83
}
84

    
85
// Check if this module is already installed
86
// and compare versions if so
87
$new_template_version=$template_version;
88
if(is_dir(WB_PATH.'/templates/'.$template_directory)) {
89
	if(file_exists(WB_PATH.'/templates/'.$template_directory.'/info.php')) {
90
		require(WB_PATH.'/templates/'.$template_directory.'/info.php');
91
		// Version to be installed is older than currently installed version
92
		if (versionCompare($template_version, $new_template_version, '>=')) {
93
			if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
94
			$admin->print_error($MESSAGE['GENERIC']['ALREADY_INSTALLED']);
95
		}
96
	} 
97
	$success_message=$MESSAGE['GENERIC']['UPGRADED'];
98
} else {
99
	$success_message=$MESSAGE['GENERIC']['INSTALLED'];
100
}
101

    
102
// Check if template dir is writable
103
if(!is_writable(WB_PATH.'/templates/')) {
104
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
105
	$admin->print_error($MESSAGE['TEMPLATES']['BAD_PERMISSIONS']);
106
}
107

    
108
// Set template dir
109
$template_dir = WB_PATH.'/templates/'.$template_directory;
110

    
111
// Make sure the template dir exists, and chmod if needed
112
if(!file_exists($template_dir)) {
113
	make_dir($template_dir);
114
} else {
115
	change_mode($template_dir, 'dir');
116
}
117

    
118
// Unzip template to the template dir
119
$list = $archive->extract(PCLZIP_OPT_PATH, $template_dir, PCLZIP_OPT_REPLACE_NEWER);
120
if(!$list) {
121
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNZIP']);
122
}
123

    
124
// Delete the temp zip file
125
if(file_exists($temp_file)) { unlink($temp_file); }
126

    
127
// Chmod all the uploaded files
128
$dir = dir($template_dir);
129
while(false !== $entry = $dir->read()) {
130
	// Skip pointers
131
	if(substr($entry, 0, 1) != '.' AND $entry != '.svn' AND !is_dir($template_dir.'/'.$entry)) {
132
		// Chmod file
133
		change_mode($template_dir.'/'.$entry);
134
	}
135
}
136

    
137
// Load template info into DB
138
load_template($template_dir);
139

    
140
// Print success message
141
$admin->print_success($success_message);
142

    
143
// Print admin footer
144
$admin->print_footer();
145

    
146
?>
(3-3/4)