add unsubscribe and view mail on the web buttons
This commit is contained in:
parent
8bdd63afe2
commit
f095954a33
20 changed files with 289 additions and 224 deletions
|
|
@ -1,24 +1,23 @@
|
|||
<?php
|
||||
|
||||
return array(
|
||||
"debug" => true,
|
||||
"panel" => array(
|
||||
"menu" => require __DIR__ . "/menu.php",
|
||||
"css" => "assets/css/panel.css"
|
||||
),
|
||||
"email" => [
|
||||
"transport" => [
|
||||
"type" => "smtp",
|
||||
"host" => "mail.infomaniak.com",
|
||||
"port" => 465,
|
||||
"auth" => true,
|
||||
"username" => "info@actuel-inactuel.fr",
|
||||
"password" => "v!Vr$#JH7quJ35"
|
||||
]
|
||||
return [
|
||||
'debug' => true,
|
||||
'panel' => [
|
||||
'menu' => require __DIR__ . '/menu.php',
|
||||
'css' => 'assets/css/panel.css',
|
||||
],
|
||||
'email' => [
|
||||
'transport' => [
|
||||
'type' => 'smtp',
|
||||
'host' => 'smtp.mailersend.net',
|
||||
'port' => 587,
|
||||
'auth' => true,
|
||||
'username' => 'MS_K9grTE@actuel-inactuel.fr',
|
||||
'password' => 'mssp.GJGywUh.z3m5jgrq71xldpyo.owybzs9',
|
||||
],
|
||||
"routes" => array(
|
||||
require __DIR__ . "/routes/virtual-category.php",
|
||||
require __DIR__ . "/routes/send-newsletter.php",
|
||||
require __DIR__ . "/routes/subscribe.php",
|
||||
)
|
||||
);
|
||||
],
|
||||
'routes' => [
|
||||
require __DIR__ . '/routes/virtual-category.php',
|
||||
require __DIR__ . '/routes/subscribe.php',
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -2,62 +2,62 @@
|
|||
|
||||
return [
|
||||
'site' => [
|
||||
'label' => 'Accueil',
|
||||
'label' => 'Accueil',
|
||||
'current' => function ($current) {
|
||||
$path = Kirby::instance()->request()->path()->toString();
|
||||
return Str::contains($path, 'site');
|
||||
}
|
||||
},
|
||||
],
|
||||
'texts' => [
|
||||
'icon' => 'pen',
|
||||
'label' => 'Textes',
|
||||
'link' => 'pages/textes',
|
||||
'icon' => 'pen',
|
||||
'label' => 'Textes',
|
||||
'link' => 'pages/textes',
|
||||
'current' => function ($current) {
|
||||
$path = Kirby::instance()->request()->path()->toString();
|
||||
return Str::contains($path, 'pages/textes');
|
||||
}
|
||||
},
|
||||
],
|
||||
'authors' => [
|
||||
'icon' => 'users',
|
||||
'label' => 'Auteurs',
|
||||
'link' => 'pages/auteurs',
|
||||
'icon' => 'users',
|
||||
'label' => 'Auteurs',
|
||||
'link' => 'pages/auteurs',
|
||||
'current' => function ($current) {
|
||||
$path = Kirby::instance()->request()->path()->toString();
|
||||
return Str::contains($path, 'pages/auteurs');
|
||||
}
|
||||
$path = Kirby::instance()->request()->path()->toString();
|
||||
return Str::contains($path, 'pages/auteurs');
|
||||
},
|
||||
],
|
||||
'-',
|
||||
'-',
|
||||
'infos' => [
|
||||
'icon' => 'question',
|
||||
'label' => 'À propos',
|
||||
'link' => 'pages/a-propos',
|
||||
'icon' => 'question',
|
||||
'label' => 'À propos',
|
||||
'link' => 'pages/a-propos',
|
||||
'current' => function ($current) {
|
||||
$path = Kirby::instance()->request()->path()->toString();
|
||||
return Str::contains($path, 'pages/a-propos');
|
||||
}
|
||||
},
|
||||
],
|
||||
'subscription' => [
|
||||
'icon' => 'email',
|
||||
'label' => 'Liste de diffusion',
|
||||
'link' => 'pages/inscription',
|
||||
'icon' => 'email',
|
||||
'label' => 'Liste de diffusion',
|
||||
'link' => 'pages/lettre',
|
||||
'current' => function ($current) {
|
||||
$path = Kirby::instance()->request()->path()->toString();
|
||||
return Str::contains($path, 'pages/liste-de-diffusion');
|
||||
}
|
||||
},
|
||||
],
|
||||
'-',
|
||||
'-',
|
||||
'users',
|
||||
'comments',
|
||||
'admin' => [
|
||||
'icon' => 'folder',
|
||||
'label' => 'Administration',
|
||||
'link' => 'pages/admin',
|
||||
'icon' => 'folder',
|
||||
'label' => 'Administration',
|
||||
'link' => 'pages/admin',
|
||||
'current' => function ($current) {
|
||||
$path = Kirby::instance()->request()->path()->toString();
|
||||
return Str::contains($path, 'pages/admin');
|
||||
}
|
||||
},
|
||||
],
|
||||
'-',
|
||||
'-',
|
||||
|
|
|
|||
|
|
@ -1,75 +0,0 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'pattern' => '/send-newsletter.json',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
$jsonRequest = file_get_contents("php://input");
|
||||
$data = json_decode($jsonRequest);
|
||||
|
||||
if (!$data || !isset($data->pageUri) || !isset($data->isTest)) {
|
||||
return json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Invalid request data. Required fields: pageUri, isTest.'
|
||||
]);
|
||||
}
|
||||
|
||||
$kirby = kirby();
|
||||
$emailPage = page('inscription')->childrenAndDrafts()->find($data->pageUri);
|
||||
|
||||
if (!$emailPage) {
|
||||
return json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'The specified page does not exist.'
|
||||
]);
|
||||
}
|
||||
|
||||
$recipients = $data->isTest
|
||||
? $kirby->users()->pluck('email', null, true)
|
||||
: page('inscription')->subscribers()->toStructure()->pluck('email', true, true);
|
||||
|
||||
if (empty($recipients)) {
|
||||
return json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'No recipients found.'
|
||||
]);
|
||||
}
|
||||
|
||||
$subject = $data->isTest
|
||||
? "[TEST] - " . $emailPage->title()->value()
|
||||
: $emailPage->title()->value();
|
||||
|
||||
$from = new \Kirby\Cms\User([
|
||||
'email' => 'info@actuel-inactuel.fr',
|
||||
'name' => 'actuel-inactuel',
|
||||
]);
|
||||
|
||||
try {
|
||||
foreach ($recipients as $recipient) {
|
||||
$kirby->email([
|
||||
'from' => $from,
|
||||
'to' => $recipient,
|
||||
'subject' => $subject,
|
||||
'template' => 'newsletter',
|
||||
'data' => [
|
||||
'body' => $emailPage->body()
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
if (!$data->isTest) {
|
||||
$emailPage->changeStatus('listed');
|
||||
}
|
||||
|
||||
return json_encode([
|
||||
'status' => 'success',
|
||||
'message' => 'Email(s) sent successfully.'
|
||||
]);
|
||||
} catch (Exception $error) {
|
||||
return json_encode([
|
||||
'status' => 'error',
|
||||
'message' => $error->getMessage() . " file " . $error->getFile() . " line " . $error->getLine()
|
||||
]);
|
||||
}
|
||||
}
|
||||
];
|
||||
|
|
@ -2,43 +2,42 @@
|
|||
|
||||
return [
|
||||
'pattern' => '/subscribe.json',
|
||||
'method' => 'POST',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
$jsonRequest = file_get_contents("php://input");
|
||||
$jsonRequest = file_get_contents('php://input');
|
||||
$email = Str::lower(json_decode($jsonRequest));
|
||||
|
||||
if (V::email($email)) {
|
||||
kirby()->impersonate('kirby');
|
||||
|
||||
$page = page("inscription");
|
||||
|
||||
$page = page('lettre');
|
||||
$subscribers = $page->subscribers()->yaml();
|
||||
|
||||
$emailExists = in_array(["email" => $email], $subscribers);
|
||||
$emailExists = in_array(['email' => $email], $subscribers);
|
||||
|
||||
if ($emailExists) {
|
||||
return [
|
||||
"status" => "error",
|
||||
"message" => "Cet email est déjà inscris."
|
||||
'status' => 'error',
|
||||
'message' => 'Cet email est déjà inscris.',
|
||||
];
|
||||
}
|
||||
|
||||
$newSubscriber = ["email" => $email];
|
||||
$newSubscriber = ['email' => $email];
|
||||
$subscribers[] = $newSubscriber;
|
||||
|
||||
|
||||
$page->update([
|
||||
'subscribers' => $subscribers
|
||||
'subscribers' => $subscribers,
|
||||
]);
|
||||
|
||||
return [
|
||||
"status" => "success",
|
||||
"message" => "Inscription réussie."
|
||||
'status' => 'success',
|
||||
'message' => 'lettre réussie.',
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
"status" => "error",
|
||||
"message" => "Email invalide."
|
||||
'status' => 'error',
|
||||
'message' => 'Email invalide.',
|
||||
];
|
||||
}
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue