Browse Source

Merge pull request #1313 from Arantor/release-2.1

! There are simply just too many permutations for handling week numbers ...
Arantor 10 years ago
parent
commit
0c00c4d844

+ 2 - 4
Sources/Calendar.php

@@ -135,7 +135,6 @@ function CalendarMain()
 			'birthdays' => isset($modSettings['cal_highlight_birthdays']) ? $modSettings['cal_highlight_birthdays'] : 0,
 		),
 		'show_week_num' => true,
-		'tpl_show_week_num' => !empty($modSettings['cal_week_numbers']),
 		'short_day_titles' => !empty($modSettings['cal_short_days']),
 		'short_month_titles' => !empty($modSettings['cal_short_months']),
 		'show_next_prev' => !empty($modSettings['cal_prev_next_links']),
@@ -175,10 +174,9 @@ function CalendarMain()
 	$context['current_year'] = $curPage['year'];
 	$context['show_all_birthdays'] = isset($_GET['showbd']);
 	$context['blocks_disabled'] = !empty($modSettings['cal_disable_prev_next']) ? 1 : 0;
-	$context['tpl_show_week_num'] = !empty($calendarOptions['tpl_show_week_num']) ? 1 : 0;
 
 	// Set the page title to mention the month or week, too
-	$context['page_title'] .= ' - ' . ($context['view_week'] ? sprintf($txt['calendar_week_title'], $context['calendar_grid_main']['week_number'], ($context['calendar_grid_main']['week_number'] == 53 ? $context['current_year'] - 1 : $context['current_year'])) : $txt['months'][$context['current_month']] . ' ' . $context['current_year']);
+	$context['page_title'] .= ' - ' . ($context['view_week'] ? $context['calendar_grid_main']['week_title'] : $txt['months'][$context['current_month']] . ' ' . $context['current_year']);
 
 	// Load up the linktree!
 	$context['linktree'][] = array(
@@ -194,7 +192,7 @@ function CalendarMain()
 	if ($context['view_week'])
 		$context['linktree'][] = array(
 			'url' => $scripturl . '?action=calendar;viewweek;year=' . $context['current_year'] . ';month=' . $context['current_month'] . ';day=' . $context['current_day'],
-			'name' => $txt['calendar_week'] . ' ' . $context['calendar_grid_main']['week_number']
+			'name' => $context['calendar_grid_main']['week_title'],
 		);
 
 	// Build the calendar button array.

+ 0 - 1
Sources/ManageCalendar.php

@@ -361,7 +361,6 @@ function ModifyCalendarSettings($return_config = false)
 				array('check', 'cal_prev_next_links'),
 				array('check', 'cal_short_days'),
 				array('check', 'cal_short_months'),
-				array('check', 'cal_week_numbers'),
 		);
 	else
 		$config_vars = array(

+ 3 - 45
Sources/Subs-Calendar.php

@@ -395,35 +395,6 @@ function getCalendarGrid($month, $year, $calendarOptions, $is_previous = false)
 			$count = 0;
 	}
 
-	// An adjustment value to apply to all calculated week numbers.
-	if (!empty($calendarOptions['show_week_num']))
-	{
-		// If the first day of the year is a Sunday, then there is no
-		// adjustment to be made. However, if the first day of the year is not
-		// a Sunday, then there is a partial week at the start of the year
-		// that needs to be accounted for.
-		if ($calendarOptions['start_day'] === 0)
-			$nWeekAdjust = $month_info['first_day_of_year'] === 0 ? 0 : 1;
-		// If we are viewing the weeks, with a starting date other than Sunday,
-		// then things get complicated! Basically, as PHP is calculating the
-		// weeks with a Sunday starting date, we need to take this into account
-		// and offset the whole year dependant on whether the first day in the
-		// year is above or below our starting date. Note that we offset by
-		// two, as some of this will get undone quite quickly by the statement
-		// below.
-		else
-			$nWeekAdjust = $calendarOptions['start_day'] > $month_info['first_day_of_year'] && $month_info['first_day_of_year'] !== 0 ? 2 : 1;
-
-		// If our week starts on a day greater than the day the month starts
-		// on, then our week numbers will be one too high. So we need to
-		// reduce it by one - all these thoughts of offsets makes my head
-		// hurt...
-		if ($month_info['first_day']['day_of_week'] < $calendarOptions['start_day'] || $month_info['first_day_of_year'] > 4)
-			$nWeekAdjust--;
-	}
-	else
-		$nWeekAdjust = 0;
-
 	// Iterate through each week.
 	$calendarGrid['weeks'] = array();
 	for ($nRow = 0; $nRow < $nRows; $nRow++)
