array( 'msg_display_number' => '表示件数', 'msg_title' => '最近の更新', 'msg_all' => 'すべて', 'btn_prev' => '前へ', 'btn_next' => '次へ' ) ); /* // en.lng.php $messages = array( '_recentupdates_messages' => array( 'msg_display_number' => 'Event display', 'msg_all' => 'ALL', 'btn_prev' => 'Prev', 'btn_next' => 'Next' ) ); */ set_plugin_messages($messages); } function plugin_recentupdates_convert() { global $_recentupdates_messages, $_LANG; global $vars; global $date_format, $time_format, $weeklabels; static $exec_count = 1; $script = get_script_uri(); $isMax = false; $isAll = $vars['limit'] == 0 && isset($vars['limit']); $show_lines = PLUGIN_RECENTUPDATES_DEFAULT_SHOW_LINES; if (func_num_args()) { $args = func_get_args(); if (! is_numeric($args[0]) || isset($args[1])) { return PLUGIN_RECENTUPDATES_USAGE . '
'; } else { $show_lines = $args[0]; } } $isAction = false; if (strtolower($vars['plugin']) == 'recentupdates' || strtolower($vars['cmd']) == 'recentupdates') $isAction = true; $from = 1; if (isset($vars['limit'])) $show_lines = $vars['limit']; if (isset($vars['from'])) $from = $vars['from']; // int型へキャスト if (!is_int($show_lines)) $show_lines = (int) $show_lines; if (!is_int($from)) $from = (int) $from; --$from; if ($from < 0) $from = 0; // Show only N times if ($exec_count > PLUGIN_RECENTUPDATES_EXEC_LIMIT) { return '#recentupdates(): You called me too much' . '
' . "\n"; } else { ++$exec_count; } if (! file_exists(PLUGIN_RECENTUPDATES_CACHE)) { put_lastmodified(); if (! file_exists(PLUGIN_RECENTUPDATES_CACHE)) { return '#recentupdates(): ' . PLUGIN_RECENTUPDATES_CACHE . '/ not found' . '
'; } } // Cache if (! file_exists(PLUGIN_RECENTUPDATES_EXTENTION_CACHE) || filemtime(PLUGIN_RECENTUPDATES_CACHE) != filemtime(PLUGIN_RECENTUPDATES_EXTENTION_CACHE)) { $lines = file(PLUGIN_RECENTUPDATES_CACHE); pkwk_touch_file(PLUGIN_RECENTUPDATES_EXTENTION_CACHE); $fp = fopen(PLUGIN_RECENTUPDATES_EXTENTION_CACHE, 'r+') or die_message('Cannot open' . PLUGIN_RECENTUPDATES_EXTENTION_CACHE); set_file_buffer($fp, 0); flock($fp, LOCK_EX); ftruncate($fp, 0); rewind($fp); foreach ($lines as $line) { list($time, $page) = explode("\t", rtrim($line)); $page_head = file_head(get_filename($page))[0]; $author = ''; if (preg_match("/#author\(\".*?\",\".*?\",\"(.*?)\"\)/", $page_head, $matches)) { $author = $matches[1]; } fputs($fp, $time . "\t" . $page . "\t" . plugin_recentupdates_get_diff_str($page) . "\t" . $author . "\n"); } flock($fp, LOCK_UN); fclose($fp); // 最終更新をrecent.datに合わせる。 touch(PLUGIN_RECENTUPDATES_EXTENTION_CACHE, filemtime(PLUGIN_RECENTUPDATES_CACHE)); if (! file_exists(PLUGIN_RECENTUPDATES_EXTENTION_CACHE)) { return '#recentupdates(): ' . PLUGIN_RECENTUPDATES_EXTENTION_CACHE . '/ not found' . '
'; } } // 定義より大きい場合、定義値にする if ($show_lines > PLUGIN_RECENTUPDATES_LIMIT_SHOW_LINES) { $show_lines = PLUGIN_RECENTUPDATES_LIMIT_SHOW_LINES; } // Get latest N changes if ($show_lines == 0) { $lines = array_slice(file(PLUGIN_RECENTUPDATES_EXTENTION_CACHE), $from); if ($lines == FALSE) return '#recentupdates(): File can not open' . '
' . "\n"; } else { $lines_p = array_slice(file_head(PLUGIN_RECENTUPDATES_EXTENTION_CACHE, $show_lines + $from + 1), $from); $lines = array_slice($lines_p, 0, $show_lines); if ($lines == FALSE) return '#recentupdates(): File can not open' . '
' . "\n"; $next_line = array_slice($lines_p, $show_lines); if ($next_line == FALSE) $isMax = true; unset($lines_p); unset($next_line); } $page_count = 0; $fp = fopen(PLUGIN_RECENTUPDATES_CACHE, 'r'); for($page_count = 0; fgets($fp); ++$page_count); fclose($fp); if ($isAll) $show_lines = $page_count; $num_operation = ''; $move_n = round(PLUGIN_RECENTUPDATES_OPERATION_COUNT / 2); for ($c = 1;$c <= PLUGIN_RECENTUPDATES_OPERATION_COUNT; ++$c) { $n = ($from + $show_lines) / $show_lines; $disp_num = $c; if ($n > $move_n) $disp_num = $c + $n - $move_n; $f = $disp_num * $show_lines - $show_lines + 1; if ($f > $page_count) break; $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) . '">' . $disp_num . ' | '; } $num_operation = substr($num_operation, 0, -3); if ($isAll) { $operation = ''; } else { $operation = '
' . ($from > 0 ? '' . $_recentupdates_messages['btn_prev'] . ' | ' : '') . ' ' . $num_operation . ' ' . ($isMax != true ? ' | ' . $_recentupdates_messages['btn_next'] . '' : '') . '
'; } $option = '
' . $_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 | <' . ($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 | <' . ($show_lines == 100 ? 'span' : 'a' ) . ' href="' . ($isAction ? $script . '?plugin=recentupdates' : get_page_uri($vars['page'])) . '&limit=100' . (isset($vars['from']) ? '&from=' . $vars['from'] : '') . '">100 | <' . ($show_lines == 250 ? 'span' : 'a' ) . ' href="' . ($isAction ? $script . '?plugin=recentupdates' : get_page_uri($vars['page'])) . '&limit=250' . (isset($vars['from']) ? '&from=' . $vars['from'] : '') . '">250 | <' . ($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'] . ' ]
'; $date = $items = ''; foreach ($lines as $line) { list($time, $page, $diff_html, $author_tmp) = explode("\t", rtrim($line)); $_date = date($date_format, $time) . ' (' . $weeklabels[date('w', $time)] . ') '; if ($date != $_date) { // End of the day if ($date != '') $items .= '' . "\n"; // New day $date = $_date; $items .= '' . $date . '' . "\n" . '' . "\n"; return $operation . $items . $operation . $option; } function plugin_recentupdates_action() { global $_recentupdates_messages; return array('msg' => $_recentupdates_messages['msg_title'], 'body' => plugin_recentupdates_convert()); } function plugin_recentupdates_get_diff_str($page) { // 差分の文字数計算 $diff_len = 0; $diff_len_str = ''; $diff_file = DIFF_DIR . encode($page) . '.txt'; if (file_exists($diff_file)) { foreach (file($diff_file) as $line) { $head = $line[0]; if ($head == "+") { $diff_len += mb_strlen($line) - 1; } else if ($head == "-") { $diff_len -= mb_strlen($line) - 1; } } } else if (is_page($page)) { $diff_len = mb_strlen(join('', get_source($page))); } else { $diff_len = 0; } if ($diff_len == 0) $diff_len_str = '(0)'; if ($diff_len > 0) $diff_len_str = '(+' . $diff_len . ')'; if ($diff_len < 0) $diff_len_str = '(' . $diff_len . ')'; return $diff_len_str; }