Project

General

Profile

« Previous | Next » 

Revision 1289

Added by kweitzel over 14 years ago

Branch 2.8.1 merged back into Trunk

View differences:

reload.php
1
<?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
 * @version		0.1.1
15
 * @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
if (count($post_check) == 0) die(header('Location: index.php?advanced'));
43

  
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
$js_back = ADMIN_URL . '/addons/index.php?advanced';
73

  
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

  
1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         addons
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2010, 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 4.3.4 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL:  $
15
 * @lastmodified    $Date:  $
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
if ($admin->get_permission('admintools') == false) die(header('Location: ../../index.php'));
38

  
39
// check if the referer URL if available
40
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 
41
	(isset($HTTP_SERVER_VARS['HTTP_REFERER']) ? $HTTP_SERVER_VARS['HTTP_REFERER'] : '');
42

  
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
$admin = new admin('Addons', '', true, false);
56
$js_back = ADMIN_URL . '/addons/index.php?advanced';
57

  
58
/**
59
 * Reload all specified Addons
60
 */
61
$msg = array();
62
$table = TABLE_PREFIX . 'addons';
63

  
64
foreach ($post_check as $key) {
65
	switch ($key) {
66
		case 'reload_modules':
67
			if ($handle = opendir(WB_PATH . '/modules')) {
68
				// delete modules from database
69
				$sql = "DELETE FROM `$table` WHERE `type` = 'module'";
70
				$database->query($sql);
71

  
72
				// loop over all modules
73
				while(false !== ($file = readdir($handle))) {
74
					if ($file != '' && substr($file, 0, 1) != '.' && $file != 'admin.php' && $file != 'index.php') {
75
						load_module(WB_PATH . '/modules/' . $file);
76
					}
77
				}
78
				closedir($handle);
79
				// add success message
80
				$msg[] = $MESSAGE['ADDON']['MODULES_RELOADED'];
81

  
82
			} else {
83
				// provide error message and stop
84
				$admin->print_error($MESSAGE['ADDON']['ERROR_RELOAD'], $js_back);
85
			}
86
			break;
87
			
88
		case 'reload_templates':
89
			if ($handle = opendir(WB_PATH . '/templates')) {
90
				// delete templates from database
91
				$sql = "DELETE FROM `$table` WHERE `type` = 'template'";
92
				$database->query($sql);
93

  
94
				// loop over all templates
95
				while(false !== ($file = readdir($handle))) {
96
					if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
97
						load_template(WB_PATH . '/templates/' . $file);
98
					}
99
				}
100
				closedir($handle);
101
				// add success message
102
				$msg[] = $MESSAGE['ADDON']['TEMPLATES_RELOADED'];
103

  
104
			} else {
105
				// provide error message and stop
106
				$admin->print_error($MESSAGE['ADDON']['ERROR_RELOAD'], $js_back);
107
			}
108
			break;
109

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

  
134
// output success message
135
$admin->print_success(implode($msg, '<br />'), $js_back);
136
$admin->print_footer();
137

  
153 138
?>

Also available in: Unified diff