Project

General

Profile

1 1425 Luisehahne
<?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$
14 1457 Luisehahne
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
16 1425 Luisehahne
 *
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
// if referer is set, check if script was invoked from "admin/modules/index.php"
44
$required_url = ADMIN_URL . '/addons/index.php';
45
if ($referer != '' && (!(strpos($referer, $required_url) !== false || strpos($referer, $required_url) !== false)))
46
	die(header('Location: ../../index.php'));
47
48
// include WB functions file
49
require_once(WB_PATH . '/framework/functions.php');
50
51
// load WB language file
52
require_once(WB_PATH . '/languages/' . LANGUAGE .'.php');
53
54
// create Admin object with admin header
55 1457 Luisehahne
$admin = new admin('Addons', '', false, false);
56 1425 Luisehahne
$js_back = ADMIN_URL . '/addons/index.php?advanced';
57
58
if (!$admin->checkFTAN())
59
{
60 1457 Luisehahne
	$admin->print_header();
61 1425 Luisehahne
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$js_back);
62
}
63
64
/**
65
 * Reload all specified Addons
66
 */
67
$msg = array();
68
$table = TABLE_PREFIX . 'addons';
69
70
foreach ($post_check as $key) {
71
	switch ($key) {
72
		case 'reload_modules':
73
			if ($handle = opendir(WB_PATH . '/modules')) {
74
				// delete modules from database
75
				$sql = "DELETE FROM `$table` WHERE `type` = 'module'";
76
				$database->query($sql);
77
78
				// loop over all modules
79
				while(false !== ($file = readdir($handle))) {
80
					if ($file != '' && substr($file, 0, 1) != '.' && $file != 'admin.php' && $file != 'index.php') {
81
						load_module(WB_PATH . '/modules/' . $file);
82
					}
83
				}
84
				closedir($handle);
85
				// add success message
86
				$msg[] = $MESSAGE['ADDON']['MODULES_RELOADED'];
87
88
			} else {
89
				// provide error message and stop
90
				$admin->print_error($MESSAGE['ADDON']['ERROR_RELOAD'], $js_back);
91
			}
92
			break;
93
94
		case 'reload_templates':
95
			if ($handle = opendir(WB_PATH . '/templates')) {
96
				// delete templates from database
97
				$sql = "DELETE FROM `$table` WHERE `type` = 'template'";
98
				$database->query($sql);
99
100
				// loop over all templates
101
				while(false !== ($file = readdir($handle))) {
102
					if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
103
						load_template(WB_PATH . '/templates/' . $file);
104
					}
105
				}
106
				closedir($handle);
107
				// add success message
108
				$msg[] = $MESSAGE['ADDON']['TEMPLATES_RELOADED'];
109
110
			} else {
111
				// provide error message and stop
112 1457 Luisehahne
				$admin->print_header();
113 1425 Luisehahne
				$admin->print_error($MESSAGE['ADDON']['ERROR_RELOAD'], $js_back);
114
			}
115
			break;
116
117
		case 'reload_languages':
118
			if ($handle = opendir(WB_PATH . '/languages/')) {
119
				// delete languages from database
120
				$sql = "DELETE FROM `$table` WHERE `type` = 'language'";
121
				$database->query($sql);
122
123
				// loop over all languages
124
				while(false !== ($file = readdir($handle))) {
125
					if ($file != '' && substr($file, 0, 1) != '.' && $file != 'index.php') {
126
						load_language(WB_PATH . '/languages/' . $file);
127
					}
128
				}
129
				closedir($handle);
130
				// add success message
131
				$msg[] = $MESSAGE['ADDON']['LANGUAGES_RELOADED'];
132
133
			} else {
134
				// provide error message and stop
135 1457 Luisehahne
				$admin->print_header();
136 1425 Luisehahne
				$admin->print_error($MESSAGE['ADDON']['ERROR_RELOAD'], $js_back);
137
			}
138
			break;
139
	}
140
}
141
142
// output success message
143 1457 Luisehahne
$admin->print_header();
144 1425 Luisehahne
$admin->print_success(implode($msg, '<br />'), $js_back);
145
$admin->print_footer();