1
|
<?php
|
2
|
|
3
|
// $Id: uninstall.php 893 2008-12-29 10:35:10Z aldus $
|
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
|
$debug = true;
|
27
|
|
28
|
if (true === $debug) {
|
29
|
ini_set('display_errors', 1);
|
30
|
error_reporting(E_ALL);
|
31
|
}
|
32
|
|
33
|
// Check if user selected template
|
34
|
if(!isset($_POST['file']) OR $_POST['file'] == "") {
|
35
|
header("Location: index.php");
|
36
|
exit(0);
|
37
|
} else {
|
38
|
$file = $_POST['file'];
|
39
|
}
|
40
|
|
41
|
// Extra protection
|
42
|
if(trim($file) == '') {
|
43
|
header("Location: index.php");
|
44
|
exit(0);
|
45
|
}
|
46
|
|
47
|
// Setup admin object
|
48
|
require('../../config.php');
|
49
|
require_once(WB_PATH.'/framework/class.admin.php');
|
50
|
$admin = new admin('Addons', 'templates_uninstall');
|
51
|
|
52
|
// Include the WB functions file
|
53
|
require_once(WB_PATH.'/framework/functions.php');
|
54
|
|
55
|
// Check if the template exists
|
56
|
if(!is_dir(WB_PATH.'/templates/'.$file)) {
|
57
|
$admin->print_error($MESSAGE['GENERIC']['NOT_INSTALLED']);
|
58
|
}
|
59
|
|
60
|
if (!function_exists("replace_all")) {
|
61
|
function replace_all ($aStr = "", &$aArray ) {
|
62
|
foreach($aArray as $k=>$v) $aStr = str_replace("{{".$k."}}", $v, $aStr);
|
63
|
return $aStr;
|
64
|
}
|
65
|
}
|
66
|
|
67
|
/**
|
68
|
* Check if the template is the standard-template or still in use
|
69
|
*/
|
70
|
if (!array_key_exists('CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE', $MESSAGE['GENERIC'] ) )
|
71
|
$MESSAGE['GENERIC']['CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE'] = "Can't uninstall this template <b>{{name}}</b> because it's the standardtemplate!";
|
72
|
|
73
|
if ($file == DEFAULT_TEMPLATE) {
|
74
|
$temp = array ('name' => $file );
|
75
|
$msg = replace_all( $MESSAGE['GENERIC']['CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE'], $temp );
|
76
|
$admin->print_error( $msg );
|
77
|
|
78
|
} else {
|
79
|
|
80
|
/**
|
81
|
* Check if the template is still in use by a page ...
|
82
|
*
|
83
|
* @version 0.2.0
|
84
|
* @build 5
|
85
|
* @author aldus
|
86
|
* @since 0.1.0
|
87
|
* @lastchange 2008-10-23
|
88
|
*
|
89
|
*/
|
90
|
$info = $database->query("SELECT page_id, page_title FROM ".TABLE_PREFIX."pages WHERE template='".$file."' order by page_title");
|
91
|
|
92
|
if ($info->numRows() > 0) {
|
93
|
|
94
|
/**
|
95
|
* Template is still in use, so we're collecting the page-titles
|
96
|
*
|
97
|
* @version 0.2.0
|
98
|
* @build 5
|
99
|
* @since 0.1.1
|
100
|
* @lastchange 2008-10-23
|
101
|
*
|
102
|
* 0.2.0 Codechanges for Websitebaker to use it without the Black-Hawk-Engine
|
103
|
*
|
104
|
* 0.1.1 add this page <if we found only one> / these pages
|
105
|
*
|
106
|
* @notice All listed pages got linked to "settings.php" so the user can easy change
|
107
|
* the template-settings. Modifications could be made in "page_template_str".
|
108
|
* For additional informations you will have to modify the query, the page_template_str
|
109
|
* and the page_info array.
|
110
|
*
|
111
|
* @todo 1 - Additional informations about the pages (modified, modified_by, visibility, etc)
|
112
|
*
|
113
|
* 2 - What happends about pages, the user is not allowed to edit?
|
114
|
* Marked "red"?
|
115
|
*
|
116
|
* 3 - Multiple language support here ...
|
117
|
*/
|
118
|
|
119
|
/**
|
120
|
* The base-message template-string for the top of the message
|
121
|
*
|
122
|
* 0.1.2 this page/ these pages
|
123
|
*
|
124
|
*/
|
125
|
if (!array_key_exists("CANNOT_UNINSTALL_IN_USE_TMPL", $MESSAGE['GENERIC'])) {
|
126
|
$add = $info->numRows() == 1 ? "this page" : "these pages";
|
127
|
$msg_template_str = "<br /><br />{{type}} <b>{{type_name}}</b> could not be uninstalled because it is still in use by {{pages}}";
|
128
|
$msg_template_str .= ":<br /><i>click for editing.</i><br /><br />";
|
129
|
} else {
|
130
|
$msg_template_str = $MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE_TMPL'];
|
131
|
$temp = explode(";",$MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE_TMPL_PAGES']);
|
132
|
$add = $info->numRows() == 1 ? $temp[0] : $temp[1];
|
133
|
}
|
134
|
/**
|
135
|
* The template-string for displaying the Page-Titles ... in this case as a link
|
136
|
*/
|
137
|
$page_template_str = "- <b><a href='../pages/settings.php?page_id={{id}}'>{{title}}</a></b><br />";
|
138
|
|
139
|
$values = array ('type' => 'Template', 'type_name' => $file, 'pages' => $add);
|
140
|
$msg = replace_all ( $msg_template_str, $values );
|
141
|
|
142
|
$page_names = "";
|
143
|
|
144
|
while ($data = $info->fetchRow() ) {
|
145
|
|
146
|
$page_info = array(
|
147
|
'id' => $data['page_id'],
|
148
|
'title' => $data['page_title']
|
149
|
);
|
150
|
|
151
|
$page_names .= replace_all ( $page_template_str, $page_info );
|
152
|
}
|
153
|
|
154
|
/**
|
155
|
* Printing out the error-message and die().
|
156
|
*/
|
157
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE'].$msg.$page_names);
|
158
|
}
|
159
|
}
|
160
|
|
161
|
// Check if we have permissions on the directory
|
162
|
if(!is_writable(WB_PATH.'/templates/'.$file)) {
|
163
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL'].WB_PATH.'/templates/'.$file);
|
164
|
}
|
165
|
|
166
|
// Try to delete the template dir
|
167
|
if(!rm_full_dir(WB_PATH.'/templates/'.$file)) {
|
168
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL']);
|
169
|
} else {
|
170
|
// Remove entry from DB
|
171
|
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE directory = '".$file."' AND type = 'template'");
|
172
|
}
|
173
|
|
174
|
// Update pages that use this template with default template
|
175
|
$database = new database();
|
176
|
$database->query("UPDATE ".TABLE_PREFIX."pages SET template = '".DEFAULT_TEMPLATE."' WHERE template = '$file'");
|
177
|
|
178
|
// Print success message
|
179
|
$admin->print_success($MESSAGE['GENERIC']['UNINSTALLED']);
|
180
|
|
181
|
// Print admin footer
|
182
|
$admin->print_footer();
|
183
|
|
184
|
?>
|