Merge branch '5.3'
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 18 Feb 2021 10:12:38 +0000 (11:12 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 18 Feb 2021 10:12:38 +0000 (11:12 +0100)
1  2 
wcfsetup/install/files/lib/data/contact/option/ContactOptionAction.class.php
wcfsetup/install/files/lib/data/contact/recipient/ContactRecipient.class.php

index 8d9c0307c5f3ded6290c5e9cacd99575585f8dd3,21ecda03bab4908cef9fefd78a1cbf481f522f43..10562c2d7cf1cbde432d987f7734204f801ede0a
@@@ -20,151 -18,147 +20,151 @@@ use wcf\system\WCF
  
  /**
   * Executes contact option related actions.
 - * 
 - * @author    Alexander Ebert
 - * @copyright 2001-2019 WoltLab GmbH
 - * @license   GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 - * @package   WoltLabSuite\Core\Data\Contact\Option
 - * @since     3.1
 - * 
 - * @method    ContactOptionEditor[]   getObjects()
 - * @method    ContactOptionEditor     getSingleObject()
 + *
 + * @author  Alexander Ebert
 + * @copyright   2001-2019 WoltLab GmbH
 + * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 + * @package WoltLabSuite\Core\Data\Contact\Option
 + * @since   3.1
 + *
 + * @method  ContactOptionEditor[]   getObjects()
 + * @method  ContactOptionEditor getSingleObject()
   */
 -class ContactOptionAction extends CustomOptionAction implements ISortableAction {
 -      /**
 -       * @inheritDoc
 -       */
 -      protected $className = ContactOptionEditor::class;
 -      
 -      /**
 -       * @inheritDoc
 -       */
 -      protected $permissionsCreate = ['admin.contact.canManageContactForm'];
 -      
 -      /**
 -       * @inheritDoc
 -       */
 -      protected $permissionsDelete = ['admin.contact.canManageContactForm'];
 -      
 -      /**
 -       * @inheritDoc
 -       */
 -      protected $permissionsUpdate = ['admin.contact.canManageContactForm'];
 -      
 -      /**
 -       * @inheritDoc
 -       */
 -      protected $requireACP = ['create', 'delete', 'update', 'updatePosition'];
 -      
 -      /**
 -       * Sends an email to the selected recipient.
 -       */
 -      public function send() {
 -              $defaultLanguage = LanguageFactory::getInstance()->getDefaultLanguage();
 -              
 -              $recipient = new ContactRecipient($this->parameters['recipientID']);
 -              /** @var ContactOptionHandler $optionHandler */
 -              $optionHandler = $this->parameters['optionHandler'];
 -              
 -              /** @var AttachmentHandler $attachmentHandler */
 -              $attachmentHandler = (!empty($this->parameters['attachmentHandler'])) ? $this->parameters['attachmentHandler'] : null;
 -              
 -              /** @var ContactAttachment[] $attachments */
 -              $attachments = [];
 -              if ($attachmentHandler !== null) {
 -                      foreach ($attachmentHandler->getAttachmentList() as $attachment) {
 -                              $attachments[] = ContactAttachmentEditor::create([
 -                                      'attachmentID' => $attachment->attachmentID,
 -                                      'accessKey' => ContactAttachment::generateKey(),
 -                              ]);
 -                              
 -                              (new AttachmentEditor($attachment))->update([
 -                                      'objectID' => $attachment->attachmentID,
 -                                      'tmpHash' => '',
 -                              ]);
 -                      }
 -              }
 -              
 -              $options = [];
 -              foreach ($optionHandler->getOptions() as $option) {
 -                      /** @var ContactOption $object */
 -                      $object = $option['object'];
 -                      if ($object->optionType === 'date' && !$object->getOptionValue()) {
 -                              // skip empty dates
 -                              continue;
 -                      }
 -                      
 -                      $options[] = [
 -                              'isMessage' => $object->isMessage(),
 -                              'title' => $object->getLocalizedName($defaultLanguage),
 -                              'value' => $object->getFormattedOptionValue(true),
 -                              'htmlValue' => $object->getFormattedOptionValue(),
 -                      ];
 -              }
 -              
 -              // build message data
 -              $messageData = [
 -                      'options' => $options,
 -                      'recipient' => $recipient,
 -                      'name' => $this->parameters['name'],
 -                      'emailAddress' => $this->parameters['email'],
 -                      'attachments' => $attachments,
 -              ];
 -              
 -              // build mail
 -              $email = new Email();
 -              $email->addRecipient($recipient->getMailbox());
 -              $email->setSubject($defaultLanguage->get('wcf.contact.mail.subject'));
 -              $email->setBody(new MimePartFacade([
 -                      new RecipientAwareTextMimePart('text/html', 'email_contact', 'wcf', $messageData),
 -                      new RecipientAwareTextMimePart('text/plain', 'email_contact', 'wcf', $messageData)
 -              ]));
 -              
 -              // add reply-to tag
 -              $email->setReplyTo(new Mailbox($this->parameters['email']));
 -              
 -              // send mail
 -              $email->send();
 -      }
 -      
 -      /**
 -       * @inheritDoc
 -       */
 -      public function validateUpdatePosition() {
 -              WCF::getSession()->checkPermissions($this->permissionsUpdate);
 -              
 -              if (!isset($this->parameters['data']['structure']) || !is_array($this->parameters['data']['structure'])) {
 -                      throw new UserInputException('structure');
 -              }
 -              
 -              $recipientList = new ContactOptionList();
 -              $recipientList->setObjectIDs($this->parameters['data']['structure'][0]);
 -              if ($recipientList->countObjects() != count($this->parameters['data']['structure'][0])) {
 -                      throw new UserInputException('structure');
 -              }
 -      }
 -      
 -      /**
 -       * @inheritDoc
 -       */
 -      public function updatePosition() {
 -              $sql = "UPDATE  wcf".WCF_N."_contact_option
 -                      SET     showOrder = ?
 -                      WHERE   optionID = ?";
 -              $statement = WCF::getDB()->prepareStatement($sql);
 -              
 -              $showOrder = 1;
 -              WCF::getDB()->beginTransaction();
 -              foreach ($this->parameters['data']['structure'][0] as $optionID) {
 -                      $statement->execute([
 -                              $showOrder++,
 -                              $optionID
 -                      ]);
 -              }
 -              WCF::getDB()->commitTransaction();
 -      }
 +class ContactOptionAction extends CustomOptionAction implements ISortableAction
 +{
 +    /**
 +     * @inheritDoc
 +     */
 +    protected $className = ContactOptionEditor::class;
 +
 +    /**
 +     * @inheritDoc
 +     */
 +    protected $permissionsCreate = ['admin.contact.canManageContactForm'];
 +
 +    /**
 +     * @inheritDoc
 +     */
 +    protected $permissionsDelete = ['admin.contact.canManageContactForm'];
 +
 +    /**
 +     * @inheritDoc
 +     */
 +    protected $permissionsUpdate = ['admin.contact.canManageContactForm'];
 +
 +    /**
 +     * @inheritDoc
 +     */
 +    protected $requireACP = ['create', 'delete', 'update', 'updatePosition'];
 +
 +    /**
 +     * Sends an email to the selected recipient.
 +     */
 +    public function send()
 +    {
 +        $defaultLanguage = LanguageFactory::getInstance()->getDefaultLanguage();
 +
 +        $recipient = new ContactRecipient($this->parameters['recipientID']);
 +        /** @var ContactOptionHandler $optionHandler */
 +        $optionHandler = $this->parameters['optionHandler'];
 +
 +        /** @var AttachmentHandler $attachmentHandler */
 +        $attachmentHandler = (!empty($this->parameters['attachmentHandler'])) ? $this->parameters['attachmentHandler'] : null;
 +
 +        /** @var ContactAttachment[] $attachments */
 +        $attachments = [];
 +        if ($attachmentHandler !== null) {
 +            foreach ($attachmentHandler->getAttachmentList() as $attachment) {
 +                $attachments[] = ContactAttachmentEditor::create([
 +                    'attachmentID' => $attachment->attachmentID,
 +                    'accessKey' => ContactAttachment::generateKey(),
 +                ]);
 +
 +                (new AttachmentEditor($attachment))->update([
 +                    'objectID' => $attachment->attachmentID,
 +                    'tmpHash' => '',
 +                ]);
 +            }
 +        }
 +
 +        $options = [];
 +        foreach ($optionHandler->getOptions() as $option) {
 +            /** @var ContactOption $object */
 +            $object = $option['object'];
 +            if ($object->optionType === 'date' && !$object->getOptionValue()) {
 +                // skip empty dates
 +                continue;
 +            }
 +
 +            $options[] = [
 +                'isMessage' => $object->isMessage(),
 +                'title' => $object->getLocalizedName($defaultLanguage),
 +                'value' => $object->getFormattedOptionValue(true),
 +                'htmlValue' => $object->getFormattedOptionValue(),
 +            ];
 +        }
 +
 +        // build message data
 +        $messageData = [
 +            'options' => $options,
 +            'recipient' => $recipient,
 +            'name' => $this->parameters['name'],
 +            'emailAddress' => $this->parameters['email'],
 +            'attachments' => $attachments,
 +        ];
 +
 +        // build mail
 +        $email = new Email();
-         $email->addRecipient(new Mailbox($recipient->email));
++        $email->addRecipient($recipient->getMailbox());
 +        $email->setSubject($defaultLanguage->get('wcf.contact.mail.subject'));
 +        $email->setBody(new MimePartFacade([
 +            new RecipientAwareTextMimePart('text/html', 'email_contact', 'wcf', $messageData),
 +            new RecipientAwareTextMimePart('text/plain', 'email_contact', 'wcf', $messageData),
 +        ]));
 +
 +        // add reply-to tag
 +        $email->setReplyTo(new Mailbox($this->parameters['email']));
 +
 +        // send mail
 +        $email->send();
 +    }
 +
 +    /**
 +     * @inheritDoc
 +     */
 +    public function validateUpdatePosition()
 +    {
 +        WCF::getSession()->checkPermissions($this->permissionsUpdate);
 +
 +        if (!isset($this->parameters['data']['structure']) || !\is_array($this->parameters['data']['structure'])) {
 +            throw new UserInputException('structure');
 +        }
 +
 +        $recipientList = new ContactOptionList();
 +        $recipientList->setObjectIDs($this->parameters['data']['structure'][0]);
 +        if ($recipientList->countObjects() != \count($this->parameters['data']['structure'][0])) {
 +            throw new UserInputException('structure');
 +        }
 +    }
 +
 +    /**
 +     * @inheritDoc
 +     */
 +    public function updatePosition()
 +    {
 +        $sql = "UPDATE  wcf" . WCF_N . "_contact_option
 +                SET     showOrder = ?
 +                WHERE   optionID = ?";
 +        $statement = WCF::getDB()->prepareStatement($sql);
 +
 +        $showOrder = 1;
 +        WCF::getDB()->beginTransaction();
 +        foreach ($this->parameters['data']['structure'][0] as $optionID) {
 +            $statement->execute([
 +                $showOrder++,
 +                $optionID,
 +            ]);
 +        }
 +        WCF::getDB()->commitTransaction();
 +    }
  }
index 3be7ad720b3e64424c1c0789c1d71964decfa545,00a1d066994b524daacd8982e116df0146ecc784..eb45d6ffde0030d523416f37f8fb84f516820f49
@@@ -1,58 -1,83 +1,92 @@@
  <?php
 +
  namespace wcf\data\contact\recipient;
 +
  use wcf\data\DatabaseObject;
+ use wcf\system\email\Mailbox;
  use wcf\system\WCF;
  
  /**
   * Represents a contact recipient.
 - * 
 - * @author    Alexander Ebert
 - * @copyright 2001-2019 WoltLab GmbH
 - * @license   GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 - * @package   WoltLabSuite\Core\Data\Contact\Recipient
 - * @since     3.1
 - * 
 - * @property-read     integer         $recipientID            unique id of the recipient
 - * @property-read     string          $name                   name of the recipient
 - * @property-read     string          $email                  email address of the recipient
 - * @property-read     integer         $showOrder              position of the recipient in relation to other recipients
 - * @property-read     integer         $isAdministrator        is `1` if the recipient is the administrator and the `email` value equals `MAIL_ADMIN_ADDRESS`, otherwise `0`
 - * @property-read     integer         $isDisabled             is `1` if the recipient is disabled and thus is not available for selection, otherwise `0`
 - * @property-read     integer         $originIsSystem         is `1` if the recipient has been delivered by a package, otherwise `0` (i.e. the recipient has been created in the ACP)
 + *
 + * @author  Alexander Ebert
 + * @copyright   2001-2019 WoltLab GmbH
 + * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 + * @package WoltLabSuite\Core\Data\Contact\Recipient
 + * @since   3.1
 + *
 + * @property-read   int $recipientID        unique id of the recipient
 + * @property-read   string $name           name of the recipient
 + * @property-read   string $email          email address of the recipient
 + * @property-read   int $showOrder      position of the recipient in relation to other recipients
 + * @property-read   int $isAdministrator    is `1` if the recipient is the administrator and the `email` value equals `MAIL_ADMIN_ADDRESS`, otherwise `0`
 + * @property-read   int $isDisabled     is `1` if the recipient is disabled and thus is not available for selection, otherwise `0`
 + * @property-read   int $originIsSystem     is `1` if the recipient has been delivered by a package, otherwise `0` (i.e. the recipient has been created in the ACP)
   */
 -class ContactRecipient extends DatabaseObject {
 -      /**
 -       * @inheritDoc
 -       */
 -      protected function handleData($data) {
 -              // dynamically set email address for the administrator
 -              if (!empty($data['isAdministrator'])) {
 -                      $data['email'] = MAIL_ADMIN_ADDRESS;
 -              }
 -              
 -              parent::handleData($data);
 -      }
 -      
 -      /**
 -       * @inheritDoc
 -       */
 -      public function __toString() {
 -              return $this->getName();
 -      }
 -      
 -      /**
 -       * @inheritDoc
 -       */
 -      public function __wakeup() {
 -              // update the administrator's email address on de-serialization, avoids outdated caches
 -              if (!empty($this->data['isAdministrator'])) {
 -                      $this->data['isAdministrator'] = MAIL_ADMIN_ADDRESS;
 -              }
 -      }
 -      
 -      /**
 -       * Returns the localized name of this recipient.
 -       * 
 -       * @since 5.3
 -       */
 -      public function getName(): string {
 -              return WCF::getLanguage()->get($this->name);
 -      }
 -      
 -      /**
 -       * Returns the localized email address of this recipient.
 -       * 
 -       * @since 5.3
 -       */
 -      public function getEmail(): string {
 -              return WCF::getLanguage()->get($this->email);
 -      }
 -      
 -      /**
 -       * Returns a localized Mailbox for this recipient.
 -       * 
 -       * @since 5.3
 -       */
 -      public function getMailbox(): Mailbox {
 -              return new Mailbox(
 -                      $this->getEmail(),
 -                      $this->getName()
 -              );
 -      }
 +class ContactRecipient extends DatabaseObject
 +{
 +    /**
 +     * @inheritDoc
 +     */
 +    protected function handleData($data)
 +    {
 +        // dynamically set email address for the administrator
 +        if (!empty($data['isAdministrator'])) {
 +            $data['email'] = MAIL_ADMIN_ADDRESS;
 +        }
 +
 +        parent::handleData($data);
 +    }
 +
 +    /**
 +     * @inheritDoc
 +     */
 +    public function __toString()
 +    {
-         return WCF::getLanguage()->get($this->name);
++        return $this->getName();
 +    }
 +
 +    /**
 +     * @inheritDoc
 +     */
 +    public function __wakeup()
 +    {
 +        // update the administrator's email address on de-serialization, avoids outdated caches
 +        if (!empty($this->data['isAdministrator'])) {
 +            $this->data['isAdministrator'] = MAIL_ADMIN_ADDRESS;
 +        }
 +    }
++
++    /**
++     * Returns the localized name of this recipient.
++     *
++     * @since 5.3
++     */
++    public function getName(): string
++    {
++        return WCF::getLanguage()->get($this->name);
++    }
++
++    /**
++     * Returns the localized email address of this recipient.
++     *
++     * @since 5.3
++     */
++    public function getEmail(): string
++    {
++        return WCF::getLanguage()->get($this->email);
++    }
++
++    /**
++     * Returns a localized Mailbox for this recipient.
++     *
++     * @since 5.3
++     */
++    public function getMailbox(): Mailbox
++    {
++        return new Mailbox(
++            $this->getEmail(),
++            $this->getName()
++        );
++    }
  }