foreach ($matches as $m) {
    rustart:
    echo "Loading RU " . $m . "\n";
    $json = @file_get_contents("https://ru.api.pvp.net/api/lol/ru/v2.2/match/" . $m . "?api_key=" . $api['key']);
    $json = json_decode($json, TRUE);
    if (getHTTP($http_response_header[0]) == 429) {
        echo "ERROR: 429 - Rate limit reached/exeeded. Waiting 10 seconds for limit reset.\n";
        sleep(10);
        goto rustart;
    } elseif (getHTTP($http_response_header[0]) == 403) {
        die("FATAL ERROR: 403 - blacklist?");
    } elseif (getHTTP($http_response_header[0]) == 401) {
        die("FATAL ERROR: 401 - Invalid or missing api key");
    } elseif (getHTTP($http_response_header[0]) == 404) {
        echo "ERROR: 404 - Match not found. Skipping...\n";
    } elseif (getHTTP($http_response_header[0]) == 503) {
        echo "ERROR: 503 - Service unavailable. This might be just a moment, retrying in 2 minutes.\n";
        sleep(120);
        goto rustart;
    } else {
        //MATCH ID
        //$m = match id
        //SERVER
        $server = $json['region'];
        foreach ($json['participants'] as $p) {
            //OTHER ITEMS RESET
            $other = 0;
            $otherap = 0;
            $appart = 0;
            //CHAMP PLAYED
            $champ = $p['championId'];
Example #2
0
function genThumbnail()
{
    // Make sure the parameters in the URL were generated by us.
    $sign = hash_hmac('sha256', $_GET['url'], $GLOBALS['salt']);
    if ($sign != $_GET['hmac']) {
        die('Naughty boy!');
    }
    // Let's see if we don't already have the image for this URL in the cache.
    $thumbname = hash('sha1', $_GET['url']) . '.jpg';
    if (is_file($GLOBALS['config']['CACHEDIR'] . '/' . $thumbname)) {
        // We have the thumbnail, just serve it:
        header('Content-Type: image/jpeg');
        echo file_get_contents($GLOBALS['config']['CACHEDIR'] . '/' . $thumbname);
        return;
    }
    // We may also serve a blank image (if service did not respond)
    $blankname = hash('sha1', $_GET['url']) . '.gif';
    if (is_file($GLOBALS['config']['CACHEDIR'] . '/' . $blankname)) {
        header('Content-Type: image/gif');
        echo file_get_contents($GLOBALS['config']['CACHEDIR'] . '/' . $blankname);
        return;
    }
    // Otherwise, generate the thumbnail.
    $url = $_GET['url'];
    $domain = parse_url($url, PHP_URL_HOST);
    if ($domain == 'flickr.com' || endsWith($domain, '.flickr.com')) {
        // Crude replacement to handle new flickr domain policy (They prefer www. now)
        $url = str_replace('http://flickr.com/', 'http://www.flickr.com/', $url);
        // Is this a link to an image, or to a flickr page ?
        $imageurl = '';
        if (endswith(parse_url($url, PHP_URL_PATH), '.jpg')) {
            // This is a direct link to an image. e.g. http://farm1.staticflickr.com/5/5921913_ac83ed27bd_o.jpg
            preg_match('!(http://farm\\d+\\.staticflickr\\.com/\\d+/\\d+_\\w+_)\\w.jpg!', $url, $matches);
            if (!empty($matches[1])) {
                $imageurl = $matches[1] . 'm.jpg';
            }
        } else {
            list($httpstatus, $headers, $data) = getHTTP($url, 20);
            // Get the flickr html page.
            if (strpos($httpstatus, '200 OK') !== false) {
                // flickr now nicely provides the URL of the thumbnail in each flickr page.
                preg_match('!<link rel=\\"image_src\\" href=\\"(.+?)\\"!', $data, $matches);
                if (!empty($matches[1])) {
                    $imageurl = $matches[1];
                }
                // In albums (and some other pages), the link rel="image_src" is not provided,
                // but flickr provides:
                // <meta property="og:image" content="http://farm4.staticflickr.com/3398/3239339068_25d13535ff_z.jpg" />
                if ($imageurl == '') {
                    preg_match('!<meta property=\\"og:image\\" content=\\"(.+?)\\"!', $data, $matches);
                    if (!empty($matches[1])) {
                        $imageurl = $matches[1];
                    }
                }
            }
        }
        if ($imageurl != '') {
            // Let's download the image.
            list($httpstatus, $headers, $data) = getHTTP($imageurl, 10);
            // Image is 240x120, so 10 seconds to download should be enough.
            if (strpos($httpstatus, '200 OK') !== false) {
                file_put_contents($GLOBALS['config']['CACHEDIR'] . '/' . $thumbname, $data);
                // Save image to cache.
                header('Content-Type: image/jpeg');
                echo $data;
                return;
            }
        }
    } elseif ($domain == 'vimeo.com') {
        // This is more complex: we have to perform a HTTP request, then parse the result.
        // Maybe we should deport this to JavaScript ? Example: http://stackoverflow.com/questions/1361149/get-img-thumbnails-from-vimeo/4285098#4285098
        $vid = substr(parse_url($url, PHP_URL_PATH), 1);
        list($httpstatus, $headers, $data) = getHTTP('https://vimeo.com/api/v2/video/' . escape($vid) . '.php', 5);
        if (strpos($httpstatus, '200 OK') !== false) {
            $t = unserialize($data);
            $imageurl = $t[0]['thumbnail_medium'];
            // Then we download the image and serve it to our client.
            list($httpstatus, $headers, $data) = getHTTP($imageurl, 10);
            if (strpos($httpstatus, '200 OK') !== false) {
                file_put_contents($GLOBALS['config']['CACHEDIR'] . '/' . $thumbname, $data);
                // Save image to cache.
                header('Content-Type: image/jpeg');
                echo $data;
                return;
            }
        }
    } elseif ($domain == 'ted.com' || endsWith($domain, '.ted.com')) {
        // The thumbnail for TED talks is located in the <link rel="image_src" [...]> tag on that page
        // http://www.ted.com/talks/mikko_hypponen_fighting_viruses_defending_the_net.html
        // <link rel="image_src" href="http://images.ted.com/images/ted/28bced335898ba54d4441809c5b1112ffaf36781_389x292.jpg" />
        list($httpstatus, $headers, $data) = getHTTP($url, 5);
        if (strpos($httpstatus, '200 OK') !== false) {
            // Extract the link to the thumbnail
            preg_match('!link rel="image_src" href="(http://images.ted.com/images/ted/.+_\\d+x\\d+\\.jpg)"!', $data, $matches);
            if (!empty($matches[1])) {
                // Let's download the image.
                $imageurl = $matches[1];
                list($httpstatus, $headers, $data) = getHTTP($imageurl, 20);
                // No control on image size, so wait long enough.
                if (strpos($httpstatus, '200 OK') !== false) {
                    $filepath = $GLOBALS['config']['CACHEDIR'] . '/' . $thumbname;
                    file_put_contents($filepath, $data);
                    // Save image to cache.
                    if (resizeImage($filepath)) {
                        header('Content-Type: image/jpeg');
                        echo file_get_contents($filepath);
                        return;
                    }
                }
            }
        }
    } elseif ($domain == 'xkcd.com' || endsWith($domain, '.xkcd.com')) {
        // There is no thumbnail available for xkcd comics, so download the whole image and resize it.
        // http://xkcd.com/327/
        // <img src="http://imgs.xkcd.com/comics/exploits_of_a_mom.png" title="<BLABLA>" alt="<BLABLA>" />
        list($httpstatus, $headers, $data) = getHTTP($url, 5);
        if (strpos($httpstatus, '200 OK') !== false) {
            // Extract the link to the thumbnail
            preg_match('!<img src="(http://imgs.xkcd.com/comics/.*)" title="[^s]!', $data, $matches);
            if (!empty($matches[1])) {
                // Let's download the image.
                $imageurl = $matches[1];
                list($httpstatus, $headers, $data) = getHTTP($imageurl, 20);
                // No control on image size, so wait long enough.
                if (strpos($httpstatus, '200 OK') !== false) {
                    $filepath = $GLOBALS['config']['CACHEDIR'] . '/' . $thumbname;
                    file_put_contents($filepath, $data);
                    // Save image to cache.
                    if (resizeImage($filepath)) {
                        header('Content-Type: image/jpeg');
                        echo file_get_contents($filepath);
                        return;
                    }
                }
            }
        }
    } else {
        // For all other domains, we try to download the image and make a thumbnail.
        list($httpstatus, $headers, $data) = getHTTP($url, 30);
        // We allow 30 seconds max to download (and downloads are limited to 4 Mb)
        if (strpos($httpstatus, '200 OK') !== false) {
            $filepath = $GLOBALS['config']['CACHEDIR'] . '/' . $thumbname;
            file_put_contents($filepath, $data);
            // Save image to cache.
            if (resizeImage($filepath)) {
                header('Content-Type: image/jpeg');
                echo file_get_contents($filepath);
                return;
            }
        }
    }
    // Otherwise, return an empty image (8x8 transparent gif)
    $blankgif = base64_decode('R0lGODlhCAAIAIAAAP///////yH5BAEKAAEALAAAAAAIAAgAAAIHjI+py+1dAAA7');
    file_put_contents($GLOBALS['config']['CACHEDIR'] . '/' . $blankname, $blankgif);
    // Also put something in cache so that this URL is not requested twice.
    header('Content-Type: image/gif');
    echo $blankgif;
}
Example #3
0
    session_start();
    $_SESSION['btUsername'] = $_COOKIE['btUsername'];
    $_SESSION['btPassword'] = $_COOKIE['btPassword'];
} else {
    session_start();
}
if (!isset($_SESSION['csrfKey'])) {
    $_SESSION['csrfKey'] = md5(uniqid());
}
include $prevFolder . "_config.php";
define("BASE_DIRECTORY", $BASE_DIRECTORY);
//define("BASE_DIRECTORY", str_replace("//", "/", $_SERVER['DOCUMENT_ROOT'].$MAIN_ROOT));
define("MAIN_ROOT", $MAIN_ROOT);
$PAGE_NAME = "";
include_once BASE_DIRECTORY . "_functions.php";
define("FULL_SITE_URL", getHTTP() . $_SERVER['SERVER_NAME'] . MAIN_ROOT);
$mysqli = new btmysql($dbhost, $dbuser, $dbpass, $dbname);
$mysqli->set_tablePrefix($dbprefix);
$mysqli->set_testingMode(true);
$logObj = new Basic($mysqli, "logs", "log_id");
// Get Clan Info
$webInfoObj = new WebsiteInfo($mysqli);
$webInfoObj->select(1);
$websiteInfo = $webInfoObj->get_info_filtered();
$CLAN_NAME = $websiteInfo['clanname'];
$THEME = $websiteInfo['theme'];
define("THEME", $THEME);
$arrWebsiteLogoURL = parse_url($websiteInfo['logourl']);
if (!isset($arrWebsiteLogoURL['scheme']) || $arrWebsiteLogoURL['scheme'] == "") {
    $websiteInfo['logourl'] = $MAIN_ROOT . "themes/" . $THEME . "/" . $websiteInfo['logourl'];
}