Skip to content

Commit

Permalink
refactor: rename noLocaleRoute to routeWithoutLocale
Browse files Browse the repository at this point in the history
  • Loading branch information
samberrry committed Jan 31, 2023
1 parent aa746c0 commit 5caff6a
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/Controllers/BinshopsReaderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function index($locale = null, Request $request, $category_slug = null)
'categories' => $rootList,
'posts' => $posts,
'title' => $title,
'noLocaleRoute' => $request->get("noLocaleRoute")
'routeWithoutLocale' => $request->get("routeWithoutLocale")
]);
}

Expand Down Expand Up @@ -116,7 +116,7 @@ public function search(Request $request)
'categories' => $rootList,
'query' => $query,
'search_results' => $search_results,
'noLocaleRoute' => $request->get("noLocaleRoute")
'routeWithoutLocale' => $request->get("routeWithoutLocale")
]
);
}
Expand Down Expand Up @@ -170,7 +170,7 @@ public function viewSinglePost(Request $request)
'captcha' => $captcha,
'categories' => $categories,
'locale' => $request->get("locale"),
'noLocaleRoute' => $request->get("noLocaleRoute")
'routeWithoutLocale' => $request->get("routeWithoutLocale")
]);
}
}
9 changes: 5 additions & 4 deletions src/Middleware/DetectLanguage.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace BinshopsBlog\Middleware;

use BinshopsBlog\Models\BinshopsConfiguration;
Expand All @@ -12,23 +11,25 @@ class DetectLanguage
public function handle($request, Closure $next)
{
$locale = $request->route('locale');
$noLocaleRoute = false;
$routeWithoutLocale = false;

if (!$request->route('locale')){
$noLocaleRoute = true;
$routeWithoutLocale = true;
$locale = BinshopsConfiguration::get('DEFAULT_LANGUAGE_LOCALE');
}

$lang = BinshopsLanguage::where('locale', $locale)
->where('active', true)
->first();

if (!$lang){
return abort(404);
}

$request->attributes->add([
'lang_id' => $lang->id,
'locale' => $lang->locale,
'noLocaleRoute' => $noLocaleRoute
'routeWithoutLocale' => $routeWithoutLocale
]);

return $next($request);
Expand Down
4 changes: 2 additions & 2 deletions src/Models/BinshopsCategoryTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function language()
* Returns the public facing URL of showing blog posts in this category
* @return string
*/
public function url($locale, $noLocaleRoute = false)
public function url($locale, $routeWithoutLocale = false)
{
$theChainString = "";
$cat = $this->category()->get();
Expand All @@ -44,7 +44,7 @@ public function url($locale, $noLocaleRoute = false)
$theChainString .= "/" . $category->categoryTranslations()->where('lang_id' , $this->lang_id)->first()->slug;
}

return $noLocaleRoute ? route("binshopsblog.view_category",["", $theChainString]) : route("binshopsblog.view_category",[$locale, $theChainString]);
return $routeWithoutLocale ? route("binshopsblog.view_category",["", $theChainString]) : route("binshopsblog.view_category",[$locale, $theChainString]);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Models/BinshopsPostTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ public function gen_seo_title()
*
* @return string
*/
public function url($loacle, $noLocaleRoute = false)
public function url($loacle, $routeWithoutLocale = false)
{
return $noLocaleRoute ? route("binshopsblog.single", ["", $this->slug]) : route("binshopsblog.single", [$loacle, $this->slug]);
return $routeWithoutLocale ? route("binshopsblog.single", ["", $this->slug]) : route("binshopsblog.single", [$loacle, $this->slug]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Views/binshopsblog/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class='btn border btn-outline-primary btn-sm '>
@include("binshopsblog::partials._category_partial", [
'category_tree' => $categories,
'name_chain' => $nameChain = "",
'noLocaleRoute' => $noLocaleRoute
'routeWithoutLocale' => $routeWithoutLocale
])
@else
<span>No Categories</span>
Expand Down
4 changes: 2 additions & 2 deletions src/Views/binshopsblog/partials/_category_partial.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<li class="category-item-wrapper">
@php $nameChain = $nameChain .'/'. $trans->slug @endphp

<a href="{{ $noLocaleRoute ? route("binshopsblog.view_category",["", $nameChain]) : route("binshopsblog.view_category",[$locale, $nameChain])}}">
<a href="{{ $routeWithoutLocale ? route("binshopsblog.view_category",["", $nameChain]) : route("binshopsblog.view_category",[$locale, $nameChain])}}">
<span class="category-item" value='{{$category->category_id}}'>
{{$trans->category_name}}

Expand All @@ -13,7 +13,7 @@
@include("binshopsblog::partials._category_partial", [
'category_tree' => $category->siblings,
'name_chain' => $nameChain,
'noLocaleRoute' => $noLocaleRoute
'routeWithoutLocale' => $routeWithoutLocale
])
</ul>
@endif
Expand Down
2 changes: 1 addition & 1 deletion src/Views/binshopsblog/partials/categories.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class=''>
@foreach($categories as $category)
<a class='btn btn-outline-secondary btn-sm m-1' href='{{$category->categoryTranslations[0]->url($locale, $noLocaleRoute)}}'>
<a class='btn btn-outline-secondary btn-sm m-1' href='{{$category->categoryTranslations[0]->url($locale, $routeWithoutLocale)}}'>
{{$category->categoryTranslations[0]->category_name}}
</a>
@endforeach
Expand Down
4 changes: 2 additions & 2 deletions src/Views/binshopsblog/partials/index_loop.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<?=$post->image_tag("medium", true, ''); ?>
</div>
<div class="blog-inner-item">
<h3 class=''><a href='{{$post->url($locale, $noLocaleRoute)}}'>{{$post->title}}</a></h3>
<h3 class=''><a href='{{$post->url($locale, $routeWithoutLocale)}}'>{{$post->title}}</a></h3>
<h5 class=''>{{$post->subtitle}}</h5>

@if (config('binshopsblog.show_full_text_at_list'))
Expand All @@ -21,7 +21,7 @@
<span class="light-text">Authored by: </span> {{$post->post->author->name}} <span class="light-text">Posted at: </span> {{date('d M Y ', strtotime($post->post->posted_at))}}
</div>
<div class='text-center'>
<a href="{{$post->url($locale, $noLocaleRoute)}}" class="btn btn-primary">View Post</a>
<a href="{{$post->url($locale, $routeWithoutLocale)}}" class="btn btn-primary">View Post</a>
</div>
</div>
</div>
Expand Down

0 comments on commit 5caff6a

Please sign in to comment.