Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Actions/Admin/Reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ public function boardPerms(): void
[Group::ADMIN],
);

foreach ($groups_data as $group) {
foreach ($group_data as $group) {
$group->loadPermissions();
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/Actions/BoardIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,11 @@ public static function get(array $board_index_options): array

// Ensure the slug for the member has been set.
if (
!empty($row['id_member'])
&& ($row['real_name'] ?? '') !== ''
&& !isset(Slug::$known['member'][(int) $row['id_member']])
!empty($row_board['id_member'])
&& ($row_board['real_name'] ?? '') !== ''
&& !isset(Slug::$known['member'][(int) $row_board['id_member']])
) {
Slug::create($row['real_name'], 'member', (int) $row['id_member']);
Slug::create($row_board['real_name'], 'member', (int) $row_board['id_member']);
}

$parent = Board::$loaded[$row_board['id_parent']] ?? null;
Expand Down
1 change: 1 addition & 0 deletions Sources/Actions/Profile/Activate.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use SMF\Config;
use SMF\IntegrationHook;
use SMF\Logging;
use SMF\Mail;
use SMF\Profile;
use SMF\User;
use SMF\Utils;
Expand Down
118 changes: 57 additions & 61 deletions Sources/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,63 @@ public static function checkRemovePermission(self $poll): bool
return true;
}

/**
* Validates and sanitizes $_POST input for creating or editing a poll.
*/
public static function sanitizeInput(array &$errors): void
{
if (!isset($_POST['question']) || trim($_POST['question']) == '') {
$errors[] = 'no_question';
}

$_POST['options'] = empty($_POST['options']) ? [] : Utils::htmlTrimRecursive($_POST['options']);

// Get rid of empty ones.
foreach ($_POST['options'] as $k => $option) {
if ($option == '') {
unset($_POST['options'][$k], $_POST['options'][$k]);
}
}

// What are you going to vote between with one choice?!?
if (count($_POST['options']) < 2) {
$errors[] = 'poll_few';
} elseif (count($_POST['options']) > 256) {
$errors[] = 'poll_many';
}

if (!empty($errors)) {
return;
}

// Make sure these things are all sane.
$_POST['poll_max_votes'] = min(max((int) ($_POST['poll_max_votes'] ?? 1), 1), count($_POST['options'] ?? []));
$_POST['poll_expire'] = min(max((int) ($_POST['poll_expire'] ?? 0), 0), 9999);
$_POST['poll_hide'] = (int) ($_POST['poll_hide'] ?? 0);
$_POST['poll_change_vote'] = (int) !empty($_POST['poll_change_vote']);
$_POST['poll_guest_vote'] = (int) !empty($_POST['poll_guest_vote']);

// Make sure guests are actually allowed to vote generally.
if ($_POST['poll_guest_vote']) {
$_POST['poll_guest_vote'] = self::canGuestsVote();
}

// If the user tries to set the poll too far in advance, don't let them.
if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) {
ErrorHandler::fatalLang('poll_range_error', false);
}
// Don't allow them to select option 2 for hidden results if it's not time limited.
elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) {
$_POST['poll_hide'] = 1;
}

// Clean up the question and answers.
$_POST['question'] = Utils::htmlspecialchars($_POST['question']);
$_POST['question'] = Utils::truncate($_POST['question'], 255);
$_POST['question'] = preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $_POST['question']);
$_POST['options'] = Utils::htmlspecialcharsRecursive($_POST['options']);
}

/******************
* Internal methods
******************/
Expand Down Expand Up @@ -1361,65 +1418,4 @@ protected function getMostActive(int &$options): int

return (int) $most_active;
}

/*************************
* Internal static methods
*************************/

/**
* Validates and sanitizes $_POST input for creating or editing a poll.
*/
protected static function sanitizeInput(array &$errors): void
{
if (!isset($_POST['question']) || trim($_POST['question']) == '') {
$errors[] = 'no_question';
}

$_POST['options'] = empty($_POST['options']) ? [] : Utils::htmlTrimRecursive($_POST['options']);

// Get rid of empty ones.
foreach ($_POST['options'] as $k => $option) {
if ($option == '') {
unset($_POST['options'][$k], $_POST['options'][$k]);
}
}

// What are you going to vote between with one choice?!?
if (count($_POST['options']) < 2) {
$errors[] = 'poll_few';
} elseif (count($_POST['options']) > 256) {
$errors[] = 'poll_many';
}

if (!empty($errors)) {
return;
}

// Make sure these things are all sane.
$_POST['poll_max_votes'] = min(max((int) ($_POST['poll_max_votes'] ?? 1), 1), count($_POST['options'] ?? []));
$_POST['poll_expire'] = min(max((int) ($_POST['poll_expire'] ?? 0), 0), 9999);
$_POST['poll_hide'] = (int) ($_POST['poll_hide'] ?? 0);
$_POST['poll_change_vote'] = (int) !empty($_POST['poll_change_vote']);
$_POST['poll_guest_vote'] = (int) !empty($_POST['poll_guest_vote']);

// Make sure guests are actually allowed to vote generally.
if ($_POST['poll_guest_vote']) {
$_POST['poll_guest_vote'] = self::canGuestsVote();
}

// If the user tries to set the poll too far in advance, don't let them.
if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) {
ErrorHandler::fatalLang('poll_range_error', false);
}
// Don't allow them to select option 2 for hidden results if it's not time limited.
elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) {
$_POST['poll_hide'] = 1;
}

// Clean up the question and answers.
$_POST['question'] = Utils::htmlspecialchars($_POST['question']);
$_POST['question'] = Utils::truncate($_POST['question'], 255);
$_POST['question'] = preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $_POST['question']);
$_POST['options'] = Utils::htmlspecialcharsRecursive($_POST['options']);
}
}