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 |
|
|
require_once(WB_PATH.'/framework/class.admin.php');
|
24 |
1457
|
Luisehahne
|
// suppress to print the header, so no new FTAN will be set
|
25 |
|
|
$admin = new admin('Addons', 'templates_install', false);
|
26 |
1355
|
FrankH
|
if( !$admin->checkFTAN() )
|
27 |
|
|
{
|
28 |
1467
|
Luisehahne
|
$admin->print_header();
|
29 |
1425
|
Luisehahne
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
|
30 |
1355
|
FrankH
|
}
|
31 |
1457
|
Luisehahne
|
// After check print the header
|
32 |
|
|
$admin->print_header();
|
33 |
1355
|
FrankH
|
|
34 |
1457
|
Luisehahne
|
// Check if user uploaded a file
|
35 |
|
|
if(!isset($_FILES['userfile'])) {
|
36 |
|
|
header("Location: index.php");
|
37 |
|
|
exit(0);
|
38 |
|
|
}
|
39 |
|
|
|
40 |
4
|
ryan
|
// Include the WB functions file
|
41 |
|
|
require_once(WB_PATH.'/framework/functions.php');
|
42 |
|
|
|
43 |
|
|
// Set temp vars
|
44 |
|
|
$temp_dir = WB_PATH.'/temp/';
|
45 |
|
|
$temp_file = $temp_dir . $_FILES['userfile']['name'];
|
46 |
|
|
$temp_unzip = WB_PATH.'/temp/unzip/';
|
47 |
|
|
|
48 |
|
|
// Try to upload the file to the temp dir
|
49 |
|
|
if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file)) {
|
50 |
1712
|
Luisehahne
|
$admin->print_error($MESSAGE['GENERIC_CANNOT_UPLOAD']);
|
51 |
4
|
ryan
|
}
|
52 |
|
|
|
53 |
1712
|
Luisehahne
|
// Include the PclZip class file (thanks to
|
54 |
4
|
ryan
|
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
|
55 |
|
|
|
56 |
944
|
Ruebenwurz
|
// Remove any vars with name "template_directory" and "theme_directory"
|
57 |
4
|
ryan
|
unset($template_directory);
|
58 |
944
|
Ruebenwurz
|
unset($theme_directory);
|
59 |
4
|
ryan
|
|
60 |
|
|
// Setup the PclZip object
|
61 |
|
|
$archive = new PclZip($temp_file);
|
62 |
|
|
// Unzip the files to the temp unzip folder
|
63 |
99
|
stefan
|
$list = $archive->extract(PCLZIP_OPT_PATH, $temp_unzip);
|
64 |
925
|
doc
|
|
65 |
|
|
// Check if uploaded file is a valid Add-On zip file
|
66 |
1712
|
Luisehahne
|
if (!($list && file_exists($temp_unzip . 'index.php'))) $admin->print_error($MESSAGE['GENERIC_INVALID_ADDON_FILE']);
|
67 |
925
|
doc
|
|
68 |
4
|
ryan
|
// Include the templates info file
|
69 |
|
|
require($temp_unzip.'info.php');
|
70 |
925
|
doc
|
|
71 |
|
|
// Perform Add-on requirement checks before proceeding
|
72 |
|
|
require(WB_PATH . '/framework/addon.precheck.inc.php');
|
73 |
|
|
preCheckAddon($temp_file);
|
74 |
|
|
|
75 |
4
|
ryan
|
// Delete the temp unzip directory
|
76 |
|
|
rm_full_dir($temp_unzip);
|
77 |
|
|
|
78 |
|
|
// Check if the file is valid
|
79 |
|
|
if(!isset($template_directory)) {
|
80 |
|
|
if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
|
81 |
1712
|
Luisehahne
|
$admin->print_error($MESSAGE['GENERIC_INVALID']);
|
82 |
4
|
ryan
|
}
|
83 |
|
|
|
84 |
99
|
stefan
|
// Check if this module is already installed
|
85 |
|
|
// and compare versions if so
|
86 |
|
|
$new_template_version=$template_version;
|
87 |
4
|
ryan
|
if(is_dir(WB_PATH.'/templates/'.$template_directory)) {
|
88 |
99
|
stefan
|
if(file_exists(WB_PATH.'/templates/'.$template_directory.'/info.php')) {
|
89 |
|
|
require(WB_PATH.'/templates/'.$template_directory.'/info.php');
|
90 |
|
|
// Version to be installed is older than currently installed version
|
91 |
925
|
doc
|
if (versionCompare($template_version, $new_template_version, '>=')) {
|
92 |
99
|
stefan
|
if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
|
93 |
1712
|
Luisehahne
|
$admin->print_error($MESSAGE['GENERIC_ALREADY_INSTALLED']);
|
94 |
99
|
stefan
|
}
|
95 |
1712
|
Luisehahne
|
}
|
96 |
|
|
$success_message=$MESSAGE['GENERIC_UPGRADED'];
|
97 |
99
|
stefan
|
} else {
|
98 |
1712
|
Luisehahne
|
$success_message=$MESSAGE['GENERIC_INSTALLED'];
|
99 |
4
|
ryan
|
}
|
100 |
|
|
|
101 |
|
|
// Check if template dir is writable
|
102 |
|
|
if(!is_writable(WB_PATH.'/templates/')) {
|
103 |
|
|
if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
|
104 |
1712
|
Luisehahne
|
$admin->print_error($MESSAGE['TEMPLATES_BAD_PERMISSIONS']);
|
105 |
4
|
ryan
|
}
|
106 |
|
|
|
107 |
|
|
// Set template dir
|
108 |
|
|
$template_dir = WB_PATH.'/templates/'.$template_directory;
|
109 |
|
|
|
110 |
|
|
// Make sure the template dir exists, and chmod if needed
|
111 |
|
|
if(!file_exists($template_dir)) {
|
112 |
|
|
make_dir($template_dir);
|
113 |
|
|
} else {
|
114 |
|
|
change_mode($template_dir, 'dir');
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
// Unzip template to the template dir
|
118 |
1712
|
Luisehahne
|
//$list = $archive->extract(PCLZIP_OPT_PATH, $template_dir, PCLZIP_OPT_REPLACE_NEWER);
|
119 |
|
|
if(isset($_POST['overwrite'])){
|
120 |
|
|
$list = $archive->extract(PCLZIP_OPT_PATH, $template_dir, PCLZIP_OPT_REPLACE_NEWER );
|
121 |
|
|
} else {
|
122 |
|
|
$list = $archive->extract(PCLZIP_OPT_PATH, $template_dir );
|
123 |
|
|
}
|
124 |
4
|
ryan
|
if(!$list) {
|
125 |
1712
|
Luisehahne
|
$admin->print_error($MESSAGE['GENERIC_CANNOT_UNZIP']);
|
126 |
4
|
ryan
|
}
|
127 |
|
|
|
128 |
|
|
// Delete the temp zip file
|
129 |
|
|
if(file_exists($temp_file)) { unlink($temp_file); }
|
130 |
|
|
|
131 |
|
|
// Chmod all the uploaded files
|
132 |
|
|
$dir = dir($template_dir);
|
133 |
198
|
ryan
|
while(false !== $entry = $dir->read()) {
|
134 |
4
|
ryan
|
// Skip pointers
|
135 |
8
|
stefan
|
if(substr($entry, 0, 1) != '.' AND $entry != '.svn' AND !is_dir($template_dir.'/'.$entry)) {
|
136 |
4
|
ryan
|
// Chmod file
|
137 |
|
|
change_mode($template_dir.'/'.$entry);
|
138 |
|
|
}
|
139 |
|
|
}
|
140 |
|
|
|
141 |
170
|
ryan
|
// Load template info into DB
|
142 |
211
|
stefan
|
load_template($template_dir);
|
143 |
170
|
ryan
|
|
144 |
4
|
ryan
|
// Print success message
|
145 |
99
|
stefan
|
$admin->print_success($success_message);
|
146 |
4
|
ryan
|
|
147 |
|
|
// Print admin footer
|
148 |
|
|
$admin->print_footer();
|