Exemplo n.º 1
0
<?php

require_once dirname(__FILE__) . '/../include/UserSvc.php';
$uc = new UserSvc();
$user = $uc->auth();
if (!$user || !$user['uname']) {
    die('Not login!');
}
require_once dirname(__FILE__) . '/../include/ChatSvc.php';
$all_contacts = array(array('name' => 'kf_1', 'unread' => 0), array('name' => 'kf_2', 'unread' => 1), array('name' => 'kf_3', 'unread' => 0));
$resp = array('errno' => 0, 'errmsg' => '', 'data' => array());
if ($_GET['type'] == 'all') {
    $uc = new UserSvc();
    $names = $uc->listUsers();
    $contacts = array();
    foreach ($names as $name) {
        $contacts[] = array('name' => $name, 'unread' => 0);
    }
    $resp['data'] = $contacts;
} else {
    $uid = $user['uname'];
    $svc = new ChatSvc();
    $uids = $svc->listRecentContacts($uid, 20);
    $recent_contacts = array();
    foreach ($uids as $uid) {
        $recent_contacts[] = array('name' => $uid, 'unread' => 0);
    }
    $resp['data'] = $recent_contacts;
}
#usort($resp['data'], 'sort_func');
echo json_encode($resp);
Exemplo n.º 2
0
<?php

require_once dirname(__FILE__) . '/../include/UserSvc.php';
$uc = new UserSvc();
$user = $uc->auth();
if (!$user || !$user['uname']) {
    die('Not login!');
}
require_once dirname(__FILE__) . '/../include/ChatSvc.php';
$resp = array('errno' => 0, 'errmsg' => '', 'data' => array());
$uid2 = $_REQUEST['uid2'];
$text = $_REQUEST['text'];
$uid2 = htmlspecialchars(trim($uid2));
$text = htmlspecialchars(trim($text));
if (!strlen($uid2) || strlen($uid2) > 32 || !strlen($text)) {
    $resp['errno'] = 1;
    $resp['errmsg'] = 'Bad parameter!';
} else {
    if (strlen($text) > 1000) {
        $resp['errno'] = 1;
        $resp['errmsg'] = 'content too long!';
    } else {
        $uid = $user['uname'];
        $svc = new ChatSvc();
        $msg = $svc->send($uid, $uid2, $text);
        $comet_msg = $msg;
        $comet_msg['time'] = date('Y-m-d H:i:s', $comet_msg['time']);
        comet_push($uid2, json_encode($comet_msg));
        $resp['data'] = $msg;
    }
}
Exemplo n.º 3
0
<?php

require_once dirname(__FILE__) . '/include/UserSvc.php';
$uc = new UserSvc();
if ($_GET['act'] == 'logout') {
    $uc->logout();
}
$errmsg = '';
if ($_POST) {
    $uname = trim($_POST['uname']);
    if (!preg_match('/^[0-9a-z_]+$/i', $uname)) {
        $errmsg = 'bad user name!';
    }
    if (!$errmsg) {
        $uc->login($uname, '');
        header('Location: ./');
        die;
    }
}
include dirname(__FILE__) . '/header.php';
?>

<?php 
if ($errmsg) {
    ?>
	<div style="color: #f00;">
		<?php 
    echo $errmsg;
    ?>
	</div>
<?php