Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        WBCore
5
 * @package         WBCore_addons
6
 * @author          Werner v.d.Decken
7
 * @copyright       Website Baker Org. e.V.
8
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @revision        $Revision: 2005 $
11
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/addons/reload.php $
12
 * @lastmodified    $Date: 2013-11-14 22:50:05 +0100 (Thu, 14 Nov 2013) $
13
 */
14

    
15
/**
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
19
 */
20
	function ReloadAddonLoop($sType)
21
	{
22
		global $database;
23
		$sql = 'DELETE FROM `'.TABLE_PREFIX.'addons` WHERE `type`=\''.$sType.'\'';
24
		try{
25
			if(!$database->query($sql)) {
26
				throw new Exception('database error');
27
			}
28
			$oIterator = new DirectoryIterator(WB_PATH.'/'.$sType.'s');
29
			$_Function = 'load_'.$sType;
30
			foreach ($oIterator as $oFileinfo) {
31
				if( ( $oFileinfo->isFile() &&
32
					   $sType == 'language' &&
33
					   preg_match('/^([A-Z]{2}.php)/', $oFileinfo->getBasename())
34
					) ||
35
				    ($oFileinfo->isDir() && $sType != 'language')
36
				  )
37
				{
38
					if(substr($oFileinfo->getBasename(), 0,1) != '.') {
39
						$_Function($oFileinfo->getPathname());
40
					}
41
				}
42
			}
43
		}catch(Exception $e) {
44
			return false;
45
		}
46
        $sTransCachePath = WB_PATH.'/temp/TranslationTable/cache/';
47
        if(is_writeable($sTransCachePath) && ($sType = 'language') ) {
48
        	rm_full_dir ( $sTransCachePath,true );
49
        }
50
		return true;
51
	}
52
/**
53
 * check if user has permissions to access this file
54
 */
55
// include all needed core files and check permission
56
	require_once('../../config.php');
57
	require_once('../../framework/class.admin.php');
58
	$aMsg = array();
59
	$aErrors = array();
60
// check user permissions for admintools (redirect users with wrong permissions)
61
	$admin = new admin('Admintools', 'admintools', false, false);
62
	if ($admin->get_permission('admintools'))
63
	{
64
		require_once(WB_PATH . '/framework/functions.php');
65
		require_once(WB_PATH . '/languages/' . LANGUAGE .'.php');
66
	// recreate Admin object without admin header
67
		$admin = new admin('Addons', '', false, false);
68
		$js_back = ADMIN_URL . '/addons/index.php?advanced';
69
	// check transaction
70
		if ($admin->checkFTAN())
71
		{
72
		// start the selected action
73
			if(isset($_POST['cmdCopyTheme']))
74
			{
75
				$sNewTheme = (isset($_POST['ThNewTheme']) ? $_POST['ThNewTheme'] : '');
76
				require(dirname(__FILE__).'/CopyTheme.php');
77
				$ct = new CopyTheme();
78
				$ct->execute(THEME_PATH, $sNewTheme);
79
				if($ct->isError()) {
80
					$aErrors[] = $ct->getError();
81
				}else {
82
					$aMsg[] = $TEXT['THEME_COPY_CURRENT'].' :: '.$MESSAGE['GENERIC_COMPARE'];
83
				}
84
				unset($ct);
85
		// ---------------------------
86
			}elseif(isset($_POST['cmdCopyTemplate']))
87
			{
88
				$aFileList = (isset($_POST['ThTemplate']) ? $_POST['ThTemplate'] : array());
89
				require(dirname(__FILE__).'/CopyThemeHtt.php');
90
				$x = CopyThemeHtt::doImport($aFileList);
91
				if(is_null($x)) {
92
					$aMsg[] = $TEXT['THEME_IMPORT_HTT'].' :: '.$MESSAGE['GENERIC_COMPARE'];
93
				}else {
94
					$aErrors = array_merge($aErrors, $x);
95
				}
96
		// ---------------------------
97
			}elseif(isset($_POST['cmdReload']))
98
			{
99
				$aReloadType = (isset($_POST['reload']) && is_array($_POST['reload'])) ? $_POST['reload'] : array();
100
				foreach($aReloadType as $sType) {
101
					$sType = rtrim($sType, 's');
102
					switch($sType) {
103
						case 'module':
104
						case 'template':
105
						case 'language':
106
						// reload all addons from given type
107
							if(ReloadAddonLoop($sType)) {
108
								$aMsg[] = $MESSAGE['ADDON_'.strtoupper($sType).'S_RELOADED'];
109
							}else {
110
								$aErrors[] = $MESSAGE['ADDON_ERROR_RELOAD'];
111
							}
112
							break;
113
						default:
114
							$aErrors[] = $MESSAGE['GENERIC_NOT_COMPARE'].' ['.$sType.']';
115
							break;
116
					}
117
				}
118
			}else {
119
		// ---------------------------
120
				$aErrors[] = $MESSAGE['ADDON_ERROR_RELOAD'];
121
			}
122
		}else { // invalid FTAN
123
			$aErrors[] = $MESSAGE['GENERIC_SECURITY_ACCESS'];
124
		}
125
	}else { // no permission
126
		$aErrors[] = $MESSAGE['ADMIN_INSUFFICIENT_PRIVELLIGES'];
127
	}
128
	if(sizeof($aErrors) > 0)  {
129
// output error message
130
		$admin->print_header();
131
		$admin->print_error(implode('<br />', $aErrors), $js_back);
132
	}else {
133
// output success message
134
		$admin->print_header();
135
		$admin->print_success(implode('<br />', $aMsg), $js_back);
136
		$admin->print_footer();
137
	}
(4-4/4)