Project

General

Profile

1 933 doc
<?php
2
/**
3
 * $Id$
4
 * Website Baker Add-On reload
5
 *
6
 * This file contains the function to update the Add-on information from the
7
 * database with the ones stored in the Add-on files (e.g. info.php or EN.php)
8
 *
9
 * LICENSE: GNU Lesser General Public License 3.0
10
 *
11
 * @author		Christian Sommer
12
 * @copyright	(c) 2009
13
 * @license		http://www.gnu.org/copyleft/lesser.html
14 940 doc
 * @version		0.1.1
15 933 doc
 * @platform	Website Baker 2.7
16
 *
17
 * Website Baker Project <http://www.websitebaker.org/>
18
 * Copyright (C) 2004-2009, Ryan Djurovich
19
 *
20
 * Website Baker is free software; you can redistribute it and/or modify
21
 * it under the terms of the GNU General Public License as published by
22
 * the Free Software Foundation; either version 2 of the License, or
23
 * (at your option) any later version.
24
 *
25
 * Website Baker is distributed in the hope that it will be useful,
26
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
 * GNU General Public License for more details.
29
 *
30
 * You should have received a copy of the GNU General Public License
31
 * along with Website Baker; if not, write to the Free Software
32
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
33
*/
34
35
/**
36
 * check if there is anything to do
37
 */
38
$post_check = array('reload_modules', 'reload_templates', 'reload_languages');
39
foreach ($post_check as $index => $key) {
40
	if (!isset($_POST[$key])) unset($post_check[$index]);
41
}
42 940 doc
if (count($post_check) == 0) die(header('Location: index.php?advanced'));
43 933 doc
44
/**
45
 * check if user has permissions to access this file
46
 */
47
// include WB configuration file and WB admin class
48
require_once('../../config.php');
49
require_once('../../framework/class.admin.php');
50
51
// check user permissions for admintools (redirect users with wrong permissions)
52
$admin = new admin('Admintools', 'admintools', false, false);
53
if ($admin->get_permission('admintools') == false) die(header('Location: ../../index.php'));
54
55
// check if the referer URL if available
56
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] :
57
	(isset($HTTP_SERVER_VARS['HTTP_REFERER']) ? $HTTP_SERVER_VARS['HTTP_REFERER'] : '');
58
59
// if referer is set, check if script was invoked from "admin/modules/index.php"
60
$required_url = ADMIN_URL . '/addons/index.php';
61
if ($referer != '' && (!(strpos($referer, $required_url) !== false || strpos($referer, $required_url) !== false)))
62
	die(header('Location: ../../index.php'));
63
64
// include WB functions file
65
require_once(WB_PATH . '/framework/functions.php');
66
67
// load WB language file
68
require_once(WB_PATH . '/languages/' . LANGUAGE .'.php');
69
70
// create Admin object with admin header
71
$admin = new admin('Addons', '', true, false);
72 940 doc
$js_back = ADMIN_URL . '/addons/index.php?advanced';
73 933 doc
74
/**
75
 * Reload all specified Addons
76
 */
77
$msg = array();
78
$table = TABLE_PREFIX . 'addons';
79
80
foreach ($post_check as $key) {
81
	switch ($key) {
82
		case 'reload_modules':
83
			if ($handle = opendir(WB_PATH . '/modules')) {
84
				// delete modules from database
85
				$sql = "DELETE FROM `$table` WHERE `type` = 'module'";
86
				$database->query($sql);
87
88
				// loop over all modules
89
				while(false !== ($file = readdir($handle))) {
90
					if ($file != '' && substr($file, 0, 1) != '.' && $file != 'admin.php' && $file != 'index.php') {
91
						load_module(WB_PATH . '/modules/' . $file);
92
					}
93
				}
94
				closedir($handle);
95
				// add success message
96
				$msg[] = $MESSAGE['ADDON']['MODULES_RELOADED'];
97
98
			} else {
99
				// provide error message and stop
100
				$admin->print_error($MESSAGE['ADDON']['ERROR_RELOAD'], $js_back);
101
			}
102
			break;
103
104
		case 'reload_templates':
105
			if ($handle = opendir(WB_PATH . '/templates')) {
106
				// delete templates from database
107
				$sql = "DELETE FROM `$table` WHERE `type` = 'template'";
108
				$database->query($sql);
109
110
				// loop over all templates
111
				while(false !== ($file = readdir($handle))) {
112
					if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
113
						load_template(WB_PATH . '/templates/' . $file);
114
					}
115
				}
116
				closedir($handle);
117
				// add success message
118
				$msg[] = $MESSAGE['ADDON']['TEMPLATES_RELOADED'];
119
120
			} else {
121
				// provide error message and stop
122
				$admin->print_error($MESSAGE['ADDON']['ERROR_RELOAD'], $js_back);
123
			}
124
			break;
125
126
		case 'reload_languages':
127
			if ($handle = opendir(WB_PATH . '/languages/')) {
128
				// delete languages from database
129
				$sql = "DELETE FROM `$table` WHERE `type` = 'language'";
130
				$database->query($sql);
131
132
				// loop over all languages
133
				while(false !== ($file = readdir($handle))) {
134
					if ($file != '' && substr($file, 0, 1) != '.' && $file != 'index.php') {
135
						load_language(WB_PATH . '/languages/' . $file);
136
					}
137
				}
138
				closedir($handle);
139
				// add success message
140
				$msg[] = $MESSAGE['ADDON']['LANGUAGES_RELOADED'];
141
142
			} else {
143
				// provide error message and stop
144
				$admin->print_error($MESSAGE['ADDON']['ERROR_RELOAD'], $js_back);
145
			}
146
			break;
147
	}
148
}
149
150
// output success message
151
$admin->print_success(implode($msg, '<br />'), $js_back);
152
153
?>