Exemple #1
0
function getMatchData($match_id, $api_key)
{
    $response = @file_get_contents("https://na.api.pvp.net/api/lol/na/v2.2/match/" . $match_id . "?" . "&api_key=" . $api_key);
    while (!$response) {
        $parsed_header = parseHeaders($http_response_header);
        if ($parsed_header['reponse_code'] == 429) {
            //if rate limit response
            sleep(1);
            //sleep 1 second while rate limit resets
        } else {
            break;
            //stop making requests
        }
        $response = @file_get_contents("https://na.api.pvp.net/api/lol/na/v2.2/match/" . $match_id . "?" . "&api_key=" . $api_key);
    }
    return $response;
}
 public function getSummoner($region, $name)
 {
     //$apiKey
     $url = "https://{$region}.api.pvp.net/api/lol/{$region}/v1.4/summoner/by-name/" . rawurlencode($name) . "?api_key=" . apiKey;
     $data = file_get_contents($url);
     //set response code
     Engine::$response = parseHeaders($http_response_header);
     // //if the API call was successfull (summoner found)
     if (Engine::$response['response_code'] == 200) {
         $data = json_decode($data);
         //Riot returns an object with Keys labeled by the name of who we are search. The name is made lowercase, and all spaces in the name get removed.
         $index = preg_replace('/\\s+/', '', $name);
         return $data->{$index};
     } else {
         //failed return error code instead of $data
         Engine::$errorFlag = true;
         return null;
     }
 }
Exemple #3
0
<?php

