Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         templates
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id: uninstall.php 2070 2014-01-03 01:21:42Z darkviper $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/templates/uninstall.php $
14
 * @lastmodified    $Date: 2014-01-03 02:21:42 +0100 (Fri, 03 Jan 2014) $
15
 *
16
 */
17

    
18
// Setup admin object
19
require('../../config.php');
20
require_once(WB_PATH.'/framework/class.admin.php');
21
// suppress to print the header, so no new FTAN will be set
22
$admin = new admin('Addons', 'templates_uninstall', false);
23
if( !$admin->checkFTAN() )
24
{
25
	$admin->print_header();
26
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
27
}
28
// After check print the header
29
$admin->print_header();
30
if(!isset($_POST['file']) OR $_POST['file'] == "") {
31
	$admin->print_error($MESSAGE['GENERIC_FORGOT_OPTIONS']);
32
} else {
33
	$file = preg_replace('/[^a-z0-9_-]/i', "", $_POST['file']);  // fix secunia 2010-92-2
34
}
35

    
36
// Check if the template exists
37
if(!is_dir(WB_PATH.'/templates/'.$file)) {
38
	$admin->print_error($MESSAGE['GENERIC_NOT_INSTALLED']);
39
}
40

    
41
// Check if the template exists
42
if(!is_readable(WB_PATH.'/templates/'.$file)) {
43
	$admin->print_error($MESSAGE['ADMIN_INSUFFICIENT_PRIVELLIGES']);
44
}
45

    
46
// Check if user selected template
47
/*
48
if(!isset($_POST['file']) OR $_POST['file'] == "") {
49
	header("Location: index.php");
50
	exit(0);
51
} else {
52
	$file = $_POST['file'];
53
}
54

    
55
// Extra protection
56
if(trim($file) == '') {
57
	header("Location: index.php");
58
	exit(0);
59
}
60
*/
61

    
62
// Include the WB functions file
63
require_once(WB_PATH.'/framework/functions.php');
64
if (!function_exists("replace_all")) {
65
	function replace_all ($aStr = "", &$aArray ) {
66
		foreach($aArray as $k=>$v) $aStr = str_replace("{{".$k."}}", $v, $aStr);
67
		return $aStr;
68
	}
69
}
70

    
71
/**
72
*	Check if the template is the standard-template or still in use
73
*/
74
if (!array_key_exists('CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE', $MESSAGE['GENERIC'] ) )
75
	$MESSAGE['GENERIC_CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE'] = "Can't uninstall this template <b>{{name}}</b> because it's the standardtemplate!";
76

    
77
// check whether the template is used as default wb theme
78
if($file == DEFAULT_THEME) {
79
	$temp = array ('name' => $file );
80
	$msg = replace_all( $MESSAGE['GENERIC_CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE'], $temp );
81
	$admin->print_error( $msg );
82
}
83

    
84
if ($file == DEFAULT_TEMPLATE) {
85
	$temp = array ('name' => $file );
86
	$msg = replace_all( $MESSAGE['GENERIC_CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE'], $temp );
87
	$admin->print_error( $msg );
88

    
89
} else {
90

    
91
	/**
92
	*	Check if the template is still in use by a page ...
93
	*/
94
	$info = $database->query("SELECT page_id, page_title FROM ".TABLE_PREFIX."pages WHERE template='".$file."' order by page_title");
95

    
96
	if ($info->numRows() > 0) {
97
		/**
98
		*	Template is still in use, so we're collecting the page-titles
99
		*/
100

    
101
		/**
102
		*	The base-message template-string for the top of the message
103
		*/
104
		if (!array_key_exists("CANNOT_UNINSTALL_IN_USE_TMPL", $MESSAGE['GENERIC'])) {
105
			$add = $info->numRows() == 1 ? "this page" : "these pages";
106
			$msg_template_str  = "<br /><br />{{type}} <b>{{type_name}}</b> could not be uninstalled because it is still in use by {{pages}}";
107
			$msg_template_str .= ":<br /><i>click for editing.</i><br /><br />";
108
		} else {
109
			$msg_template_str = $MESSAGE['GENERIC_CANNOT_UNINSTALL_IN_USE_TMPL'];
110
			$temp = explode(";",$MESSAGE['GENERIC_CANNOT_UNINSTALL_IN_USE_TMPL_PAGES']);
111
			$add = $info->numRows() == 1 ? $temp[0] : $temp[1];
112
		}
113
		/**
114
		*	The template-string for displaying the Page-Titles ... in this case as a link
115
		*/
116
		$page_template_str = "- <b><a href='../pages/settings.php?page_id={{id}}'>{{title}}</a></b><br />";
117

    
118
		$values = array ('type' => 'Template', 'type_name' => $file, 'pages' => $add);
119
		$msg = replace_all ( $msg_template_str,  $values );
120

    
121
		$page_names = "";
122

    
123
		while ($data = $info->fetchRow() ) {
124

    
125
			$page_info = array(
126
				'id'	=> $data['page_id'],
127
				'title' => $data['page_title']
128
			);
129

    
130
			$page_names .= replace_all ( $page_template_str, $page_info );
131
		}
132

    
133
		/**
134
		*	Printing out the error-message and die().
135
		*/
136
		$admin->print_error($MESSAGE['GENERIC_CANNOT_UNINSTALL_IN_USE'].$msg.$page_names);
137
	}
138
}
139

    
140
// Check if we have permissions on the directory
141
if(!is_writable(WB_PATH.'/templates/'.$file)) {
142
	$admin->print_error($MESSAGE['GENERIC_CANNOT_UNINSTALL'].WB_PATH.'/templates/'.$file);
143
}
144

    
145
// Try to delete the template dir
146
if(!rm_full_dir(WB_PATH.'/templates/'.$file)) {
147
	$admin->print_error($MESSAGE['GENERIC_CANNOT_UNINSTALL']);
148
} else {
149
	// Remove entry from DB
150
	$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE directory = '".$file."' AND type = 'template'");
151
}
152

    
153
// Update pages that use this template with default template
154
// $database = new database();
155
$database->query("UPDATE ".TABLE_PREFIX."pages SET template = '".DEFAULT_TEMPLATE."' WHERE template = '$file'");
156

    
157
// Print success message
158
$admin->print_success($MESSAGE['GENERIC_UNINSTALLED']);
159

    
160
// Print admin footer
161
$admin->print_footer();
(4-4/4)