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