Add tmp subscribe script for News Actionnaires N3
This commit is contained in:
parent
a7d9a1e856
commit
dfa3ead82f
1 changed files with 206 additions and 0 deletions
206
subscribe.php
Normal file
206
subscribe.php
Normal file
|
|
@ -0,0 +1,206 @@
|
|||
<?php
|
||||
|
||||
use LDC\LDCCRM\CrmApiV2;
|
||||
use LDC\LDCCRM\Exceptions\ApiErrorException;
|
||||
use LDC\LDCCRM\Exceptions\CrmException;
|
||||
use LDC\LDCCRM\Exceptions\ValidationException;
|
||||
use LDC\LDCCRM\Models\SingleOptin;
|
||||
|
||||
require_once(__DIR__ . '/wp-load.php');
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$callOK = false;
|
||||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
if (isset($_GET['hashcode']) and !empty($_GET['hashcode'])) {
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
$hashcode = sanitize_text_field($_GET['hashcode']);
|
||||
|
||||
$user = $wpdb->get_row(
|
||||
sprintf(
|
||||
"SELECT * FROM news_optins WHERE hashcode = '%s'",
|
||||
$hashcode
|
||||
)
|
||||
);
|
||||
|
||||
if (!is_null($user) and is_null($user->optin_validation)) {
|
||||
// * Initialise CRM API
|
||||
new CrmApiV2(CRM_ENDPOINT, CRM_TOKEN, CRM_PASSWORD);
|
||||
// Seul single optin est géré
|
||||
try {
|
||||
SingleOptin::setStatus($user->email, true);
|
||||
$wpdb->update(
|
||||
'news_optins',
|
||||
['optin_validation' => date("Y-m-d H:i:s")],
|
||||
['id' => $user->id]
|
||||
);
|
||||
$callOK = true;
|
||||
} catch (ValidationException | CrmException | ApiErrorException $e) {
|
||||
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log,Squiz.PHP.DiscouragedFunctions.Found
|
||||
var_dump($e);
|
||||
exit;
|
||||
error_log(sprintf(
|
||||
'ERROR CRM API : %s - %s | hashcode : %s',
|
||||
(get_class($e) === CrmException::class ? $e->getMessage() : get_class($e) === ValidationException::class ? $e->getMessage() : $e->getApiError()->label),
|
||||
$e->getMessage(),
|
||||
$hashcode
|
||||
));
|
||||
}
|
||||
} else if (!is_null($user) and !is_null($user->optin_validation)) {
|
||||
$callOK = true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<!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">
|
||||
<title>Inscription à la newsletter LDC</title>
|
||||
<style>
|
||||
html,
|
||||
body,
|
||||
::before,
|
||||
::after,
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
font-size: 30px;
|
||||
font-weight: normal;
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
.post-title {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
font-size: 1.33em;
|
||||
font-weight: 700;
|
||||
color: #e30613;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #000000;
|
||||
transition: color .5s;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #e30613;
|
||||
}
|
||||
|
||||
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="/content/themes/ldc/img/logo.png" alt="Logo de la marque LDC">
|
||||
</div>
|
||||
<div class="unsub--title">
|
||||
<h1 class="post-title">Inscription</h1>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
/**
|
||||
* On ne communique pas sur model not found
|
||||
* pour ne pas créer une page où on peut determiner
|
||||
* qui est inscrit dans la crm
|
||||
*/
|
||||
if ($callOK) { ?>
|
||||
<div class="unsub--content">
|
||||
<p>Vous êtes inscris à la newsletter LDC.</p>
|
||||
<p>Pour lire la lettre aux actionnaires № 3 <a href="https://www.ldc.fr/content/uploads/2023/12/LDC_LAA3_WEB.pdf">Cliquez ici</a></p>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<div class="unsub--content">
|
||||
<p>Une erreur est survenue.</p>
|
||||
<p>Veuillez réessayer ultérieurement.</p>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="unsub--footer">
|
||||
<span>Retrouvez-nous sur <a href="https://www.ldc.fr">ldc.fr</a> !</span>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue