View source
<?php
define('SPACES_USER_ENABLED', 1);
if (function_exists('spaces_menu')) {
class space_user implements space {
var $account = NULL;
var $title = NULL;
function __construct($type, $sid = NULL, $is_active = FALSE) {
if ($sid) {
$this->account = user_load(array(
'uid' => $sid,
));
$this->title = $this->account->name;
$this->purl = 'space-' . spaces_user_make_purl($this->account->name);
}
else {
$this->account = new StdClass();
}
}
function save() {
if (!$this->save_once) {
user_save($this->account);
}
return;
}
function delete() {
return;
}
function feature_access($feature = NULL) {
if (user_access('access content') && isset($this->features[$feature]) && $this->features[$feature] == SPACES_USER_ENABLED) {
return true;
}
return false;
}
function admin_access() {
global $user;
if ($this->account->uid == $user->uid) {
return true;
}
else {
if (user_access('administer users')) {
return true;
}
}
return false;
}
function feature_options() {
return array(
SPACES_FEATURE_DISABLED => t('Disabled'),
SPACES_USER_ENABLED => t('Enabled'),
);
}
function links(&$links) {
if ($this
->admin_access()) {
$links['settings'] = array(
'title' => t('Account settings'),
'href' => 'user/' . $this->sid . '/edit',
'attributes' => array(
'class' => 'settings',
),
);
}
}
function form() {
return;
}
function validate($values) {
return;
}
function submit($values) {
if (!$this->sid) {
}
return array();
}
function preset_enforce($preset) {
}
function redirect($op = 'home') {
switch ($op) {
case 'home':
if ($home = $this->settings['home']) {
$features = spaces_features();
if (is_array($features[$home]->spaces['menu'])) {
reset($features[$home]->spaces['menu']);
$item = current($features[$home]->spaces['menu']);
$home_path = $item['href'];
purl_goto($home_path, array(
'purl' => array(
'provider' => 'spaces_user',
'id' => $this->sid,
),
));
}
}
else {
global $user;
if ($user == $this->sid) {
purl_goto("user/{$this->sid}/edit", array(
'purl' => array(
'provider' => 'spaces_user',
'id' => $this->sid,
),
));
}
else {
purl_goto("user/{$this->sid}", array(
'purl' => array(
'provider' => 'spaces_user',
'id' => $this->sid,
),
));
}
}
break;
case 'features':
purl_goto("user/{$this->sid}/spaces/features", array(
'purl' => array(
'provider' => 'spaces_user',
'id' => $this->sid,
),
));
break;
}
}
function router($op, $object = NULL, $is_active = TRUE) {
switch ($op) {
case 'menu':
if ($is_active) {
global $user;
return drupal_is_front_page() ? $this
->redirect('home') : true;
}
return true;
case 'node view':
$node = $object;
if ($is_active && $node->uid != $this->sid) {
purl_goto("node/{$node->nid}", array(
'purl' => array(
'disabled' => TRUE,
),
));
}
return true;
case 'node form':
$node = $object;
if ($is_active && $node->uid != $this->sid) {
purl_goto($_GET['q'], array(
'purl' => array(
'disabled' => TRUE,
),
));
}
return true;
case 'user view':
global $user;
$account = $object;
if (!$is_active) {
purl_goto('space-' . spaces_user_make_purl($account->name), array(
'purl' => array(
'disabled' => TRUE,
),
));
}
else {
if ($account->uid != $this->sid) {
purl_goto($_GET['q'], array(
'purl' => array(
'disabled' => TRUE,
),
));
}
}
return true;
case 'user form':
return true;
}
}
function views_filter($is_active, &$query) {
if ($is_active) {
if ($query->base_table == 'node') {
$table = $query
->ensure_table('users');
}
else {
if (!empty($query->relationships)) {
foreach ($query->relationships as $relationship => $info) {
if ($info['table'] == 'node') {
$table = $query
->ensure_table('users', $relationship);
break;
}
}
}
}
if ($table) {
$query
->add_where(0, "{$table}.uid = '%s'", $this->sid);
}
}
}
}
}
function spaces_user_menu() {
$items = array();
$spaces_items = spaces_active_space_menu('user', true, 'user/%user');
$items = $items + $spaces_items;
return $items;
}
function spaces_user_spaces_types() {
return array(
'user' => array(
'class' => 'space_user',
'title' => t('User space'),
'custom prefixes' => FALSE,
'base path' => 'user/%sid',
),
);
}
function spaces_user_purl_modifiers($reset = FALSE) {
static $modifiers;
if (!isset($modifiers) || $reset) {
$modifiers = array();
$result = db_query("SELECT uid, name FROM {users} WHERE status = 1");
while ($row = db_fetch_object($result)) {
$modifiers[] = array(
'value' => 'space-' . spaces_user_make_purl($row->name),
'id' => $row->uid,
);
}
}
return array(
'spaces_user' => $modifiers,
);
}
function spaces_user_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'form':
if ($category == 'account') {
$space = spaces_load('user', $account->uid);
$form = array(
'spaces_preset' => spaces_form_presets($space),
);
return $form;
}
break;
case 'insert':
case 'update':
if (isset($edit['preset'])) {
$space = spaces_load('user', $account->uid);
$space->preset = $edit['preset'];
spaces_save($space);
}
break;
}
}
function spaces_user_make_purl($username) {
return check_url(str_replace(' ', '-', strtolower($username)));
}
function spaces_user_context_links_alter(&$links) {
$space = spaces_get_space();
if ($space && $space->type == 'user') {
global $user;
if ($user->uid != $space->sid) {
$links = array();
}
}
}