示例#1
0
function DataIntervalsData()
{
    $cacheKey = 'dataintervalstable';
    if (($tr = MCGet($cacheKey)) !== false) {
        return $tr;
    }
    $db = DBConnect();
    $sql = <<<'EOF'
select t.house, t.lastupdate,
	t.mindelta, modes.delta as modedelta, t.avgdelta, t.maxdelta,
	r.region, group_concat(r.name order by 1 separator ', ') nms
from (
	select deltas.house, max(deltas.updated) lastupdate, round(min(delta)/5)*5 mindelta, round(avg(delta)/5)*5 avgdelta, round(max(delta)/5)*5 maxdelta
	from (
		select sn.updated,
			if(@prevhouse = sn.house and sn.updated > timestampadd(hour, -48, now()), unix_timestamp(sn.updated) - @prevdate, null) delta,
			@prevdate := unix_timestamp(sn.updated) updated_ts,
			@prevhouse := sn.house house
		from (select @prevhouse := null, @prevdate := null) setup, tblSnapshot sn
		order by sn.house, sn.updated) deltas
	group by deltas.house) t
left join (
	select house, delta
	from (
		select if(@prev = house, @rownum := @rownum + 1, @rownum := 0) o, delta, (@prev := house) as house, c
		from (
			select house, delta, count(*) c
			from (
				select sn.updated,
					round(if(@prevh = sn.house, unix_timestamp(sn.updated) - @prevd, null)/5)*5 delta,
					@prevd := unix_timestamp(sn.updated) updated_ts,
					@prevh := sn.house house
				from (select @prevh := null, @prevd := null) setup, tblSnapshot sn
				where sn.updated > timestampadd(hour, -48, now())
				order by sn.house, sn.updated) deltas
			where delta is not null
			group by house, delta
			order by house, c desc
		) tosort,
		(select @rownum := 0, @prev := null) setup) filtered
		where o=0
	) modes on modes.house = t.house
join tblRealm r on r.house = t.house and r.locale is not null
group by r.house
order by 4 asc, 3 asc, region asc, nms asc
EOF;
    $stmt = $db->prepare($sql);
    $stmt->execute();
    $result = $stmt->get_result();
    $tr = DBMapArray($result, null);
    $stmt->close();
    MCSet($cacheKey, $tr, 60);
    return $tr;
}
示例#2
0
function GetSellerList()
{
    $cacheKey = 'extra:multirealm:sellers';
    $sellers = MCGet($cacheKey);
    if ($sellers !== false) {
        return $sellers;
    }
    $sellers = [];
    $sql = <<<'EOF'
        select z2.sscnt, z2.itemcnt, s.name sellername, r.name realmname, s.firstseen, s.lastseen, r.house, r.slug
        from (
            select seller, count(distinct `snapshot`) sscnt, count(distinct item) itemcnt
            from (
                SELECT seller, item, `snapshot`
                FROM `tblSellerItemHistory` 
                where item in (128159, 127736, 127738, 127732, 127731, 127737, 127735, 127730, 127734, 127733, 127718, 128158, 127720, 127714, 127713, 127719, 127717, 127712, 127716, 127715)
            ) z1
            group by seller
            having (count(distinct item) = 2 or count(distinct item) > 3)
        ) z2
        left join tblSellerItemHistory h on h.seller = z2.seller and h.item not in (128159, 127736, 127738, 127732, 127731, 127737, 127735, 127730, 127734, 127733, 127718, 128158, 127720, 127714, 127713, 127719, 127717, 127712, 127716, 127715)
        join tblSeller s on s.id = z2.seller
        join tblRealm r on s.realm = r.id
        where h.seller is null
        and r.region = 'US'
        and s.firstseen > timestampadd(day, -14, now())
        and s.lastseen > timestampadd(hour, -36, now())
        order by r.house, s.firstseen, z2.sscnt desc, s.lastseen desc
EOF;
    $db = DBConnect();
    $db->query('set transaction isolation level read uncommitted, read only');
    $db->begin_transaction();
    $stmt = $db->prepare($sql);
    $stmt->execute();
    $result = $stmt->get_result();
    while ($row = $result->fetch_assoc()) {
        $sellers[$row['house']][] = $row;
    }
    $result->close();
    $stmt->close();
    $db->commit();
    // end transaction
    MCSet($cacheKey, $sellers);
    return $sellers;
}
示例#3
0
function GetBattleNetURL($region, $path)
{
    $region = trim(strtolower($region));
    if (substr($path, 0, 1) == '/') {
        $path = substr($path, 1);
    }
    $start = microtime(true);
    $finalUrl = '';
    while (!$finalUrl && $start + 5 > microtime(true)) {
        $cacheKey = 'BattleNetKeyUsage';
        if (!MCAdd($cacheKey . '_critical', 1, 5 * BATTLE_NET_REQUEST_PERIOD)) {
            usleep(50000);
            continue;
        }
        $apiHits = MCGet($cacheKey);
        if ($apiHits === false) {
            $apiHits = [];
        }
        $hitCount = count($apiHits);
        if ($hitCount >= BATTLE_NET_REQUEST_LIMIT) {
            $now = microtime(true);
            while ($apiHits[0] < $now && $now < $apiHits[0] + BATTLE_NET_REQUEST_PERIOD) {
                usleep(50000);
                $now = microtime(true);
            }
        }
        $apiHits[] = microtime(true);
        $hitCount++;
        if ($hitCount > BATTLE_NET_REQUEST_LIMIT) {
            array_splice($apiHits, 0, $hitCount - BATTLE_NET_REQUEST_LIMIT);
        }
        MCSet($cacheKey, $apiHits, 10 * BATTLE_NET_REQUEST_PERIOD);
        MCDelete($cacheKey . '_critical');
        $pattern = $region == 'cn' ? 'https://api.battlenet.com.%s/%s%sapikey=%s' : 'https://%s.api.battle.net/%s%sapikey=%s';
        $finalUrl = sprintf($pattern, $region, $path, strpos($path, '?') !== false ? '&' : '?', BATTLE_NET_KEY);
    }
    return $finalUrl ? $finalUrl : false;
}
示例#4
0
文件: incl.php 项目: erorus/newsstand
function APIMaintenance($when = -1, $expire = false)
{
    if (!function_exists('MCGet')) {
        DebugMessage('Tried to test for APIMaintenance without memcache loaded!', E_USER_ERROR);
    }
    $cacheKey = 'APIMaintenance';
    if ($when == -1) {
        return MCGet($cacheKey);
    }
    if ($when === false) {
        $when = 0;
    }
    if (!is_numeric($when)) {
        $when = strtotime($when);
    }
    if ($when) {
        if ($expire == false) {
            $expire = $when + 72 * 60 * 60;
        } elseif (!is_numeric($expire)) {
            $expire = strtotime($expire);
        }
        DebugMessage('Setting API maintenance mode, expected to end ' . TimeDiff($when) . ', maximum ' . TimeDiff($expire));
        MCSet($cacheKey, $when, $expire);
    } else {
        DebugMessage('Ending API maintenance mode.');
        MCDelete($cacheKey);
    }
    return $when;
}
示例#5
0
function GetRareWatches($loginState, $house = 0)
{
    $userId = $loginState['id'];
    $house = intval($house, 10);
    $limit = SUBSCRIPTION_RARE_LIMIT_TOTAL;
    if ($house) {
        $allWatches = GetRareWatches($loginState);
        $otherHouseCount = 0;
        foreach ($allWatches['watches'] as $watch) {
            if ($watch['house'] != $house) {
                $otherHouseCount++;
            }
        }
        $limit = min(SUBSCRIPTION_RARE_LIMIT_HOUSE, SUBSCRIPTION_RARE_LIMIT_TOTAL - $otherHouseCount);
    }
    $cacheKey = SUBSCRIPTION_RARE_CACHEKEY . $userId . '_' . $house;
    $json = MCGet($cacheKey);
    if ($json !== false) {
        return ['maximum' => $limit, 'watches' => $json];
    }
    $db = DBConnect();
    $sql = 'SELECT seq, house, itemclass, minquality, minlevel, maxlevel, flags & 1 as includecrafted, flags & 2 as includevendor, days from tblUserRare where user = ?';
    if ($house) {
        $sql .= ' and house = ?';
    }
    $stmt = $db->prepare($sql);
    if ($house) {
        $stmt->bind_param('ii', $userId, $house);
    } else {
        $stmt->bind_param('i', $userId);
    }
    $stmt->execute();
    $result = $stmt->get_result();
    $json = DBMapArray($result);
    $stmt->close();
    MCSet($cacheKey, $json);
    return ['maximum' => $limit, 'watches' => $json];
}
示例#6
0
function SendAndroidNotifications($regions)
{
    global $db;
    global $timeZones, $timeLeftCodes, $regionNames;
    $sent = [];
    $AndroidEndpoint = 'https://android.googleapis.com/gcm/send';
    foreach ($regions as $region) {
        $properRegion = strtoupper($region);
        if ($properRegion == 'US') {
            $properRegion = 'NA';
        }
        $sql = 'select * from tblWowToken w where region = ? order by `when` desc limit 2';
        $stmt = $db->prepare($sql);
        $stmt->bind_param('s', $region);
        $stmt->execute();
        $result = $stmt->get_result();
        $bothTokenData = DBMapArray($result, null);
        $tokenData = array_shift($bothTokenData);
        $prevTokenData = count($bothTokenData) ? array_shift($bothTokenData) : [];
        $stmt->close();
        if (!$prevTokenData) {
            continue;
        }
        if ($tokenData['marketgold'] == $prevTokenData['marketgold']) {
            continue;
        }
        if ($tokenData['result'] != 1 || $tokenData['result'] != $prevTokenData['result']) {
            continue;
        }
        $d = new DateTime('now', timezone_open($timeZones[$region]));
        $d->setTimestamp(strtotime($tokenData['when']));
        $formatted = ['BUY' => number_format($tokenData['marketgold']), 'TIMETOSELL' => isset($timeLeftCodes[$tokenData['timeleft']]) ? $timeLeftCodes[$tokenData['timeleft']] : $tokenData['timeleft'], 'UPDATED' => $d->format('M j g:ia T')];
        $direction = $tokenData['marketgold'] > $prevTokenData['marketgold'] ? 'over' : 'under';
        $sql = <<<EOF
select s.endpoint, s.id, e.region, e.value
from tblWowTokenSubs s
join tblWowTokenEvents e on e.subid = s.id
where s.lastfail is null
and e.direction = '{$direction}'
and e.region = '{$properRegion}'
and s.endpoint like '{$AndroidEndpoint}%'
EOF;
        if ($direction == 'over') {
            $sql .= ' and e.value >= ' . $prevTokenData['marketgold'] . ' and e.value < ' . $tokenData['marketgold'];
        } else {
            $sql .= ' and e.value <= ' . $prevTokenData['marketgold'] . ' and e.value > ' . $tokenData['marketgold'];
        }
        $stmt = $db->prepare($sql);
        $stmt->execute();
        $result = $stmt->get_result();
        $rows = DBMapArray($result, ['id']);
        $stmt->close();
        if (count($rows) == 0) {
            continue;
        }
        //sells in " . $formatted['TIMETOSELL'] . '
        $message = $regionNames[$properRegion] . ' price %s: now ' . $formatted['BUY'] . "g, as of " . $formatted['UPDATED'] . '.';
        $chunks = array_chunk($rows, 50, true);
        foreach ($chunks as $chunk) {
            $lookup = [];
            $toSend = [];
            $failed = [];
            $successful = [];
            foreach ($chunk as $id => $row) {
                $registrationId = substr($row['endpoint'], strlen($AndroidEndpoint) + 1);
                $msg = sprintf($message, $direction . ' ' . number_format($row['value'], 0) . 'g');
                $key = md5($row['endpoint']);
                if (!isset($sent[$key])) {
                    $lookup[] = $id;
                    $toSend[] = $registrationId;
                    $sent[$key] = $msg;
                } else {
                    $sent[$key] .= " \n" . $msg;
                }
                MCSet('tokennotify-' . $key, $sent[$key], 8 * 60 * 60);
            }
            if (!count($toSend)) {
                continue;
            }
            $toSend = json_encode(['registration_ids' => $toSend, 'time_to_live' => 4 * 60 * 60]);
            $headers = ['Authorization: key=' . ANDROID_GCM_KEY, 'Content-Type: application/json'];
            $outHeaders = [];
            $ret = \Newsstand\HTTP::Post($AndroidEndpoint, $toSend, $headers, $outHeaders);
            $ret = json_decode($ret, true);
            if (json_last_error() != JSON_ERROR_NONE || !isset($ret['results'])) {
                if (count($lookup) == 1 && isset($outHeaders['responseCode']) && $outHeaders['responseCode'] == '404') {
                    // only sent one, which failed, so mark it as failed
                    $successful = [];
                    $failed = $lookup;
                } else {
                    // can only assume all went through
                    DebugMessage("Bad response from {$AndroidEndpoint}\n" . print_r($headers, true) . $toSend . "\n" . print_r($outHeaders, true) . "\n{$ret}");
                    $successful = $lookup;
                    $failed = [];
                }
            } else {
                for ($x = 0; $x < count($ret['results']); $x++) {
                    if (isset($ret['results'][$x]['error'])) {
                        $failed[] = $lookup[$x];
                    } else {
                        $successful[] = $lookup[$x];
                    }
                }
            }
            $stmt = $db->prepare('update tblWowTokenEvents set lasttrigger=now() where subid in (' . implode(',', $lookup) . ') and region=\'' . $properRegion . '\' and direction=\'' . $direction . '\'');
            $stmt->execute();
            $stmt->close();
            if (count($successful)) {
                $stmt = $db->prepare('update tblWowTokenSubs set lastpush=now() where id in (' . implode(',', $successful) . ')');
                $stmt->execute();
                $stmt->close();
            }
            if (count($failed)) {
                $stmt = $db->prepare('update tblWowTokenSubs set lastpush=now(), lastfail=now() where id in (' . implode(',', $failed) . ')');
                $stmt->execute();
                $stmt->close();
            }
            DebugMessage('Sent ' . count($lookup) . ' messages to ' . $AndroidEndpoint . ' - ' . count($successful) . ' successful, ' . count($failed) . ' failed.');
        }
    }
}
示例#7
0
function PetGlobalNow($region, $species)
{
    global $db;
    $key = 'battlepet_globalnow2_' . $region . '_' . $species;
    if (($tr = MCGet($key)) !== false) {
        return $tr;
    }
    DBConnect();
    $sql = <<<EOF
    SELECT i.breed, r.house, i.price, i.quantity, unix_timestamp(i.lastseen) as lastseen
FROM `tblPetSummary` i
join tblRealm r on i.house = r.house and r.region = ?
WHERE i.species=?
group by i.breed, r.house
EOF;
    $stmt = $db->prepare($sql);
    $stmt->bind_param('si', $region, $species);
    $stmt->execute();
    $result = $stmt->get_result();
    $tr = DBMapArray($result, array('breed', null));
    $stmt->close();
    MCSet($key, $tr);
    return $tr;
}
示例#8
0
function CategoryRecipeMap($skill)
{
    $cacheKey = 'category_recipe_map2_' . $skill;
    $map = MCGet($cacheKey);
    if ($map !== false) {
        return $map;
    }
    $sql = <<<'EOF'
SELECT i.id recipe, s.crafteditem crafted
FROM `tblDBCItemSpell` dis
join tblDBCSpell s on dis.spell = s.id
join tblDBCItem i on dis.item = i.id
join tblDBCItem ii on ii.id = s.crafteditem
where s.skillline = ?
and i.auctionable = 1
and ii.auctionable = 1
EOF;
    $db = DBConnect();
    $stmt = $db->stmt_init();
    $stmt->prepare($sql);
    $stmt->bind_param('i', $skill);
    $stmt->execute();
    $result = $stmt->get_result();
    $map = $result->fetch_all(MYSQLI_ASSOC);
    $result->close();
    $stmt->close();
    MCSet($cacheKey, $map, 43200);
    return $map;
}
示例#9
0
function SearchItems($house, $search, $locale)
{
    global $db;
    $suffixes = MCGet('search_itemsuffixes_' . $locale);
    if ($suffixes === false) {
        $sql = <<<EOF
SELECT lower(suffix)
FROM tblDBCItemRandomSuffix
where locale='{$locale}'
union
select lower(ind.`desc_{$locale}`)
from tblDBCItemBonus ib
join tblDBCItemNameDescription ind on ind.id = ib.nameid
where ind.`desc_{$locale}` is not null
EOF;
        $stmt = $db->prepare($sql);
        $stmt->execute();
        $result = $stmt->get_result();
        $suffixes = DBMapArray($result, null);
        $stmt->close();
        MCSet('search_itemsuffixes_' . $locale, $suffixes, 86400);
    }
    $terms = preg_replace('/\\s+/', '%', " {$search} ");
    $nameSearch = "i.name_{$locale} like ?";
    $terms2 = '';
    $barewords = trim(preg_replace('/ {2,}/', ' ', preg_replace('/[^ a-zA-Z0-9\'\\.]/', '', $search)));
    for ($x = 0; $x < count($suffixes); $x++) {
        if (substr($barewords, -1 * strlen($suffixes[$x])) == $suffixes[$x]) {
            $terms2 = '%' . str_replace(' ', '%', substr($barewords, 0, -1 * strlen($suffixes[$x]) - 1)) . '%';
            $nameSearch = "(i.name_{$locale} like ? or i.name_{$locale} like ?)";
        }
    }
    $sql = <<<EOF
select results.*,
(select round(avg(case hours.h
        when  0 then ihh.silver00 when  1 then ihh.silver01 when  2 then ihh.silver02 when  3 then ihh.silver03
        when  4 then ihh.silver04 when  5 then ihh.silver05 when  6 then ihh.silver06 when  7 then ihh.silver07
        when  8 then ihh.silver08 when  9 then ihh.silver09 when 10 then ihh.silver10 when 11 then ihh.silver11
        when 12 then ihh.silver12 when 13 then ihh.silver13 when 14 then ihh.silver14 when 15 then ihh.silver15
        when 16 then ihh.silver16 when 17 then ihh.silver17 when 18 then ihh.silver18 when 19 then ihh.silver19
        when 20 then ihh.silver20 when 21 then ihh.silver21 when 22 then ihh.silver22 when 23 then ihh.silver23
        else null end) * 100)
        from tblItemHistoryHourly ihh,
        (select  0 h union select  1 h union select  2 h union select  3 h union
         select  4 h union select  5 h union select  6 h union select  7 h union
         select  8 h union select  9 h union select 10 h union select 11 h union
         select 12 h union select 13 h union select 14 h union select 15 h union
         select 16 h union select 17 h union select 18 h union select 19 h union
         select 20 h union select 21 h union select 22 h union select 23 h) hours
        where ihh.house = ? and ihh.item = results.id and ihh.bonusset = results.bonusset) avgprice,
ifnull(GROUP_CONCAT(bs.`tagid` ORDER BY 1 SEPARATOR '.'), '') tagurl,
ifnull((select concat_ws(':', nullif(bonus1,0), nullif(bonus2,0), nullif(bonus3,0), nullif(bonus4,0)) 
 FROM `tblItemBonusesSeen` ibs WHERE ibs.item=results.id and ibs.bonusset=results.bonusset order by ibs.observed desc limit 1),'') bonusurl
from (
    select i.id, i.quality, i.icon, i.class as classid, s.price, s.quantity, unix_timestamp(s.lastseen) lastseen,
    ifnull(s.bonusset,0) bonusset, i.level
    from tblDBCItem i
    left join tblItemSummary s on s.house=? and s.item=i.id
    where {$nameSearch}
    and (s.item is not null or ifnull(i.auctionable,1) = 1)
    group by i.id, ifnull(s.bonusset,0)
    limit ?
) results
left join tblBonusSet bs on results.bonusset = bs.`set`
group by results.id, results.bonusset
EOF;
    $limit = 50 * strlen(preg_replace('/\\s/', '', $search));
    $stmt = $db->prepare($sql);
    if ($terms2 == '') {
        $stmt->bind_param('iisi', $house, $house, $terms, $limit);
    } else {
        $stmt->bind_param('iissi', $house, $house, $terms, $terms2, $limit);
    }
    $stmt->execute();
    $result = $stmt->get_result();
    $tr = $result->fetch_all(MYSQLI_ASSOC);
    $stmt->close();
    return $tr;
}
示例#10
0
function SetHouseNextCheck($house, $nextCheck, $json)
{
    global $db;
    $stmt = $db->prepare('INSERT INTO tblHouseCheck (house, nextcheck, lastcheck, lastcheckresult) VALUES (?, from_unixtime(?), now(), ?) ON DUPLICATE KEY UPDATE nextcheck=values(nextcheck), lastcheck=values(lastcheck), lastcheckresult=values(lastcheckresult)');
    $stmt->bind_param('iis', $house, $nextCheck, $json);
    $stmt->execute();
    $stmt->close();
    MCSet('housecheck_' . $house, time(), 0);
}
示例#11
0
文件: item.php 项目: erorus/newsstand
function ItemGlobalMonthly($region, $item)
{
    global $db;
    $key = 'item_globalmonthly2_' . $region . '_' . $item;
    if (($tr = MCGet($key)) !== false) {
        return $tr;
    }
    DBConnect();
    $sqlCols = '';
    for ($x = 1; $x <= 31; $x++) {
        $padded = str_pad($x, 2, '0', STR_PAD_LEFT);
        $sqlCols .= ", round(avg(mktslvr{$padded})*100) mkt{$padded}, ifnull(sum(qty{$padded}),0) qty{$padded}";
    }
    $sql = <<<EOF
SELECT bonusset, month {$sqlCols}
FROM `tblItemHistoryMonthly` ihm
join tblRealm r on ihm.house = r.house and r.region = ? and r.canonical is not null
WHERE ihm.item=?
group by bonusset, month
EOF;
    $stmt = $db->prepare($sql);
    $stmt->bind_param('si', $region, $item);
    $stmt->execute();
    $result = $stmt->get_result();
    $bonusRows = DBMapArray($result, array('bonusset', null));
    $stmt->close();
    $tr = array();
    $today = strtotime(date('Y-m-d'));
    foreach ($bonusRows as $bonusSet => &$rows) {
        $prevPrice = 0;
        for ($x = 0; $x < count($rows); $x++) {
            $year = 2014 + floor(($rows[$x]['month'] - 1) / 12);
            $monthNum = $rows[$x]['month'] % 12;
            if ($monthNum == 0) {
                $monthNum = 12;
            }
            $month = ($monthNum < 10 ? '0' : '') . $monthNum;
            for ($dayNum = 1; $dayNum <= 31; $dayNum++) {
                $day = ($dayNum < 10 ? '0' : '') . $dayNum;
                if ($year == 2015 && $monthNum == 12 && ($dayNum >= 16 && $dayNum <= 22)) {
                    continue;
                }
                if (!is_null($rows[$x]['mkt' . $day])) {
                    $tr[$bonusSet][] = array('date' => "{$year}-{$month}-{$day}", 'silver' => round($rows[$x]['mkt' . $day] / 100, 2), 'quantity' => $rows[$x]['qty' . $day]);
                    $prevPrice = round($rows[$x]['mkt' . $day] / 100, 2);
                } else {
                    if (!checkdate($monthNum, $dayNum, $year)) {
                        break;
                    }
                    if (strtotime("{$year}-{$month}-{$day}") >= $today) {
                        break;
                    }
                    if ($prevPrice) {
                        $tr[$bonusSet][] = array('date' => "{$year}-{$month}-{$day}", 'silver' => $prevPrice, 'quantity' => 0);
                    }
                }
            }
        }
    }
    unset($rows);
    MCSet($key, $tr);
    return $tr;
}
示例#12
0
function CaptchaDetails()
{
    global $db;
    $cacheKey = 'captcha_' . $_SERVER['REMOTE_ADDR'];
    if (($details = MCGet($cacheKey)) !== false) {
        return $details['public'];
    }
    DBConnect();
    $races = array('bloodelf' => 10, 'draenei' => 11, 'dwarf' => 3, 'gnome' => 7, 'goblin' => 9, 'human' => 1, 'nightelf' => 4, 'orc' => 2, 'tauren' => 6, 'troll' => 8, 'undead' => 5);
    $raceExclude = array($races['bloodelf'] => array($races['nightelf']), $races['nightelf'] => array($races['bloodelf']));
    $keys = array_keys($races);
    $goodRace = $races[$keys[rand(0, count($keys) - 1)]];
    $howMany = rand(2, 3);
    $sql = 'SELECT * FROM tblCaptcha WHERE race = ? AND helm = 0 ORDER BY rand() LIMIT ?';
    $stmt = $db->prepare($sql);
    $stmt->bind_param('ii', $goodRace, $howMany);
    $stmt->execute();
    $result = $stmt->get_result();
    $goodRows = DBMapArray($result);
    $stmt->close();
    $sql = 'SELECT * FROM tblCaptcha WHERE race NOT IN (%s) ORDER BY rand() LIMIT %d';
    $exclude = array($goodRace);
    if (isset($raceExclude[$goodRace])) {
        $exclude = array_merge($exclude, $raceExclude[$goodRace]);
    }
    $sql = sprintf($sql, implode(',', $exclude), 12 - $howMany);
    $stmt = $db->prepare($sql);
    $stmt->execute();
    $result = $stmt->get_result();
    $badRows = DBMapArray($result);
    $stmt->close();
    $allRows = array_merge($goodRows, $badRows);
    shuffle($allRows);
    $details = array('answer' => '', 'public' => array('lookfor' => $goodRace, 'ids' => array()));
    for ($x = 0; $x < count($allRows); $x++) {
        if (isset($goodRows[$allRows[$x]['id']])) {
            $details['answer'] .= $x + 1;
        }
        $details['public']['ids'][] = $allRows[$x]['id'];
    }
    MCSet($cacheKey, $details);
    return $details['public'];
}
示例#13
0
function GetUserPaidUntil($userId)
{
    $cacheKey = SUBSCRIPTION_PAID_CACHEKEY . $userId;
    $ts = MCGet($cacheKey);
    if ($ts === false) {
        $db = DBConnect();
        $stmt = $db->prepare('SELECT ifnull(unix_timestamp(u.paiduntil),0) FROM tblUser u WHERE u.id=?');
        $stmt->bind_param('i', $userId);
        $stmt->execute();
        $stmt->bind_result($ts);
        if (!$stmt->fetch()) {
            $ts = 0;
        }
        $stmt->close();
        MCSet($cacheKey, $ts);
    }
    if (!$ts) {
        $ts = null;
    }
    return $ts;
}
示例#14
0
<?php

