View source
<?php
function shoutbox_user_menu() {
return array(
'shoutbox/user/%user' => array(
'title' => 'Shout box',
'page callback' => 'shoutbox_user_page',
'page arguments' => array(
2,
),
'access callback' => 'shoutbox_user_access',
'description' => 'A dedicated shoutbox page for group shouts.',
'type' => MENU_CALLBACK,
),
'shoutbox/user/%user/js/view' => array(
'title' => 'Shout tag',
'page callback' => 'shoutbox_user_js_view',
'page arguments' => array(
2,
),
'access callback' => 'shoutbox_user_access',
'description' => 'Javascript callback for viewing a user\'s shouts',
'type' => MENU_CALLBACK,
),
);
}
function shoutbox_user_page($user) {
drupal_set_title(t('!name\'s shout box', array(
'!name' => l($user->name, "user/{$user->uid}"),
)));
return shoutbox_view();
}
function shoutbox_user_access() {
if (user_access('view shouts') && user_access('access user profiles')) {
return TRUE;
}
return FALSE;
}
function shoutbox_user_shoutbox($op, &$shout, &$a1 = NULL, $form_state = NULL) {
switch ($op) {
case 'context':
if ($uid = shoutbox_user_get_current_uid()) {
$a1['shoutbox_user'] = $uid;
}
break;
case 'insert':
if ($uid = $form_state['values']['uid']) {
shoutbox_user_save($shout, $uid);
}
break;
case 'presave':
if ($uid = $form_state['values']['uid']) {
$shout->module = 'shoutbox_user';
}
case 'delete':
db_query("DELETE FROM {shoutbox_user} WHERE shout_id = %d", $shout->shout_id);
break;
case 'js path':
if ($uid = shoutbox_user_get_current_uid()) {
$a1 = "shoutbox/user/{$uid}/js/view/";
}
break;
case 'form':
if ($uid = shoutbox_user_get_current_uid()) {
$a1['uid'] = array(
'#type' => 'value',
'#value' => $uid,
);
}
break;
case 'link':
if ($uid = shoutbox_user_get_current_uid()) {
$a1 = "shoutbox/user/{$uid}";
}
break;
}
}
function shoutbox_user_db_rewrite_sql($query, $table, $primary, $contexts) {
if ($table == 'shoutbox' && isset($contexts['shoutbox_user'])) {
$query_mods['join'] = "INNER JOIN {shoutbox_user} shoutbox_user ON shoutbox.shout_id = shoutbox_user.shout_id\r\n";
$query_mods['where'] = "shoutbox_user.uid = " . (int) $contexts['shoutbox_user'];
return $query_mods;
}
}
function shoutbox_user_get_current_uid() {
if (arg(0) == 'user' && is_numeric(arg(1))) {
return arg(1);
}
else {
if (arg(0) == 'shoutbox' && arg(1) == 'user' && is_numeric(arg(2))) {
return arg(2);
}
}
return FALSE;
}
function shoutbox_user_save($shout, $user) {
$record = new stdClass();
$record->shout_id = $shout->shout_id;
$record->uid = is_object($user) ? $user->uid : $user;
drupal_write_record('shoutbox_user', $record);
}
function shoutbox_user_js_view($user) {
shoutbox_js_view();
}