. */ namespace Fisharebest\Webtrees; /** * Defined in session.php * * @global Tree $WT_TREE */ global $WT_TREE; use Fisharebest\Webtrees\Controller\PageController; use Fisharebest\Webtrees\Date\FrenchDate; use Fisharebest\Webtrees\Date\GregorianDate; use Fisharebest\Webtrees\Date\HijriDate; use Fisharebest\Webtrees\Date\JalaliDate; use Fisharebest\Webtrees\Date\JewishDate; use Fisharebest\Webtrees\Date\JulianDate; use Fisharebest\Webtrees\Functions\FunctionsDb; use Fisharebest\Webtrees\Functions\FunctionsPrint; define('WT_SCRIPT_NAME', 'calendar.php'); require './includes/session.php'; $CALENDAR_FORMAT = $WT_TREE->getPreference('CALENDAR_FORMAT'); $cal = Filter::get('cal', '@#D[A-Z ]+@'); $day = Filter::get('day', '\d\d?'); $month = Filter::get('month', '[A-Z]{3,5}'); $year = Filter::get('year', '\d{1,4}(?: B\.C\.)?|\d\d\d\d\/\d\d|\d+(-\d+|[?]+)?'); $view = Filter::get('view', 'day|month|year', 'day'); $filterev = Filter::get('filterev', '[_A-Z-]+', 'BIRT-MARR-DEAT'); $filterof = Filter::get('filterof', 'all|living|recent', 'all'); $filtersx = Filter::get('filtersx', '[MF]', ''); if ($cal . $day . $month . $year === '') { // No date specified? Use the most likely calendar $cal = I18N::defaultCalendar()->gedcomCalendarEscape(); } // Create a CalendarDate from the parameters // We cannot display new-style/old-style years, so convert to new style if (preg_match('/^(\d\d)\d\d\/(\d\d)$/', $year, $match)) { $year = $match[1] . $match[2]; } // advanced-year "year range" if (preg_match('/^(\d+)-(\d+)$/', $year, $match)) { if (strlen($match[1]) > strlen($match[2])) { $match[2] = substr($match[1], 0, strlen($match[1]) - strlen($match[2])) . $match[2]; } $ged_date = new Date("FROM {$cal} {$match[1]} TO {$cal} {$match[2]}"); $view = 'year'; } else { // advanced-year "decade/century wildcard" if (preg_match('/^(\d+)(\?+)$/', $year, $match)) { $y1 = $match[1] . str_replace('?', '0', $match[2]); $y2 = $match[1] . str_replace('?', '9', $match[2]); $ged_date = new Date("FROM {$cal} {$y1} TO {$cal} {$y2}"); $view = 'year'; } else { if ($year < 0) { $year = (-$year) . ' B.C.'; } // need BC to parse date $ged_date = new Date("{$cal} {$day} {$month} {$year}"); $year = $ged_date->minimumDate()->y; // need negative year for year entry field. } } $cal_date = $ged_date->minimumDate(); // Fill in any missing bits with todays date $today = $cal_date->today(); if ($cal_date->d === 0) { $cal_date->d = $today->d; } if ($cal_date->m === 0) { $cal_date->m = $today->m; } if ($cal_date->y === 0) { $cal_date->y = $today->y; } $cal_date->setJdFromYmd(); if ($year === 0) { $year = $cal_date->y; } // Extract values from date $days_in_month = $cal_date->daysInMonth(); $days_in_week = $cal_date->daysInWeek(); $cal_month = $cal_date->format('%O'); $today_month = $today->format('%O'); // Invalid dates? Go to monthly view, where they'll be found. if ($cal_date->d > $days_in_month && $view === 'day') { $view = 'month'; } // All further uses of $cal are to generate URLs $cal = rawurlencode($cal); $controller = new PageController; $controller->setPageTitle(I18N::translate('Anniversary calendar')); switch ($view) { case 'day': $controller->setPageTitle(I18N::translate('On this day…') . ' ' . $ged_date->display(false)); break; case 'month': $controller->setPageTitle(I18N::translate('In this month…') . ' ' . $ged_date->display(false, '%F %Y')); break; case 'year': $controller->setPageTitle(I18N::translate('In this year…') . ' ' . $ged_date->display(false, '%Y')); break; } $controller->pageHeader(); ?>
', I18N::translate('Individuals'), ' | '; echo '', I18N::translate('Families'), ' | '; echo '
';
$content = calendar_list_text($indis, '
| ';
echo '';
$content = calendar_list_text($fams, '
| ';
echo '
', I18N::translate('Total individuals: %s', count($indis));
echo ' '; echo ' ', $males, ' '; echo ' ', $females, ' '; if (count($indis) !== $males + $females) { echo ' ', count($indis) - $males - $females; } echo ' | ';
echo '', I18N::translate('Total families: %s', count($fams)), ' | '; echo '
', $day_name, ' | '; } else { echo '', $day_name, ' | '; } } echo '
---|---|
';
if ($d < 1 || $d > $days_in_month) {
if (count($cal_facts[0]) > 0) {
echo '', I18N::translate('Day not set'), ' '; echo ' ';
echo calendar_list_text($cal_facts[0], '', '', false);
echo ' ';
$cal_facts[0] = array();
}
} else {
// Format the day number using the calendar
$tmp = new Date($cal_date->format("%@ {$d} %O %E"));
$d_fmt = $tmp->minimumDate()->format('%j');
if ($d === $today->d && $cal_date->m === $today->m) {
echo '', $d_fmt, '';
} else {
echo '', $d_fmt, '';
}
// Show a converted date
foreach (explode('_and_', $CALENDAR_FORMAT) as $convcal) {
switch ($convcal) {
case 'french':
$alt_date = new FrenchDate($cal_date->minJD + $d - 1);
break;
case 'gregorian':
$alt_date = new GregorianDate($cal_date->minJD + $d - 1);
break;
case 'jewish':
$alt_date = new JewishDate($cal_date->minJD + $d - 1);
break;
case 'julian':
$alt_date = new JulianDate($cal_date->minJD + $d - 1);
break;
case 'hijri':
$alt_date = new HijriDate($cal_date->minJD + $d - 1);
break;
case 'jalali':
$alt_date = new JalaliDate($cal_date->minJD + $d - 1);
break;
default:
break 2;
}
if (get_class($alt_date) !== get_class($cal_date)) {
echo '' . $alt_date->format("%j %M") . '';
// Just show the first conversion
break;
}
}
echo '';
echo calendar_list_text($cal_facts[$d], '', '', false);
echo ' ';
}
echo ' | ';
if (($d + $cal_date->minJD - $week_start) % $days_in_week === 0) {
echo '