| 1 |
<?php |
<?php |
| 2 |
// $Id: buddylist_ui.module,v 1.6 2008/02/22 09:45:47 nodestroy Exp $ |
// $Id$ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 6 |
* User Interface for buddy_api |
* buddylist_ui module file |
| 7 |
* |
* |
| 8 |
* based on views and workflow-ng for maximum possibilities |
* contains core buddylist_ui functions to generate social networks |
| 9 |
*/ |
*/ |
| 10 |
|
|
| 11 |
/** |
/** |
| 12 |
* Implementation of hook_help() |
* HOOKS |
| 13 |
*/ |
*/ |
| 14 |
function buddylist_ui_help($section) { |
|
| 15 |
switch ($section) { |
/** |
| 16 |
case 'admin/help#buddylist_ui' : |
* Implementation of hook_menu(). |
| 17 |
$output = t("Buddylist UI is an user-interface for Buddy API"); |
*/ |
| 18 |
return $output; |
function buddylist_ui_menu() { |
| 19 |
} |
$items = array(); |
| 20 |
|
|
| 21 |
|
/* |
| 22 |
|
* Admin Items |
| 23 |
|
*/ |
| 24 |
|
$items['admin/buddylist'] = array( |
| 25 |
|
'title' => 'Buddylist', |
| 26 |
|
'description' => 'Buddylist Administration Area.', |
| 27 |
|
'position' => 'right', |
| 28 |
|
'weight' => 5, |
| 29 |
|
'page callback' => 'system_admin_menu_block_page', |
| 30 |
|
'access arguments' => array('administer buddylist'), |
| 31 |
|
'file' => 'system.admin.inc', |
| 32 |
|
'file path' => drupal_get_path('module', 'system'), |
| 33 |
|
); |
| 34 |
|
$items['admin/buddylist/rtypes'] = array( |
| 35 |
|
'title' => 'Relation types', |
| 36 |
|
'description' => 'Manage relation types for your site.', |
| 37 |
|
'page callback' => 'drupal_get_form', |
| 38 |
|
'page arguments' => array('buddylist_ui_admin_overview'), |
| 39 |
|
'access arguments' => array('administer buddylist'), |
| 40 |
|
'type' => MENU_NORMAL_ITEM, |
| 41 |
|
'weight' => -2, |
| 42 |
|
); |
| 43 |
|
$items['admin/buddylist/rtypes/list'] = array( |
| 44 |
|
'title' => 'Overview', |
| 45 |
|
'weight' => -5, |
| 46 |
|
'type' => MENU_DEFAULT_LOCAL_TASK, |
| 47 |
|
); |
| 48 |
|
$items['admin/buddylist/rtypes/add'] = array( |
| 49 |
|
'title' => 'Add a new relation type', |
| 50 |
|
'type' => MENU_LOCAL_TASK, |
| 51 |
|
'page callback' => 'drupal_get_form', |
| 52 |
|
'page arguments' => array('buddylist_ui_admin_form_edit'), |
| 53 |
|
'access arguments' => array('administer buddylist'), |
| 54 |
|
); |
| 55 |
|
$items['admin/buddylist/rtypes/%rtype/edit'] = array( |
| 56 |
|
'title' => 'Edit Relationtype', |
| 57 |
|
'type' => MENU_CALLBACK, |
| 58 |
|
'page callback' => 'drupal_get_form', |
| 59 |
|
'page arguments' => array('buddylist_ui_admin_form_edit', 3), |
| 60 |
|
'access arguments' => array('administer buddylist'), |
| 61 |
|
); |
| 62 |
|
$items['admin/buddylist/rtypes/%rtype/delete'] = array( |
| 63 |
|
'title' => 'Delete Relationtype', |
| 64 |
|
'type' => MENU_CALLBACK, |
| 65 |
|
'page callback' => 'drupal_get_form', |
| 66 |
|
'page arguments' => array('buddylist_ui_admin_form_delete', 3), |
| 67 |
|
'access arguments' => array('administer buddylist'), |
| 68 |
|
); |
| 69 |
|
return $items; |
| 70 |
} |
} |
| 71 |
|
|
| 72 |
/** |
/** |
| 73 |
* Implementation of hook_perm() |
* Implementation of hook_perm(). |
| 74 |
*/ |
*/ |
| 75 |
function buddylist_ui_perm() { |
function buddylist_ui_perm() { |
| 76 |
return array ('view buddy lists', 'maintain buddy list'); |
return array('administer buddylist'); |
| 77 |
} |
} |
| 78 |
|
|
| 79 |
/** |
/** |
| 80 |
* Implementation of hook_menu() |
* FUNCTIONS |
| 81 |
*/ |
*/ |
|
function buddylist_ui_menu($may_cache) { |
|
|
global $user; |
|
|
$items = array (); |
|
|
$id = is_numeric(arg(1)) ? arg(1) : $user->uid; |
|
|
$editAccess = (($id == $user->uid && user_access('maintain buddy list') && $user->uid) || user_access('administer users')); |
|
|
|
|
|
// Menu structure loosely based on user.module |
|
|
if ($may_cache) { |
|
|
$items[] = array ( |
|
|
'path' => 'buddylist', |
|
|
'title' => t('My @buddylist', buddy_api_translation()), |
|
|
'callback' => 'theme', |
|
|
'callback arguments' => array('buddylist_ui_page_buddylist', $id), |
|
|
'type' => MENU_NORMAL_ITEM, |
|
|
'weight' => 0, |
|
|
'access' => $editAccess, |
|
|
); |
|
|
|
|
|
// user page: buddylist |
|
|
$items[] = array ( |
|
|
'path' => 'buddylist/confirmed', |
|
|
'title' => t('My @Buddies', buddy_api_translation()), |
|
|
'type' => MENU_DEFAULT_LOCAL_TASK, |
|
|
'weight' => 1, |
|
|
); |
|
|
|
|
|
// user page: pending requests |
|
|
$items[] = array( |
|
|
'path' => 'buddylist/requests', |
|
|
'title' => t('My @Buddy Requests', buddy_api_translation()), |
|
|
'access' => $editAccess, |
|
|
'callback' => 'theme', |
|
|
'type' => MENU_LOCAL_TASK, |
|
|
'weight' => 2, |
|
|
'callback arguments' => array('buddylist_ui_page_pending_requests', $id) |
|
|
); |
|
|
|
|
|
// admin backend |
|
|
$items[] = array( |
|
|
'path' => 'admin/settings/buddylist_ui', |
|
|
'title' => t('Buddylist UI Settings'), |
|
|
'description' => t('Buddylist UI Admin Settings'), |
|
|
'callback' => 'drupal_get_form', |
|
|
'callback arguments' => 'buddylist_ui_admin_settings', |
|
|
'access' => user_access('administer site configuration'), |
|
|
); |
|
|
} |
|
|
else { |
|
|
$items[] = array ( |
|
|
'path' => 'buddy/add', |
|
|
'title' => t('Add to @buddylist', buddy_api_translation()), |
|
|
'access' => $editAccess, |
|
|
'callback' => 'drupal_get_form', |
|
|
'callback arguments' => array ('buddylist_ui_addbuddy', arg(2)), 'type' => MENU_CALLBACK, |
|
|
); |
|
|
|
|
|
$items[] = array ( |
|
|
'path' => 'buddy/delete', |
|
|
'title' => t('Delete from @buddylist', buddy_api_translation()), |
|
|
'access' => $editAccess, |
|
|
'callback' => 'drupal_get_form', |
|
|
'callback arguments' => array ('buddylist_ui_deletebuddy', arg(2)), 'type' => MENU_CALLBACK, |
|
|
); |
|
|
|
|
|
$items[] = array ( |
|
|
'path' => 'buddylist/' . $id . '/buddies/requested/accept', |
|
|
'title' => t('Accept Request'), |
|
|
'access' => $editAccess, |
|
|
'type' => MENU_CALLBACK, |
|
|
'callback' => 'drupal_get_form', |
|
|
'callback arguments' => array ('buddylist_ui_pending_requested_accept', $id), |
|
|
); |
|
|
|
|
|
$items[] = array ( |
|
|
'path' => 'buddylist/' . $id . '/buddies/requested/deny', |
|
|
'title' => t('Deny Request'), |
|
|
'access' => $editAccess, |
|
|
'type' => MENU_CALLBACK, |
|
|
'callback' => 'drupal_get_form', |
|
|
'callback arguments' => array ('buddylist_ui_pending_requested_deny', $id), |
|
|
); |
|
|
|
|
|
$items[] = array ( |
|
|
'path' => 'buddylist/' . $id . '/buddies/request/cancel', |
|
|
'title' => t('Cancel Request'), |
|
|
'access' => $editAccess, |
|
|
'type' => MENU_CALLBACK, |
|
|
'callback' => 'drupal_get_form', |
|
|
'callback arguments' => array ('buddylist_ui_cancel_request', $id), |
|
|
); |
|
|
} |
|
|
return $items; |
|
|
} |
|
| 82 |
|
|
| 83 |
/** |
/** |
| 84 |
* administration settings page |
* Generates overview of relationtypes |
| 85 |
*/ |
*/ |
| 86 |
function buddylist_ui_admin_settings() { |
function buddylist_ui_admin_overview() { |
| 87 |
$form['general'] = array( |
$form = array(); |
|
'#type' => 'fieldset', |
|
|
'#title' => t('General settings'), |
|
|
); |
|
|
|
|
|
$form['general']['buddylist_ui_oneway'] = array( |
|
|
'#type' => 'checkbox', |
|
|
'#default_value' => variable_get('buddylist_ui_oneway', 0), |
|
|
'#title' => t('One way connection mode'), |
|
|
'#description' => t("oneway means, that userA can add userB without approval. in the case of twoway a request to userB is sent, which can be denied or approved."), |
|
|
); |
|
| 88 |
|
|
| 89 |
$form['ui'] = array( |
//active relationtypes |
| 90 |
'#type' => 'fieldset', |
$form['active'] = array('#value' => '<h2>'. t('Active relationtypes'). '</h2>'); |
| 91 |
'#title' => t('User Interface'), |
$form['active_table'] = buddylist_ui_admin_get_rtypes(1); |
|
); |
|
| 92 |
|
|
| 93 |
$form['ui']['buddylist_ui_showbuddies'] = array( |
//inactive relationtypes |
| 94 |
'#type' => 'checkbox', |
$form['inactive'] = array('#value' => '<h2>'. t('Inactive relationtypes'). '</h2>'); |
| 95 |
'#default_value' => variable_get('buddylist_ui_showbuddies', 1), |
$form['inactive_table'] = buddylist_ui_admin_get_rtypes(0); |
|
'#title' => t('Show buddylist on a users page (user/x)'), |
|
|
'#description' => t("if checked, a users buddies will be shown on his users page"), |
|
|
); |
|
| 96 |
|
|
|
$form['ui']['buddylist_ui_showactionlinks'] = array( |
|
|
'#type' => 'checkbox', |
|
|
'#default_value' => variable_get('buddylist_ui_showactionlinks', 1), |
|
|
'#title' => t('Show action links on a users page (user/x)'), |
|
|
'#description' => t("if checked, action links like 'add to buddylist' will be shown on a users page"), |
|
|
); |
|
|
|
|
|
return system_settings_form($form); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Shows confirm form to deny a buddy request |
|
|
* |
|
|
* @param $requestee_uid |
|
|
* user id of requestee |
|
|
* @param $requester_uid |
|
|
* user id of requester |
|
|
* @return |
|
|
* string, confirm form |
|
|
*/ |
|
|
function buddylist_ui_pending_requested_deny($requestee_uid, $requester_uid) { |
|
|
$requestee_account = user_load(array ( |
|
|
'uid' => $requestee_uid |
|
|
)); |
|
|
$requester_account = user_load(array ( |
|
|
'uid' => $requester_uid |
|
|
)); |
|
|
$output = confirm_form(buddylist_ui_confirm_form($requester_account, $requestee_account), t('Deny Request'), $_GET['destination'], |
|
|
t("Are you sure you want to deny the request from !name?", array ( |
|
|
'!name' => theme('username', |
|
|
$requester_account |
|
|
))), t('Yes'), t('No'), 'buddylist_ui_request_deny_confirm'); |
|
|
|
|
|
return $output; |
|
|
} |
|
|
|
|
|
/** |
|
|
* submit function to deny a request |
|
|
*/ |
|
|
function buddylist_ui_pending_requested_deny_submit($form_id, $form_values) { |
|
|
buddy_api_deny_request($form_values['requestee_account'], $form_values['requester_account']); |
|
|
// no need for a drupal_set_message to show success because message is allready shown by notification system |
|
|
} |
|
|
|
|
|
/** |
|
|
* Shows confirm form to accept a buddy request |
|
|
* |
|
|
* @param $requestee_uid |
|
|
* user id of requestee |
|
|
* @param $requester_uid |
|
|
* user id of requester |
|
|
* @return |
|
|
* string, confirm form |
|
|
*/ |
|
|
function buddylist_ui_pending_requested_accept($requestee_uid, $requester_uid) { |
|
|
$requestee_account = user_load(array ( |
|
|
'uid' => $requestee_uid |
|
|
)); |
|
|
$requester_account = user_load(array ( |
|
|
'uid' => $requester_uid |
|
|
)); |
|
|
$output = confirm_form(buddylist_ui_confirm_form($requester_account, $requestee_account), t('Accept Request'), $_GET['destination'], |
|
|
t("Are you sure you want to accept the request from !name?", array ( |
|
|
'!name' => theme('username', |
|
|
$requester_account |
|
|
))), t('Yes'), t('No'), 'buddylist_ui_request_accept_confirm'); |
|
|
|
|
|
return $output; |
|
|
} |
|
|
|
|
|
/** |
|
|
* submit function to accept a request |
|
|
*/ |
|
|
function buddylist_ui_pending_requested_accept_submit($form_id, $form_values) { |
|
|
buddy_api_accept_request($form_values['requestee_account'], $form_values['requester_account']); |
|
|
// no need for a drupal_set_message to show success because message is allready shown by notification system |
|
|
} |
|
|
|
|
|
/** |
|
|
* Function to add needed values to the confirm form |
|
|
* |
|
|
* @param $requestee_uid |
|
|
* user id of requestee |
|
|
* @param $requester_uid |
|
|
* user id of requester |
|
|
* @return |
|
|
* confirm form values |
|
|
*/ |
|
|
function buddylist_ui_confirm_form($requester_account, $requestee_account) { |
|
|
$form = array (); |
|
|
|
|
|
$form['requester_account'] = array ( |
|
|
'#type' => 'value', |
|
|
'#value' => $requester_account |
|
|
); |
|
|
|
|
|
$form['requestee_account'] = array ( |
|
|
'#type' => 'value', |
|
|
'#value' => $requestee_account |
|
|
); |
|
|
|
|
| 97 |
return $form; |
return $form; |
| 98 |
} |
} |
|
/** |
|
|
* Shows confirm form to cancel a buddy request |
|
|
* |
|
|
* @param $requestee_uid |
|
|
* user id of requestee |
|
|
* @param $requester_uid |
|
|
* user id of requester |
|
|
* @return |
|
|
* string, confirm form |
|
|
*/ |
|
|
function buddylist_ui_cancel_request($requester_uid, $requestee_uid) { |
|
|
$requester_account = user_load(array ( |
|
|
'uid' => $requester_uid |
|
|
)); |
|
|
$requestee_account = user_load(array ( |
|
|
'uid' => $requestee_uid |
|
|
)); |
|
|
$output = confirm_form(buddylist_ui_cancel_request_form($requestee_account, $requester_account), t('Cancel Request'), $_GET['destination'], |
|
|
t("Are you sure you want to cancel the request to !name?", array ( |
|
|
'!name' => theme('username', |
|
|
$requestee_account |
|
|
))), t('Yes'), t('No'), 'buddylist_ui_cancel_request_confirm'); |
|
|
|
|
|
return $output; |
|
|
} |
|
| 99 |
|
|
| 100 |
/** |
/** |
| 101 |
* submit function to cancel a request |
* Loads rtype wildcard |
| 102 |
*/ |
*/ |
| 103 |
function buddylist_ui_cancel_request_submit($form_id, $form_values) { |
function rtype_load($rtid) { |
| 104 |
buddy_api_cancel_request($form_values['requester_account'], $form_values['requestee_account']); |
static $rtypes = array(); |
| 105 |
// no need for a drupal_set_message to show success because message is allready shown by notification system |
$rtypes = buddylist_api_rtypes_load(); |
|
} |
|
| 106 |
|
|
| 107 |
/** |
if (!isset($rtypes[$rtid])) { |
| 108 |
* Function to add needed values to the confirm form |
return FALSE; |
|
* |
|
|
* @param $requestee_uid |
|
|
* user id of requestee |
|
|
* @param $requester_uid |
|
|
* user id of requester |
|
|
* @return |
|
|
* confirm form values |
|
|
*/ |
|
|
function buddylist_ui_cancel_request_form($requestee_account, $requester_account) { |
|
|
$form['requestee_account'] = array ( |
|
|
'#type' => 'value', |
|
|
'#value' => $requestee_account, |
|
|
); |
|
|
|
|
|
$form['requester_account'] = array ( |
|
|
'#type' => 'value', |
|
|
'#value' => $requester_account |
|
|
); |
|
|
|
|
|
return $form; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Returns an array of posible actions (html) for the viewing user |
|
|
* |
|
|
* e.g. a link to make the viewed user a buddy |
|
|
* |
|
|
* @param $viewing_user |
|
|
* mostly acting user |
|
|
* @param $viewed_user |
|
|
* viewed user |
|
|
* @return |
|
|
* string, themed output with possible actions |
|
|
*/ |
|
|
function buddylist_ui_get_buddy_actions(& $viewing_user, & $viewed_user) { |
|
|
|
|
|
$actions = array (); |
|
|
if (!user_access('maintain buddy list') || $viewing_user->uid == $viewed_user->uid) { |
|
|
return $actions; |
|
| 109 |
} |
} |
| 110 |
|
return $rtypes[$rtid]; |
|
if (in_array($viewed_user->uid, array_keys(buddy_api_get_requestees($viewing_user->uid)))) { |
|
|
$actions['buddy_requested'] = theme('buddylist_ui_action_sent_request', $viewed_user); |
|
|
} |
|
|
else |
|
|
if (in_array($viewed_user->uid, array_keys(buddy_api_get_buddies($viewing_user->uid)))) { |
|
|
$actions['buddy_remove'] = theme('buddylist_ui_action_remove_buddy', $viewed_user); |
|
|
} |
|
|
else |
|
|
if (in_array($viewing_user->uid, array_keys(buddy_api_get_requestees($viewed_user->uid)))) { |
|
|
$actions['buddy_confirm'] = theme('buddylist_ui_action_confirm_request', $viewed_user); |
|
|
} |
|
|
else { |
|
|
$actions['buddy_add'] = theme('buddylist_ui_action_add_buddy', $viewed_user); |
|
|
} |
|
|
|
|
|
return $actions; |
|
| 111 |
} |
} |
| 112 |
|
|
| 113 |
/** |
/** |
| 114 |
* Implementation of hook_user() |
* Generates table with active/inactive relationtypes and operation links |
| 115 |
*/ |
*/ |
| 116 |
function buddylist_ui_user($type, & $edit, & $thisuser, $category = NULL) { |
function buddylist_ui_admin_get_rtypes($active_state) { |
| 117 |
|
// load all types |
| 118 |
|
$rtypes = buddylist_api_rtypes_load(); |
| 119 |
|
$final_types = array(); |
| 120 |
|
|
| 121 |
if ($type == 'view') { |
foreach($rtypes as $rtype) { |
| 122 |
$output = array(); |
// only add to table if the state matches |
| 123 |
|
if ($rtype->active == $active_state) { |
| 124 |
if (variable_get('buddylist_ui_showbuddies', 1)) { |
$path = 'admin/buddylist/rtypes/'. $rtype->rtid; |
| 125 |
$output[] = theme('buddylist_ui_user_buddies', $thisuser); |
$id = $rtype->rtid; |
| 126 |
} |
$final_types[$id] = (array)$rtype; |
| 127 |
|
$ops = array(); |
| 128 |
if (variable_get('buddylist_ui_showactionlinks', 1)) { |
$ops[] = l(t('edit'), $path .'/edit'); |
| 129 |
$output[] = theme('buddylist_ui_user_actions', $thisuser); |
|
| 130 |
} |
// only type 1 relationtypes can be deleted |
| 131 |
|
if($rtype->type == 1) |
| 132 |
if (count($output) > 0) |
$ops[] = l(t('delete'), $path .'/delete'); |
| 133 |
return array (t('@Buddylist', buddy_api_translation()) => $output); |
|
| 134 |
} |
$final_types[$id]['oneway'] = ($final_types[$id]['oneway'] == 1) ? t('Yes') : t('No'); |
| 135 |
else |
$final_types[$id]['type'] = ($final_types[$id]['type'] == 1) ? t('User') : t('Module'); |
| 136 |
if ($type == 'delete') { |
|
| 137 |
db_query("DELETE FROM {buddylist} WHERE uid = %d OR buddy = %d", $thisuser->uid, $thisuser->uid); |
unset($final_types[$id]['active']); |
| 138 |
db_query("DELETE FROM {buddylist_pending_requests} WHERE requester_uid = %d OR requestee_uid = %d", $thisuser->uid, $thisuser->uid); |
|
| 139 |
} |
$final_types[$id][] = implode(' ', $ops); |
|
else |
|
|
if ($type == 'load') { |
|
|
// Do not load buddies as objects to avoid recursion |
|
|
$thisuser->buddies = buddy_api_get_buddies($thisuser->uid); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* checks if its possible to add userX as buddy and shows confirm form |
|
|
*/ |
|
|
function buddylist_ui_addbuddy($uid) { |
|
|
global $user; |
|
|
$buddy = user_load(array ( |
|
|
'uid' => $uid |
|
|
)); |
|
|
|
|
|
if (empty ($buddy->name)) { |
|
|
drupal_set_message(t('This user does not exist')); |
|
|
} |
|
|
elseif (in_array($uid, array_keys(buddy_api_get_buddies($user->uid)))) { |
|
|
drupal_set_message(t('This user is already on your @buddylist', buddy_api_translation())); |
|
|
} |
|
|
elseif ($user->uid == $uid) { |
|
|
drupal_set_message(t('Cannot add yourself to @buddylist', buddy_api_translation())); |
|
|
} |
|
|
else { |
|
|
$form['requester_account'] = array ( |
|
|
'#type' => 'value', |
|
|
'#value' => $user |
|
|
); |
|
|
$form['requestee_account'] = array ( |
|
|
'#type' => 'value', |
|
|
'#value' => $buddy |
|
|
); |
|
|
|
|
|
// if system is in oneway mode, there is no need for displaying the message field |
|
|
if (!variable_get('buddylist_ui_oneway', 0)) { |
|
|
$form['message'] = array ( |
|
|
'#type' => 'textfield', |
|
|
'#title' => t('Message'), |
|
|
'#description' => t('Message, which is sent by mail and shown at pending requests.'), |
|
|
); |
|
| 140 |
} |
} |
|
|
|
|
$output = confirm_form($form, t('Add user %name to your @buddylist?', array ( |
|
|
'%name' => $buddy->name |
|
|
) + buddy_api_translation()), $_GET['destination'], '', t('Add'), t('Cancel'), 'buddylist_ui_addbuddy_confirm'); |
|
|
return $output; |
|
|
} |
|
|
drupal_goto(); |
|
|
} |
|
|
|
|
|
/** |
|
|
* submit function, calls buddy_api to add buddy |
|
|
*/ |
|
|
function buddylist_ui_addbuddy_submit($form_id, $form_values) { |
|
|
$buddyinfo = array(); |
|
|
|
|
|
if (isset($form_values['message'])) { |
|
|
$buddyinfo['message'] = $form_values['message']; |
|
| 141 |
} |
} |
| 142 |
|
|
| 143 |
$buddyinfo['oneway'] = variable_get('buddylist_ui_oneway', 0); |
// no relationtypes found |
| 144 |
buddy_api_add($form_values['requester_account'], $form_values['requestee_account'], $buddyinfo); |
if (!count($final_types)) { |
| 145 |
return 'user'; |
return array('#value' => '<p>'. t('None') .'</p>'); |
| 146 |
}; |
} |
| 147 |
|
|
| 148 |
/** |
$header = array(t('Relation ID'), t('Name'), t('Oneway'), t('Type'), t('Operations')); |
| 149 |
* checks if its possible to delete buddyconnetion and shows confirm form |
return array('#value' => theme('table', $header, $final_types)); |
|
*/ |
|
|
function buddylist_ui_deletebuddy($uid) { |
|
|
global $user; |
|
|
$buddy = user_load(array ( |
|
|
'uid' => $uid |
|
|
)); |
|
|
|
|
|
if (empty ($buddy->name)) { |
|
|
drupal_set_message('This user does not exist'); |
|
|
} |
|
|
else |
|
|
if (!in_array($uid, array_keys(buddy_api_get_buddies($user->uid)))) { |
|
|
drupal_set_message('This user is not on your @buddylist', buddy_api_translation()); |
|
|
} |
|
|
else { |
|
|
$form['requester_account'] = array ( |
|
|
'#type' => 'value', |
|
|
'#value' => $user |
|
|
); |
|
|
$form['requestee_account'] = array ( |
|
|
'#type' => 'value', |
|
|
'#value' => $buddy |
|
|
); |
|
|
$output = confirm_form($form, t('Remove user %name from your @buddylist?', array ( |
|
|
'%name' => $buddy->name |
|
|
) + buddy_api_translation()), $_GET['destination'], '', t('Remove'), t('Cancel'), 'buddylist_ui_deletebuddy_confirm'); |
|
|
return $output; |
|
|
} |
|
|
drupal_goto(); |
|
|
} |
|
|
|
|
|
/** |
|
|
* submit function, calls buddy_api to delete buddyconnection |
|
|
*/ |
|
|
function buddylist_ui_deletebuddy_submit($form_id, $form_values) { |
|
|
$buddyinfo = array(); |
|
|
$buddyinfo['oneway'] = variable_get('buddylist_ui_oneway', 0); |
|
|
buddy_api_remove($form_values['requester_account'], $form_values['requestee_account'], $buddyinfo); |
|
|
}; |
|
|
|
|
|
/** |
|
|
* theme function for action "add buddy" on users profile |
|
|
*/ |
|
|
function theme_buddylist_ui_action_add_buddy($buddyuser) { |
|
|
return l(t('Add %name to my @buddylist', array ( |
|
|
'%name' => $buddyuser->name |
|
|
) + buddy_api_translation()), 'buddy/add/' . $buddyuser->uid, NULL, drupal_get_destination(), NULL, FALSE, TRUE); |
|
| 150 |
} |
} |
| 151 |
|
|
| 152 |
/** |
/** |
| 153 |
* theme function for action "remove buddy" on users profile |
* Returns the form for editing/adding a rtype |
| 154 |
*/ |
*/ |
| 155 |
function theme_buddylist_ui_action_remove_buddy($buddyuser) { |
function buddylist_ui_admin_form_edit(&$form_state, $rtid = NULL) { |
| 156 |
return l(t('Remove %name from my @buddylist', array ( |
$form = array(); |
| 157 |
'%name' => $buddyuser->name |
|
| 158 |
) + buddy_api_translation()), 'buddy/delete/' . $buddyuser->uid, NULL, drupal_get_destination(), NULL, FALSE, TRUE); |
// only write rtid in form if we are in edit process |
| 159 |
} |
if($rtid != NULL) { |
| 160 |
|
$form['rtid'] = array( |
| 161 |
/** |
'#type' => 'hidden', |
| 162 |
* theme function for sent requests |
'#default_value' => $rtid->rtid, |
| 163 |
*/ |
); |
| 164 |
function theme_buddylist_ui_action_sent_request($buddyuser) { |
} |
| 165 |
return t('You have requested to add %name to your @buddylist. (See !your_pending_requests)', array ( |
$form['name'] = array( |
| 166 |
'%name' => $buddyuser->name, |
'#type' => 'textfield', |
| 167 |
'!your_pending_requests' => l(t('your pending requests' |
'#title' => t('Name'), |
| 168 |
), 'buddylist/requests')) + buddy_api_translation()); |
'#maxlength' => 255, |
| 169 |
} |
'#default_value' => $rtid->name, |
| 170 |
|
'#description' => t("Example: buddy, friend, colleague."), |
| 171 |
/** |
'#required' => TRUE, |
| 172 |
* theme function for user who has request to add the acting user |
); |
| 173 |
*/ |
$form['oneway'] = array( |
| 174 |
function theme_buddylist_ui_action_confirm_request($buddyuser) { |
'#type' => 'checkbox', |
| 175 |
return t('%name has requested to add you to your @buddylist. (See !your_pending_requests)', array ( |
'#title' => t('This is a oneway relationship'), |
| 176 |
'%name' => $buddyuser->name, |
'#default_value' => $rtid->oneway, |
| 177 |
'!your_pending_requests' => l(t('your pending requests' |
'#description' => t('Check this if this relationship should only go one way (Example: Fan, Subscriber)'), |
| 178 |
), 'buddylist/requests')) + buddy_api_translation()); |
); |
| 179 |
} |
$form['active'] = array( |
| 180 |
|
'#type' => 'checkbox', |
| 181 |
/** |
'#title' => t('Relationtype is active'), |
| 182 |
* Main page for displaying confirmed buddylist |
'#default_value' => $rtid->active, |
| 183 |
* |
'#description' => t('If checked, users can use this relationship'), |
| 184 |
* @return |
); |
| 185 |
* string, html formatted output |
$form['submit'] = array( |
| 186 |
*/ |
'#type' => 'submit', |
| 187 |
function theme_buddylist_ui_page_buddylist() { |
'#value' => 'Save', |
| 188 |
drupal_set_title(t('@Buddylist', buddy_api_translation())); |
); |
|
$view = views_get_view('buddy_api_my_buddylist'); |
|
|
$title = views_get_title($view); |
|
|
$view_buddylist = views_build_view('embed', $view, array(), FALSE); |
|
|
if (!strlen($view_buddylist)) { |
|
|
$output .= '<p>'. t('NONE') .'</p>'; |
|
|
} |
|
|
$output .= $view_buddylist; |
|
| 189 |
|
|
| 190 |
return theme_box($title, $output, $region = 'main'); |
return $form; |
| 191 |
} |
} |
| 192 |
|
|
| 193 |
/** |
/** |
| 194 |
* Main page for displaying pending buddy requests (sent & received) |
* Submit function for edit/delete a relationtype |
|
* |
|
|
* @return |
|
|
* string, html formatted output |
|
| 195 |
*/ |
*/ |
| 196 |
function theme_buddylist_ui_page_pending_requests($id) { |
function buddylist_ui_admin_form_edit_submit($form, &$form_state) { |
| 197 |
drupal_set_title(t('Pending Requests')); |
$res = new stdClass(); |
| 198 |
|
foreach(array('name', 'oneway', 'active', 'rtid') as $key) { |
| 199 |
$view = views_get_view('buddy_api_received_requests'); |
$res->{$key} = $form_state['values'][$key]; |
|
$title = views_get_title($view); |
|
|
$view_received_requests = views_build_view('embed', $view, array(), FALSE); |
|
|
if (!strlen($view_received_requests)) { |
|
|
$view_received_requests .= '<p>'. t('NONE') .'</p>'; |
|
| 200 |
} |
} |
|
$themed_received_requests = theme_box($title, $view_received_requests, $region = 'main'); |
|
| 201 |
|
|
| 202 |
$view = views_get_view('buddy_api_sent_requests'); |
if(is_numeric($res->rtid)) |
| 203 |
$title = views_get_title($view); |
drupal_set_message(t('Relation type has been updated')); |
| 204 |
$view_sent_requests = views_build_view('embed', $view, array(), FALSE); |
else |
| 205 |
if (!strlen($view_sent_requests)) { |
drupal_set_message(t('Relation type has been saved')); |
| 206 |
$view_sent_requests .= '<p>'. t('NONE') .'</p>'; |
|
| 207 |
} |
buddylist_api_rtype_save($res); |
|
$themed_sent_requests = theme_box($title, $view_sent_requests, $region = 'main'); |
|
| 208 |
|
|
| 209 |
return $themed_received_requests . $themed_sent_requests; |
$form_state['redirect'] = 'admin/buddylist/rtypes'; |
| 210 |
} |
} |
| 211 |
|
|
| 212 |
|
|
| 213 |
/** |
/** |
| 214 |
* Themes default display of buddies on user profile |
* Returns the form for deleting a rtype |
|
* |
|
|
* @return |
|
|
* string, html formatted output |
|
| 215 |
*/ |
*/ |
| 216 |
function theme_buddylist_ui_user_buddies($buddyuser) { |
function buddylist_ui_admin_form_delete(&$form_state, $rtid = NULL) { |
| 217 |
|
if ($rtid) { |
| 218 |
// Permission check first |
$form['rtid'] = array( |
| 219 |
global $user; |
'#type' => 'value', |
| 220 |
if ( !user_access('view buddy lists') && $buddyuser->uid != $user->uid) return; |
'#value' => (int)$rtid->rtid, |
| 221 |
|
); |
| 222 |
// Display entire buddylist page |
|
| 223 |
$view = views_get_view('buddy_api_buddylist'); |
return confirm_form( |
| 224 |
$view_buddylist = views_build_view('embed', $view, array(), FALSE); |
$form, |
| 225 |
if (!strlen($view_buddylist)){ |
t('Are you sure you want to delete %name?', array('%name' => $rtid->name)), |
| 226 |
$output .= '<p>'. t('NONE') .'</p>'; |
'admin/buddylist/rtypes', |
| 227 |
|
t('This action cannot be undone.'), |
| 228 |
|
t('Delete'), t('Cancel') |
| 229 |
|
); |
| 230 |
|
} |
| 231 |
|
else { |
| 232 |
|
drupal_set_message(t('Donīt exists')); |
| 233 |
|
drupal_goto('admin/buddylist/rtypes'); |
| 234 |
} |
} |
|
$output .= $view_buddylist; |
|
|
|
|
|
return array ('title' => t('@Buddies', buddy_api_translation()), 'value' => theme_box('', $output, $region = 'main')); |
|
| 235 |
} |
} |
| 236 |
|
|
| 237 |
/** |
/** |
| 238 |
* Themes default display of buddy actions on user profile |
* Submit function for deleting a relationtype |
|
* |
|
|
* @return |
|
|
* string, html formatted output |
|
| 239 |
*/ |
*/ |
| 240 |
function theme_buddylist_ui_user_actions($buddyuser) { |
function buddylist_ui_admin_form_delete_submit($form, &$form_state) { |
| 241 |
|
buddylist_api_rtype_delete($form_state['values']['rtid']); |
| 242 |
// Retrieve all actions |
drupal_set_message(t('Relationship has been deleted.')); |
| 243 |
global $user; |
$form_state['redirect'] = 'admin/buddylist/rtypes'; |
|
$actions = buddylist_ui_get_buddy_actions($user, $buddyuser); |
|
|
|
|
|
// Return actions as a list, if there are any |
|
|
if ($actions) |
|
|
return array ('title' => t('@Buddy actions', buddy_api_translation()), 'value' => theme('item_list', $actions), 'class' => 'buddylist_actions'); |
|
| 244 |
} |
} |