aboutsummaryrefslogtreecommitdiffstats
path: root/content/vendor/form-comments/commentsubmit.php
blob: d2be0e0d9a445bb75f3c06d993fb71602b2e3b39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php

$post_id = $_POST["post_id"];
$return_url = $_POST["return_url"];

// Slug
function seourl($string) {
    //Lower case everything
    $string = strtolower($string);
    //Make alphanumeric (removes all other characters)
    $string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
    //Clean up multiple dashes or whitespaces
    $string = preg_replace("/[\s-]+/", " ", $string);
    //Convert whitespaces and underscore to dash
    $string = preg_replace("/[\s_]/", "-", $string);
    return $string;
}

// if the url field is empty
if(isset($_POST['url']) && $_POST['url'] == '') {
    // Check for empty fields
    if(empty($_POST['name'])    ||
       empty($_POST['comment']) ||
       empty($_POST['email'])   ||
       !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)
    )
    {
        // Rediret to current post
        header( "Location: {$return_url}");
    } else {

        $DATE_FORMAT = "Y-m-d H:i:s";
        $publish = date($DATE_FORMAT);

        $name = strip_tags(utf8_decode(utf8_encode($_POST['name'])));
        $link = strip_tags(htmlspecialchars($_POST['link']));
        $email_address = strip_tags(htmlspecialchars($_POST['email']));
        $comment = utf8_decode($_POST['comment']);

        // article
        $postID = str_replace('/','',$post_id);

        // web-site
        if (!empty($link)) {
            $web = "Web: {$link}";
        } else {
            $web = NULL;
        }

        //slug
        $nslug = seourl($name);
        $fslug = date("Ymd-H:i:s");
        $slug = "$nslug-$fslug";

        // Create the email and send the message
        // Add your email address
        $local_address = "heckyel@riseup.net";
        $recipients = array(
            $local_address,
            $email_address,
            // more emails
        );
        $to = implode(',', $recipients);
        $email_subject = <<<EOT
[conocimientoslibres.tuxfamily.org] Mensaje de {$name}
EOT;

        $email_body = <<<EOT
Nuevo comentario del formulario de conocimientoslibres.tuxfamily.org
Aqui estan los detalles:\n
post_id: {$postID}
Author: {$name}
Date: {$publish}
Email: {$email_address}
Slug: {$slug}
{$web}\n
{$comment}\n\n
¿Usted no ha escrito este comentario?
Responde este mensaje para eliminar el comentario.
EOT;

        $headers = "From: noreply@conocimientoslibres.tuxfamily.org\n"; // Using something like noreply@yourdomain.com.
        $headers .= "Reply-To: $local_address";
        mail($to,$email_subject,utf8_decode($email_body),$headers);

        // Rediret to current post
        header("Refresh: 10; URL={$return_url}");
        printf('Hurra! %s su comentario se envió correctamente,
volviendo a la web en 10 segundos...', $name);
    }
} else {
    // woow!
    header("Refresh: 10; URL={$return_url}");
    printf('Hurra! %s su comentario se envió correctamente,
volviendo a la web en 10 segundos...', $name);
}