Example #1
0
function main()
{
    !isset($_GET['url']) && exit_script('Hello Tumblr!');
    isImageUrl($_GET['url']) && redirect_location($_GET['url']) && exit_script();
    $hosts_number = 4;
    $hash_no = str_hash($_GET['url'], $hosts_number);
    $redirect_url = "http://tumblr-images-{$hash_no}.appspot.com/fetch.php?url={$_GET['url']}";
    $redirect_url = encode_cjk_url($redirect_url);
    redirect_location($redirect_url);
}
Example #2
0
function main()
{
    !isset($_GET['url']) && exit_script('Hello Tumblr!');
    $query_param = get_query_param($_GET['url']);
    !$query_param && isImageUrl($_GET['url']) && redirect_location($_GET['url']) && exit_script();
    !$query_param && echoTxtFile("NOT VALID TUMBLR URL: [{$_GET['url']}]") && exit_script();
    $post_info = query_tumblr_api($query_param);
    !$post_info && echoTxtFile("NO POST INFO FETCHED FROM TUMBLR WITH GIVEN URL: [{$_GET['url']}], THE POST MIGHT BE DELETED") && exit_script();
    $post_info = $post_info['posts'][0];
    switch ($post_info['type']) {
        case 'link':
            $output = <<<EOD
                <p>Title: <h3>{$post_info['link-text']}</h3></p>
                <p>link: <a href="{$post_info['link-url']}">{$post_info['link-url']}</a></p>
                <p>Description:</p>
                <p>{$post_info['link-description']}</p>
EOD;
            echoHtmlFile($output);
            exit_script();
            break;
        case 'regular':
            $output = "<h3>{$post_info['regular-title']}</h3>{$post_info['regular-body']}";
            echoHtmlFile($output);
            exit_script();
            break;
        case 'answer':
            $question = htmlCharsDecode($post_info['question']);
            $answer = htmlCharsDecode($post_info['answer']);
            $tags = implode(', ', $post_info['tags']);
            $output = "[Q&A]\r\n\r\n{$question}\r\n\r\n{$answer}\r\n\r\nTags: {$tags}\r\n";
            echoTxtFile($output);
            exit_script();
            break;
        case 'video':
            $url = get_video_url($post_info);
            redirect_location($url) && exit_script();
            break;
        case 'photo':
        default:
            $urls = get_photo_urls($post_info);
            $count = count($urls);
            if ($count === 1) {
                redirect_location($urls[0]);
                exit_script();
            } else {
                $image_pack = fetch_images($urls);
                $zip_str = makeZip($image_pack);
                echoZipFile($zip_str);
                exit_script();
            }
            break;
    }
}
function main()
{
    $html = get_page(encode_cjk_url($_GET['url']));
    $img_urls = parse_img_urls($html);
    switch (count($img_urls)) {
        case 0:
            exit_with_msg('Images not found');
            break;
        case 1:
            redirect_location(array_pop($img_urls));
            break;
        default:
            output_zip(make_zip(fetch_and_store_images($img_urls)));
            break;
    }
}
function return_recorded_data($record_data)
{
    $data = $record_data['data'];
    switch ($record_data['responseType']) {
        case 'redirect':
            redirect_location($data);
            exit_script();
            break;
        case 'txt':
            echoTxtFile($data);
            exit_script();
            break;
        case 'html':
            echoHtmlFile($data);
            exit_script();
            break;
        case 'photoSet':
            echoTxtFile($data);
            exit_script();
            break;
        default:
            echo 'unknow response type';
            exit_script();
    }
    return true;
}