function drupalchat_get_messages_specific in DrupalChat 7.2
Same name and namespace in other branches
- 6.2 drupalchat.module \drupalchat_get_messages_specific()
- 7 drupalchat.module \drupalchat_get_messages_specific()
1 string reference to 'drupalchat_get_messages_specific'
- drupalchat_menu in ./
drupalchat.module - Implements hook_menu().
File
- ./
drupalchat.module, line 1165 - Module code for DrupalChat.
Code
function drupalchat_get_messages_specific($id = "1") {
if (!(user_access('access drupalchat own logs') || user_access('access drupalchat all logs'))) {
drupal_access_denied();
}
else {
global $user;
if ($user->uid > 0 || _drupalchat_get_sid() != -1) {
$guid = $user->uid ? $user->uid : '0-' . _drupalchat_get_sid();
$output = '';
if (check_plain(variable_get('drupalchat_polling_method', DRUPALCHAT_AJAX)) == DRUPALCHAT_COMMERCIAL) {
global $user;
if (!isset($_SESSION['drupalchat_switch_user'])) {
$_SESSION['drupalchat_switch_user'] = $user->uid ? $user->uid : '0-' . _drupalchat_get_sid();
}
$data = json_encode(array(
'uid1' => $_SESSION['drupalchat_switch_user'],
'uid2' => $id,
'api_key' => check_plain(variable_get('drupalchat_external_api_key', NULL)),
));
$options = array(
'method' => 'POST',
'data' => $data,
'timeout' => 15,
'headers' => array(
'Content-Type' => 'application/json',
),
);
$result = drupal_http_request(DRUPALCHAT_EXTERNAL_A_HOST . ':' . DRUPALCHAT_EXTERNAL_A_PORT . '/q/', $options);
$q = json_decode($result->data);
}
else {
$result = db_select('drupalchat_msg', 'm');
$result
->innerJoin('drupalchat_users', 'u', '(m.uid1 = u.uid AND u.uid!= 0) OR (u.uid = 0 AND m.uid1 = CONCAT(\'0-\', u.session))');
$result
->innerJoin('drupalchat_users', 'v', '(m.uid2 = v.uid AND v.uid!= 0) OR (v.uid = 0 AND m.uid2 = CONCAT(\'0-\', v.session))');
$result
->addField('u', 'name', 'from_name');
$result
->addField('v', 'name', 'to_name');
$result
->fields('m', array(
'uid1',
'uid2',
'message',
'timestamp',
));
$result
->condition(db_or()
->condition(db_and()
->condition('uid1', $guid)
->condition('uid2', $id))
->condition(db_and()
->condition('uid1', $id)
->condition('uid2', $guid)));
$q = $result
->execute();
}
$oldname = NULL;
foreach ($q as $record) {
if ($oldname == $record->from_name) {
$output .= '<div style="display: block; padding-top: 0%; padding-bottom: 0%;">' . $record->message . '</div>';
}
else {
$output .= '<div style="display:block;border-bottom: 1px solid #ccc; padding: 1% 0% 1% 0%;"></div><div style="display:block; padding-top: 1%; padding-bottom: 0%"><div style="font-size:100%; display: inline;"><a href="#">' . $record->from_name . '</a></div><div style="float:right;font-size: 70%;">' . format_date($record->timestamp, 'long') . '</div><div style="display: block; padding-top: 1%; padding-bottom: 0%">' . check_plain($record->message) . '</div></div>';
}
$oldname = $record->from_name;
}
$output .= '';
}
return filter_xss($ouput, array(
'a',
'div',
));
}
}