Model.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <?php
  2. namespace ForkBB\Models\User;
  3. use ForkBB\Models\DataModel;
  4. use ForkBB\Models\Model as BaseModel;
  5. use ForkBB\Models\Forum;
  6. use RuntimeException;
  7. class Model extends DataModel
  8. {
  9. /**
  10. * Статус неподтвержденного
  11. *
  12. * @return bool
  13. */
  14. protected function getisUnverified()
  15. {
  16. return 0 === $this->group_id;
  17. }
  18. /**
  19. * Статус гостя
  20. *
  21. * @return bool
  22. */
  23. protected function getisGuest()
  24. {
  25. return $this->group_id === $this->c->GROUP_GUEST
  26. || $this->id < 2
  27. || null === $this->group_id;
  28. }
  29. /**
  30. * Статус админа
  31. *
  32. * @return bool
  33. */
  34. protected function getisAdmin()
  35. {
  36. return $this->group_id === $this->c->GROUP_ADMIN;
  37. }
  38. /**
  39. * Статус админа/модератора
  40. *
  41. * @return bool
  42. */
  43. protected function getisAdmMod()
  44. {
  45. return $this->group_id === $this->c->GROUP_ADMIN
  46. || 1 == $this->g_moderator;
  47. }
  48. /**
  49. * Статус модератора для указанной модели
  50. *
  51. * @param BaseModel $model
  52. *
  53. * @throws RuntimeException
  54. *
  55. * @return bool
  56. */
  57. public function isModerator(BaseModel $model)
  58. {
  59. if (1 != $this->g_moderator) {
  60. return false;
  61. }
  62. while (! $model instanceof Forum) {
  63. $model = $model->parent;
  64. if (! $model instanceof BaseModel) {
  65. throw new RuntimeException('Moderator\'s rights can not be found');
  66. }
  67. }
  68. return isset($model->moderators[$this->id]);
  69. }
  70. /**
  71. * Время последнего действия пользователя
  72. *
  73. * @return int
  74. */
  75. protected function getlogged()
  76. {
  77. return empty($this->a['logged']) ? \time() : $this->a['logged'];
  78. }
  79. /**
  80. * Статус наличия данных пользователя в таблице online //????
  81. *
  82. * @return bool
  83. */
  84. protected function getisLogged()
  85. {
  86. return ! empty($this->a['logged']);
  87. }
  88. /**
  89. * Текущий язык пользователя
  90. *
  91. * @return string
  92. */
  93. protected function getlanguage()
  94. {
  95. $langs = $this->c->Func->getLangs();
  96. $lang = $this->isGuest || empty($this->a['language']) || ! \in_array($this->a['language'], $langs)
  97. ? $this->c->config->o_default_lang
  98. : $this->a['language'];
  99. if (\in_array($lang, $langs)) {
  100. return $lang;
  101. } else {
  102. return isset($langs[0]) ? $langs[0] : 'English';
  103. }
  104. }
  105. /**
  106. * Текущий стиль отображения
  107. *
  108. * @return string
  109. */
  110. protected function getstyle()
  111. {
  112. $styles = $this->c->Func->getStyles();
  113. $style = $this->isGuest || empty($this->a['style']) || ! \in_array($this->a['style'], $styles)
  114. ? $this->c->config->o_default_style
  115. : $this->a['style'];
  116. if (\in_array($style, $styles)) {
  117. return $style;
  118. } else {
  119. return isset($styles[0]) ? $styles[0] : 'ForkBB';
  120. }
  121. }
  122. /**
  123. * Ссылка на профиль пользователя
  124. *
  125. * @return null|string
  126. */
  127. protected function getlink()
  128. {
  129. if ($this->isGuest) {
  130. return null;
  131. } else {
  132. return $this->c->Router->link('User', ['id' => $this->id, 'name' => $this->username]);
  133. }
  134. }
  135. /**
  136. * Ссылка на аватару пользователя
  137. *
  138. * @return null|string
  139. */
  140. protected function getavatar()
  141. {
  142. $filetypes = ['jpg', 'gif', 'png'];
  143. foreach ($filetypes as $type) {
  144. $path = $this->c->DIR_PUBLIC . "{$this->c->config->o_avatars_dir}/{$this->id}.{$type}";
  145. if (\file_exists($path) && \getimagesize($path)) {
  146. return $this->c->PUBLIC_URL . "{$this->c->config->o_avatars_dir}/{$this->id}.{$type}";
  147. }
  148. }
  149. return null;
  150. }
  151. /**
  152. * Титул пользователя
  153. *
  154. * @return string
  155. */
  156. public function title()
  157. {
  158. if (isset($this->c->bans->userList[mb_strtolower($this->username)])) { //????
  159. return \ForkBB\__('Banned');
  160. } elseif ($this->title != '') {
  161. return \ForkBB\cens($this->title);
  162. } elseif ($this->g_user_title != '') {
  163. return \ForkBB\cens($this->g_user_title);
  164. } elseif ($this->isGuest) {
  165. return \ForkBB\__('Guest');
  166. } else {
  167. return \ForkBB\__('Member');
  168. }
  169. }
  170. /**
  171. * Статус online
  172. *
  173. * @return bool
  174. */
  175. protected function getonline()
  176. {
  177. return isset($this->c->Online->online[$this->id]);
  178. }
  179. /**
  180. * HTML код подписи
  181. *
  182. * @return string
  183. */
  184. protected function gethtmlSign()
  185. {
  186. return $this->c->censorship->censor($this->c->Parser->parseSignature($this->signature));
  187. }
  188. /**
  189. * Статус видимости профилей пользователей
  190. *
  191. * @return bool
  192. */
  193. protected function getviewUsers()
  194. {
  195. return 1 == $this->g_view_users || $this->isAdmin;
  196. }
  197. /**
  198. * Статус поиска пользователей
  199. *
  200. * @return bool
  201. */
  202. protected function getsearchUsers()
  203. {
  204. return 1 == $this->g_search_users || $this->isAdmin;
  205. }
  206. /**
  207. * Статус показа аватаров
  208. *
  209. * @return bool
  210. */
  211. protected function getshowAvatar()
  212. {
  213. return '1' == $this->c->config->o_avatars && 1 == $this->show_avatars;
  214. }
  215. /**
  216. * Статус показа информации пользователя
  217. *
  218. * @return bool
  219. */
  220. protected function getshowUserInfo()
  221. {
  222. return '1' == $this->c->config->o_show_user_info;
  223. }
  224. /**
  225. * Статус показа подписи
  226. *
  227. * @return bool
  228. */
  229. protected function getshowSignature()
  230. {
  231. return '1' == $this->c->config->o_signatures && 1 == $this->show_sig;
  232. }
  233. /**
  234. * Статус показа количества сообщений
  235. *
  236. * @return bool
  237. */
  238. protected function getshowPostCount()
  239. {
  240. return '1' == $this->c->config->o_show_post_count || $this->isAdmMod;
  241. }
  242. }