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 . '' . ($f == $from + 1 ? 'span' : 'a' ) . '> | ';
}
$num_operation = substr($num_operation, 0, -3);
if ($isAll) {
$operation = '';
} else {
$operation = '