You are here

function drupalchat_get_messages_specific in DrupalChat 6.2

Same name and namespace in other branches
  1. 7.2 drupalchat.module \drupalchat_get_messages_specific()
  2. 7 drupalchat.module \drupalchat_get_messages_specific()
1 string reference to 'drupalchat_get_messages_specific'
drupalchat_menu in ./drupalchat.module
Implementaiton of hook_menu()

File

./drupalchat.module, line 919
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 (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' => 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/', array(
          'Content-Type' => 'application/json',
        ), 'POST', $data, 15);
        $q = json_decode($result->data);
        $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%">' . $record->message . '</div></div>';
          }
          $oldname = $record->from_name;
        }
      }
      else {
        $result = db_query('SELECT u.name AS from_name,
          v.name AS to_name,
          m.uid1 AS uid1,
          m.uid2 AS uid2,
          m.message AS message,
          m.timestamp AS timestamp
          FROM {drupalchat_msg} m
          INNER JOIN drupalchat_users u
          ON (m.uid1 = u.uid AND u.uid!= 0)
          OR (u.uid = 0 AND m.uid1 = CONCAT(\'0-\', u.session))
          INNER JOIN drupalchat_users v
          ON (m.uid2 = v.uid AND v.uid!= 0)
          OR (v.uid = 0 AND m.uid2 = CONCAT(\'0-\', v.session))
          WHERE (((uid1 = \'%s\')
          AND (uid2 = \'%s\'))
          OR((uid1 = \'%s\') AND (uid2 = \'%s\')))', $guid, $id, $id, $guid);
        while ($record = db_fetch_object($result)) {
          $output .= '<div style="display:block;border-bottom: 1px solid #ccc; padding: 10px;"><div style="font-size:100%; display: inline; color: #3B5998;">' . $record->from_name . '</div><div style="float:right;color:#AAA; font-size: 70%;">' . format_date($record->timestamp, 'long') . '</div><div style="display: block; padding: 10px;">' . $record->message . '</div></div>';
        }
      }
      $output .= '';
    }
    return $output;
  }
}