Project

General

Profile

« Previous | Next » 

Revision 1643

Added by darkviper over 12 years ago

added backend functions to copy themes and import htt-template files according to the the new theme fallback functionality

View differences:

reload.php
1 1
<?php
2 2
/**
3 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.
4
 * @category        WBCore
5
 * @package         WBCore_addons
6
 * @author          Werner v.d.Decken
7
 * @copyright       Website Baker Org. e.V.
9 8
 * @link			http://www.websitebaker2.org/
10 9
 * @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$
10
 * @revision        $Revision$
14 11
 * @filesource		$HeadURL$
15 12
 * @lastmodified    $Date$
16
 *
17 13
 */
18 14

  
19 15
/**
20
 * check if there is anything to do
16
 * loop through all resource directories of one type and reload the resources
17
 * @param string $sType type of resource ( module / template / language )
18
 * @return bool
21 19
 */
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

  
20
	function ReloadAddonLoop($sType)
21
	{
22
		global $database;
23
		$database->query('DELETE FROM `'.TABLE_PREFIX.'addons` WHERE `type`=\''.$sType.'\'');
24
		try{
25
			$oIterator = new DirectoryIterator(WB_PATH.'/'.$sType.'s');
26
			$_Function = 'load_'.$sType;
27
			foreach ($oIterator as $oFileinfo) {
28
				if( ( $oFileinfo->isFile() &&
29
					   $sType == 'language' &&
30
					   preg_match('/^([A-Z]{2}.php)/', $oFileinfo->getBasename())
31
					) ||
32
				    ($oFileinfo->isDir() && $sType != 'language')
33
				  )
34
				{
35
					if(substr($oFileinfo->getBasename(), 0,1) != '.') {
36
						$_Function($oFileinfo->getPathname());
37
					}
38
				}
39
			}
40
		}catch(Exception $e) {
41
			return false;
42
		}
43
		return true;
44
	}
28 45
/**
29 46
 * check if user has permissions to access this file
30 47
 */
31
// include WB configuration file and WB admin class
32
require_once('../../config.php');
33
require_once('../../framework/class.admin.php');
34

  
48
// include all needed core files and check permission
49
	require_once('../../config.php');
50
	require_once('../../framework/class.admin.php');
51
	$aMsg = array();
52
	$aErrors = array();
35 53
// 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
					}
54
	$admin = new admin('Admintools', 'admintools', false, false);
55
	if ($admin->get_permission('admintools'))
56
	{
57
		require_once(WB_PATH . '/framework/functions.php');
58
		require_once(WB_PATH . '/languages/' . LANGUAGE .'.php');
59
	// recreate Admin object without admin header
60
		$admin = new admin('Addons', '', false, false);
61
		$js_back = ADMIN_URL . '/addons/index.php?advanced';
62
	// check transaction
63
		if ($admin->checkFTAN())
64
		{
65
		// start the selected action
66
			if(isset($_POST['cmdCopyTheme']))
67
			{
68
				$sNewTheme = (isset($_POST['ThNewTheme']) ? $_POST['ThNewTheme'] : '');
69
				require(dirname(__FILE__).'/CopyTheme.php');
70
				$ct = new CopyTheme();
71
				$ct->execute(THEME_PATH, $sNewTheme);
72
				if($ct->isError()) {
73
					$aErrors[] = $ct->getError();
74
				}else {
75
					$aMsg[] = $TEXT['THEME_COPY_CURRENT'].' :: '.$MESSAGE['GENERIC_COMPARE'];
84 76
				}
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
					}
77
				unset($ct);
78
		// ---------------------------
79
			}elseif(isset($_POST['cmdCopyTemplate']))
80
			{
81
				$aFileList = (isset($_POST['ThTemplate']) ? $_POST['ThTemplate'] : array());
82
				require(dirname(__FILE__).'/CopyThemeHtt.php');
83
				$x = CopyThemeHtt::doImport($aFileList);
84
				if(is_null($x)) {
85
					$aMsg[] = $TEXT['THEME_IMPORT_HTT'].' :: '.$MESSAGE['GENERIC_COMPARE'];
86
				}else {
87
					$aErrors = array_merge($aErrors, $x);
106 88
				}
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);
89
		// ---------------------------
90
			}elseif(isset($_POST['cmdReload']))
91
			{
92
				$aReloadType = (isset($_POST['reload']) && is_array($_POST['reload'])) ? $_POST['reload'] : array();
93
				foreach($aReloadType as $sType) {
94
					switch($sType) {
95
						case 'modules':
96
						// reload all modules
97
							if(ReloadAddonLoop('module')) {
98
								$aMsg[] = $MESSAGE['ADDON_MODULES_RELOADED'];
99
							}else {
100
								$aErrors[] = $MESSAGE['ADDON_ERROR_RELOAD'];
101
							}
102
							break;
103
						case 'templates':
104
						// reload all templates
105
							if(ReloadAddonLoop('template')) {
106
								$aMsg[] = $MESSAGE['ADDON_TEMPLATES_RELOADED'];
107
							}else {
108
								$aErrors[] = $MESSAGE['ADDON_ERROR_RELOAD'];
109
							}
110
							break;
111
						case 'languages':
112
						// reload all languages
113
							if(ReloadAddonLoop('language')) {
114
								$aMsg[] = $MESSAGE['ADDON_LANGUAGES_RELOADED'];
115
							}else {
116
								$aErrors[] = $MESSAGE['ADDON_ERROR_RELOAD'];
117
							}
118
							break;
119
						default:
120
							$aErrors[] = $MESSAGE['GENERIC_NOT_COMPARE'].' ['.$sType.']';
121
							break;
128 122
					}
129 123
				}
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);
124
			}else {
125
		// ---------------------------
126
				$aErrors[] = $MESSAGE['ADDON_ERROR_RELOAD'];
138 127
			}
139
			break;
128
		}else { // invalid FTAN
129
			$aErrors[] = $MESSAGE['GENERIC_SECURITY_ACCESS'];
130
		}
131
	}else { // no permission
132
		$aErrors[] = $MESSAGE['ADMIN_INSUFFICIENT_PRIVELLIGES'];
140 133
	}
141
}
142

  
134
	if(sizeof($aErrors) > 0)  {
135
// output error message
136
		$admin->print_header();
137
		$admin->print_error(implode('<br />', $aErrors), $js_back);
138
	}else {
143 139
// output success message
144
$admin->print_header();
145
$admin->print_success(implode($msg, '<br />'), $js_back);
146
$admin->print_footer();
140
		$admin->print_header();
141
		$admin->print_success(implode('<br />', $aMsg), $js_back);
142
		$admin->print_footer();
143
	}

Also available in: Unified diff