Hi all,
I follow the steps in here http://drupal.org/node/685320 to create a custom module to post to my facebook pages' wall. But I can't even make the checkbox option to show up. Below is my code, please help as I'm not a programmer.
<?php
/**
* Implementation of hook_form_alter.
*
* Adds a checkbox to node edit and comment forms. This checkbox lets
* facebook users know that content may be published to their Wall,
* and gives them a chance to prevent that.
*/
function fb_postwall_form_alter(&$form, $form_state, $form_id) {
if (module_exists('fb')) {
if (fb_facebook_user()) {
if ($form['#id'] == 'page-node-form') {
// Add checkbox to control feed publish.
$form['fb_postwall']['stream_publish'] = array(
'#type' => 'checkbox',
'#title' => 'Share on Facebook',
'#default_value' => TRUE,
);
}
else if ($form['form_id']['#value'] == 'comment_form') {
// Add checkbox to control feed publish.
$form['fb_postwall']['stream_publish'] = array(
'#type' => 'checkbox',
'#title' => 'Share on Facebook',
'#default_value' => TRUE,
);
}
}
}
}/**
* Implementation of hook_nodeapi().
*
* Publish to facebook Walls when users submit nodes.
*/
/*function fb_postwall_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($op == 'insert' || $op == 'update') {
if (isset($node->stream_publish) && $node->stream_publish) {
//dpm($node, "fb_postwall_nodeapi, publishing to stream");
// http://wiki.developers.facebook.com/index.php/Attachment_(Streams)
$attachment = array(
'name' => $node->title,
'href' => url('node/' . $node->nid, array('absolute' => TRUE)),
'description' => $node->teaser,
);
$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('user_message' => $user_message,
'attachment' => $attachment,
'action_links' => $actions,
));
}
}
}
*/
function fb_postwall_node_update($node) {
if (isset($node->stream_publish) && $node->stream_publish) {
$attachment = array(
'name' => $node->title,
'href' => url('node/' . $node->nid, array('absolute' => TRUE)),
// No more $node->content nor $node->teaser, but fields
'description' => filter_xss($node->body['und'][0]['value'], array()),
);
if ($logo_path = theme_get_setting('logo_path')) {
$url = url($logo_path, array('absolute' => TRUE));
$attachment['media'][] = array(
'type' => 'image',
'src' => $url,
'href' => $url,
);
}
$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('message' => $user_message,
'attachment' => $attachment,
'action_links' => $actions,
));
}
}
/**
* Implementation of hook_comment().
*
* Publish to facebook Walls when users submit comments.
*/
function fb_postwall_comment(&$a1, $op) {
if ($op == 'insert' || $op == 'update') {
if ($a1['stream_publish']) {
//dpm($a1, "fb_postwall_comment, publishing to stream");
$node = node_load($a1['nid']);
// http://wiki.developers.facebook.com/index.php/Attachment_(Streams)
$attachment = array(
'name' => $a1['subject'],
'href' => url('node/' . $a1['nid'], array('absolute' => TRUE, 'fragment' => 'comment-' . $a1['cid'])),
'description' => $a1['comment'],
'properties' => array(t('In reply to') => array('text' => $node->title, 'href' => url("node/" . $node->nid, array('absolute' => TRUE)))),
);
$user_message = t('Check out my latest comment 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/'.$a1['nid'], array('absolute' => TRUE)),
);
fb_stream_publish_dialog(array('user_message' => $user_message,
'attachment' => $attachment,
'action_links' => $actions,
));
}
}
}
?>Thanks.