require_once __DIR__ . '/../incl/memcache.incl.php';
require_once __DIR__ . '/../incl/wowtoken-twitter.credentials.php';
header('Content-type: text/plain');
if (isset($_GET['newkey'])) {
    $oauth = new OAuth($twitterCredentials['consumerKey'], $twitterCredentials['consumerSecret']);
    $requestTokenInfo = $oauth->getRequestToken('https://api.twitter.com/oauth/request_token', 'https://wowtoken.info/twittertoken.php?callback=showkey');
    if (!empty($requestTokenInfo)) {
        MCSet('twittertoken-' . $requestTokenInfo['oauth_token'], $requestTokenInfo, 30 * 60);
        header('Location: https://api.twitter.com/oauth/authorize?oauth_token=' . rawurlencode($requestTokenInfo['oauth_token']));
    } else {
        echo 'No request token info.';
    }
}
if (isset($_GET['callback']) && $_GET['callback'] == 'showkey' && isset($_GET['oauth_token'])) {
    $requestTokenInfo['oauth_token'] = $_GET['oauth_token'];
    $verifier = $_GET['oauth_verifier'];
    $requestTokenInfo = MCGet('twittertoken-' . $requestTokenInfo['oauth_token']);
    if ($requestTokenInfo === false) {
        echo 'Could not find cached token';
        exit;
    }
    MCDelete('twittertoken-' . $requestTokenInfo['oauth_token']);
    $oauth = new OAuth($twitterCredentials['consumerKey'], $twitterCredentials['consumerSecret']);
    $oauth->setToken($requestTokenInfo['oauth_token'], $requestTokenInfo['oauth_token_secret']);
    $accessToken = $oauth->getAccessToken('https://api.twitter.com/oauth/access_token', '', $verifier);
    header('Content-type: text/plain');
    print_r($accessToken);
}