@param string $region
@param int    $gameId

@return bool
760813
public function isGameExists($region, $gameId)
    {
        $metas = $this->buzz->get(sprintf($this->getUrl($region) . self::URL_META, $region, $gameId));

        // Check if game exists
        if ('HTTP/1.1 500 Internal Server Error' == $metas->getHeaders()[0]) {
            return false;
        }

        return true;
    }
1285884
public function fetch_profile($gamertag, $region)
    {
        $gamertag = trim($gamertag);
        $url = 'http://live.xbox.com/' . $region . '/Profile?gamertag=' . urlencode($gamertag);
        $key = $this->version . ':profile.' . $gamertag;

        $data = $this->__cache->fetch($key);
        if (!$data) {
            $data      = $this->fetch_url($url);
            $freshness = 'new';
            $this->__cache->store($key, $data, 3600);
        } else {
            $freshness = 'from cache';
        }

        if (stripos($data, '<section class="contextRail custom">')) {
            $user = array();
            $user['gamertag']                   = trim($gamertag);
            $user['tier']                       = (strpos($data, '<div class="goldBadge">') !== false) ? 'gold' : 'silver';
            $user['badges']['xboxlaunchteam']   = false;
            $user['badges']['nxelaunchteam']    = false;
            $user['badges']['kinectlaunchteam'] = false;
            $user['avatar']['full']             = 'http://avatar.xboxlive.com/avatar/' . $gamertag . '/avatar-body.png';
            $user['avatar']['small']            = 'http://avatar.xboxlive.com/avatar/' . $gamertag . '/avatarpic-s.png';
            $user['avatar']['large']            = 'http://avatar.xboxlive.com/avatar/' . $gamertag . '/avatarpic-l.png';
            $user['avatar']['tile']             = trim(str_replace('https://avatar-ssl', 'http://avatar', $this->find($data, '<img class="gamerpic" src="', '" alt="')));
            $user['gamerscore']                 = (int) trim($this->find($data, '<div class="gamerscore">', '</div>'));
            $user['reputation']                 = 0;
            $user['presence']                   = trim(str_replace("\r\n", ' - ', $this->find($data, '<div class="presence">', '</div>')));
            $user['online']                     = (bool)(strpos($user['presence'], 'Online') !== false && strpos($user['presence'], 'Online Status Unavailable') === false);
            $user['gamertag']                   = str_replace(array('&#39;s Profile', '\'s Profile'), '', trim($this->find($data, '<h1 class="pageTitle">', '</h1>')));
            $user['motto']                      = $this->clean(trim(strip_tags($this->find($data, '<div class="motto">', '</div>'))));
            $user['name']                       = trim(strip_tags($this->find($data, '<div class="name" title="', '">')));
            $user['location']                   = trim(strip_tags(str_replace('<label>Location:</label>', '', trim($this->find($data, '<div class="location">', '</div>')))));
            $user['biography']                  = trim(strip_tags(str_replace('<label>Bio:</label>', '', trim($this->find($data, '<div class="bio">', '</div>')))));

            $recentactivity = $this->fetch_games($gamertag, $region);
            if (is_array($recentactivity)) {
                $user['recentactivity'] = array_slice($recentactivity['games'], 0, 5, true);
            } else {
                $user['recentactivity'] = null;
            }

            if (strpos($data, '<div class="badges">') !== false) {
                if (strpos($data, 'xbox360Badge') !== false) {
                    $user['badges']['xboxlaunchteam'] = true;
                }
                if (strpos($data, 'nxeBadge') !== false) {
                    $user['badges']['nxelaunchteam'] = true;
                }
                if (strpos($data, 'kinectBadge') !== false) {
                    $user['badges']['kinectlaunchteam'] = true;
                }
            }

            $starvalue = array(
                'Empty'        => 0,
                'Quarter'      => 1,
                'Half'         => 2,
                'ThreeQuarter' => 3,
                'Full'         => 4,
            );

            preg_match_all('~<div class="Star (.*?)"></div>~si', $data, $reputation);
            foreach ($reputation[1] as $value) {
                $user['reputation'] = $user['reputation'] + $starvalue[$value];
            }

            $user['freshness'] = $freshness;

            return $user;
        } elseif (stripos($data, 'errorCode: \'404\'')) {
            $this->error = 501;

            return false;
        } else {
            $this->error = 500;
            $this->__cache->remove($key);
            $this->force_new_login();

            return false;
        }
    }
