Document $php_self_pattern and $php_self_replacement
[squirrelmail.git] / include / options / display.php
CommitLineData
c36ed9cf 1<?php
e7db48af 2
35586184 3/**
4 * options_display.php
5 *
35586184 6 * Displays all optinos about display preferences
7 *
c4faef33 8 * @copyright 1999-2020 The SquirrelMail Project Team
4b4abf93 9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
763b63fe 10 * @version $Id$
2b646597 11 * @package squirrelmail
35586184 12 */
cbe5423b 13
2b646597 14/** Define the group constants for the display options page. */
cbe5423b 15define('SMOPT_GRP_GENERAL', 0);
16define('SMOPT_GRP_MAILBOX', 1);
17define('SMOPT_GRP_MESSAGE', 2);
4fe67ca6 18define('SMOPT_GRP_ABOOK', 3);
cbe5423b 19
a144f6b8 20global $use_iframe;
21if (! isset($use_iframe)) $use_iframe=false;
22
48af4b64 23/**
24 * This function builds an array with all the information about
25 * the options available to the user, and returns it. The options
26 * are grouped by the groups in which they are displayed.
27 * For each option, the following information is stored:
28 * - name: the internal (variable) name
29 * - caption: the description of the option in the UI
30 * - type: one of SMOPT_TYPE_*
31 * - refresh: one of SMOPT_REFRESH_*
32 * - size: one of SMOPT_SIZE_*
33 * - save: the name of a function to call when saving this option
34 * @return array all option information
35 */
cbe5423b 36function load_optpage_data_display() {
299d1d03 37 global $theme, $fontsets, $language, $languages,$aTemplateSet,
ce68b76b 38 $default_use_mdn, $squirrelmail_language, $allow_thread_sort,
1e721874 39 $show_alternative_names, $use_iframe, $use_icons,
40 $sTemplateID, $oTemplate,
41 $user_themes, $chosen_theme;
a3ec3c91 42
ce393174 43 /* Build a simple array into which we will build options. */
bbcafebd 44 $optgrps = array();
45 $optvals = array();
a3ec3c91 46
bbcafebd 47 /******************************************************/
48 /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */
49 /******************************************************/
bbcafebd 50
51 /*** Load the General Options into the array ***/
52 $optgrps[SMOPT_GRP_GENERAL] = _("General Display Options");
53 $optvals[SMOPT_GRP_GENERAL] = array();
54
299d1d03 55 /* load the template set option */
56 $templateset_values = array();
57
58 foreach ($aTemplateSet as $sKey => $aTemplateSetAttributes) {
28294310 59 $templateset_values[$aTemplateSetAttributes['NAME']] = $aTemplateSetAttributes['ID'];
299d1d03 60 }
61 ksort($templateset_values);
62 $templateset_values = array_flip($templateset_values);
9edbc08b 63 // display template options only when there is more than one template
64 if (count($templateset_values)>1) {
65 $optvals[SMOPT_GRP_GENERAL][] = array(
28294310 66 'name' => 'sTemplateID',
67 'caption' => _("Skin"),
9edbc08b 68 'type' => SMOPT_TYPE_STRLIST,
69 'refresh' => SMOPT_REFRESH_ALL,
70 'posvals' => $templateset_values,
71 'save' => 'save_option_template'
72 );
73 }
299d1d03 74
bbcafebd 75 /* Load the theme option. */
ce393174 76 $theme_values = array();
deb25c8f 77
78 // Always provide the template default first.
79 $theme_values['none'] = 'Template Default Theme';
80
dfbd2895 81 // List alternate themes provided by templates first
83fc5c5e 82 $template_themes = $oTemplate->get_alternative_stylesheets(true);
f9376f0b 83 asort($template_themes);
84 foreach ($template_themes as $sheet=>$name) {
3047e291 85 $theme_values[$sheet] = 'Template Theme - '.sm_encode_html_special_chars($name);
deb25c8f 86 }
f9376f0b 87 // Next, list user-provided styles
82351c82 88 asort($user_themes);
89 foreach ($user_themes as $style) {
90 if ($style['PATH'] == 'none')
91 continue;
3047e291 92 $theme_values[$style['PATH']] = 'User Theme - '.sm_encode_html_special_chars($style['NAME']);
ce393174 93 }
deb25c8f 94
82351c82 95 if (count($user_themes) + count($template_themes) > 1) {
96 $optvals[SMOPT_GRP_GENERAL][] = array(
97 'name' => 'chosen_theme',
98 'caption' => _("Theme"),
99 'type' => SMOPT_TYPE_STRLIST,
100 'refresh' => SMOPT_REFRESH_ALL,
101 'posvals' => $theme_values,
102 'save' => 'css_theme_save'
103 );
104 }
5d110fa6 105
dfbd2895 106 /* Icon theme selection */
107 if ($use_icons) {
108 global $icon_themes, $icon_theme;
5d110fa6 109
dfbd2895 110 $temp = array();
111 $value = 0;
112 for ($count = 0; $count < sizeof($icon_themes); $count++) {
113 $temp[$icon_themes[$count]['PATH']] = $icon_themes[$count]['NAME'];
114 }
115 if (sizeof($icon_themes) > 0) {
116 $optvals[SMOPT_GRP_GENERAL][] = array(
117 'name' => 'icon_theme',
118 'caption' => _("Icon Theme"),
119 'type' => SMOPT_TYPE_STRLIST,
120 'refresh' => SMOPT_REFRESH_NONE,
121 'posvals' => $temp,
122 'save' => 'icon_theme_save'
123 );
124 }
e2cdae1f 125 }
81132de8 126
127 $fontset_values = array();
bed0ac1d 128 $fontset_list = array();
129
130 if (!empty($fontsets) && is_array($fontsets)) {
131
132 foreach (array_keys($fontsets) as $fontset_key) {
133 $fontset_list[$fontset_key]=$fontset_key;
134 }
135 ksort($fontset_list);
81132de8 136 }
81132de8 137
138 if (count($fontset_list) > 1) {
139 $fontset_list = array_merge(array('' => _("Default font style")), $fontset_list);
140 $optvals[SMOPT_GRP_GENERAL][] = array(
141 'name' => 'chosen_fontset',
142 'caption' => _("Font style"),
143 'type' => SMOPT_TYPE_STRLIST,
144 'refresh' => SMOPT_REFRESH_ALL,
145 'posvals' => $fontset_list
146 );
147 }
148
149 $optvals[SMOPT_GRP_GENERAL][] = array(
150 'name' => 'chosen_fontsize',
151 'caption' => _("Font size"),
152 'type' => SMOPT_TYPE_STRLIST,
153 'refresh' => SMOPT_REFRESH_ALL,
154 'posvals' => array('' => _("Default font size"),
155 '8' => '8 px',
156 '10' => '10 px',
157 '12' => '12 px',
158 '14' => '14 px')
159 );
39d3ec89 160
e557fdb0 161 $language_values = array();
5ba5dc8e 162 foreach ($languages as $lang_key => $lang_attributes) {
163 if (isset($lang_attributes['NAME'])) {
164 $language_values[$lang_key] = $lang_attributes['NAME'];
165 if ( isset($show_alternative_names) &&
166 $show_alternative_names &&
167 isset($lang_attributes['ALTNAME']) ) {
168 $language_values[$lang_key] .= " / " . $lang_attributes['ALTNAME'];
0bb37159 169 }
170 }
ce393174 171 }
5ba5dc8e 172
e557fdb0 173 asort($language_values);
8405d0a4 174 $language_values =
175 array_merge(array('' => _("Default")), $language_values);
ec2c91a1 176 $language = $squirrelmail_language;
5ba5dc8e 177
299d1d03 178 // add language selection only when more than 2 languages are available
48d5ec1f 179 // (default, English and some other)
180 if (count($language_values)>2) {
181 $optvals[SMOPT_GRP_GENERAL][] = array(
182 'name' => 'language',
183 'caption' => _("Language"),
184 'type' => SMOPT_TYPE_STRLIST,
185 'refresh' => SMOPT_REFRESH_ALL,
186 'posvals' => $language_values,
187 'htmlencoded' => true
188 );
189 }
ce393174 190
a3ec3c91 191 /* Set values for the "use javascript" option. */
bbcafebd 192 $optvals[SMOPT_GRP_GENERAL][] = array(
a3ec3c91 193 'name' => 'javascript_setting',
ce393174 194 'caption' => _("Use Javascript"),
a3ec3c91 195 'type' => SMOPT_TYPE_STRLIST,
196 'refresh' => SMOPT_REFRESH_ALL,
197 'posvals' => array(SMPREF_JS_AUTODETECT => _("Autodetect"),
198 SMPREF_JS_ON => _("Always"),
ae958cd3 199 SMPREF_JS_OFF => _("Never")),
200 'save' => 'save_option_javascript_autodetect',
c4e3cf06 201 'extra_attributes' => array('onclick' => 'document.option_form.new_js_autodetect_results.value = \'' . SMPREF_JS_ON . '\';'),
a3ec3c91 202 );
203
bbcafebd 204 $optvals[SMOPT_GRP_GENERAL][] = array(
a3ec3c91 205 'name' => 'js_autodetect_results',
206 'caption' => '',
207 'type' => SMOPT_TYPE_HIDDEN,
ae958cd3 208 'refresh' => SMOPT_REFRESH_NONE
5826affb 209 //'post_script' => $js_autodetect_script,
a3ec3c91 210 );
f2df3fa1 211
5bcd1b00 212 $optvals[SMOPT_GRP_GENERAL][] = array(
213 'name' => 'hour_format',
214 'caption' => _("Hour Format"),
215 'type' => SMOPT_TYPE_STRLIST,
216 'refresh' => SMOPT_REFRESH_FOLDERLIST,
217 'posvals' => array(SMPREF_TIME_12HR => _("12-hour clock"),
218 SMPREF_TIME_24HR => _("24-hour clock"))
219 );
a3ec3c91 220
bbcafebd 221 /*** Load the General Options into the array ***/
222 $optgrps[SMOPT_GRP_MAILBOX] = _("Mailbox Display Options");
223 $optvals[SMOPT_GRP_MAILBOX] = array();
224
225 $optvals[SMOPT_GRP_MAILBOX][] = array(
a3ec3c91 226 'name' => 'show_num',
f2df3fa1 227 'caption' => _("Number of Messages per Page"),
a3ec3c91 228 'type' => SMOPT_TYPE_INTEGER,
bbcafebd 229 'refresh' => SMOPT_REFRESH_NONE,
230 'size' => SMOPT_SIZE_TINY
a3ec3c91 231 );
232
bbcafebd 233 $optvals[SMOPT_GRP_MAILBOX][] = array(
a440e68f 234 'name' => 'alt_index_colors',
235 'caption' => _("Enable Alternating Row Colors"),
236 'type' => SMOPT_TYPE_BOOLEAN,
237 'refresh' => SMOPT_REFRESH_NONE
238 );
239
18adc53f 240 $optvals[SMOPT_GRP_MAILBOX][] = array(
241 'name' => 'fancy_index_highlite',
242 'caption' => _("Enable Fancy Row Mouseover Highlighting"),
243 'type' => SMOPT_TYPE_BOOLEAN,
244 'refresh' => SMOPT_REFRESH_NONE
245 );
246
fd181f53 247 $optvals[SMOPT_GRP_MAILBOX][] = array(
248 'name' => 'show_flag_buttons',
249 'caption' => _("Show Flag / Unflag Buttons"),
250 'type' => SMOPT_TYPE_BOOLEAN,
251 'refresh' => SMOPT_REFRESH_NONE
252 );
253
24bb7e49 254 $optvals[SMOPT_GRP_MAILBOX][] = array(
255 'name' => 'show_copy_buttons',
256 'caption' => _("Enable Message Copy Buttons"),
257 'type' => SMOPT_TYPE_BOOLEAN,
258 'refresh' => SMOPT_REFRESH_NONE
259 );
260
bbcafebd 261 $optvals[SMOPT_GRP_MAILBOX][] = array(
a440e68f 262 'name' => 'page_selector',
263 'caption' => _("Enable Page Selector"),
264 'type' => SMOPT_TYPE_BOOLEAN,
265 'refresh' => SMOPT_REFRESH_NONE
266 );
267
0bb37159 268 $optvals[SMOPT_GRP_MAILBOX][] = array(
269 'name' => 'compact_paginator',
270 'caption' => _("Use Compact Page Selector"),
271 'type' => SMOPT_TYPE_BOOLEAN,
272 'refresh' => SMOPT_REFRESH_NONE
273 );
274
bbcafebd 275 $optvals[SMOPT_GRP_MAILBOX][] = array(
a440e68f 276 'name' => 'page_selector_max',
277 'caption' => _("Maximum Number of Pages to Show"),
278 'type' => SMOPT_TYPE_INTEGER,
bbcafebd 279 'refresh' => SMOPT_REFRESH_NONE,
280 'size' => SMOPT_SIZE_TINY
a440e68f 281 );
282
969c1e9f 283 $optvals[SMOPT_GRP_MAILBOX][] = array(
284 'name' => 'show_personal_names',
285 'caption' => _("Show Names Instead of Email Addresses"),
286 'type' => SMOPT_TYPE_BOOLEAN,
287 'refresh' => SMOPT_REFRESH_NONE,
288 );
289
3e3b60e3 290 $optvals[SMOPT_GRP_MAILBOX][] = array(
291 'name' => 'show_full_date',
292 'caption' => _("Always Show Full Date"),
293 'type' => SMOPT_TYPE_BOOLEAN,
294 'refresh' => SMOPT_REFRESH_NONE
295 );
296
26017e66 297 $optvals[SMOPT_GRP_MAILBOX][] = array(
298 'name' => 'custom_date_format',
299 'caption' => _("Custom Date Format"),
3692c2ed 300//FIXME: need better wording here. users should be made aware that this is for advanced use. It might be nice to provide a list of the more common date format characters. It may be helpful to know that it overrides settings such as the one above show_full_date, and only if kept empty will the other date formats apply. For non-English users, it also may be helpful to know that the format is still passed through our own date_intl() function which translates things like the day of the week, month names and abbreviations, etc.
26017e66 301 'trailing_text' => ' ' . _("(Uses format of PHP date() function)"),
302 'type' => SMOPT_TYPE_STRING,
303 'refresh' => SMOPT_REFRESH_NONE,
304 'size' => SMOPT_SIZE_TINY,
305 );
306
459e3347 307 $optvals[SMOPT_GRP_MAILBOX][] = array(
308 'name' => 'truncate_sender',
309 'caption' => _("Length of From/To Field (0 for full)"),
310 'type' => SMOPT_TYPE_INTEGER,
311 'refresh' => SMOPT_REFRESH_NONE,
312 'size' => SMOPT_SIZE_TINY
313 );
314
3fc1a95f 315 $optvals[SMOPT_GRP_MAILBOX][] = array(
316 'name' => 'truncate_subject',
317 'caption' => _("Length of Subject Field (0 for full)"),
318 'type' => SMOPT_TYPE_INTEGER,
319 'refresh' => SMOPT_REFRESH_NONE,
320 'size' => SMOPT_SIZE_TINY
321 );
91c27aee 322/*
28294310 323FIXME!
91c27aee 324 disabled because the template doesn't support it (yet?)
1ae2832e 325 $optvals[SMOPT_GRP_MAILBOX][] = array(
326 'name' => 'show_recipient_instead',
327 'caption' => _("Show recipient name if the message is from your default identity"),
328 'type' => SMOPT_TYPE_BOOLEAN,
329 'refresh' => SMOPT_REFRESH_NONE,
330 'size' => SMOPT_SIZE_TINY
331 );
91c27aee 332*/
f2df3fa1 333
5ed9d4fd 334 if ($allow_thread_sort == TRUE) {
335 $optvals[SMOPT_GRP_MAILBOX][] = array(
336 'name' => 'sort_by_ref',
337 'caption' => _("Enable Thread Sort by References Header"),
338 'type' => SMOPT_TYPE_BOOLEAN,
339 'refresh' => SMOPT_REFRESH_ALL
340 );
341 }
342
1ae2832e 343
459e3347 344
bbcafebd 345 /*** Load the General Options into the array ***/
5ed9d4fd 346 $optgrps[SMOPT_GRP_MESSAGE] = _("Message Display Options");
bbcafebd 347 $optvals[SMOPT_GRP_MESSAGE] = array();
348
349 $optvals[SMOPT_GRP_MESSAGE][] = array(
a3ec3c91 350 'name' => 'wrap_at',
351 'caption' => _("Wrap Incoming Text At"),
352 'type' => SMOPT_TYPE_INTEGER,
bbcafebd 353 'refresh' => SMOPT_REFRESH_NONE,
354 'size' => SMOPT_SIZE_TINY
a3ec3c91 355 );
356
bbcafebd 357 $optvals[SMOPT_GRP_MESSAGE][] = array(
fd87494d 358 'name' => 'show_html_default',
359 'caption' => _("Show HTML Version by Default"),
360 'type' => SMOPT_TYPE_BOOLEAN,
361 'refresh' => SMOPT_REFRESH_NONE
362 );
363
a144f6b8 364 if ($use_iframe) {
365 // Type is set to string in order to be able to use 100%.
366 $optvals[SMOPT_GRP_MESSAGE][] = array(
367 'name' => 'iframe_height',
368 'caption' => _("Height of inline frame"),
369 'type' => SMOPT_TYPE_STRING,
370 'size' => SMOPT_SIZE_TINY,
371 'refresh' => SMOPT_REFRESH_NONE
372 );
373 }
bbcafebd 374 $optvals[SMOPT_GRP_MESSAGE][] = array(
6206f6c4 375 'name' => 'enable_forward_as_attachment',
376 'caption' => _("Enable Forward as Attachment"),
fd87494d 377 'type' => SMOPT_TYPE_BOOLEAN,
378 'refresh' => SMOPT_REFRESH_NONE
379 );
380
bbcafebd 381 $optvals[SMOPT_GRP_MESSAGE][] = array(
9ab0d96f 382 'name' => 'show_xmailer_default',
a440e68f 383 'caption' => _("Enable Mailer Display"),
9ab0d96f 384 'type' => SMOPT_TYPE_BOOLEAN,
385 'refresh' => SMOPT_REFRESH_NONE
386 );
387
7baf86a9 388 $optvals[SMOPT_GRP_MESSAGE][] = array(
389 'name' => 'attachment_common_show_images',
10f0ce72 390 'caption' => _("Display Attached Images with Message"),
7baf86a9 391 'type' => SMOPT_TYPE_BOOLEAN,
392 'refresh' => SMOPT_REFRESH_NONE
393 );
394
57257333 395 if ($default_use_mdn) {
396 $optvals[SMOPT_GRP_MESSAGE][] = array(
397 'name' => 'mdn_user_support',
6206f6c4 398 'caption' => _("Enable Mail Delivery Notification"),
57257333 399 'type' => SMOPT_TYPE_BOOLEAN,
400 'refresh' => SMOPT_REFRESH_NONE
401 );
402 }
07687736 403
4267d5de 404 $optvals[SMOPT_GRP_MESSAGE][] = array(
405 'name' => 'delete_prev_next_display',
407e7032 406 'caption' => _("Show 'Delete &amp; Prev/Next' Links"),
4267d5de 407 'type' => SMOPT_TYPE_BOOLEAN,
408 'refresh' => SMOPT_REFRESH_ALL
409 );
5d110fa6 410
4fe67ca6 411
412
413 /*** Load the Address Book Options into the array ***/
414 $optgrps[SMOPT_GRP_ABOOK] = _("Address Book Display Options");
415 $optvals[SMOPT_GRP_ABOOK] = array();
416
417 $optvals[SMOPT_GRP_ABOOK][] = array(
418 'name' => 'abook_show_num',
419 'caption' => _("Number of Addresses per Page"),
420 'type' => SMOPT_TYPE_INTEGER,
421 'refresh' => SMOPT_REFRESH_NONE,
422 'size' => SMOPT_SIZE_TINY
423 );
424
425 $optvals[SMOPT_GRP_ABOOK][] = array(
426 'name' => 'abook_page_selector',
427 'caption' => _("Enable Page Selector"),
428 'type' => SMOPT_TYPE_BOOLEAN,
429 'refresh' => SMOPT_REFRESH_NONE
430 );
431
432 $optvals[SMOPT_GRP_ABOOK][] = array(
433 'name' => 'abook_compact_paginator',
434 'caption' => _("Use Compact Page Selector"),
435 'type' => SMOPT_TYPE_BOOLEAN,
436 'refresh' => SMOPT_REFRESH_NONE
437 );
438
439 $optvals[SMOPT_GRP_ABOOK][] = array(
440 'name' => 'abook_page_selector_max',
441 'caption' => _("Maximum Number of Pages to Show"),
442 'type' => SMOPT_TYPE_INTEGER,
443 'refresh' => SMOPT_REFRESH_NONE,
444 'size' => SMOPT_SIZE_TINY
445 );
446
447
448
cbe5423b 449 /* Assemble all this together and return it as our result. */
450 $result = array(
451 'grps' => $optgrps,
ae958cd3 452 'vals' => $optvals
cbe5423b 453 );
454 return ($result);
455}
a3ec3c91 456
cbe5423b 457/******************************************************************/
458/** Define any specialized save functions for this option page. ***/
459/******************************************************************/
f1e6f580 460
299d1d03 461/**
462 * This function saves a new template setting.
463 * It updates the template array.
464 */
465function save_option_template($option) {
466 global $aTemplateSet;
467
e4dd61df 468 /* Do checking to make sure new template is in the available templates array. */
299d1d03 469 $templateset_in_array = false;
470 for ($i = 0; $i < count($aTemplateSet); ++$i) {
28294310 471 if ($aTemplateSet[$i]['ID'] == $option->new_value) {
299d1d03 472 $templateset_in_array = true;
473 break;
474 }
475 }
476
477 if (!$templateset_in_array) {
478 $option->new_value = '';
e4dd61df 479 } else {
480
481 // clear template cache when changing template sets
482 // (in order to do so, we have to change the global
483 // template set ID now... should not be a problem --
484 // in fact, if we don't do it now, very anomalous
485 // problems occur)
486 //
487 global $sTemplateID;
488 $sTemplateID = $option->new_value;
d81572f7 489 Template::cache_template_file_hierarchy($sTemplateID, TRUE);
e4dd61df 490
299d1d03 491 }
e4dd61df 492
83fc5c5e 493 /**
494 * TODO: If the template changes and we are using a template provided theme
495 * ($user_theme), do we want to reset $user_theme?
496 */
299d1d03 497 /* Save the option like normal. */
498 save_option($option);
499}
500
48af4b64 501/**
502 * This function saves the javascript detection option.
503 */
cbe5423b 504function save_option_javascript_autodetect($option) {
ae958cd3 505 save_option($option);
506 checkForJavascript(TRUE);
cbe5423b 507}
508
5d110fa6 509/**
6395c46d 510 * This function saves the user's icon theme setting
511 */
512function icon_theme_save($option) {
f9376f0b 513 global $icon_themes;
6395c46d 514
515
5d110fa6 516 // Don't assume the new value is there, double check
517 // and only save if found
991c88e7 518 $found = false;
519 while (!$found && (list($index, $data) = each($icon_themes))) {
520 if ($data['PATH'] == $option->new_value)
521 $found = true;
522 }
4e655787 523
524 if (!$found)
525 $option->new_value = 'none';
526
527 save_option($option);
6395c46d 528}
deb25c8f 529
530function css_theme_save ($option) {
f9376f0b 531 global $user_themes, $oTemplate;
deb25c8f 532
533 // Don't assume the new value is there, double check
534 // and only save if found
deb25c8f 535 $found = false;
82351c82 536 reset($user_themes);
537 while (!$found && (list($index, $data) = each($user_themes))) {
83fc5c5e 538 if ($data['PATH'] == $option->new_value)
deb25c8f 539 $found = true;
540 }
f9376f0b 541
83fc5c5e 542 if (!$found) {
543 $template_themes = $oTemplate->get_alternative_stylesheets(true);
544 while (!$found && (list($path, $name) = each($template_themes))) {
545 if ($path == $option->new_value)
546 $found = true;
547 }
f9376f0b 548 }
549
550 if (!$found)
551 $option->new_value = 'none';
552
553 save_option($option);
deb25c8f 554}
555
556