コード例 #1
0
ファイル: page.php プロジェクト: TwelveNights/anime-bracket
 public static final function render(array $params)
 {
     // Set some page default things
     Lib\Display::addKey('title', DEFAULT_TITLE);
     Lib\Display::setLayout('default');
     static::_initTemplateHelpers();
     Lib\Display::addKey('CSS_VERSION', CSS_VERSION);
     Lib\Display::addKey('JS_VERSION', JS_VERSION);
     Lib\Display::addKey('USE_MIN', USE_MIN);
     $user = Api\User::getCurrentUser();
     Lib\Display::addKey('user', $user);
     // If we have a user, seed the test bucket so that
     // random distribution is deterministic
     if ($user) {
         Lib\TestBucket::initialize($user->id);
     }
     // Kick off page specific rendering
     static::generate($params);
 }
コード例 #2
0
ファイル: vote.php プロジェクト: TwelveNights/anime-bracket
 public static function generate(array $params)
 {
     $user = self::_checkLogin();
     self::_enableAd();
     $perma = array_shift($params);
     $bracket = Api\Bracket::getBracketByPerma($perma);
     if ($bracket->start <= time() && ($bracket->state == BS_ELIMINATIONS || $bracket->state == BS_VOTING || $bracket->state == BS_WILDCARD)) {
         $cacheKey = 'CurrentRound_' . $bracket->id . '_' . $user->id;
         $out = Lib\Cache::fetch(function () use($user, $bracket) {
             $out = new stdClass();
             $out->userId = $user->id;
             $out->round = Api\Round::getCurrentRounds($bracket->id);
             $out->title = Api\Round::getBracketTitleForActiveRound($bracket);
             return $out;
         }, $cacheKey, CACHE_MEDIUM);
         if ($out) {
             $out->bracket = $bracket;
             $template = $out->bracket->state == BS_ELIMINATIONS ? 'eliminations' : 'voting';
             if ($bracket->state != BS_ELIMINATIONS) {
                 $entrantSwap = Lib\TestBucket::get('entrantSwap');
                 if ($entrantSwap !== 'control') {
                     foreach ($out->round as $round) {
                         // Interesting side effect that I had not considered before:
                         // When TestBucket initializes, it's setting the random seed for the entire RNG (duh).
                         // That means the following random line will produce a static set of results, so the
                         // user experience won't be wonky.
                         if ($entrantSwap === 'flip' || $entrantSwap === 'random' && rand() % 2 === 0) {
                             $round = self::_flipEntrants($round);
                         }
                     }
                 }
             }
             Lib\Display::addKey('page', 'vote');
             Lib\Display::addKey('title', $bracket->name . ' - Voting' . DEFAULT_TITLE_SUFFIX);
             Lib\Display::renderAndAddKey('content', $template, $out);
         }
     }
 }
コード例 #3
0
ファイル: page.php プロジェクト: kleitz/anime-bracket
 protected static function _checkLogin()
 {
     $user = Api\User::getCurrentUser();
     $readonly = Lib\Url::GetBool('readonly', null);
     if (!$user && !$readonly && stripos($_SERVER['HTTP_USER_AGENT'], 'google') === false) {
         header('Location: /user/login/?redirect=' . urlencode($_GET['q']));
         exit;
     }
     // Setup a default user if we're in readonly
     if (!$user) {
         $user = new stdClass();
         $user->id = 0;
     }
     // Seed the test bucket with the user's ID
     Lib\TestBucket::initialize($user->id);
     return $user;
 }