forked from soerennb/extplorer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.php
185 lines (177 loc) · 5.1 KB
/
application.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
// ensure this file is being included by a parent file
if( !defined( '_JEXEC' ) && !defined( '_VALID_MOS' ) ) die( 'Restricted access' );
/**
* @package eXtplorer
* @version $Id: application.php 241 2015-01-22 20:57:42Z soeren $
* @copyright soeren 2007-2015
* @author The eXtplorer project (http://extplorer.net)
* @license
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License',
*
* Alternatively, the contents of this file may be used under the terms
* of the GNU General Public License Version 2 or later (the "GPL"), in
* which case the provisions of the GPL are applicable instead of
* those above. If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use
* your version of this file under the MPL, indicate your decision by
* deleting the provisions above and replace them with the notice and
* other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this file
* under either the MPL or the GPL."
*
*/
/**
* Abstract Action Class
* @abstract
*/
class ext_Action {
/**
* This function executes the action
*
* @param string $dir
* @param string $item
*/
static function execAction( $dir, $item ) {
// to be overridden by the child class
}
}
/**
* Wrapper Class for the Global Language Array
* @since 2.0.0
* @author soeren
*
*/
class ext_Lang {
/**
* Returns a string from $GLOBALS['messages']
*
* @param string $msg
* @param boolean $make_javascript_safe
* @return string
*/
static function msg( $msg, $make_javascript_safe=false ) {
$str = ext_Lang::_get('messages', $msg );
if( $make_javascript_safe ) {
return ext_Lang::escape_for_javascript( $str );
} else {
return $str;
}
}
/**
* Returns a string from $GLOBALS['error_msg']
*
* @param string $err
* @param boolean $make_javascript_safe
* @return string
*/
static function err( $err, $make_javascript_safe=false ) {
$str = ext_Lang::_get('error_msg', $err );
if( $make_javascript_safe ) {
return ext_Lang::escape_for_javascript( $str );
} else {
return $str;
}
}
static function mime( $mime, $make_javascript_safe=false ) {
$str = ext_Lang::_get('mimes', $mime );
if( $make_javascript_safe ) {
return ext_Lang::escape_for_javascript( $str );
} else {
return $str;
}
}
/**
* Gets the string from the array
*
* @param string $array_index
* @param string $message
* @return string
* @access private
*/
static function _get( $array_index, $message ) {
if( is_array( $message )) {
return @$GLOBALS[$array_index][key($message)][current($message)];
}
return isset($GLOBALS[$array_index][$message]) ? $GLOBALS[$array_index][$message] : $message;
}
static function escape_for_javascript( $string ) {
return str_replace(Array("\r", "\n" ), Array('\r', '\n' ) , addslashes($string));
}
static function detect_lang() {
$default = 'english';
if( empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) return $default;
$_AL=strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']);
$_UA=strtolower($_SERVER['HTTP_USER_AGENT']);
// Try to detect Primary language if several languages are accepted',
foreach($GLOBALS['_LANG'] as $K => $lang) {
if(strpos($_AL, $K)===0)
return file_exists( _EXT_PATH.'/languages/'.$lang.'.php' ) ? $lang : $default;
}
// Try to detect any language if not yet detected',
foreach($GLOBALS['_LANG'] as $K => $lang) {
if(strpos($_AL, $K)!==false)
return file_exists( _EXT_PATH.'/languages/'.$lang.'.php' ) ? $lang : $default;
}
foreach($GLOBALS['_LANG'] as $K => $lang) {
if(preg_match("/[\[\( ]{$K}[;,_\-\)]/",$_UA))
return file_exists( _EXT_PATH.'/languages/'.$lang.'.php' ) ? $lang : $default;
}
// Return default language if language is not yet detected',
return $default;
}
}
// Define all available languages',
// WARNING: uncomment all available languages
$GLOBALS['_LANG'] = array(
'af' => 'afrikaans',
'ar' => 'arabic',
'bg' => 'bulgarian',
'ca' => 'catalan',
'cs' => 'czech',
'da' => 'danish',
'de' => 'german',
'el' => 'greek',
'en' => 'english',
'es' => 'spanish',
'et' => 'estonian',
'fi' => 'finnish',
'fr' => 'french',
'gl' => 'galician',
'he' => 'hebrew',
'hi' => 'hindi',
'hr' => 'croatian',
'hu' => 'hungarian',
'id' => 'indonesian',
'it' => 'italian',
'ja' => 'japanese',
'ko' => 'korean',
'ka' => 'georgian',
'lt' => 'lithuanian',
'lv' => 'latvian',
'ms' => 'malay',
'nl' => 'dutch',
'no' => 'norwegian',
'pl' => 'polish',
'pt' => 'portuguese',
'ro' => 'romanian',
'ru' => 'russian',
'sk' => 'slovak',
'sl' => 'slovenian',
'sq' => 'albanian',
'sr' => 'serbian',
'sv' => 'swedish',
'th' => 'thai',
'tr' => 'turkish',
'uk' => 'ukrainian',
'zh-tw' => 'traditional_chinese',
'zh-cn' => 'simplified_chinese'
);