View source
<?php
class space_og extends space_type_purl {
var $group = NULL;
function title() {
return $this->group->title;
}
function activate() {
if (parent::activate()) {
og_set_group_context($this->group);
og_set_language($this->group);
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) && ($this->group->og_private != 1 || og_is_group_member($this->id, TRUE, $account->uid) || !$account->uid);
}
function access_admin($account = NULL) {
global $user;
$account = isset($account) ? $account : $user;
if ($this->group && (og_is_group_admin($this->group, $account) || $this->group->uid === $account->uid)) {
return TRUE;
}
else {
if (user_access('administer spaces', $account) || user_access('administer organic groups', $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;
$access = $access && (user_access('administer organic groups') || !$this->group->og_private || og_is_group_member($this->id, TRUE, $account->uid));
if ($op === 'create') {
return $access && og_is_group_member($this->id, TRUE, $account->uid);
}
return $access;
}
function access_user($op = 'view', $account = NULL) {
global $user;
$account = isset($account) ? $account : $user;
$test_user = og_is_group_member($this->id);
$test_account = og_is_group_member($this->id, 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->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_omitted_type($node->type) && !empty($node->og_groups)) {
if ($this->active && in_array($this->id, $node->og_groups)) {
return;
}
reset($node->og_groups);
spaces_load('og', current($node->og_groups))
->activate();
return;
}
}
break;
}
}
function views_filter(&$query, $base_table = '', $relationship = '') {
switch ($base_table) {
case 'node':
$table = $query
->ensure_table('og_ancestry', $relationship);
$query
->add_where(0, "{$table}.group_nid = ***CURRENT_GID***");
break;
case 'users':
$table = $query
->ensure_table('og_uid', $relationship);
$query
->add_where(0, "{$table}.nid = ***CURRENT_GID***");
break;
}
}
function group_node_admin_access($node) {
if ($node && og_is_group_type($node->type)) {
return $this
->admin_access();
}
return FALSE;
}
protected function excluded_paths() {
$excluded = parent::excluded_paths();
$excluded[] = 'og';
$excluded[] = 'og/my';
$excluded[] = 'og/all';
return $excluded;
}
}