Revisión | f9c56c546e812b5d567c36862985c55b58a26619 (tree) |
---|---|
Tiempo | 2004-08-10 22:39:25 |
Autor | henoheno <henoheno> |
Commiter | henoheno |
Cleanup. Added comments
@@ -1,17 +1,20 @@ | ||
1 | 1 | <?php |
2 | 2 | /* |
3 | 3 | * PukiWiki calendar_viewerプラグイン |
4 | - * $Id: calendar_viewer.inc.php,v 1.20 2004/08/10 13:18:05 henoheno Exp $ | |
4 | + * $Id: calendar_viewer.inc.php,v 1.21 2004/08/10 13:39:25 henoheno Exp $ | |
5 | 5 | * calendarrecentプラグインを元に作成 |
6 | 6 | */ |
7 | 7 | |
8 | 8 | /** |
9 | 9 | * 概要 |
10 | 10 | calendarプラグインやcalendar2プラグインで作成したページを一覧表示するためのプラグインです。 |
11 | + | |
11 | 12 | * 使い方 |
12 | 13 | #calendar_viewer(pagename,(yyyy-mm|n|this),[mode],[separater]) |
14 | + | |
13 | 15 | ** pagename |
14 | 16 | calendar or calendar2プラグインを記述してるページ名 |
17 | + | |
15 | 18 | ** (yyyy-mm|n|this) |
16 | 19 | - yyyy-mm |
17 | 20 | -- yyyy-mmで指定した年月のページを一覧表示 |
@@ -19,6 +22,7 @@ | ||
19 | 22 | -- n件の一覧表示 |
20 | 23 | - this |
21 | 24 | -- 今月のページを一覧表示 |
25 | + | |
22 | 26 | ** [mode] |
23 | 27 | 省略可能です。省略時のデフォルトはpast |
24 | 28 | - past |
@@ -27,6 +31,7 @@ | ||
27 | 31 | -- 今日以降のページの一覧表示モード。イベント予定やスケジュール向き |
28 | 32 | - view |
29 | 33 | -- 過去から未来への一覧表示モード。表示抑止するページはありません。 |
34 | + | |
30 | 35 | ** [separater] |
31 | 36 | - 年月日を区切るセパレータを指定。 |
32 | 37 | - 省略可能。デフォルトは-。(calendar2なら省略でOK) |
@@ -48,7 +53,7 @@ function plugin_calendar_viewer_convert() | ||
48 | 53 | $limit_page = 7; // 表示する件数制限 |
49 | 54 | $date_YM = ''; // 一覧表示する年月 |
50 | 55 | $mode = 'past'; // 動作モード |
51 | - $date_sep = '-'; // 日付のセパレータ calendar2なら'-' calendarなら'' | |
56 | + $date_sep = '-'; // 日付のセパレータ calendar2なら '-', calendarなら '' | |
52 | 57 | |
53 | 58 | |
54 | 59 | // 引数の確認 |
@@ -63,22 +68,22 @@ function plugin_calendar_viewer_convert() | ||
63 | 68 | } |
64 | 69 | if (preg_match('/[0-9]{4}' . $date_sep . '[0-9]{2}/', $func_vars_array[1])) { |
65 | 70 | // 指定年月の一覧表示 |
66 | - $page_YM = $func_vars_array[1]; | |
67 | - $limit_base = 0; | |
68 | - $limit_page = 31; // 手抜き。31日分をリミットとする。 | |
71 | + $page_YM = $func_vars_array[1]; | |
72 | + $limit_base = 0; | |
73 | + $limit_page = 31; // 手抜き。31日分をリミットとする。 | |
69 | 74 | } else if (preg_match('/this/si', $func_vars_array[1])) { |
70 | 75 | // 今月の一覧表示 |
71 | - $page_YM = get_date('Y' . $date_sep . 'm'); | |
72 | - $limit_base = 0; | |
73 | - $limit_page = 31; | |
76 | + $page_YM = get_date('Y' . $date_sep . 'm'); | |
77 | + $limit_base = 0; | |
78 | + $limit_page = 31; | |
74 | 79 | } else if (preg_match('/^[0-9]+$/', $func_vars_array[1])) { |
75 | 80 | // n日分表示 |
76 | - $page_YM = ''; | |
81 | + $page_YM = ''; | |
77 | 82 | $limit_page = $func_vars_array[1]; |
78 | 83 | $limit_base = 0; |
79 | 84 | $limit_pitch = $func_vars_array[1]; |
80 | 85 | } else if (preg_match('/([0-9]+)\*([0-9]+)/', $func_vars_array[1], $reg_array)) { |
81 | - $page_YM = ''; | |
86 | + $page_YM = ''; | |
82 | 87 | $limit_base = $reg_array[1]; |
83 | 88 | $limit_page = $reg_array[1] + $reg_array[2]; |
84 | 89 | $limit_pitch = $reg_array[2]; |
@@ -86,7 +91,8 @@ function plugin_calendar_viewer_convert() | ||
86 | 91 | return $_err_calendar_viewer_param2; |
87 | 92 | } |
88 | 93 | |
89 | - if (isset($func_vars_array[2]) && preg_match('/^(past|view|future)$/si', $func_vars_array[2])) { | |
94 | + if (isset($func_vars_array[2]) && | |
95 | + preg_match('/^(past|view|future)$/si', $func_vars_array[2])) { | |
90 | 96 | // モード指定 |
91 | 97 | $mode = $func_vars_array[2]; |
92 | 98 | } |
@@ -95,14 +101,14 @@ function plugin_calendar_viewer_convert() | ||
95 | 101 | // 一覧表示するページ名とファイル名のパターン ファイル名には年月を含む |
96 | 102 | if ($pagename == '') { |
97 | 103 | // pagename無しのyyyy-mm-ddに対応するための処理 |
98 | - $pagepattern = ''; | |
104 | + $pagepattern = ''; | |
99 | 105 | $pagepattern_len = 0; |
100 | - $filepattern = encode($page_YM); | |
106 | + $filepattern = encode($page_YM); | |
101 | 107 | $filepattern_len = strlen($filepattern); |
102 | 108 | } else { |
103 | - $pagepattern = strip_bracket($pagename) . '/'; | |
109 | + $pagepattern = strip_bracket($pagename) . '/'; | |
104 | 110 | $pagepattern_len = strlen($pagepattern); |
105 | - $filepattern = encode($pagepattern . $page_YM); | |
111 | + $filepattern = encode($pagepattern . $page_YM); | |
106 | 112 | $filepattern_len = strlen($filepattern); |
107 | 113 | } |
108 | 114 |
@@ -114,38 +120,43 @@ function plugin_calendar_viewer_convert() | ||
114 | 120 | $pagelist = array(); |
115 | 121 | if ($dir = @opendir(DATA_DIR)) { |
116 | 122 | $_date = get_date('Y' . $date_sep . 'm' . $date_sep . 'd'); |
117 | - while($file = readdir($dir)) | |
118 | - { | |
123 | + while($file = readdir($dir)) { | |
119 | 124 | if ($file == '..' || $file == '.') continue; |
120 | 125 | if (substr($file, 0, $filepattern_len) != $filepattern) continue; |
126 | + | |
121 | 127 | //echo "OK"; |
122 | 128 | $page = decode(trim(preg_replace('/\.txt$/', ' ', $file))); |
129 | + | |
123 | 130 | // $pageがカレンダー形式なのかチェック デフォルトでは、 yyyy-mm-dd |
124 | 131 | $page = strip_bracket($page); |
125 | 132 | if (plugin_calendar_viewer_isValidDate(substr($page, $pagepattern_len), $date_sep) == false) continue; |
126 | 133 | |
127 | 134 | // mode毎に別条件ではじく |
135 | + | |
128 | 136 | // past modeでは未来のページはNG |
129 | - if (((substr($page, $pagepattern_len)) > $_date) && ($mode == 'past'))continue; | |
137 | + if (((substr($page, $pagepattern_len)) > $_date) && | |
138 | + ($mode == 'past')) continue; | |
139 | + | |
130 | 140 | // future modeでは過去のページはNG |
131 | - if (((substr($page, $pagepattern_len)) < $_date) && ($mode == 'future'))continue; | |
141 | + if (((substr($page, $pagepattern_len)) < $_date) && | |
142 | + ($mode == 'future')) continue; | |
143 | + | |
132 | 144 | // view modeならall OK |
133 | 145 | $pagelist[] = $page; |
134 | 146 | } |
135 | 147 | } |
136 | 148 | closedir($dir); |
137 | 149 | //echo count($pagelist); |
138 | - // ここからインクルード開始 | |
139 | 150 | |
151 | + // ここからインクルード開始 | |
140 | 152 | $tmppage = $vars['page']; |
141 | 153 | $return_body = ''; |
154 | + | |
142 | 155 | // まずソート |
143 | 156 | if ($mode == 'past') { |
144 | - // past modeでは新→旧 | |
145 | - rsort ($pagelist); | |
157 | + rsort($pagelist); // past modeでは新→旧 | |
146 | 158 | } else { |
147 | - // view mode と future mode では、旧→新 | |
148 | - sort ($pagelist); | |
159 | + sort($pagelist); // view mode と future mode では、旧→新 | |
149 | 160 | } |
150 | 161 | |
151 | 162 | // $limit_pageの件数までインクルード |
@@ -156,17 +167,17 @@ function plugin_calendar_viewer_convert() | ||
156 | 167 | |
157 | 168 | $get['page'] = $post['page'] = $vars['page'] = $page; |
158 | 169 | |
159 | - // 現状で閲覧許可がある場合だけ表示する | |
160 | - if (check_readable($page, false, false)) { | |
161 | - $body = convert_html(get_source($page)); | |
162 | - } else { | |
163 | - $body = str_replace('$1', $page, $_msg_calendar_viewer_restrict); | |
164 | - } | |
170 | + // 現状で閲覧許可がある場合だけ表示する | |
171 | + if (check_readable($page, false, false)) { | |
172 | + $body = convert_html(get_source($page)); | |
173 | + } else { | |
174 | + $body = str_replace('$1', $page, $_msg_calendar_viewer_restrict); | |
175 | + } | |
165 | 176 | |
166 | 177 | $r_page = rawurlencode($page); |
167 | 178 | $s_page = htmlspecialchars($page); |
168 | - $link = "<a href=\"$script?cmd=edit&page=$r_page\">$s_page</a>"; | |
169 | - $head = "<h1>$link</h1>\n"; | |
179 | + $link = "<a href=\"$script?cmd=edit&page=$r_page\">$s_page</a>"; | |
180 | + $head = "<h1>$link</h1>\n"; | |
170 | 181 | $return_body .= $head . $body; |
171 | 182 | |
172 | 183 | ++$tmp; |
@@ -179,10 +190,11 @@ function plugin_calendar_viewer_convert() | ||
179 | 190 | if ($page_YM != '') { |
180 | 191 | // 年月表示時 |
181 | 192 | $date_sep_len = strlen($date_sep); |
182 | - $this_year = substr($page_YM, 0, 4); | |
183 | - $this_month = substr($page_YM, 4 + $date_sep_len, 2); | |
193 | + $this_year = substr($page_YM, 0, 4); | |
194 | + $this_month = substr($page_YM, 4 + $date_sep_len, 2); | |
195 | + | |
184 | 196 | // 次月 |
185 | - $next_year = $this_year; | |
197 | + $next_year = $this_year; | |
186 | 198 | $next_month = $this_month + 1; |
187 | 199 | if ($next_month > 12) { |
188 | 200 | ++$next_year; |
@@ -199,15 +211,15 @@ function plugin_calendar_viewer_convert() | ||
199 | 211 | } |
200 | 212 | $prev_YM = sprintf('%04d%s%02d', $prev_year, $date_sep, $prev_month); |
201 | 213 | if ($mode == 'past') { |
202 | - $right_YM = $prev_YM; | |
203 | - $right_text = $prev_YM . '>>'; | |
204 | - $left_YM = $next_YM; | |
205 | - $left_text = '<<' . $next_YM; | |
214 | + $right_YM = $prev_YM; | |
215 | + $right_text = $prev_YM . '>>'; // >> | |
216 | + $left_YM = $next_YM; | |
217 | + $left_text = '<<' . $next_YM; // << | |
206 | 218 | } else { |
207 | - $left_YM = $prev_YM; | |
208 | - $left_text = '<<' . $prev_YM; | |
209 | - $right_YM = $next_YM; | |
210 | - $right_text = $next_YM . '>>'; | |
219 | + $left_YM = $prev_YM; | |
220 | + $left_text = '<<' . $prev_YM; // << | |
221 | + $right_YM = $next_YM; | |
222 | + $right_text = $next_YM . '>>'; // >> | |
211 | 223 | } |
212 | 224 | } else { |
213 | 225 | // n件表示時 |
@@ -215,12 +227,12 @@ function plugin_calendar_viewer_convert() | ||
215 | 227 | $right_YM = ''; |
216 | 228 | } else { |
217 | 229 | $right_base = $limit_base + $limit_pitch; |
218 | - $right_YM = $right_base . '*' . $limit_pitch; | |
230 | + $right_YM = $right_base . '*' . $limit_pitch; | |
219 | 231 | $right_text = sprintf($_msg_calendar_viewer_right, $limit_pitch); |
220 | 232 | } |
221 | 233 | $left_base = $limit_base - $limit_pitch; |
222 | 234 | if ($left_base >= 0) { |
223 | - $left_YM = $left_base . '*' . $limit_pitch; | |
235 | + $left_YM = $left_base . '*' . $limit_pitch; | |
224 | 236 | $left_text = sprintf($_msg_calendar_viewer_left, $limit_pitch); |
225 | 237 | |
226 | 238 | } else { |