View source
<?php
class space_og extends space_type_purl {
var $group = NULL;
function __construct($type, $id = NULL) {
parent::__construct($type, $id);
$this->og = og_get_group('node', $this->id);
}
function title() {
return $this->group->title;
}
function activate() {
if (parent::activate()) {
if (!empty($this->group->og_theme)) {
global $custom_theme;
$custom_theme = $this->group->og_theme;
}
return TRUE;
}
return FALSE;
}
function load() {
if ($this->id === 0) {
return TRUE;
}
else {
if ($this->group = node_load($this->id)) {
return TRUE;
}
}
return FALSE;
}
function access_space($account = NULL) {
global $user;
$account = isset($account) ? $account : $user;
return parent::access_space($account) && (user_access('administer group') || $this->group->{OG_ACCESS_FIELD}[LANGUAGE_NONE][0]['value'] != 1 || og_is_member($this->og->gid, 'user', $account) || user_is_anonymous());
}
function access_admin($account = NULL) {
global $user;
$account = isset($account) ? $account : $user;
if ($this->og && ($this
->og_is_group_admin($this->og, $account) || $this->group->uid === $account->uid)) {
return TRUE;
}
else {
if (user_access('administer spaces', $account) || user_access('administer group', $account)) {
return TRUE;
}
}
return parent::access_admin($account);
}
function access_feature($op = 'view', $feature, $account = NULL) {
$access = parent::access_feature($op, $feature, $account);
global $user;
$account = isset($account) ? $account : $user;
$membership = FALSE;
if ($membership = og_get_group_membership($this->og->gid, 'user', $account->uid)) {
$membership = $membership->state;
}
$access = $access && (user_access('administer group') || $this->group->{OG_ACCESS_FIELD}[LANGUAGE_NONE][0]['value'] == OG_CONTENT_ACCESS_PUBLIC || $membership);
if ($op === 'create') {
return $access && og_is_member($this->og->gid, 'user', $account);
}
return $access;
}
function access_user($op = 'view', $account = NULL) {
global $user;
$account = isset($account) ? $account : $user;
$test_user = og_is_member($this->og->gid, 'user');
$test_account = og_is_member($this->og->gid, FALSE, $account->uid);
if ($test_user && $test_account || user_access('view users outside groups')) {
return parent::access_user($op, $account);
}
return FALSE;
}
function router($op, $object = NULL, $is_active = TRUE) {
global $user;
switch ($op) {
case 'init':
return;
case 'node':
$node = $object;
$form = !isset($node->nid) || isset($node->date) ? TRUE : FALSE;
if (og_is_group_type('node', $node->type)) {
if (!isset($node->nid) && $this->active) {
$this
->deactivate();
return;
}
else {
if (isset($node->nid) && (!$this->active || $this->active && $this->id != $node->nid) && ($space = spaces_load('og', $node->nid))) {
$space
->activate();
return;
}
}
}
else {
if (og_is_group_content_type('node', $node->type)) {
if (!empty($node->{OG_AUDIENCE_FIELD}[LANGUAGE_NONE])) {
foreach ($node->{OG_AUDIENCE_FIELD}[LANGUAGE_NONE] as $item) {
$gids[] = $item['gid'];
}
}
if ($this->active && in_array($this->og->gid, $gids)) {
return;
}
$gid = reset($gids);
if ($gid) {
spaces_load('og', og_load($gid)->etid)
->activate();
}
return;
}
}
break;
}
}
function views_filter(&$query, $base_table = '', $relationship = '') {
switch ($base_table) {
case 'node':
$table = $query
->ensure_table('field_data_group_audience', $relationship);
$query
->add_where(0, "{$table}.group_audience_gid", $this->og->gid);
break;
case 'users':
$table = $query
->ensure_table('og_membership', $relationship);
$query
->add_where(0, "{$table}.gid", $this->og->gid);
break;
}
}
function group_node_admin_access($node) {
if ($node && og_is_group_type('node', $node->type)) {
return $this
->admin_access();
}
return FALSE;
}
function og_is_group_admin($group, $account) {
$membership = og_get_group_membership($group->gid, 'user', $account->uid);
if (isset($membership->state) && $membership->state == OG_STATE_ACTIVE) {
return og_user_access($group->gid, 'manage group space', $account);
}
return FALSE;
}
protected function excluded_paths() {
$excluded = parent::excluded_paths();
$excluded[] = 'og';
$excluded[] = 'og/my';
$excluded[] = 'og/all';
return $excluded;
}
}