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: 2098 $
11
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/addons/reload.php $
12
 * @lastmodified    $Date: 2014-02-11 02:37:03 +0100 (Tue, 11 Feb 2014) $
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
    $oTrans = Translate::getInstance();
63
    $oTrans->enableAddon('admin\\addons');
64

    
65
	if ($admin->get_permission('admintools'))
66
	{
67
		require_once(WB_PATH . '/framework/functions.php');
68
		require_once(WB_PATH . '/languages/' . LANGUAGE .'.php');
69
	// recreate Admin object without admin header
70
		$admin = new admin('Addons', '', false, false);
71
		$js_back = ADMIN_URL . '/addons/index.php?advanced';
72
	// check transaction
73
		if ($admin->checkFTAN())
74
		{
75
		// start the selected action
76
			if(isset($_POST['cmdCopyTheme']))
77
			{
78
				$sNewTheme = (isset($_POST['ThNewTheme']) ? $_POST['ThNewTheme'] : '');
79
				require(dirname(__FILE__).'/CopyTheme.php');
80
				$ct = new CopyTheme();
81
				$ct->execute(THEME_PATH, $sNewTheme);
82
				if($ct->isError()) {
83
					$aErrors[] = $ct->getError();
84
				}else {
85
					$aMsg[] = $oTrans->TEXT_THEME_COPY_CURRENT.' :: '.$oTrans->MESSAGE_GENERIC_COMPARE;
86
				}
87
				unset($ct);
88
		// ---------------------------
89
			}elseif(isset($_POST['cmdCopyTemplate']))
90
			{
91
				$aFileList = (isset($_POST['ThTemplate']) ? $_POST['ThTemplate'] : array());
92
				require(dirname(__FILE__).'/CopyThemeHtt.php');
93
				$x = CopyThemeHtt::doImport($aFileList);
94
				if(is_null($x)) {
95
					$aMsg[] = $oTrans->TEXT_THEME_IMPORT_HTT.' :: '.$oTrans->MESSAGE_GENERIC_COMPARE;
96
				}else {
97
					$aErrors = array_merge($aErrors, $x);
98
				}
99
		// ---------------------------
100
			}elseif(isset($_POST['cmdReload']))
101
			{
102
				$aReloadType = (isset($_POST['reload']) && is_array($_POST['reload'])) ? $_POST['reload'] : array();
103
				foreach($aReloadType as $sType) {
104
					$sType = rtrim($sType, 's');
105
					switch($sType) {
106
						case 'module':
107
						case 'template':
108
						case 'language':
109
						// reload all addons from given type
110
							if(ReloadAddonLoop($sType)) {
111
                                $aMsg[] = $oTrans->{'MESSAGE_ADDON_'.strtoupper($sType).'S_RELOADED'};
112
							}else {
113
								$aErrors[] = $oTrans->MESSAGE_ADDON_ERROR_RELOAD;
114
							}
115
							break;
116
						default:
117
							$aErrors[] = $oTrans->MESSAGE_GENERIC_NOT_COMPARE.' ['.$sType.']';
118
							break;
119
					}
120
				}
121
			}else {
122
		// ---------------------------
123
				$aErrors[] = $oTrans->MESSAGE_ADDON_ERROR_RELOAD;
124
			}
125
		}else { // invalid FTAN
126
			$aErrors[] = $oTrans->MESSAGE_GENERIC_SECURITY_ACCESS;
127
		}
128
	}else { // no permission
129
		$aErrors[] = $oTrans->MESSAGE_ADMIN_INSUFFICIENT_PRIVELLIGES;
130
	}
131
	if(sizeof($aErrors) > 0)  {
132
// output error message
133
		$admin->print_header();
134
		$admin->print_error(implode('<br />', $aErrors), $js_back);
135
	}else {
136
// output success message
137
		$admin->print_header();
138
		$admin->print_success(implode('<br />', $aMsg), $js_back);
139
		$admin->print_footer();
140
	}
(4-4/4)