Project

General

Profile

« Previous | Next » 

Revision 2098

Added by darkviper over 10 years ago

! activate class Translate for all addons in admin/ (except pages/)
! class.admin >> add translation of the current theme to Translate

View differences:

uninstall.php
17 17

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

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

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

  
46 48
// Check if user selected template
......
62 64
// Include the WB functions file
63 65
require_once(WB_PATH.'/framework/functions.php');
64 66
if (!function_exists("replace_all")) {
65
	function replace_all ($aStr = "", &$aArray ) {
66
		foreach($aArray as $k=>$v) $aStr = str_replace("{{".$k."}}", $v, $aStr);
67
	function replace_all($aStr = "", array $aArray = null ) {
68
		foreach ($aArray as $k=>$v) {
69
            $aStr = str_replace("{{".$k."}}", $v, $aStr);
70
        }
67 71
		return $aStr;
68 72
	}
69 73
}
......
71 75
/**
72 76
*	Check if the template is the standard-template or still in use
73 77
*/
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

  
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!');
77 81
// check whether the template is used as default wb theme
78 82
if($file == DEFAULT_THEME) {
79 83
	$temp = array ('name' => $file );
80
	$msg = replace_all( $MESSAGE['GENERIC_CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE'], $temp );
84
	$msg = replace_all( $sMsgTpl, $temp );
81 85
	$admin->print_error( $msg );
82 86
}
83 87

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

  
89 93
} else {
......
91 95
	/**
92 96
	*	Check if the template is still in use by a page ...
93 97
	*/
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
	}
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
    }
138 136
}
139 137

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

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

  
153 152
// Update pages that use this template with default template
154 153
// $database = new database();
155
$database->query("UPDATE ".TABLE_PREFIX."pages SET template = '".DEFAULT_TEMPLATE."' WHERE template = '$file'");
154
$sql = 'UPDATE `'.$oDb->TablePrefix.'pages` '
155
     . 'SET `template`=\''.DEFAULT_TEMPLATE.'\' '
156
     . 'WHERE `template`=\''.$file.'\'';
157
$oDb->doQuery($sql);
156 158

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

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

Also available in: Unified diff