We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit c5e22708 authored by tobyink's avatar tobyink

group leaving/joining

parent cb23bab9
......@@ -6,6 +6,6 @@ RewriteRule ^artist/([^/]+)/track/([^/]+)/?$ track.php?artist=$1&track=$2 [B,
RewriteRule ^artist/([^/]+)/album/([^/]+)/track/([^/]+)/?$ track.php?artist=$1&album=$2&track=$3 [B,NC]
RewriteRule ^artist/([^/]+)/album/([^/]+)/?$ album.php?artist=$1&album=$2 [B,NC]
RewriteRule ^artist/([^/]+)/?$ artist.php?artist=$1 [B,NC]
RewriteRule ^group/([^/]+)/?$ group.php?group=$1 [B,NC]
RewriteRule ^group/([^/]+)/?$ group.php?group=$1 [B,NC,QSA]
RewriteRule ^country/([^/]+)/?$ location.php?country=$1 [B,NC]
RewriteRule ^logout login.php?action=logout [B,NC]
......@@ -127,6 +127,14 @@ class Group {
return Server::getGroupURL($this->name);
}
function getURLAction ($action) {
$url = $this->getURL();
if (strstr($url, '?'))
return $url . '&action=' . urlencode($action);
else
return $url . '?action=' . urlencode($action);
}
function getUsers () {
global $mdb2;
......@@ -135,12 +143,13 @@ class Group {
$res = $mdb2->query("SELECT u.* "
. "FROM Users u "
. "INNER JOIN Group_Members gm ON u.username=gm.member "
. "WHERE gm.groupname=".$mdb2->quote($this->name,'text'));
. "WHERE gm.groupname=".$mdb2->quote($this->name,'text')
. " ORDER BY gm.joined");
if ($res->numRows())
{
while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC))
{
$this->users[] = new User($row['username'], $row);
$this->users[ $row['username'] ] = new User($row['username'], $row);
}
}
......@@ -150,6 +159,51 @@ class Group {
return $this->users;
}
function memberCheck ($user) {
$users = $this->getUsers();
if ($users[ $user->name ]->name == $user->name)
return true;
return false;
}
function memberJoin ($user) {
if (memberCheck($user))
return false;
global $mdb2;
$res = $mdb2->query(sprintf("INSERT INTO Group_Members (%s, %s, %d)",
$mdb->quote($this->name, 'text'),
$mdb->quote($user->name, 'text'),
time()));
if(PEAR::isError($res))
return false;
$this->users[ $user->name ] = $user;
return true;
}
function memberLeave ($user) {
if (!memberCheck($user))
return false;
// Group owner cannot leave, so we need a way to reassign ownership.
if ($this->owner->name == $user->name)
return false;
global $mdb2;
$res = $mdb2->query(sprintf("DELETE FROM Group_Members WHERE groupname=%s AND member=%s",
$mdb->quote($this->name, 'text'),
$mdb->quote($user->name, 'text')));
if(PEAR::isError($res))
return false;
$this->users[ $user->name ] = null;
// The array key still exists though. That's annoying. PHP needs an equivalent of Perl's 'delete'.
// This shouldn't actually cause us any problems, but people should be aware of the oddness.
return true;
}
function tagCloudData () {
return TagCloud::generateTagCloud(
......
......@@ -25,6 +25,13 @@ require_once('data/Group.php');
require_once('data/TagCloud.php');
require_once('data/Server.php');
if (! $_GET['group'])
{
print "Here we should provide a list of existing groups, perhaps largest first.";
exit;
}
$group = new Group($_GET['group']);
if(isset($group->name)) {
......@@ -35,12 +42,20 @@ if(isset($group->name)) {
$smarty->assign('bio', $group->bio);
$smarty->assign('homepage', $group->homepage);
$smarty->assign('avatar', $group->getAvatar());
$aUserTagCloud = $group->tagCloudData();
if (!PEAR::isError ($aUserTagCloud)) {
$smarty->assign('group_tagcloud',$aUserTagCloud);
}
$smarty->assign('userlist', $group->getUsers());
$smarty->assign('userlist', $group->getUsers());
$smarty->assign('ismember', $group->memberCheck($_SESSION['user']));
$smarty->assign('isowner', ($group->owner->name==$_SESSION['user']->name));
$smarty->assign('link_join', $group->getURLAction('join'));
$smarty->assign('link_leave', $group->getURLAction('leave'));
$smarty->assign('link_edit', $base_url.'/edit_group.php?group='.$group->name);
$smarty->assign('extra_head_links', array(
array(
'rel' => 'meta',
......
......@@ -3,9 +3,20 @@
<h2 property="dc:title">Group: {$fullname|escape:'html':'UTF-8'}</h2>
<div about="#usergroup" typeof="foaf:Group" property="foaf:nick" content="{$group|escape:'html':'UTF-8'}">
<span property="foaf:name" content="{$fullname|escape:'html':'UTF-8'}"></span>
{if $homepage}<a rel="foaf:page" href="{$homepage|escape:'html':'UTF-8'}">{$homepage|escape:'html':'UTF-8'}</a>{/if}
<p class="note" property="dc:abstract">{$bio|escape:'html':'UTF-8'}</p>
<div class="group vcard">
<div class="avatar" rel="foaf:depiction">
<img src="{$avatar|escape:'html':'UTF-8'}" alt="avatar" class="photo" width="64" height="64" />
</div>
{if $ismember}
<a class="edit" href="{$base_url}/edit_profile.php">[edit]</a>
{/if}
<abbr class="fn org" property="foaf:name" content="{$fullname|escape:'html':'UTF-8'}" title="{$fullname|escape:'html':'UTF-8'}" style="display:none"></abbr>
{if $homepage}<a class="url" rel="foaf:page" href="{$homepage|escape:'html':'UTF-8'}">{$homepage|escape:'html':'UTF-8'}</a>{/if}
<p class="note" property="dc:abstract">{$bio|escape:'html':'UTF-8'}</p>
</div>
<ul rel="foaf:member" class="userlist">
{foreach from=$userlist item=me}
......
......@@ -7,8 +7,14 @@
<img src="{$avatar|escape:'html':'UTF-8'}" alt="avatar" class="photo" width="64" height="64" />
</div>
{if $isme}
<a class="edit" href="{$base_url}/edit_profile.php">[edit]</a>
{if $ismember}
{if $isowner}
<a class="edit" href="{$link_edit}">[edit]</a>
{else}
<a class="edit" href="{$link_leave}">[leave]</a>
{/if}
{else}
<a class="edit" href="{$link_join}">[join]</a>
{/if}
<dl>
......
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