Index: C:/Documents and Settings/gehren/My Documents/workspace/neurovation/sites/all/modules/profile_privacy/profile_privacy.module =================================================================== --- C:/Documents and Settings/gehren/My Documents/workspace/neurovation/sites/all/modules/profile_privacy/profile_privacy.module (revision 19819) +++ C:/Documents and Settings/gehren/My Documents/workspace/neurovation/sites/all/modules/profile_privacy/profile_privacy.module (working copy) @@ -1,5 +1,7 @@ uid); $profile_fields = profile_privacy_get_fields(); $return_fields = array(); - // Do not hide any information from administers - if (!user_access('administer users')) { + + if ( profile_privacy_hide_fields($account,$category) ) { foreach ($profile_fields as $field) { // If the user has set a privacy option, this always takes precidence. if (isset($account->{'private_'. $field->name}) && $field->privacy) { @@ -63,6 +65,12 @@ $edit['private_'. $field->name] = NULL; } } + if (isset($edit['private_show_buddies'])) { + profile_privacy_set_user_setting($account->uid,PROFILE_PRIVACY_SETTING_SHOW_BUDDIES,isset($edit['private_show_buddies'])); + // Set field to NULL to prevent user.module from saving in user table. + $edit['private_show_buddies'] = NULL; + } + break; case 'delete': profile_privacy_delete_user_privacy($account->uid); @@ -114,9 +122,13 @@ $profile_fields = profile_privacy_get_fields($category); $form[$category]['#theme'] = 'profile_privacy_category'; + $private_field_exists=false; foreach ($profile_keys as $key) { if ($profile_fields[$key]->privacy) { + + $private_field_exists=true; + // Remove descriptions about current privacy rules $form[$category][$key]['#description'] = str_replace(' '. t('The content of this field is kept private and will not be shown publicly.'), '', $form[$category][$key]['#description']); // Create the privacy checkbox @@ -141,6 +153,21 @@ $form[$category] = array_merge($form_first, $privacy_checkbox, $form_last); } } + + if ($private_field_exists && module_exists('buddy_api')) + { + $settings = profile_privacy_get_user_setting($account->uid); + + $privacy_checkbox=array(); + $privacy_checkbox['private_show_buddies'] = array( + '#type' => 'checkbox', + '#title' => t('Show ALL profile information to my @buddylist.',buddy_api_translation()), + '#description' => t('Show ALL profile information to my @buddylist.',buddy_api_translation()), + '#default_value' => $settings[PROFILE_PRIVACY_SETTING_SHOW_BUDDIES], + ); + + $form[$category][]=$privacy_checkbox; + } } function profile_privacy_profile_field_submit($form_id, $form_values) { @@ -185,7 +212,29 @@ return isset($users[$uid]) ? $users[$uid] : array(); } +function profile_privacy_set_user_setting($uid, $setting, $value) { + + db_query('DELETE FROM {profile_privacy_user_setting} WHERE uid = %d AND setting = %d', $uid, $setting); + db_query('INSERT INTO {profile_privacy_user_setting} (setting, uid, value) VALUES (%d, %d, %d)', $setting, $uid, $value); +} + +function profile_privacy_get_user_setting($uid, $reset = FALSE) { + static $users = array(); + + if (!isset($users[$uid]) || $reset) { + $result = db_query('SELECT setting.* FROM {profile_privacy_user_setting} setting WHERE uid = %d', $uid); + if (db_num_rows($result)) { + while ($row = db_fetch_object($result)) { + $users[$row->uid][$row->setting] = $row->value; + } + } + } + return isset($users[$uid]) ? $users[$uid] : array(); + +} + function profile_privacy_delete_user_privacy($uid) { + db_query('DELETE FROM {profile_privacy_user_settings} WHERE uid = %d', $uid); return db_query('DELETE FROM {profile_privacy_values} WHERE uid = %d', $uid); } @@ -229,3 +278,25 @@ return $fields; } + +function profile_privacy_hide_fields($account,$category) { + global $user; + + // Do not hide any information from administers + if (user_access('administer users')) + return false; + + + // check if buddy - and if set to show all info to budies + if (module_exists('buddy_api')) { + $setting = profile_privacy_get_user_setting($account->uid); + if ($setting[PROFILE_PRIVACY_SETTING_SHOW_BUDDIES] == 1) { + if (array_key_exists($account->uid, buddy_api_get_buddies())) { + return false; + } + } + } + // hide the fields + return true; +} +