コード例 #1
0
function wfUserSiteUnfollowsResponse($username, $servername)
{
    global $wgUser, $wgSitename, $wgServer, $wgHuijiPrefix;
    $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_UNKNOWN);
    // This feature is only available for logged-in users.
    if (!$wgUser->isLoggedIn()) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_NOT_LOGGED_IN);
        return $out;
    }
    // No need to allow blocked users to access this page, they could abuse it, y'know.
    if ($wgUser->isBlocked()) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_BLOCKED);
        return $out;
    }
    // Database operations require write mode
    if (wfReadOnly()) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_READ_ONLY);
        return $out;
    }
    // Are we even allowed to do this?
    if (!$wgUser->isAllowed('edit')) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_NOT_ALLOWED);
        return $out;
    }
    $usf = new UserSiteFollow();
    if ($username === $wgUser->getName()) {
        // && $servername === $wgServer
        if ($usf->deleteUserSiteFollow($wgUser, $servername)) {
            $out = ResponseGenerator::getJson(ResponseGenerator::SUCCESS);
        }
    }
    return $out;
}
コード例 #2
0
function wfUpdateUserStatus($username, $gender, $province, $city, $birthday, $status)
{
    global $wgUser;
    $city = trim($city);
    $status = trim($status);
    $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_UNKNOWN);
    // This feature is only available for logged-in users.
    if (!$wgUser->isLoggedIn()) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_NOT_LOGGED_IN);
        return $out;
    }
    // No need to allow blocked users to access this page, they could abuse it, y'know.
    if ($wgUser->isBlocked()) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_BLOCKED);
        return $out;
    }
    // Database operations require write mode
    if (wfReadOnly()) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_READ_ONLY);
        return $out;
    }
    // Are we even allowed to do this?
    if (!$wgUser->isAllowed('edit')) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_NOT_ALLOWED);
        return $out;
    }
    if ($username === $wgUser->getName()) {
        $us = new UserStatus($wgUser);
        if ($us->setAll($gender, $province, $city, $birthday, $status)) {
            $out = ResponseGenerator::getJson(ResponseGenerator::SUCCESS);
        }
    }
    return $out;
}
コード例 #3
0
function wfGetSiteFollowedUsers()
{
    global $wgUser, $wgHuijiPrefix;
    $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_UNKNOWN);
    // This feature is only available for logged-in users.
    if (!$wgUser->isLoggedIn()) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_NOT_LOGGED_IN);
        return $out;
    }
    $dateArr = array();
    for ($k = 1; $k < 31; $k++) {
        $dateArr[] = date('Y-m-d', strtotime("-{$k} day"));
    }
    $desdateArr = array_reverse($dateArr);
    $res['date'] = $desdateArr;
    foreach ($desdateArr as $key => $value) {
        $dayFollow = UserSiteFollow::getFollowerCountOneday($wgHuijiPrefix, $value);
        $dfol = (int) isset($dayFollow) ? $dayFollow : 0;
        $result[] = (int) $dfol;
    }
    $res['FollowCount'] = $result;
    if ($res) {
        $ret = array('success' => true, 'result' => $res);
        $out = json_encode($ret);
        return $out;
    }
}
コード例 #4
0
function wfUserUserUnfollowsResponse($follower, $followee)
{
    global $wgUser;
    $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_UNKNOWN);
    // This feature is only available for logged-in users.
    if (!$wgUser->isLoggedIn()) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_NOT_LOGGED_IN);
        return $out;
    }
    // No need to allow blocked users to access this page, they could abuse it, y'know.
    if ($wgUser->isBlocked()) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_BLOCKED);
        return $out;
    }
    // Database operations require write mode
    if (wfReadOnly()) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_READ_ONLY);
        return $out;
    }
    // Are we even allowed to do this?
    if (!$wgUser->isAllowed('edit')) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_NOT_ALLOWED);
        return $out;
    }
    $uuf = new UserUserFollow();
    if ($follower === $wgUser->getName() && $followee !== $follower) {
        if ($uuf->deleteUserUserFollow($wgUser, User::newFromName($followee))) {
            $out = ResponseGenerator::getJson(ResponseGenerator::SUCCESS);
        }
        //TODO: use wfMessage instead of hard code
    }
    return $out;
}
コード例 #5
0
function wfUpdateUserStatus($username, $field, $value)
{
    global $wgUser;
    // Sanitizer::escapeHtmlAllowEntities($html);
    $value = trim($value);
    $field = trim($field);
    $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_UNKNOWN);
    // This feature is only available for logged-in users.
    if (!$wgUser->isLoggedIn()) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_NOT_LOGGED_IN);
        return $out;
    }
    // No need to allow blocked users to access this page, they could abuse it, y'know.
    if ($wgUser->isBlocked()) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_BLOCKED);
        return $out;
    }
    // Database operations require write mode
    if (wfReadOnly()) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_READ_ONLY);
        return $out;
    }
    // Are we even allowed to do this?
    if (!$wgUser->isAllowed('edit')) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_NOT_ALLOWED);
        return $out;
    }
    if ($username === $wgUser->getName()) {
        $us = new UserStatus($wgUser);
        // if ($us->setAll($gender, $province, $city, $birthday, $status)){
        // 	$out = ResponseGenerator::getJson(ResponseGenerator::SUCCESS);
        // }
        if ($us->setInfo($field, $value)) {
            // $out = ResponseGenerator::getJson(ResponseGenerator::SUCCESS);
            $ret = array('success' => true, 'result' => $us->setInfo($field, $value));
            $out = json_encode($ret);
            return $out;
        }
    }
    return $out;
}
コード例 #6
0
function wfUserFollowsRecommend($follower, $followee)
{
    global $wgUser;
    $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_UNKNOWN);
    // This feature is only available for logged-in users.
    if (!$wgUser->isLoggedIn()) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_NOT_LOGGED_IN);
        return $out;
    }
    // No need to allow blocked users to access this page, they could abuse it, y'know.
    if ($wgUser->isBlocked()) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_BLOCKED);
        return $out;
    }
    // Database operations require write mode
    if (wfReadOnly()) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_READ_ONLY);
        return $out;
    }
    // Are we even allowed to do this?
    if (!$wgUser->isAllowed('edit')) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_NOT_ALLOWED);
        return $out;
    }
    $uuf = new UserUserFollow();
    if ($follower === $wgUser->getName() && $followee !== $follower) {
        if ($uuf->addUserUserFollow($wgUser, User::newFromName($followee)) !== false) {
            $weekRank = UserStats::getUserRank(20, 'week');
            $monthRank = UserStats::getUserRank(20, 'month');
            $totalRank = UserStats::getUserRank(20, 'total');
            if (count($weekRank) >= 8) {
                $recommend = $weekRank;
            } elseif (count($monthRank) >= 8) {
                $recommend = $monthRank;
            } else {
                $recommend = $totalRank;
            }
            $recommendRes = array();
            $flres = array();
            foreach ($recommend as $value) {
                $tuser = User::newFromName($value['user_name']);
                $isFollow = $uuf->checkUserUserFollow($wgUser, $tuser);
                if (!$isFollow && $value['user_name'] != $wgUser->getName()) {
                    $flres['avatar'] = $value['avatarImage'];
                    $flres['username'] = $value['user_name'];
                    $flres['userurl'] = $value['user_url'];
                    $recommendRes[] = $flres;
                }
            }
            $n = count($recommendRes);
            $i = 5;
            $newUser = isset($recommendRes[$i]) ? $recommendRes[$i] : null;
            $res = array('success' => true, 'result' => $newUser);
            $out = json_encode($res);
            return $out;
        }
    }
}