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 = ''; $multi_query = ''; $limit = 50; $respond_error = 0; $search_made = 0; $page_id = 1; if (empty($pt->config->twitch_api)) { $respond_error = 1; $error_text = 'please put your Twitch Client Id in Settings > General Settings to start import videos from Twitch.'; } if (!empty($_GET['query']) || !empty($_GET['multi-query'])) { if (!empty($_GET['query'])) { $query = PT_Secure($_GET['query']); } if (!empty($_GET['limit']) && $limit < 101) { $limit = (int) PT_Secure($_GET['limit']); } $search_made = 1; $offset = $limit; if (!empty($_GET['page-query'])) { if (is_numeric($_GET['page-query'])) { $page_id = PT_Secure($_GET['page-query']); $offset = ($page_id * $limit); } } $query = urlencode($query); for ($i=$page_id; $i <= 10 ; $i++) { $offset = ($i * $limit); $channelsApi = 'https://api.twitch.tv/kraken/channels/'.$query.'/videos?limit='.$limit; if (!empty($offset) && $page_id > 1) { $channelsApi = 'https://api.twitch.tv/kraken/channels/'.$query.'/videos?limit='.$limit.'&offset='.$offset; } $clientId = $pt->config->twitch_api; $ch = curl_init(); curl_setopt_array($ch, array( CURLOPT_HTTPHEADER => array( 'Client-ID: ' . $clientId, 'Accept: application/vnd.twitchtv.v4+json' ), CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => $channelsApi )); $response = curl_exec($ch); curl_close($ch); $get_videos = json_decode($response); if (!empty($get_videos->videos) && $get_videos->status != 400) { if (!empty($get_videos->_total)) { $ids = array(); foreach ($get_videos->videos as $key => $video) { $check_if_exists = $db->where('twitch', substr($video->_id, 1) )->getValue(T_VIDEOS, 'count(*)'); if ($check_if_exists == 0) { $ids[] = substr($video->_id, 1); } } if (!empty($ids)) { break; } else{ } } } else if($get_videos->status == 400){ $respond_error = 1; $error_text = $get_videos->message; break; } else { $respond_error = 1; $error_text = 'No video found.'; break; } $page_id = $page_id + 1; } } $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; } ?>