-
Notifications
You must be signed in to change notification settings - Fork 0
/
signature_restrictions.php
149 lines (126 loc) · 5.23 KB
/
signature_restrictions.php
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
function phorum_mod_signature_restrictions_cc_save_user($user)
{
global $PHORUM;
// We only need to handle checks if the signature is being saved.
if (!isset($user['signature'])) return $user;
// If another module returned an error already, then we won't run
// our checks right now.
if (isset($user["error"])) return $user;
$settings = $PHORUM['mod_signature_restrictions'];
$lang = $PHORUM['DATA']['LANG']['mod_signature_restrictions'];
$signature = $user['signature'];
// Trim the signature, while we are at it.
$signature = trim($signature);
// Put the trimmed info back in the data.
$user["signature"] = $PHORUM['DATA']['PROFILE']['signature'] = $signature;
// ----------------------------------------------------------------------
// Check maximum signature length.
// ----------------------------------------------------------------------
if (!empty($settings['max_length'])) {
if (strlen($signature) > $settings['max_length']) {
$str = $lang['max_length'];
$str = str_replace('%length%', $settings['max_length'], $str);
$user['error'] = $str;
}
}
// ----------------------------------------------------------------------
// Check maximum number of lines and maximum line length.
// ----------------------------------------------------------------------
// We only need to run this code if either max_lines or max_line_length
// is in use.
if (!isset($user['error']) && (
!empty($settings['max_lines']) ||
!empty($settings['max_line_length'])
)) {
// Split up the signature in separate lines.
$lines = explode("\n", $signature);
// Check if too many lines were used.
if (!empty($settings['max_lines']) &&
count($lines) > $settings['max_lines']) {
$str = $lang['max_lines'];
$str = str_replace('%lines%', $settings['max_lines'], $str);
$user['error'] = $str;
}
// Check if there are lines that are too long
elseif (!empty($settings['max_line_length']))
{
$nr = 0;
foreach ($lines as $line) {
$nr++;
if (strlen($line) > $settings['max_line_length']) {
$str = $lang['max_line_length'];
$str = str_replace(
array('%line_length%', '%line_nr%'),
array($settings['max_line_length'], $nr),
$str
);
$user['error'] = $str;
break;
}
}
}
}
// ----------------------------------------------------------------------
// Check denying of images and/or markup code
// ----------------------------------------------------------------------
// We only need to run this code if either deny_images or deny_markup
// is in use.
if (!isset($user['error']) && (
!empty($settings['deny_images']) ||
!empty($settings['deny_markup'])
)) {
// Format the signature.
include_once('./include/format_functions.php');
$formatted = phorum_format_messages(array(0 => array(
'author' => '',
'email' => '',
'subject' => '',
'body' => $user['signature']
)));
$signature = $formatted[0]['body'];
// Remove newlines for better matching.
$signature = str_replace("\n", "", $signature);
// Check for images in the signature.
if (!empty($settings['deny_images']) &&
preg_match('/<\s*img\s/', $signature)) {
$user['error'] = $lang['deny_images'];
}
// Check for markup code in the signature.
if (!isset($user['error']) && !empty($settings['deny_markup']))
{
$stripped = strip_tags($signature, '<br>');
if ($signature != $stripped)
{
// The user has used markup. Check if the users are allowed
// to use markup after being signed up for a certain amount
// of time.
if (!empty($settings['markup_user_registered_days']))
{
// Registration timestamp.
$tsregistered = $PHORUM["DATA"]["PROFILE"]["date_added"];
// Timestamp from which the user is allowed to use markup.
$tsvaliddate =
$tsregistered +
$settings['markup_user_registered_days'] * 60 * 60 * 24;
if (time() <= $tsvaliddate)
{
// Format the error to show user when they can start
// using markup.
$format = $PHORUM['short_date_time'];
$user['error'] = str_replace(
'%date%', phorum_date($format, $tsvaliddate),
$lang['markup_user_registered_days']
);
}
}
else
{
$user['error'] = $lang['deny_markup'];
}
}
}
}
return $user;
}
?>