initial commit
This commit is contained in:
85
inc/classes/inContact/AdminMenu.php
Normal file
85
inc/classes/inContact/AdminMenu.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace inContact;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Klasa Menus
|
||||
*
|
||||
* @link https://krzysztof-turek.com
|
||||
*
|
||||
* @package tylkofotografia.pl
|
||||
* @version 0.2
|
||||
*/
|
||||
class AdminMenu
|
||||
{
|
||||
|
||||
use Singleton;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->setupHooks();
|
||||
}
|
||||
|
||||
protected function setupHooks()
|
||||
{
|
||||
add_action('admin_menu', [$this, 'InContactAdminMenu']);
|
||||
}
|
||||
|
||||
public function InContactAdminMenu($id)
|
||||
{
|
||||
add_menu_page('ustawienia inContact', 'inContact', 'manage_options', 'wp-in-contact', array(
|
||||
$this,
|
||||
'InContactSettings'
|
||||
), 'dashicons-email', 100);
|
||||
}
|
||||
|
||||
public function InContactSettings()
|
||||
{
|
||||
$updated = isset($_POST['updated']) ? $_POST['updated'] : '';
|
||||
$incontactconfig = isset($_REQUEST['incontact-config']) ? $_REQUEST['incontact-config'] : '';
|
||||
if ($updated === 'true' || wp_verify_nonce($incontactconfig, 'incontact-update')) {
|
||||
update_option('incontact-site-key', $_POST['incontact-site-key']);
|
||||
update_option('incontact-secret-key', $_POST['incontact-secret-key']);
|
||||
update_option('incontact-target-mail', $_POST['incontact-target-mail']);
|
||||
?>
|
||||
|
||||
<div class="updated">
|
||||
<p>Ustawienia zostały zapisane!</p>
|
||||
</div> <?php
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h2><span class="dashicons dashicons-email"></span> InContact - Ustawienia</h2>
|
||||
<form method="POST">
|
||||
<input type="hidden" name="updated" value="true"/>
|
||||
<?php wp_nonce_field('incontact-update', 'incontact-config'); ?>
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th><label for="incontact-site-key">Klucz witryny</label></th>
|
||||
<td><input name="incontact-site-key" id="incontact-site-key" type="text"
|
||||
value="<?php echo get_option('incontact-site-key'); ?>" class="regular-text"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label for="incontact-secret-key">Tajny klucz</label></th>
|
||||
<td><input name="incontact-secret-key" id="incontact-secret-key" type="text"
|
||||
value="<?php echo get_option('incontact-secret-key'); ?>" class="regular-text"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label for="incontact-target-mail">Adresat (email)</label></th>
|
||||
<td><input name="incontact-target-mail" id="incontact-target-mail" type="text"
|
||||
value="<?php echo get_option('incontact-target-mail'); ?>" class="regular-text"/></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="submit">
|
||||
<input type="submit" name="submit" id="submit" class="button button-primary" value="Zapisz">
|
||||
</p>
|
||||
</form>
|
||||
</div> <?php
|
||||
|
||||
}
|
||||
}
|
||||
29
inc/classes/inContact/Enqueue.php
Normal file
29
inc/classes/inContact/Enqueue.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace inContact;
|
||||
|
||||
/**
|
||||
* Klasa Enqueue
|
||||
*
|
||||
* @link https://krzysztof-turek.com
|
||||
*
|
||||
* @package tylkofotografia.pl
|
||||
* @version 0.2
|
||||
*/
|
||||
|
||||
class Enqueue {
|
||||
|
||||
use Singleton;
|
||||
|
||||
function __construct() {
|
||||
add_action('wp_enqueue_scripts',[ $this, 'enqueueScripts']);
|
||||
}
|
||||
|
||||
public function enqueueScripts() {
|
||||
global $pluginDirUrl, $pluginPath;
|
||||
wp_register_style('ContactCss', $pluginDirUrl.'css/inContact.css', [], filemtime( $pluginPath . 'css/inContact.css'), 'all');
|
||||
|
||||
wp_enqueue_style('ContactCss');
|
||||
|
||||
}
|
||||
}
|
||||
23
inc/classes/inContact/Init.php
Normal file
23
inc/classes/inContact/Init.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace inContact;
|
||||
|
||||
/**
|
||||
Klasa Init
|
||||
|
||||
@link https://krzysztof-turek.com
|
||||
|
||||
@package tylkofotografia.pl
|
||||
@version 0.2
|
||||
*/
|
||||
class Init
|
||||
{
|
||||
use Singleton;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
Enqueue::getInstance();
|
||||
AdminMenu::getInstance();
|
||||
Shortcode::getInstance();
|
||||
}
|
||||
}
|
||||
252
inc/classes/inContact/Shortcode.php
Normal file
252
inc/classes/inContact/Shortcode.php
Normal file
@@ -0,0 +1,252 @@
|
||||
<?php
|
||||
|
||||
namespace inContact;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Klasa Menus
|
||||
*
|
||||
* @link https://krzysztof-turek.com
|
||||
*
|
||||
* @package tylkofotografia.pl
|
||||
* @version 0.2
|
||||
*/
|
||||
class Shortcode
|
||||
{
|
||||
|
||||
use Singleton;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->addShortcode();
|
||||
}
|
||||
|
||||
protected function addShortcode()
|
||||
{
|
||||
add_shortcode('in-contact', array(
|
||||
$this,
|
||||
'inContact'
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
public function inContact($atts)
|
||||
{
|
||||
$em_name = null;
|
||||
$em_mail = null;
|
||||
$em_meeessage = null;
|
||||
$class = null;
|
||||
$html = null;
|
||||
$error = null;
|
||||
$body = null;
|
||||
$telefon = null;
|
||||
|
||||
if(!empty($_POST['website'])) die();
|
||||
$emmsg = (isset($_POST['emmsg']) ? $_POST['emmsg'] : '');
|
||||
if(isset($_POST['em_name'])) { $em_name = $_POST['em_name']; } else {
|
||||
$error .= 'Proszę wprowadź nazwę';
|
||||
}
|
||||
if(isset($_POST['em_mail'])) { $em_mail = $_POST['em_mail']; } else {
|
||||
$error .= 'Proszę wprowadź adres email';
|
||||
}
|
||||
if(isset($_POST['em_meeessage'])) { $em_meeessage = $_POST['em_meeessage']; } else {
|
||||
$error .= 'Proszę wprowadź tersć wiadmości';
|
||||
}
|
||||
|
||||
$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 = array(
|
||||
'Content-Type: text/html; charset=UTF-8',
|
||||
'From: ' . $em_name . ' <'.$em_mail.'>',
|
||||
'Reply-To: ' . $em_name . ' <'.$em_mail.'>'
|
||||
);
|
||||
|
||||
$gRecaptchaResponse = (isset($_POST['g-recaptcha-response']) ? $_POST['g-recaptcha-response'] : '');
|
||||
|
||||
$body = '<!DOCTYPE html>
|
||||
<html lang="pl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Nowa wiadomość z formularza kontaktowego</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f5f5f5;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.container {
|
||||
width: 90%;
|
||||
max-width: 600px;
|
||||
margin: 20px auto;
|
||||
background-color: #ffffff;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.header {
|
||||
background-color: #3a7bd5;
|
||||
color: #ffffff;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
.content {
|
||||
padding: 20px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.content h2 {
|
||||
margin-top: 0;
|
||||
}
|
||||
.footer {
|
||||
background-color: #f1f1f1;
|
||||
text-align: center;
|
||||
padding: 10px;
|
||||
font-size: 12px;
|
||||
color: #777777;
|
||||
}
|
||||
.button {
|
||||
display: inline-block;
|
||||
padding: 10px 20px;
|
||||
margin-top: 20px;
|
||||
background-color: #3a7bd5;
|
||||
color: #ffffff;
|
||||
text-decoration: none;
|
||||
border-radius: 5px;
|
||||
}
|
||||
.info {
|
||||
background-color: #f9f9f9;
|
||||
border-left: 4px solid #3a7bd5;
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
@media (max-width: 600px) {
|
||||
.container {
|
||||
width: 95%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>📩 Nowa wiadomość z formularza</h1>
|
||||
</div>
|
||||
<div class="content">
|
||||
<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>
|
||||
<p>{{WIADOMOSC}}</p>
|
||||
</div>
|
||||
|
||||
<a href="mailto:{{EMAIL}}" class="button">Odpowiedz na wiadomość</a>
|
||||
</div>
|
||||
<div class="footer">
|
||||
Ten e-mail został wygenerowany automatycznie przez formularz kontaktowy strony.<br>
|
||||
© {{ROK}} Twoja Firma. Wszelkie prawa zastrzeżone.
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
';
|
||||
$body = str_replace(
|
||||
['{{IMIE_NAZWISKO}}', '{{EMAIL}}', '{{TELEFON}}', '{{WIADOMOSC}}', '{{ROK}}'],
|
||||
[$em_name, $em_mail, $telefon, nl2br($em_meeessage), date("Y")],
|
||||
$body
|
||||
);
|
||||
|
||||
if (!empty($atts['class'])) {
|
||||
$class = $atts['class'];
|
||||
}
|
||||
if ($emmsg == 'true' && $error) {
|
||||
$html .= '<div class="alert alert-success" role="alert">' . $error . '</div>';
|
||||
|
||||
} elseif ($emmsg == 'true')
|
||||
{
|
||||
|
||||
$secret = get_option('incontact-secret-key');
|
||||
$response = null;
|
||||
/*$reCaptcha = new \ReCaptcha\ReCaptcha($secret);
|
||||
$resp = $reCaptcha->setExpectedHostname($_SERVER['SERVER_NAME'])->verify($gRecaptchaResponse, $_SERVER['REMOTE_ADDR']);
|
||||
if ($resp->isSuccess())
|
||||
{*/
|
||||
$mailResult = wp_mail($targetEmail, $em_name, $body, $headers);
|
||||
/*}
|
||||
else
|
||||
{
|
||||
$errors = $resp->getErrorCodes();
|
||||
}*/
|
||||
}
|
||||
|
||||
wp_enqueue_style('ContactCss', plugins_url( '/css/cform.css', __FILE__ ));
|
||||
|
||||
$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";
|
||||
$html .= '<div class="row justify-content-md-center">
|
||||
<div class="col-12">';
|
||||
if ($mailResult == 1)
|
||||
{
|
||||
$html .= '<div class="alert alert-success" role="alert">Wiadomość wysłana pomyślnie!</div>';
|
||||
}
|
||||
$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">Nazwa</label>
|
||||
<div class="col-12">
|
||||
<input type="text" class="form-control" id="name" name="em_name" placeholder="Imię i nazwisko" value="" required>
|
||||
<div class="invalid-feedback">
|
||||
Wprowadź nazwę!
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email" class="col-2 control-label">Email</label>
|
||||
<div class="col-12">
|
||||
<input type="email" class="form-control" id="email" name="em_mail" placeholder="twoj@email.com" value="" required>
|
||||
<div class="invalid-feedback">
|
||||
Podaj adres email!
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<p class="col-2 control-label">Wiadomość</p>
|
||||
<div class="col-12">
|
||||
<textarea class="form-control" rows="4" name="em_meeessage" required></textarea>
|
||||
<div class="invalid-feedback">
|
||||
Wprowadź treść wiadmości!
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-4">
|
||||
<div class="g-recaptcha" data-sitekey="' . get_option('incontact-site-key') . '"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-4">
|
||||
<button id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">
|
||||
<i class="fas fa-paper-plane"></i> Wyślij
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div></div>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
34
inc/classes/inContact/Singleton.php
Normal file
34
inc/classes/inContact/Singleton.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace inContact;
|
||||
/**
|
||||
* Cecha singleton
|
||||
*
|
||||
* @link https://krzysztof-turek.com
|
||||
*
|
||||
* @package tylkofotografia.pl
|
||||
* @version 0.2
|
||||
*/
|
||||
trait Singleton
|
||||
{
|
||||
private static $instances = [];
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
final protected function __clone()
|
||||
{
|
||||
}
|
||||
|
||||
public static function getInstance()
|
||||
{
|
||||
|
||||
$class = get_called_class();
|
||||
|
||||
if (!isset($instances[$class])) {
|
||||
$instances[$class] = new $class;
|
||||
}
|
||||
return $instances[$class];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user