function s_pagebar_detail($current, $total, $size = 20, $gap = 5)
{
    if (s_bad_id($current, $cuttent) || s_bad_id($total, $total) || s_bad_id($size, $size) || s_bad_id($gap, $gap)) {
        return false;
    }
    $diff = floor($gap / 2);
    $max = ceil($total / $size);
    $gap = $gap - 1;
    //检查当前页是否符合最小页或最大页
    if ($current < 1) {
        $current = 1;
    } else {
        if ($current > $max) {
            $current = $max;
        }
    }
    //从末尾处计算开始的页码。页码超出实际页面范围就需要重新计算起止页码
    if (($to = $current + $diff) > $max) {
        $to = $max;
        if (($from = $to - $gap) < 1) {
            $from = 1;
        }
    } else {
        if (($from = $to - $gap) < 1) {
            $from = 1;
            if (($to = $from + $gap) > $max) {
                $to = $max;
            }
        }
    }
    return array("current" => $current, "first" => 1, "last" => $max, "nums" => range($from, $to), "prev" => $current - 1 < 1 ? 1 : $current - 1, "next" => $current + 1 > $max ? $max : $current + 1);
}
function s_memcache_set($key, &$value, $time)
{
    if (s_bad_id($time) || s_bad_string($key) || false === ($cache = s_memcache_local())) {
        return false;
    }
    return $cache->set($key, $value, 0, $time);
}
function s_memcache_set($key, &$value, $time)
{
    if (s_bad_id($time) || s_bad_string($key) || false === ($cache = s_memcache_local())) {
        return false;
    }
    //return $cache->set($key, $value, MEMCACHE_COMPRESSED, $time);
    return $cache->set($key, $value, $time);
}
function s_memcache_set($key, &$value, $time)
{
    if (s_bad_id($time) || s_bad_string($key) || false === ($cache = s_memcache_local())) {
        return false;
    }
    $key = md5(MEM_CACHE_KEY_PREFIX . $key);
    //不做值存在检查,直接写
    return $cache->set($key, json_encode($value), $time);
}
Beispiel #5
0
function s_action_user($verify = true)
{
    //先从memcache中获取
    if (false === ($sso = new SSOCookie('cookie.conf')) || false === ($cookie = $sso->getCookie()) || s_bad_id($cookie['uniqueid'], $uniqueid)) {
        return false;
    }
    if ($verify === false) {
        return $cookie;
    }
    //需要从weibo平台中获取用户信息
    return s_user_by_uid($uniqueid);
}
Beispiel #6
0
function s_cookie_set($key, $val, $exp = 0, $path = "/", $secure = false)
{
    if (s_bad_string($key)) {
        return false;
    }
    if (s_bad_string($val)) {
        $val = strval($val);
    }
    if (s_bad_id($exp)) {
        $exp = false;
    }
    //return setrawcookie($key, $val);
    return setcookie($key, $val, $exp ? $exp + s_action_time() : false, $path, $secure);
}
Beispiel #7
0
function s_action_user($update = true)
{
    //先从memcache中获取
    if (false === ($sso = new SSOCookie('cookie.conf')) || false === ($cookie = $sso->getCookie()) || s_bad_id($cookie['uniqueid'], $uniqueid)) {
        return false;
    }
    //将cookie中的变量换成标准的uid, uname
    $cookie['uid'] = $cookie['uniqueid'];
    $cookie['uname'] = $cookie['screen_name'];
    if ($update === false) {
        return $cookie;
    }
    //需要从weibo平台中获取用户信息
    return s_user_by_uid($uniqueid);
}
Beispiel #8
0
function s_badge_new($uid, $bid, $username, $password)
{
    if (s_bad_id($uid) || s_bad_string($username) || s_bad_string($password)) {
        return s_err_arg();
    }
    $key = 'badge_new_by#' . $uid . $bid . $username . $password;
    if (false === ($data = s_memcache($key))) {
        $data = array('source' => APP_KEY, 'badge_id' => $bid, 'uids' => $uid, '_username' => $username, '_password' => $password);
        if ($data = s_badge_http('http://i2.api.weibo.com/2/proxy/badges/issue.json', $data, 'post')) {
            //缓存一小时
            s_memcache($key, $data, 3600);
        }
    }
    return $data;
}
Beispiel #9
0
function s_badge_new($uid, $bid, $username, $password)
{
    if (s_bad_id($uid) || s_bad_string($username) || s_bad_string($password)) {
        return s_err_arg();
    }
    $key = "badge_new_by#uid={$uid}&bid={$bid}&user={$username}&password={$password}";
    if (false === ($data = s_memcache($key))) {
        $data = array('badge_id' => $bid, 'uids' => $uid, '_username' => $username, '_password' => $password);
        if (false === ($data = s_badge_http('http://api.t.sina.com.cn/badges/app/issue.json?source=' . APP_KEY, $data, 'post'))) {
            return s_err_sdk();
        }
        //缓存一小时
        s_memcache($key, $data, 300);
    }
    return $data;
}
Beispiel #10
0
function s_badge_new($uid, $bid, $username, $password)
{
    if (s_bad_id($uid) || s_bad_string($username) || s_bad_string($password)) {
        return s_err_arg();
    }
    $key = "badge_new_by#uid={$uid}&bid={$bid}&user={$username}&password={$password}";
    if (false === ($data = s_memcache($key))) {
        $data = array('badge_id' => $bid, 'uids' => $uid, '_username' => $username, '_password' => $password);
        //if (false === ( $data = s_badge_http('http://api.weibo.com/2/proxy/badges/issue.json', $data, 'post') )) {
        if (false === ($data = s_badge_http('http://i2.api.weibo.com/2/proxy/badges/issue.json', $data, 'post'))) {
            return s_err_sdk();
        }
        //缓存五分钟
        s_memcache($key, $data, 300);
    }
    return $data;
}
Beispiel #11
0
function s_weibo_list_by_uid($uid, $page = 1, $count = 20)
{
    if (s_bad_id($uid) || s_bad_id($page) || s_bad_id($count) || $count > 200) {
        return false;
    }
    //看cache中是否存在
    $key = "weibo_list_by_uid#" . $uid . $page . $count;
    if (false === ($data = s_memcache($key))) {
        //缓存中没有,请求服务器
        $params = array("user_id" => $uid, "count" => $count, "page" => $page);
        if (false === ($data = s_weibo_http('http://api.t.sina.com.cn/statuses/user_timeline.json', $params))) {
            return false;
        }
        //缓存起来900秒(15分钟)
        //$mem->set($key, $data, 0, 900);
    }
    return $data;
}
Beispiel #12
0
function s_string_random($len = 32, $less = true)
{
    if (s_bad_id($len)) {
        $len = 32;
    }
    $len = 64;
    $token = '';
    $chars = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
    if (!$less) {
        $arr1 = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '~', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '=', '[', ']', ';', '/', '?');
        $chars = array_merge($chars, $arr1);
    }
    //打扰数组
    shuffle($chars);
    for ($i = 0, $l = count($chars); $i < $len; ++$i) {
        $output .= $chars[mt_rand(0, $l)];
    }
    return $output;
}
Beispiel #13
0
function s_action_user($update = true, $checkref = true)
{
    //检查referer
    if ($checkref === true) {
        if (false === ($ref = s_action_referer())) {
            //没有来源,有可能是非法请求或者是flash请求
            return false;
        }
        if (false === ($allows = function_exists('source_list'))) {
        }
    }
    //先从memcache中获取
    if (false === ($sso = new SSOCookie('cookie.conf')) || false === ($cookie = $sso->getCookie()) || s_bad_id($cookie['uniqueid'], $uniqueid)) {
        return false;
    }
    //将cookie中的变量换成标准的uid, uname
    $cookie['uid'] = $cookie['uniqueid'];
    $cookie['uname'] = $cookie['screen_name'];
    if ($update === false) {
        return $cookie;
    }
    //需要从weibo平台中获取用户信息
    return s_user_by_uid($uniqueid);
}
Beispiel #14
0
function _s_db_delete($table, $v1)
{
    if (s_bad_string($table, $table, true) || !($v1 = is_array($v1) && isset($v1["id"]) ? intval($v1["id"]) : $v1) || s_bad_id($v1)) {
        return s_err_arg();
    }
    if (defined("APP_DB_PREFIX")) {
        //替换表名:"%s_user:update" => "201204disney_user:update"
        $table = sprintf($table, APP_DB_PREFIX, true);
    }
    $sql = "update `{$table}` set `status`=-1 where `id`= {$v1}";
    return s_db_exec($sql);
}
Beispiel #15
0
function s_bad_get($key, &$var = false, $type = "string", $html = true)
{
    if (s_bad_string($key) || !isset($_GET[$key])) {
        return true;
    }
    if ($type === "string") {
        //字符类型
        if ($html !== true) {
            //不需要转义,直接返回判断结果
            return s_bad_string($_GET[$key], $var);
        }
        //需要对参数转义处理
        if (true === s_bad_string($_GET[$key], $var)) {
            //不需要转义,因为参数已经验证失败
            return true;
        }
        if ($var !== false) {
            $var = s_safe_html($var);
        }
        //验证成功,此处返回
        return false;
    } else {
        if ($type === "int") {
            //整型
            return s_bad_id($_GET[$key], $var);
        } else {
            if ($type === "int0") {
                return s_bad_0id($_GET[$key], $var);
            } else {
                if ($type === 'array') {
                    return s_bad_array($_GET[$key], $var);
                } else {
                    if ($type === "email") {
                        //邮箱
                        return s_bad_email($_GET[$key], $var);
                    } else {
                        if ($type === "phone" || $type === "telphone") {
                            //手机或电话(只需要验证telphone,因为telphone的规则很松已经包含手机了)
                            return s_bad_telphone($_GET[$key], $var);
                        } else {
                            if ($type === "mobile") {
                                //手机
                                return s_bad_mobile($_GET[$key], $var);
                            }
                        }
                    }
                }
            }
        }
    }
    return true;
}
Beispiel #16
0
function s_user_ship($uid)
{
    $data = array();
    if (!s_bad_id($uid)) {
        //微博ID
        $data['target_id'] = $uid;
    } else {
        if (!s_bad_string($uid)) {
            //微博昵称
            $data['target_screen_name'] = $uid;
        }
    }
    if (s_bad_array($data)) {
        return s_err_arg();
    }
    //2.0接口返回程序未被授权
    //return s_weibo_http("https://api.weibo.com/2/friendships/create.json", $data, "post");
    return s_weibo_http("http://api.t.sina.com.cn/friendships/show.json", $data);
}
Beispiel #17
0
function s_weibo_search($sid, $uid = false, $key = false, $page = 1, $size = 10, $istag = 0, $sort = 'time', $start = false, $end = false)
{
    if (s_bad_string($sid)) {
        return s_err_arg();
    }
    //看cache中是否存在
    $mkey = "weibo_search#" . 'uid=' . $uid . 'key=' . $key . 'page=' . $page . 'size=' . $size . 'istag=' . $istag . 'sort=' . $sort . 'start=' . $start . 'end=' . $end . 'sid=' . $sid;
    if (false === ($data = s_memcache($mkey))) {
        //缓存中没有,请求服务器
        $params = array('sid' => $sid, 'page' => $page, 'count' => $size);
        if (is_string($key)) {
            $params['q'] = $key;
        }
        if (!s_bad_0id($istag)) {
            $params['istag'] = $istag;
        }
        if (!s_bad_id($uid)) {
            $params['uid'] = $uid;
        }
        if (!s_bad_id($start)) {
            $params['starttime'] = $start;
        }
        if (!s_bad_id($end)) {
            $params['endtime'] = $end;
        }
        if (false === ($data = s_weibo_http('http://i2.api.weibo.com/2/search/statuses.json', $params))) {
            return false;
        }
        //缓存起来60秒
        s_memcache($mkey, $data, 60);
    }
    return $data;
}
Beispiel #18
0
    if (!s_bad_id($token)) {
        //是数字,当UID
        $data = s_user_by_uid($token);
    } else {
        if (!s_bad_string($token)) {
            echo 'null';
            //是字符,当username
            $data = s_user_by_nickname($token);
        }
    }
} else {
    if ($type === 'getWeiboDetail') {
        if (s_bad_post('token', $token)) {
            return s_action_error('require params: wid.');
        }
        if (!s_bad_id($token)) {
            //是数字,当WID
            $data = s_weibo_by_wid($token);
        } else {
            if (!s_bad_string($token)) {
                //是BASE64,当mid
                $data = s_weibo_by_mid($token);
            }
        }
    }
}
for ($i = 0; $i < 10; ++$i) {
    $weibo = "测试p/s, from ab, at:" . time() . " " . rand(1, 100000);
    s_user_post($weibo);
    $weibo = "测试p/s, from ab, at:" . time() . " " . rand(1, 100000);
    s_user_post($weibo);
Beispiel #19
0
function s_bad_get($key, &$var = false, $type = "string")
{
    if (s_bad_string($key) || !isset($_GET[$key])) {
        return true;
    }
    if ($type === "string") {
        //字符类型
        return s_bad_string($_GET[$key], $var);
    } else {
        if ($type === "int") {
            //整型
            return s_bad_id($_GET[$key], $var);
        } else {
            if ($type === "int0") {
                return s_bad_0id($_GET[$key], $var);
            } else {
                if ($type === "email") {
                    //邮箱
                    return s_bad_email($_GET[$key], $var);
                } else {
                    if ($type === "phone" || $type === "telphone") {
                        //手机或电话(只需要验证telphone,因为telphone的规则很松已经包含手机了)
                        return s_bad_telphone($_GET[$key], $var);
                    } else {
                        if ($type === "mobile") {
                            //手机
                            return s_bad_mobile($_GET[$key], $var);
                        }
                    }
                }
            }
        }
    }
    return true;
}
Beispiel #20
0
function s_user_message($uid, $message, $mid = false)
{
    if (s_bad_id($uid)) {
        return false;
    }
    if (s_bad_string($message)) {
        return false;
    }
    $data = array();
    $data['uid'] = $uid;
    $data['text'] = $message;
    if (is_int($mid)) {
        $data['id'] = $mid;
    }
    return s_weibo_http("http://i2.api.weibo.com/2/direct_messages/new.json", $data, 'post');
}
Beispiel #21
0
function s_weibo_forward_ids($wid, $since_id = 0, $max_id = 0)
{
    if (s_bad_id($wid) || s_bad_0id($max_id) || s_bad_0id($since_id)) {
        return false;
    }
    $page = 1;
    //当前页
    $size = 50;
    //每页数
    $ret = array();
    while ($page > 0) {
        //看cache中是否存在
        $mkey = "weibo_forward_ids#" . 'wid=' . $wid . 'page=' . $page . 'size=' . $size . 'max=' . $max_id . 'since=' . $since_id;
        if (false === ($data = s_memcache($mkey))) {
            //缓存中没有,请求服务器
            $params = array('id' => $wid, 'page' => $page, 'count' => $size, 'max_id' => $max_id, 'since_id' => $since_id);
            if (($data = s_weibo_http('https://api.weibo.com/2/statuses/repost_timeline/ids.json', $params)) && isset($data['statuses']) && count($data['statuses'])) {
                //缓存起来60秒
                s_memcache($mkey, $data, 60);
            }
        }
        if (isset($data['statuses']) && count($data['statuses'])) {
            //计算总页数
            $ret = array_merge($ret, $data['statuses']);
        }
        $page = intval($data['next_cursor']);
    }
    //返回整个微博转发列表的微博主键
    return $ret;
}
Beispiel #22
0
function _s_db_delete($table, $v1)
{
    if (s_bad_string($table, $table, true) || !($v1 = is_array($v1) && isset($v1["id"]) ? intval($v1["id"]) : $v1) || s_bad_id($v1)) {
        return s_err_arg();
    }
    $prev = defined("APP_DB_PREFIX") ? APP_DB_PREFIX . "_" : "";
    $sql = "update `{$prev}{$table}` set `status`=-1 where `id`= {$v1}";
    return s_db_exec($sql);
}
Beispiel #23
0
function s_sql_limit($sql, $limit)
{
    if (s_bad_string($sql) || s_bad_id($limit)) {
        return false;
    }
    $sql = substr($sql, $limit + 5);
    $sql = str_replace(" ", "", $sql);
    $sql = explode(",", $sql);
    return count($sql) === 1 ? array("0", $sql[0]) : $sql;
}
Beispiel #24
0
function s_live_now(&$user, $type = 1, $page = 1, $max = 10)
{
    if (s_bad_array($user) || s_bad_id($page) || s_bad_id($type)) {
        return s_err_arg();
    }
    $key = 'live_list_by#' . $page . $type . $max;
    if (false === ($data = s_memcache($key))) {
        $data = array('uid' => $user['uid'], 'type' => $type, 'page' => $page, 'pagesize' => $max);
        if (false === ($data = s_live_http('http://i.service.t.sina.com.cn/sapps/live/getlivelist.php', $data))) {
            return s_err_sdk();
        }
        //缓存60秒
        s_memcache($key, $data, 60);
    }
    return $data;
}
Beispiel #25
0
function s_user_follow($fuid)
{
    if (s_bad_id($fuid)) {
        return false;
    }
    $data = array("uid" => $fuid);
    //2.0接口返回程序未被授权
    //return s_weibo_http("https://api.weibo.com/2/friendships/create.json", $data, "post");
    return s_weibo_http("http://api.t.sina.com.cn/friendships/create/{$fuid}.json", $data, "post");
}