Пример #1
0
function s_smarty_tpl($tpl, &$assign = false)
{
    if (!is_file($tpl) || !is_readable($tpl)) {
        return s_err_arg('no suce file of ' . $tpl);
    }
    $smarty = s_smarty_object();
    try {
        $smarty->assign($assign);
    } catch (SmartyException $se) {
    }
    return $smarty->fetch($tpl);
}
Пример #2
0
function s_smarty_tpl($tpl)
{
    if (!is_file($tpl) || !is_readable($tpl)) {
        return s_err_arg('no suce file of ' . $tpl);
    }
    $smarty = s_smarty_object();
    try {
        return $smarty->fetch($tpl);
    } catch (SmartyException $se) {
        return s_log($se->getMessage());
    }
}
Пример #3
0
function s_weibo_by_wid($wid)
{
    if (s_bad_id($wid)) {
        return s_err_arg();
    }
    $key = 'weibo_by_wid#' . $wid;
    if (false === ($data = s_memcache($key))) {
        if (false === ($data = s_weibo_http('https://api.weibo.com/2/statuses/show.json', array('id' => $wid)))) {
            return s_err_sdk();
        }
        //缓存
        s_memcache($key, $data);
    }
    return $data;
}
Пример #4
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;
}
Пример #5
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;
}
Пример #6
0
function s_weibo_by_wid($wid)
{
    if (s_bad_id($wid)) {
        return s_err_arg();
    }
    $key = 'weibo_by_wid#' . $wid;
    if (false === ($data = s_memcache($key))) {
        if (false === ($data = s_weibo_http('https://api.weibo.com/2/statuses/show.json', array('id' => $wid)))) {
            //有些微博会被删除,所以不提示
            return false;
        }
        //缓存24小时
        s_memcache($key, $data, 24 * 3600);
    }
    return $data;
}
Пример #7
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;
}
Пример #8
0
function &s_watermark(&$photo, &$watermark, $x = 0, $y = 0)
{
    if (s_bad_gd() || s_bad_string($photo) || s_bad_string($watermark)) {
        return s_err_arg();
    }
    //获取底板图片和水印图片
    if (false === ($plate = @imagecreatefromjpeg($photo)) || false === ($water = @imagecreatefrompng($watermark))) {
        return s_err_log('image error.');
    }
    //计算水平间隔
    //检查图片大小
    $p_w = imagesx($plate);
    $p_h = imagesy($plate);
    $w_w = imagesx($water);
    $w_h = imagesy($water);
    if ($p_w < $w_w || $p_h < $w_h) {
        //消毁对象
        imagedestroy($plate);
        imagedestroy($water);
        return s_err_log('water height or width more than plate');
    }
    //TODO: 使用临时目录
    $time = s_action_time();
    $path = '/tmp/';
    $path .= defined('APP_NAME') ? APP_NAME : date('Y-m-d', $time) . '_auto';
    if (!is_dir($path) && !mkdir($path, 0755, true)) {
        return false;
    }
    $file = $path . '/' . $time . '_' . rand(1, 10000) . '.jpg';
    //合并图片
    if (false === imagecopy($plate, $water, $p_w - $w_w, $p_h - $w_h, 0, 0, $w_w, $w_h) || false === imagejpeg($plate, $file)) {
        return s_err_log('unsuccess to {$file}.');
    }
    //消毁对象
    imagedestroy($plate);
    imagedestroy($water);
    //返回图片地址或者图片数据
    return $file;
}
Пример #9
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;
}
Пример #10
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);
}
Пример #11
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);
}
Пример #12
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;
}
Пример #13
0
function _s_user_friends($uid, $count = 200, $page = 1)
{
    if (s_bad_id($count) || s_bad_id($page)) {
        return s_err_arg();
    }
    if (!s_bad_id($uid)) {
        //微博ID
        $data['uid'] = $uid;
    } else {
        if (!s_bad_string($uid)) {
            //微博昵称
            $data['screen_name'] = $uid;
        }
    }
    $data['count'] = $count > 5000 ? 200 : $count;
    //游标从0开始
    $data['cursor'] = $page - 1;
    $key = "user_followers_by_uid#{$uid}_{$count}_{$page}";
    if (false !== ($users = s_memcache($key))) {
        return $users;
    }
    //缓存中没有,从微博平台中获取
    if (false === ($ret = s_weibo_http("https://api.weibo.com/2/friendships/followers.json", $data)) || s_bad_array($ret['users'])) {
        return false;
    }
    $users = s_user_sample($ret['users']);
    //缓存中存储起来
    s_memcache($key, $users);
    return $users;
}
Пример #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();
    }
    $prev = defined("APP_DB_PREFIX") ? APP_DB_PREFIX . "_" : "";
    $sql = "update `{$prev}{$table}` set `status`=-1 where `id`= {$v1}";
    return s_db_exec($sql);
}