function fb_example_nodeapi in Drupal for Facebook 6.3
Implements hook_nodeapi().
Publish to facebook Walls when users submit nodes.
See also
http://developers.facebook.com/docs/reference/rest/stream.publish
http://developers.facebook.com/docs/guides/attachments
File
- contrib/
fb_example.module, line 71 - Example customizations to modules/fb.
Code
function fb_example_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($op == 'insert' || $op == 'update') {
if (isset($node->stream_publish) && $node->stream_publish) {
$attachment = array(
'name' => $node->title,
'href' => url('node/' . $node->nid, array(
'absolute' => TRUE,
)),
'description' => filter_xss($node->teaser, array()),
);
/*
if ($picture = $GLOBALS['user']->picture) {
$url = url($picture, array('absolute' => TRUE));
$attachment['media'][] = array(
'type' => 'image',
'src' => $url,
'href' => $url,
);
}
*/
if ($logo_path = theme_get_setting('logo_path')) {
$url = url($logo_path, array(
'absolute' => TRUE,
));
$attachment['media'][] = array(
'type' => 'image',
'src' => $url,
'href' => $url,
);
}
/* Facebook has disabled the message. Deprecated.
$user_message = t('Check out my latest post on !site...',
array('!site' => variable_get('site_name', t('my Drupal for Facebook powered site'))));
*/
$actions = array();
$actions[] = array(
'text' => t('Read More'),
'href' => url('node/' . $node->nid, array(
'absolute' => TRUE,
)),
);
fb_stream_publish_dialog(array(
'attachment' => $attachment,
'action_links' => $actions,
));
}
}
// Another way to add like button, as part of a node.
if ($op == 'view' && variable_get('fb_example_nodeapi_add_like', FALSE)) {
$url = fb_scrub_urls(url('node/' . $node->nid, array(
'absolute' => TRUE,
)));
$node->content['dff_like'] = array(
'#value' => "<fb:like href={$url}></fb:like>",
'#type' => 'markup',
'#prefix' => '<div class="dff_like_wrapper">',
'#suffix' => '</div>',
);
}
}