Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         templates
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id: install.php 2098 2014-02-11 01:37:03Z darkviper $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/templates/install.php $
14
 * @lastmodified    $Date: 2014-02-11 02:37:03 +0100 (Tue, 11 Feb 2014) $
15
 *
16
 */
17

    
18
// do not display notices and warnings during installation
19
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
20

    
21
// Setup admin object
22
require('../../config.php');
23
$oTrans = Translate::getInstance();
24
$oTrans->enableAddon('admin\\addons');
25
require_once(WB_PATH.'/framework/class.admin.php');
26
// suppress to print the header, so no new FTAN will be set
27
$admin = new admin('Addons', 'templates_install', false);
28
if( !$admin->checkFTAN() )
29
{
30
	$admin->print_header();
31
	$admin->print_error($oTrans->MESSAGE_GENERIC_SECURITY_ACCESS);
32
}
33
// After check print the header
34
$admin->print_header();
35

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

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

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

    
50
// Try to upload the file to the temp dir
51
if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file)) {
52
	$admin->print_error($oTrans->MESSAGE_GENERIC_CANNOT_UPLOAD);
53
}
54

    
55
// Include the PclZip class file (thanks to
56
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
57

    
58
// Remove any vars with name "template_directory" and "theme_directory"
59
unset($template_directory);
60
unset($theme_directory);
61

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

    
67
// Check if uploaded file is a valid Add-On zip file
68
if (!($list && file_exists($temp_unzip . 'index.php'))) $admin->print_error($oTrans->MESSAGE_GENERIC_INVALID_ADDON_FILE);
69

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

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

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

    
80
// Check if the file is valid
81
if(!isset($template_directory)) {
82
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
83
	$admin->print_error($oTrans->MESSAGE_GENERIC_INVALID);
84
}
85

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

    
103
// Check if template dir is writable
104
if(!is_writable(WB_PATH.'/templates/')) {
105
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
106
	$admin->print_error($oTrans->MESSAGE_TEMPLATES_BAD_PERMISSIONS);
107
}
108

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

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

    
119
// Unzip template to the template dir
120
//$list = $archive->extract(PCLZIP_OPT_PATH, $template_dir, PCLZIP_OPT_REPLACE_NEWER);
121
if(isset($_POST['overwrite'])){
122
	$list = $archive->extract(PCLZIP_OPT_PATH, $template_dir, PCLZIP_OPT_REPLACE_NEWER );
123
} else {
124
	$list = $archive->extract(PCLZIP_OPT_PATH, $template_dir );
125
}
126
if(!$list) {
127
	$admin->print_error($oTrans->MESSAGE_GENERIC_CANNOT_UNZIP);
128
}
129

    
130
// Delete the temp zip file
131
if(file_exists($temp_file)) { unlink($temp_file); }
132

    
133
// Chmod all the uploaded files
134
$dir = dir($template_dir);
135
while(false !== $entry = $dir->read()) {
136
	// Skip pointers
137
	if(substr($entry, 0, 1) != '.' AND $entry != '.svn' AND !is_dir($template_dir.'/'.$entry)) {
138
		// Chmod file
139
		change_mode($template_dir.'/'.$entry);
140
	}
141
}
142

    
143
// Load template info into DB
144
load_template($template_dir);
145

    
146
// Print success message
147
$admin->print_success($success_message);
148

    
149
// Print admin footer
150
$admin->print_footer();
(3-3/4)