? Entries.Log
Index: username_highlighter.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/username_highlighter/username_highlighter.info,v
retrieving revision 1.2
diff -u -p -r1.2 username_highlighter.info
--- username_highlighter.info	24 Jul 2009 13:31:34 -0000	1.2
+++ username_highlighter.info	28 Jul 2009 07:17:42 -0000
@@ -1,5 +1,6 @@
 ; $Id: username_highlighter.info,v 1.2 2009/07/24 13:31:34 soxofaan Exp $
 name = "User name highlighter"
-description = "Provides an input filter that highlights the user names of the site users."
+description = "Provides highlighting of user names."
+dependencies[] = mentions
 core = 6.x
 package = "Filters"
Index: username_highlighter.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/username_highlighter/username_highlighter.module,v
retrieving revision 1.6
diff -u -p -r1.6 username_highlighter.module
--- username_highlighter.module	24 Jul 2009 14:18:15 -0000	1.6
+++ username_highlighter.module	28 Jul 2009 07:17:43 -0000
@@ -2,7 +2,8 @@
 // $Id: username_highlighter.module,v 1.6 2009/07/24 14:18:15 soxofaan Exp $
 
 /**
- * @file Implementation of the User name highlighter module.
+ * @file
+ * Implementation of the User name highlighter module.
  *
  * Provides an input filter that adds a unique background color to user names
  * in the filtered text.
@@ -24,41 +25,13 @@ function username_highlighter_menu() {
   return $items;
 }
 
-
-/**
- * Implementation of hook_filter().
- */
-function username_highlighter_filter($op, $delta = 0, $format = -1, $text = '') {
-  switch ($op) {
-
-    case 'list':
-      return array(0 => t('User name highlighter'));
-
-    case 'description':
-      return t('Highlights each user name with a unique color.');
-
-    case 'settings':
-      return NULL;
-
-    case 'prepare':
-      return $text;
-
-    case 'process':
-      if ($delta == 0) {
-        $username_map = _username_highlighter_username_map();
-        return preg_replace(array_keys($username_map), array_values($username_map), $text);
-      }
-
-    default:
-      return $text;
-  }
-}
-
 /**
- * Implementation of hook_filter_tips().
+ * Implementation of hook_theme_registry_alter().
  */
-function username_highlighter_filter_tips($delta, $format, $long = FALSE) {
-  return t('User names will be highlighted.');
+function username_highlighter_theme_registry_alter(&$theme_registry) {
+  $theme_registry['mentions']['theme path'] = drupal_get_path('module', 'username_highlighter');
+  $theme_registry['mentions']['function'] = 'theme_username_highlighter_mentions';
+  $theme_registry['mentions']['theme paths'][0] = drupal_get_path('module', 'username_highlighter');
 }
 
 /**
@@ -91,13 +64,12 @@ function username_highlighter_admin() {
   // Make it a settings form.
   $form = system_settings_form($form);
 
-
   // Add example of highlighting.
   $text = 'Lorem ipsum';
   $lorem_ipsum = explode(' ', 'lorem ipsum dolor sit amet consectetuer adipiscing elit integer viverra diam suspendisse aliquam ligula ut justo cras sodales tortor in');
   $result = db_query_range('SELECT uid, name FROM {users} WHERE name <> "" ORDER BY RAND()', 0, 20);
   while ($user = db_fetch_object($result)) {
-    $text .= ' '. $user->name;
+    $text .= ' '. theme('mentions_input', $user->name);
     foreach (array_rand($lorem_ipsum, rand(2, 5)) as $i) {
       $text .= ' '. $lorem_ipsum[$i];
     }
@@ -106,7 +78,7 @@ function username_highlighter_admin() {
   $form['username_highlighter_example'] = array(
     '#type' => 'item',
     '#title' => t('Example'),
-    '#value' => '<p>'. username_highlighter_filter('process', 0, -1, $text) .'</p>',
+    '#value' => '<p>'. mentions_filter('process', 0, -1, $text) .'</p>',
   );
 
   return $form;
@@ -138,29 +110,6 @@ function _username_highlighter_uid2color
   return _username_highlighter_hsv2rgbhexcode($hue, $sat, $val);
 }
 
-
-/**
- * Helper function for fetching the user name replacements.
- */
-function _username_highlighter_username_map() {
-  static $username_map = NULL;
-  if (!$username_map) {
-    $result = db_query('SELECT uid, name FROM {users} WHERE name <> ""');
-    while ($user = db_fetch_object($result)) {
-      $color = _username_highlighter_uid2color($user->uid);
-      $username_map['/\\b'. $user->name .'\\b/'] =
-        l($user->name, 'user/' . $user->uid,
-          array('attributes' => array(
-            'class' => 'user-name-highlighter user-name-highlighter-uid-'. $user->uid,
-            'style' => 'background-color:'. $color .';')
-          )
-        );
-    }
-  }
-  return $username_map;
-}
-
-
 /**
  * Helper function for HSV to RGB hex code conversion.
  * @param $h the hue, in range [0-360]
@@ -169,12 +118,32 @@ function _username_highlighter_username_
  */
 function _username_highlighter_hsv2rgbhexcode($h, $s, $v) {
   // Map hue to the piecewise linear R, G, B curves in the range [0-1] first.
-  $r = min(1.0, max(0.0, abs($h-180.0)/60.0 - 1));
-  $g = min(1.0, max(0.0, 2 - abs($h-120.0)/60.0));
-  $b = min(1.0, max(0.0, 2 - abs($h-240.0)/60.0));
+  $r = min(1.0, max(0.0, abs($h - 180.0) / 60.0 - 1));
+  $g = min(1.0, max(0.0, 2 - abs($h - 120.0) / 60.0));
+  $b = min(1.0, max(0.0, 2 - abs($h - 240.0) / 60.0));
   // Rescale dynamic range, considering value and saturation.
-  $r = min(255, max(0, (int)(256 * ($r*$v + (1.0-$r)*(1.0-$s)*$v))));
-  $g = min(255, max(0, (int)(256 * ($g*$v + (1.0-$g)*(1.0-$s)*$v))));
-  $b = min(255, max(0, (int)(256 * ($b*$v + (1.0-$b)*(1.0-$s)*$v))));
+  $r = min(255, max(0, (int)(256 * ($r * $v + (1.0 - $r) * (1.0 - $s) * $v))));
+  $g = min(255, max(0, (int)(256 * ($g * $v + (1.0 - $g) * (1.0 - $s) * $v))));
+  $b = min(255, max(0, (int)(256 * ($b * $v + (1.0 - $b) * (1.0 - $s) * $v))));
   return sprintf('#%02X%02X%02X', $r, $g, $b);
 }
+
+/**
+ * Return a '@username' link to user's profile.
+ *
+ * @param $user
+ *   A Drupal user account.
+ */
+function theme_username_highlighter_mentions($user) {
+  $text = !module_exists('token')
+    ? $user->name
+    : token_replace(variable_get('mentions_output_content', '[user]'), 'user', $user);
+
+  $attributes = array(
+    'class' => 'mentions mentions-'. $user->uid,
+    'style' => 'background-color: '. _username_highlighter_uid2color($user->uid),
+    'title' => $text,
+  );
+
+  return l(variable_get('mentions_output_prefix', '@') . $text . variable_get('mentions_output_suffix', ''), 'user/'. $user->uid, array('attributes' => $attributes));
+}
