4
0

UserConfiguration.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @property string $apiPasswordHash
  5. * @property array{keep_period:string|false,keep_max:int|false,keep_min:int|false,keep_favourites:bool,keep_labels:bool,keep_unreads:bool} $archiving
  6. * @property bool $auto_load_more
  7. * @property bool $auto_remove_article
  8. * @property bool $bottomline_date
  9. * @property bool $bottomline_favorite
  10. * @property bool $bottomline_link
  11. * @property bool $bottomline_read
  12. * @property bool $bottomline_sharing
  13. * @property bool $bottomline_tags
  14. * @property bool $bottomline_myLabels
  15. * @property string $content_width
  16. * @property-read int $default_state
  17. * @property string $default_view
  18. * @property string|bool $display_categories
  19. * @property string $show_tags
  20. * @property int $show_tags_max
  21. * @property string $show_author_date
  22. * @property string $show_feed_name
  23. * @property string $show_article_icons
  24. * @property bool $display_posts
  25. * @property string $email_validation_token
  26. * @property-read bool $enabled
  27. * @property string $feverKey
  28. * @property bool $hide_read_feeds
  29. * @property int $html5_notif_timeout
  30. * @property bool $html5_enable_notif
  31. * @property int $good_notification_timeout
  32. * @property int $bad_notification_timeout
  33. * @property-read bool $is_admin
  34. * @property int|null $keep_history_default
  35. * @property string $language
  36. * @property string $timezone
  37. * @property bool $lazyload
  38. * @property string $mail_login
  39. * @property bool $mark_updated_article_unread
  40. * @property array<string,bool|int> $mark_when
  41. * @property int $max_posts_per_rss
  42. * @property-read array<string,int> $limits
  43. * @property int|null $old_entries
  44. * @property bool $onread_jump_next
  45. * @property string $passwordHash
  46. * @property int $posts_per_page
  47. * @property array<int,array{get?:string,name?:string,order?:string,search?:string,state?:int,url?:string,token?:string,
  48. * shareRss?:bool,shareOpml?:bool,description?:string,imageUrl?:string}> $queries
  49. * @property bool $reading_confirm
  50. * @property int $since_hours_posts_per_rss
  51. * @property bool $show_fav_unread
  52. * @property bool $show_favicons
  53. * @property bool $icons_as_emojis
  54. * @property int $simplify_over_n_feeds
  55. * @property bool $show_nav_buttons
  56. * @property 'big'|'small'|'none' $mark_read_button
  57. * @property 'ASC'|'DESC' $sort_order
  58. * @property 'id'|'c.name'|'date'|'f.name'|'length'|'link'|'rand'|'title' $sort
  59. * @property 'ASC'|'DESC' $secondary_sort_order
  60. * @property 'id'|'date'|'link'|'title' $secondary_sort
  61. * @property array<int,array<string,string>> $sharing
  62. * @property array<string,string> $shortcuts
  63. * @property bool $sides_close_article
  64. * @property bool $sticky_post
  65. * @property string $theme
  66. * @property string $darkMode
  67. * @property string $token
  68. * @property bool $topline_date
  69. * @property bool $topline_display_authors
  70. * @property bool $topline_favorite
  71. * @property bool $topline_myLabels
  72. * @property bool $topline_sharing
  73. * @property bool $topline_link
  74. * @property bool $topline_read
  75. * @property bool $topline_summary
  76. * @property string $topline_website
  77. * @property string $topline_thumbnail
  78. * @property int $ttl_default
  79. * @property int $dynamic_opml_ttl_default
  80. * @property string $view_mode
  81. * @property array<string,bool|int|string> $volatile
  82. * @property array<string,array<string,mixed>> $extensions
  83. * @property bool $retrieve_extension_list
  84. */
  85. final class FreshRSS_UserConfiguration extends Minz_Configuration {
  86. use FreshRSS_FilterActionsTrait;
  87. /** @throws Minz_FileNotExistException */
  88. public static function init(string $config_filename, ?string $default_filename = null): FreshRSS_UserConfiguration {
  89. parent::register('user', $config_filename, $default_filename);
  90. try {
  91. return parent::get('user');
  92. } catch (Minz_ConfigurationNamespaceException $ex) {
  93. FreshRSS::killApp($ex->getMessage());
  94. }
  95. }
  96. /**
  97. * Access the default configuration for users.
  98. * @throws Minz_FileNotExistException
  99. */
  100. public static function default(): FreshRSS_UserConfiguration {
  101. /** @var FreshRSS_UserConfiguration|null $default_user_conf */
  102. static $default_user_conf = null;
  103. if ($default_user_conf === null) {
  104. $namespace = 'user_default';
  105. FreshRSS_UserConfiguration::register($namespace, '_', FRESHRSS_PATH . '/config-user.default.php');
  106. $default_user_conf = FreshRSS_UserConfiguration::get($namespace);
  107. }
  108. return $default_user_conf;
  109. }
  110. /**
  111. * Register and return the configuration for a given user.
  112. *
  113. * Note this function has been created to generate temporary configuration
  114. * objects. If you need a long-time configuration, please don't use this function.
  115. *
  116. * @param string $username the name of the user of which we want the configuration.
  117. * @return FreshRSS_UserConfiguration|null object, or null if the configuration cannot be loaded.
  118. * @throws Minz_ConfigurationNamespaceException
  119. */
  120. public static function getForUser(string $username): ?FreshRSS_UserConfiguration {
  121. if (!FreshRSS_user_Controller::checkUsername($username)) {
  122. return null;
  123. }
  124. $namespace = 'user_' . $username;
  125. try {
  126. FreshRSS_UserConfiguration::register($namespace,
  127. USERS_PATH . '/' . $username . '/config.php',
  128. FRESHRSS_PATH . '/config-user.default.php');
  129. } catch (Minz_FileNotExistException $e) {
  130. Minz_Log::warning($e->getMessage(), ADMIN_LOG);
  131. return null;
  132. }
  133. $user_conf = FreshRSS_UserConfiguration::get($namespace);
  134. return $user_conf;
  135. }
  136. }