271 lines
11 KiB
PHP
271 lines
11 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Str;
|
|
use Jenssegers\Agent\Agent;
|
|
use Illuminate\Support\Facades\Cookie;
|
|
use GuzzleHttp\Client;
|
|
use App\Services\DeviceDetect;
|
|
|
|
|
|
|
|
|
|
class AdsController
|
|
{
|
|
|
|
protected $primary_buttons;
|
|
protected $primary_buttons_mobile;
|
|
protected $primary_buttons_android;
|
|
protected $primary_buttons_ios;
|
|
|
|
|
|
protected $primary_pops = '(AU|NZ)';
|
|
|
|
protected $mac_os_modal = '(XYZ)';
|
|
|
|
protected $us_secondary_link;
|
|
protected $primary_link;
|
|
protected $secondary_link;
|
|
|
|
|
|
// protected $pop_s2s_source = 'http://aringours.com/?tid=867257';
|
|
// protected $pop_s2s_source_secondary = 'http://aringours.com/?tid=867257';
|
|
// protected $pop_s2s_source_us = 'http://aringours.com/?tid=985767';
|
|
|
|
protected $pop_s2s_source;
|
|
protected $pop_s2s_source_secondary;
|
|
protected $pop_s2s_source_us;
|
|
|
|
protected $primary_soap2day = '(AU|NZ|SI)';
|
|
protected $primary_soap2day_mobile = '(AU|NZ|SI|SA)';
|
|
protected $primary_soap2day_mobile_no_android = '(XYZ)';
|
|
protected $primary_soap2day_mobile_no_ios = '(XYZ)';
|
|
|
|
public function __construct()
|
|
{
|
|
$this->primary_buttons = config('ads.buttons.countries.primary');
|
|
$this->primary_buttons_mobile = config('ads.buttons.countries.primary_mobile');
|
|
$this->primary_buttons_android = config('ads.buttons.countries.primary_android');
|
|
$this->primary_buttons_ios = config('ads.buttons.countries.primary_ios');
|
|
|
|
$this->pop_s2s_source = config('ads.pop.links.primary');
|
|
$this->pop_s2s_source_secondary = config('ads.pop.links.secondary');
|
|
$this->pop_s2s_source_us = config('ads.pop.links.primary_us');
|
|
|
|
|
|
$this->primary_link = config('ads.buttons.links.primary');
|
|
$this->secondary_link = config('ads.buttons.links.secondary');
|
|
$this->us_secondary_link = config('ads.buttons.links.secondary_us');
|
|
}
|
|
|
|
|
|
protected $direct = [];
|
|
protected $sources = [];
|
|
|
|
public function shouldGetModal($country_code) {
|
|
$agent = new Agent();
|
|
$is_primary = (bool) preg_match('~' . $this->primary_buttons . '~', $country_code);
|
|
$is_primary_mobile = (bool) preg_match('~' . $this->primary_buttons_mobile . '~', $country_code);
|
|
$is_primary_android = (bool) preg_match('~' . $this->primary_buttons_android . '~', $country_code);
|
|
|
|
if ($agent->isAndroidOS() && $is_primary_android) {
|
|
return true;
|
|
}
|
|
if ($agent->isMobile() && $is_primary_mobile) {
|
|
return true;
|
|
}
|
|
|
|
return $is_primary === true;
|
|
|
|
}
|
|
|
|
protected function getCountries():\stdClass
|
|
{
|
|
$req_src = 'all';
|
|
$get_src = 'true';
|
|
$client = new Client(['headers' => ['user-agent' => 'Putlocker FairFan Countries Service']]);
|
|
try {
|
|
$direct = true;
|
|
$response = $client->get('https://fairfan.com/api/availability.php?'.http_build_query(compact('req_src', 'get_src')));
|
|
$data = json_decode($response->getBody()->getContents());
|
|
$this->direct = $data->direct;
|
|
$this->sources = $data->sources;
|
|
return $data;
|
|
} catch (\Throwable $th) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
protected function getSourcesCountries()
|
|
{
|
|
return $this->sources;
|
|
}
|
|
|
|
public function isSourceCountry($country)
|
|
{
|
|
return in_array($country, $this->getSourcesCountries()) || $this->isFairfanDirectCountry($country);
|
|
}
|
|
|
|
protected function isFairfanDirectCountry($country) {
|
|
return in_array($country, $this->direct);
|
|
}
|
|
|
|
public function getFairfanLink($type, $tmdb_id, $country, $season = null, $episode = null)
|
|
{
|
|
$direct = $this->isFairfanDirectCountry($country);
|
|
$request_options = compact('type', 'tmdb_id', 'country');
|
|
if (isset($season)) {
|
|
$request_options = array_merge($request_options, compact('season', 'episode'));
|
|
$request_options['type'] = 'episode';
|
|
}
|
|
|
|
if ($direct) {
|
|
$request_options = array_merge($request_options, compact('direct'));
|
|
$client = new Client(['headers' => ['user-agent' => config('app.name') . ' FairFan Link Service']]);
|
|
try {
|
|
$response = $client->get('https://fairfan.com/api/availability.php?'.http_build_query($request_options));
|
|
$data = json_decode($response->getBody()->getContents());
|
|
if (isset($data->url)) {
|
|
return $data->url;
|
|
}
|
|
} catch (\Throwable $th) {
|
|
|
|
}
|
|
} else {
|
|
|
|
$client = new Client(['headers' => ['user-agent' => config('app.name') . ' FairFan Source Availability Service']]);
|
|
try {
|
|
$response = $client->get('https://fairfan.com/api/availability.php?'.http_build_query($request_options));
|
|
$data = json_decode($response->getBody()->getContents());
|
|
if (isset($data->url)) {
|
|
return $data->url;
|
|
}
|
|
} catch (\Throwable $th) {
|
|
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
public function isPrimaryCountry($country_code):bool
|
|
{
|
|
// return self::isCountry(self::$primary) || (($detect->isMobile() || $detect->isAndroidOS() || $detect->isiPadOS()) && self::isCountry(self::$primary_buttons_mobile));
|
|
$agent = new Agent();
|
|
return (bool) preg_match('~' . $this->primary_buttons . '~', $country_code) ||
|
|
(preg_match('~' . $this->primary_buttons_ios. '~', $country_code) && $agent->isiOS()) ||
|
|
(preg_match('~' . $this->primary_buttons_android. '~', $country_code) && $agent->isAndroidOS()) ||
|
|
(preg_match('~' . $this->primary_buttons_mobile. '~', $country_code) && $agent->isMobile()) ||
|
|
(preg_match('~' . $this->mac_os_modal. '~', $country_code) && $this->isMacOs($agent->getUserAgent()));
|
|
}
|
|
protected function isPrimaryPopCountry($country_code):bool
|
|
{
|
|
return (bool) preg_match('~' . $this->primary_pops . '~', $country_code);
|
|
}
|
|
|
|
protected function isMacOs($userAgent):bool
|
|
{
|
|
$dd = DeviceDetect::getDeviceDetector($userAgent);
|
|
return (bool) $dd->is_mac;
|
|
}
|
|
|
|
/**
|
|
* Get watch Button Link
|
|
*/
|
|
protected function getLink($country_code, $type, $id, $season = null, $episode = null):string
|
|
{
|
|
|
|
if ($this->isSourceCountry($country_code)) {
|
|
|
|
|
|
$link = $this->getFairfanLink($type, $id, $country_code, $season, $episode);
|
|
if (isset($link)) {
|
|
return $link;
|
|
}
|
|
}
|
|
|
|
|
|
$is_us = (bool) preg_match('~' . '(US)' . '~', $country_code);
|
|
if ($is_us) {
|
|
$this->secondary_link = $this->us_secondary_link;
|
|
}
|
|
|
|
$is_primary = (bool) preg_match('~' . $this->primary_buttons . '~', $country_code);
|
|
$is_primary_mobile = (bool) preg_match('~' . $this->primary_buttons_mobile . '~', $country_code);
|
|
$is_primary_android = (bool) preg_match('~' . $this->primary_buttons_android . '~', $country_code);
|
|
$is_primary_ios = (bool) preg_match('~' . $this->primary_buttons_ios . '~', $country_code);
|
|
$is_mac_os = (bool) preg_match('~' . $this->mac_os_modal . '~', $country_code);
|
|
$agent = new Agent();
|
|
return ($is_primary || ($is_primary_android && $agent->isAndroidOS()) || ($is_primary_ios && $agent->isiOS()) || ($is_primary_mobile && $agent->isMobile()) || ($is_mac_os && $this->isMacOs($agent->getUserAgent())) ) ? $this->primary_link : $this->secondary_link;
|
|
|
|
}
|
|
|
|
/**
|
|
* Watch Button
|
|
*/
|
|
public function index(Request $request, $type, $id, $season = null, $episode = null)
|
|
{
|
|
$this->getCountries();
|
|
$country_code = $request->headers->get('cf-ipcountry');
|
|
$link = $this->getLink($country_code, $type, $id, $season, $episode);
|
|
|
|
// $link = 'https://s.optzsrv.com/d.php?z=8278&sub=25';
|
|
// $link = 'https://intorterraon.com/4/5374775';
|
|
Cookie::queue('return', Str::random(5), 43200);
|
|
return view('loading', compact('link'));
|
|
}
|
|
|
|
|
|
public function getPop(Request $request)
|
|
{
|
|
$disabledCall = fn() => response('/* disabled */', 200, ['Content-Type' => 'application/javascript', 'Cache-Control' => 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0']);
|
|
$agent = new Agent();
|
|
if ($agent->isBot()) return $disabledCall();
|
|
$country_code = $request->headers->get('cf-ipcountry');
|
|
// primary countries
|
|
$isMobileCountry = (bool) preg_match('~' . config('ads.pop.countries.primary_mobile') . '~', $country_code);
|
|
$isMobileNoAndroidCountry = (bool) preg_match('~' . config('ads.pop.countries.primary_android') . '~', $country_code);
|
|
$isMobileNoIosCountry = (bool) preg_match('~' . config('ads.pop.countries.primary_ios') . '~', $country_code);
|
|
$isCountry = (bool) preg_match('~' . config('ads.pop.countries.primary') . '~', $country_code);
|
|
|
|
if ($isMobileNoAndroidCountry && ($agent->isMobile() && !$agent->isAndroidOS()) && !$request->hasCookie('return')) return $disabledCall();
|
|
if ($isMobileNoIosCountry && ($agent->isMobile() && !$agent->isiOS()) && !$request->hasCookie('return')) return $disabledCall();
|
|
if ($isMobileCountry && $agent->isMobile() && !$request->hasCookie('return')) return $disabledCall();
|
|
if ($isCountry && !$request->hasCookie('return')) return $disabledCall();
|
|
|
|
// // iOS new pop
|
|
// if (in_array($country_code, ['US','GB']) && $agent->isiOS()) {
|
|
// // do nothing, let the pop load
|
|
// } else {
|
|
// if ((in_array($country_code, ["US","AU","GB","CA","NZ"]) && !$request->hasCookie('return') && $agent->isMobile()) || (in_array($country_code, ['NZ']) && !$request->hasCookie('return'))) {
|
|
// return response('/* disabled */', 200, ['Content-Type' => 'application/javascript', 'Cache-Control' => 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0']);
|
|
// }
|
|
// }
|
|
|
|
|
|
return response($this->isPrimaryPopCountry($country_code) ? $this->getPopJs('primary', $country_code) : $this->getPopJs('secondary', $country_code), 200, ['Content-Type' => 'application/javascript', 'Cache-Control' => 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0']);
|
|
}
|
|
|
|
/**
|
|
* Get Js Script Data
|
|
*/
|
|
public function getPopJs($type, $country_code):string
|
|
{
|
|
$cache_key = implode('_', ['pop_js_neox', $type, $country_code]);
|
|
return Cache::remember($cache_key, 15*60, function() use ($type, $country_code){
|
|
return $type === 'primary' ? '/* primary '.$country_code.' */'.file_get_contents($country_code === 'US' ? $this->pop_s2s_source_us:$this->pop_s2s_source, false, stream_context_create(["ssl"=>array(
|
|
"verify_peer"=>false,
|
|
"verify_peer_name"=>false,
|
|
)])) : '/* secondary */'.file_get_contents($country_code === 'US' ? $this->pop_s2s_source_us : $this->pop_s2s_source_secondary, false, stream_context_create(["ssl"=>array(
|
|
"verify_peer"=>false,
|
|
"verify_peer_name"=>false,
|
|
)]));
|
|
});
|
|
}
|
|
|
|
|
|
|
|
}
|