function fb_app_fb in Drupal for Facebook 6.2
Same name and namespace in other branches
- 5.2 fb_app.module \fb_app_fb()
- 5 fb_app.module \fb_app_fb()
- 6.3 fb_app.module \fb_app_fb()
- 7.3 fb_app.module \fb_app_fb()
Implementation of hook_fb().
File
- ./
fb_app.module, line 26 - Implementation of Drupal for Facebook application.
Code
function fb_app_fb($op, $data, &$return) {
$fb = isset($data['fb']) ? $data['fb'] : NULL;
$fb_app = isset($data['fb_app']) ? $data['fb_app'] : NULL;
if ($op == FB_OP_GET_APP) {
// Load app data, using the criteria passed in.
$args = array();
$where = array();
// This implementation uses 'label' as the unique id.
foreach (array(
FB_SETTINGS_CB,
FB_SETTINGS_LABEL,
) as $key) {
if (isset($data[$key]) && is_numeric($data[$key])) {
// DEPRECATED
// for backward compatibility we accept the nid, but that will go away in a later release!
$where[] = "(label = '%s' || nid = '%d')";
$args[] = $data[$key];
$args[] = $data[$key];
}
elseif (isset($data[$key])) {
// This is the right way, using label.
$where[] = "label = '%s'";
$args[] = $data[$key];
}
}
// We also support these ways to query an app.
foreach (array(
'fba_id' => '%d',
'apikey' => "'%s'",
'nid' => '%d',
) as $key => $type) {
if (isset($data[$key])) {
$where[] = "{$key} = {$type}";
$args[] = $data[$key];
}
}
// Status is a special query. Admin pages include disabled apps.
if (isset($data['status'])) {
$where[] = "status >= %d";
$args[] = $data['status'];
}
else {
$where[] = "status > 0";
}
if (count($args)) {
$fb_app = db_fetch_object(db_query("SELECT * FROM {fb_app} fba WHERE " . implode(' AND ', $where), $args));
}
if ($fb_app) {
$return = $fb_app;
}
}
elseif ($op == FB_OP_GET_ALL_APPS) {
// Return all known applications, including disabled.
$result = db_query("SELECT fba.* FROM {fb_app} fba");
while ($app = db_fetch_object($result)) {
$return[] = $app;
}
}
elseif ($op == FB_OP_POST_INIT) {
// Include our admin hooks.
if (fb_is_fb_admin_page()) {
require drupal_get_path('module', 'fb_app') . '/fb_app.admin.inc';
}
}
elseif ($op == FB_OP_CURRENT_APP) {
// Normally the current app is determined by fb_canvas or fb_connect, unless it is our event callback.
if (arg(0) == 'fb_app' && !$return) {
if (function_exists('fb_settings')) {
if (fb_settings(FB_SETTINGS_TYPE) == FB_SETTINGS_TYPE_CANVAS && ($apikey = fb_settings(FB_SETTINGS_APIKEY))) {
$return = fb_get_app(array(
'apikey' => $apikey,
));
}
}
}
}
}