Project

General

Profile

1
<?php
2
/**
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: uninstall.php 1457 2011-06-25 17:18:50Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/templates/uninstall.php $
15
 * @lastmodified    $Date: 2011-06-25 19:18:50 +0200 (Sat, 25 Jun 2011) $
16
 *
17
 */
18

    
19
// 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
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
27
}
28
// After check print the header
29
$admin->print_header();
30

    
31
// Check if user selected template
32
if(!isset($_POST['file']) OR $_POST['file'] == "") {
33
	header("Location: index.php");
34
	exit(0);
35
} else {
36
	$file = $_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 template exists
49
if(!is_dir(WB_PATH.'/templates/'.$file)) {
50
	$admin->print_error($MESSAGE['GENERIC']['NOT_INSTALLED']);
51
}
52

    
53
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
}
59

    
60
/**
61
*	Check if the template is the standard-template or still in use
62
*/
63
if (!array_key_exists('CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE', $MESSAGE['GENERIC'] ) )
64
	$MESSAGE['GENERIC']['CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE'] = "Can't uninstall this template <b>{{name}}</b> because it's the standardtemplate!";
65

    
66
// check whether the template is used as default wb theme
67
if($file == DEFAULT_THEME) {
68
	$temp = array ('name' => $file );
69
	$msg = replace_all( $MESSAGE['GENERIC']['CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE'], $temp );
70
	$admin->print_error( $msg );
71
}
72

    
73
if ($file == DEFAULT_TEMPLATE) {
74
	$temp = array ('name' => $file );
75
	$msg = replace_all( $MESSAGE['GENERIC']['CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE'], $temp );
76
	$admin->print_error( $msg );
77

    
78
} else {
79
	
80
	/**
81
	*	Check if the template is still in use by a page ...
82
	*/
83
	$info = $database->query("SELECT page_id, page_title FROM ".TABLE_PREFIX."pages WHERE template='".$file."' order by page_title");
84
	
85
	if ($info->numRows() > 0) {
86
		/**
87
		*	Template is still in use, so we're collecting the page-titles
88
		*/
89
		
90
		/**
91
		*	The base-message template-string for the top of the message
92
		*/
93
		if (!array_key_exists("CANNOT_UNINSTALL_IN_USE_TMPL", $MESSAGE['GENERIC'])) {
94
			$add = $info->numRows() == 1 ? "this page" : "these pages";
95
			$msg_template_str  = "<br /><br />{{type}} <b>{{type_name}}</b> could not be uninstalled because it is still in use by {{pages}}";
96
			$msg_template_str .= ":<br /><i>click for editing.</i><br /><br />";
97
		} else {
98
			$msg_template_str = $MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE_TMPL'];
99
			$temp = explode(";",$MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE_TMPL_PAGES']);
100
			$add = $info->numRows() == 1 ? $temp[0] : $temp[1];
101
		}
102
		/**
103
		*	The template-string for displaying the Page-Titles ... in this case as a link
104
		*/
105
		$page_template_str = "- <b><a href='../pages/settings.php?page_id={{id}}'>{{title}}</a></b><br />";
106
		
107
		$values = array ('type' => 'Template', 'type_name' => $file, 'pages' => $add);
108
		$msg = replace_all ( $msg_template_str,  $values );
109
		
110
		$page_names = "";
111
		
112
		while ($data = $info->fetchRow() ) {
113
			
114
			$page_info = array(
115
				'id'	=> $data['page_id'], 
116
				'title' => $data['page_title']
117
			);
118
			
119
			$page_names .= replace_all ( $page_template_str, $page_info );
120
		}
121
		
122
		/**
123
		*	Printing out the error-message and die().
124
		*/
125
		$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE'].$msg.$page_names);
126
	}
127
}
128

    
129
// Check if we have permissions on the directory
130
if(!is_writable(WB_PATH.'/templates/'.$file)) {
131
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL'].WB_PATH.'/templates/'.$file);
132
}
133

    
134
// Try to delete the template dir
135
if(!rm_full_dir(WB_PATH.'/templates/'.$file)) {
136
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL']);
137
} else {
138
	// Remove entry from DB
139
	$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE directory = '".$file."' AND type = 'template'");
140
}
141

    
142
// Update pages that use this template with default template
143
// $database = new database();
144
$database->query("UPDATE ".TABLE_PREFIX."pages SET template = '".DEFAULT_TEMPLATE."' WHERE template = '$file'");
145

    
146
// Print success message
147
$admin->print_success($MESSAGE['GENERIC']['UNINSTALLED']);
148

    
149
// Print admin footer
150
$admin->print_footer();
151

    
152
?>
(4-4/4)