diff --git a/src/mibew/libs/classes/Mibew/Controller/Chat/User/MailController.php b/src/mibew/libs/classes/Mibew/Controller/Chat/User/MailController.php new file mode 100644 index 00000000..34501976 --- /dev/null +++ b/src/mibew/libs/classes/Mibew/Controller/Chat/User/MailController.php @@ -0,0 +1,111 @@ + array(), + ); + + // Get and validate thread id + $thread_id = $request->request->get('thread'); + if (!preg_match("/^\d{1,10}$/", $thread_id)) { + throw new BadRequestException('Wrong value of "thread" argument.'); + } + + // Get token and verify it + $token = $request->request->get('token'); + if (!preg_match("/^\d{1,10}$/", $token)) { + throw new BadRequestException('Wrong value of "token" argument.'); + } + + $thread = Thread::load($thread_id, $token); + if (!$thread) { + throw new BadRequestException('Wrong thread.'); + } + + $email = $request->request->get('email'); + $page['email'] = $email; + $group = is_null($thread->groupId) ? null : group_by_id($thread->groupId); + if (!$email) { + $page['errors'][] = no_field('form.field.email'); + } elseif (!is_valid_email($email)) { + $page['errors'][] = wrong_field('form.field.email'); + } + + if (count($page['errors']) > 0) { + $page['formemail'] = $email; + $page['chat.thread.id'] = $thread->id; + $page['chat.thread.token'] = $thread->lastToken; + $page['level'] = ''; + $page = array_merge_recursive( + $page, + setup_logo($group) + ); + + return $this->render('mail', $page); + } + + $history = ''; + $last_id = -1; + $messages = $thread->getMessages(true, $last_id); + foreach ($messages as $msg) { + $history .= message_to_text($msg); + } + + $subject = getstring('mail.user.history.subject', true); + $body = getstring2( + 'mail.user.history.body', + array($thread->userName, + $history, + Settings::get('title'), + Settings::get('hosturl') + ), + true + ); + + mibew_mail($email, $mibew_mailbox, $subject, $body); + + $page = array_merge_recursive($page, setup_logo($group)); + + return $this->render('mailsent', $page); + } +} diff --git a/src/mibew/libs/routing.yml b/src/mibew/libs/routing.yml index fd85d722..b2201f03 100644 --- a/src/mibew/libs/routing.yml +++ b/src/mibew/libs/routing.yml @@ -19,6 +19,11 @@ chat_user: defaults: _controller: Mibew\Controller\Chat\User\ChatController::indexAction +chat_user_mail: + path: /chat/mail + defaults: + _controller: Mibew\Controller\Chat\User\MailController::indexAction + # Pages that are available for all users button: path: /b diff --git a/src/mibew/mail.php b/src/mibew/mail.php deleted file mode 100644 index 48b718cf..00000000 --- a/src/mibew/mail.php +++ /dev/null @@ -1,85 +0,0 @@ - array(), -); - -$token = verify_param("token", "/^\d{1,8}$/"); -$thread_id = verify_param("thread", "/^\d{1,8}$/"); - -$thread = Thread::load($thread_id, $token); -if (!$thread) { - die("wrong thread"); -} - -// Initialize chat style which is currently used in system -$chat_style = new ChatStyle(ChatStyle::getCurrentStyle()); - -$email = get_param('email'); -$page['email'] = $email; -$group = is_null($thread->groupId) ? null : group_by_id($thread->groupId); -if (!$email) { - $page['errors'][] = no_field("form.field.email"); -} elseif (!is_valid_email($email)) { - $page['errors'][] = wrong_field("form.field.email"); -} - -if (count($page['errors']) > 0) { - $page['formemail'] = $email; - $page['chat.thread.id'] = $thread->id; - $page['chat.thread.token'] = $thread->lastToken; - $page['level'] = ""; - $page = array_merge_recursive( - $page, - setup_logo($group) - ); - $chat_style->render('mail', $page); - exit; -} - -$history = ""; -$last_id = -1; -$messages = $thread->getMessages(true, $last_id); -foreach ($messages as $msg) { - $history .= message_to_text($msg); -} - -$subject = getstring("mail.user.history.subject", true); -$body = getstring2( - "mail.user.history.body", - array($thread->userName, - $history, - Settings::get('title'), - Settings::get('hosturl') - ), - true -); - -mibew_mail($email, $mibew_mailbox, $subject, $body); - -$page = array_merge_recursive($page, setup_logo($group)); - -$chat_style->render('mailsent', $page); diff --git a/src/mibew/styles/dialogs/default/templates_src/server_side/mail.handlebars b/src/mibew/styles/dialogs/default/templates_src/server_side/mail.handlebars index 52795c85..ef0b0581 100644 --- a/src/mibew/styles/dialogs/default/templates_src/server_side/mail.handlebars +++ b/src/mibew/styles/dialogs/default/templates_src/server_side/mail.handlebars @@ -8,7 +8,7 @@ {{/override}} {{#override "message"}} -