function fb_friend_request_content in Drupal for Facebook 7.3
Same name and namespace in other branches
- 6.3 contrib/fb_friend.module \fb_friend_request_content()
Builds a data structure, similar to Drupal's form API structure, which renders a facebook request-form.
By default, hook_fb_friend will be invoked both when the user submits the invitation form and when their friends accept the invitation. (Default behavior can be overridden by passing parameters in $form_data.)
@TODO - better documentation here.
Parameters
$invite_data: Name-value pairs describing the invitation or request. Recommended to include:
- 'module': Not necessarily the name of a module, but identifies which module is responsible for this invite.
- 'ref_id': Node id or other drupal object. Along with 'module', identifies what the invitation is about.
$form_data: Name-value pairs used in building the request-form markup.
1 call to fb_friend_request_content()
- fb_friend_block in contrib/
fb_friend.module - Implementation of hook_block().
File
- contrib/
fb_friend.module, line 420 - This module implements several features specific to Facebook friend networks.
Code
function fb_friend_request_content($invite_data, $form_data) {
// defaults
$defaults = array(
'action_path' => fb_friend_request_submit_path($invite_data),
'action_text' => 'Invite',
'accept_path' => fb_friend_request_accept_path($invite_data),
'accept_text' => 'Accept',
'exclude_ids' => array(),
'text' => 'has invited you to <a href="!url">!title</a>.',
'title' => drupal_get_title(),
'type' => variable_get('site_name', t('page view')),
'invite' => FALSE,
'target' => '_top',
// _top helpful on canvas pages.
'hook' => NULL,
'ref_id' => NULL,
'module' => NULL,
'style' => NULL,
);
$params = array_merge($defaults, $form_data, $invite_data);
$submit_url = url($params['action_path'], array(
'absolute' => TRUE,
'fb_canvas' => FALSE,
));
// No canvas, http://forum.developers.facebook.net/viewtopic.php?pid=209230#p209230
$accept_url = url($params['accept_path'], array(
'absolute' => TRUE,
'fb_canvas' => fb_is_canvas(),
));
// Learn which users to exclude
$result = db_query("SELECT fbu_target FROM {fb_friend} WHERE module='%s' AND fbu_actor=%d AND ref_id=%d", $params['module'], fb_facebook_user(), $params['ref_id']);
while ($data = db_fetch_object($result)) {
$params['exclude_ids'][] = $data->fbu_target;
}
if (!$params['title']) {
$params['title'] = variable_get('site_name', $GLOBALS['_fb_app']->title);
}
//dpm($params['exclude_ids'], "exclude_ids"); // debug
// Build the alterable data structure.
// http://developers.facebook.com/docs/reference/fbml/request-form
$fbml = fb_form_requestform(array(
'type' => $params['type'],
'style' => $params['style'],
'content' => array(
'markup' => array(
'#value' => t($params['text'], array(
'!url' => $accept_url,
'!title' => t($params['title']),
)),
),
'choice' => array(
'#type' => 'fb_form_req_choice',
'#attributes' => array(
'url' => $accept_url,
'label' => t($params['accept_text']),
),
),
),
'invite' => $params['invite'],
'action' => $submit_url,
'method' => 'POST',
'target' => $params['target'],
));
$fbml['selector'] = fb_form_multi_selector(array(
'actiontext' => t($params['action_text']),
'target' => $params['target'],
'exclude_ids' => implode(',', $params['exclude_ids']),
));
// Change some of facebook's bizarre defaults.
foreach (array(
'cols',
'email_invite',
'import_external_friends',
) as $key) {
if (isset($params[$key])) {
$fbml['selector']['#attributes'][$key] = $params[$key];
}
}
// Allow third-party to modify the form
if ($params['hook']) {
drupal_alter($params['hook'], $fbml);
}
if ($fbml) {
// Wrap in serverfbml.
$xfbml = array(
'#type' => 'fb_form_serverfbml',
'fbml' => $fbml,
'#prefix' => '<div class="fb-request-form">',
'#suffix' => '</div>',
);
// Allow third-party to modify wrapper
if ($params['hook']) {
drupal_alter($params['hook'] . '_wrap', $xfbml);
}
return $xfbml;
}
}