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

Diff of /contributions/modules/false_account/false_account.module

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

revision 1.11, Wed Oct 15 16:20:08 2008 UTC revision 1.12, Wed Oct 15 16:37:32 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: false_account.module,v 1.10 2008/08/25 15:21:54 introfini Exp $  // $Id: false_account.module,v 1.10 2008/08/25 15:21:54 introfini Exp $
3    
4    /**
5     * @file
6     * Use this module to detect false accounts on your site
7     */
8    
9  define('FALSE_ACCOUNT_DEFAULT', 0);  define('FALSE_ACCOUNT_DEFAULT', 0);
10  define('FALSE_ACCOUNT_WHITELISTED', 1);  define('FALSE_ACCOUNT_WHITELISTED', 1);
11  define('FALSE_ACCOUNT_BLOCKED', 2);  define('FALSE_ACCOUNT_BLOCKED', 2);
# Line 22  function false_account_user($op, &$edit, Line 27  function false_account_user($op, &$edit,
27            $cid, FALSE_ACCOUNT_BLOCKED            $cid, FALSE_ACCOUNT_BLOCKED
28          ));          ));
29          if ($count) {          if ($count) {
30            watchdog('false account', 'Blocked: '. $cid, WATCHDOG_NOTICE);            watchdog('false account', 'Blocked: %cid',  array('%cid' => $cid), WATCHDOG_NOTICE);
31            drupal_goto(variable_get('false_account_redirect', '<front>'));            drupal_goto(variable_get('false_account_redirect', '<front>'));
32          }          }
33        }        }
# Line 65  function false_account_user($op, &$edit, Line 70  function false_account_user($op, &$edit,
70        break;        break;
71      case 'view':      case 'view':
72        if (user_access('manage false account detector')) {        if (user_access('manage false account detector')) {
73          $res = db_query('SELECT cid FROM {false_accounts} WHERE uid = %d', $account->uid);          $res = db_query('
74          if (db_num_rows($res) > 0) {            SELECT cid
75                                          while ($res_cid = db_fetch_object($res)) {            FROM {false_accounts}
76                                                  $ors[] = 'cid = "'. $res_cid->cid .'"';            WHERE uid = %d',
77                                          }            $account->uid
78                                          $or = implode(' OR ', $ors);          );
79                                          $sql = "SELECT * FROM {false_accounts} WHERE " . $or;  
80            $num_rows = db_result(db_query('
81                                          $header = array(            SELECT COUNT(cid)
82                                                  array('data' => t('User Accounts')),            FROM {false_accounts}
83                                                  array('data' => t('Created'), 'field' => 'created', 'sort' => 'desc'),            WHERE uid = %d',
84                                          );            $account->uid
85                                          $result= pager_query($sql . tablesort_sql($header), 50, 0, NULL);          ));
86                                          $rows = array();  
87            if ($num_rows > 0) {
88                                          $cookies = array();            while ($res_cid = db_fetch_object($res)) {
89                $ors[] = 'cid = "'. $res_cid->cid .'"';
90                                          while ($cookie = db_fetch_object($result)) {            }
91                                                  if (array_key_exists($cookie->cid, $cookies)) {            $or = implode(' OR ', $ors);
92                                                          array_push($cookies[$cookie->cid]['users'], $cookie->uid);            $sql = "SELECT * FROM {false_accounts} WHERE " . $or;
93                                                  }  
94                                                  else {            $header = array(
95                                                          $cookies[$cookie->cid] = array();              array('data' => t('User Accounts')),
96                                                          $cookies[$cookie->cid]['users'] = array();              array('data' => t('Created'), 'field' => 'created', 'sort' => 'desc'),
97                                                          array_push($cookies[$cookie->cid]['users'], $cookie->uid);            );
98                                                          $cookies[$cookie->cid]['created'] = $cookie->created;            $result= pager_query($sql . tablesort_sql($header), 50, 0, NULL);
99                                                  }            $rows = array();
100                                          }  
101              $cookies = array();
102                                          $items['fad'] = array(  
103                                                  'value' => _false_account_build_user_table($header, $cookies, $account->uid),            while ($cookie = db_fetch_object($result)) {
104                                          );              if (array_key_exists($cookie->cid, $cookies)) {
105                  array_push($cookies[$cookie->cid]['users'], $cookie->uid);
106                                          return array(t('False Account') => $items);              }
107                                  }              else {
108                                  else {                $cookies[$cookie->cid] = array();
109                                    $items['fad'] = array(                $cookies[$cookie->cid]['users'] = array();
110                                                  'value' => t('No false accounts detected.'),                array_push($cookies[$cookie->cid]['users'], $cookie->uid);
111                                          );                $cookies[$cookie->cid]['created'] = $cookie->created;
112                                          return array(t('False Account') => $items);              }
113                                  }            }
114    
115              $account->content['fad'] = array(
116                '#type' => 'user_profile_category',
117                '#title' => t('False Account'),
118                'table' => array(
119                  '#type' => 'user_profile_item',
120                  '#value' => _false_account_build_user_table($header, $cookies, $account->uid)),
121                '#weight' => -10
122              );
123            }
124            else {
125              $account->content['fad'] = array(
126                '#type' => 'user_profile_category',
127                '#title' => t('False Account'),
128                'table' => array(
129                  '#type' => 'user_profile_item',
130                  '#title' => t('No false accounts detected.')),
131                '#weight' => -10
132              );
133            }
134        }        }
135        break;        break;
136    }    }
137  }  }
138    
139  function false_account_menu($may_cache) {  
140    $access = user_access('manage false account detector');  /**
141    if ($may_cache) {   * Implementation of hook_menu().
142      $items[] = array(   */
143        'path' => 'admin/user/false_account',  function false_account_menu() {
144        'title' => t('False Account Detector'),    $access = array('manage false account detector');
145        'callback' => 'false_account_page',  
146        'callback arguments' => array(FALSE_ACCOUNT_DEFAULT),    $items['false_account'] = array(
147        'access' => $access,      'title' => 'False Account Detector',
148        'weight' => 0      'title callback' => 't',
149      );      'page callback' => 'false_account_page',
150      $items[] = array(      'page arguments' => array('FALSE_ACCOUNT_DEFAULT'),
151        'path' => 'admin/user/false_account/default',      'access arguments' => $access,
152        'title' => t('Default'),      'weight' => 0,
153        'callback' => 'false_account_page',      'type' => MENU_CALLBACK
154        'callback arguments' => array(FALSE_ACCOUNT_DEFAULT),    );
155        'access' => $access,    $items['admin/user/false_account'] = array(
156        'type' => MENU_DEFAULT_LOCAL_TASK,      'title' => 'False Account Detector',
157        'weight' => 0      'title callback' => 't',
158      );      'page callback' => 'false_account_page',
159      $items[] = array(      'page arguments' => array('FALSE_ACCOUNT_DEFAULT'),
160        'path' => 'admin/user/false_account/whitelisted',      'access arguments' => $access,
161        'title' => t('Whitelisted'),      'weight' => 0
162        'callback' => 'false_account_page',    );
163        'callback arguments' => array(FALSE_ACCOUNT_WHITELISTED),    $items['admin/user/false_account/default'] = array(
164        'access' => $access,      'title' => 'Default',
165        'type' => MENU_LOCAL_TASK,      'title callback' => 't',
166        'weight' => 1      'page callback' => 'false_account_page',
167      );      'page arguments' => array('FALSE_ACCOUNT_DEFAULT'),
168      $items[] = array(      'access arguments' => $access,
169        'path' => 'admin/user/false_account/blocked',      'type' => MENU_DEFAULT_LOCAL_TASK,
170        'title' => t('Blocked'),      'weight' => 0
171        'callback' => 'false_account_page',    );
172        'callback arguments' => array(FALSE_ACCOUNT_BLOCKED),    $items['admin/user/false_account/whitelisted'] = array(
173        'access' => $access,      'title' => 'Whitelisted',
174        'type' => MENU_LOCAL_TASK,      'title callback' => 't',
175        'weight' => 1      'page callback' => 'false_account_page',
176        );      'page arguments' => array('FALSE_ACCOUNT_WHITELISTED'),
177      $items[] = array(      'access arguments' => $access,
178        'path' => 'admin/user/false_account/settings',      'type' => MENU_LOCAL_TASK,
179        'title' => t('Settings'),      'weight' => 1
180        'callback' => 'drupal_get_form',    );
181        'callback arguments' => array('false_account_settings'),    $items['admin/user/false_account/blocked'] = array(
182        'access' => $access,      'title' => 'Blocked',
183        'type' => MENU_LOCAL_TASK,      'title callback' => 't',
184        'weight' => 2      'page callback' => 'false_account_page',
185      );      'page arguments' => array('FALSE_ACCOUNT_BLOCKED'),
186        $items[] = array(      'access arguments' => $access,
187        'path' => 'admin/user/false_account/search',      'type' => MENU_LOCAL_TASK,
188        'title' => t('Search'),      'weight' => 1
       'callback' => 'false_account_searchfa',  
       'access' => $access,  
       'type' => MENU_LOCAL_TASK,  
       'weight' => 2  
     );  
     $items[] = array(  
       'path' => 'admin/user/false_account/op',  
       'callback' => 'false_account_operations',  
       'access' => $access,  
       'type' => MENU_CALLBACK  
189      );      );
190    }    $items['admin/user/false_account/settings'] = array(
191        'title' => 'Settings',
192        'title callback' => 't',
193        'page callback' => 'drupal_get_form',
194        'page arguments' => array('false_account_settings'),
195        'access arguments' => $access,
196        'type' => MENU_LOCAL_TASK,
197        'weight' => 2
198      );
199        $items['admin/user/false_account/search'] = array(
200        'title' => 'Search',
201        'title callback' => 't',
202        'page callback' => 'false_account_searchfa',
203        'access arguments' => $access,
204        'type' => MENU_LOCAL_TASK,
205        'weight' => 2
206      );
207      $items['admin/user/false_account/op'] = array(
208        'page callback' => 'false_account_operations',
209        'access arguments' => $access,
210        'type' => MENU_CALLBACK
211      );
212    
213    return $items;    return $items;
214  }  }
215    
216    
217    /**
218     * Implementation of hook_perm().
219     */
220  function false_account_perm() {  function false_account_perm() {
221    return array('manage false account detector');    return array('manage false account detector');
222  }  }
223    
224    
225  /**  /**
226  * Define the settings form.  * Define the settings form.
227  */  */
# Line 193  function false_account_settings() { Line 235  function false_account_settings() {
235    
236    return system_settings_form($form);    return system_settings_form($form);
237  }  }
238  function false_account_page($op = FALSE_ACCOUNT_DEFAULT) {  
239    
240    
241    function false_account_page($op = 'FALSE_ACCOUNT_DEFAULT') {
242    
243      switch ($op) {
244        case 'FALSE_ACCOUNT_DEFAULT':
245          $op = 0;
246          break;
247        case 'FALSE_ACCOUNT_WHITELISTED':
248          $op = 1;
249          break;
250        case 'FALSE_ACCOUNT_BLOCKED':
251          $op = 2;
252          break;
253      }
254    
255    $content = t('<p>User accounts marked with an * are blocked</p>');    $content = t('<p>User accounts marked with an * are blocked</p>');
256    $sql = 'SELECT * FROM {false_accounts} WHERE status = '. $op ;    $sql = 'SELECT * FROM {false_accounts} WHERE status = '. $op ;
# Line 291  function false_account_searchfa_form() { Line 348  function false_account_searchfa_form() {
348    
349  }  }
350    
351  function false_account_searchfa_form_validate($form_id, $form_values) {  function false_account_searchfa_form_validate($form, &$form_state) {
352    if (!$account = user_load(array('name' => $form_values['username']))) {    if (!$account = user_load(array('name' => $form_state['values']['username']))) {
353      form_set_error('username', t('Username not found'));      form_set_error('username', t('Username not found'));
354    }    }
355  }  }
356    
357  function false_account_searchfa_form_submit($form_id, $form_values) {  function false_account_searchfa_form_submit($form, &$form_state) {
358    $account = user_load(array('name' => $form_values['username']));    $account = user_load(array('name' => $form_state['values']['username']));
359    return 'admin/user/false_account/search/'. $account->uid;    $form_state['redirect'] = 'admin/user/false_account/search/'. $account->uid;
360  }  }
361    
362    
# Line 354  function _false_account_build_user_table Line 411  function _false_account_build_user_table
411      foreach ($cookie['users'] as $user) {      foreach ($cookie['users'] as $user) {
412        $uid = trim($user);        $uid = trim($user);
413        $status = user_load(array('uid' => $uid));        $status = user_load(array('uid' => $uid));
414                          if ($userid == $uid) {        if ($userid == $uid) {
415          $account[] = ($status->status == 0) ? $status->name .'*' : $status->name;          $account[] = ($status->status == 0) ? $status->name .'*' : $status->name;
416                          }        }
417                          else {        else {
418          $account[] = l(($status->status == 0) ? $status->name .'*' : $status->name, 'user/'. $uid);          $account[] = l(($status->status == 0) ? $status->name .'*' : $status->name, 'user/'. $uid);
419        }        }
420      }      }

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

  ViewVC Help
Powered by ViewVC 1.1.2