You are here

function fb_example_node_update in Drupal for Facebook 7.3

Implements hook_node_update().

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 104
Example customizations to modules/fb.

Code

function fb_example_node_update($node) {
  if (!empty($node->stream_publish)) {
    $teaser = node_view($node, 'teaser');
    $attachment = array(
      'name' => $node->title,
      'href' => url('node/' . $node->nid, array(
        'absolute' => TRUE,
      )),
      'description' => filter_xss($teaser['body'][0]['#markup'], 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,
      ));

      //dpm($logo_path, "logo_path is $logo_path and url is $url");
      $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,
    ));
  }
}