Skip to content

Commit

Permalink
Merge pull request #307 from juzaweb/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
juzaweb committed Feb 18, 2023
2 parents 6295eba + 5cae226 commit 7d137ac
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 55 deletions.
9 changes: 6 additions & 3 deletions README.md
Expand Up @@ -8,8 +8,8 @@ JUZACMS - Laravel CMS for Your Project
[![GitHub followers](https://img.shields.io/github/followers/juzaweb?style=social)](https://github.com/juzaweb)
[![YouTube Channel Subscribers](https://img.shields.io/youtube/channel/subscribers/UCo6Dz9HjjBOJpgWsxkln0-A?style=social)](https://www.youtube.com/@juzaweb)

- [JuzaWeb CMS](https://juzaweb.com) is a Content Management System ([Laravel CMS](https://juzaweb.com)) like WordPress developed based on Laravel Framework 9 and web platform whose sole purpose is to make your development workflow simple again.
- JuzaWeb CMS was engineered to be easy — for both developers and users. Project develop by Juzaweb.
- [JuzaWeb CMS](https://juzaweb.com) is a Content Management System (CMS) like WordPress developed based on Laravel Framework 9 and web platform whose sole purpose is to make your development workflow simple again.
- JuzaWeb CMS is a [Laravel CMS](https://juzaweb.com) was engineered to be easy — for both developers and users. Project develop by Juzaweb Team.
- Demo Site:
- Frontend: https://cms.juzaweb.com
- Admin:
Expand Down Expand Up @@ -97,7 +97,7 @@ View all [JuzaWeb CMS documentation](https://juzaweb.com/documentation/plugin/cm
* [Ads Manager](https://github.com/juzaweb/ads-manager)
* [Demo Site](https://github.com/juzaweb/demo-site)

## Theme
## Include Themes
### Default
### Gamxo

Expand All @@ -109,3 +109,6 @@ View all [JuzaWeb CMS documentation](https://juzaweb.com/documentation/plugin/cm

## Change Logs
[https://juzaweb.com/documentation/changelog](https://juzaweb.com/documentation/changelog)

## Buy me coffee
[![Juzaweb Buy me coffee](https://i.imgur.com/MAqboRu.png)](https://buymeacoffee.com/juzaweb)
13 changes: 13 additions & 0 deletions modules/Backend/Models/Comment.php
Expand Up @@ -6,6 +6,7 @@
use Juzaweb\CMS\Facades\HookAction;
use Juzaweb\CMS\Models\Model;
use Juzaweb\CMS\Models\User;
use Juzaweb\CMS\Traits\QueryCache\QueryCacheable;

/**
* Juzaweb\Backend\Models\Comment
Expand Down Expand Up @@ -44,7 +45,12 @@
*/
class Comment extends Model
{
use QueryCacheable;

public string $cachePrefix = 'comments_';

protected $table = 'comments';

protected $fillable = [
'email',
'name',
Expand Down Expand Up @@ -116,4 +122,11 @@ public static function allStatuses()
]
);
}

protected function getCacheBaseTags(): array
{
return [
'comments',
];
}
}
3 changes: 1 addition & 2 deletions modules/Backend/Models/EmailList.php
Expand Up @@ -42,9 +42,8 @@
* @method static \Illuminate\Database\Eloquent\Builder|EmailList whereUpdatedAt($value)
* @mixin \Eloquent
* @method static \Illuminate\Database\Eloquent\Builder|EmailList whereSiteId($value)
* @method static \Illuminate\Database\Eloquent\Builder|EmailList WhereTemplate($code)
* @method static \Illuminate\Database\Eloquent\Builder|EmailList whereTemplate($code)
* @property int|null $site_id
* @method static Builder|EmailList whereTemplate(string $code)
* @method static Builder|EmailList whereTemplateCode($value)
*/
class EmailList extends Model implements RootNetworkModelInterface
Expand Down
16 changes: 8 additions & 8 deletions modules/Backend/Repositories/PostRepository.php
Expand Up @@ -19,21 +19,21 @@ interface PostRepository extends BaseRepository
public function create(array $attributes);

public function update(array $attributes, $id);
public function findBySlug(string $slug): null|Post;
public function frontendListByTaxonomyPaginate(int $limit, int $taxonomy): LengthAwarePaginator;

public function findBySlug(string $slug, $fail = true): null|Post;

public function frontendListByTaxonomyPaginate(int $limit, int $taxonomy, ?int $page = null): LengthAwarePaginator;

/**
* @param int $limit
* @return LengthAwarePaginator
* @throws RepositoryException
*/
public function frontendListPaginate(int $limit): LengthAwarePaginator;

public function createSelectFrontendBuilder(): Builder|Taxonomy;

public function createFrontendDetailBuilder(): Builder;

public function getStatuses(string $type = 'posts'): array;
}
52 changes: 28 additions & 24 deletions modules/Backend/Repositories/PostRepositoryEloquent.php
Expand Up @@ -17,52 +17,56 @@
class PostRepositoryEloquent extends BaseRepositoryEloquent implements PostRepository
{
use UseSearchCriteria, UseFilterCriteria, UseSortableCriteria;

protected array $searchableFields = ['title', 'description'];
protected array $filterableFields = ['status', 'type'];
protected array $sortableFields = ['id', 'status', 'title', 'views'];
protected array $sortableDefaults = ['id' => 'DESC'];

public function model(): string
{
return Post::class;
}
public function findBySlug(string $slug): null|Post

public function findBySlug(string $slug, $fail = true): null|Post
{
$result = $this->createFrontendDetailBuilder()->where(['slug' => $slug])->firstOrFail();

if ($fail) {
$result = $this->createFrontendDetailBuilder()->where(['slug' => $slug])->firstOrFail();
} else {
$result = $this->createFrontendDetailBuilder()->where(['slug' => $slug])->first();
}

return $this->parserResult($result);
}

public function frontendListPaginate(int $limit): LengthAwarePaginator
{
$this->applyCriteria();
$this->applyScope();

$result = $this->createSelectFrontendBuilder()->paginate($limit);

$this->resetModel();
$this->resetScope();

return $this->parserResult($result);
}
public function frontendListByTaxonomyPaginate(int $limit, int $taxonomy): LengthAwarePaginator

public function frontendListByTaxonomyPaginate(int $limit, int $taxonomy, ?int $page = null): LengthAwarePaginator
{
$this->applyCriteria();
$this->applyScope();

$result = $this->createSelectFrontendBuilder()
->whereTaxonomy($taxonomy)
->paginate($limit);
->paginate($limit, [], 'page', $page);

$this->resetModel();
$this->resetScope();

return $this->parserResult($result);
}

public function createSelectFrontendBuilder(): Builder|Taxonomy
{
$builder = $this->model->newQuery()->with($this->withFrontendDefaults())
Expand All @@ -85,19 +89,19 @@ public function createSelectFrontendBuilder(): Builder|Taxonomy
]
)
->wherePublish();

return apply_filters('post.selectFrontendBuilder', $builder);
}

public function createFrontendDetailBuilder(): Builder
{
$builder = $this->model->newQuery()->with($this->withFrontendDefaults())
->cacheFor(3600)
->cacheFor(config('juzaweb.performance.query_cache.lifetime', 3600))
->whereIn('status', [Post::STATUS_PUBLISH, Post::STATUS_PRIVATE]);

return apply_filters('post.createFrontendDetailBuilder', $builder);
}

public function withFrontendDefaults(): array
{
return [
Expand All @@ -109,7 +113,7 @@ public function withFrontendDefaults(): array
},
];
}

public function getStatuses(string $type = 'posts'): array
{
$statuses = [
Expand All @@ -118,7 +122,7 @@ public function getStatuses(string $type = 'posts'): array
Post::STATUS_DRAFT => trans('cms::app.draft'),
Post::STATUS_TRASH => trans('cms::app.trash'),
];

return apply_filters($type.'.statuses', $statuses);
}
}
2 changes: 1 addition & 1 deletion modules/CMS/Version.php
Expand Up @@ -14,6 +14,6 @@ class Version
{
public static function getVersion(): string
{
return 'v3.3.4';
return 'v3.3.5';
}
}
3 changes: 2 additions & 1 deletion modules/CMS/config/juzaweb.php
Expand Up @@ -200,7 +200,7 @@
*
* Default: true
*/
'image_resizer' => env('JW_IMAGE_RESIZER', true),
'image_resizer' => env('JW_IMAGE_RESIZER', false),

/**
* File type
Expand Down Expand Up @@ -231,6 +231,7 @@
* Default: 5 (MB)
*/
'max_size' => env('JW_MEDIA_IMAGE_MAX_SIZE', 5),

'valid_mime' => [
...Facades::defaultImageMimetypes(),
//
Expand Down
22 changes: 13 additions & 9 deletions modules/Frontend/Http/Controllers/PostController.php
Expand Up @@ -31,7 +31,7 @@ class PostController extends FrontendController
public function __construct(protected PostRepository $postRepository)
{
}

public function index(...$slug)
{
if (count($slug) > 1) {
Expand Down Expand Up @@ -59,13 +59,13 @@ public function index(...$slug)
public function detail(...$slug)
{
do_action("frontend.post_type.detail", $slug);

$base = Arr::get($slug, 0);
$postSlug = $this->getPostSlug($slug);
$permalink = $this->getPermalinks($base);

$postType = HookAction::getPostTypes($permalink->get('post_type'));

do_action(
"frontend.post_type.{$permalink->get('post_type')}.detail",
$slug,
Expand All @@ -76,8 +76,11 @@ public function detail(...$slug)
/**
* @var Post $postModel
*/
$postModel = $this->postRepository->findBySlug($postSlug);

$postModel = $this->postRepository->findBySlug($postSlug, false);
if (empty($postModel) && count($slug) > 2) {
$postModel = $this->postRepository->findBySlug($slug[1]);
}

Facades::$isPostPage = true;

Facades::$post = $postModel;
Expand All @@ -92,6 +95,7 @@ public function detail(...$slug)
$post = (new PostResource($postModel))->toArray(request());

$rows = Comment::with(['user'])
->cacheFor(config('juzaweb.performance.query_cache.lifetime'))
->where(['object_id' => $post['id']])
->whereApproved()
->paginate(10);
Expand Down Expand Up @@ -138,7 +142,7 @@ public function comment(CommentRequest $request, $slug): JsonResponse|RedirectRe
]
);
}

$post = $this->postRepository->findBySlug($slug);
$data = $request->all();
$data['object_type'] = $permalink->get('post_type');
Expand All @@ -150,11 +154,11 @@ public function comment(CommentRequest $request, $slug): JsonResponse|RedirectRe

return $this->success(trans('cms::app.comment_success'));
}

private function getPostSlug(array $slug): string
{
unset($slug[0]);

return implode('/', $slug);
}
}
15 changes: 11 additions & 4 deletions modules/Frontend/Http/Controllers/TaxonomyController.php
Expand Up @@ -18,22 +18,29 @@ public function __construct(
protected TaxonomyRepository $taxonomyRepository
) {
}

public function index(...$slug): string
{
$taxSlug = Arr::get($slug, 1);

$currentPage = Arr::get($slug, count($slug) - 1);
if (str_contains($currentPage, 'page-')) {
$currentPage = (int) str_replace('page-', '', $currentPage);
} else {
$currentPage = null;
}

$taxonomy = $this->taxonomyRepository->findBySlug($taxSlug);

Facades::$isTaxonomyPage = true;

Facades::$taxonomy = $taxonomy;

$title = $taxonomy->getName();

$posts = $this->postRepository->frontendListByTaxonomyPaginate(
get_config('posts_per_page', 12),
$taxonomy->id
$taxonomy->id,
$currentPage
);

$template = get_name_template_part(
Expand Down
5 changes: 2 additions & 3 deletions modules/Frontend/routes/theme.php
@@ -1,5 +1,4 @@
<?php

/**
* JUZAWEB CMS - Laravel CMS for Your Project
*
Expand Down Expand Up @@ -47,12 +46,12 @@
Route::get('taxonomy/{taxonomy}/feed', [FeedController::class, 'taxonomy'])->name('feed.taxonomy');

Route::match(
['get', 'post'],
['get', 'post', 'put'],
'ajax/{slug}',
[AjaxController::class, 'ajax']
)
->name('ajax')
->where('slug', '[a-z\-\/]+');
->where('slug', '[a-z0-9\-\/]+');

Route::get('/', [HomeController::class, 'index'])->name('home');

Expand Down

0 comments on commit 7d137ac

Please sign in to comment.