Poprawki w strukturze html (komentarze, admin panel)

This commit is contained in:
2026-01-15 15:35:54 +01:00
parent 029e5fdec9
commit e13efb0fef
2 changed files with 224 additions and 136 deletions

View File

@@ -2,8 +2,6 @@
namespace inContact;
/**
* Klasa Menus
*
@@ -14,7 +12,6 @@ namespace inContact;
*/
class Shortcode
{
use Singleton;
function __construct()
@@ -22,53 +19,64 @@ class Shortcode
$this->addShortcode();
}
protected function addShortcode()
protected function addShortcode(): void
{
add_shortcode('in-contact', array(
$this,
'inContact'
));
add_shortcode("in-contact", [$this, "inContact"]);
}
public function inContact($atts)
{
$em_name = null;
$em_mail = null;
$em_message = null;
$class = null;
$html = null;
$error = null;
$body = null;
$telefon = null;
$mailResult = 0;
$form_submitted = ($_SERVER['REQUEST_METHOD'] === 'POST');
if(!empty($_POST['website'])) die();
if ($form_submitted) {
$emmsg = (isset($_POST['emmsg']) ? $_POST['emmsg'] : '');
if(!empty($_POST['em_name'])) { $em_name = $_POST['em_name']; } else {
$error .= 'Please enter your name </br>';
}
if(!empty($_POST['em_mail'])) { $em_mail = $_POST['em_mail']; } else {
$error .= 'Please enter your email address </br>';
}
if(!empty($_POST['em_message'])) { $em_message = $_POST['em_message']; } else {
$error .= 'Please enter your message </br>';
}
$targetEmail = 'To: Tylkofotografia <' .get_option('incontact-target-mail') .'>';
$em_name = null;
$em_mail = null;
$em_message = null;
$class = null;
$html = null;
$error = null;
$body = null;
$telefon = null;
$mailResult = 0;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=".get_bloginfo('charset')."" . "\r\n";
$headers .= "From: " . $em_name ." <".$em_mail.">" . "\r\n";
$headers = array(
'Content-Type: text/html; charset=UTF-8',
'From: ' . $em_name . ' <'.$em_mail.'>',
'Reply-To: ' . $em_name . ' <'.$em_mail.'>'
);
$body = '<!DOCTYPE html>
$form_submitted = $_SERVER["REQUEST_METHOD"] === "POST";
if (!empty($_POST["website"])) {
die();
}
if ($form_submitted) {
$emmsg = isset($_POST["emmsg"]) ? $_POST["emmsg"] : "";
if (!empty($_POST["em_name"])) {
$em_name = $_POST["em_name"];
} else {
$error .= "Please enter your name </br>";
}
if (!empty($_POST["em_mail"])) {
$em_mail = $_POST["em_mail"];
} else {
$error .= "Please enter your email address </br>";
}
if (!empty($_POST["em_message"])) {
$em_message = $_POST["em_message"];
} else {
$error .= "Please enter your message </br>";
}
$targetEmail =
"To: Tylkofotografia <" .
get_option("incontact-target-mail") .
">";
$mailResult = 0;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .=
"Content-type: text/html; charset=" .
get_bloginfo("charset") .
"" .
"\r\n";
$headers .= "From: " . $em_name . " <" . $em_mail . ">" . "\r\n";
$headers = [
"Content-Type: text/html; charset=UTF-8",
"From: " . $em_name . " <" . $em_mail . ">",
"Reply-To: " . $em_name . " <" . $em_mail . ">",
];
$body = '<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
@@ -140,7 +148,7 @@ class Shortcode
<h2>Dane kontaktowe</h2>
<p><strong>Imię i nazwisko:</strong> {{IMIE_NAZWISKO}}</p>
<p><strong>Email:</strong> {{EMAIL}}</p>
<div class="info">
<h3>📬 Treść wiadomości:</h3>
@@ -157,86 +165,117 @@ class Shortcode
</body>
</html>
';
$body = str_replace(
['{{IMIE_NAZWISKO}}', '{{EMAIL}}', '{{TELEFON}}', '{{WIADOMOSC}}', '{{ROK}}'],
[$em_name, $em_mail, $telefon, str_replace(array("\r\n", "\r", "\n"), "<br />", $em_message), date("Y")],
$body
) ;
$gRecaptchaResponse = (isset($_POST['g-recaptcha-response']) ? $_POST['g-recaptcha-response'] : '');
if (!empty($error)) {
$html .= '<div class="alert alert-success" role="alert">' . $error . '</div>';
$body = str_replace(
[
"{{IMIE_NAZWISKO}}",
"{{EMAIL}}",
"{{TELEFON}}",
"{{WIADOMOSC}}",
"{{ROK}}",
],
[
$em_name,
$em_mail,
$telefon,
str_replace(["\r\n", "\r", "\n"], "<br />", $em_message),
date("Y"),
],
$body,
);
$gRecaptchaResponse = isset($_POST["g-recaptcha-response"])
? $_POST["g-recaptcha-response"]
: "";
} elseif ($emmsg == 'true')
{
if (!empty($error)) {
$html .=
'<div class="alert alert-success" role="alert">' .
$error .
"</div>";
} elseif ($emmsg == "true") {
$secret = get_option("incontact-secret-key");
$response = null;
if (get_option("incontact-site-key") != "") {
$reCaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $reCaptcha
->setExpectedHostname($_SERVER["SERVER_NAME"])
->verify($gRecaptchaResponse, $_SERVER["REMOTE_ADDR"]);
if ($resp->isSuccess()) {
$canSend = true;
} else {
$errors = $resp->getErrorCodes();
}
} else {
$canSend = true;
}
$secret = get_option('incontact-secret-key');
$response = null;
if (get_option('incontact-site-key') != '')
{
$reCaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $reCaptcha->setExpectedHostname($_SERVER['SERVER_NAME'])->verify($gRecaptchaResponse, $_SERVER['REMOTE_ADDR']);
if ($resp->isSuccess())
{
$canSend = true;
if ($canSend) {
$mailResult = wp_mail(
$targetEmail,
$em_name,
$body,
$headers,
);
}
else
{
$errors = $resp->getErrorCodes();
}
} else {
$canSend = true;
}
if ($canSend) {
$mailResult = wp_mail($targetEmail, $em_name, $body, $headers);
}
}
}
wp_enqueue_style('ContactCss', plugins_url( '/css/cform.css', __FILE__ ));
wp_enqueue_style("ContactCss", plugins_url("/css/cform.css", __FILE__));
if (get_option('incontact-site-key') != '')
{
$html .= '<script src="https://www.google.com/recaptcha/api.js"></script>
if (get_option("incontact-site-key") != "") {
$html .=
'<script src="https://www.google.com/recaptcha/api.js"></script>
<script>
$(document).ready(function(){window.setTimeout(function(){$(".alert").fadeTo(500,0).slideUp(500,function(){$(this).remove()})},2e3)}),$(document).ready(function(){"use strict";window.addEventListener("load",function(){var t=document.getElementsByClassName("needs-validation");Array.prototype.filter.call(t,function(t){t.addEventListener("submit",function(e){!1===t.checkValidity()&&(e.preventDefault(),e.stopPropagation()),t.classList.add("was-validated")},!1)})},!1)})();
</script>'."\n";
</script>' . "\n";
}
$html .= '<div class="row justify-content-md-center">
$html .= '<div class="row justify-content-md-center">
<div class="col-12">';
if ($mailResult == 1)
{
$html .= '<div class="alert alert-success" role="alert">' . get_option('incontact-form-snd-ok') . '</div>';
if ($mailResult == 1) {
$html .=
'<div class="alert alert-success" role="alert">' .
get_option("incontact-form-snd-ok") .
"</div>";
}
$html .= '<div class="jumbotron"><form action="" class="needs-validation" novalidate method="post" id="demo-form">
$html .=
'<div class="jumbotron"><form action="" class="needs-validation" novalidate method="post" id="demo-form">
<input type="hidden" name="emmsg" value="true" />
<input type="text" id="website" name="website" />
<div class="jumbotron">
<div class="form-group">
<label for="name" class="col-2 control-label">' . get_option('incontact-form-name') . '</label>
<label for="name" class="col-2 control-label">' .
get_option("incontact-form-name") .
'</label>
<div class="col-12">
<input type="text" class="form-control" id="name" name="em_name" placeholder="' . get_option('incontact-form-ph-name') . '" value="" required>
<input type="text" class="form-control" id="name" name="em_name" placeholder="' .
get_option("incontact-form-ph-name") .
'" value="" required>
<div class="invalid-feedback">
Please enter your name!
</div>
</div>
</div>
<div class="form-group">
<label for="email" class="col-2 control-label">' . get_option('incontact-form-email') . '</label>
<label for="email" class="col-2 control-label">' .
get_option("incontact-form-email") .
'</label>
<div class="col-12">
<input type="email" class="form-control" id="email" name="em_mail" placeholder="' . get_option('incontact-form-ph-email') . '" value="" required>
<input type="email" class="form-control" id="email" name="em_mail" placeholder="' .
get_option("incontact-form-ph-email") .
'" value="" required>
<div class="invalid-feedback">
Please enter your email address!
</div>
</div>
</div>
<div class="form-group">
<p class="col-2 control-label">' . get_option('incontact-form-message') . '</p>
<p class="col-2 control-label">' .
get_option("incontact-form-message") .
'</p>
<div class="col-12">
<textarea class="form-control" rows="4" name="em_message" placeholder="' . get_option('incontact-form-ph-message') . '" required></textarea>
<textarea class="form-control" rows="4" name="em_message" placeholder="' .
get_option("incontact-form-ph-message") .
'" required></textarea>
<div class="invalid-feedback">
Please enter your message!
</div>
@@ -244,7 +283,9 @@ class Shortcode
</div>
<div class="form-group">
<div class="col-4">
<div class="g-recaptcha" data-sitekey="' . get_option('incontact-site-key') . '"></div>
<div class="g-recaptcha" data-sitekey="' .
get_option("incontact-site-key") .
'"></div>
</div>
</div>
<div class="form-group">
@@ -259,10 +300,7 @@ class Shortcode
</form>
</div>
</div></div>';
return $html;
}
}
}