OSDN Git Service

BugTrack2/57: PLUGIN_CALENDAR_VIEWER_DATE_FORMAT allows using date format you want
authorhenoheno <henoheno>
Sun, 5 Jun 2005 12:39:55 +0000 (21:39 +0900)
committerhenoheno <henoheno>
Sun, 5 Jun 2005 12:39:55 +0000 (21:39 +0900)
plugin/calendar_viewer.inc.php

index 4311d54..0b6eb9b 100644 (file)
@@ -1,12 +1,20 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone
-// $Id: calendar_viewer.inc.php,v 1.32 2005/06/04 04:08:57 henoheno Exp $
+// $Id: calendar_viewer.inc.php,v 1.33 2005/06/05 12:39:55 henoheno Exp $
 //
 // Calendar viewer plugin - List pages that calendar/calnedar2 plugin created
 // (Based on calendar and recent plugin)
 
-// Use 'pagename/2004-12-30' => '2004/12/30' for page title
-define('PLUGIN_CALENDAR_VIEWER_SHOW_DATE_ONLY', 1); // 1 = Shorten
+// Page title's date format
+//  * See PHP date() manual for detail
+//  * '$\w' = weeklabel defined in $_msg_week
+define('PLUGIN_CALENDAR_VIEWER_DATE_FORMAT',
+       //      FALSE         // 'pagename/2004-02-09' -- As is
+       //      'D, d M, Y'    // 'Mon, 09 Feb, 2004'
+       //      'F d, Y'      // 'February 09, 2004'
+       //      '[Y-m-d]'     // '[2004-02-09]'
+               'Y/n/j ($\w)' // '2004/2/9 (Mon)'
+       );
 
 // ----
 
@@ -41,7 +49,7 @@ define('PLUGIN_CALENDAR_VIEWER_USAGE',
 
 function plugin_calendar_viewer_convert()
 {
-       global $vars, $get, $post, $script;
+       global $vars, $get, $post, $script, $weeklabels;
        global $_msg_calendar_viewer_right, $_msg_calendar_viewer_left;
        global $_msg_calendar_viewer_restrict, $_err_calendar_viewer_param2;
 
@@ -165,8 +173,18 @@ function plugin_calendar_viewer_convert()
 
                $r_page = rawurlencode($page);
 
-               if (PLUGIN_CALENDAR_VIEWER_SHOW_DATE_ONLY) {
-                       $s_page = htmlspecialchars(strtr(basename($page), $date_sep, '/'));
+               if (PLUGIN_CALENDAR_VIEWER_DATE_FORMAT !== FALSE) {
+                       $time = strtotime(basename($page)); // $date_sep must be assumed '-' or ''!
+                       if ($time == -1) {
+                               $s_page = htmlspecialchars($page); // Failed. Why?
+                       } else {
+                               $week   = $weeklabels[date('w', $time)];
+                               $s_page = htmlspecialchars(str_replace(
+                                               array('$w' ),
+                                               array($week),
+                                               date(PLUGIN_CALENDAR_VIEWER_DATE_FORMAT, $time)
+                                       ));
+                       }
                } else {
                        $s_page = htmlspecialchars($page);
                }
@@ -310,5 +328,4 @@ function plugin_calendar_viewer_isValidDate($aStr, $aSepList = '-/ .')
                return FALSE;
        }
 }
-
 ?>