diff --git a/app/Models/Pages/Email.php b/app/Models/Pages/Email.php index f93a989b..01bdd7dc 100644 --- a/app/Models/Pages/Email.php +++ b/app/Models/Pages/Email.php @@ -37,13 +37,8 @@ class Email extends Page return $this->c->Message->message('Bad request'); } - $rules = $this->c->ProfileRules->setUser($this->curUser); - - if ( - ! $rules->viewEmail - || ! $rules->sendEmail - ) { - $message = null === $rules->sendEmail ? 'Form email disabled' : 'Bad request'; + if (empty($this->curUser->linkEmail)) { + $message = null === $this->curUser->linkEmail ? 'Form email disabled' : 'Bad request'; return $this->c->Message->message($message); } diff --git a/app/Models/Pages/Profile/View.php b/app/Models/Pages/Profile/View.php index bb524952..d4b7d69e 100644 --- a/app/Models/Pages/Profile/View.php +++ b/app/Models/Pages/Profile/View.php @@ -72,6 +72,7 @@ class View extends Profile $fields[] = [ 'type' => 'endwrap', ]; + if ( $this->rules->useAvatar && $this->curUser->avatar @@ -82,6 +83,7 @@ class View extends Profile 'value' => 'avatar', ]; } + $form['sets']['header'] = [ 'class' => ['header'], 'legend' => 'Essentials', @@ -98,10 +100,10 @@ class View extends Profile 'legend' => 'Admin note', 'fields' => [ 'admin_note' => [ - 'class' => ['pline'], - 'type' => 'str', - 'caption' => 'Admin note', - 'value' => $this->curUser->admin_note, + 'class' => ['pline'], + 'type' => 'str', + 'caption' => 'Admin note', + 'value' => $this->curUser->admin_note, ], ], ]; @@ -109,6 +111,7 @@ class View extends Profile // личное $fields = []; + if ('' != $this->curUser->realname) { $fields['realname'] = [ 'class' => ['pline'], @@ -117,10 +120,12 @@ class View extends Profile 'value' => $this->curUser->censorRealname, ]; } + $genders = [ FORK_GEN_MAN => __('Male'), FORK_GEN_FEM => __('Female'), ]; + if (isset($genders[$this->curUser->gender])) { $fields['gender'] = [ 'class' => ['pline'], @@ -129,6 +134,7 @@ class View extends Profile 'caption' => 'Gender', ]; } + if ('' != $this->curUser->location) { $fields['location'] = [ 'class' => ['pline'], @@ -137,6 +143,7 @@ class View extends Profile 'value' => $this->curUser->censorLocation, ]; } + if (! empty($fields)) { $form['sets']['personal'] = [ 'class' => ['data'], @@ -147,6 +154,7 @@ class View extends Profile // контактная информация $fields = []; + if ($this->rules->sendPM) { $this->c->Csrf->setHashExpiration(3600); @@ -166,27 +174,27 @@ class View extends Profile 'href' => $this->c->Router->link('PMAction', $pmArgs), ]; } - if ($this->rules->viewEmail) { - if (0 === $this->curUser->email_setting) { + + if (! empty($this->curUser->linkEmail)) { + if (\str_starts_with($this->curUser->linkEmail, 'mailto:')) { $fields['email'] = [ 'class' => ['pline'], 'type' => 'link', 'caption' => 'Email info', - 'value' => $this->curUser->censorEmail, - 'href' => 'mailto:' . $this->curUser->censorEmail, + 'value' => \substr($this->curUser->linkEmail, 7), + 'href' => $this->curUser->linkEmail, ]; - } elseif ($this->rules->sendEmail) { - $this->c->Csrf->setHashExpiration(3600); - + } else { $fields['email'] = [ 'class' => ['pline'], 'type' => 'link', 'caption' => 'Email info', 'value' => __('Send email'), - 'href' => $this->c->Router->link('SendEmail', ['id' => $this->curUser->id]), + 'href' => $this->curUser->linkEmail, ]; } } + if ( $this->rules->viewWebsite && $this->curUser->url @@ -201,6 +209,7 @@ class View extends Profile 'rel' => 'ugc', ]; } + if (! empty($fields)) { $form['sets']['contacts'] = [ 'class' => ['data'], @@ -212,6 +221,7 @@ class View extends Profile // подпись if ($this->rules->useSignature) { $fields = []; + if ($this->curUser->isSignature) { $fields['signature'] = [ 'type' => 'yield', @@ -221,6 +231,7 @@ class View extends Profile $this->signatureSection = true; } + if (! empty($fields)) { $form['sets']['signature'] = [ 'class' => ['data'], @@ -244,6 +255,7 @@ class View extends Profile 'value' => dt($this->curUser->last_post, true), 'caption' => 'Last post info', ]; + if ($this->curUser->last_post > 0) { if (1 === $this->user->g_search) { $fields['posts'] = [ @@ -289,10 +301,12 @@ class View extends Profile ]; } } + if ($this->rules->viewSubscription) { $subscr = $this->c->subscriptions; $subscrInfo = $subscr->info($this->curUser); $isLink = 1 === $this->user->g_search; + if (! empty($subscrInfo[$subscr::FORUMS_DATA])) { $fields['forums_subscr'] = [ 'class' => ['pline'], @@ -309,6 +323,7 @@ class View extends Profile 'title' => __('Show forums subscriptions'), ]; } + if (! empty($subscrInfo[$subscr::TOPICS_DATA])) { $fields['topics_subscr'] = [ 'class' => ['pline'], @@ -326,6 +341,7 @@ class View extends Profile ]; } } + $form['sets']['activity'] = [ 'class' => ['data'], 'legend' => 'User activity', @@ -334,6 +350,7 @@ class View extends Profile // приватная информация $fields = []; + if ($this->rules->viewLastVisit) { $fields['lastvisit'] = [ 'class' => ['pline'], @@ -344,6 +361,7 @@ class View extends Profile 'caption' => 'Last visit info', ]; } + if ($this->rules->viewOEmail) { $fields['open-email'] = [ 'class' => $this->curUser->email_confirmed ? ['pline', 'confirmed'] : ['pline', 'unconfirmed'], @@ -353,6 +371,7 @@ class View extends Profile 'href' => 'mailto:' . $this->curUser->censorEmail, ]; } + if ( $this->rules->viewIP && false !== \filter_var($this->curUser->registration_ip, \FILTER_VALIDATE_IP) @@ -371,13 +390,13 @@ class View extends Profile 'title' => __('IP title'), ]; } + $form['sets']['private'] = [ 'class' => ['data'], 'legend' => 'Private information', 'fields' => $fields, ]; - return $form; } } diff --git a/app/Models/Rules/Profile.php b/app/Models/Rules/Profile.php index ff09ef4e..b9c4ac96 100644 --- a/app/Models/Rules/Profile.php +++ b/app/Models/Rules/Profile.php @@ -62,20 +62,6 @@ class Profile extends Rules return $this->my || $this->user->isAdmMod; } - protected function getviewEmail(): bool - { - return ! $this->my - && ( - $this->user->isAdmMod // ???? модераторы у админов должны видеть email? - || ( - ! $this->user->isGuest - && ! $this->user->isAdmMod - && 1 === $this->user->g_send_email - && $this->curUser->email_setting < 2 - ) - ); - } - protected function geteditEmail(): bool { return $this->my || $this->admin; @@ -86,21 +72,6 @@ class Profile extends Rules return $this->my && ! $this->curUser->email_confirmed; } - protected function getsendEmail(): ?bool // ???? проверка на подтвержденный email? - { - if ($this->viewEmail) { - if ($this->user->isAdmMod) { - return true; - } elseif (1 === $this->curUser->email_setting) { - return true; - } - } elseif (2 === $this->curUser->email_setting) { - return null; - } - - return false; - } - protected function getsendPM(): bool { return ! $this->my diff --git a/app/Models/User/User.php b/app/Models/User/User.php index 6edb11dd..dfa4aad4 100644 --- a/app/Models/User/User.php +++ b/app/Models/User/User.php @@ -30,13 +30,14 @@ class User extends DataModel parent::__construct($container); $this->zDepend = [ - 'group_id' => ['isUnverified', 'isGuest', 'isAdmin', 'isAdmMod', 'isBanByName', 'link', 'usePM'], - 'id' => ['isGuest', 'link', 'online'], - 'last_visit' => ['currentVisit'], - 'signature' => ['isSignature'], - 'email' => ['email_normal'], - 'username' => ['username_normal'], - 'g_pm' => ['usePM'], + 'group_id' => ['isUnverified', 'isGuest', 'isAdmin', 'isAdmMod', 'isBanByName', 'link', 'usePM', 'linkEmail'], + 'id' => ['isGuest', 'link', 'online', 'linkEmail'], + 'last_visit' => ['currentVisit'], + 'signature' => ['isSignature'], + 'email' => ['email_normal', 'linkEmail'], + 'username' => ['username_normal'], + 'g_pm' => ['usePM'], + 'email_setting' => ['linkEmail'], ]; } @@ -366,4 +367,41 @@ class User extends DataModel || $this->isAdmin ); } + + /** + * Формирует ссылку на отправку письма от $this->c->user к $this + * ???? Результат используется как условие для вариантов отображения + */ + protected function getlinkEmail(): ?string + { + if ( + $this->c->user->isGuest + || $this->id === $this->c->user->id + || empty($this->email) + ) { + return ''; + } elseif (2 === $this->email_setting) { + return null; + } elseif ( + 0 === $this->email_setting + || ( + $this->isGuest + && $this->c->user->isAdmMod + ) + ) { + return 'mailto:' . $this->censorEmail; + } elseif ( + 1 === $this->email_setting + && ( + 1 === $this->c->user->g_send_email + || $this->c->user->isAdmin + ) + ) { + $this->c->Csrf->setHashExpiration(3600); + + return $this->c->Router->link('SendEmail', ['id' => $this->id]); + } else { + return ''; + } + } } diff --git a/app/templates/topic.forkbb.php b/app/templates/topic.forkbb.php index 731e9f11..c3460cda 100644 --- a/app/templates/topic.forkbb.php +++ b/app/templates/topic.forkbb.php @@ -115,8 +115,8 @@ @if ($post->user->url)