'fb_user_app',
'join' => array('left' => array('table' => 'node',
'field' => 'uid'),
'right' => array('field' => 'uid')),
);
return $tables;
}
function fb_views_views_arguments() {
$items['fb_user_author'] =
array('name' => t('Facebook User: Author is Friend'),
'help' => t('The node\'s author is a friend of the user.
The application hint is needed on non-canvas pages, ignored on canvas pages.'),
'handler' => 'fb_views_handler_author_is_friend',
'option' => array('#type' => 'select',
'#options' => fb_get_app_options(FALSE),
'#title' => t('App Hint'),
),
);
return $items;
}
function fb_views_handler_author_is_friend($op, &$query, $a1, $a2 = null) {
//dpm(func_get_args(), "fb_views_handler_author_is_friend");
// For convenience, allow 'current' for current user
if ($a2 == 'current') {
global $user;
$a2 = $user->uid;
}
if ($op == 'summary') {
// Ideally, we'd display all users who are known facebook users. However, because the primary table is node, we can only show those who have actually posted content.
$query->add_table('fb_user_app', TRUE);
$query->add_where('fb_user_app.uid IS NOT NULL');
$query->add_table('users', true);
$query->add_field('name', 'users');
$query->add_field('uid', 'users');
$fieldinfo['field'] = "users.name";
return $fieldinfo;
}
else if ($op == 'filter') {
$fb_app = $GLOBALS['fb_app']; // Canvas pages only.
if (!$fb_app)
$fb_app = fb_get_app(array('nid' => $a1['options']));
$uid = intval($a2);
$fbu = fb_get_fbu($uid, $fb_app);
$friends = array();
// On non-canvas pages, we have to work harder to get the facebook id.
if ($uid && !$fbu) {
// This code may never be reached.
$result = db_query("SELECT fbu FROM {fb_user_app} WHERE uid='%d'",
$uid);
while ($data = db_fetch_object($result)) {
$friends = array_merge($friends, fb_get_friends($data->fbu));
}
}
else
$friends = fb_get_friends($fbu, $fb_app);
if (is_array($friends) && count($friends)) {
$query->add_table('fb_user_app', TRUE);
$query->add_where('fb_user_app.fbu IN (%s)', implode(',', $friends));
}
else {
// No friends found. How best to handle this?
$query->add_where('0');
}
}
else if ($op == 'link') {
return l($query->name, "$a2/" . intval($query->uid));
}
else if ($op == 'title') {
if ($query == 'current') {
global $user;
$query = $user->uid;
}
$data = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = '%d'", $query));
return check_plain($data->name);
}
}
/**
* Introduce a theme style that mimics a facebook discussion board.
*
* To use: make a theme which provides a page view, and select view type
* 'Facebook Discussion'. Then under Fields, include Node: Title, Node:
* Created Time, Node: Author Name, Comment: Count, Comment: Last Comment
* Author, Comment: Last Comment Time.
*
* It may not look exactly like a facebook discussion, but comes close.
*/
function fb_views_views_style_plugins() {
$items = array();
$items['fb_discussion'] =
array('name' => 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 .= '