1
|
<?php
|
2
|
|
3
|
// $Id: uninstall.php 879 2008-11-12 07:17:44Z 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
|
// Setup admin object
|
27
|
require('../../config.php');
|
28
|
require_once(WB_PATH.'/framework/class.admin.php');
|
29
|
$admin = new admin('Addons', 'modules_uninstall');
|
30
|
|
31
|
// Check if user selected module
|
32
|
if(!isset($_POST['file']) OR $_POST['file'] == "") {
|
33
|
header("Location: index.php");
|
34
|
exit(0);
|
35
|
} else {
|
36
|
$file = $admin->add_slashes($_POST['file']);
|
37
|
}
|
38
|
|
39
|
// Extra protection
|
40
|
if(trim($file) == '') {
|
41
|
header("Location: index.php");
|
42
|
exit(0);
|
43
|
}
|
44
|
|
45
|
// Include the WB functions file
|
46
|
require_once(WB_PATH.'/framework/functions.php');
|
47
|
|
48
|
// Check if the module exists
|
49
|
if(!is_dir(WB_PATH.'/modules/'.$file)) {
|
50
|
$admin->print_error($MESSAGE['MODULES']['NOT_INSTALLED']);
|
51
|
}
|
52
|
|
53
|
/**
|
54
|
* Check if the module is in use
|
55
|
*
|
56
|
* @version 0.1.1
|
57
|
* @build 2
|
58
|
* @date 2008-11-12
|
59
|
* @author aldus
|
60
|
* @package Websitebaker - Admin - modules
|
61
|
* @state @dev
|
62
|
*
|
63
|
*/
|
64
|
|
65
|
if (!function_exists("replace_all")) {
|
66
|
function replace_all ($aStr = "", &$aArray ) {
|
67
|
foreach($aArray as $k=>$v) $aStr = str_replace("{{".$k."}}", $v, $aStr);
|
68
|
return $aStr;
|
69
|
}
|
70
|
}
|
71
|
|
72
|
$info = $database->query("SELECT section_id, page_id FROM ".TABLE_PREFIX."sections WHERE module='".$_POST['file']."'" );
|
73
|
|
74
|
if ( $info->numRows() > 0) {
|
75
|
|
76
|
/**
|
77
|
* Modul is in use, so we have to warn the user
|
78
|
*/
|
79
|
|
80
|
$add = $info->numRows() == 1 ? "this page" : "these pages";
|
81
|
$msg_template_str = "<br /><br />Modul <b>{{modul_name}}</b> could not be uninstalled because it is still in use on ";
|
82
|
$msg_template_str .= $add.":<br /><i>click for editing.</i><br /><br />";
|
83
|
|
84
|
/**
|
85
|
* The template-string for displaying the Page-Titles ... in this case as a link
|
86
|
*/
|
87
|
$page_template_str = "- <b><a href='../pages/sections.php?page_id={{id}}'>{{title}}</a></b><br />";
|
88
|
|
89
|
$values = array ('modul_name' => $file);
|
90
|
$msg = replace_all ( $msg_template_str, $values );
|
91
|
|
92
|
$page_names = "";
|
93
|
|
94
|
while ($data = $info->fetchRow() ) {
|
95
|
|
96
|
$temp = $database->query("SELECT page_title from ".TABLE_PREFIX."pages where page_id=".$data['page_id']);
|
97
|
$temp_title = $temp->fetchRow();
|
98
|
|
99
|
$page_info = array(
|
100
|
'id' => $data['page_id'],
|
101
|
'title' => $temp_title['page_title']
|
102
|
);
|
103
|
|
104
|
$page_names .= replace_all ( $page_template_str, $page_info );
|
105
|
}
|
106
|
|
107
|
/**
|
108
|
* Printing out the error-message and die().
|
109
|
*/
|
110
|
$admin->print_error(str_replace ("Datei", "Modul", $MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE']).$msg.$page_names);
|
111
|
}
|
112
|
|
113
|
// Check if we have permissions on the directory
|
114
|
if(!is_writable(WB_PATH.'/modules/'.$file)) {
|
115
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL']);
|
116
|
}
|
117
|
|
118
|
$database->query("DELETE FROM ".TABLE_PREFIX."modules WHERE directory = '$file'");
|
119
|
|
120
|
// Run the modules uninstall script if there is one
|
121
|
if(file_exists(WB_PATH.'/modules/'.$file.'/uninstall.php')) {
|
122
|
require(WB_PATH.'/modules/'.$file.'/uninstall.php');
|
123
|
}
|
124
|
|
125
|
// Try to delete the module dir
|
126
|
if(!rm_full_dir(WB_PATH.'/modules/'.$file)) {
|
127
|
$admin->print_error($MESSAGE['MODULES']['CANNOT_UNINSTALL']);
|
128
|
} else {
|
129
|
// Remove entry from DB
|
130
|
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE directory = '".$file."' AND type = 'module'");
|
131
|
}
|
132
|
|
133
|
// Print success message
|
134
|
$admin->print_success($MESSAGE['GENERIC']['UNINSTALLED']);
|
135
|
|
136
|
// Print admin footer
|
137
|
$admin->print_footer();
|
138
|
|
139
|
?>
|