Closed (won't fix)
Project:
Buddylist
Version:
4.7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
10 Nov 2006 at 03:33 UTC
Updated:
30 Jan 2013 at 21:44 UTC
The privacy feature I've developed for this module is not a patch to buddylist.module.
REQUIREMENTS:
Drupal 4.7 (w/ PHPTemplate)
Buddylist.module with accept/reject feature
Here's what I've done:
1. Create a privacy table
--
-- Table structure for table `privacymode`
--
CREATE TABLE `privacymode` (
`uid` int(11) NOT NULL default '0',
`privacyid` int(11) NOT NULL default '0',
PRIMARY KEY (`uid`,`privacyid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
2. Create a new page in your Drupal site
<?php
global $user;
echo '<form enctype="multipart/form-data" action="process.php" method="post">
Who can see your profile:<br><br>
<INPUT TYPE=RADIO NAME="Selectprivacymode" VALUE="1">Your friends only<br>
<INPUT TYPE=RADIO NAME="Selectprivacymode" VALUE="2">All registered users<br><br>
<input type="hidden" name="Useridnumber" value="';?><?php print $user->uid ?>
<?php
global $user;
echo '">
<input class="inputsubmit" type=submit value="Save"> <input class="inputsubmit" type=reset value="Cancel"></form>'; ?>
3. Create a global.inc.php file
<?php
function pt_register()
{
$num_args = func_num_args();
$vars = array();
if ($num_args >= 2) {
$method = strtoupper(func_get_arg(0));
if (($method != 'SESSION') && ($method != 'GET') && ($method != 'POST') && ($method != 'SERVER') && ($method != 'COOKIE') && ($method != 'ENV')) {
die('The first argument of pt_register must be one of the following: GET, POST, SESSION, SERVER, COOKIE, or ENV');
}
$varname = "HTTP_{$method}_VARS";
global ${$varname};
for ($i = 1; $i < $num_args; $i++) {
$parameter = func_get_arg($i);
if (isset(${$varname}[$parameter])) {
global $$parameter;
$$parameter = ${$varname}[$parameter];
}
}
} else {
die('You must specify at least two arguments');
}
}
?>
4. Create a process.php file (which the form action will post to)
<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','Selectprivacymode');
pt_register('POST','Useridnumber');
if($errors==1) echo $error;
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Selectprivacymode: ".$Selectprivacymode."
Useridnumber: ".$Useridnumber."
";
if ($_SERVER['HTTP_REFERER'] !=("http://yoursite.com/?q="); //Change URL to where the form is located. It's
//It's a weak but effective security feature
header("Location: http://yoursite.com/error"); //Create an error page
} else {
$link = mysql_connect("HOST","USERNAME","PASSWORD");
mysql_select_db("DATABASE",$link);
$query =mysql_query("SELECT uid FROM privacymode WHERE uid = '$Useridnumber'");
$result = mysql_num_rows($query);
if ($result > "0") {
$query = "UPDATE privacymode SET privacyid = '$Selectprivacymode' WHERE uid = '$Useridnumber'";
mysql_query($query);
} else {
$query="INSERT into privacymode (privacyid,uid) values (".$Selectprivacymode.",".$Useridnumber.")";
mysql_query($query);
}
}
}
?>
5. Create a private profile, save it as private_profile.tpl.php, place it in your default template folder.
6. Create a public profile, save it as user_profile.tpl.php, place it in your default template folder.
7. Insert snippet into template.php
<?php
function phptemplate_user_profile($user, $fields = array()) {
$link = mysql_connect("HOST","USER","PASSWORD");
mysql_select_db("DATABASE",$link);
$sql = "SELECT privacyid FROM privacymode WHERE uid = '{$user->uid}'";
$result = mysql_query($sql) or die ("Unable to run $sql: " . mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
if ($user->uid == ($GLOBALS['user']->uid)){ //viewing own profile
return _phptemplate_callback('user_profile', array('user' => $user, 'fields' => $fields));
} else if ($row['privacyid'] == 2){ //public profile
return _phptemplate_callback('user_profile', array('user' => $user, 'fields' => $fields));
} else if ($row['privacyid'] == 1){ //private profile
if (@in_array($user->uid, array_keys(buddylist_get_buddies($account->uid))) && user_access('maintain buddy list')) { //user is friend
return _phptemplate_callback('user_profile', array('user' => $user, 'fields' => $fields));
} else { //user is not friend
return _phptemplate_callback('private_profile', array('user' => $user, 'fields' => $fields));
}
} else if ($row['privacyid'] == NULL){ //profile user has not selected a privacy mode
return _phptemplate_callback('private_profile', array('user' => $user, 'fields' => $fields));
} else { //some error
print 'Privacy mode error';
}
}
function phptemplate_profile_listing($user, $fields = array()) {
$link = mysql_connect("HOST","USER","PASSWORD");
mysql_select_db("DATABASE",$link);
$sql = "SELECT privacyid FROM privacymode WHERE uid = '{$user->uid}'";
$result = mysql_query($sql) or die ("Unable to run $sql: " . mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
if ($user->uid == ($GLOBALS['user']->uid)){ //viewing own profile
return _phptemplate_callback('profile_listing', array('user' => $user, 'fields' => $fields));
} else if ($row['privacyid'] == 2){ //public profile
return _phptemplate_callback('profile_listing', array('user' => $user, 'fields' => $fields));
} else if ($row['privacyid'] == 1){ //private profile
if (@in_array($user->uid, array_keys(buddylist_get_buddies($account->uid))) && user_access('maintain buddy list')) { //user is friend
return _phptemplate_callback('profile_listing', array('user' => $user, 'fields' => $fields));
} else { //user is not friend
return _phptemplate_callback('private_profile_list', array('user' => $user, 'fields' => $fields));
}
} else if ($row['privacyid'] == NULL){ //profile user has not selected a privacy mode
return _phptemplate_callback('private_profile_list', array('user' => $user, 'fields' => $fields));
} else { //some error
print 'Privacy mode error';
}
}
?>
Let me know if you have any questions.
Comments
Comment #1
Popboard commentedI thought I stopped it from posting, but I guess I didn't. Can someone delete the other three issues? I wish we could edit our posts to make corrections...
Comment #2
Popboard commentedAlso, the PHPTemplate snippet above has a function for the 'My Buddies' list..so you would want to make a profile_listing.tpl.php and a private_profile_list.tpl.php file.
Comment #3
ngstigator commentedAre you also using organic groups, by chance? I understand that Drupal doesn't like using mixing privacy modules, and I'd be very interested in seeing if buddylist privacy and og play nice.
Comment #4
Popboard commentedYes, however, my site ( http://thepopboard.com/ ) doesn't allow groups for buddies only. Actually there really are no privacy settings for groups on my site.
Comment #5
Popboard commentedAlso, you can insert custom snippets and custom forms (perhaps multiple forms on a single 'privacy' page) to have different privacy settings for different nodes (insert PHPTemplate snippets in blog.tpl.php, node-quotes.tpl.php, etc)
Comment #6
simon georges commentedThis version of Buddylist is not supported anymore. The issue is closed for this reason.
Please upgrade to a supported version and feel free to reopen the issue on the new version if applicable.