Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
samberrry committed Dec 28, 2022
2 parents d79786d + 30ce041 commit ab91580
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 58 deletions.
18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Laravel Blog
Have you worked with Wordpress? Developers call this package wordpress-like laravel blog.

## [Installation Video - Less than 5 Minutes](https://youtu.be/N9NpFUqbftA)
[![Laravel Blog Package](http://img.youtube.com/vi/N9NpFUqbftA/0.jpg)](https://youtu.be/N9NpFUqbftA)

### Lightweight and Comprehensive

Incredible features with a lightweight laravel blog package. I highly recommend it because:
Incredible features with a lightweight laravel blog package.
- Quick installation (<3 minutes)
- It's very easy to extend
- Included great features out-of-box
Expand Down Expand Up @@ -132,7 +131,7 @@ You can see the single version in "single-lang" branch.
## What/who this package is for:

- For websites running Laravel
- Who wants to have a site blog. This laravel blog gives an easy to use interface to write blog posts/assign categories/manage existing posts
- Anyone, who wants to have a site blog. This laravel blog gives an easy to use interface to write blog posts/assign categories/manage existing posts
- Where only admin users can edit/manage the blog (this is not suitable for every user on your site to be able to manage posts)
- For anyone who likes to add a wordpress-like laravel blog to laravel website

Expand Down Expand Up @@ -201,8 +200,8 @@ Try adding this to config/app.php:
- Ensure that /public/blog_images (or whatever directory you set it to in the config) is writable by the server
- You might need to set a higher memory limit, or upload smaller image files. This will depend on your server. I've used it to upload huge (10mb+) jpg images without problem, once the server was set up correctly to handle larger file uploads.

## Version History
- **9.2.x** Stable version of package
## Version History
- **9.3.x** Stable version of package
- 9.0.x Multi-language support beta release
- 8.0.x Compatibility with Laravel 8
- 7.3.0 New Admin UI
Expand All @@ -212,12 +211,3 @@ Try adding this to config/app.php:
- 1.0.5 - composer.json changes.
- 1.0 - First release
- 0.1 - Initial release

## Contributors ✨
<table>
<tr>
<td align="center"><a href="https://github.com/samberrry"><img src="https://avatars.githubusercontent.com/u/20775532?v=4" width="80px;" alt=""/><br /><sub><b>Sam Berry</b></sub></a><br /></td>
<td align="center"><a href="https://github.com/dasscheman"><img src="https://avatars.githubusercontent.com/u/6064248?v=4" width="80px;" alt=""/><br /><sub><b>Alef Barbeli</b></sub></a><br /> </td>

</tr>
</table>
12 changes: 8 additions & 4 deletions src/Controllers/BinshopsReaderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct()
* @param null $category_slug
* @return mixed
*/
public function index($locale, Request $request, $category_slug = null)
public function index($locale = null, Request $request, $category_slug = null)
{
// the published_at + is_published are handled by BinshopsBlogPublishedScope, and don't take effect if the logged in user can manageb log posts

Expand Down Expand Up @@ -126,10 +126,12 @@ public function search(Request $request)
* @param $category_slug
* @return mixed
*/
public function view_category($locale, $hierarchy, Request $request)
public function view_category(Request $request)
{
$hierarchy = $request->route('subcategories');

$categories = explode('/', $hierarchy);
return $this->index($locale, $request, end($categories));
return $this->index($request->get('locale'), $request, end($categories));
}

/**
Expand All @@ -139,8 +141,10 @@ public function view_category($locale, $hierarchy, Request $request)
* @param $blogPostSlug
* @return mixed
*/
public function viewSinglePost(Request $request, $locale, $blogPostSlug)
public function viewSinglePost(Request $request)
{
$blogPostSlug = $request->route('blogPostSlug');

// the published_at + is_published are handled by BinshopsBlogPublishedScope, and don't take effect if the logged in user can manage log posts
$blog_post = BinshopsPostTranslation::where([
["slug", "=", $blogPostSlug],
Expand Down
16 changes: 14 additions & 2 deletions src/Middleware/DetectLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,33 @@

namespace BinshopsBlog\Middleware;

use BinshopsBlog\Models\BinshopsConfiguration;
use Closure;
use BinshopsBlog\Models\BinshopsLanguage;

class DetectLanguage
{
public function handle($request, Closure $next)
{
$lang = BinshopsLanguage::where('locale', $request->route('locale'))
$locale = $request->route('locale');
$noLocaleRoute = false;

if (!$request->route('locale')){
$noLocaleRoute = 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]);
$request->attributes->add([
'lang_id' => $lang->id,
'locale' => $lang->locale,
'noLocaleRoute' => $noLocaleRoute
]);

return $next($request);
}
Expand Down
7 changes: 3 additions & 4 deletions src/Models/BinshopsCategoryTranslation.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?php


namespace BinshopsBlog\Models;

use Illuminate\Database\Eloquent\Model;

class BinshopsCategoryTranslation extends Model
{

public $fillable = [
'category_id',
'category_name',
Expand Down Expand Up @@ -37,15 +35,16 @@ public function language()
* Returns the public facing URL of showing blog posts in this category
* @return string
*/
public function url($loacle)
public function url($locale, $noLocaleRoute = false)
{
$theChainString = "";
$cat = $this->category()->get();
$chain = $cat[0]->getAncestorsAndSelf();
foreach ($chain as $category){
$theChainString .= "/" . $category->categoryTranslations()->where('lang_id' , $this->lang_id)->first()->slug;
}
return route("binshopsblog.view_category",[$loacle, $theChainString]);

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

/**
Expand Down
8 changes: 3 additions & 5 deletions src/Models/BinshopsPostTranslation.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace BinshopsBlog\Models;

use Cviebrock\EloquentSluggable\Sluggable;
Expand Down Expand Up @@ -199,11 +198,9 @@ protected function check_valid_image_size(string $size = 'medium')
throw new \InvalidArgumentException("Invalid image size ($size). BinshopsPost image size should not begin with 'image_'. Remove this from the start of $size. It *should* be in the binshopsblog.image_sizes config though!");
}


throw new \InvalidArgumentException("BinshopsPost image size should be 'large','medium','thumbnail' or another field as defined in config/binshopsblog.php. Provided size ($size) is not valid");
}


/**
*
* If $this->seo_title was set, return that.
Expand All @@ -219,14 +216,15 @@ public function gen_seo_title()
}
return $this->title;
}

/**
* Returns the public facing URL to view this blog post
*
* @return string
*/
public function url($loacle)
public function url($loacle, $noLocaleRoute = false)
{
return route("binshopsblog.single", [$loacle, $this->slug]);
return $noLocaleRoute ? route("binshopsblog.single", ["", $this->slug]) : route("binshopsblog.single", [$loacle, $this->slug]);
}

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

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

@if( count($category->siblings) > 0)
<ul>
@include("binshopsblog::partials._category_partial", [
'category_tree' => $category->siblings,
'name_chain' => $nameChain
'name_chain' => $nameChain,
'noLocaleRoute' => $noLocaleRoute
])
</ul>
@endif
Expand Down
10 changes: 5 additions & 5 deletions src/Views/binshopsblog/partials/categories.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class=''>
@foreach($categories as $category)
<a class='btn btn-outline-secondary btn-sm m-1' href='{{$category->categoryTranslations[0]->url($locale)}}'>
{{$category->categoryTranslations[0]->category_name}}
</a>
@endforeach
@foreach($categories as $category)
<a class='btn btn-outline-secondary btn-sm m-1' href='{{$category->categoryTranslations[0]->url($locale, $noLocaleRoute)}}'>
{{$category->categoryTranslations[0]->category_name}}
</a>
@endforeach
</div>
2 changes: 1 addition & 1 deletion src/Views/binshopsblog/partials/disqus_comments.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus</a>, and run by <a href='https://binshops.binshops.com/'>BinshopsBlog Laravel Blog package</a></noscript>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus</a>, and run by <a href='https://binshops.com/'>BinshopsBlog Laravel Blog package</a></noscript>
7 changes: 3 additions & 4 deletions src/Views/binshopsblog/partials/index_loop.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{{--Used on the index page (so shows a small summary--}}
{{--See the guide on binshops.binshops.com for how to copy these files to your /resources/views/ directory--}}
{{--https://binshops.binshops.com/laravel-blog-package--}}
{{--See the guide on binshops.com for how to copy these files to your /resources/views/ directory--}}

<div class="col-md-6">
<div class="blog-item">
Expand All @@ -9,7 +8,7 @@
<?=$post->image_tag("medium", true, ''); ?>
</div>
<div class="blog-inner-item">
<h3 class=''><a href='{{$post->url($locale)}}'>{{$post->title}}</a></h3>
<h3 class=''><a href='{{$post->url($locale, $noLocaleRoute)}}'>{{$post->title}}</a></h3>
<h5 class=''>{{$post->subtitle}}</h5>

@if (config('binshopsblog.show_full_text_at_list'))
Expand All @@ -22,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)}}" class="btn btn-primary">View Post</a>
<a href="{{$post->url($locale, $noLocaleRoute)}}" class="btn btn-primary">View Post</a>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/Views/binshopsblog/partials/use_view_file.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{{--is logged in + canManageBinshopsBlogPosts() == true, so show a detailed error--}}
<div class='alert alert-danger'>Custom blog post blade view file
(<code>{{$post->full_view_file_path()}}</code>) not found. <a
href='https://binshops.binshops.com/laravel/packages/help-documentation/laravel-blog-package-binshopsblog'
href='https://github.com/binshops/laravel-blog'
target='_blank'>See Laravel Blog Package help here</a>.
</div>

Expand Down
4 changes: 2 additions & 2 deletions src/Views/binshopsblog/single_post.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</div>
@endif

{{--https://binshops.binshops.com/laravel/packages/binshopsblog-blog-system-for-your-laravel-app/help-documentation/laravel-blog-package-binshopsblog#guide_to_views--}}
{{--https://github.com/binshops/laravel-blog--}}

<div class='container'>
<div class='row'>
Expand Down Expand Up @@ -40,4 +40,4 @@

@section('blog-custom-js')
<script src="{{asset('binshops-blog.js')}}"></script>
@endsection
@endsection
33 changes: 20 additions & 13 deletions src/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,39 @@

Route::get('/category{subcategories}', 'BinshopsReaderController@view_category')->where('subcategories', '^[a-zA-Z0-9-_\/]+$')->name('binshopsblog.view_category');

// Route::get('/category/{categorySlug}',
// 'BinshopsReaderController@view_category')
// ->name('binshopsblog.view_category');

Route::get('/{blogPostSlug}',
'BinshopsReaderController@viewSinglePost')
->name('binshopsblog.single');


// throttle to a max of 10 attempts in 3 minutes:
Route::group(['middleware' => 'throttle:10,3'], function () {

Route::post('save_comment/{blogPostSlug}',
'BinshopsCommentWriterController@addNewComment')
->name('binshopsblog.comments.add_new_comment');
});
});

Route::group(['prefix' => config('binshopsblog.blog_prefix', 'blog')], function () {

});
Route::get('/', 'BinshopsReaderController@index')
->name('binshopsblognolocale.index');

});
Route::get('/search', 'BinshopsReaderController@search')
->name('binshopsblognolocale.search');

Route::get('/category{subcategories}', 'BinshopsReaderController@view_category')->where('subcategories', '^[a-zA-Z0-9-_\/]+$')->name('binshopsblognolocale.view_category');

Route::get('/{blogPostSlug}',
'BinshopsReaderController@viewSinglePost')
->name('binshopsblognolocale.single');

// throttle to a max of 10 attempts in 3 minutes:
Route::group(['middleware' => 'throttle:10,3'], function () {
Route::post('save_comment/{blogPostSlug}',
'BinshopsCommentWriterController@addNewComment')
->name('binshopsblognolocale.comments.add_new_comment');
});
});

/* Admin backend routes - CRUD for posts, categories, and approving/deleting submitted comments */
Route::group(['prefix' => config('binshopsblog.admin_prefix', 'blog_admin')], function () {
Expand Down Expand Up @@ -83,10 +95,8 @@

Route::get("/upload", "BinshopsImageUploadController@create")->name("binshopsblog.admin.images.upload");
Route::post("/upload", "BinshopsImageUploadController@store")->name("binshopsblog.admin.images.store");

});


Route::delete('/delete_post/{blogPostId}',
'BinshopsAdminController@destroy_post')
->name('binshopsblog.admin.destroy_post');
Expand Down Expand Up @@ -129,10 +139,8 @@
Route::delete('/delete_category/{categoryId}',
'BinshopsCategoryAdminController@destroy_category')
->name('binshopsblog.admin.categories.destroy_category');

});


Route::group(['prefix' => 'languages'], function () {

Route::get('/',
Expand All @@ -153,7 +161,6 @@
Route::post('/toggle_language/{languageId}',
'BinshopsLanguageAdminController@toggle_language')
->name('binshopsblog.admin.languages.toggle_language');

});
});
});
Expand Down

0 comments on commit ab91580

Please sign in to comment.