namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\{Session, Redirect}; use App\Services\ApiService; class FixUrlsController extends Controller { private $apiService; public function __construct(ApiService $apiService) { $this->apiService = $apiService; } public function fixShortDiv(Request $request, $slug) { $selectedLang = Session::get('selected_lang'); $store = $this->apiService->getStore($slug, "slug") ; $title = $selectedLang == "ar" ? $store["title"] : $store["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('store', ['country' => $store["country"] , 'lang' => $selectedLang , 'storeName' => $title , 'store' => $store['id']]))); return Redirect::to($url , 301) ; } public function fixOffer(Request $request, $id, $slug) { $selectedCountry = Session::get('selected_country'); $selectedLang = Session::get('selected_lang'); // weird issue in tsawq links if(preg_match("/[0-9]+/" , $slug)) { $id = $slug ; } if( $topic = $this->apiService->getTopicById($id, $selectedCountry) ) { $title = $selectedLang == "ar" ? $topic["title"] : $topic["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('offer', ['country' => $topic["country"] , 'lang' => $selectedLang , 'offerName' => $title , 'offer' => $topic['id']]))); return Redirect::to($url , 301) ; } return Redirect::to("https://www.tsawq.net/{$selectedCountry}/{$selectedLang}/home" , 302) ; } public function fixAmp(Request $rquest, $id) { try { $selectedCountry = Session::get('selected_country'); $selectedLang = Session::get('selected_lang'); $topic = $this->apiService->getTopicById($id, $selectedCountry) ; $title = $selectedLang == "ar" ? $topic["title"] : $topic["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('offer', ['country' => $topic["country"] , 'lang' => $selectedLang , 'offerName' => $title , 'offer' => $topic['id']]))); $url = str_replace("amp." , "www." , $url) ; return Redirect::to($url , 301) ; } catch(\Exception $e) { \Log::error("something went wrong: " . $e->getMessage(). " >> " . request()->ip() ." url is >>" . request()->fullUrl()); return Redirect::to("https://www.tsawq.net/" , 302) ; } } public function fixDownload(Request $rquest) { $id = $_GET["id"] ; $selectedCountry = Session::get('selected_country'); $selectedLang = Session::get('selected_lang'); $topic = $this->apiService->getTopicById($id, $selectedCountry) ; $title = $selectedLang == "ar" ? $topic["title"] : $topic["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('download', ['country' => $topic["country"] , 'lang' => $selectedLang , 'offerName' => $title , 'offer' => $topic['id']]))); return Redirect::to($url , 301) ; } public function fixOthers(Request $request, $file) { $accepted = [ "showLatest" => "%s/%s/home" , "mostViewed" => "%s/%s/most-view-offers" , "important" => "%s/%s/latest" , "showTopic" => "%s/%s/offers/%s/%s" , "showDiv" => "%s/%s/store/%s/%s" ] ; ( ! ($path = $accepted[$file] ?? null) ) && abort(404); $url = parse_url($request->getRequestUri()); (!isset($url["query"]) && !in_array($file, ["showLatest" , "mostViewed" , "important"]) ) && abort(404); if(in_array($file, ["showLatest" , "mostViewed" , "important"]) && !isset($url["query"])) { $selectedCountry = Session::get('selected_country'); $selectedLang = Session::get('selected_lang'); $url = sprintf($accepted[$file], $selectedCountry, $selectedLang) ; return Redirect::to($url , 301) ; } parse_str($url["query"] , $query) ; if(strtolower($file) === "showtopic" ){ $selectedLang = Session::get('selected_lang'); $topic = $this->apiService->getTopicById($query["id"], "") ; $title = $selectedLang == "ar" ? $topic["title"] : $topic["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('offer', ['country' => $topic["country"] , 'lang' => $selectedLang , 'offerName' => $title , 'offer' => $topic['id']]))); return Redirect::to($url , 301) ; } if(strtolower($file) === "showdiv" ){ $selectedLang = Session::get('selected_lang'); $store = $this->apiService->getStore($query["id"], "id") ; $title = $selectedLang == "ar" ? $store["title"] : $store["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('store', ['country' => $store["country"] , 'lang' => $selectedLang , 'storeName' => $title , 'store' => $store['id']]))); return Redirect::to($url , 301) ; } $lang = Session::get('selected_lang'); $country = $query["country"] ?? Session::get('selected_country'); if(isset($query["lang"])) { $lang = $query["lang"] ; } return Redirect::to( sprintf($path , $country, $lang) , 301); } } ?> namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\{Session, Redirect}; use App\Services\ApiService; class FixUrlsController extends Controller { private $apiService; public function __construct(ApiService $apiService) { $this->apiService = $apiService; } public function fixShortDiv(Request $request, $slug) { $selectedLang = Session::get('selected_lang'); $store = $this->apiService->getStore($slug, "slug") ; $title = $selectedLang == "ar" ? $store["title"] : $store["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('store', ['country' => $store["country"] , 'lang' => $selectedLang , 'storeName' => $title , 'store' => $store['id']]))); return Redirect::to($url , 301) ; } public function fixOffer(Request $request, $id, $slug) { $selectedCountry = Session::get('selected_country'); $selectedLang = Session::get('selected_lang'); // weird issue in tsawq links if(preg_match("/[0-9]+/" , $slug)) { $id = $slug ; } if( $topic = $this->apiService->getTopicById($id, $selectedCountry) ) { $title = $selectedLang == "ar" ? $topic["title"] : $topic["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('offer', ['country' => $topic["country"] , 'lang' => $selectedLang , 'offerName' => $title , 'offer' => $topic['id']]))); return Redirect::to($url , 301) ; } return Redirect::to("https://www.tsawq.net/{$selectedCountry}/{$selectedLang}/home" , 302) ; } public function fixAmp(Request $rquest, $id) { try { $selectedCountry = Session::get('selected_country'); $selectedLang = Session::get('selected_lang'); $topic = $this->apiService->getTopicById($id, $selectedCountry) ; $title = $selectedLang == "ar" ? $topic["title"] : $topic["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('offer', ['country' => $topic["country"] , 'lang' => $selectedLang , 'offerName' => $title , 'offer' => $topic['id']]))); $url = str_replace("amp." , "www." , $url) ; return Redirect::to($url , 301) ; } catch(\Exception $e) { \Log::error("something went wrong: " . $e->getMessage(). " >> " . request()->ip() ." url is >>" . request()->fullUrl()); return Redirect::to("https://www.tsawq.net/" , 302) ; } } public function fixDownload(Request $rquest) { $id = $_GET["id"] ; $selectedCountry = Session::get('selected_country'); $selectedLang = Session::get('selected_lang'); $topic = $this->apiService->getTopicById($id, $selectedCountry) ; $title = $selectedLang == "ar" ? $topic["title"] : $topic["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('download', ['country' => $topic["country"] , 'lang' => $selectedLang , 'offerName' => $title , 'offer' => $topic['id']]))); return Redirect::to($url , 301) ; } public function fixOthers(Request $request, $file) { $accepted = [ "showLatest" => "%s/%s/home" , "mostViewed" => "%s/%s/most-view-offers" , "important" => "%s/%s/latest" , "showTopic" => "%s/%s/offers/%s/%s" , "showDiv" => "%s/%s/store/%s/%s" ] ; ( ! ($path = $accepted[$file] ?? null) ) && abort(404); $url = parse_url($request->getRequestUri()); (!isset($url["query"]) && !in_array($file, ["showLatest" , "mostViewed" , "important"]) ) && abort(404); if(in_array($file, ["showLatest" , "mostViewed" , "important"]) && !isset($url["query"])) { $selectedCountry = Session::get('selected_country'); $selectedLang = Session::get('selected_lang'); $url = sprintf($accepted[$file], $selectedCountry, $selectedLang) ; return Redirect::to($url , 301) ; } parse_str($url["query"] , $query) ; if(strtolower($file) === "showtopic" ){ $selectedLang = Session::get('selected_lang'); $topic = $this->apiService->getTopicById($query["id"], "") ; $title = $selectedLang == "ar" ? $topic["title"] : $topic["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('offer', ['country' => $topic["country"] , 'lang' => $selectedLang , 'offerName' => $title , 'offer' => $topic['id']]))); return Redirect::to($url , 301) ; } if(strtolower($file) === "showdiv" ){ $selectedLang = Session::get('selected_lang'); $store = $this->apiService->getStore($query["id"], "id") ; $title = $selectedLang == "ar" ? $store["title"] : $store["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('store', ['country' => $store["country"] , 'lang' => $selectedLang , 'storeName' => $title , 'store' => $store['id']]))); return Redirect::to($url , 301) ; } $lang = Session::get('selected_lang'); $country = $query["country"] ?? Session::get('selected_country'); if(isset($query["lang"])) { $lang = $query["lang"] ; } return Redirect::to( sprintf($path , $country, $lang) , 301); } } ?> namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\{Session, Redirect}; use App\Services\ApiService; class FixUrlsController extends Controller { private $apiService; public function __construct(ApiService $apiService) { $this->apiService = $apiService; } public function fixShortDiv(Request $request, $slug) { $selectedLang = Session::get('selected_lang'); $store = $this->apiService->getStore($slug, "slug") ; $title = $selectedLang == "ar" ? $store["title"] : $store["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('store', ['country' => $store["country"] , 'lang' => $selectedLang , 'storeName' => $title , 'store' => $store['id']]))); return Redirect::to($url , 301) ; } public function fixOffer(Request $request, $id, $slug) { $selectedCountry = Session::get('selected_country'); $selectedLang = Session::get('selected_lang'); // weird issue in tsawq links if(preg_match("/[0-9]+/" , $slug)) { $id = $slug ; } if( $topic = $this->apiService->getTopicById($id, $selectedCountry) ) { $title = $selectedLang == "ar" ? $topic["title"] : $topic["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('offer', ['country' => $topic["country"] , 'lang' => $selectedLang , 'offerName' => $title , 'offer' => $topic['id']]))); return Redirect::to($url , 301) ; } return Redirect::to("https://www.tsawq.net/{$selectedCountry}/{$selectedLang}/home" , 302) ; } public function fixAmp(Request $rquest, $id) { try { $selectedCountry = Session::get('selected_country'); $selectedLang = Session::get('selected_lang'); $topic = $this->apiService->getTopicById($id, $selectedCountry) ; $title = $selectedLang == "ar" ? $topic["title"] : $topic["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('offer', ['country' => $topic["country"] , 'lang' => $selectedLang , 'offerName' => $title , 'offer' => $topic['id']]))); $url = str_replace("amp." , "www." , $url) ; return Redirect::to($url , 301) ; } catch(\Exception $e) { \Log::error("something went wrong: " . $e->getMessage(). " >> " . request()->ip() ." url is >>" . request()->fullUrl()); return Redirect::to("https://www.tsawq.net/" , 302) ; } } public function fixDownload(Request $rquest) { $id = $_GET["id"] ; $selectedCountry = Session::get('selected_country'); $selectedLang = Session::get('selected_lang'); $topic = $this->apiService->getTopicById($id, $selectedCountry) ; $title = $selectedLang == "ar" ? $topic["title"] : $topic["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('download', ['country' => $topic["country"] , 'lang' => $selectedLang , 'offerName' => $title , 'offer' => $topic['id']]))); return Redirect::to($url , 301) ; } public function fixOthers(Request $request, $file) { $accepted = [ "showLatest" => "%s/%s/home" , "mostViewed" => "%s/%s/most-view-offers" , "important" => "%s/%s/latest" , "showTopic" => "%s/%s/offers/%s/%s" , "showDiv" => "%s/%s/store/%s/%s" ] ; ( ! ($path = $accepted[$file] ?? null) ) && abort(404); $url = parse_url($request->getRequestUri()); (!isset($url["query"]) && !in_array($file, ["showLatest" , "mostViewed" , "important"]) ) && abort(404); if(in_array($file, ["showLatest" , "mostViewed" , "important"]) && !isset($url["query"])) { $selectedCountry = Session::get('selected_country'); $selectedLang = Session::get('selected_lang'); $url = sprintf($accepted[$file], $selectedCountry, $selectedLang) ; return Redirect::to($url , 301) ; } parse_str($url["query"] , $query) ; if(strtolower($file) === "showtopic" ){ $selectedLang = Session::get('selected_lang'); $topic = $this->apiService->getTopicById($query["id"], "") ; $title = $selectedLang == "ar" ? $topic["title"] : $topic["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('offer', ['country' => $topic["country"] , 'lang' => $selectedLang , 'offerName' => $title , 'offer' => $topic['id']]))); return Redirect::to($url , 301) ; } if(strtolower($file) === "showdiv" ){ $selectedLang = Session::get('selected_lang'); $store = $this->apiService->getStore($query["id"], "id") ; $title = $selectedLang == "ar" ? $store["title"] : $store["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('store', ['country' => $store["country"] , 'lang' => $selectedLang , 'storeName' => $title , 'store' => $store['id']]))); return Redirect::to($url , 301) ; } $lang = Session::get('selected_lang'); $country = $query["country"] ?? Session::get('selected_country'); if(isset($query["lang"])) { $lang = $query["lang"] ; } return Redirect::to( sprintf($path , $country, $lang) , 301); } } ?> namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\{Session, Redirect}; use App\Services\ApiService; class FixUrlsController extends Controller { private $apiService; public function __construct(ApiService $apiService) { $this->apiService = $apiService; } public function fixShortDiv(Request $request, $slug) { $selectedLang = Session::get('selected_lang'); $store = $this->apiService->getStore($slug, "slug") ; $title = $selectedLang == "ar" ? $store["title"] : $store["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('store', ['country' => $store["country"] , 'lang' => $selectedLang , 'storeName' => $title , 'store' => $store['id']]))); return Redirect::to($url , 301) ; } public function fixOffer(Request $request, $id, $slug) { $selectedCountry = Session::get('selected_country'); $selectedLang = Session::get('selected_lang'); // weird issue in tsawq links if(preg_match("/[0-9]+/" , $slug)) { $id = $slug ; } if( $topic = $this->apiService->getTopicById($id, $selectedCountry) ) { $title = $selectedLang == "ar" ? $topic["title"] : $topic["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('offer', ['country' => $topic["country"] , 'lang' => $selectedLang , 'offerName' => $title , 'offer' => $topic['id']]))); return Redirect::to($url , 301) ; } return Redirect::to("https://www.tsawq.net/{$selectedCountry}/{$selectedLang}/home" , 302) ; } public function fixAmp(Request $rquest, $id) { try { $selectedCountry = Session::get('selected_country'); $selectedLang = Session::get('selected_lang'); $topic = $this->apiService->getTopicById($id, $selectedCountry) ; $title = $selectedLang == "ar" ? $topic["title"] : $topic["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('offer', ['country' => $topic["country"] , 'lang' => $selectedLang , 'offerName' => $title , 'offer' => $topic['id']]))); $url = str_replace("amp." , "www." , $url) ; return Redirect::to($url , 301) ; } catch(\Exception $e) { \Log::error("something went wrong: " . $e->getMessage(). " >> " . request()->ip() ." url is >>" . request()->fullUrl()); return Redirect::to("https://www.tsawq.net/" , 302) ; } } public function fixDownload(Request $rquest) { $id = $_GET["id"] ; $selectedCountry = Session::get('selected_country'); $selectedLang = Session::get('selected_lang'); $topic = $this->apiService->getTopicById($id, $selectedCountry) ; $title = $selectedLang == "ar" ? $topic["title"] : $topic["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('download', ['country' => $topic["country"] , 'lang' => $selectedLang , 'offerName' => $title , 'offer' => $topic['id']]))); return Redirect::to($url , 301) ; } public function fixOthers(Request $request, $file) { $accepted = [ "showLatest" => "%s/%s/home" , "mostViewed" => "%s/%s/most-view-offers" , "important" => "%s/%s/latest" , "showTopic" => "%s/%s/offers/%s/%s" , "showDiv" => "%s/%s/store/%s/%s" ] ; ( ! ($path = $accepted[$file] ?? null) ) && abort(404); $url = parse_url($request->getRequestUri()); (!isset($url["query"]) && !in_array($file, ["showLatest" , "mostViewed" , "important"]) ) && abort(404); if(in_array($file, ["showLatest" , "mostViewed" , "important"]) && !isset($url["query"])) { $selectedCountry = Session::get('selected_country'); $selectedLang = Session::get('selected_lang'); $url = sprintf($accepted[$file], $selectedCountry, $selectedLang) ; return Redirect::to($url , 301) ; } parse_str($url["query"] , $query) ; if(strtolower($file) === "showtopic" ){ $selectedLang = Session::get('selected_lang'); $topic = $this->apiService->getTopicById($query["id"], "") ; $title = $selectedLang == "ar" ? $topic["title"] : $topic["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('offer', ['country' => $topic["country"] , 'lang' => $selectedLang , 'offerName' => $title , 'offer' => $topic['id']]))); return Redirect::to($url , 301) ; } if(strtolower($file) === "showdiv" ){ $selectedLang = Session::get('selected_lang'); $store = $this->apiService->getStore($query["id"], "id") ; $title = $selectedLang == "ar" ? $store["title"] : $store["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('store', ['country' => $store["country"] , 'lang' => $selectedLang , 'storeName' => $title , 'store' => $store['id']]))); return Redirect::to($url , 301) ; } $lang = Session::get('selected_lang'); $country = $query["country"] ?? Session::get('selected_country'); if(isset($query["lang"])) { $lang = $query["lang"] ; } return Redirect::to( sprintf($path , $country, $lang) , 301); } } ?> namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\{Session, Redirect}; use App\Services\ApiService; class FixUrlsController extends Controller { private $apiService; public function __construct(ApiService $apiService) { $this->apiService = $apiService; } public function fixShortDiv(Request $request, $slug) { $selectedLang = Session::get('selected_lang'); $store = $this->apiService->getStore($slug, "slug") ; $title = $selectedLang == "ar" ? $store["title"] : $store["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('store', ['country' => $store["country"] , 'lang' => $selectedLang , 'storeName' => $title , 'store' => $store['id']]))); return Redirect::to($url , 301) ; } public function fixOffer(Request $request, $id, $slug) { $selectedCountry = Session::get('selected_country'); $selectedLang = Session::get('selected_lang'); // weird issue in tsawq links if(preg_match("/[0-9]+/" , $slug)) { $id = $slug ; } if( $topic = $this->apiService->getTopicById($id, $selectedCountry) ) { $title = $selectedLang == "ar" ? $topic["title"] : $topic["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('offer', ['country' => $topic["country"] , 'lang' => $selectedLang , 'offerName' => $title , 'offer' => $topic['id']]))); return Redirect::to($url , 301) ; } return Redirect::to("https://www.tsawq.net/{$selectedCountry}/{$selectedLang}/home" , 302) ; } public function fixAmp(Request $rquest, $id) { try { $selectedCountry = Session::get('selected_country'); $selectedLang = Session::get('selected_lang'); $topic = $this->apiService->getTopicById($id, $selectedCountry) ; $title = $selectedLang == "ar" ? $topic["title"] : $topic["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('offer', ['country' => $topic["country"] , 'lang' => $selectedLang , 'offerName' => $title , 'offer' => $topic['id']]))); $url = str_replace("amp." , "www." , $url) ; return Redirect::to($url , 301) ; } catch(\Exception $e) { \Log::error("something went wrong: " . $e->getMessage(). " >> " . request()->ip() ." url is >>" . request()->fullUrl()); return Redirect::to("https://www.tsawq.net/" , 302) ; } } public function fixDownload(Request $rquest) { $id = $_GET["id"] ; $selectedCountry = Session::get('selected_country'); $selectedLang = Session::get('selected_lang'); $topic = $this->apiService->getTopicById($id, $selectedCountry) ; $title = $selectedLang == "ar" ? $topic["title"] : $topic["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('download', ['country' => $topic["country"] , 'lang' => $selectedLang , 'offerName' => $title , 'offer' => $topic['id']]))); return Redirect::to($url , 301) ; } public function fixOthers(Request $request, $file) { $accepted = [ "showLatest" => "%s/%s/home" , "mostViewed" => "%s/%s/most-view-offers" , "important" => "%s/%s/latest" , "showTopic" => "%s/%s/offers/%s/%s" , "showDiv" => "%s/%s/store/%s/%s" ] ; ( ! ($path = $accepted[$file] ?? null) ) && abort(404); $url = parse_url($request->getRequestUri()); (!isset($url["query"]) && !in_array($file, ["showLatest" , "mostViewed" , "important"]) ) && abort(404); if(in_array($file, ["showLatest" , "mostViewed" , "important"]) && !isset($url["query"])) { $selectedCountry = Session::get('selected_country'); $selectedLang = Session::get('selected_lang'); $url = sprintf($accepted[$file], $selectedCountry, $selectedLang) ; return Redirect::to($url , 301) ; } parse_str($url["query"] , $query) ; if(strtolower($file) === "showtopic" ){ $selectedLang = Session::get('selected_lang'); $topic = $this->apiService->getTopicById($query["id"], "") ; $title = $selectedLang == "ar" ? $topic["title"] : $topic["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('offer', ['country' => $topic["country"] , 'lang' => $selectedLang , 'offerName' => $title , 'offer' => $topic['id']]))); return Redirect::to($url , 301) ; } if(strtolower($file) === "showdiv" ){ $selectedLang = Session::get('selected_lang'); $store = $this->apiService->getStore($query["id"], "id") ; $title = $selectedLang == "ar" ? $store["title"] : $store["translated_title"] ; $url = urldecode(str_replace('%20', '-', route('store', ['country' => $store["country"] , 'lang' => $selectedLang , 'storeName' => $title , 'store' => $store['id']]))); return Redirect::to($url , 301) ; } $lang = Session::get('selected_lang'); $country = $query["country"] ?? Session::get('selected_country'); if(isset($query["lang"])) { $lang = $query["lang"] ; } return Redirect::to( sprintf($path , $country, $lang) , 301); } } ?>