sub_categories_array = array(); foreach ($pt->sub_categories as $cat_key => $subs) { $pt->sub_categories_array["'".$cat_key."'"] = ''; foreach ($subs as $sub_key => $sub_value) { $selected = ''; if (!empty($_GET['sub_category_id'])) { $selected = ($_GET['sub_category_id'] == $sub_key) ? 'selected' : ''; } $pt->sub_categories_array["'".$cat_key."'"] .= ''; } } $query = ''; $limit = 50; $multi_query = ''; $respond_error = 0; $search_made = 0; $channel = false; if (!empty($_GET['query']) || !empty($_GET['multi-query'])) { if (!empty($_GET['query'])) { $query = PT_Secure($_GET['query']); } else if ($_GET['multi-query']) { $query = PT_Secure($_GET['multi-query']); $multi_query = $query; $explode = explode(',', $query); if (!isset($_SESSION['keyword-id']) && empty($_GET['finished'])) { $query = $_SESSION['keyword-id'] = 0; $query = $explode[0]; } else { $query = $explode[$_SESSION['keyword-id']]; } } if (!empty($_GET['limit']) && $limit < 51) { $limit = (int) PT_Secure($_GET['limit']); } $search_made = 1; try { $youtube = new Madcoda\Youtube\Youtube(array('key' => $pt->config->yt_api)); $searchArray = array( 'q' => $query, 'type' => 'video', 'part' => 'id', 'maxResults' => $limit, ); if (!empty($_GET['search-type'])) { if ($_GET['search-type'] == 'channel') { $searchArray['channelId'] = $query; $searchArray['q'] = ''; $channel = true; } } $get_videos = $youtube->searchAdvanced($searchArray, true); if (!empty($get_videos)) { if ($get_videos['info']['totalResults'] > 0) { $next_token = $get_videos['info']['nextPageToken']; $ids = array(); foreach ($get_videos['results'] as $key => $video) { $check_if_exists = $db->where('youtube', $video->id->videoId)->getValue(T_VIDEOS, 'count(*)'); if ($check_if_exists == 0) { $ids[] = $video->id->videoId; } } if (empty($ids)) { for ($i = 0; $i < 10; $i++) { if (empty($ids)) { $searchArray['pageToken'] = $next_token; $get_videos = $youtube->searchAdvanced($searchArray, true); if (!empty($get_videos['results'])) { $next_token = $get_videos['info']['nextPageToken']; foreach ($get_videos['results'] as $key => $video) { $check_if_exists = $db->where('youtube', $video->id->videoId)->getValue(T_VIDEOS, 'count(*)'); if ($check_if_exists == 0) { $ids[] = $video->id->videoId; } } } } } } $ids_implode = implode(',', $ids); if (!empty($ids_implode)) { $youtube_call_url = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet&id=$ids_implode&key={$pt->config->yt_api}"; $get_videos_ = connect_to_url($youtube_call_url); if (empty($get_videos_)) { $respond_error = 1; $error_text = 'Something went wrong, please try again later'; } $get_videos_ = json_decode($get_videos_); } } } if (empty($ids) && empty($respond_error)) { $keyword_id = (isset($_SESSION['keyword-id'])) ? $_SESSION['keyword-id'] : null; if (!empty($explode[$keyword_id + 1])) { $_SESSION['keyword-id'] = $_SESSION['keyword-id'] + 1; } else { unset($_SESSION['keyword-id']); if (empty($_GET['finished']) && $search_made == 1 && $channel == false) { //header("Location: " . PT_LoadAdminLinkSettings('import-from-youtube?finished=1')); } } } } catch (\Exception $e) { $respond_error = 1; $error_text = $e->getMessage(); } } $user_id = 0; $username = ''; if (!empty($_GET['username']) && isset($_GET['username'])) { $username = PT_Secure($_GET['username']); $user = $db->where('username', $username)->getOne(T_USERS); if (!empty($user)) { $user_id = $user->id; } else{ $respond_error = 1; $error_text = 'user not found'; } } $category_filter = array_keys(ToArray($pt->categories))[0]; if (!empty($_GET['category_id'])) { if (in_array($_GET['category_id'], array_keys(ToArray($pt->categories)))) { $category_filter = $_GET['category_id']; } } $get_ini = ini_get('max_input_vars'); $auto_import = 0; if (!empty($_GET['auto_import'])) { $auto_import = 1; } ?>