View source
<?php
function spaces_views_tables() {
return array(
'spaces' => array(
'name' => 'space',
'filters' => array(
'type' => array(
'name' => t('Spaces: node in current space'),
'operator' => array(
'all' => t('Apply at all times'),
'active' => t('Apply only in a space'),
),
'list' => 'spaces_views_handler_operator_spacetype',
'list-type' => 'select',
'handler' => 'spaces_handler_filter_type',
),
),
),
);
}
function spaces_views_handler_operator_spacetype() {
$options = array(
'all' => t('Applies to any space'),
);
foreach (spaces_types() as $type => $info) {
$options[$type] = t('Applies only in a !spacetype', array(
'!spacetype' => strtolower($info['title']),
));
}
return $options;
}
function spaces_handler_filter_type($op, $filter, $filterinfo, &$query) {
$space = spaces_get_space();
if ($space) {
if ($filter['value'] == $space->type || $filter['value'] == 'all') {
$space
->views_filter(TRUE, $query);
}
}
else {
if ($filter['operator'] == 'all') {
$types = spaces_types();
foreach ($types as $type => $info) {
call_user_func(array(
$info['class'],
'views_filter',
), FALSE, $query);
}
}
}
}
function _spaces_views_empty($feature, $block = false) {
$features = spaces_features();
$space = spaces_get_space();
if ($space && $space
->feature_access($feature) && ($types = $features[$feature]->node)) {
$content_types = node_get_types();
$type_name = $content_types[current($types)]->name;
if (!$block) {
$b = spaces_node_links();
if ($b) {
$m = "<p>" . t('Please click below to add your first @content.', array(
'@content' => $type_name,
)) . "</p>";
}
else {
$m = "<p>" . t('No entries were found.', array(
'@content' => $type_name,
)) . "</p>";
}
}
return $m . $b;
}
else {
if ($block) {
return '';
}
else {
drupal_not_found();
exit;
}
}
}
function spaces_views_handler_filetype($fieldinfo, $fielddata, $value, $data) {
$file = new stdClass();
$file->filemime = $data->files_filemime;
$file->filename = $data->files_filename;
$file->filepath = $data->files_filepath;
return theme('fileview', $file);
}
function spaces_views_handler_crayon_name($fieldinfo, $fielddata, $value, $data) {
switch ($fielddata['options']) {
case 'og':
$og = db_fetch_object(og_get_node_groups_result($data->nid));
$og->nid = $og->group_nid;
return theme('crayon_popup', $og);
break;
case 'casetracker':
static $nodes = array();
$pid = $data->casetracker_case_pid;
if (!$nodes[$pid]) {
$nodes[$pid] = db_fetch_object(db_query(db_rewrite_sql("SELECT n.nid, n.title FROM {node} n WHERE n.nid = %d"), $pid));
}
return theme('crayon_popup', $nodes[$pid]);
break;
}
}
function spaces_views_style_plugins($value = '') {
$items['spaces_datetitle'] = array(
'name' => t('Spaces: Date title listing'),
'theme' => 'spaces_datetitle_view_style',
'validate' => 'views_ui_plugin_validate_list',
'needs_fields' => true,
'weight' => 0,
);
return $items;
}
function _spaces_views_get_field($op, $view) {
switch ($op) {
case 'cck_date':
$view = (object) $view;
$fields = _views_get_fields();
foreach ($view->field as $field_id => $field) {
$field_key = $field['tablename'] . '.' . $field['field'];
if ($fields[$field_key]['content_field_module'] == 'date' && $view->field[$field_id]) {
return $field_id;
}
}
return false;
}
}
function theme_spaces_datetitle_view_style($view, $nodes, $type) {
$fields = _views_get_fields();
$taken = array();
foreach ($view->field as $id => $field) {
$field_name = $field['field'];
if (isset($taken[$field_name])) {
$field_name = $field['queryname'];
}
$taken[$field_name] = true;
$field_names[$id] = $field_name;
}
$base_vars = array(
'view' => $view,
'view_type' => $type,
);
$custom_fields = array();
if (_spaces_views_get_field('cck_date', $view) !== false) {
$custom_fields[_spaces_views_get_field('cck_date', $view)] = 'cck_date';
}
foreach ($nodes as $i => $node) {
$vars = $base_vars;
$vars['node'] = $node;
$vars['count'] = $i;
$vars['stripe'] = $i % 2 ? 'even' : 'odd';
foreach ($view->field as $id => $field) {
if (isset($custom_fields[$id])) {
$name = $custom_fields[$id];
}
else {
$name = $field_names[$id];
}
$vars[$name] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
if (isset($field['label'])) {
$vars[$name . '_label'] = $field['label'];
}
}
$items[] = theme('datetime_view_style_item', $vars);
}
if ($items) {
return theme('item_list', $items);
}
}
function theme_datetime_view_style_item($vars) {
$item = (object) $vars;
$_date = array(
$item->created,
$item->changed,
$item->last_comment_timestamp,
$item->cck_date,
);
foreach ($_date as $t) {
if ($t) {
$d = $t;
break;
}
}
$_user = array(
$item->assign_to,
$item->name,
$item->user,
);
foreach ($_user as $t) {
if ($t) {
$u = $t;
break;
}
}
$_title = array(
$item->subject,
$item->node_title,
$item->title,
);
foreach ($_title as $t) {
if ($t) {
$title = $t;
break;
}
}
$output = "<div class='view-item clear-block'>";
if ($item->type) {
$output .= "<div class=\"view-type\">{$item->type}</div>";
}
if ($d || $u) {
$output .= "<div class='meta'>";
if ($d) {
$output .= "<span class=\"view-date\">{$d}</span>";
}
if ($u) {
$output .= "<span class=\"view-user\">{$u}</span>";
}
$output .= "</div>";
}
$output .= "<div class=\"view-title\">{$title}</div>";
$output .= "</div>";
return $output;
}