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($sid)) {
$this->title = $term->name;
$this->term = $term;
}
}
else {
$this->term = new StdClass();
}
}
function save() {
return;
}
function delete() {
return;
}
function feature_access($feature = NULL) {
if (isset($this->features[$feature])) {
if ($this->features[$feature] != SPACES_FEATURE_DISABLED) {
return TRUE;
}
}
return FALSE;
}
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 user_links() {
return array();
}
function admin_links() {
return array();
}
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 (!empty($this->purl)) {
if ($home = $this->settings['home']) {
if (menu_get_item($home)) {
purl_goto($home, array(
'purl' => array(
'provider' => 'spaces_taxonomy',
'id' => $this->sid,
),
));
}
}
if ($this
->admin_access() && user_access('configure spaces features')) {
drupal_set_message(t("Please setup your taxonomy space by 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 menu_access($op, $object = NULL, $is_active = TRUE) {
switch ($op) {
case 'node':
if ($is_active) {
$node = $object;
$form = !isset($node->nid) || isset($node->date) ? TRUE : FALSE;
$node_types = spaces_features_map('node');
if (!empty($node_types[$node->type])) {
$feature = $node_types[$node->type];
if ($this
->feature_access($feature)) {
return TRUE;
}
else {
return FALSE;
}
}
}
return TRUE;
case 'menu':
case 'user':
return TRUE;
}
}
function router($op, $object = NULL, $is_active = TRUE) {
switch ($op) {
case 'menu':
if ($is_active && drupal_is_front_page()) {
$this
->redirect('home');
}
break;
}
}
function views_filter(&$query, $base_table = '', $relationship = '') {
switch ($base_table) {
case 'node':
$table = $query
->ensure_table('term_node', $relationship);
$query
->add_where(0, "{$table}.tid = %d", $this->sid);
break;
}
}
}
}
function spaces_taxonomy_spaces_types() {
return array(
'taxonomy' => array(
'class' => 'space_taxonomy',
'title' => t('Term space'),
'custom purl' => 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']['preset'])) {
$space->preset = $form_state['values']['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;
}