Re: 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

Done.  Search phrases are in conf.php while the autolink checkbox is in
the user prefs.  Patches attached.  I sort of guessed at an appropriate
conf setting group, so feel free to change it if necessary.

Mike

Chuck Hagenbuch wrote:

| Quoting Mike Baptiste :
|
|
| >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.
|
|
| I think that would be much better. Would also alleviate any concerns you
| express below:
|
|
| >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
| "People ask me all the time what it will be like living without otters."
|  - Google, thanks to Harpers
|

- --
Mike Baptiste - MSB Networks - [email protected]
Download my GnuPG key at http://msbnetworks.net/msbnet.gpg
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE93X5Gtbf8BjvL+3ERAjqDAJ42/mJlJD3ZfFPsfL4hdQvZNrWphQCgsdrc
kxqTrbzlFLRtdD9LD/jxmf0=
=oJVs
-----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	22 Nov 2002 00:35:21 -0000
@@ -32,6 +32,8 @@
 
     function render(&$vars)
     {
+        global $prefs, $conf;
+
         $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') && $conf['prefs']['autolink_terms']) {
+            $term_regex = '/(' . $conf['prefs']['autolink_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()
conf.php.dist.patch (text/plain, 896 B)
Index: conf.php.dist
===================================================================
RCS file: /repository/whups/config/conf.php.dist,v
retrieving revision 1.12
diff -u -r1.12 conf.php.dist
--- conf.php.dist	18 Nov 2002 18:01:18 -0000	1.12
+++ conf.php.dist	22 Nov 2002 00:33:18 -0000
@@ -79,3 +79,15 @@
 // example providing a link to IMP (an email program) would be:
 // $conf['menu']['apps'] = array('imp');
 $conf['menu']['apps'] = array('logout');
+
+/**
+ ** User Preference Attributes
+ **/
+
+// Users can opt to automatically link to other tickets referenced
+// in comments.  The regex option allows you to specify one or more
+// phrases to match against along with a number (i.e. Ticket 101)
+// Note the search is NOT case sensitive.  Separate more than one
+// term with |
+// Set to a null string to disable this feature
+$conf['prefs']['autolink_terms'] = 'bug|ticket|issue';
prefs.php.dist.patch (text/plain, 1.3 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	22 Nov 2002 00:34:43 -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')
 );
 
 $prefGroups['notification'] = array(
@@ -139,4 +139,13 @@
     '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")
 );
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.