1 |
4
|
ryan
|
<?php
|
2 |
1392
|
Luisehahne
|
/**
|
3 |
|
|
*
|
4 |
|
|
* @category admin
|
5 |
|
|
* @package templates
|
6 |
|
|
* @author WebsiteBaker Project
|
7 |
|
|
* @copyright 2004-2009, Ryan Djurovich
|
8 |
|
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
9 |
|
|
* @link http://www.websitebaker2.org/
|
10 |
|
|
* @license http://www.gnu.org/licenses/gpl.html
|
11 |
|
|
* @platform WebsiteBaker 2.8.x
|
12 |
|
|
* @requirements PHP 5.2.2 and higher
|
13 |
|
|
* @version $Id$
|
14 |
1457
|
Luisehahne
|
* @filesource $HeadURL$
|
15 |
|
|
* @lastmodified $Date$
|
16 |
1392
|
Luisehahne
|
*
|
17 |
|
|
*/
|
18 |
4
|
ryan
|
|
19 |
1457
|
Luisehahne
|
// Setup admin object
|
20 |
|
|
require('../../config.php');
|
21 |
|
|
require_once(WB_PATH.'/framework/class.admin.php');
|
22 |
|
|
// suppress to print the header, so no new FTAN will be set
|
23 |
|
|
$admin = new admin('Addons', 'templates_uninstall', false);
|
24 |
|
|
if( !$admin->checkFTAN() )
|
25 |
|
|
{
|
26 |
1467
|
Luisehahne
|
$admin->print_header();
|
27 |
1457
|
Luisehahne
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
|
28 |
|
|
}
|
29 |
|
|
// After check print the header
|
30 |
|
|
$admin->print_header();
|
31 |
|
|
|
32 |
4
|
ryan
|
// Check if user selected template
|
33 |
|
|
if(!isset($_POST['file']) OR $_POST['file'] == "") {
|
34 |
|
|
header("Location: index.php");
|
35 |
286
|
stefan
|
exit(0);
|
36 |
4
|
ryan
|
} else {
|
37 |
|
|
$file = $_POST['file'];
|
38 |
|
|
}
|
39 |
|
|
|
40 |
268
|
ryan
|
// Extra protection
|
41 |
|
|
if(trim($file) == '') {
|
42 |
|
|
header("Location: index.php");
|
43 |
286
|
stefan
|
exit(0);
|
44 |
268
|
ryan
|
}
|
45 |
|
|
|
46 |
4
|
ryan
|
// Include the WB functions file
|
47 |
|
|
require_once(WB_PATH.'/framework/functions.php');
|
48 |
|
|
|
49 |
|
|
// Check if the template exists
|
50 |
|
|
if(!is_dir(WB_PATH.'/templates/'.$file)) {
|
51 |
|
|
$admin->print_error($MESSAGE['GENERIC']['NOT_INSTALLED']);
|
52 |
|
|
}
|
53 |
|
|
|
54 |
862
|
aldus
|
if (!function_exists("replace_all")) {
|
55 |
|
|
function replace_all ($aStr = "", &$aArray ) {
|
56 |
|
|
foreach($aArray as $k=>$v) $aStr = str_replace("{{".$k."}}", $v, $aStr);
|
57 |
|
|
return $aStr;
|
58 |
|
|
}
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
/**
|
62 |
|
|
* Check if the template is the standard-template or still in use
|
63 |
|
|
*/
|
64 |
893
|
aldus
|
if (!array_key_exists('CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE', $MESSAGE['GENERIC'] ) )
|
65 |
|
|
$MESSAGE['GENERIC']['CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE'] = "Can't uninstall this template <b>{{name}}</b> because it's the standardtemplate!";
|
66 |
862
|
aldus
|
|
67 |
944
|
Ruebenwurz
|
// check whether the template is used as default wb theme
|
68 |
|
|
if($file == DEFAULT_THEME) {
|
69 |
|
|
$temp = array ('name' => $file );
|
70 |
|
|
$msg = replace_all( $MESSAGE['GENERIC']['CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE'], $temp );
|
71 |
|
|
$admin->print_error( $msg );
|
72 |
|
|
}
|
73 |
|
|
|
74 |
862
|
aldus
|
if ($file == DEFAULT_TEMPLATE) {
|
75 |
893
|
aldus
|
$temp = array ('name' => $file );
|
76 |
|
|
$msg = replace_all( $MESSAGE['GENERIC']['CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE'], $temp );
|
77 |
|
|
$admin->print_error( $msg );
|
78 |
862
|
aldus
|
|
79 |
4
|
ryan
|
} else {
|
80 |
862
|
aldus
|
|
81 |
|
|
/**
|
82 |
|
|
* Check if the template is still in use by a page ...
|
83 |
|
|
*/
|
84 |
|
|
$info = $database->query("SELECT page_id, page_title FROM ".TABLE_PREFIX."pages WHERE template='".$file."' order by page_title");
|
85 |
|
|
|
86 |
|
|
if ($info->numRows() > 0) {
|
87 |
|
|
/**
|
88 |
|
|
* Template is still in use, so we're collecting the page-titles
|
89 |
|
|
*/
|
90 |
|
|
|
91 |
|
|
/**
|
92 |
|
|
* The base-message template-string for the top of the message
|
93 |
|
|
*/
|
94 |
893
|
aldus
|
if (!array_key_exists("CANNOT_UNINSTALL_IN_USE_TMPL", $MESSAGE['GENERIC'])) {
|
95 |
|
|
$add = $info->numRows() == 1 ? "this page" : "these pages";
|
96 |
|
|
$msg_template_str = "<br /><br />{{type}} <b>{{type_name}}</b> could not be uninstalled because it is still in use by {{pages}}";
|
97 |
|
|
$msg_template_str .= ":<br /><i>click for editing.</i><br /><br />";
|
98 |
|
|
} else {
|
99 |
|
|
$msg_template_str = $MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE_TMPL'];
|
100 |
|
|
$temp = explode(";",$MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE_TMPL_PAGES']);
|
101 |
|
|
$add = $info->numRows() == 1 ? $temp[0] : $temp[1];
|
102 |
|
|
}
|
103 |
862
|
aldus
|
/**
|
104 |
|
|
* The template-string for displaying the Page-Titles ... in this case as a link
|
105 |
|
|
*/
|
106 |
|
|
$page_template_str = "- <b><a href='../pages/settings.php?page_id={{id}}'>{{title}}</a></b><br />";
|
107 |
|
|
|
108 |
893
|
aldus
|
$values = array ('type' => 'Template', 'type_name' => $file, 'pages' => $add);
|
109 |
862
|
aldus
|
$msg = replace_all ( $msg_template_str, $values );
|
110 |
|
|
|
111 |
|
|
$page_names = "";
|
112 |
|
|
|
113 |
880
|
aldus
|
while ($data = $info->fetchRow() ) {
|
114 |
862
|
aldus
|
|
115 |
|
|
$page_info = array(
|
116 |
|
|
'id' => $data['page_id'],
|
117 |
|
|
'title' => $data['page_title']
|
118 |
|
|
);
|
119 |
|
|
|
120 |
|
|
$page_names .= replace_all ( $page_template_str, $page_info );
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
/**
|
124 |
|
|
* Printing out the error-message and die().
|
125 |
|
|
*/
|
126 |
|
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE'].$msg.$page_names);
|
127 |
4
|
ryan
|
}
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
// Check if we have permissions on the directory
|
131 |
|
|
if(!is_writable(WB_PATH.'/templates/'.$file)) {
|
132 |
99
|
stefan
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL'].WB_PATH.'/templates/'.$file);
|
133 |
4
|
ryan
|
}
|
134 |
|
|
|
135 |
|
|
// Try to delete the template dir
|
136 |
|
|
if(!rm_full_dir(WB_PATH.'/templates/'.$file)) {
|
137 |
|
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL']);
|
138 |
170
|
ryan
|
} else {
|
139 |
|
|
// Remove entry from DB
|
140 |
211
|
stefan
|
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE directory = '".$file."' AND type = 'template'");
|
141 |
4
|
ryan
|
}
|
142 |
|
|
|
143 |
|
|
// Update pages that use this template with default template
|
144 |
1386
|
Luisehahne
|
// $database = new database();
|
145 |
4
|
ryan
|
$database->query("UPDATE ".TABLE_PREFIX."pages SET template = '".DEFAULT_TEMPLATE."' WHERE template = '$file'");
|
146 |
|
|
|
147 |
|
|
// Print success message
|
148 |
|
|
$admin->print_success($MESSAGE['GENERIC']['UNINSTALLED']);
|
149 |
|
|
|
150 |
|
|
// Print admin footer
|
151 |
|
|
$admin->print_footer();
|
152 |
|
|
|
153 |
|
|
?>
|