View source
<?php
define('SPACES_FEATURE_DISABLED', 0);
define('SPACES_PRESET_DEFAULT', 0);
define('SPACES_PRESET_NORMAL', 1);
define('SPACES_PRESET_OVERRIDDEN', 2);
function spaces_init() {
if (!spaces_get_space() && module_exists('spaces_site')) {
module_invoke('spaces_site', 'init');
}
if (!spaces_menu_access()) {
menu_set_active_item('spaces-access-denied');
}
spaces_router('menu');
$router_item = menu_get_item();
switch ($router_item['path']) {
case 'admin/build/context':
case 'admin/build/features':
case 'admin/build/modules':
spaces_features_map(NULL, TRUE);
break;
}
}
function spaces_perm() {
return array(
'administer spaces',
'configure spaces features',
);
}
function spaces_purl_provider() {
$items = array();
foreach (spaces_types() as $type => $info) {
$items['spaces_' . $type] = array(
'name' => $info['title'],
'description' => t('Sets a spaces context.'),
'callback' => 'spaces_init_context',
'callback arguments' => array(
$type,
),
'example' => 'my-space',
);
}
return $items;
}
function spaces_init_context($type, $sid) {
static $once;
if (empty($once)) {
$space = spaces_load($type, $sid, TRUE);
spaces_set_space($space);
$once = TRUE;
}
}
function spaces_menu() {
$items = array();
$items['admin/build/spaces'] = array(
'title' => 'Spaces presets',
'description' => 'Create and configure spaces for your site.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'spaces_preset_default_form',
),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/build/spaces/presets'] = array(
'title' => 'Presets',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'spaces_preset_default_form',
),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -1,
);
$items['admin/build/spaces/presets/add'] = array(
'title' => 'Add',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'spaces_preset_form',
'add',
),
);
$items['admin/build/spaces/presets/edit'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array(
'spaces_preset_form',
'edit',
),
);
$items['admin/build/spaces/presets/export'] = array(
'title' => 'Export preset',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'spaces_preset_export',
),
);
$items['admin/build/spaces/presets/delete'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array(
'spaces_preset_delete_form',
5,
6,
),
);
$items['admin/build/spaces/presets/disable'] = array(
'page callback' => '_spaces_preset_disable_page',
);
$items['admin/build/spaces/presets/enable'] = array(
'page callback' => '_spaces_preset_enable_page',
);
foreach ($items as $path => $item) {
$items[$path]['access callback'] = 'user_access';
$items[$path]['access arguments'] = array(
'administer spaces',
);
$items[$path]['file'] = 'spaces_admin.inc';
if (!isset($item['type'])) {
$items[$path]['type'] = MENU_CALLBACK;
}
}
$items['spaces-access-denied'] = array(
'title' => 'Access denied',
'description' => 'Page callback for early-stack spaces router access denied.',
'page callback' => 'spaces_access_denied',
'page arguments' => array(),
'access callback' => FALSE,
'type' => MENU_CALLBACK,
);
return $items;
}
function spaces_menu_alter(&$items) {
$router_items = array(
'node/%node',
'node/%node/edit',
'user/%user/view',
'user/%user_uid_optional',
'user/%user_category/edit',
);
foreach (node_get_types('types', NULL, TRUE) as $type) {
$type_url_str = str_replace('_', '-', $type->type);
$router_items[] = 'node/add/' . $type_url_str;
}
foreach ($router_items as $path) {
if (isset($items[$path])) {
$arguments = isset($items[$path]['access arguments']) ? $items[$path]['access arguments'] : array();
$arguments[] = isset($items[$path]['access callback']) ? $items[$path]['access callback'] : NULL;
$items[$path]['access callback'] = 'spaces_menu_access';
$items[$path]['access arguments'] = $arguments;
}
}
}
function spaces_menu_access() {
$args = func_get_args();
$op = 'menu';
$object = NULL;
if (!empty($args)) {
$access_callback = array_pop($args);
if ($access_callback == 'node_access' && $args[0] == 'create') {
$object = new StdClass();
$object->type = $args[1];
$op = 'node';
}
else {
foreach ($args as $arg) {
if (is_object($arg)) {
$object = $arg;
if (isset($object->nid)) {
$op = 'node';
}
else {
if (isset($object->uid)) {
$op = 'user';
}
}
break;
}
}
}
}
$access = true;
$types = spaces_types();
if ($space = spaces_get_space()) {
$access = $access && $space
->menu_access($op, $object);
unset($types[$space->type]);
}
foreach ($types as $type => $info) {
$access = $access && call_user_func(array(
$info['class'],
'menu_access',
), $op, $object, FALSE);
}
$standard_access = !empty($access_callback) ? call_user_func_array($access_callback, $args) : TRUE;
return $access && $standard_access;
}
function spaces_access_denied() {
drupal_access_denied();
exit;
}
function spaces_help($path, $arg) {
switch ($path) {
case 'admin/build/spaces/presets/export':
return "<p>" . t('You can use exported presets in your modules by returning an array of presets in <code>hook_spaces_presets()</code>.') . "</p>";
}
}
function spaces_theme() {
$items = array();
$items['spaces_features_form'] = $items['spaces_customize_item'] = $items['spaces_preset_default_form'] = $items['spaces_form_presets'] = $items['spaces_block_customizer_settings_form'] = array(
'file' => 'spaces.theme.inc',
);
return $items;
}
function spaces_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'view':
case 'form':
spaces_router('user', $account);
break;
}
}
function spaces_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
if ($op == 'view' && $page && menu_get_object() === $node) {
spaces_router('node', $node);
}
if ($op == 'prepare') {
spaces_router('node', $node);
}
}
function spaces_flush_caches() {
spaces_features_map(NULL, TRUE);
return array();
}
function spaces_spaces_settings() {
return array(
'home' => array(
'class' => 'space_setting_home',
'file' => drupal_get_path('module', 'spaces') . '/spaces.spaces.inc',
),
);
}
function spaces_spaces_customizers() {
return array(
'menu' => array(
'class' => 'space_customizer_menu',
'file' => drupal_get_path('module', 'spaces') . '/spaces.spaces.inc',
),
'block' => array(
'class' => 'space_customizer_block',
'file' => drupal_get_path('module', 'spaces') . '/spaces.spaces.inc',
),
);
}
function spaces_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'spaces') . '/includes',
);
}
function spaces_features_api() {
return array(
'spaces' => array(
'default_hook' => 'spaces_presets',
'default_file' => FEATURES_DEFAULTS_INCLUDED_COMMON,
'file' => drupal_get_path('module', 'spaces') . '/spaces.features.inc',
),
);
}
function spaces_context_conditions() {
$type_options = array();
foreach (spaces_types() as $type => $info) {
$type_options[$type] = $info['title'];
}
$items = array();
$items['spaces_type'] = array(
'#title' => t('Spaces type'),
'#type' => 'checkboxes',
'#options' => $type_options,
'#description' => t('Set this context when the selected space types are active.'),
);
return $items;
}
interface space {
function __construct($type, $sid = NULL, $is_active = FALSE);
function save();
function delete();
function feature_options();
function user_links();
function admin_links();
function feature_access($feature = NULL);
function admin_access();
function router($op, $object = NULL, $is_active = TRUE);
function redirect($op = 'home');
function form();
function validate($values);
function submit($values);
function views_filter(&$query, $base_table = '', $relationship = '');
function preset_enforce($preset);
}
interface space_setting {
function __construct($id = NULL);
function form($space, $value = array());
function validate($space, $value);
function submit($space, $value);
}
interface space_customizer {
function form($space, $feature);
function validate($space, $feature, $value);
function submit($space, $feature, $value);
}
function spaces_context_active_contexts_alter(&$contexts) {
$space = spaces_get_space();
foreach ($contexts as $identifier => $context) {
if (!empty($context->block)) {
spaces_customizers();
space_customizer_block::customize($space, $identifier, $context->block);
}
}
}
function spaces_load($type, $sid = NULL, $is_active = FALSE) {
$types = spaces_types();
if (isset($types[$type])) {
if (!empty($types[$type]['file']) && is_file($types[$type]['file'])) {
require_once $types[$type]['file'];
}
$class = $types[$type]['class'];
$space = new $class($type, $sid, $is_active);
$space->type = $type;
$space->features = array();
$space->settings = array();
$space->customizer = array();
if ($sid) {
$space->sid = $sid;
if ($modifier = purl_load(array(
'provider' => "spaces_{$type}",
'id' => $sid,
))) {
$space->purl = $modifier['value'];
}
$result = db_query("SELECT id, value FROM {spaces_features} WHERE sid = %d AND type = '%s' ORDER BY weight ASC", $sid, $type);
while ($row = db_fetch_object($result)) {
$space->features[$row->id] = $row->value;
}
$result = db_query("SELECT id, value FROM {spaces_settings} WHERE sid = %d AND type = '%s'", $sid, $type);
while ($row = db_fetch_object($result)) {
$space->settings[$row->id] = unserialize($row->value);
}
$row = db_fetch_object(db_query("SELECT customizer, preset FROM {spaces} WHERE sid = %d AND type = '%s'", $space->sid, $space->type));
$space->customizer = $row ? unserialize($row->customizer) : array();
$valid_presets = spaces_presets($type);
$default_presets = variable_get('spaces_default_presets', array());
if ($row && isset($valid_presets[$row->preset])) {
$space->preset = $row->preset;
}
else {
if (isset($default_presets[$type])) {
$space->preset = $default_presets[$type];
}
}
if (!empty($space->preset)) {
spaces_preset_enforce($space);
}
}
return $space;
}
return false;
}
function spaces_save($space) {
if (!empty($space->sid) && !empty($space->type)) {
$existing = spaces_load($space->type, $space->sid);
if ($space->preset != $existing->preset) {
spaces_preset_enforce($space, TRUE);
}
else {
spaces_preset_enforce($space);
}
db_query("DELETE FROM {spaces_features} WHERE sid = %d AND type = '%s'", $space->sid, $space->type);
$valid_features = spaces_features($space->type);
$weight = -10;
foreach ($space->features as $feature => $value) {
if (isset($valid_features[$feature])) {
$values = array(
$space->sid,
$space->type,
$feature,
$value,
$weight,
);
db_query("INSERT INTO {spaces_features} (sid, type, id, value, weight) VALUES (%d, '%s', '%s', '%s', %d)", $values);
$weight++;
}
}
db_query("DELETE FROM {spaces_settings} WHERE sid = %d AND type = '%s'", $space->sid, $space->type);
$valid_settings = spaces_settings($space->type);
foreach (spaces_feature_settings() as $feature => $settings) {
foreach ($settings as $id => $class) {
$valid_settings[$id] = $class;
}
}
foreach ($space->settings as $setting => $value) {
if (isset($valid_settings[$setting]) && !empty($value)) {
$value = serialize($value);
$values = array(
$space->sid,
$space->type,
$setting,
$value,
);
db_query("INSERT INTO {spaces_settings} (sid, type, id, value) VALUES (%d, '%s', '%s', '%s')", $values);
}
}
$exists = db_result(db_query("SELECT count(sid) FROM {spaces} WHERE sid = %d AND type = '%s'", $space->sid, $space->type));
if ($exists) {
db_query("UPDATE {spaces} SET preset = '%s', customizer = '%s' WHERE sid = %d AND type = '%s'", $space->preset, serialize($space->customizer), $space->sid, $space->type);
}
else {
db_query("INSERT INTO {spaces} (sid, type, preset, customizer) VALUES(%d, '%s', '%s', '%s')", $space->sid, $space->type, $space->preset, serialize($space->customizer));
}
$types = spaces_types();
$save_purl = isset($types[$space->type]['custom purl']) && $types[$space->type]['custom purl'];
if ($space->purl && $save_purl) {
$modifier = array(
'provider' => 'spaces_' . $space->type,
'id' => $space->sid,
'value' => $space->purl,
);
purl_save($modifier);
}
$space
->save();
return true;
}
return false;
}
function spaces_delete($space) {
db_query("DELETE FROM {spaces} WHERE sid = %d AND type = '%s'", $space->sid, $space->type);
db_query("DELETE FROM {spaces_features} WHERE sid = %d AND type = '%s'", $space->sid, $space->type);
db_query("DELETE FROM {spaces_settings} WHERE sid = %d AND type = '%s'", $space->sid, $space->type);
$modifier = array(
'provider' => 'spaces_' . $space->type,
'id' => $space->sid,
);
purl_delete($modifier);
$space
->delete();
return true;
}
function spaces_preset_enforce(&$space, $force = FALSE) {
$presets = spaces_presets($space->type);
if (isset($space->preset) && isset($presets[$space->preset])) {
$preset = $presets[$space->preset]['preset'];
$keys = array(
'features',
'settings',
'customizer',
);
foreach ($keys as $key) {
if (isset($preset[$key]) && is_array($preset[$key])) {
if ($force) {
$space->{$key} = $preset[$key];
}
else {
foreach ($preset[$key] as $k => $v) {
if (!empty($preset['locked'][$key][$k]) || !isset($space->{$key}[$k])) {
$space->{$key}[$k] = $v;
}
}
}
}
}
if (isset($preset['weights']) && is_array($preset['weights'])) {
$preset['weights'] = array_intersect_key($preset['weights'], $space->features);
$i = 0;
foreach (array_diff_key($space->features, $preset['weights']) as $feature => $value) {
$preset['weights'][$feature] = 1000 + $i;
$i++;
}
ksort($preset['weights']);
ksort($space->features);
array_multisort($preset['weights'], $space->features, SORT_NUMERIC);
}
$space
->preset_enforce($preset);
}
}
function spaces_types($reset = false) {
static $spaces_types;
if (!isset($spaces_types) || $reset) {
$spaces_types = module_invoke_all('spaces_types');
}
return $spaces_types;
}
function spaces_presets($type = NULL, $include_disabled = FALSE, $reset = FALSE) {
static $presets;
if (!isset($presets)) {
$presets = array();
$disabled = variable_get('spaces_disabled_presets', array());
foreach (module_implements('spaces_presets') as $module) {
$items = module_invoke($module, 'spaces_presets');
foreach ($items as $id => $preset) {
$preset['disabled'] = isset($disabled[$preset['type']][$id]);
$preset['storage'] = SPACES_PRESET_DEFAULT;
$presets[$preset['type']][$id] = $preset;
}
}
drupal_alter('spaces_presets', $presets);
$result = db_query("SELECT * FROM {spaces_presets}");
while ($row = db_fetch_object($result)) {
$preset = array(
'name' => check_plain($row->name),
'description' => check_plain($row->description),
'type' => check_plain($row->type),
'preset' => unserialize($row->value),
'disabled' => isset($disabled[$row->type][$row->id]),
'storage' => isset($presets[$row->type][$row->id]) ? SPACES_PRESET_OVERRIDDEN : SPACES_PRESET_NORMAL,
);
$presets[$row->type][$row->id] = $preset;
}
}
$return = $presets;
if (!$include_disabled) {
foreach (array_keys($return) as $preset_type) {
foreach ($return[$preset_type] as $id => $preset) {
if ($preset['disabled']) {
unset($return[$preset_type][$id]);
}
}
}
}
if ($type) {
return isset($return[$type]) ? $return[$type] : array();
}
return $return;
}
function spaces_get_space() {
return spaces_set_space();
}
function spaces_set_space($space = NULL, $reset = FALSE) {
static $current_space;
if (!isset($current_space) || $reset) {
$current_space = $space;
if ($space) {
context_set_by_condition('spaces_type', $space->type);
}
}
return is_object($current_space) ? $current_space : FALSE;
}
function spaces_router($op, $object = NULL) {
if (spaces_router_get()) {
$types = spaces_types();
if ($space = spaces_get_space()) {
$space
->router($op, $object);
unset($types[$space->type]);
}
foreach ($types as $type => $info) {
call_user_func(array(
$info['class'],
'router',
), $op, $object, FALSE);
}
}
}
function spaces_router_set($status) {
return spaces_router_get($status, TRUE);
}
function spaces_router_get($enabled = 1, $reset = FALSE) {
static $status;
if (!isset($status) || $reset) {
$status = $enabled;
}
return $status;
}
function spaces_features($type = NULL, $reset = FALSE) {
static $spaces_features;
if (!isset($spaces_features) || $reset) {
$spaces_features = array(
'all' => array(),
'common' => array(),
);
$features = features_get_features();
foreach ($features as $feature) {
if (module_exists($feature->name) && !empty($feature->info['spaces'])) {
if (!empty($feature->info['spaces']['types']) && is_array($feature->info['spaces']['types'])) {
foreach ($feature->info['spaces']['types'] as $t) {
$spaces_features[$t][$feature->name] = $feature;
}
}
else {
$spaces_features['common'][$feature->name] = $feature;
}
$spaces_features['all'][$feature->name] = $feature;
}
}
foreach (array_keys($spaces_features) as $t) {
if ($t != 'all' && $t != 'common') {
$spaces_features[$t] = array_merge($spaces_features[$t], $spaces_features['common']);
}
}
}
if ($type) {
return !empty($spaces_features[$type]) ? $spaces_features[$type] : $spaces_features['common'];
}
return $spaces_features['all'];
}
function spaces_feature_settings($feature = NULL, $reset = FALSE) {
static $feature_settings;
if (!isset($feature_settings) || $reset) {
$feature_settings = array();
$features = spaces_features();
foreach (module_implements('spaces_settings') as $module) {
if (isset($features[$module])) {
$settings = module_invoke($module, 'spaces_settings');
foreach ($settings as $id => $info) {
if (is_array($info)) {
if (isset($info['file']) && is_file($info['file'])) {
require_once $info['file'];
}
if (isset($info['class']) && class_exists($info['class'])) {
$class = $info['class'];
$setting = new $class();
}
}
else {
if (is_string($info) && class_exists($info)) {
$setting = new $info();
}
else {
if (is_object($info)) {
$setting = $info;
}
}
}
$feature_settings[$module][$id] = $setting;
}
}
}
}
if ($feature) {
return isset($feature_settings[$feature]) ? $feature_settings[$feature] : array();
}
return $feature_settings;
}
function spaces_settings($type = NULL, $reset = FALSE) {
static $spaces_settings;
if (!isset($spaces_settings) || $reset) {
$spaces_settings = array(
'all' => array(),
'common' => array(),
);
$settings = array();
$features = spaces_features();
foreach (module_implements('spaces_settings') as $module) {
if (!isset($features[$module])) {
$settings = array_merge($settings, module_invoke($module, 'spaces_settings'));
}
}
foreach ($settings as $setting_name => $info) {
if (is_array($info)) {
if (isset($info['file']) && is_file($info['file'])) {
require_once $info['file'];
}
if (isset($info['class']) && class_exists($info['class'])) {
$class = $info['class'];
$setting = new $class();
}
}
else {
if (is_string($info) && class_exists($info)) {
$setting = new $info();
}
else {
if (is_object($info)) {
$setting = $info;
}
}
}
if (!empty($setting->types)) {
foreach ($setting->types as $t) {
if (!isset($spaces_settings[$t])) {
$spaces_settings[$t] = array();
}
$spaces_settings[$t][$setting_name] = $setting;
}
}
else {
$spaces_settings['common'][$setting_name] = $setting;
}
$spaces_settings['all'][$setting_name] = $setting;
}
foreach (array_keys($spaces_settings) as $t) {
if ($t != 'all' && $t != 'common') {
$spaces_settings[$t] = array_merge($spaces_settings[$t], $spaces_settings['common']);
}
}
}
if ($type) {
return !empty($spaces_settings[$type]) ? $spaces_settings[$type] : $spaces_settings['common'];
}
return $spaces_settings['all'];
}
function spaces_customizers($reset = FALSE) {
static $spaces_customizers;
if (!isset($spaces_customizers) || $reset) {
$customizers = module_invoke_all('spaces_customizers');
foreach ($customizers as $customizer_name => $info) {
if (is_array($info)) {
if (isset($info['file']) && is_file($info['file'])) {
require_once $info['file'];
}
if (isset($info['class']) && class_exists($info['class'])) {
$class = $info['class'];
$customizer = new $class();
}
}
else {
if (is_string($info) && class_exists($info)) {
$customizer = new $info();
}
else {
if (is_object($info)) {
$customizer = $info;
}
}
}
$spaces_customizers[$customizer_name] = $customizer;
}
}
return $spaces_customizers;
}
function spaces_features_map($type = NULL, $reset = FALSE) {
static $map;
if (!isset($map) || $reset) {
$map = array();
$cache = cache_get('spaces_map', 'cache');
if ($cache && !$reset) {
$map = $cache->data;
}
else {
$features = spaces_features();
foreach ($features as $feature_name => $feature) {
foreach ($feature->info['features'] as $component => $items) {
if (is_array($items)) {
foreach ($items as $item) {
if (!isset($map[$component][$item])) {
$map[$component][$item] = $feature_name;
}
}
}
}
}
$contexts = context_enabled_contexts();
$components = array(
'node',
'views',
);
if (!empty($map['context'])) {
foreach ($map['context'] as $identifier => $feature_name) {
$context = $contexts[$identifier];
if (!empty($context)) {
foreach ($components as $component) {
if (!empty($context->{$component})) {
foreach ($context->{$component} as $item) {
if (!isset($map[$component][$item])) {
$map[$component][$item] = $feature_name;
}
}
}
}
}
}
}
cache_set('spaces_map', $map, 'cache');
}
}
if (!empty($type)) {
return isset($map[$type]) ? $map[$type] : array();
}
return $map;
}
function spaces_features_items($type, $feature) {
$features = spaces_features();
if (!empty($features[$feature]) && !empty($features[$feature]->info['features'][$type])) {
return $features[$feature]->info['features'][$type];
}
return array();
}
function spaces_features_menu_links_alter(&$links) {
$space = spaces_get_space();
if ($space) {
spaces_customizers();
space_customizer_menu::customize($space, $links);
$map = spaces_features_map('menu');
$weights = array_flip(array_keys($space->features));
$weighted = array();
foreach ($links as $k => $item) {
$feature = '';
if (!empty($map[$item['href']])) {
$feature = $map[$item['href']];
}
if (!empty($feature) && $space
->feature_access($feature)) {
$links[$k]['#weight'] = $weights[$feature];
}
else {
unset($links[$k]);
}
}
uasort($links, 'element_sort');
}
}
function spaces_form_presets($space) {
$presets = spaces_presets($space->type);
if ($presets) {
if (count($presets) == 1) {
$form['preset'] = array(
'#type' => 'value',
'#value' => array_shift(array_keys($presets)),
);
}
else {
$default_presets = variable_get('spaces_default_presets', array());
if (isset($space->preset) && !empty($presets[$space->preset])) {
$default_preset = $space->preset;
}
else {
if (isset($default_presets[$space->type])) {
$default_preset = $default_presets[$space->type];
}
else {
$default_preset = NULL;
}
}
$form = array(
'#tree' => false,
'#theme' => 'spaces_form_presets',
);
$form['preset'] = array(
'#title' => t('Preset'),
'#type' => 'radios',
'#required' => true,
'#options' => array(),
'#default_value' => $default_preset,
);
$form['info'] = array();
foreach ($presets as $id => $preset) {
$form['preset']['#options'][$id] = $preset['name'];
$form['info'][$id] = array(
'#type' => 'item',
'#title' => $preset['name'],
'#description' => $preset['description'],
);
}
}
return $form;
}
return array();
}
function spaces_admin_access($type = NULL, $op = NULL) {
$return = false;
$space = spaces_get_space();
if ($space && $type == $space->type) {
$return = $space
->admin_access();
}
if ($op == 'features') {
return $return && (user_access('administer spaces') || user_access('configure spaces features'));
}
return $return;
}
function spaces_feature_access($feature = NULL) {
if ($space = spaces_get_space()) {
return user_access('access content') && $space
->feature_access($feature);
}
return user_access('access content');
}
function spaces_active_space_menu($type, $local_tasks = FALSE, $path_prefix = '') {
$types = spaces_types();
$arg_count = !empty($path_prefix) ? count(explode('/', $path_prefix)) : 0;
$path_prefix = !empty($path_prefix) ? $path_prefix . '/' : '';
$spaces_path = drupal_get_path('module', 'spaces');
$items[$path_prefix . 'spaces/features'] = array(
'title' => 'Features',
'page arguments' => array(
'spaces_features_form',
),
'access arguments' => array(
$type,
'features',
),
'type' => MENU_LOCAL_TASK,
'weight' => 1,
);
$items[$path_prefix . 'spaces/features/%'] = array(
'title' => 'Features',
'page arguments' => array(
'spaces_customize_form',
NULL,
2 + $arg_count,
),
'access arguments' => array(
$type,
'features',
),
'type' => MENU_LOCAL_TASK,
'weight' => 1,
);
foreach ($items as $path => $item) {
$items[$path]['page callback'] = 'drupal_get_form';
$items[$path]['access callback'] = 'spaces_admin_access';
$items[$path]['file'] = 'spaces_admin.inc';
$items[$path]['file path'] = $spaces_path;
}
return $items;
}
function spaces_admin_links($space = NULL) {
$space = !isset($space) ? spaces_get_space() : $space;
if ($space && $space
->admin_access()) {
$links = $space
->admin_links();
drupal_alter('spaces_admin_links', $links, $space);
return $links;
}
return array();
}
function spaces_user_links($space = NULL) {
$space = !isset($space) ? spaces_get_space() : $space;
if ($space) {
$links = $space
->user_links();
drupal_alter('spaces_user_links', $links, $space);
return $links;
}
return array();
}
function spaces_preprocess_block(&$vars) {
$space = spaces_get_space();
if (!empty($vars['block'])) {
spaces_customizers();
space_customizer_block::customize_subject($space, $vars['block']);
}
}
function spaces_preprocess_page(&$vars) {
if (variable_get('menu_primary_links_source', 'primary-links') === 'features' && !empty($vars['primary_links'])) {
spaces_features_menu_links_alter($vars['primary_links']);
}
$space = spaces_get_space();
if ($space) {
if ($links = spaces_admin_links()) {
$vars['space_admin_links'] = theme('links', $links);
}
if ($links = spaces_user_links()) {
$vars['space_user_links'] = theme('links', $links);
}
if (!empty($space->title)) {
$vars['space_title'] = l($space->title, '<front>');
}
$vars['body_classes'] .= " spaces-{$space->type}";
}
}