Project

General

Profile

1 4 ryan
<?php
2 1392 Luisehahne
/**
3
 *
4
 * @category        admin
5
 * @package         templates
6 1712 Luisehahne
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8 1392 Luisehahne
 * @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$
13 1457 Luisehahne
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
15 1392 Luisehahne
 *
16
 */
17 4 ryan
18 925 doc
// do not display notices and warnings during installation
19
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
20
21 4 ryan
// Setup admin object
22
require('../../config.php');
23 2098 darkviper
$oTrans = Translate::getInstance();
24
$oTrans->enableAddon('admin\\addons');
25 4 ryan
require_once(WB_PATH.'/framework/class.admin.php');
26 1457 Luisehahne
// suppress to print the header, so no new FTAN will be set
27
$admin = new admin('Addons', 'templates_install', false);
28 1355 FrankH
if( !$admin->checkFTAN() )
29
{
30 1467 Luisehahne
	$admin->print_header();
31 2098 darkviper
	$admin->print_error($oTrans->MESSAGE_GENERIC_SECURITY_ACCESS);
32 1355 FrankH
}
33 1457 Luisehahne
// After check print the header
34
$admin->print_header();
35 1355 FrankH
36 1457 Luisehahne
// Check if user uploaded a file
37
if(!isset($_FILES['userfile'])) {
38
	header("Location: index.php");
39
	exit(0);
40
}
41
42 4 ryan
// 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 2098 darkviper
	$admin->print_error($oTrans->MESSAGE_GENERIC_CANNOT_UPLOAD);
53 4 ryan
}
54
55 1712 Luisehahne
// Include the PclZip class file (thanks to
56 4 ryan
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
57
58 944 Ruebenwurz
// Remove any vars with name "template_directory" and "theme_directory"
59 4 ryan
unset($template_directory);
60 944 Ruebenwurz
unset($theme_directory);
61 4 ryan
62
// Setup the PclZip object
63
$archive = new PclZip($temp_file);
64
// Unzip the files to the temp unzip folder
65 99 stefan
$list = $archive->extract(PCLZIP_OPT_PATH, $temp_unzip);
66 925 doc
67
// Check if uploaded file is a valid Add-On zip file
68 2098 darkviper
if (!($list && file_exists($temp_unzip . 'index.php'))) $admin->print_error($oTrans->MESSAGE_GENERIC_INVALID_ADDON_FILE);
69 925 doc
70 4 ryan
// Include the templates info file
71
require($temp_unzip.'info.php');
72 925 doc
73
// Perform Add-on requirement checks before proceeding
74
require(WB_PATH . '/framework/addon.precheck.inc.php');
75
preCheckAddon($temp_file);
76
77 4 ryan
// 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 2098 darkviper
	$admin->print_error($oTrans->MESSAGE_GENERIC_INVALID);
84 4 ryan
}
85
86 99 stefan
// Check if this module is already installed
87
// and compare versions if so
88
$new_template_version=$template_version;
89 4 ryan
if(is_dir(WB_PATH.'/templates/'.$template_directory)) {
90 99 stefan
	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 925 doc
		if (versionCompare($template_version, $new_template_version, '>=')) {
94 99 stefan
			if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
95 2098 darkviper
			$admin->print_error($oTrans->MESSAGE_GENERIC_ALREADY_INSTALLED);
96 99 stefan
		}
97 1712 Luisehahne
	}
98 2098 darkviper
	$success_message=$oTrans->MESSAGE_GENERIC_UPGRADED;
99 99 stefan
} else {
100 2098 darkviper
	$success_message=$oTrans->MESSAGE_GENERIC_INSTALLED;
101 4 ryan
}
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 2098 darkviper
	$admin->print_error($oTrans->MESSAGE_TEMPLATES_BAD_PERMISSIONS);
107 4 ryan
}
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 1712 Luisehahne
//$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 4 ryan
if(!$list) {
127 2098 darkviper
	$admin->print_error($oTrans->MESSAGE_GENERIC_CANNOT_UNZIP);
128 4 ryan
}
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 198 ryan
while(false !== $entry = $dir->read()) {
136 4 ryan
	// Skip pointers
137 8 stefan
	if(substr($entry, 0, 1) != '.' AND $entry != '.svn' AND !is_dir($template_dir.'/'.$entry)) {
138 4 ryan
		// Chmod file
139
		change_mode($template_dir.'/'.$entry);
140
	}
141
}
142
143 170 ryan
// Load template info into DB
144 211 stefan
load_template($template_dir);
145 170 ryan
146 4 ryan
// Print success message
147 99 stefan
$admin->print_success($success_message);
148 4 ryan
149
// Print admin footer
150
$admin->print_footer();