| 1 |
<?php |
| 2 |
namespace Depicter\Modules\Elementor; |
| 3 |
|
| 4 |
use Elementor\Plugin; |
| 5 |
use Depicter\Document\CSS\Selector; |
| 6 |
use Elementor\Controls_Manager; |
| 7 |
use Elementor\Widget_Base; |
| 8 |
|
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; // Exit if accessed directly. |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* Elementor 'Slider' widget. |
| 16 |
* |
| 17 |
* Elementor widget that displays an 'Slider' with lightbox. |
| 18 |
* |
| 19 |
* @since 1.0.0 |
| 20 |
*/ |
| 21 |
class SliderWidget extends Widget_Base { |
| 22 |
|
| 23 |
/** |
| 24 |
* Get widget name. |
| 25 |
* |
| 26 |
* Retrieve 'Slider' widget name. |
| 27 |
* |
| 28 |
* @since 1.0.0 |
| 29 |
* @access public |
| 30 |
* |
| 31 |
* @return string Widget name. |
| 32 |
*/ |
| 33 |
public function get_name() { |
| 34 |
return 'depicter_slider'; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Get widget title. |
| 39 |
* |
| 40 |
* Retrieve 'Slider' widget title. |
| 41 |
* |
| 42 |
* @since 1.0.0 |
| 43 |
* @access public |
| 44 |
* |
| 45 |
* @return string Widget title. |
| 46 |
*/ |
| 47 |
public function get_title() { |
| 48 |
return __('Depicter Slider', 'depicter' ); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Get widget icon. |
| 53 |
* |
| 54 |
* Retrieve Slider widget icon. |
| 55 |
* |
| 56 |
* @since 1.0.0 |
| 57 |
* @access public |
| 58 |
* |
| 59 |
* @return string Widget icon. |
| 60 |
*/ |
| 61 |
public function get_icon() { |
| 62 |
return 'eicon-post-slider depicter-badge'; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Get widget categories. |
| 67 |
* |
| 68 |
* @since 1.0.0 |
| 69 |
* @access public |
| 70 |
* |
| 71 |
* @return string Widget icon. |
| 72 |
*/ |
| 73 |
public function get_categories() { |
| 74 |
return ['basic']; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* load dependent styles |
| 79 |
* |
| 80 |
* @return array |
| 81 |
*/ |
| 82 |
public function get_style_depends() { |
| 83 |
$styles = \Depicter::front()->assets()->enqueueStyles(); |
| 84 |
return array_keys( $styles ); |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* load dependent scripts |
| 89 |
* |
| 90 |
* @return array |
| 91 |
*/ |
| 92 |
public function get_script_depends() { |
| 93 |
$scripts = \Depicter::front()->assets()->enqueueScripts(); |
| 94 |
return array_keys( $scripts ); |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
public function getSlidersList() { |
| 99 |
$list = [ |
| 100 |
'0' => __( 'Select Slider', 'depicter' ) |
| 101 |
]; |
| 102 |
$documents = \Depicter::documentRepository()->select( ['id', 'name'] )->orderBy('modified_at', 'DESC')->findAll()->get(); |
| 103 |
$documents = $documents ? $documents->toArray() : []; |
| 104 |
foreach( $documents as $document ) { |
| 105 |
$list[ "#" . $document['id'] ] = "[#{$document['id']}]: " . $document['name']; |
| 106 |
} |
| 107 |
return $list; |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* Register 'Slider' widget controls. |
| 112 |
* |
| 113 |
* Adds different input fields to allow the user to change and customize the widget settings. |
| 114 |
* |
| 115 |
* @since 1.0.0 |
| 116 |
* @access protected |
| 117 |
*/ |
| 118 |
protected function register_controls() { |
| 119 |
|
| 120 |
/*-----------------------------------------------------------------------------------*/ |
| 121 |
/* slider_section |
| 122 |
/*-----------------------------------------------------------------------------------*/ |
| 123 |
|
| 124 |
$this->start_controls_section( |
| 125 |
'slider_section', |
| 126 |
array( |
| 127 |
'label' => __('Slider', 'depicter' ), |
| 128 |
) |
| 129 |
); |
| 130 |
|
| 131 |
$this->add_control( |
| 132 |
'slider_id', |
| 133 |
[ |
| 134 |
'label' => __('Select a Depicter slider','depicter' ), |
| 135 |
'type' => Controls_Manager::SELECT, |
| 136 |
'label_block' => 'true', |
| 137 |
'options' => $this->getSlidersList(), |
| 138 |
'default' => '0' |
| 139 |
] |
| 140 |
); |
| 141 |
|
| 142 |
$documents = \Depicter::documentRepository()->select( ['id', 'name', 'status'] )->orderBy('modified_at', 'DESC')->findAll()->get(); |
| 143 |
$documents = $documents ? $documents->toArray() : []; |
| 144 |
foreach( $documents as $key => $document ) { |
| 145 |
|
| 146 |
$args = [ |
| 147 |
'isPublishedBefore' => \Depicter::documentRepository()->isPublishedBefore( $document['id'] ), |
| 148 |
'documentStatus' => $document['status'], |
| 149 |
'documentID' => $document['id'] |
| 150 |
]; |
| 151 |
|
| 152 |
$markup = \Depicter::view('admin/notices/builders-draft-notice')->with('view_args', $args)->toString(); |
| 153 |
|
| 154 |
if ( current_user_can( 'access_depicter' ) ) { |
| 155 |
$this->add_control( |
| 156 |
'slider_control_buttons_' . $key, |
| 157 |
[ |
| 158 |
'type' => Controls_Manager::RAW_HTML, |
| 159 |
'raw' => $markup, |
| 160 |
'condition' => [ |
| 161 |
'slider_id' => '#' . $document['id'] |
| 162 |
] |
| 163 |
] |
| 164 |
); |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
$this->end_controls_section(); |
| 169 |
} |
| 170 |
|
| 171 |
/** |
| 172 |
* Render image box widget output on the frontend. |
| 173 |
* |
| 174 |
* Written in PHP and used to generate the final HTML. |
| 175 |
* |
| 176 |
* @since 1.0.0 |
| 177 |
* @access protected |
| 178 |
*/ |
| 179 |
protected function render() { |
| 180 |
|
| 181 |
$settings = $this->get_settings_for_display(); |
| 182 |
|
| 183 |
if ( $settings['slider_id'] ) { |
| 184 |
echo \Depicter::front()->render()->document( ltrim( $settings['slider_id'], '#' ) ); |
| 185 |
} else { |
| 186 |
echo esc_html__('Please select a Depicter slider','depicter' ); |
| 187 |
} |
| 188 |
|
| 189 |
} |
| 190 |
} |
| 191 |
|