function restore_time()
 {
     $this->cachefile = CACHE_DIR . "remakepage.dat";
     if (($lines = file($this->cachefile)) === FALSE) {
         return "<p><b>timestamp cache file, {$this->cachefile}, does not exist or not readable. </b></p>";
     }
     $oldpages = array();
     $failedpages = array();
     foreach ($lines as $line) {
         $line = rtrim($line);
         list($page, $time) = csv_explode(',', $line);
         $oldpages[] = $page;
         if (is_page($page) && pkwk_touch_file(get_filename($page), $time) === false) {
             $failedpages[] = $page;
         }
     }
     put_lastmodified();
     $body = '<p>';
     $body .= '<b>Restored timestamps.</b><br />';
     $nonexists = array_diff($oldpages, get_existpages());
     if (!empty($nonexists)) {
         $body .= "<b>Following pages do not exist in current wiki,</b><br />\n";
         $body .= implode("<br />\n", $nonexists) . "<br />";
     }
     if (!empty($failedpages)) {
         $body .= "<b>Failed to restore timestamp of </b><br />\n";
         $body .= implode("<br />\n", $failedpages) . "<br />";
         $body .= "<b>Skipped.</b><br />";
     }
     $body .= '</p>';
     return $body;
 }
예제 #2
0
function lastmodified_add($update = '', $remove = '')
{
    global $maxshow, $whatsnew, $autolink, $autobasealias;
    // AutoLink implimentation needs everything, for now
    if ($autolink || $autobasealias) {
        put_lastmodified();
        // Try to (re)create ALL
        return;
    }
    if (($update == '' || check_non_list($update)) && $remove == '') {
        return;
    }
    // No need
    $file = CACHE_DIR . PKWK_MAXSHOW_CACHE;
    if (!file_exists($file)) {
        put_lastmodified();
        // Try to (re)create ALL
        return;
    }
    // Read (keep the order of the lines)
    $recent_pages = $matches = array();
    foreach (file_head($file, $maxshow + PKWK_MAXSHOW_ALLOWANCE, FALSE) as $line) {
        if (preg_match('/^([0-9]+)\\t(.+)/', $line, $matches)) {
            $recent_pages[$matches[2]] = $matches[1];
        }
    }
    // Remove if it exists inside
    if (isset($recent_pages[$update])) {
        unset($recent_pages[$update]);
    }
    if (isset($recent_pages[$remove])) {
        unset($recent_pages[$remove]);
    }
    // Add to the top: like array_unshift()
    if ($update != '' && $update != $whatsnew && !check_non_list($update)) {
        $recent_pages = array($update => get_filetime($update)) + $recent_pages;
    }
    // Check
    if (count($recent_pages) < $maxshow) {
        put_lastmodified();
        // Try to (re)create ALL
        return;
    }
    // Sort decending order of last-modification date(Pointed Question/119)
    arsort($recent_pages, SORT_NUMERIC);
    // Re-create 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);
    // Update 'RecentChanges'
    $recent_pages = array_splice($recent_pages, 0, $maxshow);
    $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 ($recent_pages as $page => $time) {
        fputs($fp, '-' . htmlspecialchars(format_date($time)) . ' - ' . '[[' . htmlspecialchars($page) . ']]' . "\n");
    }
    fputs($fp, '#norelated' . "\n");
    // :)
    ignore_user_abort($last);
    @flock($fp, LOCK_UN);
    @fclose($fp);
}
예제 #3
0
function plugin_pcomment_insert()
{
    global $vars, $now, $_title_updated, $_no_name, $_pcmt_messages;
    $refer = isset($vars['refer']) ? $vars['refer'] : '';
    $page = isset($vars['page']) ? $vars['page'] : '';
    $page = get_fullname($page, $refer);
    if (!is_pagename($page)) {
        return array('msg' => 'Invalid page name', 'body' => 'Cannot add comment', 'collided' => TRUE);
    }
    check_editable($page, true, true);
    $ret = array('msg' => $_title_updated, 'collided' => FALSE);
    $msg = str_replace('$msg', rtrim($vars['msg']), PLUGIN_PCOMMENT_FORMAT_MSG);
    $name = !isset($vars['name']) || $vars['name'] == '' ? $_no_name : $vars['name'];
    $name = $name == '' ? '' : str_replace('$name', $name, PLUGIN_PCOMMENT_FORMAT_NAME);
    $date = !isset($vars['nodate']) || $vars['nodate'] != '1' ? str_replace('$now', $now, PLUGIN_PCOMMENT_FORMAT_NOW) : '';
    if ($date != '' || $name != '') {
        $msg = str_replace("" . 'MSG' . "", $msg, PLUGIN_PCOMMENT_FORMAT_STRING);
        $msg = str_replace("" . 'NAME' . "", $name, $msg);
        $msg = str_replace("" . 'DATE' . "", $date, $msg);
    }
    $reply_hash = isset($vars['reply']) ? $vars['reply'] : '';
    if ($reply_hash || !is_page($page)) {
        $msg = preg_replace('/^\\-+/', '', $msg);
    }
    $msg = rtrim($msg);
    if (!is_page($page)) {
        $postdata = '[[' . htmlsc(strip_bracket($refer)) . ']]' . "\n\n" . '-' . $msg . "\n";
    } else {
        $postdata = get_source($page);
        $count = count($postdata);
        $digest = isset($vars['digest']) ? $vars['digest'] : '';
        if (md5(join('', $postdata)) != $digest) {
            $ret['msg'] = $_pcmt_messages['title_collided'];
            $ret['body'] = $_pcmt_messages['msg_collided'];
        }
        $start_position = 0;
        while ($start_position < $count) {
            if (preg_match('/^\\-/', $postdata[$start_position])) {
                break;
            }
            ++$start_position;
        }
        $end_position = $start_position;
        $dir = isset($vars['dir']) ? $vars['dir'] : '';
        // Find the comment to reply
        $level = 1;
        $b_reply = FALSE;
        if ($reply_hash != '') {
            while ($end_position < $count) {
                $matches = array();
                if (preg_match('/^(\\-{1,2})(?!\\-)(.*)$/', $postdata[$end_position++], $matches) && md5($matches[2]) == $reply_hash) {
                    $b_reply = TRUE;
                    $level = strlen($matches[1]) + 1;
                    while ($end_position < $count) {
                        if (preg_match('/^(\\-{1,3})(?!\\-)/', $postdata[$end_position], $matches) && strlen($matches[1]) < $level) {
                            break;
                        }
                        ++$end_position;
                    }
                    break;
                }
            }
        }
        if ($b_reply == FALSE) {
            $end_position = $dir == '0' ? $start_position : $count;
        }
        // Insert new comment
        array_splice($postdata, $end_position, 0, str_repeat('-', $level) . $msg . "\n");
        if (PLUGIN_PCOMMENT_AUTO_LOG) {
            $_count = isset($vars['count']) ? $vars['count'] : '';
            plugin_pcomment_auto_log($page, $dir, $_count, $postdata);
        }
        $postdata = join('', $postdata);
    }
    page_write($page, $postdata, PLUGIN_PCOMMENT_TIMESTAMP);
    if (PLUGIN_PCOMMENT_TIMESTAMP) {
        if ($refer != '') {
            pkwk_touch_file(get_filename($refer));
        }
        put_lastmodified();
    }
    return $ret;
}
예제 #4
0
function lastmodified_add($update = '', $remove = '')
{
    global $maxshow, $whatsnew, $autolink;
    // AutoLink implimentation needs everything, for now
    if ($autolink) {
        put_lastmodified();
        // Try to (re)create ALL
        return;
    }
    if (($update == '' || check_non_list($update)) && $remove == '') {
        return;
    }
    // No need
    $file = CACHE_DIR . PKWK_MAXSHOW_CACHE;
    if (!file_exists($file)) {
        put_lastmodified();
        // Try to (re)create ALL
        return;
    }
    // Open
    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);
    // Read (keep the order of the lines)
    $recent_pages = $matches = array();
    foreach (file_head($file, $maxshow + PKWK_MAXSHOW_ALLOWANCE, FALSE) as $line) {
        if (preg_match('/^([0-9]+)\\t(.+)/', $line, $matches)) {
            $recent_pages[$matches[2]] = $matches[1];
        }
    }
    // Remove if it exists inside
    if (isset($recent_pages[$update])) {
        unset($recent_pages[$update]);
    }
    if (isset($recent_pages[$remove])) {
        unset($recent_pages[$remove]);
    }
    // Add to the top: like array_unshift()
    if ($update != '') {
        $recent_pages = array($update => get_filetime($update)) + $recent_pages;
    }
    // Check
    $abort = count($recent_pages) < $maxshow;
    if (!$abort) {
        // Write
        ftruncate($fp, 0);
        rewind($fp);
        foreach ($recent_pages as $_page => $time) {
            fputs($fp, $time . "\t" . $_page . "\n");
        }
    }
    flock($fp, LOCK_UN);
    fclose($fp);
    if ($abort) {
        put_lastmodified();
        // Try to (re)create ALL
        return;
    }
    // ----
    // Update the page 'RecentChanges'
    $recent_pages = array_splice($recent_pages, 0, $maxshow);
    $file = get_filename($whatsnew);
    // Open
    pkwk_touch_file($file);
    $fp = fopen($file, 'r+') or die_message('Cannot open ' . htmlspecialchars($whatsnew));
    set_file_buffer($fp, 0);
    flock($fp, LOCK_EX);
    // Recreate
    ftruncate($fp, 0);
    rewind($fp);
    foreach ($recent_pages as $_page => $time) {
        fputs($fp, '-' . htmlspecialchars(format_date($time)) . ' - ' . '[[' . htmlspecialchars($_page) . ']]' . "\n");
    }
    fputs($fp, '#norelated' . "\n");
    // :)
    flock($fp, LOCK_UN);
    fclose($fp);
}
예제 #5
0
function file_write($dir,$page,$str,$notimestamp=FALSE)
{
	global $post,$update_exec;
	global $_msg_invalidiwn;
	global $notify,$notify_diff_only,$notify_to,$notify_from,$notify_subject,$notify_header;
	global $smtp_server,$smtp_auth;
	
	if (!is_pagename($page))
	{
		die_message(
			str_replace('$1',htmlspecialchars($page),
				str_replace('$2','WikiName',$_msg_invalidiwn)
			)
		);
	}
	$page = strip_bracket($page);
	$timestamp = FALSE;
	$file = $dir.encode($page).'.txt';
	
	if ($dir == DATA_DIR and $str == '' and file_exists($file))
	{
		unlink($file);
	}
	if ($str != '')
	{
		$str = preg_replace("/\r/",'',$str);
		$str = rtrim($str)."\n";
		
		if ($notimestamp and file_exists($file))
		{
			$timestamp = filemtime($file) - LOCALZONE;
		}
		
		$fp = fopen($file,'w')
			or die_message('cannot write page file or diff file or other'.htmlspecialchars($page).'<br />maybe permission is not writable or filename is too long');
		flock($fp,LOCK_EX);
		fputs($fp,$str);
		flock($fp,LOCK_UN);
		fclose($fp);
		if ($timestamp)
		{
			touch($file,$timestamp + LOCALZONE);
		}
	}
	
	// is_pageのキャッシュをクリアする。
	is_page($page,TRUE);
	
	if (!$timestamp and $dir == DATA_DIR)
	{
		put_lastmodified();
	}
	
	if ($update_exec and $dir == DATA_DIR)
	{
		system($update_exec.' > /dev/null &');
	}
	
	if ($notify and $dir == DIFF_DIR)
	{
		if ($notify_diff_only)
		{
			// 差分だけを送信する
			$str = preg_replace('/^[^-+].*\n/m','',$str);
		}
		if ($smtp_auth)
		{
			pop_before_smtp();
		}
 		$subject = str_replace('$page',$page,$notify_subject);
		ini_set('SMTP',$smtp_server);
 		mb_language(LANG);
 		mb_send_mail($notify_to,$subject,$str,$notify_header);
	}
}
예제 #6
0
 /**
  * Update recent
  * 
  * PukiWiki Version Adapter
  *
  * @param string $page
  */
 function update_recent($page)
 {
     if (is_page($page) && function_exists('lastmodified_add')) {
         lastmodified_add($page);
         // 1.4.7 or higher
     } elseif (function_exists('put_lastmodified')) {
         put_lastmodified();
     }
 }