2010年11月02日(Tue)
■ drupal、Archiveモジュール(pixture版)のパッチ
ブロックカレンダーの日付の不具合修正
Archiveモジュールを改造する | PIXTURE STUDIOを入れてみたところ、Drupal 6.19、mysql 5.1.51、PHP 5.2.14の環境で次のような不具合があっため、パッチを書いた。
- ブロックにカレンダーが表示されるページが年月日の属性を持たない(nodeではない。パネルやビューページ)の場合、当月が1970/01になる不具合
- next-monthまたはprev-monthが存在しない場合、リンク先が1970/01になる不具合
--- /home/socodanet/local/downloads/archive/archive.module 2010-09-26 13:33:31.000000000 +0900
+++ /home/socodanet/www/socodanet/arg/modules/archive/archive.module 2010-11-02 21:47:53.000000000 +0900
@@ -107,8 +107,9 @@
*/
function theme_archive_block_calendar($timestamp) {
- if (!$timestamp) {
- $timestamp = mktime();
+ $defaulttime = mktime(0,0,0,1,1,1970);
+ if ($timestamp==$defaulttime) {
+ $timestamp = _archive_get_current_post_date('all');
}
$the_date = explode(' ', format_date($timestamp, 'custom', 'F Y n t'));
$title = $the_date[0] .' '. $the_date[1];
@@ -143,8 +144,8 @@
$month_title = '';
// add a link to the previous month
- if (($oldest_year < $prev_year) ||
- ($oldest_year == $prev_year && $oldest_month <= $prev_month)) {
+ if (($prev_year!='1970') || ($oldest_year < $prev_year) ||
+ ($oldest_year == $prev_year && $oldest_month <= $prev_month)) {
$month_title .= '<span class="prev-month">';
$month_title .= l('<', _archive_url('all', $prev_year, $prev_month), array('attributes' => array('title' => format_plural($num_prev_month, '1 post', '@count posts'))));
$month_title .= '</span>';
@@ -166,8 +167,8 @@
$month_title .= '</span>';
// add a link to the next month
- if (($next_year < $current_year) ||
- ($next_year == $current_year && $next_month <= $current_month)) {
+ if (($next_year!='1970') || ($current_year <= $next_year ) ||
+ ($next_year == $current_year && $current_month < $next_month )) {
$month_title .= " ";
$month_title .= '<span class="next-month">';
$month_title .= l('>', _archive_url('all', $next_year, $next_month), array('attributes' => array('title' => format_plural($num_next_month, '1 post', '@count posts'))));
@@ -582,6 +583,13 @@
return $result;
}
+function _archive_get_current_post_date($type) {
+ $final_types = _archive_types_sql_string($type);
+ $result = db_result(db_query(db_rewrite_sql('SELECT MAX(n.created) FROM {node} n WHERE n.status = 1 '. $final_types)));
+ return $result;
+}
+
+
/**
* Get the date of the closesr next post that is not in the specified month
*/
アーカイブページの日付表記の修正
コードに日本語を直接書き込むのはあまりお行儀がよくないです…。
--- /home/socodanet/local/downloads/archive/archive.pages.inc 2010-09-25 04:00:33.000000000 +0900
+++ ./archive.pages.inc 2010-11-02 23:09:55.000000000 +0900
@@ -229,13 +229,13 @@
$title = t('Archive');
$month_names = array('', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
if ($day) {
- $title .= ' - '. t($month_names[$month]) .' '. $day .', '. $year;
+ $title .= ' - '. $year .'年 '. t($month_names[$month]) .' '. $day.'日';
}
else if ($month) {
- $title .= ' - '. t($month_names[$month]) .' '. $year;
+ $title .= ' - '. $year .'年 '.t($month_names[$month]) ;
}
else if ($year) {
- $title .= ' - '. $year;
+ $title .= ' - '. $year .'年';
}
if ($type != 'all') {
@@ -414,13 +414,13 @@
function theme_archive_separator($date_created, $separators) {
$date_sep = '';
if ($separators['year'] && $separators['month'] && $separators['day']) {
- $date_sep = format_date($date_created, 'custom', 'F jS, Y');
+ $date_sep = format_date($date_created, 'custom', 'Y年 n月 d日');
}
else if ($separators['month'] && $separators['day']) {
- $date_sep = format_date($date_created, 'custom', 'F jS');
+ $date_sep = format_date($date_created, 'custom', 'n月 d日');
}
else if ($separators['day']) {
- $date_sep = format_date($date_created, 'custom', 'F jS');
+ $date_sep = format_date($date_created, 'custom', 'n月 d日');
}
return '<h3>'. $date_sep .'</h3>';
[ツッコミを入れる]
