1 |
4
|
ryan
|
<?php
|
2 |
|
|
|
3 |
40
|
stefan
|
// $Id$
|
4 |
4
|
ryan
|
|
5 |
|
|
/*
|
6 |
|
|
|
7 |
|
|
Website Baker Project <http://www.websitebaker.org/>
|
8 |
915
|
Ruebenwurz
|
Copyright (C) 2004-2009, Ryan Djurovich
|
9 |
4
|
ryan
|
|
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 |
286
|
stefan
|
exit(0);
|
30 |
4
|
ryan
|
} else {
|
31 |
|
|
$file = $_POST['file'];
|
32 |
|
|
}
|
33 |
|
|
|
34 |
268
|
ryan
|
// Extra protection
|
35 |
|
|
if(trim($file) == '') {
|
36 |
|
|
header("Location: index.php");
|
37 |
286
|
stefan
|
exit(0);
|
38 |
268
|
ryan
|
}
|
39 |
|
|
|
40 |
4
|
ryan
|
// 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 |
1355
|
FrankH
|
if( !$admin->checkFTAN() )
|
46 |
|
|
{
|
47 |
|
|
$admin->print_error($MESSAGE['PAGES_NOT_SAVED'],'index.php');
|
48 |
|
|
exit();
|
49 |
|
|
}
|
50 |
|
|
|
51 |
4
|
ryan
|
// Include the WB functions file
|
52 |
|
|
require_once(WB_PATH.'/framework/functions.php');
|
53 |
|
|
|
54 |
|
|
// Check if the template exists
|
55 |
|
|
if(!is_dir(WB_PATH.'/templates/'.$file)) {
|
56 |
|
|
$admin->print_error($MESSAGE['GENERIC']['NOT_INSTALLED']);
|
57 |
|
|
}
|
58 |
|
|
|
59 |
862
|
aldus
|
if (!function_exists("replace_all")) {
|
60 |
|
|
function replace_all ($aStr = "", &$aArray ) {
|
61 |
|
|
foreach($aArray as $k=>$v) $aStr = str_replace("{{".$k."}}", $v, $aStr);
|
62 |
|
|
return $aStr;
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
/**
|
67 |
|
|
* Check if the template is the standard-template or still in use
|
68 |
|
|
*/
|
69 |
893
|
aldus
|
if (!array_key_exists('CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE', $MESSAGE['GENERIC'] ) )
|
70 |
|
|
$MESSAGE['GENERIC']['CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE'] = "Can't uninstall this template <b>{{name}}</b> because it's the standardtemplate!";
|
71 |
862
|
aldus
|
|
72 |
944
|
Ruebenwurz
|
// check whether the template is used as default wb theme
|
73 |
|
|
if($file == DEFAULT_THEME) {
|
74 |
|
|
$temp = array ('name' => $file );
|
75 |
|
|
$msg = replace_all( $MESSAGE['GENERIC']['CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE'], $temp );
|
76 |
|
|
$admin->print_error( $msg );
|
77 |
|
|
}
|
78 |
|
|
|
79 |
862
|
aldus
|
if ($file == DEFAULT_TEMPLATE) {
|
80 |
893
|
aldus
|
$temp = array ('name' => $file );
|
81 |
|
|
$msg = replace_all( $MESSAGE['GENERIC']['CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE'], $temp );
|
82 |
|
|
$admin->print_error( $msg );
|
83 |
862
|
aldus
|
|
84 |
4
|
ryan
|
} else {
|
85 |
862
|
aldus
|
|
86 |
|
|
/**
|
87 |
|
|
* Check if the template is still in use by a page ...
|
88 |
|
|
*/
|
89 |
|
|
$info = $database->query("SELECT page_id, page_title FROM ".TABLE_PREFIX."pages WHERE template='".$file."' order by page_title");
|
90 |
|
|
|
91 |
|
|
if ($info->numRows() > 0) {
|
92 |
|
|
/**
|
93 |
|
|
* Template is still in use, so we're collecting the page-titles
|
94 |
|
|
*/
|
95 |
|
|
|
96 |
|
|
/**
|
97 |
|
|
* The base-message template-string for the top of the message
|
98 |
|
|
*/
|
99 |
893
|
aldus
|
if (!array_key_exists("CANNOT_UNINSTALL_IN_USE_TMPL", $MESSAGE['GENERIC'])) {
|
100 |
|
|
$add = $info->numRows() == 1 ? "this page" : "these pages";
|
101 |
|
|
$msg_template_str = "<br /><br />{{type}} <b>{{type_name}}</b> could not be uninstalled because it is still in use by {{pages}}";
|
102 |
|
|
$msg_template_str .= ":<br /><i>click for editing.</i><br /><br />";
|
103 |
|
|
} else {
|
104 |
|
|
$msg_template_str = $MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE_TMPL'];
|
105 |
|
|
$temp = explode(";",$MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE_TMPL_PAGES']);
|
106 |
|
|
$add = $info->numRows() == 1 ? $temp[0] : $temp[1];
|
107 |
|
|
}
|
108 |
862
|
aldus
|
/**
|
109 |
|
|
* The template-string for displaying the Page-Titles ... in this case as a link
|
110 |
|
|
*/
|
111 |
|
|
$page_template_str = "- <b><a href='../pages/settings.php?page_id={{id}}'>{{title}}</a></b><br />";
|
112 |
|
|
|
113 |
893
|
aldus
|
$values = array ('type' => 'Template', 'type_name' => $file, 'pages' => $add);
|
114 |
862
|
aldus
|
$msg = replace_all ( $msg_template_str, $values );
|
115 |
|
|
|
116 |
|
|
$page_names = "";
|
117 |
|
|
|
118 |
880
|
aldus
|
while ($data = $info->fetchRow() ) {
|
119 |
862
|
aldus
|
|
120 |
|
|
$page_info = array(
|
121 |
|
|
'id' => $data['page_id'],
|
122 |
|
|
'title' => $data['page_title']
|
123 |
|
|
);
|
124 |
|
|
|
125 |
|
|
$page_names .= replace_all ( $page_template_str, $page_info );
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
/**
|
129 |
|
|
* Printing out the error-message and die().
|
130 |
|
|
*/
|
131 |
|
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE'].$msg.$page_names);
|
132 |
4
|
ryan
|
}
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
// Check if we have permissions on the directory
|
136 |
|
|
if(!is_writable(WB_PATH.'/templates/'.$file)) {
|
137 |
99
|
stefan
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL'].WB_PATH.'/templates/'.$file);
|
138 |
4
|
ryan
|
}
|
139 |
|
|
|
140 |
|
|
// Try to delete the template dir
|
141 |
|
|
if(!rm_full_dir(WB_PATH.'/templates/'.$file)) {
|
142 |
|
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL']);
|
143 |
170
|
ryan
|
} else {
|
144 |
|
|
// Remove entry from DB
|
145 |
211
|
stefan
|
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE directory = '".$file."' AND type = 'template'");
|
146 |
4
|
ryan
|
}
|
147 |
|
|
|
148 |
|
|
// Update pages that use this template with default template
|
149 |
1386
|
Luisehahne
|
// $database = new database();
|
150 |
4
|
ryan
|
$database->query("UPDATE ".TABLE_PREFIX."pages SET template = '".DEFAULT_TEMPLATE."' WHERE template = '$file'");
|
151 |
|
|
|
152 |
|
|
// Print success message
|
153 |
|
|
$admin->print_success($MESSAGE['GENERIC']['UNINSTALLED']);
|
154 |
|
|
|
155 |
|
|
// Print admin footer
|
156 |
|
|
$admin->print_footer();
|
157 |
|
|
|
158 |
|
|
?>
|