Commit 299ef6aa authored by Adrian Rossouw's avatar Adrian Rossouw

much about with the possibility of turning hosting features into features. and...

much about with the possibility of turning hosting features into features. and space enabling clients.
parent a80e5139
......@@ -2,5 +2,8 @@ name = Site aliases
description = Maintain domain aliases for sites.
package = Hosting
dependencies[] = hosting_site
core = 6.x
\ No newline at end of file
dependencies[] = features
features[dummy][] = dummy
spaces[types][] = site
spaces[types][] = client
core = 6.x
<?php
/**
* Implementation of hook_init().
*/
function hosting_client_init() {
if (arg(0) === 'node' && is_numeric(arg(1))) {
spaces_init_space('client', arg(1));
}
}
/**
* Implementation of hook_ctools_plugin_api().
*/
function hosting_client_ctools_plugin_api($module, $api) {
if ($module == 'spaces' && $api == 'plugins') {
return array('version' => 3);
}
}
/**
* Implementation of hook_spaces_plugins().
*/
function hosting_client_spaces_plugins() {
$plugins = array();
$plugins['space_client'] = array(
'handler' => array(
'path' => drupal_get_path('module', 'hosting_client') .'/plugins',
'file' => 'space_client.inc',
'class' => 'space_client',
'parent' => 'space_type',
),
);
return $plugins;
}
/**
* Implementation of hook_spaces_registry().
*/
function hosting_client_spaces_registry() {
return array(
'types' => array(
'client' => array(
'title' => t('Client space'),
'plugin' => 'space_client',
'path' => 'node/%node',
),
),
);
}
/**
* Implementation of hook_user().
function hosting_client_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'form':
if ($category === 'account') {
module_load_include('inc', 'spaces', 'spaces.admin');
$presets = spaces_preset_load(NULL, 'client');
if (count($presets) === 1) {
$form['spaces_preset_client'] = array('#type' => 'value', '#value' => key($presets));
}
else if (count($presets) > 1) {
$form = array();
$form['spaces_preset'] = spaces_preset_form($presets, 'client', 'save');
$form['spaces_preset']['#type'] = 'fieldset';
}
return $form;
}
break;
case 'insert':
case 'update':
// Save preset values
if (!empty($edit['spaces_preset_client'])) {
$space = spaces_load('client', $account->uid);
if ($space->activate()) {
$space->controllers->variable->set('spaces_preset_client', $edit['spaces_preset_client']);
}
}
break;
}
}
*/
/**
* Implementation of hook_form_alter() for spaces_features_form.
* Disallow site_frontpage var from being customizable within a user space.
*/
function hosting_client_form_spaces_features_form_alter(&$form, &$form_state) {
$space = spaces_get_space();
if ($space && $space->type === 'client' && !empty($form['site_frontpage'])) {
unset($form['site_frontpage']);
}
}
/**
* Implementation of hook_purl_provider().
*/
function hosting_client_purl_provider() {
$items = array();
$items["spaces_client"] = array(
'name' => t('Client space'),
'description' => t('Sets a space as the active space.'),
'callback' => 'spaces_init_space',
'callback arguments' => array('client'),
'example' => 'my-space',
);
return $items;
}
......@@ -795,4 +795,6 @@ function hosting_client_views_api() {
'api' => 2,
'path' => drupal_get_path('module', 'hosting_client'),
);
}
}
include_once('hosting.spaces.inc');
<?php
/**
* User integration for Spaces.
*/
class space_client extends space_type {
/**
* Override of load().
* Load the user account object for this space and bail if it can't be loaded.
*/
function load() {
parent::load();
$node = node_load(array('nid' => $this->id));
if ($node->type == 'client') {
$this->client = $node;
return TRUE;
}
if ($node->type == 'site') {
$this->client = node_load($node->client);
return TRUE;
}
return FALSE;
}
function router($op, $object) {
parent::router($op, $object);
switch ($op) {
case 'init':
return;
case 'node':
$node = $object;
if ($node->type == 'client') {
if (isset($node->nid) && (!$this->active || ($this->active && $this->id != $node->nid)) && $space = spaces_load('client', $node->nid)) {
$space->activate();
return;
}
}
elseif (($node->type == 'site') && isset($node->nid)) {
if ($this->active && ($this->id == $node->client)) {
return;
}
spaces_load('client', $node->client)->activate();
return;
}
break;
}
}
/**
* Override of deactivate().
* We don't have too many good options here except to leave the user/x path.
* If the site frontpage has also been set to a user/x path, we just need
* to fail miserably.
*/
function deactivate() {
if (strpos(variable_get('site_frontpage', 'node'), 'user') !== 0) {
drupal_goto('<front>');
}
return;
}
/**
* Override of title().
*/
function title() {
return $this->client->title;
}
function access_space($account = NULL) {
global $user;
$account = isset($account) ? $account : $user;
return (in_array($this->id, array_keys( (array) $account->client_id)));
}
/**
* Override of access_admin().
*/
function access_admin($account = NULL) {
if ($this->id != $this->client->nid) {
return FALSE;
}
global $user;
$account = isset($account) ? $account : $user;
return (in_array($this->id, array_keys( (array) $account->client_id)) && user_access('edit own client')) || parent::access_admin($account);
}
}
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