-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathunsubscribe.php
More file actions
72 lines (62 loc) · 2.51 KB
/
unsubscribe.php
File metadata and controls
72 lines (62 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* One-click unsubscribe endpoint (RFC 8058).
*
* Handles both GET (browser click from email) and POST (one-click from mail client).
*
* @package local_bbcomailing
* @copyright 2026 David Herney @ BambuCo
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// No login required — recipients may not have Moodle accounts.
// phpcs:disable moodle.Files.RequireLogin.Missing
require_once('../../config.php');
$code = required_param('code', PARAM_ALPHANUMEXT);
$confirm = optional_param('confirm', 0, PARAM_BOOL);
// POST = RFC 8058 one-click unsubscribe from mail client.
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !$confirm) {
\local_bbcomailing\manager::unsubscribe($code);
http_response_code(200);
exit;
}
// GET = user clicked the link in the email — show confirmation page.
$PAGE->set_context(context_system::instance());
$PAGE->set_url(new \core\url('/local/bbcomailing/unsubscribe.php', ['code' => $code]));
$PAGE->set_title(get_string('unsubscribe', 'local_bbcomailing'));
$PAGE->set_heading(get_string('unsubscribe', 'local_bbcomailing'));
$PAGE->set_pagelayout('maintenance');
if ($confirm) {
$result = \local_bbcomailing\manager::unsubscribe($code);
echo $OUTPUT->header();
if ($result) {
echo $OUTPUT->notification(get_string('unsubscribe_success', 'local_bbcomailing'), 'success');
} else {
echo $OUTPUT->notification(get_string('unsubscribe_invalid', 'local_bbcomailing'), 'error');
}
echo $OUTPUT->footer();
exit;
}
// Show confirmation form.
echo $OUTPUT->header();
$confirmurl = new \core\url('/local/bbcomailing/unsubscribe.php', ['code' => $code, 'confirm' => 1]);
$cancelurl = new \core\url($CFG->wwwroot);
echo $OUTPUT->confirm(
get_string('unsubscribe_confirm_message', 'local_bbcomailing'),
$confirmurl,
$cancelurl
);
echo $OUTPUT->footer();