453378
public function createDirs($region, $gameId)
    {
        // Check if exists
        $replayDirPath = $this->getReplayDirPath($region, $gameId);
        if (is_dir($replayDirPath)) {
            throw new ReplayFolderAlreadyExistsException('The replay #' . $gameId . ' already exists');
        }

        // Create dirs for replay
        $permissions = 0755;
        mkdir($replayDirPath . '/chunks', $permissions, true);
        mkdir($replayDirPath . '/keyframes', $permissions, true);

        // Save decrypted file only in dev
        if ($this->options['replay.decoder.enable'] && $this->options['replay.decoder.save_files']) {
            mkdir($replayDirPath . '/keyframes.decoded', $permissions, true);
            mkdir($replayDirPath . '/chunks.decoded', $permissions, true);
        }
    }
1341113
public function regionFillField($field, $value, $region)
    {
        $field = $this->fixStepArgument($field);
        $value = $this->fixStepArgument($value);
        $regionObj = $this->getRegion($region);
        $regionObj->fillField($field, $value);
    }
275732
public function setRegion($region, $item)
    {
        if (is_array($item)) {
            $template = array_shift($item);
            $data = $item ? reset($item) : array();
            $content = $this->render($template, $data);
        } else {
            $content = trim($item);
        }

        if ($content !== '' && isset($this->templates["region_$region"])) {

            $weight = 1;

            if (isset($this->data["region_$region"])) {
                $weight = count($this->data["region_$region"]) + 1;
            }

            $this->data["region_$region"][] = array('rendered' => $content, 'weight' => $weight);
        }
    }
549227
public function downloadKeyframe($region, $gameId, $keyframeId)
    {
        try {
            $keyframe = $this->buzz->get(sprintf(
                $this->getUrl($region) . self::URL_KEYFRAME_DOWNLOAD,
                $region,
                $gameId,
                $keyframeId
            ));
        } catch (TimeoutException $e) {
            return false;
        } catch (RequestException $e) {
            return false;
        }

        // Check if game exists
        $header = $keyframe->getHeaders()[0];
        if ('HTTP/1.1 500 Internal Server Error' == $header || 'HTTP/1.1 404 Not Found' == $header) {
            return false;
        }

        return $keyframe->getContent();
    }
425134
public function getReplayDirPath($region, $gameId)
    {
        $stringGameId = (string) $gameId;

        return sprintf(
            '%s/%s/%s/%s/%s/%d',
            $this->path,
            $region,
            $stringGameId[0] . $stringGameId[1],
            $stringGameId[2],
            $stringGameId[3],
            $gameId
        );
    }
1166330
public String getUrl(String domain, String region) {
        if (url != null) {
            return url;
        }

        return urlFromUri(domain, region, uri);
    }
1357664
public function iClickOnTheLocalizedTextInRegion($text, $region){
        $text = $this->localizeTarget($text);
        $this->iClickOnTheTextInRegion($text, $region);
    }
529261
public function getKeyframeContent($region, $gameId, $keyframeId)
    {
        return file_get_contents($this->getKeyframePath($region, $gameId, $keyframeId));
    }
519816
public function getGameMode($gameModeId, $fields = ['name', 'slug', 'url'])
    {
        $apiUrl = $this->getEndpoint('game_modes');
        $apiUrl .= $gameModeId;

        $params = array(
            'fields' => implode(',', $fields)
        );

        $apiData = $this->apiGet($apiUrl, $params);

        return $this->decodeSingle($apiData);
    }
1235023
public function getChunkPath($region, $gameId, $chunkId)
    {
        $filePath = $this->getReplayDirPath($region, $gameId) . '/chunks/' . $chunkId;

        if (!is_file($filePath)) {
            throw new ReplayChunkNotFoundException('The chunk #' . $chunkId . ' is not found');
        }

        return $filePath;
    }
