Search comments for references to Flyspray tasks (in the format FS#???)
and make them into clickable links.

Signed-off-by: Ragnis Armus <rag...@aragnis.com>
---
 conf/config.proto   |  1 +
 web/lib/aur.inc.php | 34 +++++++++++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/conf/config.proto b/conf/config.proto
index df10b99..39257f6 100644
--- a/conf/config.proto
+++ b/conf/config.proto
@@ -33,6 +33,7 @@ log_uri = https://aur.archlinux.org/cgit/aur.git/log/?h=%s
 snapshot_uri = /cgit/aur.git/snapshot/%s.tar.gz
 enable-maintenance = 1
 maintenance-exceptions = 127.0.0.1
+fs_task_uri = https://bugs.archlinux.org/task/%d

 [notifications]
 notify-cmd = /usr/local/bin/aurweb-notify
diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php
index d58df40..418b7cc 100644
--- a/web/lib/aur.inc.php
+++ b/web/lib/aur.inc.php
@@ -557,6 +557,35 @@ function comment_by_id($comment_id) {
 }

 /**
+ * Process comment body replacing any references to tasks with an actual link
+ *
+ * @param string $text The input text
+ *
+ * @return string The text with any task references replaces with HTML links
+ */
+function parse_comment_flyspray_links($text) {
+ $matches = preg_split('/(?<=\W|^)FS#(\d+)(?=\W|$)/', $text, -1,
+ PREG_SPLIT_DELIM_CAPTURE);
+
+ $output = '';
+
+ for ($i = 0; $i < count($matches); $i++) {
+ if ($i % 2) {
+ # link the tasks
+ $url = sprintf(config_get('options', 'fs_task_uri'), $matches[$i]);
+
+ $output .= '<a href="' . htmlspecialchars($url) .
+ '" rel="nofollow">FS#' . htmlspecialchars($matches[$i]) . '</a>';
+ } else {
+ # keep everything else
+ $output .= $matches[$i];
+ }
+ }
+
+ return $output;
+}
+
+/**
  * Process submitted comments so any links can be followed
  *
  * @param string $comment Raw user submitted package comment
@@ -579,7 +608,10 @@ function parse_comment($comment) {
  }
  else {
  # convert everything else
- $html .= nl2br(htmlspecialchars($matches[$i]));
+ $value = nl2br(htmlspecialchars($matches[$i]));
+ $value = parse_comment_flyspray_links($value);
+
+ $html .= $value;
  }
  }

-- 
2.12.2

Reply via email to