| 1 |
2
|
Manuela
|
<?php
|
| 2 |
|
|
/**
|
| 3 |
|
|
*
|
| 4 |
|
|
* @category admin
|
| 5 |
|
|
* @package templates
|
| 6 |
|
|
* @author WebsiteBaker Project
|
| 7 |
|
|
* @copyright Ryan Djurovich
|
| 8 |
|
|
* @copyright WebsiteBaker Org. e.V.
|
| 9 |
|
|
* @link http://websitebaker.org/
|
| 10 |
|
|
* @license http://www.gnu.org/licenses/gpl.html
|
| 11 |
|
|
* @platform WebsiteBaker 2.8.3
|
| 12 |
|
|
* @requirements PHP 5.3.6 and higher
|
| 13 |
|
|
* @version $Id$
|
| 14 |
|
|
* @filesource $HeadURL$
|
| 15 |
|
|
* @lastmodified $Date$
|
| 16 |
|
|
*
|
| 17 |
|
|
*/
|
| 18 |
|
|
|
| 19 |
|
|
// Include config file and admin class file
|
| 20 |
|
|
if ( !defined( 'WB_PATH' ) ){ require( dirname(dirname((__DIR__))).'/config.php' ); }
|
| 21 |
|
|
if ( !class_exists('admin', false) ) { require(WB_PATH.'/framework/class.admin.php'); }
|
| 22 |
|
|
// Include the WB functions file
|
| 23 |
|
|
if ( !function_exists( 'get_modul_version' ) ) { require(WB_PATH.'/framework/functions.php'); }
|
| 24 |
|
|
if (!function_exists("replace_all")) {
|
| 25 |
|
|
function replace_all ($aStr = "", &$aArray ) {
|
| 26 |
|
|
foreach($aArray as $k=>$v) $aStr = str_replace("{{".$k."}}", $v, $aStr);
|
| 27 |
|
|
return $aStr;
|
| 28 |
|
|
}
|
| 29 |
|
|
}
|
| 30 |
|
|
|
| 31 |
|
|
// suppress to print the header, so no new FTAN will be set
|
| 32 |
|
|
$admin = new admin('Addons', 'templates_uninstall', false);
|
| 33 |
|
|
|
| 34 |
|
|
$js_back = ADMIN_URL.'/templates/index.php';
|
| 35 |
|
|
|
| 36 |
|
|
if( !$admin->checkFTAN() ){
|
| 37 |
|
|
$admin->print_header();
|
| 38 |
|
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $js_back );
|
| 39 |
|
|
}
|
| 40 |
|
|
// After check print the header
|
| 41 |
|
|
$admin->print_header();
|
| 42 |
|
|
|
| 43 |
|
|
$file = '';
|
| 44 |
|
|
// Check if user selected template
|
| 45 |
|
|
if (!isset($_POST['file']) || $_POST['file'] == false) {
|
| 46 |
|
|
$iAddonId = 0;
|
| 47 |
|
|
$admin->print_error( $MESSAGE['GENERIC_FORGOT_OPTIONS'], $js_back );
|
| 48 |
|
|
} else {
|
| 49 |
|
|
$iAddonId = $admin->checkIDKEY('file',0);
|
| 50 |
|
|
}
|
| 51 |
|
|
if ($iAddonId == 0){
|
| 52 |
|
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $js_back );
|
| 53 |
|
|
}
|
| 54 |
|
|
|
| 55 |
|
|
// Get template directory
|
| 56 |
|
|
$sqlAddons = 'SELECT `directory` FROM `'.TABLE_PREFIX.'addons` '
|
| 57 |
|
|
. 'WHERE `addon_id`='.(int)$iAddonId.' '
|
| 58 |
|
|
. ''.'';
|
| 59 |
|
|
if ($file = $database->get_one($sqlAddons)) {
|
| 60 |
|
|
$file = preg_replace('/[^a-z0-9_-]/i', "", $file); // fix secunia 2010-92-2
|
| 61 |
|
|
}
|
| 62 |
|
|
|
| 63 |
|
|
// check whether the template is used as default wb theme
|
| 64 |
|
|
$aPreventFromUninstall = array ('wb_theme', 'WbTheme', 'default_theme', 'DefaultTheme', 'default' );
|
| 65 |
|
|
if(
|
| 66 |
|
|
$file == DEFAULT_THEME ||
|
| 67 |
|
|
preg_match('/'.$file.'/si', implode('|', $aPreventFromUninstall ))
|
| 68 |
|
|
) {
|
| 69 |
|
|
$temp = array ('name' => $file );
|
| 70 |
|
|
$msg = replace_all( $MESSAGE['GENERIC_CANNOT_UNINSTALL_IS_DEFAULT_THEME'], $temp );
|
| 71 |
|
|
$admin->print_error( $msg );
|
| 72 |
|
|
}
|
| 73 |
|
|
// Check if the template exists
|
| 74 |
|
|
if (!is_dir(WB_PATH.'/templates/'.$file)) {
|
| 75 |
|
|
$admin->print_error($MESSAGE['GENERIC_NOT_INSTALLED'], $js_back );
|
| 76 |
|
|
}
|
| 77 |
|
|
/**
|
| 78 |
|
|
* Check if the template is the standard-template or still in use
|
| 79 |
|
|
*/
|
| 80 |
|
|
if (!array_key_exists('CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE', $MESSAGE['GENERIC'] ) )
|
| 81 |
|
|
$MESSAGE['GENERIC_CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE'] = "Can't uninstall this template <b>{{name}}</b> because it's the standardtemplate!";
|
| 82 |
|
|
|
| 83 |
|
|
// check whether the template is used as default wb theme
|
| 84 |
|
|
if($file == DEFAULT_THEME) {
|
| 85 |
|
|
$temp = array ('name' => $file );
|
| 86 |
|
|
$msg = replace_all( $MESSAGE['GENERIC_CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE'], $temp );
|
| 87 |
|
|
$admin->print_error( $msg );
|
| 88 |
|
|
}
|
| 89 |
|
|
|
| 90 |
|
|
if ($file == DEFAULT_TEMPLATE) {
|
| 91 |
|
|
$temp = array ('name' => $file );
|
| 92 |
|
|
$msg = replace_all( $MESSAGE['GENERIC_CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE'], $temp );
|
| 93 |
|
|
$admin->print_error( $msg );
|
| 94 |
|
|
|
| 95 |
|
|
} else {
|
| 96 |
|
|
|
| 97 |
|
|
/**
|
| 98 |
|
|
* Check if the template is still in use by a page ...
|
| 99 |
|
|
*/
|
| 100 |
|
|
|
| 101 |
|
|
$sqlPage = 'SELECT `page_id`, `page_title` FROM `'.TABLE_PREFIX.'pages` '
|
| 102 |
|
|
. 'WHERE `template`=\''.$file.'\' '
|
| 103 |
|
|
. 'ORDER BY `page_title`'.' ';
|
| 104 |
|
|
$info = $database->query($sqlPage);
|
| 105 |
|
|
if ($info->numRows() > 0) {
|
| 106 |
|
|
/**
|
| 107 |
|
|
* Template is still in use, so we're collecting the page-titles
|
| 108 |
|
|
*/
|
| 109 |
|
|
|
| 110 |
|
|
/**
|
| 111 |
|
|
* The base-message template-string for the top of the message
|
| 112 |
|
|
*/
|
| 113 |
|
|
if (!array_key_exists("CANNOT_UNINSTALL_IN_USE_TMPL", $MESSAGE['GENERIC'])) {
|
| 114 |
|
|
$add = $info->numRows() == 1 ? "this page" : "these pages";
|
| 115 |
|
|
$msg_template_str = "<br /><br />{{type}} <b>{{type_name}}</b> could not be uninstalled because it is still in use by {{pages}}";
|
| 116 |
|
|
$msg_template_str .= ":<br /><i>click for editing.</i><br /><br />";
|
| 117 |
|
|
} else {
|
| 118 |
|
|
$msg_template_str = $MESSAGE['GENERIC_CANNOT_UNINSTALL_IN_USE_TMPL'];
|
| 119 |
|
|
$temp = explode(";",$MESSAGE['GENERIC_CANNOT_UNINSTALL_IN_USE_TMPL_PAGES']);
|
| 120 |
|
|
$add = $info->numRows() == 1 ? $temp[0] : $temp[1];
|
| 121 |
|
|
}
|
| 122 |
|
|
/**
|
| 123 |
|
|
* The template-string for displaying the Page-Titles ... in this case as a link
|
| 124 |
|
|
*/
|
| 125 |
|
|
$page_template_str = "- <b><a href='../pages/settings.php?page_id={{id}}'>{{title}}</a></b><br />";
|
| 126 |
|
|
$values = array ('type' => 'Template', 'type_name' => $file, 'pages' => $add);
|
| 127 |
|
|
$msg = replace_all ( $msg_template_str, $values );
|
| 128 |
|
|
$page_names = "";
|
| 129 |
|
|
|
| 130 |
|
|
while ($data = $info->fetchRow() ) {
|
| 131 |
|
|
$page_info = array(
|
| 132 |
|
|
'id' => $data['page_id'],
|
| 133 |
|
|
'title' => $data['page_title']
|
| 134 |
|
|
);
|
| 135 |
|
|
$page_names .= replace_all ( $page_template_str, $page_info );
|
| 136 |
|
|
}
|
| 137 |
|
|
|
| 138 |
|
|
/**
|
| 139 |
|
|
* Printing out the error-message and die().
|
| 140 |
|
|
*/
|
| 141 |
|
|
$admin->print_error($MESSAGE['GENERIC_CANNOT_UNINSTALL_IN_USE'].$msg.$page_names);
|
| 142 |
|
|
}
|
| 143 |
|
|
}
|
| 144 |
|
|
|
| 145 |
|
|
// Check if we have permissions on the directory
|
| 146 |
|
|
if (!is_writable(WB_PATH.'/templates/'.$file)) {
|
| 147 |
|
|
$admin->print_error(' ('.$file.') '.$MESSAGE['GENERIC_CANNOT_UNINSTALL'], $js_back);
|
| 148 |
|
|
}
|
| 149 |
|
|
// Try to delete the template dir
|
| 150 |
|
|
if (!rm_full_dir(WB_PATH.'/templates/'.$file)) {
|
| 151 |
|
|
$admin->print_error(' ('.$file.') '.$MESSAGE['GENERIC_CANNOT_UNINSTALL'], $js_back);
|
| 152 |
|
|
} else {
|
| 153 |
|
|
// Remove entry from DB
|
| 154 |
|
|
$sql = 'DELETE FROM `'.TABLE_PREFIX.'addons`'
|
| 155 |
|
|
. 'WHERE `directory` = \''.$file.'\' '
|
| 156 |
|
|
. 'AND type = \'template\' ';
|
| 157 |
|
|
$database->query($sql);
|
| 158 |
|
|
}
|
| 159 |
|
|
|
| 160 |
|
|
// Update pages that use this template with default template
|
| 161 |
|
|
$sql = 'UPDATE '.TABLE_PREFIX.'pages SET '
|
| 162 |
|
|
. 'template = '.DEFAULT_TEMPLATE.''
|
| 163 |
|
|
. 'WHERE template = \''.$file.'\'';
|
| 164 |
|
|
if (!$database->query($sql)){}
|
| 165 |
|
|
// Print success message
|
| 166 |
|
|
$admin->print_success(' ('.$file.') '.$MESSAGE['GENERIC_UNINSTALLED'], $js_back);
|
| 167 |
|
|
|
| 168 |
|
|
|
| 169 |
|
|
// Print admin footer
|
| 170 |
|
|
$admin->print_footer();
|