Commit e341ee1e authored by robertDouglass's avatar robertDouglass

zapping the forked, out of date, untagged CVS version of buddylist. Adding...

zapping the forked, out of date, untagged CVS version of buddylist. Adding info into the README explaining why.
parent 0e28c08c
Readme
------
This module allows users to put each other on a personal 'Buddy List'.
Features include buddy groups and the ability to track your buddies' recent posts.
Where is the module???
Send comments to Robert Douglass at: http://drupal.org/user/5449/contact
You're looking at the CVS version of the buddylist module. It doesn't exist.
Available versions are:
DRUPAL-4-5
DRUPAL-4-6
DRUPAL-4-7
DRUPAL-5-0
Requirements
------------
This module requires Drupal 4.7.
This module does not yet offer PostgreSQL support. If you would like to contribute to this module by creating the appropriate PostgreSQL schema, please submit your code at http://drupal.org/project/issues/buddylist
As of this writing, all of the 4-* versions can be downloaded from the modules page:
http://drupal.org/project/Modules
The DRUPAL-5-0 modules aren't being tarballed yet (October 25, 2006), so you have to get that version straight from CVS:
Upgrading from 4.6
------------------
WARNING: There is currently no migration path from 4.6 to 4.7. There are significant database schema changes and the 4.7 module will not work with the 4.6 schema. A migration path is forthcoming. If you need one sooner, contact me: http://drupal.org/user/5449/contact
cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib co -d buddylist -r DRUPAL-5-0 contributions/modules/buddylist
Installation
------------
1. Copy the buddylist.module to the Drupal modules/ directory.
Why no CVS version?
2. Enable buddy list in the "site settings | modules" administration screen.
It is the least useful version that Drupal has. If you are actually honestly maintaining your module against the CVS development branch of Drupal, fine, have a CVS version of your module. The typical case is much uglier, however, and has led to our cvs repository being horribly disorganized. The typical case is that a module author wants to check in a new module and learns just enough CVS to get it into the repository, without a tag. Thus you find modules in the CVS repository, without tags, that are intended to be used with every imaginable flavor of Drupal. It is a mess.
Enabling the buddylist module will trigger the creation of the database schema. If you are shown error messages you may have to create the schema by hand. Please see the database definition at the end of this file.
3. Enable buddy list blocks you want in the "blocks" administration screen.
4. Optionally add the following theme function to your PHPTemplate's template.php file:
function phptemplate_username($object) {
global $user;
/* Use the default theme_username for anonymous users, nodes by this user */
if ($user->uid == 0 || $object->uid == $user->uid || $object->uid == 0) {
return theme_username($object);
}
if (!user_access('maintain buddy list')) {
return theme_username($object);
}
/* an array, keyed on buddy uids */
$buddies = buddylist_get_buddies($user->uid);
/* Find out if this buddy is in the user's buddy list */
foreach ($buddies as $buddyuid => $buddystructure) {
if ($buddyuid == $object->uid) {
$output .= theme_username($object);
$output .= ' (';
$output .= theme('remove_from_buddylist_link', $object);
$output .= ')';
return $output;
}
}
/* The user is not in the buddylist, give a link to add */
$output .= theme_username($object);
$output .= ' (';
$output .= theme('add_to_buddylist_link', $object);
$output .= ')';
return $output;
}
Database Schema
---------------
If the automatic creation of the database tables was unsuccessful you can try creating the tables by hand using the following SQL:
CREATE TABLE `buddylist` (
`uid` int(10) unsigned NOT NULL default '0',
`buddy` int(10) unsigned NOT NULL default '0',
`timestamp` int(11) NOT NULL default '0',
`received` tinyint(1) NOT NULL default '0',
UNIQUE KEY `uid-buddy-label` (`uid`,`buddy`),
KEY `uid` (`uid`)
) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;
--
-- Table structure for table `buddylist_buddy_group`
--
CREATE TABLE `buddylist_buddy_group` (
`uid` int(11) NOT NULL default '0',
`buddy` int(11) NOT NULL default '0',
`label_id` int(11) NOT NULL default '0',
PRIMARY KEY (`uid`,`buddy`,`label_id`)
) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;
--
-- Table structure for table `buddylist_groups`
--
CREATE TABLE `buddylist_groups` (
`uid` int(11) NOT NULL default '0',
`label_id` int(11) NOT NULL default '0',
`label` varchar(255) NOT NULL default '',
`visible` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`uid`,`label_id`)
) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;
Credits
-------
Written by Adrian Rossouw.
Thanks to Ratko Kovacina for the comments/debugging info
Browsing improvements by Doug Sikora
Maintainer: Robert Douglass
Status: maintained (Feb. 2006)
TODO
----
1. PGSQL schema (see buddylist.install, buddylist_install())
2. Rework texts so that one is not stuck with "buddy" but could choose "contact", for example
3. Make a workflow whereby a buddy request is sent to the buddy for confirmation which is required before the buddy can be added.
4. Make the notification that someone added you to their buddylist use the privatemsg module, if available.
5. Consider possible Views module integration.
\ No newline at end of file
On the other hand, a tagged version of a module is clear; use this version with DRUPAL-*-*. Furthermore, at this time, the development branch of Drupal core IS DRUPAL-5-0. When the development branch is opened up again after the 5-0 release, if someone is interested in chasing it with the buddylist, we'll reinstate the untagged "CVS" version of buddylist.
<?php
// $Id$
/**
* Install the initial schema.
*/
function buddylist_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$query1 = db_query(
<<<MYSQL_UPDATE
CREATE TABLE {buddylist} (
uid int(10) unsigned NOT NULL default '0',
buddy int(10) unsigned NOT NULL default '0',
timestamp int(11) NOT NULL default '0',
received tinyint(1) NOT NULL default '0',
PRIMARY KEY (uid,buddy)
) /*!40100 DEFAULT CHARACTER SET utf8 */;
MYSQL_UPDATE
);
$query2 = db_query(
<<<MYSQL_UPDATE
CREATE TABLE {buddylist_buddy_group} (
uid int(11) NOT NULL default '0',
buddy int(11) NOT NULL default '0',
label_id int(11) NOT NULL default '0',
PRIMARY KEY (uid, buddy, label_id)
) /*!40100 DEFAULT CHARACTER SET utf8 */;
MYSQL_UPDATE
);
$query3 = db_query(
<<<MYSQL_UPDATE
CREATE TABLE {buddylist_groups} (
uid int(11) NOT NULL default '0',
label_id int(11) NOT NULL default '0',
label varchar(255) NOT NULL default '',
visible tinyint(1) NOT NULL default '0',
PRIMARY KEY (uid, label_id)
) /*!40100 DEFAULT CHARACTER SET utf8 */;
MYSQL_UPDATE
);
if ($query1 && $query2 && $query3) {
$created = TRUE;
}
break;
}
if ($created) {
drupal_set_message(t('Buddylist module installed successfully.'));
}
else {
drupal_set_message(t('Table installation for the Buddylist module was unsuccessful. The tables may need to be installed by hand. See the README.txt file for a list of the installation queries.'), 'error');
}
}
function buddylist_update_1() {
return _system_update_utf8(array('buddylist'));
}
\ No newline at end of file
This diff is collapsed.
<?php
// $Id$
/**
* @file
* Add access control to nodes based on buddygroups
*/
/**
* Implementation of hook_help().
*/
function buddylist_access_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('node access control by buddy group');
}
}
function buddylist_access_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
global $user;
switch ($op) {
case 'load':
// nothing yet
break;
case 'form post':
if (user_access('maintain buddy list')) {
// Allow node authors to set 'view' permissions by buddy groups.
if ($edit = $_POST['edit']) {
// do nothing
}
else {
$sql = "SELECT realm FROM {node_access} WHERE nid = %d AND realm LIKE '%s' AND gid = %d";
$result = db_query($sql, $node->nid, 'buddyof%', $node->uid);
while ($row = db_fetch_object($result)) {
$edit['buddylist_groups'][] = substr($row->realm, 9);
}
$form = buddylist_groups_select($node->uid, t('Optional. Restrict access to this post to members of these groups.'), $edit);
$form['buddylist_groups_uid'] = array(
'#type' => 'hidden',
'#value' => $node->uid
);
}
return $form;
}
break;
case 'insert':
case 'update':
buddylist_access_save_access($node);
break;
case 'delete':
$sql = "DELETE FROM {node_access} WHERE nid = %d AND realm LIKE '%s'";
db_query($sql, $node->nid, 'buddyof%');
break;
}
}
function buddylist_access_save_access($node) {
buddylist_access_nodeapi($node, 'delete');
if ($node->buddylist_groups) {
// this check prevents us from entering access control while editing an author. thats dangerous, because we might not have shown the author the right groups on the form
if ($node->buddylist_groups_uid == $node->uid) {
foreach ($node->buddylist_groups as $key => $label) {
$sql = "INSERT INTO {node_access} (nid, realm, gid, grant_view) VALUES (%d, '%s', %d, %d)";
db_query($sql, $node->nid, "buddyof||$label", $node->buddylist_groups_uid, 1);
}
}
}
else {
// if no groups are defined, this is a public node.
$sql = "INSERT INTO {node_access} (nid, gid, realm, grant_view) VALUES (%d, 0, 'buddyof||universal', 1)";
db_query($sql, $node->nid);
}
}
// realm = buddyof||$label
// we use a gid=$node->uid so that all access restrictions become moot during a node author change
function buddylist_access_node_grants($account, $op) {
if ($op == 'view') {
$sql = 'SELECT b.uid, g.label FROM {buddylist} b INNER JOIN {buddylist_groups} g ON b.uid = g.uid INNER JOIN {users} u ON b.uid = u.uid WHERE b.buddy = %d';
$result = db_query($sql, $account->uid);
while ($row = db_fetch_object($result)) {
$grants["buddyof||$row->label"][] = $row->uid;
}
// the universal grant
$grants['buddyof||universal'][] = 0;
return $grants;
}
}
function buddylist_access_settings() {
$op = $_POST['op'];
drupal_set_title(t('Buddylist access configuration'));
$status = t('disabled');
$btn_text = t('Enable');
if (variable_get('buddylist_access_enabled', 0)) {
$status = t('enabled');
$btn_text = t('Disable');
}
$form['module_status'] = array(
'#type' => 'fieldset',
'#title' => t('Module status'),
'#prefix' => t('Buddylist_access access control is currently') . ' ' . theme('placeholder', $status). '.<br />',
'#description' => t('After enabling this module via the module settings page or before disabling this module, use the above button to properly configure your node_access table.')
);
$form['module_status'] = array(
'#type' => 'button',
'#value' => $btn_text,
'#suffix' => '<br />'
);
if ($op) {
if ($op == t('Enable')) {
_buddylist_access_update_db(TRUE);
variable_set('buddylist_access_enabled', 1);
}
elseif ($op == t('Disable')) {
_buddylist_access_update_db(FALSE);
variable_set('buddylist_access_enabled', 0);
}
drupal_goto('admin/settings/buddylist_access');
}
return $form;
}
/**
* Update the node_access table when a user enables/disables the module in the
* settings page. Because Drupal does not, at this
* time, provide hooks that run automatically upon the enabling/disabling of a
* module in the admin/modules page, we must force the site-admin to explicitly
* enable/disable a module on the settings page, in
* addition to enabling/disabling the module in the admin/modules page.
*
* Here, if the user is enabling the module, we make sure the default entry in
* the node_access table is deleted and walk through all the nodes in the node table
* and grant all view access as is the default case when this module is not
* enabled. We only do this for nodes whose permissions haven't been set before by
* this module. It is possible that a site-admin may have previously enabled the
* module before disabling it. Upon re-enabling, we want to account for the old
* permissions set by the module by not re-inserting entries for them.
*
* Disabling the module simply requires re-inserting the default entry back into
* the node access table to give 'view' perms to everyone for everything:
* (0, 0, 'all', 1, 0, 0)
*/
function _buddylist_access_update_db($enable) {
if (!$enable) {
// We use the delete statement to avoid inserting a duplicate entry into the database.
// Without the DELETE query, this can happen when a site admin has already enabled the modules
// from the settings page and goes back to it and resaves the enabled setting.
db_query('REPLACE INTO {node_access} VALUES (0, 0, \'all\', 1, 0, 0)');
drupal_set_message(t('Buddylist_access access control has been disabled. You may now disable the module on the <em>%modules</em> page', array('%modules' => l(t('admin/modules'), 'admin/modules'))));
}
else { // the module was just enabled or re-enabled; provide default view access to everyone for nodes that were created
// between the previous disabling of the module and the current enabling of the module;
// nodes that were created during a previous enabled period are left-alone.
// Permissions for those nodes will be the same as when the module was previously enabled.
db_query('DELETE from {node_access} WHERE nid=0 AND gid=0 AND realm=\'all\' AND grant_view=1 AND grant_update=0 AND grant_delete=0');
// Assign universal grant to all nodes which don't already have any grants from this module
$result = db_query("SELECT n.nid FROM {node} n LEFT JOIN {node_access} na ON n.nid = na.nid AND realm LIKE '%buddyof%' WHERE ISNULL(na.gid)");
while ($row = db_fetch_object($result)) {
$sql = "INSERT INTO {node_access} (nid, gid, realm, grant_view) VALUES (%d, 0, 'buddyof||universal', 1)";
db_query($sql, $row->nid);
}
drupal_set_message(t('Buddylist_access access control enabled.'));
}
}
<?php
// $ID$
function buddylistinvite_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('Integrates the %buddylist and invite modules.', array('%buddylist' => t('buddylist')));
case 'admin/help#buddylistinvite':
return t("<p>Whenever a person resonds to an invitation from the invite module and joins the site, the inviter and invitee are added to each other's %buddy list.</p>", array('%buddy' => t('buddy')));
case 'invite':
if (module_exist('buddylist') && user_access('maintain buddy list')) {
return t('<p>The people you invite will automatically added to your %buddylist when they accept the invitation.</p>', array('%buddylist' => t('buddylist')));
}
break;
}
}
/**
* implementation of hook_invite
* (see invite.module)
*/
function buddylistinvite_invite($op, $args) {
if (!module_exist('buddylist')) {
return;
}
switch ($op) {
case 'escalate':
$time = time();
watchdog('buddylistinvite', t("Users %uid1 and %uid2 are becoming %buddies", array('%uid1' => $args['invitee']->uid, '%uid2' => $args['inviter']->uid, '%buddies' => t('buddies'))));
db_query('INSERT INTO {buddylist} (received, uid, buddy, timestamp) VALUES (1, %d, %d, %d)', $args['invitee']->uid, $args['inviter']->uid, $time);
db_query('INSERT INTO {buddylist} (received, uid, buddy, timestamp) VALUES (1, %d, %d, %d)', $args['inviter']->uid, $args['invitee']->uid, $time);
break;
}
}
function buddylistinvite_settings() {
$allgood = TRUE;
if (!module_exist('buddylist')) {
drupal_set_message(t('The buddylistinvite module depends on the %module module. Please <a href="admin/modules">enable</a> the %module module.', array('%module' => 'buddylist')));
$allgood = FALSE;
}
if (!module_exist('buddylist')) {
drupal_set_message(t('The buddylistinvite module depends on the %module module. Please <a href="admin/modules">enable</a> the %module module.', array('%module' => 'invite')));
$allgood = FALSE;
}
if ($allgood) {
drupal_set_message(t('Everything is ready to go. Inviters and Invitees will become %buddies automatically.', array('%buddies' => t('buddies'))));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment