load_prefs.php 17 KB

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