View source
<?php
function spaces_core_menu($may_cache) {
$items = array();
if ($may_cache) {
if (module_exists('book')) {
$items[] = array(
'title' => t('Documents'),
'path' => 'documents',
'description' => t('Displays the parent book node for a given spaces group.'),
'callback' => 'spaces_core_documents',
'access' => user_access('access content'),
'type' => MENU_NORMAL_ITEM,
);
}
if (module_exists('taxonomy')) {
$items[] = array(
'title' => t('Taxonomy'),
'path' => 'taxonomy/term',
'description' => t('Custom taxonomy term callback.'),
'callback' => 'spaces_core_taxonomy',
'access' => user_access('access content'),
'type' => MENU_CALLBACK,
);
}
return $items;
}
}
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_id, &$form) {
switch ($form_id) {
case 'og_search_form':
$form['#theme'] = '';
break;
case 'user_edit':
unset($form['og_settings']);
break;
case 'comment_form':
if (!drupal_get_title()) {
drupal_set_title(t('Reply'));
}
break;
}
}
function spaces_core_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case "view":
switch ($node->type) {
case 'book':
if (strlen(strip_tags($node->content['body']['#value'])) > 1000) {
$node->content['spaces_book'] = array(
'#value' => theme('book_navigation', $node, false),
'#weight' => -100,
);
}
_spaces_core_book_link();
break;
}
break;
}
}
function spaces_core_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'view':
context_set('spaces', 'user', $account->uid);
break;
}
}
function spaces_core_views_default_views() {
$default_views = array(
'_spaces_core_views_blog',
'_spaces_core_views_blog_comments',
'_spaces_core_views_ref_blog2book',
'_spaces_core_views_user_posts',
'_spaces_core_views_changes',
'_spaces_core_views_comments',
'_spaces_core_views_taxonomy',
'_spaces_core_views_tags',
);
foreach ($default_views as $v) {
$view = call_user_func($v);
if (is_object($view) && $view->name) {
$views[$view->name] = $view;
}
}
return $views;
}
function spaces_core_context_define() {
$items = array();
if (module_exists('blog')) {
$items[] = array(
'namespace' => 'spaces',
'attribute' => 'feature',
'value' => 'blog',
'node' => array(
'blog',
),
'views' => array(
'spaces_blog',
'spaces_blog_comments',
),
'block' => array(
array(
'module' => 'views',
'delta' => 'spaces_blog_comments',
'region' => 'right',
'weight' => -11,
),
),
'menu' => array(
'blog',
),
'spaces' => array(
'label' => t('Blog'),
'description' => t('A member blog and team discussion space.'),
'options' => _spaces_group_options(),
'#weight' => -5,
),
);
}
if (module_exists('book')) {
$items[] = array(
'namespace' => 'spaces',
'attribute' => 'feature',
'value' => 'book',
'node' => array(
'book',
),
'block' => array(
array(
'module' => 'spaces_core',
'delta' => 'book',
'region' => 'right',
'weight' => -11,
),
),
'menu' => array(
'documents',
),
'spaces' => array(
'label' => t('Documents'),
'description' => t('A document section for maintaining a knowledge base.'),
'options' => _spaces_group_options(),
),
);
}
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_perm() {
return array(
'add child page to any book',
);
}
function spaces_core_documents() {
$gid = spaces_gid();
$nid = db_result(db_query('SELECT n.nid FROM {node} n JOIN {book} b ON n.nid = b.nid AND n.vid = b.vid JOIN {og_ancestry} og ON og.nid = n.nid WHERE og.group_nid = %d AND n.type = "%s" AND b.parent = %d LIMIT 1', $gid, 'book', 0));
if ($nid) {
drupal_goto('node/' . $nid);
}
context_ui_set('node', 'book');
_spaces_core_book_link();
$message = t('Please add your first book page to get started.');
$button = theme('spaces_button');
$o = "<p>{$message}</p>{$button}";
return $o;
}
function spaces_core_taxonomy($tid) {
if (is_numeric($tid) && ($t = taxonomy_get_term($tid))) {
$v = taxonomy_get_vocabulary($t->vid);
$use_gid = false;
if ($gid = spaces_gid()) {
foreach ($v->nodes as $type) {
if (!og_is_omitted_type($type)) {
$use_gid = true;
break;
}
}
}
}
if ($use_gid) {
$view = views_get_view('spaces_taxonomy');
$content = views_build_view('page', $view, array(
$gid,
$tid,
), true, 25);
}
else {
$view = views_get_view('spaces_taxonomy');
$content = views_build_view('page', $view, array(
0,
$tid,
), true, 25);
}
if (is_object($t) && is_object($v)) {
drupal_set_title($v->name . ': ' . $t->name);
context_set('taxonomy', array(
'vid' => $t->vid,
'tid' => $t->tid,
));
if ($use_gid) {
context_set('taxonomy', 'group_vocab', true);
}
}
return $content;
}
function _spaces_core_book_link() {
if (spaces_gid() && spaces_is_member() && spaces_feature('book')) {
if (arg(0) == 'node' && is_numeric(arg(1))) {
$pid = arg(1);
$types = node_get_types();
$links['book']['title'] = $types['book']->name;
$links['book']['href'] = 'node/add/book/parent/' . $pid;
}
if ($links) {
context_set('spaces', 'links', $links);
}
}
}
function _spaces_core_block_tags() {
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(
spaces_gid(),
));
$block['subject'] = $vocab->name;
return $block;
}
}
}
function _spaces_core_block_book() {
$result = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.nid = %d'), arg(1));
if (db_num_rows($result) > 0) {
$node = db_fetch_object($result);
$path = book_location($node);
$path[] = $node;
$expand = array();
foreach ($path as $key => $node) {
$expand[] = $node->nid;
}
$label = spaces_custom_menu('label', 'documents');
$block['subject'] = $label ? $label : t('Documents');
$block['content'] = _spaces_core_book_tree(0, 5, $expand);
return $block;
}
}
function _spaces_core_book_tree($parent = 0, $depth = 3, $unfold = array(), $gid = NULL) {
if (!$gid) {
$gid = spaces_gid();
}
if ($gid) {
$result = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid JOIN {og_ancestry} og ON og.nid = b.nid WHERE n.status = 1 AND og.group_nid = %d ORDER BY b.weight, n.title'), $gid);
while ($node = db_fetch_object($result)) {
$list = isset($children[$node->parent]) ? $children[$node->parent] : array();
$list[] = $node;
$children[$node->parent] = $list;
}
if ($tree = book_tree_recurse($parent, $depth, $children, $unfold)) {
return '<ul class="menu">' . $tree . '</ul>';
}
}
else {
return '';
}
}
function _spaces_core_views_blog() {
$view = new stdClass();
$view->name = 'spaces_blog';
$view->description = t('Provides a default blog listing that is filterable by uid.');
$view->access = array();
$view->view_args_php = '';
$view->menu = TRUE;
$view->menu_title = t('Blog');
$view->page = TRUE;
$view->page_title = t('Blog');
$view->page_empty = '<?php print _spaces_views_empty("blog"); ?>';
$view->page_empty_format = '2';
$view->page_type = 'teaser';
$view->url = 'blog';
$view->use_pager = TRUE;
$view->nodes_per_page = '5';
$view->block = TRUE;
$view->block_title = t('Recent blog posts');
$view->block_empty = "<p class='views-empty'>" . t('No blog entries found.') . "</p>";
$view->block_empty_format = '1';
$view->block_type = 'spaces_datetitle';
$view->nodes_per_block = '3';
$view->block_more = TRUE;
$view->sort = array(
array(
'tablename' => 'node',
'field' => 'created',
'sortorder' => 'DESC',
'options' => 'normal',
),
);
$view->argument = array(
array(
'type' => 'uid',
'argdefault' => '2',
'title' => '%1\'s Blog',
'options' => '',
'wildcard' => 'all',
'wildcard_substitution' => '',
),
array(
'type' => 'node_feed',
'argdefault' => '2',
'title' => 'Blog',
'options' => '',
'wildcard' => '',
'wildcard_substitution' => '',
),
);
$view->field = array(
array(
'tablename' => 'node',
'field' => 'created',
'label' => '',
'handler' => 'views_handler_field_date_small',
),
array(
'tablename' => 'node',
'field' => 'title',
'label' => '',
'handler' => 'views_handler_field_nodelink',
'options' => 'link',
),
);
$view->filter = array(
array(
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
array(
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array(
0 => 'blog',
),
),
array(
'tablename' => 'og_ancestry',
'field' => 'picg',
'operator' => '=',
'options' => '',
'value' => '***CURRENT_GID***',
),
);
$view->exposed_filter = array();
$view->requires = array(
node,
);
return $view;
}
function _spaces_core_views_blog_comments() {
$view = new stdClass();
$view->name = 'spaces_blog_comments';
$view->description = t('');
$view->access = array();
$view->view_args_php = '';
$view->page = FALSE;
$view->block = TRUE;
$view->block_title = t('Recent Comments');
$view->block_empty = "<p class='views-empty'>" . t('No recent comments.') . "</p>";
$view->block_empty_format = '1';
$view->block_type = 'spaces_datetitle';
$view->nodes_per_block = '5';
$view->sort = array(
array(
'tablename' => 'node_comment_statistics',
'field' => 'last_comment_timestamp',
'sortorder' => 'DESC',
'options' => 'normal',
),
);
$view->argument = array();
$view->field = array(
array(
'tablename' => 'comments',
'field' => 'subject',
'label' => t('Comment'),
'handler' => 'views_handler_field_commentlink',
'options' => 'link',
),
array(
'tablename' => 'comments',
'field' => 'name',
'label' => t('By'),
),
array(
'tablename' => 'node',
'field' => 'title',
'label' => t('On Post'),
'handler' => 'views_handler_field_nodelink',
'options' => 'nolink',
),
array(
'tablename' => 'node_comment_statistics',
'field' => 'last_comment_timestamp',
'label' => t('Date'),
'handler' => 'views_handler_field_date_small',
),
);
$view->filter = array(
array(
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
array(
'tablename' => 'node_comment_statistics',
'field' => 'comment_count',
'operator' => '>',
'options' => '',
'value' => '0',
),
array(
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array(
0 => 'blog',
),
),
array(
'tablename' => 'og_ancestry',
'field' => 'picg',
'operator' => '=',
'options' => '',
'value' => '***CURRENT_GID***',
),
array(
'tablename' => 'node_comment_statistics',
'field' => 'last_comment_timestamp',
'operator' => '>',
'options' => -1 * SPACES_ARCHIVE_TIMESTAMP,
'value' => 'now',
),
);
$view->exposed_filter = array();
$view->requires = array(
node_comment_statistics,
comments,
node,
);
return $view;
}
function _spaces_core_views_ref_blog2book() {
$view = new stdClass();
$view->name = 'ref_blog2book';
$view->description = 'Provides a list of blog entries that refer to the given book page.';
$view->access = array();
$view->view_args_php = '';
$view->page = FALSE;
$view->block = TRUE;
$view->block_title = t('Discussions');
$view->block_type = 'table';
$view->nodes_per_block = '50';
$view->sort = array(
array(
'tablename' => 'node',
'field' => 'created',
'sortorder' => 'DESC',
'options' => 'normal',
),
);
$view->argument = array(
array(
'type' => 'content: field_referenced_book_page',
'argdefault' => '1',
),
);
$view->field = array(
array(
'tablename' => 'node',
'field' => 'title',
'label' => t('Title'),
'handler' => 'views_handler_field_nodelink',
'options' => 'link',
),
array(
'tablename' => 'users',
'field' => 'name',
'label' => t('Author'),
),
array(
'tablename' => 'node',
'field' => 'created',
'label' => t('Posted'),
'handler' => 'views_handler_field_date_small',
),
);
$view->filter = array(
array(
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array(
0 => 'blog',
),
),
array(
'tablename' => 'og_ancestry',
'field' => 'picg',
'operator' => '=',
'options' => '',
'value' => '***CURRENT_GID***',
),
);
$view->requires = array(
node,
node_comment_statistics,
users,
);
return $view;
}
function _spaces_core_views_user_posts() {
$view = new stdClass();
$view->name = 'spaces_user_posts';
$view->description = t('Shows updated posts.');
$view->access = array();
$view->view_args_php = '';
$view->page = TRUE;
$view->page_title = t('Recent Posts');
$view->page_empty = '<p class="views-empty">' . t('No recent posts found') . '</p>';
$view->page_empty_format = '2';
$view->page_type = 'table';
$view->url = 'userposts';
$view->use_pager = TRUE;
$view->nodes_per_page = '25';
$view->block = TRUE;
$view->block_title = t('Recent Posts');
$view->block_empty = '<p class="views-empty">' . t('No recent posts found') . '</p>';
$view->block_empty_format = '1';
$view->block_type = 'table';
$view->nodes_per_block = '10';
$view->block_more = TRUE;
$view->sort = array(
array(
'tablename' => 'node_comment_statistics',
'field' => 'last_comment_timestamp',
'sortorder' => 'DESC',
'options' => 'normal',
),
);
$view->argument = array(
array(
'type' => 'uidtouch',
'argdefault' => '7',
'title' => "%1's Posts",
),
);
$view->field = array(
array(
'tablename' => 'node',
'field' => 'title',
'label' => 'Title',
'handler' => 'views_handler_field_nodelink_with_mark',
'options' => 'link',
),
array(
'tablename' => 'node',
'field' => 'type',
'label' => 'Type',
),
array(
'tablename' => 'node_comment_statistics',
'field' => 'comment_count',
'label' => 'Replies',
'handler' => 'views_handler_comments',
),
array(
'tablename' => 'node_comment_statistics',
'field' => 'last_comment_timestamp',
'label' => 'Last Post',
'handler' => 'views_handler_field_since',
'options' => 1,
),
);
$view->filter = array(
array(
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
array(
'tablename' => 'node',
'field' => 'type',
'operator' => 'NOR',
'options' => '',
'value' => array_merge(og_get_types('group'), array(
'shout',
)),
),
array(
'tablename' => 'og_ancestry',
'field' => 'picg',
'operator' => '=',
'options' => '',
'value' => '***CURRENT_GID***',
),
);
$view->requires = array(
node_comment_statistics,
node,
);
return $view;
}
function _spaces_core_views_changes() {
$view = new stdClass();
$view->name = 'spaces_changes';
$view->description = t('Displays a list of recently modified nodes.');
$view->access = array();
$view->view_args_php = 'return _spaces_views_arg_og_handler($args);';
$view->page = TRUE;
$view->page_title = t('Recent Changes');
$view->page_type = 'table';
$view->url = 'changes';
$view->use_pager = TRUE;
$view->nodes_per_page = '25';
$view->block = TRUE;
$view->block_title = t('Recent Changes');
$view->block_empty = "<p class='views-empty'>" . t('No recent changes.') . "</p>";
$view->block_empty_format = '1';
$view->block_type = 'spaces_datetitle';
$view->nodes_per_block = '5';
$view->argument = array(
array(
'type' => 'gid',
'argdefault' => '2',
),
);
$view->sort = array(
array(
'tablename' => 'node',
'field' => 'changed',
'sortorder' => 'DESC',
'options' => 'normal',
),
);
$view->field = array(
array(
'tablename' => 'og_node_data',
'field' => 'title',
'label' => 'Group',
'handler' => 'spaces_views_handler_crayon_name',
'options' => 'og',
),
array(
'tablename' => 'node',
'field' => 'title',
'label' => t('Title'),
'handler' => 'views_handler_field_nodelink',
'options' => 'link',
),
array(
'tablename' => 'node',
'field' => 'changed',
'label' => t('Changed'),
'handler' => 'views_handler_field_since',
'options' => 1,
),
array(
'tablename' => 'node',
'field' => 'type',
'label' => t('Type'),
),
array(
'tablename' => 'users',
'field' => 'name',
'label' => t('Author'),
),
);
if (variable_get('spaces_calendar_feed_itemtype', '')) {
$excluded = array(
'shout',
variable_get('spaces_calendar_feed_itemtype', ''),
);
}
else {
$excluded = array(
'shout',
);
}
$view->filter = array(
array(
'tablename' => 'node',
'field' => 'type',
'operator' => 'NOR',
'options' => '',
'value' => array_merge(og_get_types('group'), $excluded),
),
array(
'tablename' => 'og_uid_node',
'field' => 'currentuid',
'operator' => '=',
'options' => '',
'value' => '***CURRENT_USER***',
),
array(
'tablename' => 'node',
'field' => 'changed',
'operator' => '>',
'options' => -1 * SPACES_ARCHIVE_TIMESTAMP,
'value' => 'now',
),
);
$view->exposed_filter = array();
$view->requires = array(
'node',
'users',
'og_node_data',
'og_uid_node',
);
return $view;
}
function _spaces_core_views_comments() {
$view = new stdClass();
$view->name = 'spaces_comments';
$view->description = t('Displays a listing of recent comments');
$view->access = array();
$view->view_args_php = 'return _spaces_views_arg_og_handler($args);';
$view->page = TRUE;
$view->page_title = t('Recent Comments');
$view->page_empty = '<p class="views-empty">' . t('No recent comments found.') . '</p>';
$view->page_empty_format = '2';
$view->page_type = 'table';
$view->url = 'comments';
$view->use_pager = TRUE;
$view->nodes_per_page = '25';
$view->block = TRUE;
$view->block_title = t('Recent Comments');
$view->block_empty = "<p class='views-empty'>" . t('No recent comments.') . "</p>";
$view->block_empty_format = '1';
$view->block_type = 'spaces_datetitle';
$view->nodes_per_block = '5';
$view->sort = array(
array(
'tablename' => 'node_comment_statistics',
'field' => 'last_comment_timestamp',
'sortorder' => 'DESC',
'options' => 'normal',
),
);
$view->argument = array(
array(
'type' => 'gid',
'argdefault' => '2',
),
);
$view->field = array(
array(
'tablename' => 'og_node_data',
'field' => 'title',
'label' => 'Group',
'handler' => 'spaces_views_handler_crayon_name',
'options' => 'og',
),
array(
'tablename' => 'comments',
'field' => 'subject',
'label' => t('Comment'),
'handler' => 'views_handler_field_commentlink',
'options' => 'link',
),
array(
'tablename' => 'comments',
'field' => 'name',
'label' => t('By'),
),
array(
'tablename' => 'node',
'field' => 'title',
'label' => t('On Post'),
'handler' => 'views_handler_field_nodelink',
'options' => 'nolink',
),
array(
'tablename' => 'node',
'field' => 'type',
'label' => t('Type'),
),
array(
'tablename' => 'node_comment_statistics',
'field' => 'last_comment_timestamp',
'label' => t('Date'),
'handler' => 'views_handler_field_date_small',
),
);
$view->filter = array(
array(
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
array(
'tablename' => 'node_comment_statistics',
'field' => 'comment_count',
'operator' => '>',
'options' => '',
'value' => '0',
),
array(
'tablename' => 'og_uid_node',
'field' => 'currentuid',
'operator' => '=',
'options' => '',
'value' => '***CURRENT_USER***',
),
array(
'tablename' => 'node_comment_statistics',
'field' => 'last_comment_timestamp',
'operator' => '>',
'options' => -1 * SPACES_ARCHIVE_TIMESTAMP,
'value' => 'now',
),
);
$view->exposed_filter = array();
$view->requires = array(
node_comment_statistics,
comments,
node,
og_node_data,
og_uid_node,
);
return $view;
}
function _spaces_core_views_taxonomy() {
$view = new stdClass();
$view->name = 'spaces_taxonomy';
$view->description = t('Spaces taxonomy override.');
$view->access = $view->field = $view->exposed_filter = array();
$view->page = TRUE;
$view->page_empty = '<p>' . t('No entries found.') . '</p>';
$view->page_empty_format = '2';
$view->page_type = 'table';
$view->use_pager = TRUE;
$view->nodes_per_page = '20';
$view->field = array(
array(
'tablename' => 'node',
'field' => 'title',
'label' => 'Title',
'handler' => 'views_handler_field_nodelink',
'sortable' => '1',
'options' => 'link',
),
array(
'tablename' => 'node',
'field' => 'created',
'label' => 'Date',
'handler' => 'views_handler_field_date_small',
'sortable' => '1',
'defaultsort' => 'DESC',
),
array(
'tablename' => 'node',
'field' => 'type',
'label' => 'Type',
'sortable' => '1',
),
);
$view->sort = array();
$view->argument = array(
array(
'type' => 'gid',
'argdefault' => '2',
),
array(
'type' => 'taxid',
'argdefault' => '1',
'options' => '0',
'wildcard' => '',
'wildcard_substitution' => '',
),
);
$view->filter = array(
array(
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
);
$view->requires = array(
node,
);
return $view;
}
function _spaces_core_views_tags() {
$view = new stdClass();
$view->name = 'spaces_tags';
$view->description = '';
$view->access = array();
$view->view_args_php = 'return _spaces_views_arg_og_handler($args);';
$view->page = FALSE;
$view->block = TRUE;
$view->block_title = t('Tags');
$view->block_empty = '<p>' . t('No tags found.') . '</p>';
$view->block_empty_format = '1';
$view->block_type = 'tagadelic';
$view->nodes_per_block = '20';
$view->sort = array();
$view->filter = array(
array(
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
array(
'tablename' => 'term_data',
'field' => 'vid',
'operator' => 'AND',
'options' => '',
'value' => array(
0 => '11',
),
),
);
$view->argument = array(
array(
'type' => 'gid',
'argdefault' => '2',
),
);
$view->field = array(
array(
'tablename' => 'term_node',
'field' => 'name',
'label' => '',
'options' => 'link',
),
);
$view->exposed_filter = array();
$view->requires = array(
term_node,
node,
term_data,
);
return $view;
}