262 lines
8.8 KiB
PHP
262 lines
8.8 KiB
PHP
<?php
|
|
|
|
|
|
namespace App\PageBuilder\Addons\Blog;
|
|
use App\Blog;
|
|
use App\BlogCategory;
|
|
use App\Helpers\LanguageHelper;
|
|
use App\Helpers\SanitizeInput;
|
|
use App\PageBuilder\Fields\IconPicker;
|
|
use App\PageBuilder\Fields\Image;
|
|
use App\PageBuilder\Fields\NiceSelect;
|
|
use App\PageBuilder\Fields\Notice;
|
|
use App\PageBuilder\Fields\Number;
|
|
use App\PageBuilder\Fields\Select;
|
|
use App\PageBuilder\Fields\Slider;
|
|
use App\PageBuilder\Fields\Switcher;
|
|
use App\PageBuilder\Fields\Text;
|
|
use App\PageBuilder\Fields\Textarea;
|
|
use App\PageBuilder\PageBuilderBase;
|
|
use Illuminate\Support\Str;
|
|
|
|
class BlogGridStyleThree extends PageBuilderBase
|
|
{
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function preview_image()
|
|
{
|
|
return 'blog/slider-04.png';
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function admin_render()
|
|
{
|
|
$output = $this->admin_form_before();
|
|
$output .= $this->admin_form_start();
|
|
$output .= $this->default_fields();
|
|
$widget_saved_values = $this->get_settings();
|
|
|
|
|
|
$output .= $this->admin_language_tab(); //have to start language tab from here on
|
|
$output .= $this->admin_language_tab_start();
|
|
|
|
$all_languages = LanguageHelper::all_languages();
|
|
foreach ($all_languages as $key => $lang) {
|
|
$output .= $this->admin_language_tab_content_start([
|
|
'class' => $key == 0 ? 'tab-pane fade show active' : 'tab-pane fade',
|
|
'id' => "nav-home-" . $lang->slug
|
|
]);
|
|
$output .= Text::get([
|
|
'name' => 'readmore_text_'.$lang->slug,
|
|
'label' => __('Read More Text'),
|
|
'value' => $widget_saved_values['readmore_text_' . $lang->slug] ?? null,
|
|
]);
|
|
$categories = BlogCategory::where(['status' => 'publish','lang' => $lang->slug])->get()->pluck('name', 'id')->toArray();
|
|
$output .= NiceSelect::get([
|
|
'name' => 'categories_'.$lang->slug,
|
|
'multiple' => true,
|
|
'label' => __('Category'),
|
|
'placeholder' => __('Select Category'),
|
|
'options' => $categories,
|
|
'value' => $widget_saved_values['categories_'.$lang->slug] ?? null,
|
|
'info' => __('you can select category for blog, if you want to show all event leave it empty')
|
|
]);
|
|
$output .= $this->admin_language_tab_content_end();
|
|
}
|
|
$output .= $this->admin_language_tab_end(); //have to end language tab
|
|
|
|
$output .= Select::get([
|
|
'name' => 'order_by',
|
|
'label' => __('Order By'),
|
|
'options' => [
|
|
'id' => __('ID'),
|
|
'created_at' => __('Date'),
|
|
],
|
|
'value' => $widget_saved_values['order_by'] ?? null,
|
|
'info' => __('set order by')
|
|
]);
|
|
$output .= Select::get([
|
|
'name' => 'order',
|
|
'label' => __('Order'),
|
|
'options' => [
|
|
'asc' => __('Accessing'),
|
|
'desc' => __('Decreasing'),
|
|
],
|
|
'value' => $widget_saved_values['order'] ?? null,
|
|
'info' => __('set order')
|
|
]);
|
|
$output .= Select::get([
|
|
'name' => 'theme',
|
|
'label' => __('Theme'),
|
|
'options' => [
|
|
'lawyer-home' => __('Style 01'),
|
|
'political-home' => __('Style 02'),
|
|
],
|
|
'value' => $widget_saved_values['theme'] ?? null,
|
|
]);
|
|
|
|
$output .= Number::get([
|
|
'name' => 'items',
|
|
'label' => __('Items'),
|
|
'value' => $widget_saved_values['items'] ?? null,
|
|
'info' => __('enter how many item you want to show in frontend'),
|
|
]);
|
|
|
|
$output .= Select::get([
|
|
'name' => 'columns',
|
|
'label' => __('Column'),
|
|
'options' => [
|
|
'col-lg-3' => __('04 Column'),
|
|
'col-lg-4' => __('03 Column'),
|
|
'col-lg-6' => __('02 Column'),
|
|
],
|
|
'value' => $widget_saved_values['columns'] ?? null,
|
|
'info' => __('set column')
|
|
]);
|
|
$output .= Notice::get([
|
|
'type' => 'secondary',
|
|
'text' => __('Pagination Settings')
|
|
]);
|
|
$output .= Switcher::get([
|
|
'name' => 'pagination_status',
|
|
'label' => __('Enable/Disable Pagination'),
|
|
'value' => $widget_saved_values['pagination_status'] ?? null,
|
|
'info' => __('your can show/hide pagination'),
|
|
]);
|
|
$output .= Select::get([
|
|
'name' => 'pagination_alignment',
|
|
'label' => __('Pagination Alignment'),
|
|
'options' => [
|
|
'text-left' => __('Left'),
|
|
'text-center' => __('Center'),
|
|
'text-right' => __('Right'),
|
|
],
|
|
'value' => $widget_saved_values['pagination_alignment'] ?? null,
|
|
'info' => __('set pagination alignment'),
|
|
]);
|
|
|
|
|
|
$output .= Slider::get([
|
|
'name' => 'padding_top',
|
|
'label' => __('Padding Top'),
|
|
'value' => $widget_saved_values['padding_top'] ?? 110,
|
|
'max' => 200,
|
|
]);
|
|
$output .= Slider::get([
|
|
'name' => 'padding_bottom',
|
|
'label' => __('Padding Bottom'),
|
|
'value' => $widget_saved_values['padding_bottom'] ?? 110,
|
|
'max' => 200,
|
|
]);
|
|
|
|
// add padding option
|
|
|
|
$output .= $this->admin_form_submit_button();
|
|
$output .= $this->admin_form_end();
|
|
$output .= $this->admin_form_after();
|
|
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function frontend_render()
|
|
{
|
|
$settings = $this->get_settings();
|
|
$current_lang = LanguageHelper::user_lang_slug();
|
|
$readmore_text = SanitizeInput::esc_html($settings['readmore_text_'.$current_lang]);
|
|
$category = $settings['categories_'.$current_lang] ?? [];
|
|
|
|
$order_by = SanitizeInput::esc_html($settings['order_by']);
|
|
$order = SanitizeInput::esc_html($settings['order']);
|
|
$items = SanitizeInput::esc_html($settings['items']);
|
|
$padding_top = SanitizeInput::esc_html($settings['padding_top']);
|
|
$padding_bottom = SanitizeInput::esc_html($settings['padding_bottom']);
|
|
$theme = SanitizeInput::esc_html($settings['theme']);
|
|
$pagination_alignment = $settings['pagination_alignment'];
|
|
$pagination_status = $settings['pagination_status'] ?? '';
|
|
$columns = SanitizeInput::esc_html($settings['columns']);
|
|
|
|
$blogs = Blog::query()->where(['lang' => $current_lang,'status' => 'publish']);
|
|
if (!empty($category)){
|
|
$blogs->whereIn('blog_categories_id', $category);
|
|
}
|
|
$blogs =$blogs->orderBy($order_by,$order);
|
|
|
|
if(!empty($items)){
|
|
$blogs = $blogs->paginate($items);
|
|
}else{
|
|
$blogs = $blogs->get();
|
|
}
|
|
|
|
$pagination_markup = '';
|
|
if (!empty($pagination_status) && !empty($items)){
|
|
$pagination_markup = '<div class="col-lg-12"><div class="pagination-wrapper '.$pagination_alignment.'">'.$blogs->links().'</div></div>';
|
|
}
|
|
|
|
|
|
|
|
$category_markup = '';
|
|
|
|
foreach ($blogs as $item){
|
|
$image = render_image_markup_by_attachment_id($item->image,'','grid');
|
|
$day = date_format($item->created_at,'d');
|
|
$month = date_format($item->created_at,'M');
|
|
$route = route('frontend.blog.single',$item->slug);
|
|
$title = SanitizeInput::esc_html($item->title);
|
|
$excerpt = SanitizeInput::esc_html($item->excerpt);
|
|
|
|
$readmore_text_markup = '';
|
|
if (!empty($readmore_text)){
|
|
$readmore_text_markup .= '<a class="readmore" href="'.SanitizeInput::esc_url($route).'">'.$readmore_text.'<i class="fas fa-long-arrow-alt-right"></i></a>';
|
|
}
|
|
|
|
$category_markup .= <<<HTML
|
|
<div class="col-md-6 {$columns}">
|
|
<div class="single-portfolio-blog-grid {$theme} margin-bottom-30">
|
|
<div class="thumb">
|
|
{$image}
|
|
<div class="time-wrap">
|
|
<span class="date">{$day}</span>
|
|
<span class="month">{$month}</span>
|
|
</div>
|
|
</div>
|
|
<div class="content">
|
|
<h4 class="title">
|
|
<a href="{$route}">{$title}</a>
|
|
</h4>
|
|
<p class="excerpt">{$excerpt}</p>
|
|
{$readmore_text_markup}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
HTML;
|
|
}
|
|
|
|
|
|
return <<<HTML
|
|
<div class="const-news-area" data-padding-top="{$padding_top}" data-padding-bottom="{$padding_bottom}">
|
|
<div class="container">
|
|
<div class="row">
|
|
{$category_markup}
|
|
{$pagination_markup}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
HTML;
|
|
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function addon_title()
|
|
{
|
|
return __('Blog Grid: 03');
|
|
}
|
|
} |