Ejemplo n.º 1
0
    protected function DELETE_submissions($rsc, $j)
    {
        global $config;
        global $phphw_common_json;
        $assignment = $rsc[1];
        $login = $j->login;
        $token = $j->token;
        $guard = new \PHPREST\DB\Guard($config['db']);
        $user = get_user_by_token($guard, $token, $login);
        if (!$user) {
            return $phphw_common_json['unauthorized'];
        }
        $submission = get_submission($guard, $user['id'], $assignment, TRUE);
        if (!$submission) {
            return $phphw_common_json['nonexist'];
        }
        $sql = <<<EOSQL
UPDATE {$guard->tables->submission}
SET deleted = TRUE
WHERE id = ?
EOSQL;
        $stmt = $guard->mysqli->prepare($sql);
        $stmt->bind_param('i', $submission['id']);
        $stmt->execute();
        $stmt->close();
        $guard->commit();
        return ['result' => 'OK', 'status' => '200', 'reason' => 'Success'];
    }
Ejemplo n.º 2
0
 protected function GET_download($rsc)
 {
     global $config;
     global $phphw_common_json;
     $assignment = $rsc[1];
     $guard = new \PHPREST\DB\Guard($config['db']);
     if (!isset($_GET['login']) || !isset($_GET['token'])) {
         return $phphw_common_json['field_missing'];
     }
     $login = $_GET['login'];
     $token = $_GET['token'];
     $user = get_user_by_token($guard, $token, $login);
     if (!$user) {
         return $phphw_common_json['unauthorized'];
     }
     $submission = get_submission($guard, $user['id'], $assignment);
     if (!$submission) {
         return $phphw_common_json['nonexist'];
     }
     $f = $this->open_file_by_digest($submission['digest']);
     if (!is_resource($f)) {
         return $phphw_common_json['server_error'];
     }
     $guard->commit();
     return (object) ['filename' => $submission['filename'], 'stream' => $f];
 }
Ejemplo n.º 3
0
 protected function GET_status($rsc, $j = NULL)
 {
     global $config;
     global $phphw_common_json;
     $assignment = $rsc[1];
     $guard = new \PHPREST\DB\Guard($config['db']);
     if (!isset($_GET['login']) || !isset($_GET['token'])) {
         return $phphw_common_json['field_missing'];
     }
     $login = $_GET['login'];
     $token = $_GET['token'];
     $user = get_user_by_token($guard, $token, $login);
     if (!$user) {
         return $phphw_common_json['unauthorized'];
     }
     $submission = get_submission($guard, $user['id'], $assignment);
     if (!$submission) {
         return $phphw_common_json['nonexist'];
     }
     $guard->commit();
     unset($submission['user']);
     unset($submission['assignment']);
     return ['result' => 'OK', 'status' => '200', 'reason' => 'OK', 'submission' => $submission];
 }
Ejemplo n.º 4
0
function s_users_by_uids(&$uids, $encoded = false)
{
    if (!s_bad_array($uids) || !($uids = array_unique($uids)) || !($uids = array_values($uids)) || empty($uids)) {
        return false;
    }
    //看cache中是否存在
    asort($uids);
    $mem = mem_cache_share();
    $key = md5(MEM_CACHE_KEY_PREFIX . "_user_by_uids_" . implode(",", $uids) . strval($encoded));
    if ($data = $mem->get($key)) {
        //缓存中已经存在
        $data = json_decode($data, true);
    }
    if (!$data) {
        //缓存中没有,请求服务器
        $max = 20;
        $time = 0;
        $times = ceil(count($uids) / $max);
        $list = array();
        do {
            $ids = array();
            $num0 = $time * $max;
            $num1 = ($time + 1) * $max - 1;
            foreach (range($num0, $num1) as $index) {
                if (!isset($uids[$index]) || intval($uids[$index]) <= 0) {
                    break;
                }
                $ids[] = $uids[$index];
            }
            $params = array("uids" => implode(",", $ids), "source" => APP_KEY, "cookie" => array("SUE" => $_COOKIE["SUE"], "SUP" => $_COOKIE["SUP"]));
            $data = s_http_get();
            $req = new HTTP_Request('http://i2.api.weibo.com/2/users/show_batch.json');
            $req->setMethod(HTTP_REQUEST_METHOD_GET);
            $req->addCookie("SUE", URLEncode($_COOKIE["SUE"]));
            $req->addCookie("SUP", URLEncode($_COOKIE["SUP"]));
            $req->addQueryString('uids', implode(",", $ids));
            $req->addQueryString('is_encoded', $encoded === false ? 0 : 1);
            $req->addQueryString('source', MBLOG_APP_KEY);
            $rs = $req->sendRequest();
            if (PEAR::isError($rs) || !($ret = json_decode($req->getResponseBody(), true)) || isset($ret["error_code"])) {
                return false;
            }
            //有可能是空数组
            if (isset($ret["users"])) {
                $list = array_merge($list, $ret["users"]);
            }
            unset($ret);
        } while (++$time < $times);
        $data = array();
        //重新组合成uid => array()
        foreach ($list as &$item) {
            if (isset($item["id"]) && $item["idstr"] > 0) {
                $data[$item["idstr"]] = $item;
            }
            unset($item);
        }
        //检查自己是否在数组中
        if (false !== ($me = login_user_info()) && ($meid = $me["uniqueid"]) && in_array($meid, $uids) && ($me = get_user_by_token(intval($meid)))) {
            $data[$me["id"]] = $me;
        }
        unset($list);
        //缓存十小时
        $mem->set($key, json_encode($data), 0, MEM_CACHE_LIFETIME_LUCKY);
    }
    return $data;
}