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