--- D:/Temp/Drupal patching/theme.inc.orig Thu Mar 04 22:42:00 2010 +++ D:/Temp/Drupal patching/theme.inc Mon Mar 29 10:11:46 2010 @@ -27,20 +27,123 @@ $view->date_info->week = date_week($view->date_info->year .'-'. date_pad($view->date_info->month) .'-'. date_pad($view->date_info->day)); } $displays = $view->date_info->display_types; - + $current_year = date_format($now, 'Y'); + $current_month = date_format($now, 'm'); + $current_week = date_format($now, 'W'); + $current_day = date_format($now, 'd'); + $calendar_links = array(); $base = array('attributes' => array('rel' => 'nofollow')); - if (!empty($displays['year'])) { - $calendar_links[] = $base + array('title' => date_t('Year', 'datetime'), 'href' => date_real_url($view, 'year')); + if ($view->date_info->granularity == 'year') { + if (!empty($displays['year'])) { + $url = date_real_url($view, NULL, $view->date_info->year); + $calendar_links[] = $base + array('title' => date_t('Year', 'datetime'), 'href' => $url); + } + if (!empty($displays['month'])) { + // IF the current month is included in the year THEN the current month ELSE first month of the year + if ($view->date_info->year == $current_year) { + $url = date_real_url($view, NULL, $view->date_info->year . '-' . $current_month); + $calendar_links[] = $base + array('title' => date_t('Month', 'datetime'), 'href' => $url); + } else { + $url = date_real_url($view, NULL, $view->date_info->year . '-01'); + $calendar_links[] = $base + array('title' => date_t('Month', 'datetime'), 'href' => $url); + } + } + if (!empty($displays['week'])) { + // IF the current week is included in the year THEN the current week ELSE first week of the year + if ($view->date_info->year == $current_year) { + $url = date_real_url($view, NULL, $view->date_info->year . '-W' . $current_week); + $calendar_links[] = $base + array('title' => date_t('Week', 'datetime'), 'href' => $url); + } else { + $url = date_real_url($view, NULL, $view->date_info->year . '-W01'); + $calendar_links[] = $base + array('title' => date_t('Week', 'datetime'), 'href' => $url); + } + } + if (!empty($displays['day'])) { + // IF the current day is included in the year THEN the current day ELSE first day of the year + if ($view->date_info->year == $current_year) { + $url = date_real_url($view, NULL, $view->date_info->year . '-' . $current_month . '-' . $current_day); + $calendar_links[] = $base + array('title' => date_t('Day', 'datetime'), 'href' => $url); + } else { + $url = date_real_url($view, NULL, $view->date_info->min_date_date); + $calendar_links[] = $base + array('title' => date_t('Day', 'datetime'), 'href' => $url); + } + } } - if (!empty($displays['month'])) { - $calendar_links[] = $base + array('title' => date_t('Month', 'datetime'), 'href' => date_real_url($view, 'month')); + if ($view->date_info->granularity == 'month') { + if (!empty($displays['year'])) { + $url = date_real_url($view, NULL, $view->date_info->year); + $calendar_links[] = $base + array('title' => date_t('Year', 'datetime'), 'href' => $url); + } + if (!empty($displays['month'])) { + $url = date_real_url($view, NULL, $view->date_info->year . '-' . $view->date_info->month); + $calendar_links[] = $base + array('title' => date_t('Month', 'datetime'), 'href' => $url); + } + if (!empty($displays['week'])) { + // IF the current week is included in the chosen month THEN the current week ELSE first week of the chosen month + if ($view->date_info->year == $current_year && $view->date_info->month == $current_month) { + $url = date_real_url($view, NULL, $view->date_info->year . '-W' . $current_week); + $calendar_links[] = $base + array('title' => date_t('Week', 'datetime'), 'href' => $url); + } else { + $firstweekofmonth = date_week($view->date_info->year . '-' . $view->date_info->month . '-01'); + $url = date_real_url($view, NULL, $view->date_info->year . '-W' . $firstweekofmonth); + $calendar_links[] = $base + array('title' => date_t('Week', 'datetime'), 'href' => $url); + } + } + if (!empty($displays['day'])) { + // IF the current day is included in the chosen month THEN the current day ELSE first day of the chosen month + if ($view->date_info->year == $current_year && $view->date_info->month == $current_month) { + $url = date_real_url($view, NULL, $view->date_info->year . '-' . $current_month . '-' . $current_day); + $calendar_links[] = $base + array('title' => date_t('Day', 'datetime'), 'href' => $url); + } else { + $url = date_real_url($view, NULL, $view->date_info->min_date_date); + $calendar_links[] = $base + array('title' => date_t('Day', 'datetime'), 'href' => $url); + } + } } - if (!empty($displays['week'])) { - $calendar_links[] = $base + array('title' => date_t('Week', 'datetime'), 'href' => date_real_url($view, 'week')); + if ($view->date_info->granularity == 'week') { + if (!empty($displays['year'])) { + $url = date_real_url($view, NULL, $view->date_info->year); + $calendar_links[] = $base + array('title' => date_t('Year', 'datetime'), 'href' => $url); + } + if (!empty($displays['month'])) { + // the month in which the first day of the chosen week is present + $monthofweek = date_format($view->date_info->min_date, 'm'); + $url = date_real_url($view, NULL, $view->date_info->year . '-' . $monthofweek); + $calendar_links[] = $base + array('title' => date_t('Month', 'datetime'), 'href' => $url); + } + if (!empty($displays['week'])) { + $url = date_real_url($view, NULL, $view->date_info->year . '-W' . $view->date_info->week); + $calendar_links[] = $base + array('title' => date_t('Week', 'datetime'), 'href' => $url); + } + if (!empty($displays['day'])) { + // IF the current day is included in the chosen week THEN the current day ELSE first day of the chosen week + if ($view->date_info->year == $current_year && $view->date_info->week == $current_week) { + $url = date_real_url($view, NULL, $view->date_info->year . '-' . $current_month . '-' . $current_day); + $calendar_links[] = $base + array('title' => date_t('Day', 'datetime'), 'href' => $url); + } else { + $url = date_real_url($view, NULL, $view->date_info->min_date_date); + $calendar_links[] = $base + array('title' => date_t('Day', 'datetime'), 'href' => $url); + } + } } - if (!empty($displays['day'])) { - $calendar_links[] = $base + array('title' => date_t('Day', 'datetime'), 'href' => date_real_url($view, 'day')); + if ($view->date_info->granularity == 'day') { + if (!empty($displays['year'])) { + $url = date_real_url($view, NULL, $view->date_info->year); + $calendar_links[] = $base + array('title' => date_t('Year', 'datetime'), 'href' => $url); + } + if (!empty($displays['month'])) { + $url = date_real_url($view, NULL, $view->date_info->year . '-' . $view->date_info->month); + $calendar_links[] = $base + array('title' => date_t('Month', 'datetime'), 'href' => $url); + } + if (!empty($displays['week'])) { + $url = date_real_url($view, NULL, $view->date_info->year . '-W' . $view->date_info->week); + $calendar_links[] = $base + array('title' => date_t('Week', 'datetime'), 'href' => $url); + } + if (!empty($displays['day'])) { + $url = date_real_url($view, NULL, $view->date_info->min_date_date); + $calendar_links[] = $base + array('title' => date_t('Day', 'datetime'), 'href' => $url); + } } $vars['calendar_links'] = $calendar_links;