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 1467 2011-07-02 00:06:53Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/templates/uninstall.php $
15
 * @lastmodified    $Date: 2011-07-02 02:06:53 +0200 (Sat, 02 Jul 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_header();
27
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
28
}
29
// After check print the header
30
$admin->print_header();
31

    
32
// Check if user selected template
33
if(!isset($_POST['file']) OR $_POST['file'] == "") {
34
	header("Location: index.php");
35
	exit(0);
36
} else {
37
	$file = $_POST['file'];
38
}
39

    
40
// Extra protection
41
if(trim($file) == '') {
42
	header("Location: index.php");
43
	exit(0);
44
}
45

    
46
// 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
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
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

    
67
// 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
if ($file == DEFAULT_TEMPLATE) {
75
	$temp = array ('name' => $file );
76
	$msg = replace_all( $MESSAGE['GENERIC']['CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE'], $temp );
77
	$admin->print_error( $msg );
78

    
79
} else {
80
	
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
		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
		/**
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
		$values = array ('type' => 'Template', 'type_name' => $file, 'pages' => $add);
109
		$msg = replace_all ( $msg_template_str,  $values );
110
		
111
		$page_names = "";
112
		
113
		while ($data = $info->fetchRow() ) {
114
			
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
	}
128
}
129

    
130
// Check if we have permissions on the directory
131
if(!is_writable(WB_PATH.'/templates/'.$file)) {
132
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL'].WB_PATH.'/templates/'.$file);
133
}
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
} else {
139
	// Remove entry from DB
140
	$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE directory = '".$file."' AND type = 'template'");
141
}
142

    
143
// Update pages that use this template with default template
144
// $database = new database();
145
$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
?>
(4-4/4)