View source
<?php
function spaces_contacts_context_define() {
$items = array();
$items[] = array(
'namespace' => 'spaces',
'attribute' => 'feature',
'value' => 'contacts',
'block' => array(
array(
'module' => 'spaces_contacts',
'delta' => 'contact_list',
'region' => 'right',
'weight' => -11,
),
),
'menu' => array(
'contacts',
),
'spaces' => array(
'label' => t('Contacts'),
'description' => t('A contacts section with member listings.'),
'options' => array(
0 => t('Disabled'),
2 => t('Enabled'),
),
),
);
return $items;
}
function spaces_contacts_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks['contact_list']['info'] = t('Spaces Contacts: Contact List');
return $blocks;
}
else {
if ($op == 'view') {
switch ($delta) {
case 'contact_list':
$users = _spaces_contacts_users();
$items = array();
if ($users) {
foreach ($users as $account) {
$item = new stdClass();
$item->title = theme('username', $account);
$items[] = theme('datetime_view_style_item', $item);
}
$block['content'] = theme('item_list', $items);
}
else {
$block['content'] = "<p>" . t('No contacts found.') . "</p>";
}
$block['subject'] = t('Contacts');
return $block;
}
}
}
}
function spaces_contacts_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'contacts',
'title' => t('Contacts'),
'description' => t('Provides a group-aware contact listing.'),
'callback' => 'spaces_contacts_pageview',
'access' => user_access('access content'),
'type' => MENU_NORMAL_ITEM,
);
}
return $items;
}
function spaces_contacts_help($page) {
if (context_get('spaces', 'feature') == 'contacts') {
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>";
}
}
function spaces_contacts_user($op, &$edit, &$account, $category = NULL) {
if (in_array($op, array(
'view',
'form',
)) && spaces_gid()) {
context_set('spaces', 'feature', 'contacts');
}
}
function spaces_contacts_pageview() {
drupal_set_title(t('Contacts'));
context_set('spaces', 'feature', 'contacts');
context_set('theme', 'layout', 'wide');
$rows = array();
$users = _spaces_contacts_users();
foreach ($users as $account) {
$row = array(
theme('user_picture', $account),
theme('username', $account),
l($account->mail, 'mailto:' . $account->mail),
);
if (module_exists('profile')) {
$row[] = $account->profile_organization ? $account->profile_organization : null;
}
$rows[] = $row;
}
$labels = array(
null,
t('Name'),
t('Email'),
);
if (module_exists('profile')) {
$labels[] = t('Organization');
}
return "<div class='view-content'>" . theme('table', $labels, $rows, array(
'class' => 'userlist',
)) . "</div>";
}
function _spaces_contacts_users() {
$users = spaces_get_users();
if (module_exists('profile')) {
foreach ($users as $key => $account) {
$account = user_load($account);
profile_load_profile($account);
if ($account->profile_givenname && $account->profile_familyname) {
$account->name = $account->profile_givenname . ' ' . $account->profile_familyname;
}
else {
if ($account->profile_givenname) {
$account->name = $account->profile_givenname;
}
}
$users[$key] = $account;
}
}
return $users;
}