t('Facebook Discussion'),
'theme' => 'views_fb_discussion',
'summary_theme' => 'views_summary',
'needs_table_header' => true,
'needs_fields' => TRUE, // without this, table header will not be built
);
$items['fb_teasers'] =
array('name' => t('Facebook Teaser List'),
'theme' => 'views_fb_teasers',
'summary_theme' => 'views_summary',
'needs_table_header' => true,
'needs_fields' => TRUE, // without this, table header will not be built
);
return $items;
}
function theme_views_fb_discussion($view, $nodes, $type) {
//drupal_set_message("theme_views_fb_discussion, type is '$type'" . dprint_r($view, 1) . dprint_r($nodes, 1)); // debug
if ($type == 'page') {
// use tablesort code to generate the sort links.
$sorts = array();
$ts = tablesort_init($view->table_header);
foreach($view->table_header as $cell) {
$th = tablesort_header($cell, $view->table_header, $ts);
$sorts[] = $th['data'];
}
$output .= theme('sortable_header_links', $sorts);
$output .= theme('fb_discussion_nodes', $view, $nodes);
}
else if ($type == 'block') {
// If were displaying in a block, its most likely the profile page, where
// all styles have to be inline. So here we do our best to mimic the
// block view of a facebook discussion.
foreach ($nodes as $data) {
$reply_count = format_plural($data->node_comment_statistics_comment_count+1, '1 post', '@count posts');
$output .= '
';
$output .= '
'.l($data->node_title, 'node/'.$data->nid, array(), NULL, NULL, TRUE)."
$reply_countUpdated ". format_interval(time() - $data->node_comment_statistics_last_comment_timestamp)." ago.
\n";
$output .= "
\n";
}
}
return $output;
}
function theme_sortable_header_links($items = array()) {
if (!empty($items)) {
$output .= "";
$output .= "- ".t('Sort by').'
';
foreach ($items as $item) {
$output .= '- '. $item .'
';
}
$output .= "
";
}
return $output;
}
function theme_fb_discussion_nodes($view, $items = array()) {
$fields = _views_get_fields();
if (!empty($items)) {
foreach ($items as $item) {
$out = array();
$row = array();
foreach ($view->field as $field) {
if ($fields[$field['id']]['visible'] !== FALSE) {
$out[$field['field']] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $item, $view);
}
}
$reply_count = format_plural($item->node_comment_statistics_comment_count + 1, '1 post', '@count posts');
// Title link, reply count and created date
$row[] = array('class' => 'fb_discussion_topic',
'data' => ''.$out['title'].'
'.
''.$reply_count.'. '.
t('Created !time',
array('!time' => $out['created'])).
'.
');
// Most recent reply info
$row[] = array('class' => 'fb_discussion_reply',
'data' => ''.
t('Latest post by !name',
array('!name' => $out['last_comment_name'])).
'
'.$out['last_comment_timestamp'].'
');
$rows[] = $row;
}
if (count($rows)) {
$output = theme('table', array(), $rows, array('class' => 'fb_discussion'));
}
}
return $output;
}
function theme_views_fb_teasers($view, $nodes, $type) {
//drupal_set_message("theme_views_fb_teasers, type is '$type'" . dprint_r($view, 1) . dprint_r($nodes, 1)); // debug
// If were displaying in a block, its most likely the profile page, where
// all styles have to be inline. So here we do our best to mimic the
// block view of a facebook discussion.
foreach ($nodes as $data) {
$node = node_load($data->nid);
$output .= '';
$output .= '
'.l($node->title, 'node/'.$data->nid, array(), NULL, NULL, TRUE)."
";
$node = node_build_content($node, TRUE, FALSE);
$output .= drupal_render($node->content);
$output .= "
\n";
}
return $output;
}
?>