/**
* 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();
+ }
}
<?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()
++ );
++ }
}