You are here

function fb_example_node_insert in Drupal for Facebook 7.3

Implements hook_node_insert().

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

Code

function fb_example_node_insert($node) {
  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,
      ));

      //dpm($logo_path, "logo_path is $logo_path and url is $url");
      $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(
      'message' => $user_message,
      'attachment' => $attachment,
      'action_links' => $actions,
    ));
  }
}