Пример #1
0
function put_lastmodified()
{
    global $maxshow, $whatsnew, $autolink;
    $qm = get_qm();
    if (PKWK_READONLY) {
        return;
    }
    // Do nothing
    // Get WHOLE page list
    $pages = get_existpages();
    // Check ALL filetime
    $recent_pages = array();
    foreach ($pages as $page) {
        if ($page != $whatsnew && !check_non_list($page)) {
            $recent_pages[$page] = get_filetime($page);
        }
    }
    // Sort decending order of last-modification date
    arsort($recent_pages, SORT_NUMERIC);
    // Cut unused lines
    // BugTrack2/179: array_splice() will break integer keys in hashtable
    $count = $maxshow + PKWK_MAXSHOW_ALLOWANCE;
    $_recent = array();
    foreach ($recent_pages as $key => $value) {
        unset($recent_pages[$key]);
        $_recent[$key] = $value;
        if (--$count < 1) {
            break;
        }
    }
    $recent_pages =& $_recent;
    // Re-create PKWK_MAXSHOW_CACHE
    $file = CACHE_DIR . PKWK_MAXSHOW_CACHE;
    pkwk_touch_file($file);
    $fp = fopen($file, 'r+') or die_message($qm->replace('fmt_err_open_cachedir', PKWK_MAXSHOW_CACHE));
    set_file_buffer($fp, 0);
    flock($fp, LOCK_EX);
    ftruncate($fp, 0);
    rewind($fp);
    foreach ($recent_pages as $page => $time) {
        fputs($fp, $time . "\t" . $page . "\n");
    }
    flock($fp, LOCK_UN);
    fclose($fp);
    // Create RecentChanges
    $file = get_filename($whatsnew);
    pkwk_touch_file($file);
    $fp = fopen($file, 'r+') or die_message($qm->replace('file.err_cannot_open', h($whatsnew)));
    set_file_buffer($fp, 0);
    flock($fp, LOCK_EX);
    ftruncate($fp, 0);
    rewind($fp);
    foreach (array_keys($recent_pages) as $page) {
        $time = $recent_pages[$page];
        $s_lastmod = htmlspecialchars(format_date($time));
        $s_page = htmlspecialchars($page);
        $pagetile = get_page_title($page);
        fputs($fp, '-' . $s_lastmod . ' - [[' . $pagetile . '>' . $s_page . ']]' . "\n");
    }
    fputs($fp, '#freeze' . "\n");
    fputs($fp, '#norelated' . "\n");
    fputs($fp, '#nofollow' . "\n");
    flock($fp, LOCK_UN);
    fclose($fp);
    // For AutoLink
    if ($autolink) {
        list($pattern, $pattern_a, $forceignorelist) = get_autolink_pattern($pages);
        $file = CACHE_DIR . PKWK_AUTOLINK_REGEX_CACHE;
        pkwk_touch_file($file);
        $fp = fopen($file, 'r+') or die_message($qm->replace('fmt_err_open_cachedir', PKWK_AUTOLINK_REGEX_CACHE));
        set_file_buffer($fp, 0);
        flock($fp, LOCK_EX);
        ftruncate($fp, 0);
        rewind($fp);
        fputs($fp, $pattern . "\n");
        fputs($fp, $pattern_a . "\n");
        fputs($fp, join("\t", $forceignorelist) . "\n");
        flock($fp, LOCK_UN);
        fclose($fp);
    }
}
Пример #2
0
function put_lastmodified()
{
    global $maxshow, $whatsnew, $autolink, $autobasealias;
    // if (PKWK_READONLY) return; // Do nothing
    if (auth::check_role('readonly')) {
        return;
    }
    // Do nothing
    // Get WHOLE page list
    $pages = get_existpages();
    // Check ALL filetime
    $recent_pages = array();
    foreach ($pages as $page) {
        if ($page != $whatsnew && !check_non_list($page)) {
            $recent_pages[$page] = get_filetime($page);
        }
    }
    // Sort decending order of last-modification date
    arsort($recent_pages, SORT_NUMERIC);
    // Cut unused lines
    // BugTrack2/179: array_splice() will break integer keys in hashtable
    $count = $maxshow + PKWK_MAXSHOW_ALLOWANCE;
    $_recent = array();
    foreach ($recent_pages as $key => $value) {
        unset($recent_pages[$key]);
        $_recent[$key] = $value;
        if (--$count < 1) {
            break;
        }
    }
    $recent_pages =& $_recent;
    // Re-create PKWK_MAXSHOW_CACHE
    $file = CACHE_DIR . PKWK_MAXSHOW_CACHE;
    pkwk_touch_file($file);
    $fp = fopen($file, 'r+') or die_message('Cannot open' . 'CACHE_DIR/' . PKWK_MAXSHOW_CACHE);
    set_file_buffer($fp, 0);
    @flock($fp, LOCK_EX);
    $last = ignore_user_abort(1);
    ftruncate($fp, 0);
    rewind($fp);
    foreach ($recent_pages as $page => $time) {
        fputs($fp, $time . "\t" . $page . "\n");
    }
    ignore_user_abort($last);
    @flock($fp, LOCK_UN);
    @fclose($fp);
    // Create RecentChanges
    $file = get_filename($whatsnew);
    pkwk_touch_file($file);
    $fp = fopen($file, 'r+') or die_message('Cannot open ' . htmlspecialchars($whatsnew));
    set_file_buffer($fp, 0);
    @flock($fp, LOCK_EX);
    $last = ignore_user_abort(1);
    ftruncate($fp, 0);
    rewind($fp);
    foreach (array_keys($recent_pages) as $page) {
        $time = $recent_pages[$page];
        // $s_lastmod = htmlspecialchars(format_date($time));
        $s_lastmod = '&epoch(' . $time . ');';
        $s_page = htmlspecialchars($page);
        fputs($fp, '-' . $s_lastmod . ' - [[' . $s_page . ']]' . "\n");
    }
    fputs($fp, '#norelated' . "\n");
    // :)
    ignore_user_abort($last);
    @flock($fp, LOCK_UN);
    @fclose($fp);
    // For AutoLink
    if ($autolink) {
        autolink_pattern_write(CACHE_DIR . PKWK_AUTOLINK_REGEX_CACHE, get_autolink_pattern($pages, $autolink));
    }
    // AutoBaseAlias
    if ($autobasealias) {
        autobasealias_write(CACHE_DIR . PKWK_AUTOBASEALIAS_CACHE, $pages);
    }
}
Пример #3
0
function put_lastmodified()
{
	global $maxshow,$whatsnew,$non_list,$autolink;

	$pages = get_existpages();
	$recent_pages = array();
	foreach($pages as $page)
	{
		if ($page != $whatsnew and !preg_match("/$non_list/",$page))
		{
			$recent_pages[$page] = get_filetime($page);
		}
	}
	
	//時刻降順でソート
	arsort($recent_pages,SORT_NUMERIC);
	
	// create recent.dat (for recent.inc.php)
	$fp = fopen(CACHE_DIR.'recent.dat','w')
		or die_message('cannot write cache file '.CACHE_DIR.'recent.dat<br />maybe permission is not writable or filename is too long');
	flock($fp,LOCK_EX);
	foreach ($recent_pages as $page=>$time)
	{
		fputs($fp,"$time\t$page\n");
	}
	flock($fp,LOCK_UN);
	fclose($fp);

	// create RecentChanges
	$fp = fopen(get_filename($whatsnew),'w')
		or die_message('cannot write page file '.htmlspecialchars($whatsnew).'<br />maybe permission is not writable or filename is too long');
	flock($fp,LOCK_EX);
	foreach (array_splice($recent_pages,0,$maxshow) as $page=>$time)
	{
		$s_lastmod = htmlspecialchars(format_date($time));
		$s_page = htmlspecialchars($page);
		fputs($fp, "-$s_lastmod - [[$s_page]]\n");
	}
	fputs($fp,"#norelated\n"); // :)
	flock($fp,LOCK_UN);
	fclose($fp);
	
	// for autolink
	if ($autolink)
	{
		list($pattern,$pattern_a,$forceignorelist) = get_autolink_pattern($pages);
		
		$fp = fopen(CACHE_DIR.'autolink.dat','w')
			or die_message('cannot write autolink file '.CACHE_DIR.'/autolink.dat<br />maybe permission is not writable');
		flock($fp,LOCK_EX);
		fputs($fp,$pattern."\n");
		fputs($fp,$pattern_a."\n");
		fputs($fp,join("\t",$forceignorelist)."\n");
		flock($fp,LOCK_UN);
		fclose($fp);
	}
}