commentsubmit.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. $post_id = $_POST["post_id"];
  3. $return_url = $_POST["return_url"];
  4. // Slug
  5. function seourl($string) {
  6. //Lower case everything
  7. $string = strtolower($string);
  8. //Make alphanumeric (removes all other characters)
  9. $string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
  10. //Clean up multiple dashes or whitespaces
  11. $string = preg_replace("/[\s-]+/", " ", $string);
  12. //Convert whitespaces and underscore to dash
  13. $string = preg_replace("/[\s_]/", "-", $string);
  14. return $string;
  15. }
  16. // if the url field is empty
  17. if(isset($_POST['url']) && $_POST['url'] == '') {
  18. // Check for empty fields
  19. if(empty($_POST['name']) ||
  20. empty($_POST['comment']) ||
  21. empty($_POST['email']) ||
  22. !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)
  23. )
  24. {
  25. // Rediret to current post
  26. header( "Location: {$return_url}");
  27. } else {
  28. $DATE_FORMAT = "Y-m-d H:i:s";
  29. $publish = date($DATE_FORMAT);
  30. $name = strip_tags(utf8_decode(utf8_encode($_POST['name'])));
  31. $link = strip_tags(htmlspecialchars($_POST['link']));
  32. $email_address = strip_tags(htmlspecialchars($_POST['email']));
  33. $comment = utf8_decode($_POST['comment']);
  34. // article
  35. $postID = str_replace('/','',$post_id);
  36. // web-site
  37. if (!empty($link)) {
  38. $web = "Web: {$link}";
  39. } else {
  40. $web = NULL;
  41. }
  42. //slug
  43. $nslug = seourl($name);
  44. $fslug = date("Ymd-H:i:s");
  45. $slug = "$nslug-$fslug";
  46. // Create the email and send the message
  47. // Add your email address
  48. $local_address = "heckyel@riseup.net";
  49. $recipients = array(
  50. $local_address,
  51. $email_address,
  52. // more emails
  53. );
  54. $to = implode(',', $recipients);
  55. $email_subject = <<<EOT
  56. [conocimientoslibres.tuxfamily.org] Mensaje de {$name}
  57. EOT;
  58. $email_body = <<<EOT
  59. Nuevo comentario del formulario de conocimientoslibres.tuxfamily.org
  60. Aqui estan los detalles:\n
  61. post_id: {$postID}
  62. Author: {$name}
  63. Date: {$publish}
  64. Email: {$email_address}
  65. Slug: {$slug}
  66. {$web}\n
  67. {$comment}\n\n
  68. ¿Usted no ha escrito este comentario?
  69. Responde este mensaje para eliminar el comentario.
  70. EOT;
  71. $headers = "From: noreply@conocimientoslibres.tuxfamily.org\n"; // Using something like noreply@yourdomain.com.
  72. $headers .= "Reply-To: $local_address";
  73. mail($to,$email_subject,utf8_decode($email_body),$headers);
  74. // Rediret to current post
  75. header("Refresh: 10; URL={$return_url}");
  76. printf('Hurra! %s su comentario se envió correctamente,
  77. volviendo a la web en 10 segundos...', $name);
  78. }
  79. } else {
  80. // woow!
  81. header("Refresh: 10; URL={$return_url}");
  82. printf('Hurra! %s su comentario se envió correctamente,
  83. volviendo a la web en 10 segundos...', $name);
  84. }