summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@gmail.com>2015-01-19 14:51:00 +0000
committerGreg Roach <fisharebest@gmail.com>2015-01-19 14:51:00 +0000
commita8059c84e4e14ceb7a8b458bba3a4b1f28be9584 (patch)
treedc27602c7302891c28a7bc35f5842990722eb727
parent704b40129e9674e740d2cdac2a9eae2e7e4b57a3 (diff)
downloadwebtrees-a8059c84e4e14ceb7a8b458bba3a4b1f28be9584.tar.gz
webtrees-a8059c84e4e14ceb7a8b458bba3a4b1f28be9584.tar.bz2
webtrees-a8059c84e4e14ceb7a8b458bba3a4b1f28be9584.zip
Tidy up calendar code
-rw-r--r--calendar.php179
-rw-r--r--library/WT/Date/Calendar.php32
2 files changed, 104 insertions, 107 deletions
diff --git a/calendar.php b/calendar.php
index f87824a726..a06fa1d201 100644
--- a/calendar.php
+++ b/calendar.php
@@ -27,7 +27,6 @@ use WT\Auth;
define('WT_SCRIPT_NAME', 'calendar.php');
require './includes/session.php';
-require_once WT_ROOT . 'includes/functions/functions_print_lists.php';
$controller = new WT_Controller_Page;
$controller->setPageTitle(WT_I18N::translate('Anniversary calendar'));
@@ -37,12 +36,12 @@ $cal = WT_Filter::get('cal', '@#D[A-Z ]+@');
$day = WT_Filter::get('day', '\d\d?');
$month = WT_Filter::get('month', '[A-Z]{3,5}');
$year = WT_Filter::get('year', '\d{1,4}(?: B\.C\.)?|\d\d\d\d\/\d\d|\d+(-\d+|[?]+)?');
-$action = WT_Filter::get('action', 'year|today|calendar', 'today');
+$view = WT_Filter::get('view', 'day|month|year', 'day');
$filterev = WT_Filter::get('filterev', 'all|bdm|' . WT_REGEX_TAG, 'bdm');
$filterof = WT_Filter::get('filterof', 'all|living|recent', 'all');
$filtersx = WT_Filter::get('filtersx', '[MF]');
-if ($cal . $day . $month . $year == '') {
+if ($cal . $day . $month . $year === '') {
// No date specified? Use the most likely calendar
switch (WT_LOCALE) {
case 'fa':
@@ -73,17 +72,17 @@ if (preg_match('/^(\d+)-(\d+)$/', $year, $match)) {
$match[2] = substr($match[1], 0, strlen($match[1]) - strlen($match[2])) . $match[2];
}
$ged_date = new WT_Date("FROM {$cal} {$match[1]} TO {$cal} {$match[2]}");
- $action = 'year';
+ $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 WT_Date("FROM {$cal} {$y1} TO {$cal} {$y2}");
- $action = 'year';
+ $view = 'year';
} else {
if ($year < 0) {
- $year = (-$year) . " B.C.";
+ $year = (-$year) . ' B.C.';
} // need BC to parse date
$ged_date = new WT_Date("{$cal} {$day} {$month} {$year}");
$year = $ged_date->date1->y; // need negative year for year entry field.
@@ -116,32 +115,32 @@ $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 && $action === 'today') {
- $action = 'calendar';
+if ($cal_date->d > $days_in_month && $view === 'day') {
+ $view = 'month';
}
echo '<div id="calendar-page">';
// Calendar form
-echo '<form name="dateform" method="get" action="calendar.php">';
-echo "<input type=\"hidden\" name=\"cal\" value=\"{$cal}\">";
-echo "<input type=\"hidden\" name=\"day\" value=\"{$cal_date->d}\">";
-echo "<input type=\"hidden\" name=\"month\" value=\"{$cal_month}\">";
-echo "<input type=\"hidden\" name=\"year\" value=\"{$cal_date->y}\">";
-echo "<input type=\"hidden\" name=\"action\" value=\"{$action}\">";
-echo "<input type=\"hidden\" name=\"filterev\" value=\"{$filterev}\">";
-echo "<input type=\"hidden\" name=\"filtersx\" value=\"{$filtersx}\">";
-echo "<input type=\"hidden\" name=\"filterof\" value=\"{$filterof}\">";
+echo '<form name="dateform">';
+echo '<input type="hidden" name="cal" value="', $cal, '">';
+echo '<input type="hidden" name="day" value="', $cal_date->d, '">';
+echo '<input type="hidden" name="month" value="', $cal_month, '">';
+echo '<input type="hidden" name="year" value="', $cal_date->y, '">';
+echo '<input type="hidden" name="view" value="', $view, '">';
+echo '<input type="hidden" name="filterev" value="', $filterev, '">';
+echo '<input type="hidden" name="filtersx" value="', $filtersx, '">';
+echo '<input type="hidden" name="filterof" value="', $filterof, '">';
echo '<table class="facts_table width100">';
echo '<tr><td class="facts_label" colspan="4"><h2>';
// All further uses of $cal are to generate URLs
$cal = rawurlencode($cal);
-switch ($action) {
-case 'today':
+switch ($view) {
+case 'day':
echo WT_I18N::translate('On this day…') . '<br>' . $ged_date->display();
break;
-case 'calendar':
+case 'month':
echo WT_I18N::translate('In this month…') . '<br>' . $ged_date->display(false, '%F %Y');
break;
case 'year':
@@ -157,46 +156,46 @@ for ($d = 1; $d <= $days_in_month; $d++) {
// Format the day number using the calendar
$tmp = new WT_Date($cal_date->format("%@ {$d} %O %E"));
$d_fmt = $tmp->date1->format('%j');
- if ($d == $cal_date->d) {
- echo "<span class=\"error\">{$d_fmt}</span>";
+ if ($d === $cal_date->d) {
+ echo '<span class="error">', $d_fmt, '</span>';
} else {
- echo "<a href=\"calendar.php?cal={$cal}&amp;day={$d}&amp;month={$cal_month}&amp;year={$cal_date->y}&amp;filterev={$filterev}&amp;filterof={$filterof}&amp;filtersx={$filtersx}&amp;action={$action}" . "\">{$d_fmt}</a>";
+ echo '<a href="cal=', $cal, '&amp;day=', $d, '&amp;month=', $cal_month, '&amp;year=', $cal_date->y, '&amp;filterev=', $filterev, '&amp;filterof=', $filterof, '&amp;filtersx=', $filtersx, '&amp;view=', $view, '">', $d_fmt, '</a>';
}
echo ' | ';
}
$tmp = new WT_Date($today->format('%@ %A %O %E')); // Need a WT_Date object to get localisation
-echo "<a href=\"calendar.php?cal={$cal}&amp;day={$today->d}&amp;month={$today_month}&amp;year={$today->y}&amp;filterev={$filterev}&amp;filterof={$filterof}&amp;filtersx={$filtersx}&amp;action={$action}\"><b>" . $tmp->display() . '</b></a>';
+echo '<a href="cal=', $cal, '&amp;day=', $today->d, '&amp;month=', $today_month, '&amp;year=', $today->y, '&amp;filterev=', $filterev, '&amp;filterof=', $filterof, '&amp;filtersx=', $filtersx, '&amp;view=', $view, '"><b>', $tmp->display(), '</b></a>';
echo '</td></tr>';
// Month selector
-echo '<tr><td class="descriptionbox vmiddle">';
+echo '<tr><td class="descriptionbox">';
echo WT_I18N::translate('Month'), '</td>';
echo '<td class="optionbox" colspan="3">';
for ($n = 1, $months_in_year = $cal_date->monthsInYear(); $n <= $months_in_year; ++$n) {
$month_name = $cal_date->monthNameNominativeCase($n, $cal_date->isLeapYear());
$m = array_search($n, $cal_date::$MONTH_ABBREV);
- if ($n == 6 && $cal_date instanceof WT_Date_Jewish && !$cal_date->isLeapYear()) {
+ if ($n === 6 && $cal_date instanceof WT_Date_Jewish && !$cal_date->isLeapYear()) {
// No month 6 in Jewish non-leap years.
continue;
}
- if ($n == 7 && $cal_date instanceof WT_Date_Jewish && !$cal_date->isLeapYear()) {
+ if ($n === 7 && $cal_date instanceof WT_Date_Jewish && !$cal_date->isLeapYear()) {
// Month 7 is ADR in Jewish non-leap years.
$m = 'ADR';
}
- if ($n == $cal_date->m) {
+ if ($n === $cal_date->m) {
$month_name = '<span class="error">' . $month_name . '</span>';
}
- echo "<a href=\"calendar.php?cal={$cal}&amp;day={$cal_date->d}&amp;month={$m}&amp;year={$cal_date->y}&amp;filterev={$filterev}&amp;filterof={$filterof}&amp;filtersx={$filtersx}&amp;action={$action}\">{$month_name}</a>";
+ echo '<a href="cal=', $cal, '&amp;day=', $cal_date->d, '&amp;month=', $m, '&amp;year=', $cal_date->y, '&amp;filterev=', $filterev, '&amp;filterof=', $filterof, '&amp;filtersx=', $filtersx, '&amp;view=', $view, '">', $month_name, '</a>';
echo ' | ';
}
-echo "<a href=\"calendar.php?cal={$cal}&amp;day=" . min($cal_date->d, $today->daysInMonth()) . "&amp;month={$today_month}&amp;year={$today->y}&amp;filterev={$filterev}&amp;filterof={$filterof}&amp;filtersx={$filtersx}&amp;action={$action}\"><b>" . $today->format('%F %Y') . '</b></a></td></tr>';
+echo '<a href="cal=', $cal, '&amp;day=', min($cal_date->d, $today->daysInMonth()), '&amp;month=', $today_month, '&amp;year=', $today->y, '&amp;filterev=', $filterev, '&amp;filterof=', $filterof, '&amp;filtersx=', $filtersx, '&amp;view=', $view, '"><b>' . $today->format('%F %Y') . '</b></a></td></tr>';
// Year selector
echo '<tr><td class="descriptionbox vmiddle">';
echo WT_I18N::translate('Year'), '</td>';
echo '<td class="optionbox vmiddle">';
-echo "<a href=\"calendar.php?cal={$cal}&amp;day={$cal_date->d}&amp;month={$cal_month}&amp;year=" . ($cal_date->y == 1 ? -1 : $cal_date->y - 1) . "&amp;filterev={$filterev}&amp;filterof={$filterof}&amp;filtersx={$filtersx}&amp;action={$action}\">-1</a>";
-echo " <input type=\"text\" name=\"year\" value=\"{$year}\" size=\"4\"> ";
-echo "<a href=\"calendar.php?cal={$cal}&amp;day={$cal_date->d}&amp;month={$cal_month}&amp;year=" . ($cal_date->y == -1 ? 1 : $cal_date->y + 1) . "&amp;filterev={$filterev}&amp;filterof={$filterof}&amp;filtersx={$filtersx}&amp;action={$action}\">+1</a>";
-echo " | <a href=\"calendar.php?cal={$cal}&amp;day={$cal_date->d}&amp;month={$cal_month}&amp;year={$today->y}&amp;filterev={$filterev}&amp;filterof={$filterof}&amp;filtersx={$filtersx}&amp;action={$action}\"><b>" . $today->format('%Y') . "</b></a>";
+echo '<a href="cal=', $cal, '&amp;day=', $cal_date->d, '&amp;month=', $cal_month, '&amp;year=', $cal_date->y === 1 ? -1 : $cal_date->y - 1, '&amp;filterev=', $filterev, '&amp;filterof=', $filterof, '&amp;filtersx=', $filtersx, '&amp;view=', $view, '">-1</a>';
+echo ' <input type="text" name="year" value="', $year, '" size="4"> ';
+echo '<a href="cal=', $cal, '&amp;day=', $cal_date->d, '&amp;month=', $cal_month, '&amp;year=', $cal_date->y === -1 ? 1 : $cal_date->y + 1, '&amp;filterev=', $filterev, '&amp;filterof=', $filterof, '&amp;filtersx=', $filtersx, '&amp;view=', $view, '">+1</a>';
+echo ' | <a href="cal=', $cal, '&amp;day=', $cal_date->d, '&amp;month=', $cal_month, '&amp;year=', $today->y, '&amp;filterev=', $filterev, '&amp;filterof=', $filterof, '&amp;filtersx=', $filtersx, '&amp;view=', $view, '"><b>' . $today->format('%Y') . '</b></a>';
echo help_link('annivers_year_select');
echo '</td> ';
@@ -212,7 +211,7 @@ if ($filterof === 'all') {
echo 'selected';
}
echo '>', WT_I18N::translate('All individuals'), '</option>';
-if (!$HIDE_LIVE_PEOPLE || Auth::check()) {
+if (!$WT_TREE->getPreference('HIDE_LIVE_PEOPLE') || Auth::check()) {
echo '<option value="living" ';
if ($filterof === 'living') {
echo 'selected';
@@ -228,31 +227,31 @@ echo '</select>';
echo '&nbsp;&nbsp;&nbsp;';
-if ($filtersx == "") {
+if ($filtersx === '') {
echo '<i class="icon-sex_m_15x15" title="', WT_I18N::translate('All individuals'), '"></i>';
echo '<i class="icon-sex_f_15x15" title="', WT_I18N::translate('All individuals'), '"></i> | ';
} else {
- echo '<a href="calendar.php?cal=', $cal, '&amp;day=', $cal_date->d, '&amp;month=', $cal_month, '&amp;year=', $cal_date->y, '&amp;filterev=', $filterev, '&amp;filterof=', $filterof, '&amp;action=', $action, '">';
+ echo '<a href="cal=', $cal, '&amp;day=', $cal_date->d, '&amp;month=', $cal_month, '&amp;year=', $cal_date->y, '&amp;filterev=', $filterev, '&amp;filterof=', $filterof, '&amp;view=', $view, '">';
echo '<i class="icon-sex_m_9x9" title="', WT_I18N::translate('All individuals'), '"></i>';
echo '<i class="icon-sex_f_9x9" title="', WT_I18N::translate('All individuals'), '"></i></a> | ';
}
-if ($filtersx == "M") {
+if ($filtersx === 'M') {
echo '<i class="icon-sex_m_15x15" title="', WT_I18N::translate('Males'), '"></i> | ';
} else {
- echo '<a class="icon-sex_m_9x9" title="', WT_I18N::translate('Males'), '" href="calendar.php?cal=', $cal, '&amp;day=', $cal_date->d, '&amp;month=', $cal_month, '&amp;year=', $cal_date->y, '&amp;filterev=', $filterev, '&amp;filterof=', $filterof, '&amp;filtersx=M&amp;action=', $action, '"></a> | ';
+ echo '<a class="icon-sex_m_9x9" title="', WT_I18N::translate('Males'), '" href="cal=', $cal, '&amp;day=', $cal_date->d, '&amp;month=', $cal_month, '&amp;year=', $cal_date->y, '&amp;filterev=', $filterev, '&amp;filterof=', $filterof, '&amp;filtersx=M&amp;view=', $view, '"></a> | ';
}
if ($filtersx === 'F') {
echo '<i class="icon-sex_f_15x15" title="', WT_I18N::translate('Females'), '"></i>';
} else {
- echo '<a class="icon-sex_f_9x9" title="', WT_I18N::translate('Females'), '" href="calendar.php?cal=', $cal, '&amp;day=', $cal_date->d, '&amp;month=', $cal_month, '&amp;year=', $cal_date->y, '&amp;filterev=', $filterev, '&amp;filterof=', $filterof, '&amp;filtersx=F&amp;action=', $action, '"></a>';
+ echo '<a class="icon-sex_f_9x9" title="', WT_I18N::translate('Females'), '" href="cal=', $cal, '&amp;day=', $cal_date->d, '&amp;month=', $cal_month, '&amp;year=', $cal_date->y, '&amp;filterev=', $filterev, '&amp;filterof=', $filterof, '&amp;filtersx=F&amp;view=', $view, '"></a>';
}
echo '&nbsp;&nbsp;&nbsp;';
-echo "<input type=\"hidden\" name=\"filterev\" value=\"$filterev\">";
+echo '<input type="hidden" name="filterev" value="', $filterev, '">';
echo '<select class="list_value" name="filterev" onchange="document.dateform.submit();">';
echo '<option value="bdm"';
-if ($filterev === 'bdm' ) {
+if ($filterev === 'bdm') {
echo 'selected';
}
echo '>', WT_I18N::translate('Vital records'), '</option>';
@@ -330,57 +329,57 @@ echo '</select>';
echo '</td></tr>';
echo '</table></form>';
-echo "<table class=\"width100\">";
+echo '<table class="width100">';
// Day/Month/Year and calendar selector
echo '<tr><td class="topbottombar width50">';
-if ($action == 'today') {
+if ($view === 'day') {
echo '<span class="error">', WT_I18N::translate('View day'), '</span>';
} else {
- echo "<a href=\"calendar.php?cal={$cal}&amp;day={$cal_date->d}&amp;month={$cal_month}&amp;year={$cal_date->y}&amp;filterev={$filterev}&amp;filterof={$filterof}&amp;filtersx={$filtersx}&amp;action=today\">", WT_I18N::translate('View day'), "</a>";
+ echo '<a href="cal=', $cal. '&amp;day=', $cal_date->d, '&amp;month=', $cal_month, '&amp;year=', $cal_date->y, '&amp;filterev=', $filterev, '&amp;filterof=', $filterof, '&amp;filtersx=', $filtersx, '&amp;view=day">', WT_I18N::translate('View day'), '</a>';
}
-if ($action == 'calendar') {
+if ($view === 'calendar') {
echo ' | <span class="error">', WT_I18N::translate('View month'), '</span>';
} else {
- echo " | <a href=\"calendar.php?cal={$cal}&amp;day={$cal_date->d}&amp;month={$cal_month}&amp;year={$cal_date->y}&amp;filterev={$filterev}&amp;filterof={$filterof}&amp;filtersx={$filtersx}&amp;action=calendar\">", WT_I18N::translate('View month'), "</a>";
+ echo ' | <a href="cal=', $cal, '&amp;day=', $cal_date->d, '&amp;month=', $cal_month, '&amp;year=', $cal_date->y, '&amp;filterev=', $filterev, '&amp;filterof=', $filterof, '&amp;filtersx=', $filtersx, '&amp;view=month">', WT_I18N::translate('View month'), '</a>';
}
-if ($action == 'year') {
+if ($view === 'year') {
echo ' | <span class="error">', WT_I18N::translate('View year'), '</span>';
} else {
- echo " | <a href=\"calendar.php?cal={$cal}&amp;day={$cal_date->d}&amp;month={$cal_month}&amp;year={$cal_date->y}&amp;filterev={$filterev}&amp;filterof={$filterof}&amp;filtersx={$filtersx}&amp;action=year\">", WT_I18N::translate('View year'), "</a>";
+ echo ' | <a href="cal=', $cal, '&amp;day=', $cal_date->d, '&amp;month=', $cal_month, '&amp;year=', $cal_date->y, '&amp;filterev=', $filterev, '&amp;filterof=', $filterof, '&amp;filtersx=', $filtersx, '&amp;view=year">', WT_I18N::translate('View year'), '</a>';
}
echo '</td><td class="topbottombar width50">';
$n = 0;
foreach (array(
- 'gregorian' => WT_Date_Gregorian::calendarName(),
- 'julian' => WT_Date_Julian::calendarName(),
- 'jewish' => WT_Date_Jewish::calendarName(),
- 'french' => WT_Date_French::calendarName(),
- 'hijri' => WT_Date_Hijri::calendarName(),
- 'jalali' => WT_Date_Jalali::calendarName(),
- ) as $newcal => $cal_name) {
+ 'gregorian' => WT_Date_Gregorian::calendarName(),
+ 'julian' => WT_Date_Julian::calendarName(),
+ 'jewish' => WT_Date_Jewish::calendarName(),
+ 'french' => WT_Date_French::calendarName(),
+ 'hijri' => WT_Date_Hijri::calendarName(),
+ 'jalali' => WT_Date_Jalali::calendarName(),
+) as $newcal => $cal_name) {
$tmp = $cal_date->convertToCalendar($newcal);
if ($tmp->inValidRange()) {
if ($n++) {
echo ' | ';
}
- if (get_class($tmp) == get_class($cal_date)) {
- echo "<span class=\"error\">{$cal_name}</span>";
+ if (get_class($tmp) === get_class($cal_date)) {
+ echo '<span class="error">', $cal_name, '</span>';
} else {
$newcalesc = urlencode($tmp->format('%@'));
$tmpmonth = $tmp->format('%O');
- echo "<a href=\"calendar.php?cal={$newcalesc}&amp;day={$tmp->d}&amp;month={$tmpmonth}&amp;year={$tmp->y}&amp;filterev={$filterev}&amp;filterof={$filterof}&amp;filtersx={$filtersx}&amp;action={$action}\">{$cal_name}</a>";
+ echo '<a href="cal=', $newcalesc, '&amp;day=', $tmp->d, '&amp;month=', $tmpmonth, '&amp;year=', $tmp->y, '&amp;filterev=', $filterev, '&amp;filterof=', $filterof, '&amp;filtersx=', $filtersx, '&amp;view=', $view, '">', $cal_name, '</a>';
}
}
}
-echo "</td></tr>";
-echo "</table>";
+echo '</td></tr>';
+echo '</table>';
// Convert event filter option to a list of gedcom event codes
-if ($filterev == 'all') {
+if ($filterev === 'all') {
$events = '';
} else {
- if ($filterev == 'bdm') {
+ if ($filterev === 'bdm') {
$events = 'BIRT MARR DEAT';
} else {
$events = $filterev;
@@ -388,11 +387,11 @@ if ($filterev == 'all') {
}
// Fetch data for day/month/year views
-switch ($action) {
-case 'today':
+switch ($view) {
+case 'day':
$found_facts = apply_filter(get_anniversary_events($cal_date->minJD, $events), $filterof, $filtersx);
break;
-case 'calendar':
+case 'month':
$cal_date->d = 0;
$cal_date->setJdFromYmd();
// Make a separate list for each day. Unspecified/invalid days go in day 0.
@@ -425,9 +424,9 @@ case 'year':
}
// Group the facts by family/individual
-switch ($action) {
+switch ($view) {
case 'year':
-case 'today':
+case 'day':
$indis = array();
$fams = array();
foreach ($found_facts as $fact) {
@@ -448,7 +447,7 @@ case 'today':
}
}
break;
-case 'calendar':
+case 'month':
$cal_facts = array();
foreach ($found_facts as $d => $facts) {
$cal_facts[$d] = array();
@@ -464,9 +463,9 @@ case 'calendar':
break;
}
-switch ($action) {
+switch ($view) {
case 'year':
-case 'today':
+case 'day':
echo '<table class="width100"><tr>';
// Table headings
echo '<td class="descriptionbox center width50"><i class="icon-indis"></i>', WT_I18N::translate('Individuals'), '</td>';
@@ -494,13 +493,13 @@ case 'today':
}
echo '</td>';
- echo "</tr><tr>";
+ echo '</tr><tr>';
// Table footers
echo '<td class="descriptionbox">', WT_I18N::translate('Total individuals: %s', count($indis));
echo '<br>';
echo '<i class="icon-sex_m_15x15" title="', WT_I18N::translate('Males'), '"></i> ', $males, '&nbsp;&nbsp;&nbsp;&nbsp;';
echo '<i class="icon-sex_f_15x15" title="', WT_I18N::translate('Males'), '"></i> ', $females, '&nbsp;&nbsp;&nbsp;&nbsp;';
- if (count($indis) != $males + $females) {
+ if (count($indis) !== $males + $females) {
echo '<i class="icon-sex_u_15x15" title="', WT_I18N::translate('All individuals'), '"></i> ', count($indis) - $males - $females;
}
echo '</td>';
@@ -508,34 +507,34 @@ case 'today':
echo '</tr></table>';
break;
-case 'calendar':
+case 'month':
// We use JD%7 = 0/Mon...6/Sun. Config files use 0/Sun...6/Sat. Add 6 to convert.
$week_start = ($WEEK_START + 6) % $days_in_week;
// The french calendar has a 10-day week, but our config only lets us choose
// mon-sun as a start day. Force french calendars to start on primidi
- if ($days_in_week == 10) {
+ if ($days_in_week === 10) {
$week_start = 0;
}
- echo "<table class=\"list_table width100\"><tr>";
+ echo '<table class="list_table width100"><tr>';
for ($week_day = 0; $week_day < $days_in_week; ++$week_day) {
$day_name = $cal_date->dayNames(($week_day + $week_start) % $days_in_week);
- echo "<td class=\"descriptionbox\" width=\"" . (100 / $days_in_week) . "%\">{$day_name}</td>";
+ echo '<td class="descriptionbox" width="' . (100 / $days_in_week) . '%">', $day_name, '</td>';
}
- echo "</tr>";
+ echo '</tr>';
// Print days 1-n of the month...
// ...but extend to cover "empty" days before/after the month to make whole weeks.
// e.g. instead of 1 -> 30 (=30 days), we might have -1 -> 33 (=35 days)
$start_d = 1 - ($cal_date->minJD - $week_start) % $days_in_week;
$end_d = $days_in_month + ($days_in_week - ($cal_date->maxJD - $week_start + 1) % $days_in_week) % $days_in_week;
// Make sure that there is an empty box for any leap/missing days
- if ($start_d == 1 && $end_d == $days_in_month && count($found_facts[0]) > 0) {
+ if ($start_d === 1 && $end_d === $days_in_month && count($found_facts[0]) > 0) {
$end_d += $days_in_week;
}
for ($d = $start_d; $d <= $end_d; ++$d) {
- if (($d + $cal_date->minJD - $week_start) % $days_in_week == 1) {
- echo "<tr>";
+ if (($d + $cal_date->minJD - $week_start) % $days_in_week === 1) {
+ echo '<tr>';
}
- echo "<td class=\"optionbox wrap\">";
+ echo '<td class="optionbox wrap">';
if ($d < 1 || $d > $days_in_month) {
if (count($cal_facts[0]) > 0) {
echo '<span class="cal_day">', WT_I18N::translate('Day not set'), '</span><br style="clear: both;">';
@@ -550,10 +549,10 @@ case 'calendar':
// Format the day number using the calendar
$tmp = new WT_Date($cal_date->format("%@ {$d} %O %E"));
$d_fmt = $tmp->date1->format('%j');
- if ($d == $today->d && $cal_date->m == $today->m) {
- echo "<span class=\"cal_day current_day\">{$d_fmt}</span>";
+ if ($d === $today->d && $cal_date->m === $today->m) {
+ echo '<span class="cal_day current_day">', $d_fmt, '</span>';
} else {
- echo "<span class=\"cal_day\">{$d_fmt}</span>";
+ echo '<span class="cal_day">', $d_fmt, '</span>';
}
// Show a converted date
foreach (explode('_and_', $CALENDAR_FORMAT) as $convcal) {
@@ -579,8 +578,8 @@ case 'calendar':
default:
break 2;
}
- if (get_class($alt_date) != get_class($cal_date)) {
- echo "<span class=\"rtl_cal_day\">" . $alt_date->format("%j %M") . "</span>";
+ if (get_class($alt_date) !== get_class($cal_date)) {
+ echo '<span class="rtl_cal_day">' . $alt_date->format("%j %M") . '</span>';
// Just show the first conversion
break;
}
@@ -590,7 +589,7 @@ case 'calendar':
echo '</div>';
}
echo '</td>';
- if (($d + $cal_date->minJD - $week_start) % $days_in_week == 0) {
+ if (($d + $cal_date->minJD - $week_start) % $days_in_week === 0) {
echo '</tr>';
}
}
@@ -615,7 +614,7 @@ function apply_filter($facts, $filterof, $filtersx) {
$record = $fact->getParent();
if ($filtersx) {
// Filter on sex
- if ($record instanceof WT_Individual && $filtersx != $record->getSex()) {
+ if ($record instanceof WT_Individual && $filtersx !== $record->getSex()) {
continue;
}
// Can't display families if the sex filter is on.
@@ -637,7 +636,7 @@ function apply_filter($facts, $filterof, $filtersx) {
}
}
// Filter on recent events
- if ($filterof == 'recent' && $fact->getDate()->MaxJD() < $hundred_years) {
+ if ($filterof === 'recent' && $fact->getDate()->MaxJD() < $hundred_years) {
continue;
}
$filtered[] = $fact;
diff --git a/library/WT/Date/Calendar.php b/library/WT/Date/Calendar.php
index 115059088b..09e9e9385d 100644
--- a/library/WT/Date/Calendar.php
+++ b/library/WT/Date/Calendar.php
@@ -957,24 +957,22 @@ class WT_Date_Calendar {
* @return string
*/
public function calendarUrl($date_format) {
- $URL = 'calendar.php?cal=' . rawurlencode(static::CALENDAR_ESCAPE);
- $action = 'year';
- if (strpos($date_format, 'Y') !== false || strpos($date_format, 'y') !== false) {
- $URL .= '&amp;year=' . $this->formatGedcomYear();
- }
- if (strpos($date_format, 'F') !== false || strpos($date_format, 'M') !== false || strpos($date_format, 'm') !== false || strpos($date_format, 'n') !== false) {
- $URL .= '&amp;month=' . $this->formatGedcomMonth();
- if ($this->m > 0) {
- $action = 'calendar';
- }
- }
- if (strpos($date_format, 'd') !== false || strpos($date_format, 'D') !== false || strpos($date_format, 'j') !== false) {
- $URL .= '&amp;day=' . $this->formatGedcomDay();
- if ($this->d > 0) {
- $action = 'today';
- }
+ if (strpbrk($date_format, 'dDj') && $this->d) {
+ // If the format includes a day, and the date also includes a day, then use the day view
+ $view = 'day';
+ } elseif (strpbrk($date_format, 'FMmn') && $this->m) {
+ // If the format includes a month, and the date also includes a month, then use the month view
+ $view = 'month';
+ } else {
+ // Use the year view
+ $view = 'year';
}
- return $URL . '&amp;action=' . $action;
+ return
+ 'calendar.php?cal=' . rawurlencode(static::CALENDAR_ESCAPE) .
+ '&amp;year=' . $this->formatGedcomYear() .
+ '&amp;month=' . $this->formatGedcomMonth() .
+ '&amp;day=' . $this->formatGedcomDay() .
+ '&amp;view=' . $view;
}
}