From b43b4703365ed6229d7f59b5bdc96910a8bfd656 Mon Sep 17 00:00:00 2001 From: danij Date: Fri, 15 Jun 2012 18:55:41 +0100 Subject: [PATCH] Homepage|Build Repository: Format hyperlinks in commit titles When producing the commit log HTML doc also process hyperlinks in commit titles (as well as the message body). Also improved HTML processing so that "internal" links (i.e., other URIs on the dengine.net host) are not marked with the "link-external" CSS class. --- web/plugins/buildrepository/commitutils.php | 30 +++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/web/plugins/buildrepository/commitutils.php b/web/plugins/buildrepository/commitutils.php index 88cdf6d061..92e175246c 100644 --- a/web/plugins/buildrepository/commitutils.php +++ b/web/plugins/buildrepository/commitutils.php @@ -22,6 +22,7 @@ includeGuard('commitutils.php'); require_once(DIR_INCLUDES.'/utilities.inc.php'); +require_once(DIR_CLASSES.'/url.class.php'); require_once('buildevent.class.php'); function addCommitToGroup(&$groups, $groupName, &$commit) @@ -67,18 +68,36 @@ function groupBuildCommits(&$build, &$groups) function make_pretty_hyperlink($matches) { - $uri = implode('', array_slice($matches, 1)); - return generateHyperlinkHTML($uri, 40, 'link-external'); + global $FrontController; + + $uri = new Url(implode('', array_slice($matches, 1))); + $homeUri = new Url($FrontController->homeURL()); + + $isExternal = ($uri->host() !== $homeUri->host()); + if(!$isExternal) + { + $uri->setScheme()->setHost(); + } + + return generateHyperlinkHTML($uri, 40, $isExternal? 'link-external' : NULL); } -function formatCommitMessageHTML($msg) +function formatCommitHTML($msg) { if(strcasecmp(gettype($msg), 'string')) return $msg; // Process the commit message, replacing web URIs with clickable links. htmlspecialchars($msg); - $msg = preg_replace_callback("/([^A-z0-9])(http|ftp|https)([\:\/\/])([^\\s]+)/", + $msg = preg_replace_callback("/([^A-z0-9_])(http|ftp|https)([\:\/\/])([^\\s]+)/", "make_pretty_hyperlink", $msg); + return $msg; +} + +function formatCommitMessageHTML($msg) +{ + if(strcasecmp(gettype($msg), 'string')) return $msg; + + $msg = formatCommitHTML($msg); $msg = nl2br($msg); return $msg; } @@ -89,6 +108,7 @@ function outputCommitHTML(&$commit) throw new Exception('Invalid commit argument, array expected'); // Format the commit message for HTML output. + $title = formatCommitHTML($commit['title']); $message = formatCommitMessageHTML($commit['message']); $haveMessage = (bool)(strlen($message) > 0); @@ -116,7 +136,7 @@ function outputCommitHTML(&$commit) // Ouput HTML for the commit. ?>

> by

> by