case 'multiprune': if ($mybb->input['processed'] == 1) { if (($mybb->input['day'] || $mybb->input['month'] || $mybb->input['year']) && $mybb->input['set']) { $errors[] = $lang->multi_selected_dates; } $day = intval($mybb->input['day']); $month = intval($mybb->input['month']); $year = intval($mybb->input['year']); // Selected a date - check if the date the user entered is valid if ($mybb->input['day'] || $mybb->input['month'] || $mybb->input['year']) { // Is the date sort of valid? if ($day < 1 || $day > 31 || $month < 1 || $month > 12 || $month == 2 && $day > 29) { $errors[] = $lang->incorrect_date; } // Check the month $months = get_bdays($year); if ($day > $months[$month] - 1) { $errors[] = $lang->incorrect_date; } // Check the year if ($year != 0 && $year < date("Y") - 100 || $year > date("Y")) { $errors[] = $lang->incorrect_date; } if (!$errors) { // No errors, so let's continue and set the date to delete from $date = mktime(date('H'), date('i'), date('s'), $month, $day, $year); // Generate a unix time stamp } } elseif ($mybb->input['set'] > 0) { // Set options // For this purpose, 1 month = 31 days
/** * Verifies if a birthday is valid or not. * * @return boolean True when valid, false when invalid. */ function verify_birthday() { global $mybb; $user =& $this->data; $birthday =& $user['birthday']; if (!is_array($birthday)) { return true; } // Sanitize any input we have $birthday['day'] = (int) $birthday['day']; $birthday['month'] = (int) $birthday['month']; $birthday['year'] = (int) $birthday['year']; // Error if a day and month exists, and the birthday day and range is not in range if ($birthday['day'] != 0 || $birthday['month'] != 0) { if ($birthday['day'] < 1 || $birthday['day'] > 31 || $birthday['month'] < 1 || $birthday['month'] > 12 || $birthday['month'] == 2 && $birthday['day'] > 29) { $this->set_error("invalid_birthday"); return false; } } // Check if the day actually exists. $months = get_bdays($birthday['year']); if ($birthday['month'] != 0 && $birthday['day'] > $months[$birthday['month'] - 1]) { $this->set_error("invalid_birthday"); return false; } // Error if a year exists and the year is out of range if ($birthday['year'] != 0 && $birthday['year'] < date("Y") - 100 || $birthday['year'] > date("Y")) { $this->set_error("invalid_birthday"); return false; } else { if ($birthday['year'] == date("Y")) { // Error if birth date is in future if ($birthday['month'] > date("m") || $birthday['month'] == date("m") && $birthday['day'] > date("d")) { $this->set_error("invalid_birthday"); return false; } } } // Error if COPPA is on, and the user hasn't verified their age / under 13 if ($mybb->settings['coppa'] == "enabled" && ($birthday['year'] == 0 || !$birthday['year'])) { $this->set_error("invalid_birthday_coppa"); return false; } elseif ($mybb->settings['coppa'] == "deny" && $birthday['year'] > date("Y") - 13 && !is_moderator()) { $this->set_error("invalid_birthday_coppa2"); return false; } // Make the user's birthday field if ($birthday['year'] != 0) { // If the year is specified, put together a d-m-y string $user['bday'] = $birthday['day'] . "-" . $birthday['month'] . "-" . $birthday['year']; } elseif ($birthday['day'] && $birthday['month']) { // If only a day and month are specified, put together a d-m string $user['bday'] = $birthday['day'] . "-" . $birthday['month'] . "-"; } else { // No field is specified, so return an empty string for an unknown birthday $user['bday'] = ''; } return true; }
$mybb->input['bday2'] = $mybb->get_input('bday2', MyBB::INPUT_INT); $bdaymonthsel = array(); foreach (range(1, 12) as $number) { $bdaymonthsel[$number] = ''; } $bdaymonthsel[$mybb->input['bday2']] = "selected=\"selected\""; $mybb->input['bday3'] = $mybb->get_input('bday3', MyBB::INPUT_INT); if ($mybb->input['bday3'] == 0) { $mybb->input['bday3'] = ''; } // Is COPPA checking enabled? if ($mybb->settings['coppa'] != "disabled" && !isset($mybb->input['step'])) { // Just selected DOB, we check if ($mybb->input['bday1'] && $mybb->input['bday2'] && $mybb->input['bday3']) { my_unsetcookie("coppauser"); $months = get_bdays($mybb->input['bday3']); if ($mybb->input['bday2'] < 1 || $mybb->input['bday2'] > 12 || $mybb->input['bday3'] < date("Y") - 100 || $mybb->input['bday3'] > date("Y") || $mybb->input['bday1'] > $months[$mybb->input['bday2'] - 1]) { error($lang->error_invalid_birthday); } $bdaytime = @mktime(0, 0, 0, $mybb->input['bday2'], $mybb->input['bday1'], $mybb->input['bday3']); // Store DOB in cookie so we can save it with the registration my_setcookie("coppadob", "{$mybb->input['bday1']}-{$mybb->input['bday2']}-{$mybb->input['bday3']}", -1); // User is <= 13, we mark as a coppa user if ($bdaytime >= mktime(0, 0, 0, my_date('n'), my_date('d'), my_date('Y') - 13)) { my_setcookie("coppauser", 1, -0); $under_thirteen = true; } $mybb->request_method = ""; } else { $plugins->run_hooks("member_register_coppa"); my_unsetcookie("coppauser");
/** * Workaround for date limitation in PHP to establish the day of a birthday (Provided by meme) * * @param int The month of the birthday * @param int The day of the birthday * @param int The year of the bithday * @return int The numeric day of the week for the birthday */ function get_weekday($month, $day, $year) { $h = 4; for ($i = 1969; $i >= $year; $i--) { $j = get_bdays($i); for ($k = 11; $k >= 0; $k--) { $l = $k + 1; for ($m = $j[$k]; $m >= 1; $m--) { $h--; if ($i == $year && $l == $month && $m == $day) { return $h; } if ($h == 0) { $h = 7; } } } } }