$thumbnails = array('Auto & Tires' => 'http://ll-us-i5.wal.co/dfw/4ff9c6c9-2965/k2-_65485dae-4250-457d-b629-20868cf04b7b.v1.jpg-70445cf97afad16b884881dfe42732b7861c77ad-webp-150x150.webp?odnWidth=144&odnHeight=144', 'Baby' => 'http://ll-us-i5.wal.co/dfw/4ff9c6c9-61a4/k2-_6a85a582-7832-4169-bde4-b96827458748.v1.jpg-77ec1920d9c2e9a80851d0286fe96da834095d18-webp-150x150.webp?odnWidth=144&odnHeight=144', 'Beauty' => 'http://ll-us-i5.wal.co/dfw/4ff9c6c9-bb4c/k2-_eee0bac8-88b4-4a0b-a024-35520d5893d7.v1.jpg-00b2f297c327ad0364d6e0243c2519f787440809-webp-150x150.webp?odnWidth=144&odnHeight=144', 'Books' => 'http://i5.walmartimages.com/dfw/4ff9c6c9-be1b/k2-_aa993008-01c5-4237-862a-734802ffbb54.v1.jpg?odnWidth=80&odnHeight=80', 'Cell Phones' => 'http://i5.walmartimages.com/dfw/dce07b8c-6962/k2-_1bed3037-71ac-4380-ac80-0cdd1c29c92e.v1.jpg?odnWidth=120&odnHeight=120', 'Clothing' => 'http://i5.walmartimages.com/dfw/4ff9c6c9-cbad/k2-_32151ba4-60b4-4ab6-acc9-313f43eb5346.v1.jpg?odnWidth=80&odnHeight=80', 'Electronics' => 'http://ll-us-i5.wal.co/dfw/4ff9c6c9-4542/k2-_cb52ae11-70a5-4a3c-809f-85912da9d059.v1.jpg-4665a6ca9ab9bbe8f797a762929ddaf99239d8b5-webp-150x150.webp?odnWidth=144&odnHeight=144', 'Food' => 'http://ll-us-i5.wal.co/dfw/4ff9c6c9-c6b6/k2-_de74cad1-eaf0-4eef-bc65-5f5f91ad6dea.v1.jpg-849aada07d177479dddb4d087cd3d16d3f2e0c75-webp-150x150.webp?odnWidth=144&odnHeight=144', 'Gifts & Registry' => 'http://i5.walmartimages.com/dfw/4ff9c6c9-1e61/k2-_86ae1317-d243-44f3-9385-beed0fb5130b.v1.png?odnWidth=144&odnHeight=144', 'Health' => 'http://ll-us-i5.wal.co/dfw/4ff9c6c9-4b4d/k2-_37e8b81a-78a2-46c0-bb9d-2948a1a1906a.v1.jpg-0e1ac1e8562ac6d3f53dcfc3964943cb273f45b7-webp-150x150.webp?odnWidth=144&odnHeight=144', 'Home' => 'http://ll-us-i5.wal.co/dfw/4ff9c6c9-273b/k2-_c973a848-0bd6-4e97-98ef-d2a6040d98c2.v1.jpg-95a32d15792bee6ad4a329a76267cc0c62859cb8-webp-150x150.webp?odnWidth=144&odnHeight=144', 'Home Improvement' => 'http://i5.walmartimages.com/dfw/4ff9c6c9-8f55/k2-_0ca58390-575b-4920-b65e-9b655ea31ac3.v1.jpg?odnWidth=144&odnHeight=144', 'Household Essentials' => 'http://ll-us-i5.wal.co/dfw/4ff9c6c9-abc2/k2-_a6492e32-b828-4ca0-ae2e-24ef574b5d72.v1.jpg-eb5aa098065c49b2973a62fe97f5cc876c264fa2-webp-150x150.webp?odnWidth=144&odnHeight=144', 'Jewelry' => 'http://i5.walmartimages.com/dfw/4ff9c6c9-f2bd/k2-_b2742a54-9653-4d3d-afea-0b1d5a409ee8.v1.jpg?odnWidth=80&odnHeight=80', 'Movies & TV' => 'http://i5.walmartimages.com/dfw/4ff9c6c9-7f35/k2-_b9a5ea5d-67e3-4e7d-b3b7-03bc9f06f54f.v1.jpg?odnWidth=80&odnHeight=80', 'Music' => 'http://i5.walmartimages.com/dfw/dce07b8c-93e8/k2-_be009ba5-ca1f-4818-af60-19d8cee972d2.v4.jpg?odnWidth=80&odnHeight=80', 'Office' => 'http://i5.walmartimages.com/dfw/4ff9c6c9-9cc6/k2-_de6cb858-b5e1-45cc-aa52-68bc74369bc0.v1.jpg?odnWidth=144&odnHeight=144', 'Party & Occasions' => 'http://i5.walmartimages.com/dfw/dce07b8c-659d/k2-_bfdb2550-0c41-47e8-8bd9-1f2ada3073b8.v1.jpg?odnWidth=120&odnHeight=120', 'Patio & Garden' => 'http://i5.walmartimages.com/dfw/4ff9c6c9-8806/k2-_8dc34db8-4ced-4953-85cb-11f77e75000d.v1.jpg?odnWidth=80&odnHeight=80', 'Pets' => 'http://ll-us-i5.wal.co/dfw/4ff9c6c9-aaeb/k2-_1f1bd387-6269-4e08-b061-40a6f2428fc1.v1.jpg-30c27c4f1f5f029a3b1454d24d13525d762d9535-webp-150x150.webp?odnWidth=144&odnHeight=144', 'Photo Center' => 'http://ll-us-i5.wal.co/dfw/4ff9c6c9-1249/k2-_099f7735-e39a-403f-8c52-8b06d2094503.v1.jpg-946aaf1f1ef04b606be2ba0dcce174d58550d99a-webp-150x150.webp?odnWidth=144&odnHeight=144', 'Seasonal' => 'http://ll-us-i5.wal.co/dfw/4ff9c6c9-dfc4/k2-_fc9b05d9-25a2-407d-ad46-7958eaa79c30.v1.png-06d81ce9393e938a6a147e1732549942e559b2a2-webp-144x144.webp?odnWidth=144&odnHeight=144', 'Sports & Outdoors' => 'http://i5.walmartimages.com/dfw/4ff9c6c9-9693/k2-_06678a16-7772-47e1-92f0-0f7962118f58.v1.jpg?odnWidth=80&odnHeight=80', 'Toys' => 'http://ll-us-i5.wal.co/dfw/4ff9c6c9-b8df/k2-_9a7eb983-30bb-4162-a05a-82fdad5cd8af.v1.jpg-7a34eb9a396bdbc1f9fcde748d5e0c49057b2873-webp-150x150.webp?odnWidth=144&odnHeight=144', 'Video Games' => 'http://ll-us-i5.wal.co/dfw/4ff9c6c9-a2dc/k2-_bee6da93-d76c-4ddd-8249-337aa1759089.v1.jpg-c8391dc6083388e2f6c3a48672a574d9de3815a0-webp-150x150.webp?odnWidth=144&odnHeight=144');
$query = urldecode($_SERVER['QUERY_STRING']);
$url = $thumbnails[$query];
$data = file_get_contents($url);
$res = parseHeaders($http_response_header);
header('Content-Type: ' . $res['Content-Type']);
echo $data;
function parseHeaders($headers)
{
    $head = array();
    foreach ($headers as $k => $v) {
        $t = explode(':', $v, 2);
        if (isset($t[1])) {
            $head[trim($t[0])] = trim($t[1]);
        } else {
            $head[] = $v;
            if (preg_match("#HTTP/[0-9\\.]+\\s+([0-9]+)#", $v, $out)) {
                $head['code'] = intval($out[1]);
            }
        }
    }
    return $head;
}
function fetch_images($urls)
{
    $images_pack = array('images' => array(), 'fileNames' => array(), 'count' => 0);
    $valid_status = array(200, 301, 304);
    foreach ($urls as $url) {
        $image_str = @file_get_contents($url);
        if ($image_str === false) {
            continue;
        }
        $status = parseHeaders($http_response_header, 'status');
        $fetched = in_array($status, $valid_status);
        if ($fetched) {
            $images_pack['images'][] = $image_str;
            $images_pack['fileNames'][] = basename($url);
            $images_pack['count']++;
        }
    }
    return $images_pack;
}
Exemple #5
0
/**
 * get images raw strings
 * @param $arrImagesUrls
 * @return array
 */
