user_settings.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. $settings_entries = [
  3. [
  4. 'id' => 'show-r15',
  5. 'type' => 'checkbox',
  6. 'default' => 'off'
  7. ],
  8. [
  9. 'id' => 'show-r18',
  10. 'type' => 'checkbox',
  11. 'default' => 'off'
  12. ],
  13. [
  14. 'id' => 'show-r18g',
  15. 'type' => 'checkbox',
  16. 'default' => 'off'
  17. ],
  18. [
  19. 'id' => 'show-aigc',
  20. 'type' => 'checkbox',
  21. 'default' => 'on'
  22. ],
  23. [
  24. 'id' => 'collapse-pages',
  25. 'type' => 'checkbox',
  26. 'default' => 'on'
  27. ],
  28. [
  29. 'id' => 'load-comments',
  30. 'type' => 'checkbox',
  31. 'default' => 'on'
  32. ],
  33. [
  34. 'id' => 'load-related',
  35. 'type' => 'checkbox',
  36. 'default' => 'on'
  37. ],
  38. [
  39. 'id' => 'theme',
  40. 'type' => 'dropdown',
  41. 'options' => ['light', 'dark'],
  42. 'default' => 'dark'
  43. ],
  44. [
  45. 'id' => 'timezone',
  46. 'type' => 'dropdown',
  47. 'options' => timezone_identifiers_list(),
  48. 'default' => 'Asia/Tokyo'
  49. ],
  50. [
  51. 'id' => 'language',
  52. 'type' => 'dropdown',
  53. 'options' => ['en', 'zh'],
  54. 'default' => 'en'
  55. ]
  56. ];
  57. $settings = [];
  58. function load_settings($original) {
  59. global $settings, $settings_entries;
  60. foreach ($settings_entries as $entry) {
  61. if (!isset($original[$entry['id']])) {
  62. $settings[$entry['id']] = $entry['default'];
  63. }
  64. else switch ($entry['type']) {
  65. case 'checkbox':
  66. $settings[$entry['id']] = ($original[$entry['id']] == 'on')
  67. ? 'on': 'off';
  68. break;
  69. case 'dropdown':
  70. $settings[$entry['id']] = in_array($original[$entry['id']], $entry['options'])
  71. ? $original[$entry['id']] : $entry['default'];
  72. break;
  73. }
  74. }
  75. }