@@ -431,11 +402,7 @@ function getCalendarGrid($month, $year, $calendarOptions, $is_previous = false)
 		// Start off the week - and don't let it go above 52, since that's the number of weeks in a year.
 		$calendarGrid['weeks'][$nRow] = array(
 			'days' => array(),
-			'number' => $month_info['first_day']['week_num'] + $nRow + $nWeekAdjust
 		);
-		// Handle the dreaded "week 53", it can happen, but only once in a blue moon ;)
-		if ($calendarGrid['weeks'][$nRow]['number'] == 53 && $nShift != 4 && $month_info['first_day_of_next_year'] < 4)
-			$calendarGrid['weeks'][$nRow]['number'] = 1;
 
 		// And figure out all the days.
 		for ($nCol = 0; $nCol < 7; $nCol++)
@@ -484,7 +451,7 @@ function getCalendarGrid($month, $year, $calendarOptions, $is_previous = false)
  */
 function getCalendarWeek($month, $year, $day, $calendarOptions)
 {
-	global $scripturl, $modSettings;
+	global $scripturl, $modSettings, $txt;
 
 	// Get today's date.
 	$today = getTodayInfo();
@@ -541,17 +508,8 @@ function getCalendarWeek($month, $year, $day, $calendarOptions)
 		$first_day_of_next_year = (int) strftime('%w', mktime(0, 0, 0, 1, 1, $year + 1));
 		$last_day_of_last_year = (int) strftime('%w', mktime(0, 0, 0, 12, 31, $year - 1));
 
-		// All this is as getCalendarGrid.
-		if ($calendarOptions['start_day'] === 0)
-			$nWeekAdjust = $first_day_of_year === 0 && $first_day_of_year > 3 ? 0 : 1;
-		else
-			$nWeekAdjust = $calendarOptions['start_day'] > $first_day_of_year && $first_day_of_year !== 0 ? 2 : 1;
-
-		$calendarGrid['week_number'] = (int) strftime('%U', mktime(0, 0, 0, $month, $day, $year)) + $nWeekAdjust;
-
-		// If this crosses a year boundry and includes january it should be week one.
-		if ((int) strftime('%Y', $curTimestamp + 518400) != $year && $calendarGrid['week_number'] > 53 && $first_day_of_next_year < 5)
-			$calendarGrid['week_number'] = 1;
+		$timestamp = mktime(0, 0, 0, $month, $day, $year);
+		$calendarGrid['week_title'] = sprintf($txt['calendar_week_beginning'], date('F', $timestamp), date('j', $timestamp), date('Y', $timestamp));
 	}
 
 	// This holds all the main data - there is at least one month!

+ 3 - 7
Themes/default/Calendar.template.php

