diff --git a/resources/views/front/articles/show.blade.php b/resources/views/front/articles/show.blade.php
index b34ebea..dec32b9 100644
--- a/resources/views/front/articles/show.blade.php
+++ b/resources/views/front/articles/show.blade.php
@@ -15,116 +15,144 @@
@push('styles')
@endpush
+
@push('scripts')
-
+
@endpush
+
diff --git a/resources/views/partials/tailwindPaginationAlpinejs.blade.php b/resources/views/partials/tailwindPaginationAlpinejs.blade.php
new file mode 100644
index 0000000..05467f9
--- /dev/null
+++ b/resources/views/partials/tailwindPaginationAlpinejs.blade.php
@@ -0,0 +1,72 @@
+@if ($paginator->hasPages())
+
+
+
+
+ @if ($paginator->onFirstPage())
+
+ Previous
+
+ @else
+
+ @endif
+
+
+
+ @foreach ($elements as $element)
+
+ @if (is_string($element))
+
{{ $element }}
+ @endif
+
+
+ @if (is_array($element))
+ @foreach ($element as $page => $url)
+ @if ($page == $paginator->currentPage())
+
{{ $page }}
+ @else
+
+ @endif
+ @endforeach
+ @endif
+ @endforeach
+
+
+
+ @if ($paginator->hasMorePages())
+
+ @else
+
+ Next
+
+ @endif
+
+
+
+
+ Showing {{ $paginator->firstItem() }} to {{ $paginator->lastItem() }} of {{ $paginator->total() }} results
+
+
+
+@endif
\ No newline at end of file
diff --git a/resources/views/seo/index.blade.php b/resources/views/seo/index.blade.php
index 59fbc6d..dcce8c4 100644
--- a/resources/views/seo/index.blade.php
+++ b/resources/views/seo/index.blade.php
@@ -48,7 +48,7 @@ class="bg-gray-800 text-white"
@empty
-
No page found.
+
No page created yet.
@endforelse
@endsection
diff --git a/routes/web.php b/routes/web.php
index 6cdb446..2eaa6c6 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -41,7 +41,7 @@
Route::group(['middleware' => 'HtmlMinifier'], function () {
Route::get('/blog', 'Front\ArticleController@index')->name('blog');
Route::get('/blog/{article}', 'Front\ArticleController@show')->name('blog.show');
- Route::get('/partials/blog', 'Front\ArticleController@articles')->name('blog.partial');
+ // Route::get('/partials/blog', 'Front\ArticleController@articles')->name('blog.partial');
});
// Contact us
@@ -65,8 +65,8 @@
// Partial Views
- Route::get('/partials/articles', 'ArticleController@articles');
- Route::get('/partials/contacts', 'ContactController@contacts');
+ // Route::get('/partials/articles', 'ArticleController@articles');
+ // Route::get('/partials/contacts', 'ContactController@contacts');
// Page
Route::get('/pages', 'PageController@index')->name('pages.index');
@@ -101,7 +101,7 @@
// Media
Route::get('/media', 'MediaController@index')->name('media');
- Route::get('/partials/media', 'MediaController@media');
+ // Route::get('/partials/media', 'MediaController@media');
Route::post('/media/upload', 'MediaController@store')->name('media.store');
Route::post('/media/image/delete', 'MediaController@destroy')->name('media.destroy');
});
diff --git a/src/Controllers/ArticleController.php b/src/Controllers/ArticleController.php
index b71e778..8708e51 100644
--- a/src/Controllers/ArticleController.php
+++ b/src/Controllers/ArticleController.php
@@ -13,26 +13,40 @@
class ArticleController extends Controller
{
- public function index()
+ public function index(Request $request)
{
- $articles = Article::with('category')->orderByDesc('publish_date')->paginate(10);
+ $article = Article::query();
- return view('flowcms::articles.index', compact('articles'));
- }
+ if ($request->ajax()) {
+ if($search = request('s')) {
+ $article->where('title', 'like', '%' . $search . '%');
+ }
- public function articles()
- {
- $article = Article::with('category')->orderByDesc('publish_date');
+ $articles = $article->latest('publish_date')->paginate(10);
+ $articles->load('category');
- if ($search = request('s')) {
- $article->where('title', 'like', '%' . $search . '%');
+ return view('flowcms::articles._articles', compact('articles'))->render();
}
- $articles = $article->paginate(10);
+ $articles = $article->latest('publish_date')->paginate(10);
+ $articles->load('category');
- return view('flowcms::articles._articles', compact('articles'));
+ return view('flowcms::articles.index', compact('articles'));
}
+ // public function articles()
+ // {
+ // $article = Article::with('category')->orderByDesc('publish_date');
+
+ // if ($search = request('s')) {
+ // $article->where('title', 'like', '%' . $search . '%');
+ // }
+
+ // $articles = $article->paginate(10);
+
+ // return view('flowcms::articles._articles', compact('articles'));
+ // }
+
public function create()
{
$categories = Category::orderBy('name')->get();
diff --git a/src/Controllers/ContactController.php b/src/Controllers/ContactController.php
index 3602d24..62a32d1 100644
--- a/src/Controllers/ContactController.php
+++ b/src/Controllers/ContactController.php
@@ -12,28 +12,32 @@ class ContactController extends Controller
{
use ValidatesRequests;
- public function index()
+ public function index(Request $request)
{
- $contacts = Contact::latest()->paginate(10);
+ $contact = Contact::query();
- return view('flowcms::contacts.index', compact('contacts'));
- }
+ if ($request->ajax()) {
+ if ($search = request('s')) {
+ $contact->where('name', 'like', '%' . $search . '%');
+ $contact->orWhere('email', 'like', '%' . $search . '%');
+ $contact->orWhere('body', 'like', '%' . $search . '%');
+ }
- public function contacts()
- {
- $contact = Contact::query();
+ $contacts = $contact->latest()->paginate(10);
- if ($search = request('s')) {
- $contact->where('name', 'like', '%' . $search . '%');
- $contact->orWhere('email', 'like', '%' . $search . '%');
- $contact->orWhere('body', 'like', '%' . $search . '%');
+ return view('flowcms::contacts._contacts', compact('contacts'));
}
$contacts = $contact->latest()->paginate(10);
- return view('flowcms::contacts._contacts', compact('contacts'));
+ return view('flowcms::contacts.index', compact('contacts'));
}
+ // public function contacts()
+ // {
+
+ // }
+
public function store(Request $request)
{
$cmsblocks = collect(config('cms.blocks.contact_us'))->all();
diff --git a/src/Controllers/Front/ArticleController.php b/src/Controllers/Front/ArticleController.php
index e34911c..fe18e03 100644
--- a/src/Controllers/Front/ArticleController.php
+++ b/src/Controllers/Front/ArticleController.php
@@ -21,6 +21,10 @@ public function index()
->paginate(10);
});
+ if (request()->ajax()) {
+ return view('flowcms::front.articles._articles', compact('articles'))->render();
+ }
+
return view('flowcms::front.articles.index', compact('articles'));
}
@@ -37,7 +41,14 @@ public function show($article)
return $articleFound;
});
- return view('flowcms::front.articles.show', compact('article'));
+ $previous = Article::where('id', '<', $article->id)->orderBy('id','desc')->isPublished()->first();
+ $next = Article::where('id', '>', $article->id)->orderBy('id')->isPublished()->first();
+
+ return view('flowcms::front.articles.show', [
+ 'article' => $article,
+ 'previous' => $previous,
+ 'next' => $next
+ ]);
}
public function articles()
diff --git a/src/Controllers/MediaController.php b/src/Controllers/MediaController.php
index 1be3a5d..0856116 100644
--- a/src/Controllers/MediaController.php
+++ b/src/Controllers/MediaController.php
@@ -9,25 +9,36 @@
class MediaController extends Controller
{
- public function index()
- {
- $medias = Media::latest()->paginate(12);
- return view('flowcms::media.index', compact('medias'));
- }
-
- public function media(Request $request)
+ public function index(Request $request)
{
$media = Media::query();
- if ($search = request('s')) {
- $media->where('name', 'like', '%' . $search . '%');
+ if ($request->ajax()) {
+ if ($search = request('s')) {
+ $media->where('name', 'like', '%' . $search . '%');
+ }
+
+ $medias = $media->latest()->paginate(12);
+ return view('flowcms::media._media', compact('medias'))->render();
}
$medias = $media->latest()->paginate(12);
-
- return view('flowcms::media._media', compact('medias'));
+ return view('flowcms::media.index', compact('medias'));
}
+ // public function media(Request $request)
+ // {
+ // $media = Media::query();
+
+ // if ($search = request('s')) {
+ // $media->where('name', 'like', '%' . $search . '%');
+ // }
+
+ // $medias = $media->latest()->paginate(12);
+
+ // return view('flowcms::media._media', compact('medias'));
+ // }
+
public function store(Request $request)
{
if ($request->has('file')) {
diff --git a/src/Controllers/PageController.php b/src/Controllers/PageController.php
index 1d2c992..62e5660 100644
--- a/src/Controllers/PageController.php
+++ b/src/Controllers/PageController.php
@@ -97,7 +97,8 @@ public function store(Request $request)
$validated = $this->validate($request, [
'title' => [
'required',
- Rule::unique('pages')
+ Rule::unique('pages'),
+ Rule::notIn(['home', 'Home', 'page', 'Page', 'blog', 'Blog', 'article', 'Article'])
]
]);
diff --git a/src/FlowcmsServiceProvider.php b/src/FlowcmsServiceProvider.php
index 76acdbf..3cde121 100755
--- a/src/FlowcmsServiceProvider.php
+++ b/src/FlowcmsServiceProvider.php
@@ -15,6 +15,7 @@ class FlowcmsServiceProvider extends ServiceProvider
private const FLOWCOMPONENTS = [
"alert",
"badge",
+ "base-datatable",
"button",
"card",
"checkbox",
diff --git a/src/Helpers/functions.php b/src/Helpers/functions.php
index fed64e4..22002a1 100644
--- a/src/Helpers/functions.php
+++ b/src/Helpers/functions.php
@@ -53,12 +53,16 @@ function responsive_image($imageUrl)
}
if (collect([$imageSavedUrl, $imageSavedSecureUrl])->contains(request()->root()) && $storageFolderPath != 'cms') {
- $imageUrl = explode(config('app.url') . '/storage/', $imageUrl);
+ if (Str::contains($imageUrl, 'storage')) {
+ $filename = explode(config('app.url') . '/storage/', $imageUrl)[1];
+ } else {
+ $filename = explode(config('app.url') . '/', $imageUrl)[1];
+ }
return [
- 'small' => url('/img/' . $imageUrl[1] . '?w=320'),
- 'medium' => url('/img/' . $imageUrl[1] . '?w=640'),
- 'large' => url('/img/' . $imageUrl[1] . '?w=1024'),
+ 'small' => url('/img/' . $filename . '?w=320'),
+ 'medium' => url('/img/' . $filename . '?w=640'),
+ 'large' => url('/img/' . $filename . '?w=1024'),
// 'xlarge' => url('/img/' . $imageUrl[1] .'?w=1200'),
];
}
diff --git a/src/Models/Article.php b/src/Models/Article.php
index f84c8db..ecf3683 100644
--- a/src/Models/Article.php
+++ b/src/Models/Article.php
@@ -3,6 +3,7 @@
namespace Flowcms\Flowcms\Models;
use Illuminate\Support\Str;
+use Flowcms\Flowcms\Traits\MoveUploadedFromTempToDestination;
use Illuminate\Support\Facades\Cache;
use Illuminate\Database\Eloquent\Model;
use CyrildeWit\EloquentViewable\InteractsWithViews;
@@ -10,7 +11,7 @@
class Article extends Model implements Viewable
{
- use InteractsWithViews;
+ use InteractsWithViews, MoveUploadedFromTempToDestination;
/**
* The attributes that are mass assignable.
@@ -60,7 +61,8 @@ class Article extends Model implements Viewable
'article_summary',
'links',
'images',
- 'article_with_responsive_images'
+ 'article_with_responsive_images',
+ 'article_views'
];
protected static function boot()
@@ -111,6 +113,11 @@ public function getLinksAttribute()
];
}
+ public function getArticleViewsAttribute()
+ {
+ return views($this)->unique()->count() ?? 0;
+ }
+
public function getImagesAttribute()
{
if ($this->image === '') {
diff --git a/src/Traits/MoveUploadedFromTempToDestination.php b/src/Traits/MoveUploadedFromTempToDestination.php
new file mode 100644
index 0000000..4acad13
--- /dev/null
+++ b/src/Traits/MoveUploadedFromTempToDestination.php
@@ -0,0 +1,85 @@
+body, 'HTML-ENTITIES', 'UTF-8');
+
+ // creating new document
+ $doc = new \DOMDocument('1.0', 'UTF-8');
+
+ //turning off some errors
+ libxml_use_internal_errors(true);
+
+ // root node is required
+ $doc->loadHTML('
' . $html . '
');
+
+ //turning off some errors
+ libxml_clear_errors();
+
+ $tags = $doc->getElementsByTagName('img');
+
+ foreach ($tags as $tag) {
+ $oldSrc = $tag->getAttribute('src');
+
+ if (Storage::disk('public')->exists($oldSrc)) {
+ $newSrc = '/editor-uploads/' . explode('/', $oldSrc)[2];
+
+ if (! Storage::disk('public')->exists($newSrc)) {
+ Storage::disk('public')->move($oldSrc, $newSrc);
+ }
+
+ $tag->setAttribute('src', $newSrc);
+ $tag->setAttribute('loading', 'lazy');
+ }
+ }
+
+ $model->body = substr($doc->saveXML($doc->getElementsByTagName('div')->item(0)), 5, -6);
+ });
+
+ static::updating(function ($model) {
+
+ // converts all special characters to utf-8
+ $html = mb_convert_encoding($model->body, 'HTML-ENTITIES', 'UTF-8');
+
+ // creating new document
+ $doc = new \DOMDocument('1.0', 'UTF-8');
+
+ //turning off some errors
+ libxml_use_internal_errors(true);
+
+ // root node is required
+ $doc->loadHTML('
' . $html . '
');
+
+ //turning off some errors
+ libxml_clear_errors();
+
+ $tags = $doc->getElementsByTagName('img');
+
+ foreach ($tags as $tag) {
+ $oldSrc = $tag->getAttribute('src');
+
+ if (Storage::disk('public')->exists($oldSrc)) {
+ $newSrc = '/editor-uploads/' . explode('/', $oldSrc)[2];
+
+ if (! Storage::disk('public')->exists($newSrc)) {
+ Storage::disk('public')->move($oldSrc, $newSrc);
+ }
+
+ $tag->setAttribute('src', $newSrc);
+ $tag->setAttribute('loading', 'lazy');
+ }
+ }
+
+ $model->body = substr($doc->saveXML($doc->getElementsByTagName('div')->item(0)), 5, -6);
+ });
+ }
+ }
\ No newline at end of file