355374
public function fetch_games($gamertag, $region)
    {
        $gamertag  = trim($gamertag);
        $url       = 'https://live.xbox.com/' . $region . '/Activity';
        $key       = $this->version . ':games.' . $gamertag;
        $data      = $this->__cache->fetch($key);
        $freshness = 'from cache';

        if (!$data) {
            $data      = $this->fetch_url($url);
            $post_data = '__RequestVerificationToken=' . urlencode(trim($this->find($data, '<input name="__RequestVerificationToken" type="hidden" value="', '" />'))) . '&compareTo=' . urlencode($gamertag);
            $headers   = array('X-Requested-With: XMLHttpRequest', 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8');
            $data      = $this->fetch_url('https://live.xbox.com/' . $region . '/Activity/Summary?compareTo=' . urlencode($gamertag) . '&lc=1033', $url, 10, $post_data, $headers);
            $freshness = 'new';
            $this->__cache->store($key, $data, 3600);
        }

        $json = json_decode($data, true);

        if ($json['Success'] == 'true' && $json['Data']['Players'][0]['Gamertag'] != $this->account_gamertag) {
            $json                             = $json['Data'];
            $games                            = array();
            $games['gamertag']                = $g = $json['Players'][0]['Gamertag'];
            $games['gamerscore']['current']   = $json['Players'][0]['Gamerscore'];
            $games['gamerscore']['total']     = 0;
            $games['achievements']['current'] = 0;
            $games['achievements']['total']   = 0;
            $games['totalgames']              = $json['Players'][0]['GameCount'];
            $games['progress']                = $json['Players'][0]['PercentComplete'];

            $i = 0;
            foreach ($json['Games'] as $game) {
                if ($game['Progress'][$g]['LastPlayed'] !== 'null') {
                    $games['games'][$i]['id']                      = $game['Id'];
                    $games['games'][$i]['hid']                     = dechex($game['Id']);
                    $games['games'][$i]['isapp']                   = (bool)($game['PossibleScore'] == 0);
                    $games['games'][$i]['title']                   = $this->clean($game['Name']);
                    $games['games'][$i]['artwork']['small']        = 'http://download.xbox.com/content/images/66acd000-77fe-1000-9115-d802' . dechex($game['Id']) . '/1033/boxartsm.jpg';
                    $games['games'][$i]['artwork']['large']        = 'http://download.xbox.com/content/images/66acd000-77fe-1000-9115-d802' . dechex($game['Id']) . '/1033/boxartlg.jpg';
                    $games['games'][$i]['gamerscore']['current']   = $game['Progress'][$g]['Score'];
                    $games['games'][$i]['gamerscore']['total']     = $game['PossibleScore'];
                    $games['games'][$i]['achievements']['current'] = $game['Progress'][$g]['Achievements'];
                    $games['games'][$i]['achievements']['total']   = $game['PossibleAchievements'];
                    $games['games'][$i]['progress']                = 0;
                    $games['games'][$i]['lastplayed']              = (int)substr($game['Progress'][$g]['LastPlayed'], 6, 10);
                    $games['gamerscore']['total']                  = $games['gamerscore']['total'] + $games['games'][$i]['gamerscore']['total'];
                    $games['achievements']['current']              = $games['achievements']['current'] + $games['games'][$i]['achievements']['current'];
                    $games['achievements']['total']                = $games['achievements']['total'] + $games['games'][$i]['achievements']['total'];

                    if ($game['Progress'][$g]['Achievements'] !== 0) {
                        $games['games'][$i]['progress'] = round((($game['Progress'][$g]['Achievements'] / $game['PossibleAchievements']) * 100), 1);
                    }

                    $i++;
                }
            }

            $games['freshness'] = $freshness;
            return $games;
        } elseif ($json['Data']['Players'][0]['Gamertag'] == $this->account_gamertag) {
            $this->error = 501;
            return false;
        } else {
            $this->error = 500;
            $this->__cache->remove($key);
            $this->force_new_login();
            return false;
        }
    }
137517
public function isRegionInEditMode($region)
    {
        if ($site = $this->siteManager->getContext()) {
            return
                ($this->getPageContext()->isTemporary() && $this->isPageContextRegion($region, $site->theme)) ||
                ($this->getSiteContext()->isTemporary() && $this->isTransversalContextRegion($region, $site->theme))
            ;
        }
        return false;
    }
1086867
protected function regionUpdate(Layout $layout, Region $region)
    {
        if ($region->isUpdated()) {

            $this
                ->db
                ->delete('ucms_layout_data')
                ->condition('layout_id', $layout->getId())
                ->condition('region', $region->getName())
                ->execute()
            ;

            $values = [];

            /* @var $item Item */
            foreach ($region as $delta => $item) {
                $values[] = [
                    $layout->getId(),
                    $region->getName(),
                    $item->getNodeId(),
                    $delta,
                    $item->getViewMode(),
                ];
            }

            if (!empty($values)) {
                $q = $this->db->insert('ucms_layout_data');
                $q->fields(['layout_id', 'region', 'nid', 'weight', 'view_mode']);
                foreach ($values as $row) {
                    $q->values($row);
                }
                $q->execute();
            }

            // And create the node references

            $region->toggleUpdateStatus(false);

            return true;
        }

        return false;
    }
841801
public function attach($id, $dropletId, $regionSlug)
    {
        $data = [
            'type' => 'attach',
            'droplet_id' => $dropletId,
            'region' => $regionSlug,
        ];

        $action = $this->adapter->post(sprintf('%s/volumes/%s/actions', $this->endpoint, $id), $data);

        $action = json_decode($action);

        return new ActionEntity($action->action);
    }
168751
public function recentGame($gameId)
	{
		if ( ! isset($this->info['recentGames']))
		{
			// no rune pages
			return null;
		}
		$recentGames = $this->info['recentGames'];

		return $recentGames->game($gameId);
	}