function fetchImages($arrImagesUrls)
{
    $arrReturn = array('imageStrings' => array(), 'validImagesUrls' => array());
    $arrValidStatus = array(200, 301, 304);
    foreach ($arrImagesUrls as $strImageUrl) {
        $strImageString = @file_get_contents($strImageUrl);
        if ($strImageString === false) {
            continue;
        }
        $intHttpStatus = parseHeaders($http_response_header, 'status');
        $boolFetchSuccess = in_array($intHttpStatus, $arrValidStatus);
        if ($boolFetchSuccess) {
            $arrReturn['imageStrings'][] = $strImageString;
            $arrReturn['validImagesUrls'][] = $strImageUrl;
        }
    }
    return $arrReturn;
}
Exemple #6
0
function getCookie($targetUrl, $data)
{
    $data = http_build_query($data);
    $opts = array('http' => array('method' => 'POST', 'max_redirects' => '10', 'content' => $data));
    if ($headers) {
        $opts['http']['header'] = $headers;
    }
    $st = stream_context_create($opts);
    $fp = fopen($targetUrl, 'rb', false, $st);
    if (!$fp) {
        return false;
    }
    $headers = parseHeaders($http_response_header);
    if (isset($headers["Set-Cookie"])) {
        return array(cookie => $headers["Set-Cookie"], redirect => $headers["Location"]);
    } else {
        return null;
    }
}
Exemple #7
0
function copyFileAndGetHeaders($url, $path, $timeout = 0, $useragent = null)
{
    $chan = curl_init();
    curl_setopt($chan, CURLOPT_URL, $url);
    curl_setopt($chan, CURLOPT_HEADER, 1);
    curl_setopt($chan, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($chan, CURLOPT_RETURNTRANSFER, 1);
    //curl_setopt($chan, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($chan, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($chan, CURLOPT_CONNECTTIMEOUT, $timeout);
    if ($useragent) {
        curl_setopt($chan, CURLOPT_USERAGENT, $useragent);
    }
    $data = curl_exec($chan);
    $httpcode = curl_getinfo($chan, CURLINFO_HTTP_CODE);
    if ($httpcode >= 400) {
        return array();
    }
    $headersLen = curl_getinfo($chan, CURLINFO_HEADER_SIZE);
    curl_close($chan);
    $headers = substr($data, 0, $headersLen);
    // what about UTF8??
    $body = substr($data, $headersLen);
    file_put_contents($path, $body);
    return parseHeaders($headers);
}
function fetchEnrollments($course_id = False)
{
    if (!$course_id) {
        return array();
    }
    # Build the API endpoint for fetching the list of students
    $enrollment_params = array("page=1", 'per_page=50');
    $enrollment_params_string = implode('&', $enrollment_params);
    $enrollments_endpoint = sprintf(BASE_URL, sprintf('/courses/%d/enrollments?%s', $course_id, $enrollment_params_string));
    # Initiate cURL, adding the REQUEST_HEADERS to it for authentication
    $ch = curlhandler($enrollments_endpoint, true);
    # Execute the request
    # Fetch the response,
    $enrollment_list = curl_exec($ch);
    if (!$enrollment_list) {
        print 'error fetching student list';
    } else {
        # Strip extra whitespace from the beginning and end then parse response into JSON
        list($header_string, $enrollment_list) = explode("\r\n\r\n", $enrollment_list, 2);
        $enrollment_list = trim($enrollment_list);
        $enrollment_list_2 = json_decode($enrollment_list, true);
        #print_r($enrollment_list_2);
    }
    $headers = parseHeaders($header_string);
    $links = parseLinks($headers['Link']);
    if ($links == false) {
        $enrollment_results = $enrollment_list_2;
    } else {
        //print_r($links);
        $curl_handlers = array();
        $mh = curl_multi_init();
        for ($x = 0; $x < (int) $links['num_pages']; $x++) {
            # Initiate cURL, adding the REQUEST_HEADERS to it for authentication
            $enrollment_params = array("page={$x}", 'per_page=' . $links['per_page']);
            $enrollment_params_string = implode('&', $enrollment_params);
            // Set url
            $rep_enrollments_endpoint = sprintf(BASE_URL, sprintf('/courses/%d/enrollments?%s', $course_id, $enrollment_params_string));
            $curl_handlers[$x] = curlHandler($rep_enrollments_endpoint);
            curl_multi_add_handle($mh, $curl_handlers[$x]);
        }
        do {
            $mrc = curl_multi_exec($mh, $active);
        } while ($mrc == CURLM_CALL_MULTI_PERFORM);
        while ($active && $mrc == CURLM_OK) {
            if (curl_multi_select($mh) != -1) {
                do {
                    $mrc = curl_multi_exec($mh, $active);
                } while ($mrc == CURLM_CALL_MULTI_PERFORM);
            }
        }
        $enrollment_results = array();
        for ($i = 0; $i < (int) $links['num_pages']; $i++) {
            $content = curl_multi_getcontent($curl_handlers[$i]);
            $json_response = json_decode($content, true);
            if ($json_response) {
                $enrollment_results = array_merge($enrollment_results, $json_response);
            }
            curl_multi_remove_handle($mh, $curl_handlers[$i]);
        }
        curl_multi_close($mh);
    }
    return $enrollment_results;
}
Exemple #9
0
function UCloud_Client_Do($req)
{
    $ch = curl_init();
    $url = $req->URL;
    $options = array(CURLOPT_USERAGENT => $req->UA, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_HEADER => true, CURLOPT_NOBODY => false, CURLOPT_CUSTOMREQUEST => $req->METHOD, CURLOPT_URL => $url['host'] . "/" . rawurlencode($url['path']), CURLOPT_TIMEOUT => $req->Timeout, CURLOPT_CONNECTTIMEOUT => $req->Timeout);
    $httpHeader = $req->Header;
    if (!empty($httpHeader)) {
        $header = array();
        foreach ($httpHeader as $key => $parsedUrlValue) {
            $header[] = "{$key}: {$parsedUrlValue}";
        }
        $options[CURLOPT_HTTPHEADER] = $header;
    }
    $body = $req->Body;
    if (!empty($body)) {
        $options[CURLOPT_POSTFIELDS] = $body;
    } else {
        $options[CURLOPT_POSTFIELDS] = "";
    }
    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);
    $ret = curl_errno($ch);
    if ($ret !== 0) {
        $err = new UCloud_Error(0, $ret, curl_error($ch));
        curl_close($ch);
        return array(null, $err);
    }
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
    curl_close($ch);
    $responseArray = explode("\r\n\r\n", $result);
    $responseArraySize = sizeof($responseArray);
    $headerString = $responseArray[$responseArraySize - 2];
    $respBody = $responseArray[$responseArraySize - 1];
    $headers = parseHeaders($headerString);
    $resp = new HTTP_Response($code, $respBody);
    $resp->Header = $headers;
    $err = null;
    if (floor($resp->StatusCode / 100) != 2) {
        list($r, $m) = parseError($respBody);
        $err = new UCloud_Error($resp->StatusCode, $r, $m);
    }
    return array($resp, $err);
}
/**
 * Download images, pack into a zip, return as zip string.
 * @param Array $imageSources
 * @return Array
 */
function getImageZipAndValidSrc($imageSources)
{
    require_once 'zip.lib.php';
    $zip = new ZipFile();
    $validSrc = array();
    foreach ($imageSources as $source) {
        $image = file_get_contents($source);
        if (in_array(parseHeaders($http_response_header, 'status'), array(200, 301, 304))) {
            $zip->addFile($image, basename($source));
            $validSrc[] = $source;
        }
    }
    return array('zipFile' => $zip->file(), 'validSrc' => $validSrc);
}