You are here

function fb_example_comment in Drupal for Facebook 6.3

Implements hook_comment().

Publish to facebook Walls when users submit comments.

File

contrib/fb_example.module, line 134
Example customizations to modules/fb.

Code

function fb_example_comment(&$a1, $op) {
  if ($op == 'insert' || $op == 'update') {
    $comment_url = url('node/' . $a1['nid'], array(
      'absolute' => TRUE,
      'fragment' => 'comment-' . $a1['cid'],
    ));
    if ($a1['stream_publish']) {

      // $node = node_load($a1['nid']);
      // http://wiki.developers.facebook.com/index.php/Attachment_(Streams)
      $attachment = array(
        'name' => $a1['subject'],
        'href' => $comment_url,
        'description' => $a1['comment'],
      );
      if ($logo_path = theme_get_setting('logo_path')) {
        $url = url($logo_path, array(
          'absolute' => TRUE,
          'fb_canvas' => FALSE,
        ));
        $attachment['media'][] = array(
          'type' => 'image',
          'src' => $url,
          'href' => $url,
        );
      }
      $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(
        'message' => $user_message,
        'attachment' => $attachment,
        'action_links' => $actions,
      ));
    }
  }
}