$client = new HttpClient($_IMC['imsvr'], $_IMC['impost']); $client->post('/presences/online', $data); $pageContents = $client->getContent(); //TODO: handle errors! $pageData = json_decode($pageContents); if ($client->status != "200" || empty($pageData->ticket)) { $ticket = ""; } else { $ticket = $pageData->ticket; } if (empty($ticket)) { //登录失败 echo '{status: "' . $client->status . '", "errorMsg":"' . $pageContents . '"}'; exit; } $buddy_online_ids = ids_array($pageData->buddies); //在线好友列表ids $clientnum = $pageData->clientnum; $rooms_num = $pageData->roominfo; if (is_object($rooms_num)) { foreach ($rooms_num as $key => $value) { $rooms[$key]['count'] = $value; } } $output = array(); $output['buddy_online_ids'] = join(",", $buddy_online_ids); $output['clientnum'] = $clientnum; $output['server_time'] = microtime(true) * 1000; $output['user'] = array('id' => $space['uid'], 'name' => to_utf8($name), 'pic_url' => avatar($space['uid'], 'small', true), 'status' => '', 'presence' => 'online', 'status_time' => '', 'url' => 'space.php?uid=' . $space['uid']); //用户信息 $imserver = 'http://' . $_IMC['imsvr'] . ':' . $_IMC['impoll'];
function find_history($ids) { global $_SGLOBAL, $_IMC, $space; $uid = $space['uid']; $histories = array(); $ids = ids_array($ids); if (empty($ids)) { return array(); } for ($i = 0; $i < count($ids); $i++) { $id = $ids[$i]; $list = array(); if ((int) $id < $_IMC['room_id_pre']) { $query = $_SGLOBAL['db']->query("SELECT * FROM " . im_tname('histories') . " WHERE (`to`='{$id}' and `from`='{$uid}' and fromdel=0) or (`to`='{$uid}' and `from`='{$id}' and todel=0 and send=1) ORDER BY timestamp DESC LIMIT 30"); while ($value = $_SGLOBAL['db']->fetch_array($query)) { array_unshift($list, array('to' => $value['to'], 'from' => $value['from'], 'style' => $value['style'], 'body' => to_utf8($value['body']), 'timestamp' => $value['timestamp'], 'type' => $value['type'], 'new' => 0)); } } else { $query = $_SGLOBAL['db']->query("SELECT main.*, s.username, s.name FROM " . im_tname('histories') . " main\n \tLEFT JOIN " . tname('space') . " s ON s.uid=main.from\n \t WHERE `to`='{$id}' ORDER BY timestamp DESC LIMIT 30"); while ($value = $_SGLOBAL['db']->fetch_array($query)) { $nick = nick($value); array_unshift($list, array('to' => $value['to'], 'nick' => to_utf8($nick), 'from' => $value['from'], 'style' => $value['style'], 'body' => to_utf8($value['body']), 'timestamp' => $value['timestamp'])); } } $histories[$id] = $list; } return $histories; }
<?php include_once "common.php"; $buddy_ids = ids_array(gp("buddy_ids")); $output_buddies = array(); $online_ids = array("4", "5", "6", 7, 8, 9, 10, 11, 12, 13); foreach ($buddies as $i => $b) { if (in_array($b["id"], $online_ids)) { $b["incomplete"] = true; } if (in_array($b["id"], $buddy_ids) || in_array($b["id"], $online_ids)) { array_push($output_buddies, $b); } } $output = array("success" => true, "server_time" => microtime(true) * 1000, "user" => $user, "connection" => $connection, "buddies" => $output_buddies, "rooms" => $rooms, "new_messages" => array(array("type" => "unicast", "to" => 1, "nick" => "Susan", "from" => 2, "style" => "", "body" => "Hello world.", "timestamp" => 1246883572400.0))); //if ( !gp("username") ){ // $output = array( // "success" => false, // "error_msg" => "Not Authorized" // ); //} echo callback($output);
if (is_null($v)) { $v = p($key); } if (is_null($v)) { $v = $def; } return $v; } function ids_array($ids) { return empty($ids) ? array() : (is_array($ids) ? array_unique($ids) : array_unique(explode(",", $ids))); } function ids_except($id, $ids) { if (in_array($id, $ids)) { array_splice($ids, array_search($id, $ids), 1); } return $ids; } function callback($data) { $data = json_encode($data); if (gp("callback")) { return gp("callback") . "({$data});"; } else { return $data; } } $id = gp("id"); $ids = ids_array(gp("ids"));