Passed
Pull Request — release-2.1 (#5647)
by Mathias
04:55
created

DialogUnsubscribe()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 19
rs 9.9332
1
<?php
2
3
/**
4
 * This file has the important job of taking care of help messages and the help center.
5
 *
6
 * Simple Machines Forum (SMF)
7
 *
8
 * @package SMF
9
 * @author Simple Machines http://www.simplemachines.org
10
 * @copyright 2019 Simple Machines and individual contributors
11
 * @license http://www.simplemachines.org/about/smf/license.php BSD
12
 *
13
 * @version 2.1 RC2
14
 */
15
16
if (!defined('SMF'))
17
	die('No direct access...');
18
19
/**
20
 * Redirect to the user help ;).
21
 * It loads information needed for the help section.
22
 * It is accessed by ?action=help.
23
 *
24
 * @uses Help template and Manual language file.
25
 */
26
function DialogUnsubscribe()
27
{
28
	global $context;
29
	
30
	$context['unsubscribe_token_req'] = !empty($_REQUEST['token']) ? $_REQUEST['token'] : '';
31
	loadTemplate('Unsubscribe');
32
	loadLanguage('Unsubscribe');
33
	
34
	$subActions = array(
35
		'index' => 'DialogUnsubscribeIndex',
36
	);
37
38
	// CRUD $subActions as needed.
39
	call_integration_hook('integrate_unsubscribe', array(&$subActions));
40
41
	createToken('unsubscribe');
42
43
	$sa = isset($_GET['sa'], $subActions[$_GET['sa']]) ? $_GET['sa'] : 'index';
44
	call_helper($subActions[$sa]);
45
}
46
47
/**
48
 * Redirect to the user help ;).
49
 * It loads information needed for the help section.
50
 * It is accessed by ?action=help.
51
 *
52
 * @uses Help template and Manual language file.
53
 */
54
function DialogUnsubscribeIndex()
55
{
56
	global $txt, $context, $smcFunc, $sourcedir, $scripturl, $modSettings;
57
58
	if (empty($_GET['token']))
59
		return;
60
61
	$token = $_GET['token'];
62
63
	$memID = null;
64
65
	$request = $smcFunc['db_query']('','
66
		SELECT id_member
67
		FROM {db_prefix}themes
68
		WHERE variable = {string:token_name}
69
			AND value = {string:token}',
70
		array(
71
			'token_name' => 'unsubscribe_token',
72
			'token' => $token,
73
		)
74
	);
75
76
	while ($row = $smcFunc['db_fetch_assoc']($request))
77
			$memID = $row['id_member'];
78
79
	if (empty($memID))
80
		return;
81
82
	call_integration_hook('integrate_unsubscribe_index', array(&$subActions));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $subActions seems to be never defined.
Loading history...
83
}
84
85
/**
86
 * Deletes notification preference
87
 *
88
 * @param int $memID The user whose preference you're setting
89
 * @param array $prefs The preferences to delete
90
 */
91
function unsubscribeMail($memID)
92
{
93
	global $smcFunc;
94
95
	if (empty($memID))
96
		return;
97
	
98
	$skipPref = array('alert_timeout');
99
100
	$smcFunc['db_query']('', '
101
		UPDATE {db_prefix}user_alerts_prefs
102
		SET alert_value - 2
103
		WHERE id_member = {int:member}
104
			AND alert_pref NOT IN ({array_string:skipPref})
105
			AND (2 & alert_value) = 2',
106
		array(
107
			'member' => $memID,
108
			'skipPref' => $skipPref,
109
		)
110
	);
111
}
112
113
?>