load_prefs.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. <?php
  2. /**
  3. * load_prefs.php
  4. *
  5. * Loads preferences from the $username.pref file used by almost
  6. * every other script in the source directory and alswhere.
  7. *
  8. * @copyright &copy; 1999-2007 The SquirrelMail Project Team
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10. * @version $Id$
  11. * @package squirrelmail
  12. */
  13. /**
  14. * do not allow to call this file directly
  15. * FIXME: PHP CGI (at least on IIS 5.1) does not set 'SCRIPT_FILENAME' and
  16. * code does not handle magic_quotes_gpc=on.
  17. */
  18. if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE__) {
  19. header("Location: ../src/login.php");
  20. die();
  21. }
  22. if( ! sqgetGlobalVar('username', $username, SQ_SESSION) ) {
  23. $username = '';
  24. }
  25. // TODO Get rid of "none" strings when NULL or false should be used, i hate them i hate them i hate them!!!.
  26. $custom_css = getPref($data_dir, $username, 'custom_css', 'none' );
  27. // template set setup
  28. //
  29. $sDefaultTemplateID = Template::get_default_template_set();
  30. $sTemplateID = getPref($data_dir, $username, 'sTemplateID', $sDefaultTemplateID);
  31. // load user theme
  32. //
  33. $chosen_theme = getPref($data_dir, $username, 'chosen_theme');
  34. $chosen_theme_path = empty($chosen_theme) ?
  35. $chosen_theme_path = $user_themes[$user_theme_default]['PATH'] :
  36. $chosen_theme;
  37. // user's icon theme, if using icons
  38. $icon_theme = getPref($data_dir, $username, 'icon_theme');
  39. $default_icon_theme = $icon_themes[$icon_theme_def]['PATH'];
  40. $fallback_icon_theme = $icon_themes[$icon_theme_fallback]['PATH'];
  41. $found_theme = false;
  42. // Make sure the chosen icon theme is a legitimate one.
  43. // need to adjust $icon_theme path with SM_PATH
  44. $icon_theme = preg_replace("/(\.\.\/){1,}/", SM_PATH, $icon_theme);
  45. $k = 0;
  46. while (!$found_theme && $k < count($icon_themes)) {
  47. if ($icon_themes[$k]['PATH'] == $icon_theme)
  48. $found_theme = true;
  49. $k++;
  50. }
  51. if (!$found_theme) {
  52. $icon_theme = $default_icon_theme;
  53. }
  54. // show (or not) flag and unflag buttons on mailbox list screen
  55. $show_flag_buttons = getPref($data_dir, $username, 'show_flag_buttons', SMPREF_ON );
  56. /* Load the user's special folder preferences */
  57. $move_to_sent =
  58. getPref($data_dir, $username, 'move_to_sent', $default_move_to_sent);
  59. $move_to_trash =
  60. getPref($data_dir, $username, 'move_to_trash', $default_move_to_trash);
  61. $save_as_draft =
  62. getPref($data_dir, $username, 'save_as_draft', $default_save_as_draft);
  63. if ($default_unseen_type == '') {
  64. $default_unseen_type = 1;
  65. }
  66. if ($default_unseen_notify == '') {
  67. $default_unseen_notify = 2;
  68. }
  69. $unseen_type =
  70. getPref($data_dir, $username, 'unseen_type', $default_unseen_type);
  71. $unseen_notify =
  72. getPref($data_dir, $username, 'unseen_notify', $default_unseen_notify);
  73. $unseen_cum =
  74. getPref($data_dir, $username, 'unseen_cum', false);
  75. $folder_prefix =
  76. getPref($data_dir, $username, 'folder_prefix', $default_folder_prefix);
  77. /* Load special folder - trash */
  78. $load_trash_folder = getPref($data_dir, $username, 'trash_folder');
  79. if (($load_trash_folder == '') && ($move_to_trash)) {
  80. $trash_folder = $folder_prefix . $trash_folder;
  81. } else {
  82. $trash_folder = $load_trash_folder;
  83. }
  84. /* Load special folder - sent */
  85. $load_sent_folder = getPref($data_dir, $username, 'sent_folder');
  86. if (($load_sent_folder == '') && ($move_to_sent)) {
  87. $sent_folder = $folder_prefix . $sent_folder;
  88. } else {
  89. $sent_folder = $load_sent_folder;
  90. }
  91. /* Load special folder - draft */
  92. $load_draft_folder = getPref($data_dir, $username, 'draft_folder');
  93. if (($load_draft_folder == '') && ($save_as_draft)) {
  94. $draft_folder = $folder_prefix . $draft_folder;
  95. } else {
  96. $draft_folder = $load_draft_folder;
  97. }
  98. $show_num = getPref($data_dir, $username, 'show_num', 15 );
  99. $wrap_at = getPref( $data_dir, $username, 'wrap_at', 86 );
  100. if ($wrap_at < 15) { $wrap_at = 15; }
  101. $left_size = getPref($data_dir, $username, 'left_size');
  102. if ($left_size == '') {
  103. if (isset($default_left_size)) {
  104. $left_size = $default_left_size;
  105. } else {
  106. $left_size = 200;
  107. }
  108. }
  109. $editor_size = getPref($data_dir, $username, 'editor_size', 76 );
  110. $editor_height = getPref($data_dir, $username, 'editor_height', 20 );
  111. $use_signature = getPref($data_dir, $username, 'use_signature', SMPREF_OFF );
  112. $prefix_sig = getPref($data_dir, $username, 'prefix_sig');
  113. /* Load timezone preferences */
  114. $timezone = getPref($data_dir, $username, 'timezone', SMPREF_NONE );
  115. /* Load preferences for reply citation style. */
  116. $reply_citation_style =
  117. getPref($data_dir, $username, 'reply_citation_style', 'date_time_author' );
  118. $reply_citation_start = getPref($data_dir, $username, 'reply_citation_start');
  119. $reply_citation_end = getPref($data_dir, $username, 'reply_citation_end');
  120. $body_quote = getPref($data_dir, $username, 'body_quote', '>');
  121. if ($body_quote == 'NONE') $body_quote = '';
  122. // who is using those darn block comments? poo!
  123. // Load preference for cursor behavior for replies
  124. //
  125. $reply_focus = getPref($data_dir, $username, 'reply_focus', '');
  126. /* left refresh rate, strtolower makes 1.0.6 prefs compatible */
  127. $left_refresh = getPref($data_dir, $username, 'left_refresh', 600 );
  128. $left_refresh = strtolower($left_refresh);
  129. /* Message Highlighting Rules */
  130. $message_highlight_list = array();
  131. /* use new way of storing highlighting rules */
  132. if( $ser = getPref($data_dir, $username, 'hililist') ) {
  133. $message_highlight_list = unserialize($ser);
  134. } else {
  135. /* use old way */
  136. for ($i = 0; $hlt = getPref($data_dir, $username, "highlight$i"); ++$i) {
  137. $highlight_array = explode(',', $hlt);
  138. $message_highlight_list[$i]['name'] = $highlight_array[0];
  139. $message_highlight_list[$i]['color'] = $highlight_array[1];
  140. $message_highlight_list[$i]['value'] = $highlight_array[2];
  141. $message_highlight_list[$i]['match_type'] = $highlight_array[3];
  142. removePref($data_dir, $username, "highlight$i");
  143. }
  144. /* store in new format for the next time */
  145. setPref($data_dir, $username, 'hililist', serialize($message_highlight_list));
  146. }
  147. /* use the internal date of the message for sorting instead of the supplied header date */
  148. /* OBSOLETE */
  149. $internal_date_sort = getPref($data_dir, $username, 'internal_date_sort', SMPREF_ON);
  150. /* Index order lets you change the order of the message index */
  151. $order = getPref($data_dir, $username, 'order1');
  152. if (isset($order1)) {
  153. removePref($data_dir, $username, 'order1');
  154. for ($i = 1; $order; ++$i) {
  155. $index_order[$i-1] = $order -1;
  156. $order = getPref($data_dir, $username, 'order'.($i+1));
  157. removePref($data_dir, $username, 'order'.($i+1));
  158. }
  159. if (isset($internal_date_sort) && $internal_date_sort) {
  160. if (in_array(SQM_COL_DATE,$index_order)) {
  161. $k = array_search(SQM_COL_DATE,$index_order,true);
  162. $index_order[$k] = SQM_COL_INT_DATE;
  163. }
  164. }
  165. setPref($data_dir, $username, 'index_order', serialize($index_order));
  166. }
  167. $index_order = getPref($data_dir, $username, 'index_order');
  168. if (is_string($index_order)) {
  169. $index_order = unserialize($index_order);
  170. }
  171. // new Index order handling
  172. //$default_mailbox_pref = unserialize(getPref($data_dir, $username, 'default_mailbox_pref'));
  173. if (!$index_order) {
  174. if (isset($internal_date_sort) && $internal_date_sort == false) {
  175. $index_order = array(SQM_COL_CHECK,SQM_COL_FROM,SQM_COL_DATE,SQM_COL_FLAGS,SQM_COL_ATTACHMENT,SQM_COL_PRIO,SQM_COL_SUBJ);
  176. } else {
  177. $index_order = array(SQM_COL_CHECK,SQM_COL_FROM,SQM_COL_INT_DATE,SQM_COL_FLAGS,SQM_COL_ATTACHMENT,SQM_COL_PRIO,SQM_COL_SUBJ);
  178. }
  179. setPref($data_dir, $username, 'index_order', serialize($index_order));
  180. }
  181. if (!isset($default_mailbox_pref)) {
  182. $show_num = (isset($show_num)) ? $show_num : 15;
  183. $default_mailbox_pref = array (
  184. MBX_PREF_SORT => 0,
  185. MBX_PREF_LIMIT => $show_num,
  186. MBX_PREF_AUTO_EXPUNGE => $auto_expunge,
  187. MBX_PREF_COLUMNS => $index_order);
  188. // setPref($data_dir, $username, 'default_mailbox_pref', serialize($default_mailbox_pref));
  189. // clean up the old prefs
  190. // if (isset($prefs_cache['internal_date_sort'])) {
  191. // unset($prefs_cache['internal_date_sort']);
  192. // removePref($data_dir,$username,'internal_date_sort');
  193. // }
  194. // if (isset($prefs_cache['show_num'])) {
  195. // unset($prefs_cache['show_num']);
  196. // removePref($data_dir,$username,'show_num');
  197. // }
  198. }
  199. $alt_index_colors =
  200. getPref($data_dir, $username, 'alt_index_colors', SMPREF_ON );
  201. $fancy_index_highlite =
  202. getPref($data_dir, $username, 'fancy_index_highlite', SMPREF_ON );
  203. /* Folder List Display Format */
  204. $location_of_bar =
  205. getPref($data_dir, $username, 'location_of_bar', SMPREF_LOC_LEFT);
  206. $location_of_buttons =
  207. getPref($data_dir, $username, 'location_of_buttons', SMPREF_LOC_BETWEEN);
  208. $collapse_folders =
  209. getPref($data_dir, $username, 'collapse_folders', SMPREF_ON);
  210. $show_html_default =
  211. getPref($data_dir, $username, 'show_html_default', SMPREF_ON);
  212. $addrsrch_fullname =
  213. getPref($data_dir, $username, 'addrsrch_fullname', SMPREF_ON);
  214. $enable_forward_as_attachment =
  215. getPref($data_dir, $username, 'enable_forward_as_attachment', SMPREF_ON);
  216. $show_xmailer_default =
  217. getPref($data_dir, $username, 'show_xmailer_default', SMPREF_OFF );
  218. $attachment_common_show_images = getPref($data_dir, $username, 'attachment_common_show_images', SMPREF_OFF );
  219. /* message disposition notification support setting */
  220. $mdn_user_support = getPref($data_dir, $username, 'mdn_user_support', SMPREF_ON);
  221. $include_self_reply_all =
  222. getPref($data_dir, $username, 'include_self_reply_all', SMPREF_ON);
  223. /* Page selector options */
  224. $page_selector = getPref($data_dir, $username, 'page_selector', SMPREF_ON);
  225. $compact_paginator = getPref($data_dir, $username, 'compact_paginator', SMPREF_OFF);
  226. $page_selector_max = getPref($data_dir, $username, 'page_selector_max', 10);
  227. /* SqClock now in the core */
  228. $date_format = getPref($data_dir, $username, 'date_format', 3);
  229. $hour_format = getPref($data_dir, $username, 'hour_format', SMPREF_TIME_12HR);
  230. /* compose in new window setting */
  231. $compose_new_win = getPref($data_dir, $username, 'compose_new_win', SMPREF_OFF);
  232. $compose_height = getPref($data_dir, $username, 'compose_height', 550);
  233. $compose_width = getPref($data_dir, $username, 'compose_width', 640);
  234. /* signature placement settings */
  235. $sig_first = getPref($data_dir, $username, 'sig_first', SMPREF_OFF);
  236. /* Strip signature when replying */
  237. $strip_sigs = getPref($data_dir, $username, 'strip_sigs', SMPREF_ON);
  238. /* use the internal date of the message for sorting instead of the supplied header date */
  239. $internal_date_sort = getPref($data_dir, $username, 'internal_date_sort', SMPREF_ON);
  240. /* if server sorting is enabled/disabled */
  241. $sort_by_ref = getPref($data_dir, $username, 'sort_by_ref', SMPREF_ON);
  242. /* Load the javascript settings. */
  243. $javascript_setting = getPref($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT);
  244. if ( checkForJavascript() )
  245. {
  246. $use_javascript_folder_list = getPref($data_dir, $username, 'use_javascript_folder_list');
  247. $use_javascript_addr_book = getPref($data_dir, $username, 'use_javascript_addr_book', $default_use_javascript_addr_book);
  248. } else {
  249. $use_javascript_folder_list = false;
  250. $use_javascript_addr_book = false;
  251. }
  252. $search_memory = getPref($data_dir, $username, 'search_memory', SMPREF_OFF);
  253. $show_only_subscribed_folders =
  254. getPref($data_dir, $username, 'show_only_subscribed_folders', SMPREF_ON);
  255. /* How are mailbox select lists displayed: 0. full names, 1. indented (default),
  256. * 3. delimited) */
  257. $mailbox_select_style = getPref($data_dir, $username, 'mailbox_select_style', SMPREF_MAILBOX_SELECT_INDENTED);
  258. /* Allow user to customize, and display the full date, instead of day, or time based
  259. on time distance from date of message */
  260. $show_full_date = getPref($data_dir, $username, 'show_full_date', SMPREF_OFF);
  261. /* Allow user to customize length of from field */
  262. $truncate_sender = getPref($data_dir, $username, 'truncate_sender', 50);
  263. /* Allow user to customize length of subject field */
  264. $truncate_subject = getPref($data_dir, $username, 'truncate_subject', 50);
  265. /* Allow user to show recipient name if the message is from default identity */
  266. $show_recipient_instead = getPref($data_dir, $username, 'show_recipient_instead', SMPREF_OFF);
  267. $delete_prev_next_display = getPref($data_dir, $username, 'delete_prev_next_display', SMPREF_ON);
  268. /**
  269. * Height of iframe that displays html formated emails
  270. * @since 1.5.1
  271. */
  272. $iframe_height = getPref($data_dir, $username, 'iframe_height', '300');
  273. if (! isset($default_fontset)) $default_fontset=SMPREF_NONE;
  274. $chosen_fontset = getPref($data_dir, $username, 'chosen_fontset', $default_fontset);
  275. if (! isset($default_fontsize)) $default_fontsize=SMPREF_NONE;
  276. $chosen_fontsize = getPref($data_dir, $username, 'chosen_fontsize', $default_fontsize);
  277. /**
  278. * Controls translation of special folders
  279. * @since 1.5.2
  280. */
  281. $translate_special_folders = getPref($data_dir, $username, 'translate_special_folders', SMPREF_OFF);
  282. /**
  283. * Controls display of message copy options
  284. * @since 1.5.2
  285. */
  286. $show_copy_buttons = getPref($data_dir, $username, 'show_copy_buttons', SMPREF_OFF);
  287. /** Put in a safety net for authentication here, in case a naughty admin didn't run conf.pl when they upgraded */
  288. // TODO Get rid of "none" strings when NULL should be used, i hate them i hate them i hate them!!!.
  289. if (! isset($smtp_auth_mech)) {
  290. $smtp_auth_mech = 'none';
  291. }
  292. if (! isset($imap_auth_mech)) {
  293. $imap_auth_mech = 'login';
  294. }
  295. if (! isset($use_imap_tls)) {
  296. $use_imap_tls = false;
  297. }
  298. if (! isset($use_smtp_tls)) {
  299. $use_smtp_tls = false;
  300. }
  301. // allow plugins to override user prefs
  302. //
  303. do_hook('loading_prefs', $null);
  304. // check user prefs template selection against templates actually available
  305. //
  306. $found_templateset = false;
  307. for ($i = 0; $i < count($aTemplateSet); ++$i){
  308. if ($aTemplateSet[$i]['ID'] == $sTemplateID) {
  309. $found_templateset = true;
  310. break;
  311. }
  312. }
  313. // FIXME: do we need/want to check here for actual presence of template sets?
  314. // selected template not available, fall back to default template
  315. //
  316. if (!$found_templateset) $sTemplateID = $sDefaultTemplateID;
  317. // need to build this object now because it is used below to validate
  318. // user css theme choice
  319. //
  320. $oTemplate = Template::construct_template($sTemplateID);
  321. // Make sure the chosen theme is a legitimate one.
  322. //
  323. // need to adjust $chosen_theme path with SM_PATH
  324. $chosen_theme_path = preg_replace("/(\.\.\/){1,}/", SM_PATH, $chosen_theme_path);
  325. $found_theme = false;
  326. while (!$found_theme && (list($index, $data) = each($user_themes))) {
  327. if ($data['PATH'] == $chosen_theme_path)
  328. $found_theme = true;
  329. }
  330. if (!$found_theme) {
  331. $template_themes = $oTemplate->get_alternative_stylesheets(true);
  332. while (!$found_theme && (list($path, $name) = each($template_themes))) {
  333. if ($path == $chosen_theme_path)
  334. $found_theme = true;
  335. }
  336. }
  337. if (!$found_theme || $chosen_theme == 'none') {
  338. $chosen_theme_path = NULL;
  339. }
  340. /*
  341. * NOTE: The $icon_theme_path var should contain the path to the icon
  342. * theme to use. If the admin has disabled icons, or the user has
  343. * set the icon theme to "None," no icons will be used.
  344. */
  345. $icon_theme_path = (!$use_icons || $icon_theme=='none') ? NULL : ($icon_theme == 'template' ? SM_PATH . Template::calculate_template_images_directory($sTemplateID) : $icon_theme);
  346. $default_icon_theme_path = (!$use_icons || $default_icon_theme=='none') ? NULL : ($default_icon_theme == 'template' ? SM_PATH . Template::calculate_template_images_directory($sTemplateID) : $default_icon_theme);
  347. $fallback_icon_theme_path = (!$use_icons || $fallback_icon_theme=='none') ? NULL : ($fallback_icon_theme == 'template' ? SM_PATH . Template::calculate_template_images_directory($sTemplateID) : $fallback_icon_theme);
  348. /* Load up the Signature file */
  349. $signature_abs = $signature = getSig($data_dir, $username, 'g');