Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         addons
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: reload.php 1603 2012-02-08 03:08:19Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/addons/reload.php $
15
 * @lastmodified    $Date: 2012-02-08 04:08:19 +0100 (Wed, 08 Feb 2012) $
16
 *
17
 */
18

    
19
/**
20
 * check if there is anything to do
21
 */
22
$post_check = array('reload_modules', 'reload_templates', 'reload_languages');
23
foreach ($post_check as $index => $key) {
24
	if (!isset($_POST[$key])) unset($post_check[$index]);
25
}
26
if (count($post_check) == 0) die(header('Location: index.php?advanced'));
27

    
28
/**
29
 * check if user has permissions to access this file
30
 */
31
// include WB configuration file and WB admin class
32
require_once('../../config.php');
33
require_once('../../framework/class.admin.php');
34

    
35
// check user permissions for admintools (redirect users with wrong permissions)
36
$admin = new admin('Admintools', 'admintools', false, false);
37

    
38
if ($admin->get_permission('admintools') == false) die(header('Location: ../../index.php'));
39

    
40
// check if the referer URL if available
41
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] :
42
	(isset($HTTP_SERVER_VARS['HTTP_REFERER']) ? $HTTP_SERVER_VARS['HTTP_REFERER'] : '');
43
$referer = '';
44
// if referer is set, check if script was invoked from "admin/modules/index.php"
45
$required_url = ADMIN_URL . '/addons/index.php';
46
if ($referer != '' && (!(strpos($referer, $required_url) !== false || strpos($referer, $required_url) !== false)))
47
	die(header('Location: ../../index.php'));
48

    
49
// include WB functions file
50
require_once(WB_PATH . '/framework/functions.php');
51

    
52
// load WB language file
53
require_once(WB_PATH . '/languages/' . LANGUAGE .'.php');
54

    
55
// create Admin object with admin header
56
$admin = new admin('Addons', '', false, false);
57
$js_back = ADMIN_URL . '/addons/index.php?advanced';
58

    
59
if (!$admin->checkFTAN())
60
{
61
	$admin->print_header();
62
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$js_back);
63
}
64

    
65
/**
66
 * Reload all specified Addons
67
 */
68
$msg = array();
69
$table = TABLE_PREFIX . 'addons';
70

    
71
foreach ($post_check as $key) {
72
	switch ($key) {
73
		case 'reload_modules':
74
			if ($handle = opendir(WB_PATH . '/modules')) {
75
				// delete modules from database
76
				$sql = "DELETE FROM `$table` WHERE `type` = 'module'";
77
				$database->query($sql);
78

    
79
				// loop over all modules
80
				while(false !== ($file = readdir($handle))) {
81
					if ($file != '' && substr($file, 0, 1) != '.' && $file != 'admin.php' && $file != 'index.php') {
82
						load_module(WB_PATH . '/modules/' . $file);
83
					}
84
				}
85
				closedir($handle);
86
				// add success message
87
				$msg[] = $MESSAGE['ADDON']['MODULES_RELOADED'];
88

    
89
			} else {
90
				// provide error message and stop
91
				$admin->print_error($MESSAGE['ADDON']['ERROR_RELOAD'], $js_back);
92
			}
93
			break;
94
			
95
		case 'reload_templates':
96
			if ($handle = opendir(WB_PATH . '/templates')) {
97
				// delete templates from database
98
				$sql = "DELETE FROM `$table` WHERE `type` = 'template'";
99
				$database->query($sql);
100

    
101
				// loop over all templates
102
				while(false !== ($file = readdir($handle))) {
103
					if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
104
						load_template(WB_PATH . '/templates/' . $file);
105
					}
106
				}
107
				closedir($handle);
108
				// add success message
109
				$msg[] = $MESSAGE['ADDON']['TEMPLATES_RELOADED'];
110

    
111
			} else {
112
				// provide error message and stop
113
				$admin->print_header();
114
				$admin->print_error($MESSAGE['ADDON']['ERROR_RELOAD'], $js_back);
115
			}
116
			break;
117

    
118
		case 'reload_languages':
119
			if ($handle = opendir(WB_PATH . '/languages/')) {
120
				// delete languages from database
121
				$sql = "DELETE FROM `$table` WHERE `type` = 'language'";
122
				$database->query($sql);
123
			
124
				// loop over all languages
125
				while(false !== ($file = readdir($handle))) {
126
					if ($file != '' && substr($file, 0, 1) != '.' && $file != 'index.php') {
127
						load_language(WB_PATH . '/languages/' . $file);
128
					}
129
				}
130
				closedir($handle);
131
				// add success message
132
				$msg[] = $MESSAGE['ADDON']['LANGUAGES_RELOADED'];
133
				
134
			} else {
135
				// provide error message and stop
136
				$admin->print_header();
137
				$admin->print_error($MESSAGE['ADDON']['ERROR_RELOAD'], $js_back);
138
			}
139
			break;
140
	}
141
}
142

    
143
// output success message
144
$admin->print_header();
145
$admin->print_success(implode($msg, '<br />'), $js_back);
146
$admin->print_footer();
(2-2/2)