View.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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\Pages\Profile;
  10. use ForkBB\Models\Page;
  11. use ForkBB\Models\Pages\Profile;
  12. use ForkBB\Models\PM\Cnst;
  13. use function \ForkBB\__;
  14. use function \ForkBB\dt;
  15. use function \ForkBB\num;
  16. use function \ForkBB\url;
  17. class View extends Profile
  18. {
  19. /**
  20. * Подготавливает данные для шаблона просмотра профиля
  21. */
  22. public function view(array $args, string $method): Page
  23. {
  24. if (false === $this->initProfile($args['id'])) {
  25. return $this->c->Message->message('Bad request');
  26. }
  27. $this->hhsLevel = 'common'; // для остальных страниц профиля уровень задан в initProfile()
  28. $this->canonical = $this->curUser->link;
  29. $this->robots = null;
  30. $this->crumbs = $this->crumbs();
  31. $this->c->Online->calc($this); // для $this->curUser->lastVisit
  32. $this->form = $this->form($args);
  33. $this->actionBtns = $this->btns('view');
  34. return $this;
  35. }
  36. /**
  37. * Создает массив данных для формы
  38. */
  39. protected function form(array $args): array
  40. {
  41. $form = [
  42. 'sets' => []
  43. ];
  44. // имя, титул и аватара
  45. $fields = [];
  46. $fields['usertitle'] = [
  47. 'class' => ['usertitle'],
  48. 'type' => 'wrap',
  49. ];
  50. $fields['username'] = [
  51. 'class' => ['pline'],
  52. 'type' => 'str',
  53. 'caption' => 'Username',
  54. 'value' => $this->curUser->username,
  55. ];
  56. $fields['title'] = [
  57. 'class' => ['pline'],
  58. 'type' => 'str',
  59. 'caption' => 'Title',
  60. 'value' => $this->curUser->title(),
  61. ];
  62. $fields[] = [
  63. 'type' => 'endwrap',
  64. ];
  65. if (
  66. $this->rules->useAvatar
  67. && $this->curUser->avatar
  68. ) {
  69. $fields['avatar'] = [
  70. 'type' => 'yield',
  71. 'caption' => 'Avatar',
  72. 'value' => 'avatar',
  73. ];
  74. }
  75. $form['sets']['header'] = [
  76. 'class' => ['header'],
  77. # 'legend' => 'Options',
  78. 'fields' => $fields,
  79. ];
  80. // примечание администрации
  81. if (
  82. $this->user->isAdmMod
  83. && '' != $this->curUser->admin_note
  84. ) {
  85. $form['sets']['note'] = [
  86. 'class' => ['data'],
  87. 'legend' => 'Admin note',
  88. 'fields' => [
  89. 'admin_note' => [
  90. 'class' => ['pline'],
  91. 'type' => 'str',
  92. 'caption' => 'Admin note',
  93. 'value' => $this->curUser->admin_note,
  94. ],
  95. ],
  96. ];
  97. }
  98. // личное
  99. $fields = [];
  100. if ('' != $this->curUser->realname) {
  101. $fields['realname'] = [
  102. 'class' => ['pline'],
  103. 'type' => 'str',
  104. 'caption' => 'Realname',
  105. 'value' => $this->curUser->censorRealname,
  106. ];
  107. }
  108. $genders = [
  109. 1 => __('Male'),
  110. 2 => __('Female'),
  111. ];
  112. if (isset($genders[$this->curUser->gender])) {
  113. $fields['gender'] = [
  114. 'class' => ['pline'],
  115. 'type' => 'str',
  116. 'value' => $genders[$this->curUser->gender],
  117. 'caption' => 'Gender',
  118. ];
  119. }
  120. if ('' != $this->curUser->location) {
  121. $fields['location'] = [
  122. 'class' => ['pline'],
  123. 'type' => 'str',
  124. 'caption' => 'Location',
  125. 'value' => $this->curUser->censorLocation,
  126. ];
  127. }
  128. if (! empty($fields)) {
  129. $form['sets']['personal'] = [
  130. 'class' => ['data'],
  131. 'legend' => 'Personal information',
  132. 'fields' => $fields,
  133. ];
  134. }
  135. // контактная информация
  136. $fields = [];
  137. if ($this->rules->sendPM) {
  138. $this->c->Csrf->setHashExpiration(3600);
  139. $pmArgs = [
  140. 'action' => Cnst::ACTION_SEND,
  141. 'more1' => $this->curUser->id,
  142. ];
  143. $pmArgs += [
  144. 'more2' => $this->c->Csrf->createHash('PMAction', $pmArgs),
  145. ];
  146. $fields['pm'] = [
  147. 'class' => ['pline'],
  148. 'type' => 'link',
  149. 'caption' => 'PM',
  150. 'value' => __('Send PM'),
  151. 'href' => $this->c->Router->link('PMAction', $pmArgs),
  152. ];
  153. }
  154. if ($this->rules->viewEmail) {
  155. if (0 === $this->curUser->email_setting) {
  156. $fields['email'] = [
  157. 'class' => ['pline'],
  158. 'type' => 'link',
  159. 'caption' => 'Email info',
  160. 'value' => $this->curUser->censorEmail,
  161. 'href' => 'mailto:' . $this->curUser->censorEmail,
  162. ];
  163. } elseif ($this->rules->sendEmail) {
  164. $this->c->Csrf->setHashExpiration(3600);
  165. $fields['email'] = [
  166. 'class' => ['pline'],
  167. 'type' => 'link',
  168. 'caption' => 'Email info',
  169. 'value' => __('Send email'),
  170. 'href' => $this->c->Router->link('SendEmail', ['id' => $this->curUser->id]),
  171. ];
  172. }
  173. }
  174. if (
  175. $this->rules->viewWebsite
  176. && $this->curUser->url
  177. ) {
  178. $fields['url'] = [
  179. 'id' => 'website',
  180. 'class' => ['pline'],
  181. 'type' => 'link',
  182. 'caption' => 'Website',
  183. 'value' => $this->curUser->censorUrl,
  184. 'href' => url($this->curUser->censorUrl),
  185. 'rel' => 'ugc',
  186. ];
  187. }
  188. if (! empty($fields)) {
  189. $form['sets']['contacts'] = [
  190. 'class' => ['data'],
  191. 'legend' => 'Contact details',
  192. 'fields' => $fields,
  193. ];
  194. }
  195. // подпись
  196. if ($this->rules->useSignature) {
  197. $fields = [];
  198. if ($this->curUser->isSignature) {
  199. $fields['signature'] = [
  200. 'type' => 'yield',
  201. 'caption' => 'Signature',
  202. 'value' => 'signature',
  203. ];
  204. $this->signatureSection = true;
  205. }
  206. if (! empty($fields)) {
  207. $form['sets']['signature'] = [
  208. 'class' => ['data'],
  209. 'legend' => 'Signature',
  210. 'fields' => $fields,
  211. ];
  212. }
  213. }
  214. // активность
  215. $fields = [];
  216. $fields['registered'] = [
  217. 'class' => ['pline'],
  218. 'type' => 'str',
  219. 'value' => dt($this->curUser->registered, true),
  220. 'caption' => 'Registered info',
  221. ];
  222. $fields['lastpost'] = [
  223. 'class' => ['pline'],
  224. 'type' => 'str',
  225. 'value' => dt($this->curUser->last_post, true),
  226. 'caption' => 'Last post info',
  227. ];
  228. if ($this->curUser->last_post > 0) {
  229. if (1 === $this->user->g_search) {
  230. $fields['posts'] = [
  231. 'class' => ['pline'],
  232. 'type' => 'link',
  233. 'caption' => 'Posts info',
  234. 'value' => $this->user->showPostCount ? num($this->curUser->num_posts) : __('Show posts'),
  235. 'href' => $this->c->Router->link(
  236. 'SearchAction',
  237. [
  238. 'action' => 'posts',
  239. 'uid' => $this->curUser->id,
  240. ]
  241. ),
  242. 'title' => __('Show posts'),
  243. ];
  244. $fields['topics'] = [
  245. 'class' => ['pline'],
  246. 'type' => 'link',
  247. 'caption' => 'Topics info',
  248. 'value' => $this->user->showPostCount ? num($this->curUser->num_topics) : __('Show topics'),
  249. 'href' => $this->c->Router->link(
  250. 'SearchAction',
  251. [
  252. 'action' => 'topics',
  253. 'uid' => $this->curUser->id,
  254. ]
  255. ),
  256. 'title' => __('Show topics'),
  257. ];
  258. } elseif ($this->user->showPostCount) {
  259. $fields['posts'] = [
  260. 'class' => ['pline'],
  261. 'type' => 'str',
  262. 'caption' => 'Posts info',
  263. 'value' => num($this->curUser->num_posts),
  264. ];
  265. $fields['topics'] = [
  266. 'class' => ['pline'],
  267. 'type' => 'str',
  268. 'caption' => 'Topics info',
  269. 'value' => num($this->curUser->num_topics),
  270. ];
  271. }
  272. }
  273. if ($this->rules->viewSubscription) {
  274. $subscr = $this->c->subscriptions;
  275. $subscrInfo = $subscr->info($this->curUser);
  276. $isLink = 1 === $this->user->g_search;
  277. if (! empty($subscrInfo[$subscr::FORUMS_DATA])) {
  278. $fields['forums_subscr'] = [
  279. 'class' => ['pline'],
  280. 'type' => $isLink ? 'link' : 'str',
  281. 'caption' => 'Total forums subscriptions',
  282. 'value' => num(\count($subscrInfo[$subscr::FORUMS_DATA])),
  283. 'href' => $this->c->Router->link(
  284. 'SearchAction',
  285. [
  286. 'action' => 'forums_subscriptions',
  287. 'uid' => $this->curUser->id,
  288. ]
  289. ),
  290. 'title' => __('Show forums subscriptions'),
  291. ];
  292. }
  293. if (! empty($subscrInfo[$subscr::TOPICS_DATA])) {
  294. $fields['topics_subscr'] = [
  295. 'class' => ['pline'],
  296. 'type' => $isLink ? 'link' : 'str',
  297. 'caption' => 'Total topics subscriptions',
  298. 'value' => num(\count($subscrInfo[$subscr::TOPICS_DATA])),
  299. 'href' => $this->c->Router->link(
  300. 'SearchAction',
  301. [
  302. 'action' => 'topics_subscriptions',
  303. 'uid' => $this->curUser->id,
  304. ]
  305. ),
  306. 'title' => __('Show topics subscriptions'),
  307. ];
  308. }
  309. }
  310. $form['sets']['activity'] = [
  311. 'class' => ['data'],
  312. 'legend' => 'User activity',
  313. 'fields' => $fields,
  314. ];
  315. // приватная информация
  316. $fields = [];
  317. if ($this->rules->viewLastVisit) {
  318. $fields['lastvisit'] = [
  319. 'class' => ['pline'],
  320. 'type' => 'str',
  321. 'value' => $this->rules->my
  322. ? dt($this->curUser->last_visit)
  323. : dt($this->curUser->currentVisit, true),
  324. 'caption' => 'Last visit info',
  325. ];
  326. }
  327. if ($this->rules->viewOEmail) {
  328. $fields['open-email'] = [
  329. 'class' => $this->curUser->email_confirmed ? ['pline', 'confirmed'] : ['pline', 'unconfirmed'],
  330. 'type' => 2 === $this->curUser->email_setting ? 'str' : 'link',
  331. 'caption' => 'Email info',
  332. 'value' => $this->curUser->censorEmail,
  333. 'href' => 'mailto:' . $this->curUser->censorEmail,
  334. ];
  335. }
  336. if (
  337. $this->rules->viewIP
  338. && false !== \filter_var($this->curUser->registration_ip, \FILTER_VALIDATE_IP)
  339. ) {
  340. $fields['ip'] = [
  341. 'class' => ['pline'],
  342. 'type' => 'link',
  343. 'caption' => 'IP',
  344. 'value' => $this->curUser->registration_ip,
  345. 'href' => $this->c->Router->link(
  346. 'AdminHost',
  347. [
  348. 'ip' => $this->curUser->registration_ip,
  349. ]
  350. ),
  351. 'title' => __('IP title'),
  352. ];
  353. }
  354. $form['sets']['private'] = [
  355. 'class' => ['data'],
  356. 'legend' => 'Private information',
  357. 'fields' => $fields,
  358. ];
  359. return $form;
  360. }
  361. }