Autolink of Ticket References in Comments
Mike Baptiste <[email protected]>
| Newsgroups | gmane.comp.horde.whups |
|---|---|
| Organization | MSB Networks |
| Message-ID | <[email protected]> |
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Attached is a patch which will auto link to tickets in Whups comments when viewing ticket details. Basically you can set a sequence of search phrases that when found next to a number will create a link, this 'Ticket 67' would autolink to that ticket when clicked. I made it a user preference vs a global preference. I was on the fence about this one (I almost put it in conf.php) and opted to let the user choose. Another option might be to have the conf file contain the search regex and the user enable/disable the autolinking itself. Also, you'll note that I put the code AFTER the comment is stripped of HTML, which means someone MIGHT be able to set their search phrase in a way that lets them return HTML in ticket views - I guess I could put in a strip at the end. I wanted to put the added code higher up before htmlSpaces and enableCapitalLinks, but the Horde::link method retusn a lower case <a So any ideas on how I might structure this better, let me know. The code works as expected, buut it was more involved than I thought it would be. Mike -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQE93UUntbf8BjvL+3ERAn1sAJwKMNm3ovLN3uN8UYrxc83SCCkkuQCggufH sikf6aCZGyXh+Omt+A7h7gk= =sodO -----END PGP SIGNATURE----- -- Whups mailing list Frequently Asked Questions: http://horde.org/faq/ To unsubscribe, mail: [email protected]
comment.inc.patch
(text/plain, 1.3 KB)
Index: comment.inc
===================================================================
RCS file: /repository/whups/templates/comment.inc,v
retrieving revision 1.15
diff -u -r1.15 comment.inc
--- comment.inc 17 Nov 2002 22:29:07 -0000 1.15
+++ comment.inc 21 Nov 2002 20:32:35 -0000
@@ -32,6 +32,8 @@
function render(&$vars)
{
+ global $prefs;
+
$newstate = $vars->getVar('state_name');
$newpriority = $vars->getVar('priority_name');
@@ -61,6 +63,10 @@
$body = Text::linkUrls($body, true);
$body = Text::htmlSpaces($body);
$body = Text::enableCapitalLinks($body);
+ if ($prefs->getValue('autolink_tickets')) {
+ $term_regex = '/(' . $prefs->getValue('autolink_tickets_terms') . ')\s+(\d+)/i';
+ $body = preg_replace_callback($term_regex, array(&$this, '_autolink'), $body);
+ }
$body = nl2br($body);
?>
<tr><td>
@@ -94,6 +100,15 @@
</td></tr>
<?php
+ }
+
+ function _autolink($matches)
+ {
+
+ $url = 'details.php';
+ $url = Horde::applicationUrl(Horde::addParameter($url, 'id=' . $matches[2]));
+ $linktext = $matches[1] . ' ' . $matches[2];
+ return Horde::link($url, 'View ' . $linktext) . '<b>' . $linktext . '</b></a>';
}
function end()
prefs.php.dist.patch
(text/plain, 1.5 KB)
Index: prefs.php.dist
===================================================================
RCS file: /repository/whups/config/prefs.php.dist,v
retrieving revision 1.9
diff -u -r1.9 prefs.php.dist
--- prefs.php.dist 13 Nov 2002 03:22:20 -0000 1.9
+++ prefs.php.dist 21 Nov 2002 20:34:52 -0000
@@ -12,7 +12,7 @@
'column' => _("Other Options"),
'label' => _("Display Options"),
'desc' => _("Change display options such as the color scheme and how search results are sorted."),
- 'members' => array('sortby', 'sortdir', 'theme', 'whups_default_view', 'summary_show_requested', 'summary_show_ticket_numbers', 'report_time_format', 'show_days_ago')
+ 'members' => array('sortby', 'sortdir', 'theme', 'whups_default_view', 'summary_show_requested', 'summary_show_ticket_numbers', 'report_time_format', 'show_days_ago', 'autolink_tickets', 'autolink_tickets_terms')
);
$prefGroups['notification'] = array(
@@ -139,4 +139,21 @@
'shared' => false,
'type' => 'checkbox',
'desc' => _("Only notify me of ticket changes from other users")
+);
+
+// AutoLink to tickets references in comments
+$_prefs['autolink_tickets'] = array(
+ 'value' => 1,
+ 'locked' => false,
+ 'shared' => false,
+ 'type' => 'checkbox',
+ 'desc' => _("Autolink to other tickets in comments")
+);
+
+$_prefs['autolink_tickets_terms'] = array(
+ 'value' => 'bug|ticket|issue',
+ 'locked' => false,
+ 'shared' => false,
+ 'type' => 'text',
+ 'desc' => _("Phrases that are AutoLinked")
);