View source
<?php
function spaces_core_menu() {
$items = array();
if (module_exists('book')) {
$items['documents'] = array(
'title' => t('Documents'),
'description' => t('Displays the parent book node for a given spaces group.'),
'page callback' => 'spaces_core_documents',
'page arguments' => array(
1,
),
'access callback' => 'spaces_feature_access',
'access arguments' => array(
'book',
),
'type' => MENU_NORMAL_ITEM,
);
}
return $items;
}
function spaces_core_menu_alter(&$callbacks) {
if (module_exists('blog')) {
$unset = array(
'blog',
'blog/%user/feed',
'blog/%user_uid_optional',
);
foreach ($unset as $path) {
if (!empty($callbacks[$path]) && $callbacks[$path]['module'] == 'blog') {
unset($callbacks[$path]);
}
}
}
}
function spaces_core_help($page) {
switch (context_get('spaces', 'feature')) {
case 'blog':
return "<p>" . t('The blog is a team discussion place where you can post and discuss information relevant to your team.') . "</p>";
case 'book':
return "<p>" . t('The book provides a place for you to post documents and other reference material.') . "</p>";
}
}
function spaces_core_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks['tags']['info'] = t('Spaces Core: Tag chart');
$blocks['book']['info'] = t('Spaces Core: Book navigation');
return $blocks;
}
else {
if ($op == 'view') {
switch ($delta) {
case 'tags':
return _spaces_core_block_tags();
case 'book':
return _spaces_core_block_book();
}
}
}
}
function spaces_core_form_alter(&$form, $form_state, $form_id) {
if ($form['#id'] == 'node-form' && book_type_is_allowed($form['#node']->type)) {
$node = $form['#node'];
if (!empty($form['book'])) {
$form['book']['#weight'] = !empty($form['body_field']['#weight']) ? $form['body_field']['#weight'] : 0;
$form['book']['#collapsible'] = $form['book']['#collapsed'] = FALSE;
if (!empty($form['book']['bid']['#options'])) {
unset($form['book']['bid']['#options'][0]);
if ($view = views_get_view('spaces_book_current')) {
$view
->set_display();
$view
->set_items_per_page(0);
$view
->execute();
$books = array();
$books[$node->nid] = 1;
if (is_array($view->result) && count($view->result)) {
foreach ($view->result as $row) {
$books[$row->nid] = 1;
}
}
foreach ($form['book']['bid']['#options'] as $k => $v) {
if (is_numeric($k) && !isset($books[$k])) {
unset($form['book']['bid']['#options'][$k]);
}
}
}
}
}
}
switch ($form_id) {
case 'user_edit':
unset($form['og_settings']);
break;
case 'comment_form':
if (!drupal_get_title()) {
drupal_set_title(t('Reply'));
}
break;
}
}
function spaces_core_views_default_views() {
$views = array();
if (module_load_include('inc', 'spaces_core', 'spaces_core_views') !== FALSE) {
$default_views = _spaces_core_views_list_views();
foreach ($default_views as $v) {
$function = '_spaces_core_views_' . $v;
if (function_exists($function)) {
$view = call_user_func($function);
if (is_object($view) && $view->name) {
$views[$view->name] = $view;
}
}
else {
watchdog(WATCHDOG_ERROR, 'An exported view could not be loaded because the function !function was not found.', array(
'!function' => $function,
));
}
}
}
return $views;
}
function spaces_core_context_default_contexts() {
$items = array();
$items[] = array(
'namespace' => 'spaces',
'attribute' => 'feature',
'value' => 'blog',
'menu' => 'blog',
'node' => array(
'blog',
),
'views' => array(
'spaces_blog',
),
'block' => array(
array(
'module' => 'views',
'delta' => 'spaces_blog-block_1',
'region' => 'right',
'weight' => '11',
),
array(
'module' => 'views',
'delta' => 'spaces_blog_comments-block_1',
'region' => 'right',
'weight' => '10',
),
),
'spaces' => array(
'label' => t('Blog'),
'description' => t('A blog for team communications.'),
'menu' => array(
array(
'title' => t('Blog'),
'href' => 'blog',
),
),
'types' => array(),
),
);
if (module_exists('book')) {
$items[] = array(
'namespace' => 'spaces',
'attribute' => 'feature',
'value' => 'book',
'menu' => 'documents',
'node' => array(
'book',
),
'block' => array(
array(
'module' => 'spaces_core',
'delta' => 'book',
'region' => 'right',
'weight' => -11,
),
),
'spaces' => array(
'label' => t('Documents'),
'description' => t('A document section for maintaining a knowledge base.'),
'menu' => array(
array(
'title' => t('Documents'),
'href' => 'documents',
),
),
'types' => array(
'og',
),
),
);
}
if (module_exists('taxonomy')) {
$items[] = array(
'namespace' => 'spaces',
'attribute' => 'feature',
'value' => 'taxonomy',
'views' => array(
'spaces_taxonomy',
),
'block' => array(
array(
'module' => 'spaces_core',
'delta' => 'tags',
'region' => 'right',
'weight' => -11,
),
),
);
}
return $items;
}
function spaces_core_documents() {
if ($space = spaces_get_space()) {
if ($view = views_get_view('spaces_book_current')) {
$view
->set_display();
$view
->set_items_per_page(0);
$view
->execute();
if (is_array($view->result) && count($view->result)) {
$row = array_shift($view->result);
drupal_goto('node/' . $row->nid);
}
}
context_set_by_condition('node', 'book');
$message = t('Please add your first book page to get started.');
$button = theme('context_links', context_links());
$o = "<div class='spaces-empty'>{$message} <div class='buttons'>{$button}</div></div>";
return $o;
}
}
function spaces_core_context_links_alter(&$links) {
if (context_get('spaces', 'feature') == 'book' && isset($links['book']) && ($space = spaces_get_space())) {
if ($space
->feature_access('book') && ($node = menu_get_object())) {
if (!empty($node->book['mlid'])) {
$links['book']['query'] = 'parent=' . $node->book['mlid'];
}
}
}
}
function _spaces_core_block_tags() {
$space = spaces_get_space();
if (context_get('spaces', 'feature') == 'taxonomy') {
$terms = taxonomy_terms_parse_string(arg(2));
$tid = $terms['tids'][0];
if ($term = taxonomy_get_term($tid)) {
$vocab = taxonomy_get_vocabulary($term->vid);
$view = views_get_view('spaces_tags');
$view->filter[1]['value'] = array(
$term->vid,
);
$block['content'] = views_build_view('block', $view, array(
$space->sid,
));
$block['subject'] = $vocab->name;
return $block;
}
}
}
function _spaces_core_block_book() {
$space = spaces_get_space();
$block = array();
if ($space) {
if ($node = menu_get_object()) {
$current_bid = empty($node->book['bid']) ? 0 : $node->book['bid'];
}
$features = spaces_features();
$feature_menu = space_customizer_menu::customize($space, 'book', $features['book']->spaces['menu']);
$block['subject'] = isset($feature_menu['documents']['title']) ? $feature_menu['documents']['title'] : t('Documents');
$output = '';
if ($view = views_get_view('spaces_book_current')) {
$view
->set_display();
$view
->set_items_per_page(0);
$view
->execute();
if (is_array($view->result) && count($view->result)) {
foreach ($view->result as $row) {
$output .= menu_tree(book_menu_name($row->nid));
}
}
}
$block['content'] = $output;
}
return $block;
}