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; }
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; }
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; }
function s_user_forward(&$wid, &$message = false, $reply = 0) { if (s_bad_id($wid) || s_bad_0id($reply)) { return false; } $data['id'] = $wid; $data['is_comment'] = $reply; if ($message !== false) { $data['status'] = $message; } return s_weibo_http('https://api.weibo.com/2/statuses/repost.json', $data, 'post'); }
function s_sql_select($sql, $from, $select = 0) { if (s_bad_string($sql, $sql) || s_bad_0id($select) || s_bad_id($from)) { return false; } $sql = substr($sql, $select += 6, $from - $select); $sql = str_replace(array("`", " "), "", $sql); $sql = explode(",", $sql); return count($sql) === 1 && $sql[0] === "*" ? "*" : $sql; }
function s_user_weibo_ids($uid, $type = 0, $since = 0, $max = 0) { if (s_bad_id($uid) || s_bad_0id($max) || s_bad_0id($since) || s_bad_0id($type)) { return false; } $page = 1; $ret = array(); while ($page > 0) { $key = 'user_weibo_forward_ids_by#' . 'uid=' . $uid . 'type=' . $type . 'since_id=' . $since . 'max_id=' . $max; if (false === ($data = s_memcache($key))) { $param = array('uid' => $uid, 'since_id' => $since_id, 'max_id' => $since_id, 'page' => $page, 'feature' => $type); //if ( false === ( $data = s_weibo_http("http://i2.api.weibo.com/2/statuses/user_timeline/ids.json", $data) )) { if (false === ($data = s_weibo_http("https://api.weibo.com/2/statuses/user_timeline/ids.json", $data))) { return false; } //缓存中存储30秒 s_memcache($key, $data, 30); } $ret = array_merge($ret, $data['statuses']); $page = $data['next_cursor']; } return $ret; }
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; }
function s_user_friends($uid, $page = 1, $size = 20, $sort = 0) { if (s_bad_id($uid) || s_bad_id($page) || s_bad_id($size) || s_bad_0id($sort)) { return false; } $data = array(); $data['uid'] = $uid; $data['page'] = $page; $data['count'] = $size; $data['sort'] = $sort; $key = "user_friends_by_uid#{$uid}_{$type}_{$sort}_{$page}_{$size}"; if (false === ($ret = s_memcache($key))) { if (false === ($ret = s_weibo_http("https://api.weibo.com/2/friendships/friends/bilateral.json", $data))) { return false; } //缓存中存储起来 s_memcache($key, $ret); } return $ret; }