Merge branch 'issue-10-unsubscribe' into 'develop'
Issue 10 unsubscribe !10 See merge request ldc-web/projets/espri-restauration!8
This commit is contained in:
commit
e5c6a60eec
1 changed files with 195 additions and 0 deletions
195
public/unsubscribe.php
Normal file
195
public/unsubscribe.php
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
<?php
|
||||
|
||||
require_once(__DIR__ . '/wp/wp-load.php');
|
||||
|
||||
use LDC\LDCCRM\CrmApiV4;
|
||||
use LDC\LDCCRM\Enums\ApiError;
|
||||
use LDC\LDCCRM\Exceptions\ApiErrorException;
|
||||
use LDC\LDCCRM\Exceptions\CrmException;
|
||||
use LDC\LDCCRM\Models\SingleOptin;
|
||||
|
||||
$callOK = false;
|
||||
$modelNotFound = false;
|
||||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
if (isset($_GET['hashcode']) and !empty($_GET['hashcode'])) {
|
||||
// * Initialise CRM API
|
||||
new CrmApiV4(CRM_ENDPOINT, CRM_TOKEN, CRM_PASSWORD);
|
||||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
$hashcode = htmlspecialchars($_GET['hashcode'], ENT_QUOTES);
|
||||
|
||||
try {
|
||||
if (SingleOptin::unsetStatusWithHashcode($hashcode)) {
|
||||
$callOK = true;
|
||||
} else {
|
||||
$modelNotFound = true;
|
||||
}
|
||||
} catch (ValidationException | CrmException | ApiErrorException $e) {
|
||||
if (get_class($e) === ApiErrorException::class and $e->getApiError()->equals(ApiError::modelNotFound)) {
|
||||
$modelNotFound = true;
|
||||
} else {
|
||||
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log,Squiz.PHP.DiscouragedFunctions.Found
|
||||
error_log(sprintf(
|
||||
'ERROR CRM API : %s - %s | hashcode : %s',
|
||||
(get_class($e) === CrmException::class ? $e->getMessage() : $e->getApiError()->label()),
|
||||
$e->getMessage(),
|
||||
$hashcode
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="shortcut icon" href="<?php bloginfo('template_url'); ?>/img/favicon.ico">
|
||||
<link rel="icon" type="image/gif" href="<?php bloginfo('template_url'); ?>/img/animated_favicon.gif">
|
||||
<title>Désinscription à la newsletter Espri Restauration</title>
|
||||
<style>
|
||||
@font-face {
|
||||
font-family: 'Glacial Indifference';
|
||||
src: url('/app/themes/espri-restauration-theme/fonts/glacial_indifference/GlacialIndifference-Regular.otf') format('opentype');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
html,
|
||||
body,
|
||||
::before,
|
||||
::after,
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: #f5ecde;
|
||||
font-family: 'Glacial Indifference', Arial, Helvetica, sans-serif;
|
||||
font-size: 30px;
|
||||
font-weight: normal;
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
.post-title {
|
||||
font-family: 'Amatic SC', Arial, Helvetica, sans-serif;
|
||||
font-size: 1.33em;
|
||||
font-weight: 700;
|
||||
color: #F8A326;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #000000;
|
||||
transition: color .5s;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #F8A326;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 1em 0;
|
||||
font-size: .8em;
|
||||
}
|
||||
|
||||
span {
|
||||
font-size: .6em;
|
||||
}
|
||||
|
||||
.wrapper-unsub {
|
||||
display: grid;
|
||||
grid-template-rows: min-content min-content auto min-content;
|
||||
justify-items: center;
|
||||
min-height: 100vh;
|
||||
padding: 10vw 4vw;
|
||||
}
|
||||
|
||||
.unsub--logo {
|
||||
width: 60%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.unsub--logo img {
|
||||
width: 100%;
|
||||
max-width: 300px;
|
||||
}
|
||||
|
||||
.unsub--title {
|
||||
margin: 4vw 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.unsub--footer {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media only screen and (min-width:768px) {
|
||||
.post-title {
|
||||
font-size: 2em;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
span {
|
||||
font-size: .8em;
|
||||
}
|
||||
|
||||
.wrapper-unsub {
|
||||
padding: 4vw 10vw;
|
||||
}
|
||||
}
|
||||
|
||||
@media only screen and (min-width:1024px) {
|
||||
.post-title {
|
||||
font-size: 2.33em;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
span {
|
||||
font-size: 1em;
|
||||
}
|
||||
}
|
||||
|
||||
@media only screen and (min-width:1440px) {}
|
||||
|
||||
@media only screen and (min-width:1920px) {}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="wrapper-unsub">
|
||||
<div class="unsub--logo">
|
||||
<img src='app/themes/espri-restauration-theme/img/logo.png' alt="Logo de la marque Espri Restauration">
|
||||
</div>
|
||||
<div class="unsub--title">
|
||||
<h1 class="post-title">Désinscription</h1>
|
||||
</div>
|
||||
|
||||
<div class="unsub--content">
|
||||
<?php if($callOK || $modelNotFound) : ?>
|
||||
<p>Vous êtes désinscrits de la newsletter Espri Restauration.</p>
|
||||
<p>En espérant vous revoir bientôt !</p>
|
||||
<?php else: ?>
|
||||
<p>Une erreur est survenue.</p>
|
||||
<p>Veuillez réessayer ultérieurement.</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="unsub--footer">
|
||||
<span>Retrouvez-nous sur <a href="https://www.espri-restauration.fr/">espri-restauration.fr</a> !</span>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue