Project

General

Profile

1 1425 Luisehahne
<?php
2
/**
3
 *
4 1643 darkviper
 * @category        WBCore
5
 * @package         WBCore_addons
6
 * @author          Werner v.d.Decken
7
 * @copyright       Website Baker Org. e.V.
8 1425 Luisehahne
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10 1643 darkviper
 * @revision        $Revision$
11 1457 Luisehahne
 * @filesource		$HeadURL$
12
 * @lastmodified    $Date$
13 1425 Luisehahne
 */
14
15
/**
16 1643 darkviper
 * 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 1425 Luisehahne
 */
20 1643 darkviper
	function ReloadAddonLoop($sType)
21
	{
22
		global $database;
23 1669 darkviper
		$sql = 'DELETE FROM `'.TABLE_PREFIX.'addons` WHERE `type`=\''.$sType.'\'';
24 1643 darkviper
		try{
25 1669 darkviper
			if(!$database->query($sql)) {
26
				throw new Exception('database error');
27
			}
28 1643 darkviper
			$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 2005 Luisehahne
        $sTransCachePath = WB_PATH.'/temp/TranslationTable/cache/';
47
        if(is_writeable($sTransCachePath) && ($sType = 'language') ) {
48
        	rm_full_dir ( $sTransCachePath,true );
49
        }
50 1643 darkviper
		return true;
51
	}
52 1425 Luisehahne
/**
53
 * check if user has permissions to access this file
54
 */
55 1643 darkviper
// 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 1425 Luisehahne
// check user permissions for admintools (redirect users with wrong permissions)
61 1643 darkviper
	$admin = new admin('Admintools', 'admintools', false, false);
62 2098 darkviper
    $oTrans = Translate::getInstance();
63
    $oTrans->enableAddon('admin\\addons');
64
65 1643 darkviper
	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 2098 darkviper
					$aMsg[] = $oTrans->TEXT_THEME_COPY_CURRENT.' :: '.$oTrans->MESSAGE_GENERIC_COMPARE;
86 1425 Luisehahne
				}
87 1643 darkviper
				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 2098 darkviper
					$aMsg[] = $oTrans->TEXT_THEME_IMPORT_HTT.' :: '.$oTrans->MESSAGE_GENERIC_COMPARE;
96 1643 darkviper
				}else {
97
					$aErrors = array_merge($aErrors, $x);
98 1425 Luisehahne
				}
99 1643 darkviper
		// ---------------------------
100
			}elseif(isset($_POST['cmdReload']))
101
			{
102
				$aReloadType = (isset($_POST['reload']) && is_array($_POST['reload'])) ? $_POST['reload'] : array();
103
				foreach($aReloadType as $sType) {
104 1669 darkviper
					$sType = rtrim($sType, 's');
105 1643 darkviper
					switch($sType) {
106 1669 darkviper
						case 'module':
107
						case 'template':
108
						case 'language':
109
						// reload all addons from given type
110
							if(ReloadAddonLoop($sType)) {
111 2098 darkviper
                                $aMsg[] = $oTrans->{'MESSAGE_ADDON_'.strtoupper($sType).'S_RELOADED'};
112 1643 darkviper
							}else {
113 2098 darkviper
								$aErrors[] = $oTrans->MESSAGE_ADDON_ERROR_RELOAD;
114 1643 darkviper
							}
115
							break;
116
						default:
117 2098 darkviper
							$aErrors[] = $oTrans->MESSAGE_GENERIC_NOT_COMPARE.' ['.$sType.']';
118 1643 darkviper
							break;
119 1425 Luisehahne
					}
120
				}
121 1643 darkviper
			}else {
122
		// ---------------------------
123 2098 darkviper
				$aErrors[] = $oTrans->MESSAGE_ADDON_ERROR_RELOAD;
124 1425 Luisehahne
			}
125 1643 darkviper
		}else { // invalid FTAN
126 2098 darkviper
			$aErrors[] = $oTrans->MESSAGE_GENERIC_SECURITY_ACCESS;
127 1643 darkviper
		}
128
	}else { // no permission
129 2098 darkviper
		$aErrors[] = $oTrans->MESSAGE_ADMIN_INSUFFICIENT_PRIVELLIGES;
130 1425 Luisehahne
	}
131 1643 darkviper
	if(sizeof($aErrors) > 0)  {
132
// output error message
133
		$admin->print_header();
134
		$admin->print_error(implode('<br />', $aErrors), $js_back);
135
	}else {
136 1425 Luisehahne
// output success message
137 1643 darkviper
		$admin->print_header();
138
		$admin->print_success(implode('<br />', $aMsg), $js_back);
139
		$admin->print_footer();
140
	}