18 require_once SQ_LIB_PATH.
'/config/prefs.inc';
34 var $pref_vars = Array(
35 'SQ_FILE_MAX_SIZE' => Array(
36 'name' =>
'max_file_upload',
37 'description' =>
'This preference allows you to change the maximum size of files that can be uploaded',
41 'SQ_FILE_PREUPLOADED_MAX_SIZE' => Array(
42 'name' =>
'preuploaded_max_file_upload',
43 'description' =>
'This preference allows you to change the maximum size of files that can be created from pre-uploaded ones',
47 'SQ_FILE_ALLOW_NO_EXTENSION' => Array(
48 'name' =>
'allow_file_with_no_extension',
49 'description' =>
'This preference allows you to use file with no extension.',
53 'SQ_FILE_ALLOWED_TYPES' => Array(
54 'name' =>
'allowed_file_extensions_to_upload',
55 'description' =>
'This preference allows you to restrict the allowed types of files to upload',
59 'SQ_FILE_ALLOWED_PREUPLOADED_TYPES' => Array(
60 'name' =>
'allowed_file_extentions_for_pre_uploaded_files',
61 'description' =>
'This preference allows you to restrict the allowed types of pre-uploaded files',
66 'SQ_FILE_ASSET_SUMMARY' => Array(
67 'name' =>
'file_asset_summary',
68 'description' =>
'This preference allows user to customize the content for asset_summary_X keyword replacement',
69 'default' =>
'%file_type^uppercase%, %asset_file_size_in_bytes^divide:1024^round:2% KB',
81 $this->
Prefs($pref_file);
98 $is_root = $GLOBALS[
'SQ_SYSTEM']->userRoot();
99 $is_admin = ($is_root || $GLOBALS[
'SQ_SYSTEM']->userSystemAdmin());
102 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
105 $ini_size = strtolower(ini_get(
'upload_max_filesize'));
106 if (substr($ini_size, -1) ==
'k') {
107 $ini_size = $ini_size * 1024;
108 }
else if (substr($ini_size, -1) ==
'm') {
109 $ini_size = $ini_size * 1024 * 1024;
113 $post_size = strtolower(ini_get(
'post_max_size'));
114 if (substr($post_size, -1) ==
'k') {
115 $post_size = $post_size * 1024;
116 }
else if (substr($post_size, -1) ==
'm') {
117 $post_size = $post_size * 1024 * 1024;
120 $mem_limit_size = strtolower(ini_get(
'memory_limit'));
121 if (substr($mem_limit_size, -1) ==
'k') {
122 $mem_limit_size = $mem_limit_size * 1024;
123 }
else if (substr($mem_limit_size, -1) ==
'm') {
124 $mem_limit_size = $mem_limit_size * 1024 * 1024;
126 $php_max_file_size = min($ini_size, $post_size, $mem_limit_size);
129 if (is_null($pref) || $pref ==
'SQ_FILE_MAX_SIZE') {
130 if (is_null($pref)) {
131 $o->openField(translate( $this->pref_vars[
'SQ_FILE_MAX_SIZE'][
'name']));
134 if ($have_lock && $is_admin) {
135 text_box(
'prefs[SQ_FILE_MAX_SIZE]', $this->pref_vars[
'SQ_FILE_MAX_SIZE'][
'default'], 10);
136 echo $o->note(translate(
'warn_max_settable_file_size',
'<b>'.strtoupper(easy_filesize($php_max_file_size)).
'</b>'));
137 if ($ini_size > $post_size) {
138 echo $o->note(translate(
'warn_max_settable_file_size_warning',
'<b>'.strtoupper(easy_filesize($post_size)).
'</b>'));
141 if (!$this->pref_vars[
'SQ_FILE_MAX_SIZE'][
'default']) {
142 echo translate(
'warn_set_max_file_size',
'<b>'.strtoupper(easy_filesize($php_max_file_size)).
'</b>');
144 $max_file_size = strtolower($this->pref_vars[
'SQ_FILE_MAX_SIZE'][
'default']);
145 if (substr($max_file_size, -1) ==
'k') {
146 $max_file_size = $max_file_size * 1024;
147 }
else if (substr($max_file_size, -1) ==
'm') {
148 $max_file_size = $max_file_size * 1024 * 1024;
151 if ($max_file_size > $php_max_file_size) {
152 echo translate(
'file_size_above_limit',
'<b>'.strtoupper(easy_filesize($max_file_size)).
'</b>',
'<b>'.strtoupper(easy_filesize($php_max_file_size)).
'</b>');
154 echo strtoupper(easy_filesize($max_file_size));
156 if ($ini_size > $post_size) {
157 echo $o->note(translate(
'warn_max_settable_file_size_warning',
'<b>'.strtoupper(easy_filesize($post_size)).
'</b>'));
161 if (is_null($pref)) $o->closeField();
165 if (is_null($pref) || $pref ==
'SQ_FILE_PREUPLOADED_MAX_SIZE') {
166 if (is_null($pref)) {
167 $o->openField(translate($this->pref_vars[
'SQ_FILE_PREUPLOADED_MAX_SIZE'][
'name']));
170 if ($have_lock && $is_admin) {
171 text_box(
'prefs[SQ_FILE_PREUPLOADED_MAX_SIZE]', $this->pref_vars[
'SQ_FILE_PREUPLOADED_MAX_SIZE'][
'default'], 10);
172 echo $o->note(translate(
'warn_preuploaded_max_settable_file_size',
'<b>'.strtoupper(easy_filesize($php_max_file_size)).
'</b>'));
174 if (!$this->pref_vars[
'SQ_FILE_PREUPLOADED_MAX_SIZE'][
'default']) {
175 echo translate(
'warn_preuploaded_max_settable_file_size',
'<b>'.strtoupper(easy_filesize($php_max_file_size)).
'</b>');
177 $max_file_size = strtolower($this->pref_vars[
'SQ_FILE_PREUPLOADED_MAX_SIZE'][
'default']);
178 if (substr($max_file_size, -1) ==
'k') {
179 $max_file_size = $max_file_size * 1024;
180 }
else if (substr($max_file_size, -1) ==
'm') {
181 $max_file_size = $max_file_size * 1024 * 1024;
183 echo strtoupper(easy_filesize($max_file_size));
186 if (is_null($pref)) $o->closeField();
190 if (is_null($pref) || $pref ==
'SQ_FILE_ALLOW_NO_EXTENSION') {
191 if (is_null($pref)) {
192 $o->openField(translate($this->pref_vars[
'SQ_FILE_ALLOW_NO_EXTENSION'][
'name']));
195 $value = $this->pref_vars[
'SQ_FILE_ALLOW_NO_EXTENSION'][
'default'];
196 if ($have_lock && $is_admin) {
197 $options = Array(1 =>
'Yes', 0 =>
'No');
198 combo_box(
'prefs[SQ_FILE_ALLOW_NO_EXTENSION]', $options, FALSE, $value);
200 echo ($value) ? translate(
'yes') : translate(
'no');
202 if (is_null($pref)) $o->closeField();
206 if (is_null($pref) || $pref ==
'SQ_FILE_ALLOWED_TYPES') {
207 if (is_null($pref)) {
208 $o->openField(translate($this->pref_vars[
'SQ_FILE_ALLOWED_TYPES'][
'name']));
211 if ($have_lock && $is_admin) {
212 text_box(
'prefs[SQ_FILE_ALLOWED_TYPES]', $this->pref_vars[
'SQ_FILE_ALLOWED_TYPES'][
'default'], 20);
213 echo $o->note(translate(
'allowed_file_extensions_note'));
215 $value = $this->pref_vars[
'SQ_FILE_ALLOWED_TYPES'][
'default'];
217 echo translate(
'allowed_file_extensions_not_specified');
219 $exts = explode(
',', $value);
220 $num_exts = count($exts);
221 if ($num_exts == 1) {
222 $ext_str = array_pop($exts);
223 }
else if ($num_exts > 1) {
224 $ext_str = implode(
', ', array_slice($exts, 0, -1)).
' and '.$exts[$num_exts - 1];
226 echo translate(
'allowed_file_extensions_list', (($num_exts > 1) ?
's are ' :
' is ').$ext_str);
229 if (is_null($pref)) $o->closeField();
233 if (is_null($pref) || $pref ==
'SQ_FILE_ALLOWED_PREUPLOADED_TYPES') {
234 if (is_null($pref)) {
235 $o->openField(translate($this->pref_vars[
'SQ_FILE_ALLOWED_PREUPLOADED_TYPES'][
'name']));
238 if ($have_lock && $is_admin) {
239 text_box(
'prefs[SQ_FILE_ALLOWED_PREUPLOADED_TYPES]', $this->pref_vars[
'SQ_FILE_ALLOWED_PREUPLOADED_TYPES'][
'default'], 20);
240 echo $o->note(translate(
'allowed_file_extensions_note'));
242 $value = $this->pref_vars[
'SQ_FILE_ALLOWED_PREUPLOADED_TYPES'][
'default'];
244 echo translate(
'allowed_file_extensions_not_specified');
246 $exts = explode(
',', $value);
247 $num_exts = count($exts);
248 if ($num_exts == 1) {
249 $ext_str = array_pop($exts);
250 }
else if ($num_exts > 1) {
251 $ext_str = implode(
', ', array_slice($exts, 0, -1)).
' and '.$exts[$num_exts - 1];
253 echo translate(
'allowed_file_extensions_list', (($num_exts > 1) ?
's are ' :
' is ').$ext_str);
256 if (is_null($pref)) $o->closeField();
260 if (is_null($pref) || $pref ==
'SQ_FILE_ASSET_SUMMARY') {
261 if (is_null($pref)) {
262 $o->openField(translate($this->pref_vars[
'SQ_FILE_ASSET_SUMMARY'][
'name']));
265 if ($have_lock && $is_admin) {
266 text_area(
'prefs[SQ_FILE_ASSET_SUMMARY]', $this->pref_vars[
'SQ_FILE_ASSET_SUMMARY'][
'default'], 60, 5);
267 echo $o->note(translate(
'file_asset_summary_note'));
269 $value = $this->pref_vars[
'SQ_FILE_ASSET_SUMMARY'][
'default'];
272 if (is_null($pref)) $o->closeField();
292 $is_root = $GLOBALS[
'SQ_SYSTEM']->userRoot();
293 $is_admin = ($is_root || $GLOBALS[
'SQ_SYSTEM']->userSystemAdmin());
294 if (!$is_admin)
return FALSE;
297 if (is_null($pref) || $pref ==
'SQ_FILE_MAX_SIZE') {
298 if (isset($_POST[
'prefs'][
'SQ_FILE_MAX_SIZE'])) {
299 $max_size = strtoupper(trim($_POST[
'prefs'][
'SQ_FILE_MAX_SIZE']));
300 if (empty($max_size)) $max_size = 0;
302 if (!empty($max_size) && !preg_match(
'|^[0-9]+[KM]$|', $max_size)) {
303 trigger_localised_error(
'CORE0002', E_USER_WARNING, $max_size);
305 $this->pref_vars[
'SQ_FILE_MAX_SIZE'][
'default'] = $max_size;
311 if (is_null($pref) || $pref ==
'SQ_FILE_PREUPLOADED_MAX_SIZE') {
312 if (isset($_POST[
'prefs'][
'SQ_FILE_PREUPLOADED_MAX_SIZE'])) {
313 $max_size = strtoupper(trim($_POST[
'prefs'][
'SQ_FILE_PREUPLOADED_MAX_SIZE']));
314 if (empty($max_size)) $max_size = 0;
316 if (!empty($max_size) && !preg_match(
'|^[0-9]+[KM]$|', $max_size)) {
317 trigger_localised_error(
'CORE0002', E_USER_WARNING, $max_size);
319 $this->pref_vars[
'SQ_FILE_PREUPLOADED_MAX_SIZE'][
'default'] = $max_size;
325 if (is_null($pref) || $pref ==
'SQ_FILE_ALLOW_NO_EXTENSION') {
326 if (isset($_POST[
'prefs'][
'SQ_FILE_ALLOW_NO_EXTENSION'])) {
327 $allow = strtoupper(trim($_POST[
'prefs'][
'SQ_FILE_ALLOW_NO_EXTENSION']));
328 $this->pref_vars[
'SQ_FILE_ALLOW_NO_EXTENSION'][
'default'] = $allow;
333 if (is_null($pref) || $pref ==
'SQ_FILE_ALLOWED_TYPES') {
334 if (isset($_POST[
'prefs'][
'SQ_FILE_ALLOWED_TYPES'])) {
336 $this->pref_vars[
'SQ_FILE_ALLOWED_TYPES'][
'default'] = $result;
341 if (is_null($pref) || $pref ==
'SQ_FILE_ALLOWED_PREUPLOADED_TYPES') {
342 if (isset($_POST[
'prefs'][
'SQ_FILE_ALLOWED_PREUPLOADED_TYPES'])) {
343 $result = $this->
_tidyFileTypeString($_POST[
'prefs'][
'SQ_FILE_ALLOWED_PREUPLOADED_TYPES']);
344 $this->pref_vars[
'SQ_FILE_ALLOWED_PREUPLOADED_TYPES'][
'default'] = $result;
349 if (is_null($pref) || $pref ==
'SQ_FILE_ASSET_SUMMARY') {
350 if (isset($_POST[
'prefs'][
'SQ_FILE_ASSET_SUMMARY'])) {
351 $this->pref_vars[
'SQ_FILE_ASSET_SUMMARY'][
'default'] = $_POST[
'prefs'][
'SQ_FILE_ASSET_SUMMARY'];
372 $str = str_replace(
' ',
'', strtolower(trim($str)));
373 if (empty($str))
return '';
375 if (substr($str, -1) ==
',') {
376 $str = substr($str, 0, -1);
379 if (strpos($str,
',') !== FALSE) {
380 $tmp = explode(
',', $str);
381 $new_tokens = Array();
382 foreach ($tmp as $token) {
383 if (!empty($token)) $new_tokens[] = $token;
389 if (empty($new_tokens)) {
392 $new_tokens = array_unique($new_tokens);
394 return implode(
',', $new_tokens);
410 $merged_prefs = Array();
413 'SQ_FILE_PREUPLOADED_MAX_SIZE',
414 'SQ_FILE_ALLOW_NO_EXTENSION',
415 'SQ_FILE_ALLOWED_TYPES',
416 'SQ_FILE_ALLOWED_PREUPLOADED_TYPES',
419 foreach ($pref_vars as $var_name) {
420 if (isset($prefs1[$var_name]) && !isset($prefs2[$var_name])) {
422 $merged_prefs[$var_name] = $prefs1[$var_name];
423 }
else if (isset($prefs2[$var_name]) && !isset($prefs1[$var_name])) {
425 $merged_prefs[$var_name] = $prefs2[$var_name];
426 }
else if (isset($prefs1[$var_name]) && isset($prefs2[$var_name])) {
429 case 'SQ_FILE_MAX_SIZE' :
430 case 'SQ_FILE_PREUPLOADED_MAX_SIZE' :
432 $pref_1_size = strtolower($prefs1[$var_name][
'default']);
433 if (substr($pref_1_size, -1) ==
'k') {
434 $pref_1_size = $pref_1_size * 1024;
435 }
else if (substr($pref_1_size, -1) ==
'm') {
436 $pref_1_size = $pref_1_size * 1024 * 1024;
439 $pref_2_size = strtolower($prefs2[$var_name][
'default']);
440 if (substr($pref_1_size, -1) ==
'k') {
441 $pref_1_size = $pref_1_size * 1024;
442 }
else if (substr($pref_1_size, -1) ==
'm') {
443 $pref_1_size = $pref_1_size * 1024 * 1024;
447 if ($pref_1_size > $pref_2_size) {
448 $merged_prefs[$var_name] = $prefs1[$var_name];
450 $merged_prefs[$var_name] = $prefs2[$var_name];
453 case 'SQ_FILE_ALLOW_NO_EXTENSION' :
454 $pref_1_val = $prefs1[$var_name][
'default'];
455 $pref_2_val = $prefs2[$var_name][
'default'];
456 $merged_prefs[$var_name][
'default'] = ($pref_1_val || $pref_2_val);
458 case 'SQ_FILE_ALLOWED_TYPES' :
459 case 'SQ_FILE_ALLOWED_PREUPLOADED_TYPES' :
460 if (is_array($prefs1[$var_name]) && isset($prefs1[$var_name][
'default'])) {
461 $pref_1_exts_str = $prefs1[$var_name][
'default'];
463 $pref_1_exts_str = $prefs1[$var_name];
465 if (is_array($prefs2[$var_name]) && isset($prefs2[$var_name][
'default'])) {
466 $pref_2_exts_str = $prefs2[$var_name][
'default'];
468 $pref_2_exts_str = $prefs2[$var_name];
470 $pref_merge_str = $pref_1_exts_str.
','.$pref_2_exts_str;
471 $merged_prefs[$var_name][
'default'] = implode(
',', array_unique(explode(
',', $pref_merge_str)));
475 $merged_prefs[$var_name][
'name'] = $prefs1[$var_name][
'name'];
476 $merged_prefs[$var_name][
'description'] = $prefs1[$var_name][
'description'];
478 if (isset($prefs2[$var_name][
'protected'])) {
479 $merged_prefs[$var_name][
'protected'] = ($prefs1[$var_name][
'protected'] || $prefs2[$var_name][
'protected']);
481 $merged_prefs[$var_name][
'protected'] = $prefs1[$var_name][
'protected'];
487 return $merged_prefs;