Profile.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /**
  3. * This file is part of the ForkBB <https://github.com/forkbb>.
  4. *
  5. * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
  6. * @license The MIT License (MIT)
  7. */
  8. declare(strict_types=1);
  9. namespace ForkBB\Models\Rules;
  10. use ForkBB\Models\Model;
  11. use ForkBB\Models\Rules;
  12. use ForkBB\Models\User\User;
  13. class Profile extends Rules
  14. {
  15. protected $curUser;
  16. protected $user;
  17. /**
  18. * Задает профиль пользователя для применения правил
  19. */
  20. public function setUser(User $curUser): Profile
  21. {
  22. $this->setAttrs([]);
  23. $this->ready = true;
  24. $this->user = $this->c->user;
  25. $this->curUser = $curUser;
  26. $this->my = ! $curUser->isGuest && $curUser->id === $this->user->id;
  27. $this->admin = $this->user->isAdmin && ($this->my || ! $curUser->isAdmin);
  28. $this->moderator = $this->user->isAdmMod && ($this->my || ! $curUser->isAdmMod);
  29. $this->editProfile = $this->my || $this->admin || ($this->moderator && 1 === $this->user->g_mod_edit_users);
  30. $this->editConfig = $this->my || $this->admin || ($this->moderator && 1 === $this->user->g_mod_edit_users); // ????
  31. return $this;
  32. }
  33. protected function getrename(): bool
  34. {
  35. return ! $this->curUser->isBanByName
  36. && (
  37. $this->admin
  38. || ($this->moderator && 1 === $this->user->g_mod_rename_users)
  39. );
  40. }
  41. protected function geteditPass(): bool
  42. {
  43. return $this->my || $this->admin || ($this->moderator && 1 === $this->user->g_mod_change_passwords);
  44. }
  45. protected function getsetTitle(): bool
  46. {
  47. return $this->admin || $this->moderator || 1 === $this->user->g_set_title;
  48. }
  49. protected function getviewOEmail(): bool
  50. {
  51. return $this->my || $this->user->isAdmMod;
  52. }
  53. protected function getviewEmail(): bool
  54. {
  55. return ! $this->my
  56. && (
  57. $this->user->isAdmMod // ???? модераторы у админов должны видеть email?
  58. || (
  59. ! $this->user->isGuest
  60. && ! $this->user->isAdmMod
  61. && 1 === $this->user->g_send_email
  62. && $this->curUser->email_setting < 2
  63. )
  64. );
  65. }
  66. protected function geteditEmail(): bool
  67. {
  68. return $this->my || $this->admin;
  69. }
  70. protected function getconfirmEmail(): bool
  71. {
  72. return $this->my && ! $this->curUser->email_confirmed;
  73. }
  74. protected function getsendEmail(): ?bool // ???? проверка на подтвержденный email?
  75. {
  76. if ($this->viewEmail) {
  77. if ($this->user->isAdmMod) {
  78. return true;
  79. } elseif (1 === $this->curUser->email_setting) {
  80. return true;
  81. }
  82. } elseif (2 === $this->curUser->email_setting) {
  83. return null;
  84. }
  85. return false;
  86. }
  87. protected function getsendPM(): bool
  88. {
  89. return ! $this->my
  90. && $this->user->usePM
  91. && 1 === $this->user->u_pm
  92. && $this->curUser->usePM
  93. && (
  94. 1 === $this->curUser->u_pm
  95. || $this->user->isAdmin
  96. );
  97. }
  98. protected function getviewLastVisit(): bool
  99. {
  100. return $this->my || $this->user->isAdmMod;
  101. }
  102. protected function getbanUser(): bool
  103. {
  104. return ! $this->my
  105. && ($this->admin || ($this->moderator && 1 === $this->user->g_mod_ban_users))
  106. && ! $this->curUser->isAdmMod
  107. && ! $this->curUser->isGuest;
  108. }
  109. protected function getdeleteUser(): bool
  110. {
  111. return ! $this->my
  112. && $this->admin
  113. && ! $this->curUser->isAdmMod
  114. && ! $this->curUser->isGuest;
  115. }
  116. protected function getviewIP(): bool
  117. {
  118. return $this->user->isAdmin;;
  119. }
  120. protected function getuseAvatar(): bool
  121. {
  122. return 1 === $this->c->config->b_avatars;
  123. }
  124. protected function getuseSignature(): bool
  125. {
  126. return $this->curUser->g_sig_length > 0 && $this->curUser->g_sig_lines > 0;
  127. }
  128. protected function getviewWebsite(): bool
  129. {
  130. return $this->user->isAdmMod || 1 === $this->curUser->g_post_links;
  131. }
  132. protected function geteditWebsite(): bool
  133. {
  134. return $this->admin || (($this->moderator || $this->my) && 1 === $this->user->g_post_links); //????
  135. }
  136. protected function getchangeGroup(): bool
  137. {
  138. return $this->admin || ($this->my && $this->moderator);
  139. }
  140. protected function getconfModer(): bool
  141. {
  142. return $this->user->isAdmin && $this->curUser->isAdmMod && ! $this->curUser->isAdmin;
  143. }
  144. protected function geteditIpCheckType(): bool
  145. {
  146. return $this->my || $this->admin;
  147. }
  148. protected function getviewSubscription(): bool
  149. {
  150. return (
  151. $this->my
  152. || $this->admin
  153. )
  154. && (
  155. 1 === $this->c->config->b_forum_subscriptions
  156. || 1 === $this->c->config->b_topic_subscriptions
  157. );
  158. }
  159. }