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