View source
<?php
define('SPACES_TAXONOMY_FEATURE_ENABLED', 1);
if (function_exists('spaces_menu')) {
class space_taxonomy implements space {
var $title = NULL;
var $term = NULL;
function __construct($type, $sid = NULL, $is_active = FALSE) {
if ($sid) {
if ($term = taxonomy_get_term($tid)) {
$this->title = $term->name;
$this->term = $term;
}
}
else {
$this->term = new StdClass();
}
}
function save() {
return;
}
function delete() {
return;
}
function feature_access($feature = NULL) {
return true;
}
function admin_access() {
global $user;
return user_access('administer spaces');
}
function feature_options() {
return array(
SPACES_FEATURE_DISABLED => t('Disabled'),
SPACES_TAXONOMY_FEATURE_ENABLED => t('Enabled'),
);
}
function links(&$links) {
}
function form() {
return array();
}
function validate($values) {
return;
}
function submit($values) {
return array();
}
function preset_enforce($preset) {
}
function redirect($op = 'home') {
switch ($op) {
case 'home':
if ($this->prefix) {
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_taxonomy',
'id' => $this->sid,
),
));
}
}
else {
if (user_access('administer spaces')) {
drupal_set_message(t("Please setup your taxonomy space by enabling at least 1 feature and choosing a homepage setting."));
purl_goto('spaces/features', array(
'purl' => array(
'provider' => 'spaces_taxonomy',
'id' => $this->sid,
),
));
}
}
}
else {
if (user_access('administer spaces')) {
drupal_goto('admin/content/taxonomy/edit/term/' . $this->sid);
}
else {
drupal_goto('taxonomy/term/' . $this->sid);
}
}
break;
case 'features':
purl_goto('spaces/features', array(
'purl' => array(
'provider' => 'spaces_taxonomy',
'id' => $this->sid,
),
));
break;
}
}
function router($op, $object = NULL, $is_active = TRUE) {
switch ($op) {
case 'menu':
return true;
case 'node view':
return true;
case 'node form':
return true;
case 'user view':
return true;
case 'user form':
return true;
}
}
function views_filter($is_active, &$query) {
if ($is_active) {
$table = $query
->ensure_table('term_node');
$query
->add_where(0, "{$table}.tid = %d", $this->sid);
}
else {
$table = $query
->ensure_table('term_node');
$query
->add_where(0, "{$table}.tid = 0");
}
}
}
}
function spaces_taxonomy_spaces_types() {
return array(
'taxonomy' => array(
'class' => 'space_taxonomy',
'title' => t('Term space'),
'custom prefixes' => TRUE,
),
);
}
function spaces_taxonomy_menu() {
$items = array();
$items['admin/build/spaces/taxonomy'] = array(
'title' => 'Taxonomy',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'spaces_taxonomy_settings',
),
'access callback' => 'user_access',
'access arguments' => array(
'administer spaces',
),
'type' => MENU_LOCAL_TASK,
);
$spaces_items = spaces_active_space_menu('taxonomy', FALSE);
foreach ($spaces_items as $path => $item) {
$spaces_items[$path]['access callback'] = 'user_access';
$spaces_items[$path]['access arguments'] = array(
'administer spaces',
);
}
$items = $items + $spaces_items;
return $items;
}
function spaces_taxonomy_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'taxonomy_form_term':
$vid = variable_get('spaces_taxonomy_vid', 0);
if (isset($form_state['confirm_delete'])) {
$form['#submit'][] = '_spaces_taxonomy_form_delete';
}
else {
if ($vid != 0 && $form['vid']['#value'] == $vid) {
$tid = isset($form['tid']['#value']) ? $form['tid']['#value'] : 0;
$space = spaces_load('taxonomy', $tid);
$form['spaces'] = array(
'#type' => 'fieldset',
'#title' => t('Spaces'),
'#tree' => FALSE,
'#weight' => 0,
);
$form['spaces']['purl'] = purl_form('spaces_taxonomy', $tid, $space->purl);
$form['spaces']['spaces_preset'] = spaces_form_presets($space);
$form['#submit'][] = '_spaces_taxonomy_form_submit';
}
}
break;
}
}
function _spaces_taxonomy_form_delete($form, &$form_state) {
$tid = $form_state['values']['tid'];
if ($tid) {
$space = spaces_load('taxonomy', $tid);
spaces_delete($space);
}
}
function _spaces_taxonomy_form_submit($form, &$form_state) {
$tid = $form_state['values']['tid'];
if ($tid) {
$space = spaces_load('taxonomy', $tid);
if (isset($form_state['values']['purl']['value'])) {
$space->purl = $form_state['values']['purl']['value'];
}
if (isset($form_state['values']['spaces_preset'])) {
$space->preset = $form_state['values']['spaces_preset'];
}
$result = spaces_save($space);
}
}
function spaces_taxonomy_settings(&$form_state) {
$form = array();
$vocabs = array(
0 => '---',
);
foreach (taxonomy_get_vocabularies() as $vocab) {
if (!$vocab->multiple && !$vocab->tags) {
$vocabs[$vocab->vid] = $vocab->name;
}
}
$form['spaces_taxonomy_vid'] = array(
'#type' => 'select',
'#title' => t('Spaces vocabulary'),
'#description' => t('Choose one of the following vocabularies to enable for use with Spaces.'),
'#options' => $vocabs,
'#default_value' => variable_get('spaces_taxonomy_vid', 0),
);
$form = system_settings_form($form);
return $form;
}