@@ -206,10 +206,6 @@ function template_show_month_grid($grid_name, $is_mini = false)
 				// A lot of stuff, we're not showing on mini-calendars to conserve space.
 				if ($is_mini === false)
 				{
-					// If this is the first day of a week and we're showing week numbers, go ahead and do so now.
-					if ($day['is_first_day'] && !empty($context['tpl_show_week_num']))
-						echo '<span class="smalltext"> - <a href="', $scripturl, '?action=calendar;viewweek;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], '">', $txt['calendar_week'], ' ', $week['number'], '</a></span>';
-
 					// Holidays are always fun, let's show them!
 					if (!empty($day['holidays']))
 						echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>';
@@ -331,15 +327,15 @@ function template_show_week_grid($grid_name)
 					if (empty($calendar_data['previous_calendar']['disabled']) && !empty($calendar_data['show_next_prev']))
 					{
 						echo '
-							<span class="floatleft xlarge_text>
+							<span class="floatleft xlarge_text">
 								<a href="', $calendar_data['previous_week']['href'], '">&#171;</a>
 							</span>
 						';
 					}
 
 					// The Month Title + Week Number...
-					if (!empty($calendar_data['week_number']))
-							echo $txt['calendar_week'], ' ', $calendar_data['week_number'], ' - ', $month_data['current_year'];
+					if (!empty($calendar_data['week_title']))
+							echo $calendar_data['week_title'];
 
 					// Next Week Link...
 					if (empty($calendar_data['next_calendar']['disabled']) && !empty($calendar_data['show_next_prev']))

+ 0 - 1
Themes/default/languages/Help.english.php

@@ -207,7 +207,6 @@ $helptxt['cal_week_links'] = 'If this setting is checked, links will be added al
 $helptxt['cal_prev_next_links'] = 'If this setting is checked, previous month and next month links will be added to the top of each month for easy navigation.';
 $helptxt['cal_short_months'] = 'If this setting is checked, month names within the calendar will be shortened.<br><br><strong>Enabled:</strong> ' . $txt['months_short'][1] . ' 1<br><strong>Disabled:</strong> ' . $txt['months_titles'][1] . ' 1';
 $helptxt['cal_short_days'] = 'If this setting is checked, day names within the calendar will be shortened.<br><br><strong>Enabled:</strong> ' . $txt['days_short'][1] . '<br><strong>Disbaled:</strong> ' . $txt['days'][1];
-$helptxt['cal_week_numbers'] = 'If this setting is checked, the first day of every week will have the week number next to that day.<br><br><strong>Enabled:</strong> March 3 - Week 10</strong><br><strong>Disabled:</strong> March 3';
 
 $helptxt['serversettings'] = '<strong>Server Settings</strong><br>
 	Here you can perform the core configuration for your forum. This section includes the database and url settings, as well as other

+ 0 - 1
Themes/default/languages/ManageCalendar.english.php

@@ -54,7 +54,6 @@ $txt['setting_cal_prev_next_links'] = 'Show <em>Previous / Next</em> Month Links
 // The name of this setting is kind of misleading...we can't shorten actual months unfortunately!
 $txt['setting_cal_short_months'] = 'Short Month Titles';
 $txt['setting_cal_short_days'] = 'Short Day Titles';
-$txt['setting_cal_week_numbers'] = 'Show Week Numbers';
 
 // Adding/Editing/Viewing Holidays
 $txt['manage_holidays_desc'] = 'From here you can add and remove holidays from your forum calendar.';

+ 2 - 0
Themes/default/languages/index.english.php

@@ -511,6 +511,8 @@ $txt['calendar_upcoming'] = 'Upcoming Calendar';
 $txt['calendar_today'] = 'Today\'s Calendar';
 $txt['calendar_week'] = 'Week';
 $txt['calendar_week_title'] = 'Week %1$d of %2$d';
+// %1$s is the month, %2$s is the day, %3$s is the year. Change to suit your language.
+$txt['calendar_week_beginning'] = 'Week beginning %1$s %2$s, %3$s';
 $txt['calendar_numb_days'] = 'Number of Days:';
 $txt['calendar_how_edit'] = 'how do you edit these events?';
 $txt['calendar_link_event'] = 'Link Event To Post:';

+ 0 - 1
other/install_2-1_mysql.sql

@@ -1760,7 +1760,6 @@ VALUES ('smfVersion', '{$smf_version}'),
 	('cal_prev_next_links', '1'),
 	('cal_short_days', '0'),
 	('cal_short_months', '0'),
-	('cal_week_numbers', '0'),
 	('smtp_host', ''),
 	('smtp_port', '25'),
 	('smtp_username', ''),

+ 0 - 1
other/install_2-1_postgresql.sql

@@ -2271,7 +2271,6 @@ INSERT INTO {$db_prefix}settings (variable, value) VALUES ('cal_week_links', '2'
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('cal_prev_next_links', '1');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('cal_short_days', '0');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('cal_short_months', '0');
-INSERT INTO {$db_prefix}settings (variable, value) VALUES ('cal_week_numbers', '0');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('smtp_host', '');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('smtp_port', '25');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('smtp_username', '');

+ 0 - 1
other/install_2-1_sqlite.sql

@@ -1903,7 +1903,6 @@ INSERT INTO {$db_prefix}settings (variable, value) VALUES ('cal_week_links', '2'
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('cal_prev_next_links', '1');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('cal_short_days', '0');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('cal_short_months', '0');
-INSERT INTO {$db_prefix}settings (variable, value) VALUES ('cal_week_numbers', '0');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('smtp_host', '');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('smtp_port', '25');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('smtp_username', '');

+ 0 - 1
other/install_2-1_sqlite3.sql

@@ -1903,7 +1903,6 @@ INSERT INTO {$db_prefix}settings (variable, value) VALUES ('cal_week_links', '2'
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('cal_prev_next_links', '1');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('cal_short_days', '0');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('cal_short_months', '0');
-INSERT INTO {$db_prefix}settings (variable, value) VALUES ('cal_week_numbers', '0');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('smtp_host', '');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('smtp_port', '25');
 INSERT INTO {$db_prefix}settings (variable, value) VALUES ('smtp_username', '');