$postdata = plugin_bugtrack_template($base, $summary, $name, $priority,
$state, $category, $version, $body);
- $id = $jump = 1;
- $page = $base . '/' . sprintf(PLUGIN_BUGTRACK_NUMBER_FORMAT, $id);
- while (is_page($page)) {
- $id = $jump;
- $jump += 50;
- $page = $base . '/' . sprintf(PLUGIN_BUGTRACK_NUMBER_FORMAT, $jump);
+ $page_list = plugin_bugtrack_get_page_list($base, false);
+ usort($page_list, '_plugin_bugtrack_list_paganame_compare');
+ if (count($page_list) == 0) {
+ $id = 1;
+ } else {
+ $latest_page = $page_list[count($page_list) - 1]['name'];
+ $id = intval(substr($latest_page, strlen($base) + 1)) + 1;
}
$page = $base . '/' . sprintf(PLUGIN_BUGTRACK_NUMBER_FORMAT, $id);
- while (is_page($page))
- $page = $base . '/' . sprintf(PLUGIN_BUGTRACK_NUMBER_FORMAT, ++$id);
if ($pagename == '') {
page_write($page, $postdata);
return strnatcmp($a['name'], $b['name']);
}
-function __pkwk_ctype_digit($s) {
- static $ctype_digits_exists;
- if (!isset($ctype_digits_exists)) {
- $ctype_digits_exists = function_exists('ctype_digit');
- }
- if ($ctype_digits_exists) {
- return ctype_digit($s);
+
+/**
+ * Get page list for "$page/"
+ */
+function plugin_bugtrack_get_page_list($page, $needs_filetime) {
+ $page_list = array();
+ $pattern = $page . '/';
+ $pattern_len = strlen($pattern);
+ foreach (get_existpages() as $p) {
+ if (strncmp($p, $pattern, $pattern_len) === 0 && pkwk_ctype_digit(substr($p, $pattern_len))) {
+ if ($needs_filetime) {
+ $page_list[] = array('name'=>$p,'filetime'=>get_filetime($p));
+ } else {
+ $page_list[] = array('name'=>$p);
+ }
+ }
}
- return preg_match('/^[0-9]+$/', $s) ? true : false;
+ return $page_list;
}
/**
if (is_pagename($_page)) $page = $_page;
}
$data = array();
- $page_list = array();
- $pattern = $page . '/';
- $pattern_len = strlen($pattern);
- foreach (get_existpages() as $p) {
- if (strncmp($p, $pattern, $pattern_len) === 0 && __pkwk_ctype_digit(substr($p, $pattern_len))) {
- $page_list[] = array('name'=>$p,'filetime'=>get_filetime($p));
- }
- }
+ $page_list = plugin_bugtrack_get_page_list($page, true);
usort($page_list, '_plugin_bugtrack_list_paganame_compare');
$count_list = count($_plugin_bugtrack['state_list']);
$data_map = array();
// Cache management
$data_updated = true;
$cache_filepath = CACHE_DIR . encode($page) . '.bugtrack';
- $json_cached = file_get_contents($cache_filepath);
+ $json_cached = pkwk_file_get_contents($cache_filepath);
if ($json_cached) {
$wrapdata = json_decode($json_cached);
if (is_object($wrapdata)) {
}
$json = array('refreshed_at'=>$refreshed_at, 'pages'=>$data, 'version'=>$cache_format_version);
$cache_body = json_encode($json, JSON_UNESCAPED_UNICODE + JSON_UNESCAPED_SLASHES);
- file_put_contents($cache_filepath, $cache_body);
+ file_put_contents($cache_filepath, $cache_body, LOCK_EX);
}
}
$table = array();