Advertisement
MEXXIO

contact.php

May 3rd, 2022
1,107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.67 KB | None | 0 0
  1. <?php
  2.  
  3. use Chevereto\Legacy\Classes\Login;
  4. use function Chevereto\Legacy\G\get_base_url;
  5. use function Chevereto\Legacy\G\get_client_ip;
  6. use function Chevereto\Legacy\G\get_input_auth_token;
  7. use Chevereto\Legacy\G\Handler;
  8. use function Chevereto\Legacy\G\include_theme_footer;
  9. use function Chevereto\Legacy\G\include_theme_header;
  10. use function Chevereto\Legacy\get_recaptcha_component;
  11. use function Chevereto\Legacy\getSetting;
  12. use function Chevereto\Legacy\getSettings;
  13. use function Chevereto\Legacy\recaptcha_check;
  14. use function Chevereto\Legacy\send_mail;
  15. use function Chevereto\Vars\post;
  16. use function Chevereto\Vars\request;
  17. use function Chevereto\Vars\server;
  18.  
  19. if (!defined('access') or !access) {
  20.     die('This file cannot be directly accessed.');
  21. } ?>
  22. <?php
  23. $is_error = false;
  24. $input_errors = [];
  25. $is_sent = false;
  26. $allowed_subjects = [
  27.     'general' => _s('General questions/comments'),
  28.     'dmca' => _s('DMCA complaint'),
  29. ];
  30. if (Handler::cond('is_captcha_needed') || (getSetting('recaptcha') && getSetting('force_recaptcha_contact_page'))) {
  31.     Handler::setCond('captcha_show', true);
  32.     Handler::setVar(...get_recaptcha_component());
  33. }
  34. if (post() !== []) {
  35.     if (!Handler::checkAuthToken(request()['auth_token'])) {
  36.         die(_s("Request denied"));
  37.     }
  38.     if (strlen(post()['name']) == 0) {
  39.         $input_errors['name'] = _s('Invalid name');
  40.     }
  41.     if (strlen(post()['message']) == 0) {
  42.         $input_errors['message'] = _s('Invalid message');
  43.     }
  44.     if (!array_key_exists(post()['subject'], $allowed_subjects)) {
  45.         $input_errors['subject'] = _s('Invalid subject');
  46.     }
  47.     if (!filter_var(post()['email'], FILTER_VALIDATE_EMAIL)) {
  48.         $input_errors['email'] = _s('Invalid email');
  49.     }
  50.     if (Handler::cond('captcha_show')) {
  51.         $captcha = recaptcha_check();
  52.         if (!$captcha->is_valid) {
  53.             $input_errors['recaptcha'] = _s('%s says you are a robot', 'reCAPTCHA');
  54.         }
  55.     }
  56.     if (count($input_errors) > 0) {
  57.         $is_error = true;
  58.     } else {
  59.         $email = trim(post()['email']);
  60.         $subject = getSettings()['website_name'] . ' contact form';
  61.         $name = post()['name'];
  62.         $send_mail = [
  63.             'to' => getSettings()['email_incoming_email'],
  64.             'from' => [getSettings()['email_from_email'], $name . ' (' . getSettings()['website_name'] . ' contact form)'],
  65.             'reply-to' => [$email]
  66.         ];
  67.         $body_arr = [ // Mail body array (easier to edit)
  68.             'Name' => $name,
  69.             'E-mail' => $email,
  70.             'User' => (Login::isLoggedUser() ? Login::getUser()['url'] : 'not user'),
  71.             'Subject' => post()['subject'] . "\n",
  72.             'Message' => strip_tags(post()['message']) . "\n",
  73.             'IP' => get_client_ip(),
  74.             'Browser' => server()['HTTP_USER_AGENT'] ?? 'n/a',
  75.             'URL' => get_base_url() . "\n"
  76.         ];
  77.         $body = '';
  78.         foreach ($body_arr as $k => $v) {
  79.             $body .= $k . ': ' . $v . "\n";
  80.         }
  81.  
  82.         send_mail($send_mail, $subject, $body);
  83.         $is_sent = true;
  84.     }
  85. }
  86. include_theme_header(); ?>
  87. <div class="content-width">
  88.     <div class="c24 center-box margin-top-20">
  89.         <div class="header default-margin-bottom">
  90.             <h1><?php echo $is_sent
  91.                 ? '<span class="fas fa-check-circle color-success margin-right-5"></span>' . _s('Message sent')
  92.                 : '<span class="fas fa-at margin-right-5"></span>' . _s('Contact'); ?></h1>
  93.         </div>
  94.         <form method="post" class="form-content">
  95.             <?php echo get_input_auth_token(); ?>
  96.             <p><?php echo $is_sent ? _s('Message sent. We will get in contact soon.') : _s('If you want to send a message fill the form below.'); ?></p>
  97.             <div class="input-label c8">
  98.                 <label for="name"><?php _se('Name'); ?></label>
  99.                 <input type="text" name="name" id="name" class="text-input" placeholder="<?php _se('Your name'); ?>" value="<?php if ($is_error) {
  100.                     echo Handler::var('safe_post')['name'];
  101.                 } ?>" required>
  102.                 <div class="input-warning red-warning"><?php echo $input_errors['name'] ?? ''; ?></div>
  103.             </div>
  104.             <div class="input-label c8">
  105.                 <label for="email"><?php _se('Email address'); ?></label>
  106.                 <input type="email" name="email" id="email" class="text-input" placeholder="<?php _se('Your email address'); ?>" value="<?php if ($is_error) {
  107.                     echo Handler::var('safe_post')['email'];
  108.                 } ?>" required>
  109.                 <div class="input-warning red-warning"><?php echo $input_errors['name'] ?? ''; ?></div>
  110.             </div>
  111.             <div class="input-label c8">
  112.                 <label for="subject"><?php _se('Subject'); ?></label>
  113.                 <select type="text" name="subject" id="subject" class="text-input">
  114.                     <?php
  115.                         $ask_for = Handler::var('safe_post') ? Handler::var('safe_post')['subject'] : '';
  116.                         foreach ($allowed_subjects as $k => $v) {
  117.                             ?>
  118.                     <option value="<?php echo $k; ?>"<?php if ($ask_for == $k) {
  119.                                 ?> selected<?php
  120.                             } ?>><?php echo $v; ?></option>
  121.                     <?php
  122.                         }
  123.                     ?>
  124.                 </select>
  125.                 <div class="input-warning red-warning"><?php echo $input_errors['subject'] ?? ''; ?></div>
  126.             </div>
  127.             <div class="input-label c12">
  128.                 <label for="message"><?php _se('Message'); ?></label>
  129.                 <textarea name="message" id="message" class="text-input r3" required><?php if ($is_error) {
  130.                         echo Handler::var('safe_post')['message'];
  131.                     } ?></textarea>
  132.                 <div class="input-warning red-warning"><?php echo $input_errors['message'] ?? ''; ?></div>
  133.             </div>
  134.             <?php if (Handler::cond('captcha_show')) {
  135.                         ?>
  136.             <?php if (Handler::var('recaptcha_html')) {
  137.                             ?>
  138.             <div class="input-label">
  139.                 <label for="recaptcha_response_field">reCAPTCHA</label>
  140.                 <?php echo Handler::var('recaptcha_html'); ?>
  141.             </div>
  142.             <?php
  143.                         } ?>
  144.             <div class="input-below red-warning"><?php echo $input_errors['recaptcha'] ?? ''; ?></div>
  145.             <?php
  146.                     } ?>
  147.             <div class="btn-container">
  148.                 <button class="btn btn-input default" type="submit"><span class="btn-icon fas fa-check-circle"></span><span class="btn-text"><?php _se('Send'); ?></span></button></span>
  149.             </div>
  150.         </form>
  151.     </div>
  152. </div>
  153. <?php if (post() and $is_error) {
  154.                         ?>
  155. <script>
  156. $(function() {
  157.     PF.fn.growl.call("<?php echo $error ? $error : _s('Check the errors in the form to continue.'); ?>");
  158. });
  159. </script>
  160. <?php
  161.                     } ?>
  162. <?php include_theme_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement