123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- <?php
- /**
- * This file is part of the ForkBB <https://github.com/forkbb>.
- *
- * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
- * @license The MIT License (MIT)
- */
- declare(strict_types=1);
- namespace ForkBB\Models\Pages;
- use ForkBB\Models\Model;
- use function \ForkBB\__;
- trait PostFormTrait
- {
- /**
- * Возвращает данные для построения формы создания темы/сообщения
- */
- protected function messageForm(?Model $model, string $marker, array $args, bool $edit, bool $first, bool $quick): array
- {
- $vars = $args['_vars'] ?? null;
- unset($args['_vars']);
- $notPM = $this->fIndex !== self::FI_PM;
- $autofocus = $quick ? null : true;
- $form = [
- 'action' => $this->c->Router->link($marker, $args),
- 'hidden' => [
- 'token' => $this->c->Csrf->create($marker, $args),
- ],
- 'sets' => [],
- 'btns' => [
- 'submit' => [
- 'type' => 'submit',
- 'value' => __('NewTopic' === $marker ? 'Create topic' : 'Submit'),
- ],
- 'preview' => [
- 'type' => 'submit',
- 'value' => __('Preview'),
- 'class' => ['f-opacity'],
- ],
- ],
- ];
- $fieldset = [];
- if ($this->user->isGuest) {
- $fieldset['username'] = [
- 'class' => ['w1'],
- 'type' => 'text',
- 'maxlength' => '25',
- 'caption' => 'Username',
- 'required' => true,
- 'pattern' => '^.{2,25}$',
- 'value' => $vars['username'] ?? null,
- 'autofocus' => $autofocus,
- ];
- $fieldset['email'] = [
- 'class' => ['w2'],
- 'type' => 'text',
- 'maxlength' => '80',
- 'caption' => 'Email',
- 'required' => 1 === $this->c->config->b_force_guest_email,
- 'pattern' => '.+@.+',
- 'value' => $vars['email'] ?? null,
- ];
- $autofocus = null;
- }
- if ($first) {
- $fieldset['subject'] = [
- 'class' => ['w0'],
- 'type' => 'text',
- 'maxlength' => '70',
- 'caption' => 'Subject',
- 'required' => true,
- 'value' => $vars['subject'] ?? null,
- 'autofocus' => $autofocus,
- ];
- $autofocus = null;
- }
- $fieldset['message'] = [
- 'class' => ['w0'],
- 'type' => 'textarea',
- 'caption' => 'Message',
- 'required' => true,
- 'value' => $vars['message'] ?? null,
- 'autofocus' => $autofocus,
- ];
- $form['sets']['uesm'] = [
- 'fields' => $fieldset,
- ];
- $autofocus = null;
- $fieldset = [];
- if ($notPM) {
- if (
- $this->user->isAdmin
- || $this->user->isModerator($model)
- ) {
- if ($first) {
- $fieldset['stick_topic'] = [
- 'type' => 'checkbox',
- 'label' => 'Stick topic',
- 'checked' => (bool) ($vars['stick_topic'] ?? false),
- ];
- $fieldset['stick_fp'] = [
- 'type' => 'checkbox',
- 'label' => 'Stick first post',
- 'checked' => (bool) ($vars['stick_fp'] ?? false),
- ];
- } elseif (! $edit) {
- $fieldset['merge_post'] = [
- 'type' => 'checkbox',
- 'label' => 'Merge posts',
- 'checked' => (bool) ($vars['merge_post'] ?? true),
- ];
- }
- if (
- $edit
- && ! $model->user->isGuest
- && ! $model->user->isAdmin
- ) {
- $fieldset['edit_post'] = [
- 'type' => 'checkbox',
- 'label' => 'EditPost edit',
- 'checked' => (bool) ($vars['edit_post'] ?? false),
- ];
- }
- }
- if (
- ! $edit
- && 1 === $this->c->config->b_topic_subscriptions
- && $this->user->email_confirmed
- ) {
- $subscribed = ! $first && $model->is_subscribed;
- if ($quick) {
- if (
- $subscribed
- || $this->user->auto_notify
- ) {
- $form['hidden']['subscribe'] = '1';
- }
- } else {
- $fieldset['subscribe'] = [
- 'type' => 'checkbox',
- 'label' => $subscribed ? 'Stay subscribed' : 'New subscribe',
- 'checked' => (bool) ($vars['subscribe'] ?? ($subscribed || $this->user->auto_notify)),
- ];
- }
- }
- }
- if (
- ! $quick
- && 1 === $this->c->config->b_smilies
- ) {
- $fieldset['hide_smilies'] = [
- 'type' => 'checkbox',
- 'label' => 'Hide smilies',
- 'checked' => (bool) ($vars['hide_smilies'] ?? false),
- ];
- }
- if ($fieldset) {
- $form['sets']['uesm-options'] = [
- 'legend' => 'Options',
- 'fields' => $fieldset,
- ];
- }
- if (
- $first
- && $notPM
- && $this->user->usePoll
- ) {
- $term = $edit && $model->parent->poll_term
- ? $model->parent->poll_term
- : $this->c->config->i_poll_term;
- $fieldset = [];
- $fieldset['poll_enable'] = [
- 'type' => 'checkbox',
- 'label' => 'Include poll',
- 'checked' => (bool) ($vars['poll_enable'] ?? false),
- 'disabled' => $vars['pollNoEdit'] ?? null,
- ];
- $fieldset["poll[duration]"] = [
- 'type' => 'number',
- 'min' => '0',
- 'max' => '366',
- 'value' => $vars['poll']['duration'] ?? 0,
- 'caption' => 'Poll duration label',
- 'help' => 'Poll duration help',
- 'disabled' => $vars['pollNoEdit'] ?? null,
- ];
- $fieldset['poll[hide_result]'] = [
- 'type' => 'checkbox',
- 'label' => ['Hide poll results up to %s voters', $term],
- 'checked' => (bool) ($vars['poll']['hide_result'] ?? false),
- 'disabled' => $vars['pollNoEdit'] ?? null,
- ];
- $form['sets']['uesm-poll'] = [
- 'legend' => 'Poll legend',
- 'fields' => $fieldset,
- ];
- for ($qid = 1; $qid <= $this->c->config->i_poll_max_questions; $qid++) {
- $fieldset = [];
- $fieldset["poll[question][{$qid}]"] = [
- 'type' => 'text',
- 'maxlength' => '240',
- 'caption' => 'Question text label',
- 'value' => $vars['poll']['question'][$qid] ?? null,
- 'disabled' => $vars['pollNoEdit'] ?? null,
- ];
- $fieldset["poll[type][{$qid}]"] = [
- 'type' => 'number',
- 'min' => '1',
- 'max' => (string) $this->c->config->i_poll_max_fields,
- 'value' => $vars['poll']['type'][$qid] ?? 1,
- 'caption' => 'Answer type label',
- 'help' => 'Answer type help',
- 'disabled' => $vars['pollNoEdit'] ?? null,
- ];
- for ($fid = 1; $fid <= $this->c->config->i_poll_max_fields; $fid++) {
- $fieldset["poll[answer][{$qid}][{$fid}]"] = [
- 'type' => 'text',
- 'maxlength' => '240',
- 'caption' => ['Answer %s label', $fid],
- 'value' => $vars['poll']['answer'][$qid][$fid] ?? null,
- 'disabled' => $vars['pollNoEdit'] ?? null,
- ];
- }
- $form['sets']["uesm-q-{$qid}"] = [
- 'legend' => ['Question %s legend', $qid],
- 'fields' => $fieldset,
- ];
- }
- $this->pageHeader('pollJS', 'script', 9000, [
- 'src' => $this->publicLink('/js/poll.js'),
- ]);
- }
- return $form;
- }
- }
|