View source
<?php
class space_setting_home implements space_setting {
var $id;
function __construct($id = NULL) {
if ($id) {
$this->id = $id;
}
else {
$this->id = 'home';
}
}
function form($space, $value = array()) {
$options = array(
0 => '---',
);
$original = spaces_get_space();
spaces_set_space($space, TRUE);
$links = menu_navigation_links('features');
spaces_set_space($original, TRUE);
$form = array();
if (count($links)) {
foreach ($links as $link) {
$options[$link['href']] = $link['title'];
}
$form = array(
'#title' => t('Homepage'),
'#description' => t('The default page for this space.'),
'#type' => 'select',
'#options' => $options,
'#default_value' => $value ? $value : 0,
);
}
return $form;
}
function validate($space, $value) {
}
function submit($space, $value) {
return $value;
}
}
class space_customizer_menu implements space_customizer {
var $name = 'Menu';
function form($space, $feature) {
$menu = spaces_features_items('menu', $feature);
if (!empty($menu)) {
$form = array();
$menu_items = menu_navigation_links('features');
$default_items = $menu_items;
$this
->customize($space, $menu_items);
foreach ($menu_items as $key => $item) {
if (in_array($item['href'], $menu)) {
$form[$item['href']] = array(
'#title' => $item['href'],
'#type' => 'fieldset',
'#tree' => TRUE,
);
$form[$item['href']]['title'] = array(
'#title' => t('Title'),
'#type' => 'textfield',
'#size' => 40,
'#maxlength' => 255,
'#default_value' => $item['title'],
);
$form[$item['href']]['default'] = array(
'#type' => 'value',
'#value' => $default_items[$key]['title'],
);
}
}
}
return $form;
}
function validate($space, $feature, $value) {
return;
}
function submit($space, $feature, $value) {
$customizer = $space->customizer['menu'];
foreach ($value as $path => $item) {
if ($item['title'] == $item['default']) {
unset($customizer[$path]);
}
else {
if ($item['title'] != $item['default']) {
$customizer[$path] = $item['title'];
}
}
}
return $customizer;
}
function customize($space, &$menu = NULL) {
foreach ($menu as $k => $item) {
if (!empty($space->customizer['menu'][$item['href']])) {
$menu[$k]['title'] = $space->customizer['menu'][$item['href']];
}
}
}
}
class space_customizer_block implements space_customizer {
var $name = 'Blocks';
var $info = array();
function get_block_info($module, $delta) {
if (!isset($this->info[$module])) {
$this->info[$module] = module_invoke($module, 'block', 'list');
if ($module == 'views') {
foreach ($this->info[$module] as $k => $v) {
$viewname = strpos($v['info'], ':');
if ($viewname !== FALSE) {
$v['info'] = substr($v['info'], $viewname + 2);
$this->info[$module][$k] = $v;
}
}
}
}
return !empty($this->info[$module][$delta]['info']) ? $this->info[$module][$delta]['info'] : '';
}
function form($space, $feature) {
global $theme_key;
init_theme();
$regions = system_region_list($theme_key);
$feature_contexts = drupal_map_assoc(spaces_features_items('context', $feature));
$contexts = context_enabled_contexts();
$contexts = array_intersect_key($contexts, $feature_contexts);
$master_contexts = array();
$master_defaults = array();
foreach ($contexts as $identifier => $context) {
if (!empty($context->block)) {
$customizer = !empty($space->customizer['block'][$identifier]) ? $space->customizer['block'][$identifier] : array();
$subject = !empty($space->customizer['block']['subject']) ? $space->customizer['block']['subject'] : array();
$form = array(
'#title' => $identifier,
'#tree' => TRUE,
);
$defaults = array(
'#tree' => TRUE,
);
foreach ($context->block as $i => $block) {
$block = (array) $block;
$bid = "{$block['module']}-{$block['delta']}";
if (!empty($block['region']) && !empty($regions[$block['region']])) {
$region = $block['region'];
if (!isset($form[$region])) {
$form[$region] = array(
'#title' => $regions[$region],
'#tree' => TRUE,
);
}
$block_details = module_invoke($block['module'], 'block', 'view', $block['delta']);
$default_subject = !empty($block_details['subject']) ? $block_details['subject'] : '';
$default_weight = isset($block[$i]['weight']) ? $block[$i]['weight'] : 0;
$default_status = isset($block[$i]['status']) ? $block[$i]['status'] : 1;
$defaults[$region][$bid]['weight'] = array(
'#type' => 'value',
'#value' => $default_weight,
);
$defaults[$region][$bid]['status'] = array(
'#type' => 'value',
'#value' => $default_status,
);
$defaults[$region][$bid]['subject'] = array(
'#type' => 'value',
'#value' => $default_subject,
);
$form[$region][$bid] = array(
'#tree' => TRUE,
'#weight' => isset($customizer[$region][$bid]['weight']) ? $customizer[$region][$bid]['weight'] : 0,
);
$form[$region][$bid]['weight'] = array(
'#type' => 'weight',
'#delta' => 25,
'#default_value' => isset($customizer[$region][$bid]['weight']) ? $customizer[$region][$bid]['weight'] : 0,
);
$form[$region][$bid]['status'] = array(
'#type' => 'checkbox',
'#default_value' => isset($customizer[$region][$bid]['status']) ? $customizer[$region][$bid]['status'] : 1,
);
if (!empty($default_subject)) {
$form[$region][$bid]['subject'] = array(
'#type' => 'textfield',
'#default_value' => !empty($subject[$bid]) ? $subject[$bid] : $default_subject,
'#description' => $this
->get_block_info($block['module'], $block['delta']),
);
}
else {
$form[$region][$bid]['subject'] = array(
'#type' => 'markup',
'#value' => $this
->get_block_info($block['module'], $block['delta']),
);
}
}
}
$master_contexts[$identifier] = $form;
$master_defaults[$identifier] = $defaults;
}
}
if (!empty($master_contexts) && !empty($master_defaults)) {
$master_form = array(
'#theme' => 'spaces_block_customizer_settings_form',
'contexts' => array_merge(array(
'#tree' => TRUE,
), $master_contexts),
'defaults' => array_merge(array(
'#tree' => TRUE,
), $master_defaults),
);
return $master_form;
}
else {
return NULL;
}
}
function validate($space, $feature, $value) {
return;
}
function submit($space, $feature, $value) {
$customizer = $space->customizer['block'];
foreach ($value['contexts'] as $identifier => $context) {
foreach ($context as $region => $blocks) {
foreach ($blocks as $bid => $block) {
foreach ($block as $k => $v) {
if ($v === $value['defaults'][$identifier][$region][$bid][$k]) {
unset($block[$k]);
}
else {
if ($k == 'subject') {
unset($block[$k]);
$customizer['subject'][$bid] = $v;
}
}
}
if (!empty($block)) {
$customizer[$identifier][$region][$bid] = $block;
}
}
}
}
return $customizer;
}
function customize($space, $identifier, &$block = NULL) {
if (!empty($space->customizer['block'][$identifier])) {
$customizer = $space->customizer['block'][$identifier];
foreach ($block as $key => $b) {
$b = (array) $b;
$block[$key] = (array) $block[$key];
$bid = "{$b['module']}-{$b['delta']}";
if (!empty($customizer[$b['region']][$bid])) {
if (isset($customizer[$b['region']][$bid]['status']) && $customizer[$b['region']][$bid]['status'] === 0) {
unset($block[$key]);
}
if (isset($customizer[$b['region']][$bid]['weight'])) {
$block[$key]['weight'] = $customizer[$b['region']][$bid]['weight'];
}
}
}
}
}
function customize_subject($space, &$block) {
$bid = "{$block->module}-{$block->delta}";
if (!empty($space->customizer['block']['subject'][$bid])) {
$block->subject = $space->customizer['block']['subject'][$bid];
}
}
}