コード例 #1
0
ファイル: Menu.php プロジェクト: mflayhart/gw2tools
 /**
  * 
  * @param User $user
  * @return array
  */
 public function getItems(User $user = null)
 {
     if ($user === null) {
         return $this->items;
     }
     $items = [];
     foreach ($this->items as $item) {
         if ($item->getRight() == '' || $user->hasRight($item->getRight())) {
             $items[] = $item;
         }
     }
     return $this->trimSeparators($items);
 }
コード例 #2
0
ファイル: ModuleApi.php プロジェクト: mflayhart/gw2tools
 /**
  * 
  * @return ResponseJson
  */
 public function routeTokenCheck()
 {
     $data = [];
     try {
         $token = $this->getService()->getRequest()->get('token');
         if (empty($token)) {
             throw new InvalidTokenException('No token was provided.');
         } elseif (!preg_match('!^[A-F0-9-]{70,80}$!', $token)) {
             throw new InvalidTokenException('Invalid token.');
         }
         $user = User::findByToken($token);
         if (empty($user)) {
             $user = User::create($token);
         }
         $code = $user->getCode();
         $data['code'] = $code;
         $data['tokens'] = array_unique(array_merge(array_map(function (User $user) {
             return $user->getToken();
         }, $this->getCookieUsers(true)), [$token]));
     } catch (InvalidTokenException $e) {
         $data['error'] = $e->getMessage();
     } catch (MissingPermissionException $e) {
         $data['error'] = 'The token is missing "' . $e->getMessage() . '" permission.';
     }
     return new ResponseJson($data);
 }
コード例 #3
0
ファイル: Statistics.php プロジェクト: mflayhart/gw2tools
 /**
  * 
  * @return array
  */
 public function getDatasetUsers()
 {
     $cacheKey = 'percentile/users_connections/' . ($this->account ? $this->account->getName() : '');
     return $this->cacheGet($cacheKey, function () {
         $array = $this->cacheGet('rawpercentile/users_connections', function () {
             $conn = User::getConnection();
             $sql = "SELECT " . time() . " - `lastaccess` as n FROM `tokens` ORDER BY n";
             $array = [];
             foreach ($conn->query($sql) as $row) {
                 $array[] = floor($row['n'] / 86400);
             }
             return $array;
         }, 3600);
         return $this->doCalcPercentiles($array);
     }, 900);
 }
コード例 #4
0
<?php

/*
 * This file is part of the Arnapou FileStore package.
 *
 * (c) Arnaud Buathier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
include_once __DIR__ . '/../vendor/autoload.php';
Arnapou\GW2Tools\Service::getInstance();
use Arnapou\GW2Tools\User;
/*
 * STATISTICS
 */
foreach (User::getConnection()->query("SELECT * FROM `" . User::table() . "`") as $row) {
    try {
        $user = new User($row);
        $account = $user->checkAccount();
        if (empty($account)) {
            continue;
        }
        $account->calculateStatistics();
    } catch (\Exception $ex) {
        echo $user->getAccount()->getName() . " " . $ex->getMessage() . "\n";
    }
}
コード例 #5
0
ファイル: users-clean.php プロジェクト: mflayhart/gw2tools
<?php

/*
 * This file is part of the Arnapou FileStore package.
 *
 * (c) Arnaud Buathier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
include_once __DIR__ . '/../vendor/autoload.php';
Arnapou\GW2Tools\Service::getInstance();
use Arnapou\GW2Tools\User;
/*
 * DELETE OLD USERS
 */
$conn = User::getConnection();
// clean old non accessed codes / users : more than one year
$conn->executeDelete(User::table(), 'lastaccess < ' . (time() - 365 * 86400));
////
//// 2015-10-04
//// disabled because of some weird issues on the api when doing a lot of requests
//// I should look further before reactivating it
////
//foreach ($conn->query("SELECT * FROM `" . User::table() . "`") as $row) {
//    $user = new User($row);
//    $user->checkAccount(); // automatic delete if error with token
//}