From 43b7deb581ab6c31309e376408d8dc36879a05de Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Fri, 23 Dec 2005 20:30:57 +0000 Subject: [PATCH] Added format_log_message() to SVNLib --- browse.php | 2 +- diff.php | 2 +- includes/svnlib.php | 63 +++++++++++++++++++++++++++++++++++++++++++++ log.php | 2 +- view.php | 2 +- 5 files changed, 67 insertions(+), 4 deletions(-) diff --git a/browse.php b/browse.php index a9ef900..ebe2a10 100644 --- a/browse.php +++ b/browse.php @@ -49,7 +49,7 @@ if ($show['prev']) $revinfo = $viewsvn->svn->common->fetch_log($path, $viewsvn->paths->fetch_rev_num()); -$revinfo['message_clean'] = nl2br(htmlspecialchars($revinfo['message'])); +$revinfo['message_clean'] = $viewsvn->svn->format_log_message($revinfo['message']); $listing = $viewsvn->svn->ls($repos, $relpath, $viewsvn->paths->fetch_rev_num()); diff --git a/diff.php b/diff.php index ce500c5..067cbdb 100644 --- a/diff.php +++ b/diff.php @@ -62,7 +62,7 @@ if ($show['fullchangeset']) $log = $viewsvn->svn->common->fetch_log($path, $high); -$log['message_clean'] = nl2br(htmlspecialchars($log['message'])); +$log['message_clean'] = $viewsvn->svn->format_log_message($log['message']); $files = $viewsvn->svn->common->construct_file_changes($log['files'], $repos, $high); diff --git a/includes/svnlib.php b/includes/svnlib.php index e2a7283..a36ec77 100644 --- a/includes/svnlib.php +++ b/includes/svnlib.php @@ -110,6 +110,69 @@ class SVNLib return $string; } + /** + * Formats a SVN log message + * + * @access public + * + * @param string Unformatted log message + * + * @return string Output-ready log message + */ + function format_log_message($message) + { + global $viewsvn; + + $message = $viewsvn->entity_encode($message); + + $message = preg_replace('#(^| )r([0-9]*)( |$)#e', '$viewsvn->paths->out("diff.php" . $viewsvn->paths->fetch_rev_str(true, \2, 0), $viewsvn->paths->fetch_repos())', $message); + + $list = false; + $lines = explode("\n", $message); + $message = ''; + foreach ($lines AS $line) + { + if (preg_match('#^\s*?(\*|\-)\s?(.*)#', $line, $matches)) + { + if ($list) + { + $message .= '
  • ' . $matches[2] . '
  • '; + } + else + { + $message .= ''; + $message .= $line; + } + else + { + $message .= $line; + $message .= '
    '; + } + $list = false; + } + + $message .= "\n"; + } + + if ($list) + { + $message .= ''; + } + + $message = preg_replace('#(
    )*$#', '', $message); + + return $message; + } + /** * Counts the spaces and replaces two or more ones * diff --git a/log.php b/log.php index 236d76a..4041c1b 100644 --- a/log.php +++ b/log.php @@ -56,7 +56,7 @@ foreach ($logs->fetch() AS $log) $link['diffprev'] = $viewsvn->paths->out('diff.php' . $viewsvn->paths->fetch_rev_str(true, $log['rev'], $prev), $path); } - $log['message_clean'] = nl2br(htmlspecialchars($log['message'])); + $log['message_clean'] = $viewsvn->svn->format_log_message($log['message']); eval('$nodes .= "' . $template->fetch('log_node') . '";'); } diff --git a/view.php b/view.php index 2489e4d..3c49e76 100644 --- a/view.php +++ b/view.php @@ -49,7 +49,7 @@ if ($show['prev']) $logmsg = $viewsvn->svn->common->fetch_log($path, $viewsvn->paths->fetch_rev_num()); unset($logmsg['files']); -$logmsg['message_clean'] = nl2br(htmlspecialchars($logmsg['message'])); +$logmsg['message_clean'] = $viewsvn->svn->format_log_message($logmsg['message']); $catdata = implode("\n", $viewsvn->svn->cat($repos, $relpath, $viewsvn->paths->fetch_rev_num())); -- 2.43.5