| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
function active_profiles_help($section) {
|
| 4 |
switch($section) {
|
| 5 |
case 'admin/modules#description':
|
| 6 |
return t("This module lists users with active profiles");
|
| 7 |
}
|
| 8 |
}
|
| 9 |
|
| 10 |
function active_profiles_menu($may_cache) {
|
| 11 |
if ($may_cache) {
|
| 12 |
$items[] = array('path' => 'declare/active',
|
| 13 |
'title' => t('Active Profiles'),
|
| 14 |
'access' => user_access('view active profiles'),
|
| 15 |
'callback' => 'active_profiles_view',
|
| 16 |
'type' => MENU_CALLBACK
|
| 17 |
);
|
| 18 |
}
|
| 19 |
return $items;
|
| 20 |
}
|
| 21 |
|
| 22 |
/**
|
| 23 |
* Provides the block that this module is capable of displaying.
|
| 24 |
*
|
| 25 |
* @param $op the operation that is being requested. This defaults to 'list', which indicates that the method should
|
| 26 |
* return which blocks are available.
|
| 27 |
* @param $delta the specific block to display. This is actually the offset into an array.
|
| 28 |
* @return one of two possibilities. The first is an array of available blocks. The other is an array containing a
|
| 29 |
* block.
|
| 30 |
*/
|
| 31 |
function active_profiles_block($op = 'list', $delta = 0) {
|
| 32 |
switch ($op) {
|
| 33 |
case 'list' :
|
| 34 |
$blocks[0]['info'] = t('List of Active Profiles.');
|
| 35 |
return $blocks;
|
| 36 |
break;
|
| 37 |
case 'view' :
|
| 38 |
if (user_access('access content')) {
|
| 39 |
switch ($delta) {
|
| 40 |
case 0:
|
| 41 |
$block['subject'] = t('Most Active Members');
|
| 42 |
$block['content'] = active_profiles_view('block');
|
| 43 |
return $block;
|
| 44 |
}
|
| 45 |
}
|
| 46 |
break;
|
| 47 |
}
|
| 48 |
}
|
| 49 |
|
| 50 |
/**
|
| 51 |
* Fetches and themes the active profiles data.
|
| 52 |
*
|
| 53 |
* @param $op the operation that is being requested. This defaults to 'page', which indicates that the method should
|
| 54 |
* print a page showing active profiles. The other option is 'block' which indicates that the method should return
|
| 55 |
* a themed table of active profiles.
|
| 56 |
* @return The output when a block is requested.
|
| 57 |
*/
|
| 58 |
function active_profiles_view($op = 'page') {
|
| 59 |
global $mode, $pager_total, $pager_from_array;
|
| 60 |
|
| 61 |
// Build the columns and sort ordering
|
| 62 |
switch ($op) {
|
| 63 |
case 'page':
|
| 64 |
$header[] = array('data' => t('Name'), 'field' => "u.name");
|
| 65 |
$header[] = array('data' => t('City'), 'field' => "l.city");
|
| 66 |
$header[] = array('data' => t('State'), 'field' => "l.province");
|
| 67 |
$header[] = array('data' => t('Country'), 'field' => "l.country");
|
| 68 |
$header[] = array('data' => t('Posts'), 'field' => "posts", 'sort' => 'desc'); // Default sort order
|
| 69 |
$header[] = array('data' => t('Joined'), 'field' => "u.created");
|
| 70 |
$sql_order = tablesort_sql($header);
|
| 71 |
break;
|
| 72 |
case 'block':
|
| 73 |
$header[] = array('data' => t('Name')); // No field - no user sorting in block'
|
| 74 |
$header[] = array('data' => t('City'));
|
| 75 |
$header[] = array('data' => t('State'));
|
| 76 |
$sql_order = "ORDER BY posts DESC"; // Force sort by number of posts
|
| 77 |
break;
|
| 78 |
}
|
| 79 |
|
| 80 |
|
| 81 |
// The last line of this query makes this impossible to count via SQL, so we put it in a temporary table and use that
|
| 82 |
$tmp = db_query("CREATE TEMPORARY TABLE activeprofiles SELECT u.uid, u.name, u.created, l.city, l.province, l.country, " . // Regular data
|
| 83 |
"(COUNT(DISTINCT c.cid)+COUNT(DISTINCT n.nid)) AS posts " . // Count comments and nodes
|
| 84 |
"FROM {users} u LEFT JOIN {profile_values} p ON (u.uid = p.uid) " .
|
| 85 |
"LEFT JOIN {comments} c ON (u.uid = c.uid) " . // Bring in comments
|
| 86 |
"LEFT JOIN {node} n ON (u.uid = n.uid) " . // Bring in nodes
|
| 87 |
"LEFT JOIN {location_user} l ON (u.uid = l.uid) " . // Bring in locations
|
| 88 |
"WHERE (p.value NOT LIKE '') AND (p.value NOT LIKE '0') " .
|
| 89 |
"GROUP BY u.uid HAVING (COUNT(DISTINCT p.fid) > 2) " . $sql_order); // Select only users that have at least 3 profile items complete
|
| 90 |
|
| 91 |
switch ($op) {
|
| 92 |
case 'page':
|
| 93 |
$users = pager_query("SELECT * FROM activeprofiles", 45);
|
| 94 |
break;
|
| 95 |
case 'block':
|
| 96 |
$users = db_query("SELECT * FROM activeprofiles LIMIT 0, 20"); // We just need the first 20 results, and no pager
|
| 97 |
break;
|
| 98 |
}
|
| 99 |
|
| 100 |
$tmp = db_query("DROP TEMPORARY TABLE activeprofiles");
|
| 101 |
|
| 102 |
$rows = array();
|
| 103 |
|
| 104 |
switch ($op) {
|
| 105 |
case 'page':
|
| 106 |
while ($user = db_fetch_object($users)) {
|
| 107 |
// Build the rows.
|
| 108 |
$row = array(l($user->name, 'declare/my/' . $user->uid));
|
| 109 |
$row[] = $user->city;
|
| 110 |
$row[] = $user->province;
|
| 111 |
$row[] = strtoupper($user->country);
|
| 112 |
$row[] = $user->posts;
|
| 113 |
$row[] = format_date($user->created,'custom','m/d/y');
|
| 114 |
$rows[] = $row;
|
| 115 |
}
|
| 116 |
$mode = 'declare'; // Theme the page as a 'declare' page
|
| 117 |
$start = $pager_from_array[0] + 1;
|
| 118 |
$end = $start + 44;
|
| 119 |
$pager = '<div class="active-profiles-pager">';
|
| 120 |
$pager .= theme('pager', array(t('< first '), t('< previous '), 5, t(' next >'), t(' last >')), 45, 0, tablesort_pager());
|
| 121 |
$pager .= "$start-$end of $pager_total[0]</div>\n";
|
| 122 |
$output .= $pager;
|
| 123 |
$output .= '<div class="box"><div class="content">'.theme('table', $header, $rows)."</div></div>";
|
| 124 |
$output .= $pager;
|
| 125 |
print theme('page', '<div class="active-profiles">'.$output."</div>\n");
|
| 126 |
break;
|
| 127 |
case 'block':
|
| 128 |
while ($user = db_fetch_object($users)) {
|
| 129 |
// Build the rows.
|
| 130 |
$row = array(l($user->name, 'declare/my/' . $user->uid));
|
| 131 |
$row[] = $user->city;
|
| 132 |
$row[] = $user->province;
|
| 133 |
$rows[] = $row;
|
| 134 |
}
|
| 135 |
$output .= theme('table', $header, $rows);
|
| 136 |
return '<div class="active-profiles">'.$output."</div>\n";
|
| 137 |
}
|
| 138 |
}
|
| 139 |
|
| 140 |
function active_profiles_perm() {
|
| 141 |
return array('view active profiles');
|
| 142 |
}
|
| 143 |
|
| 144 |
?>
|