修訂 | 4bde0eec54d27d1f108257b13e8ae23937a9373c (tree) |
---|---|
時間 | 2022-01-24 01:16:43 |
作者 | hai-fun <haifun129@gmai...> |
Commiter | hai-fun |
recentupdates plugin
@@ -1,89 +0,0 @@ | ||
1 | -<?php | |
2 | -// PukiWiki - Yet another WikiWikiWeb clone | |
3 | -// recent.inc.php | |
4 | -// Copyright | |
5 | -// 2002-2017 PukiWiki Development Team | |
6 | -// 2002 Y.MASUI http://masui.net/pukiwiki/ masui@masui.net | |
7 | -// License: GPL v2 or (at your option) any later version | |
8 | -// | |
9 | -// Recent plugin -- Show RecentChanges list | |
10 | -// * Usually used at 'MenuBar' page | |
11 | -// * Also used at special-page, without no #recnet at 'MenuBar' | |
12 | - | |
13 | -// Default number of 'Show latest N changes' | |
14 | -define('PLUGIN_RECENT_DEFAULT_LINES', 10); | |
15 | - | |
16 | -// Limit number of executions | |
17 | -define('PLUGIN_RECENT_EXEC_LIMIT', 2); // N times per one output | |
18 | - | |
19 | -// ---- | |
20 | - | |
21 | -define('PLUGIN_RECENT_USAGE', '#recent(number-to-show)'); | |
22 | - | |
23 | -// Place of the cache of 'RecentChanges' | |
24 | -define('PLUGIN_RECENT_CACHE', CACHE_DIR . 'recent.dat'); | |
25 | - | |
26 | -function plugin_recent_convert() | |
27 | -{ | |
28 | - global $vars, $date_format, $_recent_plugin_frame; | |
29 | - static $exec_count = 1; | |
30 | - | |
31 | - $recent_lines = PLUGIN_RECENT_DEFAULT_LINES; | |
32 | - if (func_num_args()) { | |
33 | - $args = func_get_args(); | |
34 | - if (! is_numeric($args[0]) || isset($args[1])) { | |
35 | - return PLUGIN_RECENT_USAGE . '<br />'; | |
36 | - } else { | |
37 | - $recent_lines = $args[0]; | |
38 | - } | |
39 | - } | |
40 | - | |
41 | - // Show only N times | |
42 | - if ($exec_count > PLUGIN_RECENT_EXEC_LIMIT) { | |
43 | - return '#recent(): You called me too much' . '<br />' . "\n"; | |
44 | - } else { | |
45 | - ++$exec_count; | |
46 | - } | |
47 | - | |
48 | - if (! file_exists(PLUGIN_RECENT_CACHE)) { | |
49 | - put_lastmodified(); | |
50 | - if (! file_exists(PLUGIN_RECENT_CACHE)) { | |
51 | - return '#recent(): Cache file of RecentChanges not found' . '<br />'; | |
52 | - } | |
53 | - } | |
54 | - | |
55 | - // Get latest N changes | |
56 | - $lines = file_head(PLUGIN_RECENT_CACHE, $recent_lines); | |
57 | - if ($lines == FALSE) return '#recent(): File can not open' . '<br />' . "\n"; | |
58 | - $date = $items = ''; | |
59 | - foreach ($lines as $line) { | |
60 | - list($time, $page) = explode("\t", rtrim($line)); | |
61 | - | |
62 | - $_date = get_date($date_format, $time); | |
63 | - if ($date != $_date) { | |
64 | - // End of the day | |
65 | - if ($date != '') $items .= '</ul>' . "\n"; | |
66 | - | |
67 | - // New day | |
68 | - $date = $_date; | |
69 | - $items .= '<strong>' . $date . '</strong>' . "\n" . | |
70 | - '<ul class="recent_list">' . "\n"; | |
71 | - } | |
72 | - | |
73 | - $s_page = htmlsc($page); | |
74 | - | |
75 | - if ($page === $vars['page']) { | |
76 | - // No need to link to the page you just read, or notify where you just read | |
77 | - $items .= ' <li>' . $s_page . '</li>' . "\n"; | |
78 | - } else { | |
79 | - $attrs = get_page_link_a_attrs($page); | |
80 | - $items .= ' <li><a href="' . get_page_uri($page) . '" class="' . | |
81 | - $attrs['class'] . '" data-mtime="' . $attrs['data_mtime'] . | |
82 | - '">' . $s_page . '</a></li>' . "\n"; | |
83 | - } | |
84 | - } | |
85 | - // End of the day | |
86 | - if ($date != '') $items .= '</ul>' . "\n"; | |
87 | - | |
88 | - return sprintf($_recent_plugin_frame, count($lines), $items); | |
89 | -} |
@@ -0,0 +1,276 @@ | ||
1 | +<?php | |
2 | +// $Id: recentupdates.inc.php,v 1.1 2022/01/07 01:54:29 はいふん Exp $ | |
3 | + | |
4 | +// Origin: | |
5 | +// PukiWiki - Yet another WikiWikiWeb clone | |
6 | +// recent.inc.php | |
7 | +// Copyright | |
8 | +// 2002-2017 PukiWiki Development Team | |
9 | +// 2002 Y.MASUI http://masui.net/pukiwiki/ masui@masui.net | |
10 | +// License: GPL v2 or (at your option) any later version | |
11 | +// | |
12 | +// Recent plugin -- Show RecentChanges list | |
13 | +// * Usually used at 'MenuBar' page | |
14 | +// * Also used at special-page, without no #recnet at 'MenuBar' | |
15 | + | |
16 | +// Default event display | |
17 | +define('PLUGIN_RECENTUPDATES_DEFAULT_SHOW_LINES', 50); | |
18 | + | |
19 | +// max of event display | |
20 | +define('PLUGIN_RECENTUPDATES_LIMIT_SHOW_LINES', 500); | |
21 | + | |
22 | +// number of Page of operation | |
23 | +define('PLUGIN_RECENTUPDATES_OPERATION_COUNT', 9); | |
24 | + | |
25 | +// Limit number of executions | |
26 | +define('PLUGIN_RECENTUPDATES_EXEC_LIMIT', 3); // N times per one output | |
27 | + | |
28 | +// Display author of page | |
29 | +define('PLUGIN_RECENTUPDATES_DISPLAY_AUTHOR', TRUE); | |
30 | + | |
31 | +// ---- | |
32 | + | |
33 | +define('PLUGIN_RECENTUPDATES_USAGE', '#recentupdates(number-to-show)'); | |
34 | + | |
35 | +// Place of the cache of 'RecentChanges' | |
36 | +define('PLUGIN_RECENTUPDATES_CACHE', CACHE_DIR . 'recent.dat'); | |
37 | +define('PLUGIN_RECENTUPDATES_EXTENTION_CACHE', CACHE_DIR . 'recentupdates.dat'); | |
38 | + | |
39 | +function plugin_recentupdates_init() { | |
40 | + // ja.lng.php | |
41 | + $messages = array( | |
42 | + '_recentupdates_messages' => array( | |
43 | + 'msg_display_number' => '表示件数', | |
44 | + 'msg_title' => '最近の更新', | |
45 | + 'msg_all' => 'すべて', | |
46 | + 'btn_prev' => '前へ', | |
47 | + 'btn_next' => '次へ' | |
48 | + ) | |
49 | + ); | |
50 | + | |
51 | + /* | |
52 | + // en.lng.php | |
53 | + $messages = array( | |
54 | + '_recentupdates_messages' => array( | |
55 | + 'msg_display_number' => 'Event display', | |
56 | + 'msg_all' => 'ALL', | |
57 | + 'btn_prev' => 'Prev', | |
58 | + 'btn_next' => 'Next' | |
59 | + ) | |
60 | + ); | |
61 | + */ | |
62 | + | |
63 | + set_plugin_messages($messages); | |
64 | +} | |
65 | + | |
66 | +function plugin_recentupdates_convert() | |
67 | +{ | |
68 | + global $_recentupdates_messages, $_LANG; | |
69 | + global $vars; | |
70 | + global $date_format, $time_format, $weeklabels; | |
71 | + static $exec_count = 1; | |
72 | + $script = get_script_uri(); | |
73 | + | |
74 | + $isMax = false; | |
75 | + $isAll = $vars['limit'] == 0 && isset($vars['limit']); | |
76 | + | |
77 | + $show_lines = PLUGIN_RECENTUPDATES_DEFAULT_SHOW_LINES; | |
78 | + if (func_num_args()) { | |
79 | + $args = func_get_args(); | |
80 | + if (! is_numeric($args[0]) || isset($args[1])) { | |
81 | + return PLUGIN_RECENTUPDATES_USAGE . '<br />'; | |
82 | + } else { | |
83 | + $show_lines = $args[0]; | |
84 | + } | |
85 | + } | |
86 | + | |
87 | + $isAction = false; | |
88 | + if (strtolower($vars['plugin']) == 'recentupdates' || strtolower($vars['cmd']) == 'recentupdates') $isAction = true; | |
89 | + | |
90 | + $from = 1; | |
91 | + if (isset($vars['limit'])) $show_lines = $vars['limit']; | |
92 | + if (isset($vars['from'])) $from = $vars['from']; | |
93 | + // int型へキャスト | |
94 | + if (!is_int($show_lines)) $show_lines = (int) $show_lines; | |
95 | + if (!is_int($from)) $from = (int) $from; | |
96 | + --$from; | |
97 | + if ($from < 0) $from = 0; | |
98 | + | |
99 | + // Show only N times | |
100 | + if ($exec_count > PLUGIN_RECENTUPDATES_EXEC_LIMIT) { | |
101 | + return '#recentupdates(): You called me too much' . '<br />' . "\n"; | |
102 | + } else { | |
103 | + ++$exec_count; | |
104 | + } | |
105 | + | |
106 | + if (! file_exists(PLUGIN_RECENTUPDATES_CACHE)) { | |
107 | + put_lastmodified(); | |
108 | + if (! file_exists(PLUGIN_RECENTUPDATES_CACHE)) { | |
109 | + return '#recentupdates(): ' . PLUGIN_RECENTUPDATES_CACHE . '/ not found' . '<br />'; | |
110 | + } | |
111 | + } | |
112 | + // Cache | |
113 | + if (! file_exists(PLUGIN_RECENTUPDATES_EXTENTION_CACHE) || filemtime(PLUGIN_RECENTUPDATES_CACHE) != filemtime(PLUGIN_RECENTUPDATES_EXTENTION_CACHE)) { | |
114 | + $lines = file(PLUGIN_RECENTUPDATES_CACHE); | |
115 | + pkwk_touch_file(PLUGIN_RECENTUPDATES_EXTENTION_CACHE); | |
116 | + $fp = fopen(PLUGIN_RECENTUPDATES_EXTENTION_CACHE, 'r+') or | |
117 | + die_message('Cannot open' . PLUGIN_RECENTUPDATES_EXTENTION_CACHE); | |
118 | + set_file_buffer($fp, 0); | |
119 | + flock($fp, LOCK_EX); | |
120 | + ftruncate($fp, 0); | |
121 | + rewind($fp); | |
122 | + foreach ($lines as $line) { | |
123 | + list($time, $page) = explode("\t", rtrim($line)); | |
124 | + $page_head = file_head(get_filename($page))[0]; | |
125 | + $author = ''; | |
126 | + if (preg_match("/#author\(\".*?\",\".*?\",\"(.*?)\"\)/", $page_head, $matches)) { | |
127 | + $author = $matches[1]; | |
128 | + } | |
129 | + fputs($fp, $time . "\t" . $page . "\t" . plugin_recentupdates_get_diff_str($page) . "\t" . $author . "\n"); | |
130 | + } | |
131 | + flock($fp, LOCK_UN); | |
132 | + fclose($fp); | |
133 | + | |
134 | + // 最終更新をrecent.datに合わせる。 | |
135 | + touch(PLUGIN_RECENTUPDATES_EXTENTION_CACHE, filemtime(PLUGIN_RECENTUPDATES_CACHE)); | |
136 | + if (! file_exists(PLUGIN_RECENTUPDATES_EXTENTION_CACHE)) { | |
137 | + return '#recentupdates(): ' . PLUGIN_RECENTUPDATES_EXTENTION_CACHE . '/ not found' . '<br />'; | |
138 | + } | |
139 | + } | |
140 | + | |
141 | + // 定義より大きい場合、定義値にする | |
142 | + if ($show_lines > PLUGIN_RECENTUPDATES_LIMIT_SHOW_LINES) { | |
143 | + $show_lines = PLUGIN_RECENTUPDATES_LIMIT_SHOW_LINES; | |
144 | + } | |
145 | + | |
146 | + // Get latest N changes | |
147 | + if ($show_lines == 0) { | |
148 | + $lines = array_slice(file(PLUGIN_RECENTUPDATES_EXTENTION_CACHE), $from); | |
149 | + | |
150 | + if ($lines == FALSE) return '#recentupdates(): File can not open' . '<br />' . "\n"; | |
151 | + } else { | |
152 | + $lines_p = array_slice(file_head(PLUGIN_RECENTUPDATES_EXTENTION_CACHE, $show_lines + $from + 1), $from); | |
153 | + $lines = array_slice($lines_p, 0, $show_lines); | |
154 | + if ($lines == FALSE) return '#recentupdates(): File can not open' . '<br />' . "\n"; | |
155 | + $next_line = array_slice($lines_p, $show_lines); | |
156 | + if ($next_line == FALSE) $isMax = true; | |
157 | + unset($lines_p); | |
158 | + unset($next_line); | |
159 | + } | |
160 | + $page_count = 0; | |
161 | + $fp = fopen(PLUGIN_RECENTUPDATES_CACHE, 'r'); | |
162 | + for($page_count = 0; fgets($fp); ++$page_count); | |
163 | + fclose($fp); | |
164 | + if ($isAll) $show_lines = $page_count; | |
165 | + $num_operation = ''; | |
166 | + $move_n = round(PLUGIN_RECENTUPDATES_OPERATION_COUNT / 2); | |
167 | + for ($c = 1;$c <= PLUGIN_RECENTUPDATES_OPERATION_COUNT; ++$c) { | |
168 | + $n = ($from + $show_lines) / $show_lines; | |
169 | + $disp_num = $c; | |
170 | + if ($n > $move_n) $disp_num = $c + $n - $move_n; | |
171 | + $f = $disp_num * $show_lines - $show_lines + 1; | |
172 | + if ($f > $page_count) break; | |
173 | + $num_operation .= '<' . ($f == $from + 1 ? 'span' : 'a' ) . ' href="' . ($isAction ? $script . '?plugin=recentupdates' : get_page_uri($vars['page'])) . (isset($vars['limit']) ? '&limit=' . $vars['limit'] : '') . '&from=' . ($f) . '"><strong>' . $disp_num . '</strong></' . ($f == $from + 1 ? 'span' : 'a' ) . '> | '; | |
174 | + } | |
175 | + $num_operation = substr($num_operation, 0, -3); | |
176 | + if ($isAll) { | |
177 | + $operation = ''; | |
178 | + } else { | |
179 | + $operation = ' | |
180 | + <div style="text-align:center"> | |
181 | + ' . ($from > 0 ? '<a href="' . ($isAction ? $script . '?plugin=recentupdates' : get_page_uri($vars['page'])) . (isset($vars['limit']) ? '&limit=' . $vars['limit'] : '') . '&from=' . ($from + 1 - $show_lines) . '"><strong>' . $_recentupdates_messages['btn_prev'] . '</strong></a> | ' : '') . ' | |
182 | + ' . $num_operation . ' | |
183 | + ' . ($isMax != true ? ' | <a href="' . ($isAction ? $script . '?plugin=recentupdates' : get_page_uri($vars['page'])) . (isset($vars['limit']) ? '&limit=' . $vars['limit'] : '') . '&from=' . ($from + 1 + $show_lines) . '"><strong>' . $_recentupdates_messages['btn_next'] . '</strong></a>' : '') . ' | |
184 | + </div> | |
185 | + '; | |
186 | + } | |
187 | + $option = ' | |
188 | + <div> | |
189 | + ' . $_recentupdates_messages['msg_display_number'] . ': [ <' . ($show_lines == 25 ? 'span' : 'a' ) . ' href="' . ($isAction ? $script . '?plugin=recentupdates' : get_page_uri($vars['page'])) . '&limit=25' . (isset($vars['from']) ? '&from=' . $vars['from'] : '') . '">25</a> | | |
190 | + <' . ($show_lines == 50 ? 'span' : 'a' ) . ' href="' . ($isAction ? $script . '?plugin=recentupdates' : ($isAction ? $script . '?plugin=recentupdates' : get_page_uri($vars['page']))) . '&limit=50' . (isset($vars['from']) ? '&from=' . $vars['from'] : '') . '">50</a> | | |
191 | + <' . ($show_lines == 100 ? 'span' : 'a' ) . ' href="' . ($isAction ? $script . '?plugin=recentupdates' : get_page_uri($vars['page'])) . '&limit=100' . (isset($vars['from']) ? '&from=' . $vars['from'] : '') . '">100</a> | | |
192 | + <' . ($show_lines == 250 ? 'span' : 'a' ) . ' href="' . ($isAction ? $script . '?plugin=recentupdates' : get_page_uri($vars['page'])) . '&limit=250' . (isset($vars['from']) ? '&from=' . $vars['from'] : '') . '">250</a> | | |
193 | + <' . ($vars['limit'] == 0 && isset($vars['limit']) ? 'span' : 'a' ) . ' href="' . ($isAction ? $script . '?plugin=recentupdates' : get_page_uri($vars['page'])) . '&limit=0' . (isset($vars['from']) ? '&from=' . $vars['from'] : '') . '">' . $_recentupdates_messages['msg_all'] . '</a> ] | |
194 | + </div> | |
195 | + '; | |
196 | + $date = $items = ''; | |
197 | + foreach ($lines as $line) { | |
198 | + list($time, $page, $diff_html, $author_tmp) = explode("\t", rtrim($line)); | |
199 | + $_date = date($date_format, $time) . ' (' . $weeklabels[date('w', $time)] . ') '; | |
200 | + if ($date != $_date) { | |
201 | + // End of the day | |
202 | + if ($date != '') $items .= '</ul>' . "\n"; | |
203 | + | |
204 | + // New day | |
205 | + $date = $_date; | |
206 | + $items .= '<strong>' . $date . '</strong>' . "\n" . | |
207 | + '<ul class="recent_list">' . "\n"; | |
208 | + } | |
209 | + $tag_plugin = ""; | |
210 | + if (exist_plugin("tag")) { | |
211 | + $tagfile = CACHE_DIR . encode($page) . "_page.tag"; | |
212 | + if (file_exists($tagfile)) { | |
213 | + $tags = implode(', ', array_map( | |
214 | + function($str) { | |
215 | + return '<a href="' . $script . '?cmd=taglist&tag=' . $str . '">' . htmlsc($str) . "</a>"; | |
216 | + }, | |
217 | + array_map("rtrim", file($tagfile)) | |
218 | + )); | |
219 | + $tag_plugin = ' (Tag: ' . $tags . ")"; | |
220 | + unset($tags); | |
221 | + } | |
222 | + } | |
223 | + $author = ""; | |
224 | + if (PLUGIN_RECENTUPDATES_DISPLAY_AUTHOR) { | |
225 | + $author = $author_tmp; | |
226 | + } | |
227 | + $s_page = htmlsc($page); | |
228 | + $attrs = get_page_link_a_attrs($page); | |
229 | + $items .= ' <li> | |
230 | + ' . date($time_format, $time) . ' - ' . '[ <a href="' . $script . '?cmd=diff&page=' . $s_page . '">' . $_LANG['skin']['diff'] . '</a>' . ' | <a href="' . $script . '?cmd=backup&page=' . $s_page . '">' . $_LANG['skin']['backup'] . '</a> ] ' . | |
231 | + '<a href="' . get_page_uri($page) . '" class="' . | |
232 | + $attrs['class'] . '" data-mtime="' . $attrs['data_mtime'] . | |
233 | + '">' . $s_page . '</a>' . | |
234 | + ' -- ' . | |
235 | + ($author == "" ? "" : make_pagelink($author) . ' ') . | |
236 | + $diff_html . | |
237 | + $tag_plugin . | |
238 | + '</li>' . "\n"; | |
239 | + } | |
240 | + // End of the day | |
241 | + if ($date != '') $items .= '</ul>' . "\n"; | |
242 | + | |
243 | + return $operation . $items . $operation . $option; | |
244 | +} | |
245 | + | |
246 | +function plugin_recentupdates_action() | |
247 | +{ | |
248 | + global $_recentupdates_messages; | |
249 | + return array('msg' => $_recentupdates_messages['msg_title'], 'body' => plugin_recentupdates_convert()); | |
250 | +} | |
251 | + | |
252 | +function plugin_recentupdates_get_diff_str($page) { | |
253 | + // 差分の文字数計算 | |
254 | + $diff_len = 0; | |
255 | + $diff_len_str = ''; | |
256 | + $diff_file = DIFF_DIR . encode($page) . '.txt'; | |
257 | + if (file_exists($diff_file)) { | |
258 | + foreach (file($diff_file) as $line) { | |
259 | + $head = $line[0]; | |
260 | + if ($head == "+") { | |
261 | + $diff_len += mb_strlen($line) - 1; | |
262 | + } | |
263 | + else if ($head == "-") { | |
264 | + $diff_len -= mb_strlen($line) - 1; | |
265 | + } | |
266 | + } | |
267 | + } else if (is_page($page)) { | |
268 | + $diff_len = mb_strlen(join('', get_source($page))); | |
269 | + } else { | |
270 | + $diff_len = 0; | |
271 | + } | |
272 | + if ($diff_len == 0) $diff_len_str = '<span class="diff_unchanged">(0)</span>'; | |
273 | + if ($diff_len > 0) $diff_len_str = '<span class="diff_added">(+' . $diff_len . ')</span>'; | |
274 | + if ($diff_len < 0) $diff_len_str = '<span class="diff_removed">(' . $diff_len . ')</span>'; | |
275 | + return $diff_len_str; | |
276 | +} | |
\ No newline at end of file |