nieuws: prefer full names of comment authors
[minimedit.git] / contact.php
index c55ec0c033081af57341d891810722feb10aa547..b50537517d7b68952f50922a53c244b7763e8e91 100644 (file)
@@ -1,8 +1,9 @@
 <?php
 $error = NULL;
 if ($_POST) {
-       if (!empty($User)) {
-               $_REQUEST['login'] = $User['name'];
+       global $User;
+       if ($User) {
+               $_REQUEST['login'] = $User->login;
        }
        $error = mailform($_REQUEST);
        if (!empty($error)) {
@@ -13,7 +14,8 @@ if ($_POST) {
 function mailform($input = [])
 {
        $source = empty($input['subject']) ? 'reactie' : $input['subject'];
-       $rcpt = 'info@'.$_SERVER['HTTP_HOST'];
+       $domain = preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
+       $rcpt = "info@$domain";
        $subject = "Formulier {$_SERVER['HTTP_HOST']}: $source";
 
        if (!$input) {
@@ -21,6 +23,14 @@ function mailform($input = [])
        }
 
 switch ($source) {
+       case 'melding':
+               if (empty($input['login'])) {
+                       return "Inloggen is verplicht om een melding te plaatsen.";
+               }
+               if (empty($input['body'])) {
+                       return "Geen bericht opgegeven.";
+               }
+               break;
        case 'bbq':
                if (empty($input['naam']) or empty($input['huis'])) {
                        return 'De bedoeling is juist dat je opgeeft wie er komt.';
@@ -37,7 +47,7 @@ switch ($source) {
 }
 
        $reply = preg_match('/\A\w+@\w+\.[a-z]+\z/', @$input['email'])
-               ? $input['email'] : 'noreply@'.$_SERVER['HTTP_HOST'];
+               ? $input['email'] : "noreply@$domain";
        $header = "From: $reply";
 
        foreach (array(
@@ -49,7 +59,9 @@ switch ($source) {
        }
 
        $origin = $_SERVER['REMOTE_ADDR'];
-       $origin .= sprintf(' (%s)', gethostbyaddr($origin));
+       if ($resolved = @gethostbyaddr($origin) and $resolved !== $origin) {
+               $origin .= sprintf(' (%s)', gethostbyaddr($origin));
+       }
        $body = "Ingevuld vanaf $origin:\r\n\r\n";
 
        foreach ($input as $k => $v) {
@@ -67,6 +79,9 @@ switch ($source) {
        case 'bbq':
                print "<p>Bedankt voor je deelname. Tot ziens!</p>";
                break;
+       case 'melding':
+               print "<p>Bedankt voor de melding. Na goedkeuring zal het hier geplaatst worden.</p>";
+               break;
        default:
                print '<p>Bedankt voor uw reactie!</p>';
        }