function update_info($root) { $info_files = scan_info_files($root); if (!$info_files) { echo json_encode(["ERROR" => $root . " has no resources"], JSON_UNESCAPED_SLASHES); return false; } $photo_files = generate_photo_files($info_files); $thumbnail_files = generate_thumbnail_files($info_files); if (!$info_files) { return false; } $photoInfoObj = new PhotoInfo(""); $i = 0; foreach ($info_files as $info) { $jsonStr = file_get_contents($info, FILE_TEXT); // 往原始的json数据中添加新的信息 if (substr($jsonStr, 0, 3) == pack("CCC", 0xef, 0xbb, 0xbf)) { $jsonStr = substr($jsonStr, 3); } $filename = $photo_files[$i]; $thumbnail_filename = $thumbnail_files[$i]; ++$i; $json_obj = json_decode($jsonStr, true); $json_obj["filename"] = pathinfo($filename, PATHINFO_BASENAME); $json_obj["thumbnail_filename"] = pathinfo($thumbnail_filename, PATHINFO_BASENAME); // 往原始的json数据中添加新的信息 $photoInfoObj->decode_json_info(json_encode($json_obj)); // var_dump($photoInfoObj->get_info()); $title = $photoInfoObj->getTitle(); $photographer = $photoInfoObj->getPhotographer(); $model = $photoInfoObj->getModel(); $timestamp = $photoInfoObj->getTime(); $location = $photoInfoObj->getLocation(); $tag_list = $photoInfoObj->getTags(); // 保存一份tag_str到数据库中 $tag_json = json_encode($tag_list); $ratio = $photoInfoObj->getRatio(); $filename = $photoInfoObj->getFilename(); $thumbnail_filename = $photoInfoObj->getThumbnailFilename(); // 增加模特信息 $model_id = insert_model($model); // tag 信息 $tag_id_list = array(); foreach ($tag_list as $tag) { $tag_id_list[] = insert_tag($tag); } echo "处理照片: " . $filename . "<br>"; // 添加照片信息到数据库 insert_photo($filename, $thumbnail_filename, $model_id, $title, $photographer, $model, $timestamp, $location, $ratio, $tag_id_list, $tag_json); } }
//検索結果の取得($tweets_objはJSONの検索結果が入る) $tweets_obj = $connection->OAuthRequest('https://api.twitter.com/1.1/search/tweets.json', 'GET', $params); if ($tweets_obj) { //検索結果をjson_decodeで連想配列に変換 $tweets_arr = json_decode($tweets_obj, true); //画像のURLを取得 foreach ($tweets_arr['statuses'] as $statuses) { if (isset($statuses['entities']['media'][0]['media_url'])) { $photoURL = $statuses['entities']['media'][0]['media_url']; //APIの日時に合わせる date_default_timezone_set('Europe/London'); //投稿日時を取得 $postedDatetime = date('Y-m-d H:i:s', strtotime($tweets_arr['statuses'][0]['created_at'])); //DBに画像のURLと投稿日時を追加 if ($db == true) { $result = insert_photo($photoURL, $postedDatetime, $snsID); } } } } //先頭の「?」を除去 $next_results = preg_replace('/^\\?/', '', $tweets_arr['search_metadata']['next_results']); //$next_resultsが無ければ処理を終了 if (empty($next_results)) { break; } //パラメータに変換 parse_str($next_results, $params); } //エラーが発生しなければ表示 if (!isset($result)) {