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

Contents of /contributions/modules/latest_members/latest_members.module

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


Revision 1.4 - (show annotations) (download) (as text)
Fri Jul 10 12:58:16 2009 UTC (4 months, 2 weeks ago) by toemaz
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +2 -2 lines
File MIME type: text/x-php
Small fix on cache checking
1 <?php
2 // $Id: latest_members.module,v 1.3 2008/05/14 10:45:58 toemaz Exp $
3
4 /**
5 * Implementation of hook_block
6 */
7 function latest_members_block($op = 'list', $delta = 0, $edit = array()) {
8
9 switch ($op) {
10
11 case 'list':
12 $blocks[0]['info'] = t('Latest Members');
13 return $blocks;
14
15 case 'configure':
16 $form['latest_members_block_num_members'] = array (
17 '#type' => 'textfield',
18 '#title' => t('Number of latest members to show in block'),
19 '#default_value' => variable_get('latest_members_block_num_members', 6),
20 );
21 $form['latest_members_block_cache_time'] = array (
22 '#type' => 'textfield',
23 '#title' => t('Cache time'),
24 '#default_value' => variable_get('latest_members_block_cache_time', 3600),
25 '#description' => t('Time to cache the latest members block in seconds'),
26 );
27 return $form;
28
29 case 'save':
30 variable_set('latest_members_block_num_members', (int) $edit['latest_members_block_num_members']);
31 variable_set('latest_members_block_cache_time', (int) $edit['latest_members_block_cache_time']);
32 break;
33
34 case 'view':
35 $block = array();
36 $block['subject'] = t('Latest Members');
37 $block['content'] = theme_latest_members(latest_members_list());
38 return $block;
39
40 }//end switch
41 }
42
43 /**
44 * Get the list of latest active members
45 * which will be stored in the cache table
46 * @return
47 * array of user pictures
48 */
49 function latest_members_list() {
50
51 // retrieve the list from the cache
52 $cache = cache_get('latest_members_list', 'cache');
53
54 if ($cache->expire > time()) {
55 $accounts = unserialize($cache->data);
56 }
57 else {
58 $num_members = variable_get('latest_members_block_num_members', 6);
59 $query = "SELECT uid, name, picture FROM {users} WHERE status != 0 and uid != 0 AND picture <> '' ORDER BY uid DESC";
60 $result = db_query_range($query, NULL, 0, $num_members);
61
62 $accounts = array();
63 while ($account = db_fetch_object($result)) {
64 $accounts[] = theme('user_picture', $account);
65 }
66 cache_set('latest_members_list', 'cache', serialize($accounts), (time() + variable_get('latest_members_block_cache_time', 3600)));
67 }
68
69 return $accounts;
70 }
71
72 /**
73 * Generates a display of all users pics if user has a pic and links to their profile page
74 * @param $accounts
75 * array of user pictures
76 * @return
77 * html output
78 */
79 function theme_latest_members($accounts) {
80 $output = '<div class="latest-members">' . implode(' ', $accounts) . '</div>';
81 return $output;
82 }

  ViewVC Help
Powered by ViewVC 1.1.2