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 |
656
|
thorn
|
// 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 |
4
|
ryan
|
// Check if user selected module
|
32 |
|
|
if(!isset($_POST['file']) OR $_POST['file'] == "") {
|
33 |
|
|
header("Location: index.php");
|
34 |
286
|
stefan
|
exit(0);
|
35 |
4
|
ryan
|
} else {
|
36 |
656
|
thorn
|
$file = $admin->add_slashes($_POST['file']);
|
37 |
4
|
ryan
|
}
|
38 |
|
|
|
39 |
268
|
ryan
|
// Extra protection
|
40 |
|
|
if(trim($file) == '') {
|
41 |
|
|
header("Location: index.php");
|
42 |
286
|
stefan
|
exit(0);
|
43 |
268
|
ryan
|
}
|
44 |
|
|
|
45 |
4
|
ryan
|
// 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 |
942
|
doc
|
$admin->print_error($MESSAGE['GENERIC']['NOT_INSTALLED']);
|
51 |
4
|
ryan
|
}
|
52 |
|
|
|
53 |
863
|
aldus
|
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 |
4
|
ryan
|
}
|
59 |
|
|
|
60 |
863
|
aldus
|
$info = $database->query("SELECT section_id, page_id FROM ".TABLE_PREFIX."sections WHERE module='".$_POST['file']."'" );
|
61 |
|
|
|
62 |
|
|
if ( $info->numRows() > 0) {
|
63 |
|
|
|
64 |
|
|
/**
|
65 |
|
|
* Modul is in use, so we have to warn the user
|
66 |
|
|
*/
|
67 |
893
|
aldus
|
if (!array_key_exists("CANNOT_UNINSTALL_IN_USE_TMPL", $MESSAGE['GENERIC'])) {
|
68 |
|
|
$add = $info->numRows() == 1 ? "this page" : "these pages";
|
69 |
|
|
$msg_template_str = "<br /><br />{{type}} <b>{{type_name}}</b> could not be uninstalled because it is still in use on {{pages}}";
|
70 |
|
|
$msg_template_str .= ":<br /><i>click for editing.</i><br /><br />";
|
71 |
|
|
} else {
|
72 |
|
|
$msg_template_str = $MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE_TMPL'];
|
73 |
|
|
$temp = explode(";",$MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE_TMPL_PAGES']);
|
74 |
|
|
$add = $info->numRows() == 1 ? $temp[0] : $temp[1];
|
75 |
|
|
}
|
76 |
863
|
aldus
|
/**
|
77 |
|
|
* The template-string for displaying the Page-Titles ... in this case as a link
|
78 |
|
|
*/
|
79 |
|
|
$page_template_str = "- <b><a href='../pages/sections.php?page_id={{id}}'>{{title}}</a></b><br />";
|
80 |
|
|
|
81 |
893
|
aldus
|
$values = array ('type' => 'Modul', 'type_name' => $file, 'pages' => $add );
|
82 |
863
|
aldus
|
$msg = replace_all ( $msg_template_str, $values );
|
83 |
|
|
|
84 |
|
|
$page_names = "";
|
85 |
|
|
|
86 |
879
|
aldus
|
while ($data = $info->fetchRow() ) {
|
87 |
863
|
aldus
|
|
88 |
|
|
$temp = $database->query("SELECT page_title from ".TABLE_PREFIX."pages where page_id=".$data['page_id']);
|
89 |
896
|
Ruebenwurz
|
$temp_title = $temp->fetchRow();
|
90 |
863
|
aldus
|
|
91 |
|
|
$page_info = array(
|
92 |
|
|
'id' => $data['page_id'],
|
93 |
|
|
'title' => $temp_title['page_title']
|
94 |
|
|
);
|
95 |
|
|
|
96 |
|
|
$page_names .= replace_all ( $page_template_str, $page_info );
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
/**
|
100 |
|
|
* Printing out the error-message and die().
|
101 |
|
|
*/
|
102 |
896
|
Ruebenwurz
|
$admin->print_error(str_replace ($TEXT['FILE'], "Modul", $MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE']).$msg.$page_names);
|
103 |
863
|
aldus
|
}
|
104 |
|
|
|
105 |
4
|
ryan
|
// Check if we have permissions on the directory
|
106 |
|
|
if(!is_writable(WB_PATH.'/modules/'.$file)) {
|
107 |
|
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL']);
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
// Run the modules uninstall script if there is one
|
111 |
|
|
if(file_exists(WB_PATH.'/modules/'.$file.'/uninstall.php')) {
|
112 |
|
|
require(WB_PATH.'/modules/'.$file.'/uninstall.php');
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
// Try to delete the module dir
|
116 |
|
|
if(!rm_full_dir(WB_PATH.'/modules/'.$file)) {
|
117 |
942
|
doc
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL']);
|
118 |
170
|
ryan
|
} else {
|
119 |
|
|
// Remove entry from DB
|
120 |
210
|
stefan
|
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE directory = '".$file."' AND type = 'module'");
|
121 |
4
|
ryan
|
}
|
122 |
|
|
|
123 |
|
|
// Print success message
|
124 |
|
|
$admin->print_success($MESSAGE['GENERIC']['UNINSTALLED']);
|
125 |
|
|
|
126 |
|
|
// Print admin footer
|
127 |
|
|
$admin->print_footer();
|
128 |
|
|
|
129 |
|
|
?>
|