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 2098 2014-02-11 01:37:03Z darkviper $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/templates/uninstall.php $
14
 * @lastmodified    $Date: 2014-02-11 02:37:03 +0100 (Tue, 11 Feb 2014) $
15
 *
16
 */
17

    
18
// Setup admin object
19
require('../../config.php');
20
$oDb = WbDatabase::getInstance();
21
$oTrans = Translate::getInstance();
22
$oTrans->enableAddon('admin\\addons');
23
// suppress to print the header, so no new FTAN will be set
24
$admin = new admin('Addons', 'templates_uninstall', false);
25
if( !$admin->checkFTAN() )
26
{
27
	$admin->print_header();
28
	$admin->print_error($oTrans->MESSAGE_GENERIC_SECURITY_ACCESS);
29
}
30
// After check print the header
31
$admin->print_header();
32
if(!isset($_POST['file']) OR $_POST['file'] == "") {
33
	$admin->print_error($oTrans->MESSAGE_GENERIC_FORGOT_OPTIONS);
34
} else {
35
	$file = preg_replace('/[^a-z0-9_-]/i', "", $_POST['file']);  // fix secunia 2010-92-2
36
}
37

    
38
// Check if the template exists
39
if(!is_dir(WB_PATH.'/templates/'.$file)) {
40
	$admin->print_error($oTrans->MESSAGE_GENERIC_NOT_INSTALLED);
41
}
42

    
43
// Check if the template exists
44
if(!is_readable(WB_PATH.'/templates/'.$file)) {
45
	$admin->print_error($oTrans->MESSAGE_ADMIN_INSUFFICIENT_PRIVELLIGES);
46
}
47

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

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

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

    
75
/**
76
*	Check if the template is the standard-template or still in use
77
*/
78
$sMsgTpl = (isset($oTrans->MESSAGE_GENERIC_CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE)
79
            ? $oTrans->MESSAGE_GENERIC_CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE
80
            : 'Can\'t uninstall this template <b>{{name}}</b> because it\'s the standardtemplate!');
81
// check whether the template is used as default wb theme
82
if($file == DEFAULT_THEME) {
83
	$temp = array ('name' => $file );
84
	$msg = replace_all( $sMsgTpl, $temp );
85
	$admin->print_error( $msg );
86
}
87

    
88
if ($file == DEFAULT_TEMPLATE) {
89
	$temp = array ('name' => $file );
90
	$msg = replace_all( $sMsgTpl, $temp );
91
	$admin->print_error( $msg );
92

    
93
} else {
94

    
95
	/**
96
	*	Check if the template is still in use by a page ...
97
	*/
98
	$sql = 'SELECT `page_id` `id`, `page_title` `title` FROM `'.$oDb->TablePrefix.'pages` '
99
         . 'WHERE `template`=\''.$file.'\' '
100
         . 'ORDER BY `page_title`';
101
	if (($info = $oDb->doQuery($sql))) {
102
        if (($iNumberOfRows = $info->numRows())) {
103
            /**
104
            *	Template is still in use, so we're collecting the page-titles
105
            *	The base-message template-string for the top of the message
106
            */
107
            if (!isset($oTrans->MESSAGE_GENERIC_CANNOT_UNINSTALL_IN_USE_TMPL)) {
108
                $add = ($iNumberOfRows == 1 ? 'this page' : 'these pages');
109
                $msg_template_str  = '<br /><br />{{type}} <b>{{type_name}}</b> could not be uninstalled because it is still in use by {{pages}}';
110
                $msg_template_str .= ':<br /><i>click for editing.</i><br /><br />';
111
            } else {
112
                $msg_template_str = $oTrans->MESSAGE_GENERIC_CANNOT_UNINSTALL_IN_USE_TMPL;
113
                $temp = explode(";",$oTrans->MESSAGE_GENERIC_CANNOT_UNINSTALL_IN_USE_TMPL_PAGES);
114
                $add = $iNumberOfRows == 1 ? $temp[0] : $temp[1];
115
            }
116
            /**
117
            *	The template-string for displaying the Page-Titles ... in this case as a link
118
            */
119
            $page_template_str = "- <b><a href='../pages/settings.php?page_id={{id}}'>{{title}}</a></b><br />";
120
            $values = array ('type' => 'Template', 'type_name' => $file, 'pages' => $add);
121
            $msg = replace_all($msg_template_str, $values);
122
            $page_names = "";
123
            while ($page_info = $info->fetchRow(MYSQL_ASSOC) ) {
124
//                $page_info = array(
125
//                    'id'	=> $data['page_id'],
126
//                    'title' => $data['page_title']
127
//                );
128
                $page_names .= replace_all($page_template_str, $page_info);
129
            }
130
            /**
131
            *	Printing out the error-message and die().
132
            */
133
            $admin->print_error($oTrans->MESSAGE_GENERIC_CANNOT_UNINSTALL_IN_USE.$msg.$page_names);
134
        }
135
    }
136
}
137

    
138
// Check if we have permissions on the directory
139
if(!is_writable(WB_PATH.'/templates/'.$file)) {
140
	$admin->print_error($oTrans->MESSAGE_GENERIC_CANNOT_UNINSTALL.WB_PATH.'/templates/'.$file);
141
}
142

    
143
// Try to delete the template dir
144
if(!rm_full_dir(WB_PATH.'/templates/'.$file)) {
145
	$admin->print_error($oTrans->MESSAGE_GENERIC_CANNOT_UNINSTALL);
146
} else {
147
	// Remove entry from DB
148
	$sql = 'DELETE FROM `'.$oDb->TablePrefix.'addons` '
149
         . 'WHERE `directory`=\''.$file.'\' AND `type`=\'template\'';
150
	$oDb->doQuery($sql);
151
}
152
// Update pages that use this template with default template
153
// $database = new database();
154
$sql = 'UPDATE `'.$oDb->TablePrefix.'pages` '
155
     . 'SET `template`=\''.DEFAULT_TEMPLATE.'\' '
156
     . 'WHERE `template`=\''.$file.'\'';
157
$oDb->doQuery($sql);
158

    
159
// Print success message
160
$admin->print_success($oTrans->MESSAGE_GENERIC_UNINSTALLED);
161

    
162
// Print admin footer
163
$admin->print_footer();
(4-4/4)