summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Kiss2008-01-07 13:14:51 (GMT)
committer Dominik Kiss2008-01-07 13:14:51 (GMT)
commit60925491399d682441f1be47ca51be057e1323de (patch)
treeb226feea20c039a685d084cd02d0ef9f6b32d8b6
parentf1c26b08f7d687d261940875c61f82b6fcb62972 (diff)
FIX #1:
Made persistent menu items cached, using user.module as a model. This is required to allow admins to customize / move them. Note the change from MENU_SUGGESTED_ITEM to MENU_NORMAL_ITEM to show up in navigation by default. FIX #2: Streamlined buddylist_ui_user to generate output through themeable functions. In buddylist_ui_get_buddy_actions added keys to the action list to allow further theming customization by name. E.g. to make "Remove Friend" harder to find, like on Facebook. FIX #3: Removed buddylist_ui_buddy_api function, which is never used and is unnecessary
-rw-r--r--buddylist_ui/README.txt5
-rw-r--r--buddylist_ui/buddylist_ui.module166
2 files changed, 87 insertions, 84 deletions
diff --git a/buddylist_ui/README.txt b/buddylist_ui/README.txt
index 1870f0a..323ca62 100644
--- a/buddylist_ui/README.txt
+++ b/buddylist_ui/README.txt
@@ -80,11 +80,12 @@ INSTALLATION:
for authenticated users at
administer -> user management -> access control
-6. Activate the needed views (buddy_api_buddylist,
+
+[6. Activate the needed views (buddy_api_buddylist,
buddy_api_received_requests and buddy_api_sent_requests)
it the views UI at
administer -> site building -> views
- (Views UI must be enabled to do this)
+ (Views UI must be enabled to do this)]
7. goto ?q=buddylist and see your buddylist central managing page
[add a menu item, which points to ?q=buddylist]
diff --git a/buddylist_ui/buddylist_ui.module b/buddylist_ui/buddylist_ui.module
index 709fa8b..ac02ec0 100644
--- a/buddylist_ui/buddylist_ui.module
+++ b/buddylist_ui/buddylist_ui.module
@@ -45,7 +45,48 @@ function buddylist_ui_menu($may_cache) {
$id = is_numeric(arg(1)) ? arg(1) : $user->uid;
$editAccess = (($id == $user->uid && user_access('maintain buddy list') && $user->uid) || user_access('administer users'));
- if (!$may_cache) {
+ // Menu structure loosely based on user.module
+ if ($may_cache) {
+ $items[] = array (
+ 'path' => 'buddylist',
+ 'title' => t('My @buddylist', buddylist_ui_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', buddylist_ui_translation()),
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'weight' => 1,
+ );
+
+ // user page: pending requests
+ $items[] = array(
+ 'path' => 'buddylist/requests',
+ 'title' => t('My @Buddy Requests', buddylist_ui_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', buddylist_ui_translation()),
@@ -88,47 +129,6 @@ function buddylist_ui_menu($may_cache) {
'callback' => 'drupal_get_form',
'callback arguments' => array ('buddylist_ui_cancel_request', $id),
);
-
- // user page: buddylist overview
- $items[] = array (
- 'path' => 'buddylist',
- 'title' => t('My @buddylist', buddylist_ui_translation()),
- 'callback' => 'theme',
- 'callback arguments' => array('buddylist_ui_page_buddylist', $id),
- 'type' => MENU_SUGGESTED_ITEM,
- 'weight' => 0,
- 'access' => $editAccess,
- );
-
- // user page: buddylist
- $items[] = array (
- 'path' => 'buddylist/confirmed',
- 'title' => t('My @Buddies', buddylist_ui_translation()),
- 'type' => MENU_DEFAULT_LOCAL_TASK,
- 'weight' => 0,
- );
-
- // user page: pending requests
- $items[] = array(
- 'path' => 'buddylist/requests',
- 'title' => t('My @Buddy Requests', buddylist_ui_translation()),
- 'access' => $editAccess,
- 'callback' => 'theme',
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 1,
- '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'),
- );
-
}
return $items;
}
@@ -300,18 +300,18 @@ function buddylist_ui_get_buddy_actions(& $viewing_user, & $viewed_user) {
}
if (in_array($viewed_user->uid, array_keys(buddy_api_get_requestees($viewing_user->uid)))) {
- $actions[] = theme('buddylist_ui_action_sent_request', $viewed_user);
+ $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[] = theme('buddylist_ui_action_remove_buddy', $viewed_user);
+ $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[] = theme('buddylist_ui_action_confirm_request', $viewed_user);
+ $actions['buddy_confirm'] = theme('buddylist_ui_action_confirm_request', $viewed_user);
}
else {
- $actions[] = theme('buddylist_ui_action_add_buddy', $viewed_user);
+ $actions['buddy_add'] = theme('buddylist_ui_action_add_buddy', $viewed_user);
}
return $actions;
@@ -322,36 +322,13 @@ function buddylist_ui_get_buddy_actions(& $viewing_user, & $viewed_user) {
* @return
*/
function buddylist_ui_user($type, & $edit, & $thisuser, $category = NULL) {
- global $user;
-
- $output = array ();
if ($type == 'view') {
- //
- $view = views_get_view('buddy_api_buddylist');
- $view_received_requests = views_build_view('embed', $view, array(), FALSE);
- if (!strlen($view_received_requests)){
- $view_received_requests .= '<p>'. t('NONE') .'</p>';
- }
- $themed_received_requests = theme_box('', $view_received_requests, $region = 'main');
- //
- if(strlen($themed_received_requests) > 0 && (user_access('view buddy lists') || $user->uid == $thisuser->uid)){
- $output[] = array ('title' => t('@Buddies', buddylist_ui_translation()), 'value' => $themed_received_requests);
- }
- /*if ($list = buddylist_ui_get_buddylist($thisuser)) {
- $output[] = array ('title' => t('@Buddies', buddylist_ui_translation()), 'value' => $list, 'class' => 'buddylist');
- }*/
- /*if ($list = buddylist_ui_get_buddylist($thisuser, TRUE)) {
- $output[] = array ('title' => t('@buddy of', buddylist_ui_translation()), 'value' => $list, 'class' => 'buddyoflist');
- }*/
- if ($actions = buddylist_ui_get_buddy_actions($user, $thisuser)) {
- $output[] = array ('title' => t('Buddy actions'), 'value' => theme('item_list', $actions), 'class' => 'buddylist_actions');
- }
- if (count($output) > 0) {
- return array (
- t('@Buddylist', buddylist_ui_translation()) => $output
- );
- }
+ $output = array();
+ $output[] = theme('buddylist_ui_user_buddies', $thisuser);
+ $output[] = theme('buddylist_ui_user_actions', $thisuser);
+ if (count($output) > 0)
+ return array (t('@Buddylist', buddylist_ui_translation()) => $output);
}
else
if ($type == 'delete') {
@@ -365,6 +342,7 @@ function buddylist_ui_user($type, & $edit, & $thisuser, $category = NULL) {
}
}
+
/**
* @param $uid
* @return
@@ -550,16 +528,40 @@ function theme_buddylist_ui_page_pending_requests($id) {
return $themed_received_requests . $themed_sent_requests;
}
-
/**
- * implementation of buddy_api (module: buddy_api)
- * @param $op
- * @param $userA
- * @param $userB
- * @param $buddyinfo
+ * Themes default display of buddies on user profile
+ *
+ * @return string, html formatted output
*/
-function buddylist_ui_buddy_api($op, $userA, $userB, &$buddyinfo){
- $buddyinfo['oneway'] = variable_get('buddylist_ui_oneway', 0);
+function theme_buddylist_ui_user_buddies($buddyuser) {
+
+ // Permission check first
+ global $user;
+ if ( !user_access('view buddy lists') && $buddyuser->uid != $user->uid) return;
+
+ // Display entire buddylist page
+ $view = views_get_view('buddy_api_buddylist');
+ $view_buddylist = views_build_view('embed', $view, array(), FALSE);
+ if (!strlen($view_buddylist)){
+ $output .= '<p>'. t('NONE') .'</p>';
+ }
+ $output .= $view_buddylist;
+
+ return array ('title' => t('@Buddies', buddylist_ui_translation()), 'value' => theme_box('', $output, $region = 'main'));
}
+/**
+ * Themes default display of buddy actions on user profile
+ *
+ * @return string, html formatted output
+ */
+function theme_buddylist_ui_user_actions($buddyuser) {
+
+ // Retrieve all actions
+ global $user;
+ $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', buddylist_ui_translation()), 'value' => theme('item_list', $actions), 'class' => 'buddylist_actions');
+} \ No newline at end of file