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->prefix = 'space-' . spaces_user_make_prefix($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) {
return true;
if (isset($this->features[$feature])) {
$features = spaces_features();
if ($this->feature[$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'])) {
$home_path = key($features[$home]->spaces['menu']);
context_prefix_goto('spaces_og', $this->sid, $home_path);
}
}
else {
global $user;
if ($user == $this->sid) {
context_prefix_goto('spaces_og', $this->sid, 'user/' . $this->sid . '/edit');
}
else {
context_prefix_goto('spaces_og', $this->sid, 'user/' . $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) {
clswitch('set', TRUE);
drupal_goto('node/' . $node->nid);
}
return true;
case 'node form':
$node = $object;
if ($is_active && $node->uid != $this->sid) {
clswitch('set', TRUE);
drupal_goto($_GET['q']);
}
return true;
case 'user view':
global $user;
$account = $object;
if (!$is_active) {
clswitch('set', TRUE);
drupal_goto('space-' . spaces_user_make_prefix($account->name));
}
else {
if ($account->uid != $this->sid) {
clswitch('set', TRUE);
drupal_goto($_GET['q']);
}
}
return true;
}
}
function views_filter($is_active, &$query) {
if ($is_active) {
$query
->ensure_table('users');
$query
->add_where("users.uid = '%s'", $this->sid);
}
}
}
}
function spaces_user_menu($may_cache) {
$items = array();
if (!$may_cache) {
if (arg(0) == 'user' && is_numeric(arg(1)) && ($account = user_load(array(
'uid' => arg(1),
)))) {
$space = spaces_get_space();
if ($space->type == 'user') {
$spaces_items = spaces_active_space_menu($space, true, 'user/' . arg(1));
unset($spaces_items['spaces/settings']);
$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,
),
);
}
function spaces_user_context_prefix_prefixes($reset = FALSE) {
static $prefixes;
if (!isset($prefixes) || $reset) {
$prefixes = array();
$result = db_query("SELECT uid, name FROM {users} WHERE status = 1");
while ($row = db_fetch_object($result)) {
$prefixes[] = array(
'prefix' => 'space-' . spaces_user_make_prefix($row->name),
'id' => $row->uid,
);
}
}
return array(
'spaces_user' => $prefixes,
);
}
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_prefix($username) {
return check_url(strtolower($username));
}