Index: user_relationships_panels_visibility/user_relationships_panels_visibility.module =================================================================== --- user_relationships_panels_visibility/user_relationships_panels_visibility.module (revision 0) +++ user_relationships_panels_visibility/user_relationships_panels_visibility.module (revision 589) @@ -0,0 +1,15 @@ + t("User: Relationship Profile Access"), + 'description' => t('Control access to profile based on the user\'s relationship to this user'), + 'callback' => 'user_relationships_panels_visibility_ctools_access_check', + 'default' => array('perm' => 'access content'), + 'settings form' => 'user_relationships_panels_visibility_ctools_access_settings', + 'summary' => 'user_relationships_panels_visibility_ctools_access_summary', + 'required context' => new ctools_context_required(t('User'), 'user'), + ); + + return $args; +} + +/** + * Settings form for the 'by perm' access plugin + */ +function user_relationships_panels_visibility_ctools_access_settings(&$form, &$form_state, $conf) { + + $relationships = user_relationships_types_load(); + $options = array(); + foreach ($relationships as $key => $relationship) { + $options[$key] = $relationship->name; + } + + $form['settings']['disclaimer'] = array( + '#type' => 'markup', + '#value' => t('This access plugin does not use the user context setting ("User being viewed" or "Logged-in User" above). It only uses the currently logged-in user\'s relationships'), + ); + $form['settings']['panels_visibility'] = array( + '#type' => 'checkboxes', + '#options' => $options, + '#title' => t('Allow logged-in user to view if they have this relationship to profile user'), + '#description' => t('Allow access to the profile if viewing user has this relationship to profile user.'), + '#default_value' => $conf['panels_visibility'], + + ); +} + +/** + * Check for access. + */ +function user_relationships_panels_visibility_ctools_access_check($conf, $context) { + +// dsm($conf, "conf"); +// dsm($context, 'context'); + // As far as I know there should always be a context at this point, but this + // is safe. + if (empty($context) || empty($context->data)) { + return FALSE; + } + + // Note that we ignore the passed in user context and use the current user instead + global $user; + + $profile_owner = menu_get_object('user_uid_optional'); + if (!$profile_owner) { + return FALSE; + } + + $relationships = user_relationships_load(array("between" => array($user->uid, $profile_owner->uid))); + foreach ($relationships as $relationship) { + // If this relationship is in the conf file + if (!empty($conf['panels_visibility'][$relationship->rtid])) { + // If no approval required, or approval has been granted + if ( !$relationship->requires_approval || ($relationship->requires_approval && $relationship->approved) ) { + // If not a oneway, or else it is a oneway requested by this user + if (!$relationship->is_oneway || ($relationship->requester_id == $user->uid)) { + return TRUE; + } + } + } + } + return FALSE; + +} + + +/** + * Provide a summary description based upon the checked roles. + */ +function user_relationships_panels_visibility_ctools_access_summary($conf, $context) { + if (!isset($conf['panels_visibility'])) { + return t('Error, unset permission'); + } + + $relationship_types = user_relationships_types_load(); + + $names = array(); + foreach (array_filter($conf['panels_visibility']) as $rtid) { + $names[] = check_plain($relationship_types[$rtid]->name); + } + + if (empty($names)) { + return t('@identifier can have any relationship', array('@identifier' => $context->identifier)); + } + + return format_plural(count($names), '@identifier must have relationship "@rtids"', '@identifier can have relationships: "@rtids"', array('@rtids' => implode(', ', $names), '@identifier' => $context->identifier)); +} + + Index: user_relationships_panels_visibility/user_relationships_panels_visibility.info =================================================================== --- user_relationships_panels_visibility/user_relationships_panels_visibility.info (revision 0) +++ user_relationships_panels_visibility/user_relationships_panels_visibility.info (revision 589) @@ -0,0 +1,7 @@ +; $Id: user_relationships_panels_perm.info,v 1.4.2.1 2009/02/04 13:42:50 rfay Exp $ +name = UR-Panels Visibility +description = "Provide visibility for panels panes and pages based on User Relationships" +dependencies[] = user_relationships_api +dependencies[] = panels +core = 6.x +package = "User Relationships"