/[drupal]/contributions/modules/username_highlighter/username_highlighter.module
ViewVC logotype

Diff of /contributions/modules/username_highlighter/username_highlighter.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.2, Thu Jun 26 07:52:13 2008 UTC revision 1.3, Thu Jun 26 07:57:40 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2    // $Id$
3    
4    /**
5     * @file Implementation of the User name highlighter module.
6     *
7     * Provides an input filter that adds a unique background color to user names
8     * in the filtered text.
9     */
10    
11  /**  /**
12   * Implementation of hook_menu().   * Implementation of hook_menu().
# Line 90  function username_highlighter_admin() { Line 98  function username_highlighter_admin() {
98    // Add example of highlighting.    // Add example of highlighting.
99    $text = 'Lorem ipsum';    $text = 'Lorem ipsum';
100    $lorem_ipsum = explode(' ', 'lorem ipsum dolor sit amet consectetuer adipiscing elit integer viverra diam suspendisse aliquam ligula ut justo cras sodales tortor in');    $lorem_ipsum = explode(' ', 'lorem ipsum dolor sit amet consectetuer adipiscing elit integer viverra diam suspendisse aliquam ligula ut justo cras sodales tortor in');
101    $result = db_query_range('SELECT uid, name FROM {users} WHERE name != "" ORDER BY RAND()', 0, 20);    $result = db_query_range('SELECT uid, name FROM {users} WHERE name <> "" ORDER BY RAND()', 0, 20);
102    while ($user = db_fetch_object($result)) {    while ($user = db_fetch_object($result)) {
103      $text .= ' ' . $user->name;      $text .= ' '. $user->name;
104      foreach (array_rand($lorem_ipsum, rand(2, 5)) as $i) {      foreach (array_rand($lorem_ipsum, rand(2, 5)) as $i) {
105        $text .= ' ' . $lorem_ipsum[$i];        $text .= ' '. $lorem_ipsum[$i];
106      }      }
107    }    }
108    $text .= '.';    $text .= '.';
109    $form['username_highlighter_example'] = array(    $form['username_highlighter_example'] = array(
110      '#type' => 'item',      '#type' => 'item',
111      '#title' => t('Example'),      '#title' => t('Example'),
112      '#value' => '<p>' . username_highlighter_filter('process', 0, -1, $text) . '</p>',      '#value' => '<p>'. username_highlighter_filter('process', 0, -1, $text) .'</p>',
113    );    );
114    
115    return $form;    return $form;
# Line 140  function _username_highlighter_uid2color Line 148  function _username_highlighter_uid2color
148  function _username_highlighter_username_map() {  function _username_highlighter_username_map() {
149    static $username_map = NULL;    static $username_map = NULL;
150    if (!$username_map) {    if (!$username_map) {
151      $result = db_query('SELECT uid, name FROM {users} WHERE name != ""');      $result = db_query('SELECT uid, name FROM {users} WHERE name <> ""');
152      while ($user = db_fetch_object($result)) {      while ($user = db_fetch_object($result)) {
153        $color = _username_highlighter_uid2color($user->uid);        $color = _username_highlighter_uid2color($user->uid);
154        $username_map['/\\b' . $user->name . '\\b/'] = '<span style="background-color:' . $color . ';">' . $user->name . '</span>';        $username_map['/\\b'. $user->name .'\\b/'] = '<span style="background-color:'. $color .';">'. $user->name .'</span>';
155      }      }
156    }    }
157    return $username_map;    return $username_map;

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.2