| 1 |
<?php
|
| 2 |
// $Id: spaces_contacts.module,v 1.6.6.1 2008/09/19 13:48:54 yhahn Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_context_define()
|
| 6 |
*/
|
| 7 |
function spaces_contacts_context_define() {
|
| 8 |
$items = array();
|
| 9 |
$items[] = array(
|
| 10 |
'namespace' => 'spaces',
|
| 11 |
'attribute' => 'feature',
|
| 12 |
'value' => 'contacts',
|
| 13 |
'block' => array(
|
| 14 |
array(
|
| 15 |
'module' => 'spaces_contacts',
|
| 16 |
'delta' => 'contact_list',
|
| 17 |
'region' => 'right',
|
| 18 |
'weight' => -11,
|
| 19 |
),
|
| 20 |
),
|
| 21 |
'spaces' => array(
|
| 22 |
'label' => t('Contacts'),
|
| 23 |
'description' => t('A contacts section with member listings.'),
|
| 24 |
'types' => array('og'),
|
| 25 |
'menu' => array(
|
| 26 |
'contacts' => array('title' => t('Contacts')),
|
| 27 |
),
|
| 28 |
),
|
| 29 |
);
|
| 30 |
return $items;
|
| 31 |
}
|
| 32 |
|
| 33 |
/**
|
| 34 |
* Implementation of hook_block()
|
| 35 |
*/
|
| 36 |
function spaces_contacts_block($op = 'list', $delta = 0) {
|
| 37 |
if ($op == 'list') {
|
| 38 |
$blocks['contact_list']['info'] = t('Spaces Contacts: Contact List');
|
| 39 |
return $blocks;
|
| 40 |
}
|
| 41 |
else if ($op == 'view') {
|
| 42 |
switch ($delta) {
|
| 43 |
case 'contact_list':
|
| 44 |
$users = _spaces_contacts_users();
|
| 45 |
$items = array();
|
| 46 |
if ($users) {
|
| 47 |
foreach ($users as $account) {
|
| 48 |
$item = new stdClass();
|
| 49 |
$item->title = theme('username', $account);
|
| 50 |
$items[] = theme('datetime_view_style_item', $item);
|
| 51 |
}
|
| 52 |
$block['content'] = theme('item_list', $items);
|
| 53 |
}
|
| 54 |
else {
|
| 55 |
$block['content'] = "<p>". t('No contacts found.') ."</p>";
|
| 56 |
}
|
| 57 |
$block['subject'] = t('Contacts');
|
| 58 |
return $block;
|
| 59 |
}
|
| 60 |
}
|
| 61 |
}
|
| 62 |
|
| 63 |
/**
|
| 64 |
* Implementation of hook_menu()
|
| 65 |
*/
|
| 66 |
function spaces_contacts_menu($may_cache) {
|
| 67 |
$items = array();
|
| 68 |
if ($may_cache) {
|
| 69 |
$items[] = array(
|
| 70 |
'path' => 'contacts',
|
| 71 |
'title' => t('Contacts'),
|
| 72 |
'description' => t('Provides a group-aware contact listing.'),
|
| 73 |
'callback' => 'spaces_contacts_pageview',
|
| 74 |
'access' => user_access('access content'),
|
| 75 |
'type' => MENU_NORMAL_ITEM,
|
| 76 |
);
|
| 77 |
}
|
| 78 |
return $items;
|
| 79 |
}
|
| 80 |
|
| 81 |
/**
|
| 82 |
* Implementation of hook_help()
|
| 83 |
*/
|
| 84 |
function spaces_contacts_help($page) {
|
| 85 |
if (context_get('spaces', 'feature') == 'contacts') {
|
| 86 |
return "<p>". t('Contacts shows the team members that are part of this group and any additional contact information if they have provided it.') ."</p>";
|
| 87 |
}
|
| 88 |
}
|
| 89 |
|
| 90 |
/**
|
| 91 |
* Implementation of hook_user()
|
| 92 |
*/
|
| 93 |
function spaces_contacts_user($op, &$edit, &$account, $category = NULL) {
|
| 94 |
if (in_array($op, array('view', 'form')) && spaces_get_space()) {
|
| 95 |
context_set('spaces', 'feature', 'contacts');
|
| 96 |
}
|
| 97 |
}
|
| 98 |
|
| 99 |
/**
|
| 100 |
* Page callback that displays a user contact listing
|
| 101 |
*/
|
| 102 |
function spaces_contacts_pageview() {
|
| 103 |
drupal_set_title(t('Contacts'));
|
| 104 |
context_set('spaces', 'feature', 'contacts');
|
| 105 |
context_set('theme', 'layout', 'wide');
|
| 106 |
$rows = array();
|
| 107 |
$users = _spaces_contacts_users();
|
| 108 |
foreach ($users as $account) {
|
| 109 |
$row = array(
|
| 110 |
theme('user_picture', $account),
|
| 111 |
theme('username', $account),
|
| 112 |
l($account->mail, 'mailto:'. $account->mail)
|
| 113 |
);
|
| 114 |
if (module_exists('profile')) {
|
| 115 |
$row[] = $account->profile_organization ? $account->profile_organization : null;
|
| 116 |
}
|
| 117 |
$rows[] = $row;
|
| 118 |
}
|
| 119 |
$labels = array(null, t('Name'), t('Email'));
|
| 120 |
if (module_exists('profile')) {
|
| 121 |
$labels[] = t('Organization');
|
| 122 |
}
|
| 123 |
// wrap the table as if it were produced by a view
|
| 124 |
return "<div class='view-content'>". theme('table', $labels, $rows, array('class' => 'userlist')) ."</div>";
|
| 125 |
}
|
| 126 |
|
| 127 |
/**
|
| 128 |
* Wrapper around spaces_og_get_users() that provides additional support for vcard name fields
|
| 129 |
*/
|
| 130 |
function _spaces_contacts_users() {
|
| 131 |
$users = spaces_og_get_users();
|
| 132 |
if (module_exists('profile')) {
|
| 133 |
foreach ($users as $key => $account) {
|
| 134 |
$account = user_load($account);
|
| 135 |
profile_load_profile($account);
|
| 136 |
// Replace username listing with real name if possible
|
| 137 |
if ($account->profile_givenname && $account->profile_familyname) {
|
| 138 |
$account->name = $account->profile_givenname .' '. $account->profile_familyname;
|
| 139 |
}
|
| 140 |
else if ($account->profile_givenname) {
|
| 141 |
$account->name = $account->profile_givenname;
|
| 142 |
}
|
| 143 |
$users[$key] = $account;
|
| 144 |
}
|
| 145 |
}
|
| 146 |
return $users;
|
| 147 |
}
|