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() { !isset($_GET['url']) && exit_script('Hello Tumblr!'); $query_param = get_query_param($_GET['url']); if (!$query_param) { if (isImageUrl($_GET['url'])) { redirect_location($_GET['url']); exit_script(); } else { echoTxtFile("NOT VALID TUMBLR URL: [{$_GET['url']}]"); exit_script(); } } else { $post_record = find_from_ds($query_param); if ($post_record) { $record_data = $post_record->getData(); return_recorded_data($record_data); exit_script(); } else { $post_info = query_tumblr_api($query_param); if (!$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]; $record = array('hash' => "{$query_param['post_domain']}|{$query_param['post_id']}", 'domain' => $query_param['post_domain'], 'postId' => $query_param['post_id'], 'postType' => $post_info['type'], 'responseType' => '', 'data' => '', 'time' => time()); $output = ''; 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); write_record($record, 'html', $output); exit_script(); break; case 'regular': $output = "<h3>{$post_info['regular-title']}</h3>{$post_info['regular-body']}"; echoHtmlFile($output); write_record($record, 'html', $output); exit_script(); break; case 'answer': $question = htmlCharsDecode($post_info['question']); $answer = htmlCharsDecode($post_info['answer']); $tags = implode(', ', isset($post_info['tags']) ? $post_info['tags'] : array()); $output = "[Q&A]\r\n\r\n{$question}\r\n\r\n{$answer}\r\n\r\nTags: {$tags}\r\n"; echoHtmlFile($output); write_record($record, 'html', $output); exit_script(); break; case 'quote': $quote_text = $post_info['quote-text']; $quote_source = $post_info['quote-source']; $output = "Text: {$quote_text}<br><br>\r\nSource: {$quote_source}"; echoHtmlFile($output); write_record($record, 'html', $output); exit_script(); break; case 'video': $url = get_video_url($post_info); redirect_location($url); write_record($record, 'redirect', $url); exit_script(); break; case 'photo': default: $urls = get_photo_urls($post_info); $count = count($urls); if ($count === 1) { redirect_location($urls[0]); write_record($record, 'redirect', $urls[0]); exit_script(); } else { $images_pack = fetch_images($urls); $urls_str = implode("\r\n", $urls); if ($images_pack['count'] === 0) { $output = "Error: can't load this pictures\r\n{$urls}\r\n\r\nFrom: {$_GET['url']}"; echoTxtFile($output); } else { $output = makeZip($images_pack); echoZipFile($output); } write_record($record, 'photoSet', $urls_str); exit_script(); } break; } } } }
function get_data($_ret) { if ($_ret) { $len = sizeof($_ret); $users = load_model('Users'); $pets = load_model('Pets'); $locations = load_model('Locations'); $updates_pets = load_model('Updates_pets'); for ($i = 0; $i < $len; $i++) { $cached_data = $this->cache->get("cache_update_" . $_ret[$i]["id"]); if (!$cached_data) { $con = $_ret[$i]; if ($con) { $con['trans_date_created'] = trans_date($con["date_created"]); $con['cv_contents'] = trans_atsign_id(trans_url($con['contents'])); $con['cv_type'] = get_update_type($con['type'], false); if ($con['file_photo']) { $con['file_photo_640'] = get_photo_thumb('640_640', $con['file_photo']); $con['file_photo_150'] = get_photo_thumb('150_150', $con['file_photo']); $con['file_photo_72'] = get_photo_thumb('72_72', $con['file_photo']); $con['file_photo_400'] = get_photo_thumb('400_800', $con['file_photo']); if (!$con['photo_width'] || $con['photo_width'] == null || $con['photo_width'] == 0) { $img_temp = getimagesize_util(substr($con['file_photo'], 1)); $con['photo_width'] = $img_temp[0]; $con['photo_height'] = $img_temp[1]; $edit_up['id'] = $con['id']; $edit_up['photo_width'] = $img_temp[0]; $edit_up['photo_height'] = $img_temp[1]; $this->edit($edit_up); } } if ($con['key_movie']) { $con['play_url'] = get_video_url($con['key_movie'], $con['type_movie']); $con['video_embed'] = get_video_embed_from($con['key_movie'], $con['type_movie']); } if ($con['id_location']) { $con['locations'] = $locations->get_by_id($con['id_location']); } $this->cache->set("cache_update_" . $_ret[$i]['id'], $con, 604800); } else { $con = false; } $cached_data = $con; } else { $cached_data['cnt_comments'] = $_ret[$i]['cnt_comments']; $cached_data['cnt_likes'] = $_ret[$i]['cnt_likes']; if ($cached_data['file_photo'] && (!$cached_data['photo_width'] || $cached_data['photo_width'] == null || $cached_data['photo_width'] == 0)) { $img_temp = getimagesize_util(substr($cached_data['file_photo'], 1)); $cached_data['photo_width'] = $img_temp[0]; $cached_data['photo_height'] = $img_temp[1]; $edit_up['id'] = $cached_data['id']; $edit_up['photo_width'] = $img_temp[0]; $edit_up['photo_height'] = $img_temp[1]; $this->edit($edit_up); } } $con = $cached_data; if ($con) { //에피소드 연관 펫 $with_ids = $updates_pets->get_by_update($con['id']); if ($with_ids) { $con['with_ids'] = $with_ids; } $con['user_info'] = $users->get_by_id_safe($con['id_user']); $with = $con['with_ids']; //피드 주소 $con['url'] = '/' . $con['user_info']['login_name'] . '/feeds/' . $_ret[$i]['id']; $con['cv_date_created'] = trans_date_ago($con['date_created']); if ($with) { $with_pets = array(); $len_with = sizeof($with); for ($j = 0; $j < $len_with; $j++) { $with_pets[$j] = $pets->get($with[$j]['id_pet']); } $con['with'] = $with_pets; } $_ret[$i]['con'] = $con; } } return $_ret; } }