| 1 |
<?php |
| 2 |
|
| 3 |
namespace MasterAddons\Addons; |
| 4 |
|
| 5 |
use MasterAddons\Inc\Classes\Base\Master_Widget; |
| 6 |
use \Elementor\Controls_Stack; |
| 7 |
use \Elementor\Controls_Manager; |
| 8 |
use \Elementor\Utils; |
| 9 |
use \Elementor\Group_Control_Image_Size; |
| 10 |
use \Elementor\Group_Control_Typography; |
| 11 |
|
| 12 |
use MasterAddons\Inc\Admin\Config; |
| 13 |
|
| 14 |
/** |
| 15 |
* Author Name: Liton Arefin |
| 16 |
* Author URL: https://jeweltheme.com |
| 17 |
* Date: 6/27/19 |
| 18 |
*/ |
| 19 |
|
| 20 |
if (!defined('ABSPATH')) exit; // If this file is called directly, abort. |
| 21 |
|
| 22 |
class Cards extends Master_Widget |
| 23 |
{ |
| 24 |
use \MasterAddons\Inc\Traits\Widget_Notice; |
| 25 |
use \MasterAddons\Inc\Traits\Widget_Assets_Trait; |
| 26 |
|
| 27 |
public function get_name() |
| 28 |
{ |
| 29 |
return 'ma-el-card'; |
| 30 |
} |
| 31 |
public function get_title() |
| 32 |
{ |
| 33 |
return esc_html__('Cards', 'master-addons' ); |
| 34 |
} |
| 35 |
public function get_icon() |
| 36 |
{ |
| 37 |
return 'jltma-icon ' . Config::get_addon_icon('ma-cards'); |
| 38 |
} |
| 39 |
|
| 40 |
protected function register_controls() |
| 41 |
{ |
| 42 |
|
| 43 |
/** |
| 44 |
* Card Content Section |
| 45 |
*/ |
| 46 |
$this->start_controls_section( |
| 47 |
'ma_el_card_content', |
| 48 |
[ |
| 49 |
'label' => esc_html__('Content', 'master-addons' ), |
| 50 |
] |
| 51 |
); |
| 52 |
|
| 53 |
$this->add_control( |
| 54 |
'ma_el_card_image', |
| 55 |
[ |
| 56 |
'label' => __('Image', 'master-addons' ), |
| 57 |
'type' => Controls_Manager::MEDIA, |
| 58 |
'default' => [ |
| 59 |
'url' => Utils::get_placeholder_image_src(), |
| 60 |
], |
| 61 |
] |
| 62 |
); |
| 63 |
$this->add_group_control( |
| 64 |
Group_Control_Image_Size::get_type(), |
| 65 |
[ |
| 66 |
'name' => 'thumbnail', |
| 67 |
'default' => 'full', |
| 68 |
'condition' => [ |
| 69 |
'ma_el_card_image[url]!' => '', |
| 70 |
], |
| 71 |
] |
| 72 |
); |
| 73 |
|
| 74 |
$this->add_control( |
| 75 |
'ma_el_card_title', |
| 76 |
[ |
| 77 |
'label' => esc_html__('Title', 'master-addons' ), |
| 78 |
'type' => Controls_Manager::TEXT, |
| 79 |
'label_block' => true, |
| 80 |
'separator' => 'before', |
| 81 |
'default' => esc_html__('Card Title', 'master-addons' ), |
| 82 |
] |
| 83 |
); |
| 84 |
|
| 85 |
$this->add_control( |
| 86 |
'ma_el_card_title_link', |
| 87 |
[ |
| 88 |
'label' => __('Title URL', 'master-addons' ), |
| 89 |
'type' => Controls_Manager::URL, |
| 90 |
'placeholder' => __('https://your-link.com', 'master-addons' ), |
| 91 |
'label_block' => true, |
| 92 |
'default' => [ |
| 93 |
'url' => '', |
| 94 |
'is_external' => true, |
| 95 |
], |
| 96 |
] |
| 97 |
); |
| 98 |
|
| 99 |
$this->add_control( |
| 100 |
'ma_el_card_tag', |
| 101 |
[ |
| 102 |
'label' => esc_html__('Tag', 'master-addons' ), |
| 103 |
'type' => Controls_Manager::TEXT, |
| 104 |
'label_block' => true, |
| 105 |
'default' => esc_html__('Card Tag', 'master-addons' ), |
| 106 |
] |
| 107 |
); |
| 108 |
|
| 109 |
$this->add_control( |
| 110 |
'ma_el_card_description', |
| 111 |
[ |
| 112 |
'label' => esc_html__('Description', 'master-addons' ), |
| 113 |
'type' => Controls_Manager::TEXTAREA, |
| 114 |
'default' => esc_html__('Basic description about the Card', 'master-addons' ), |
| 115 |
] |
| 116 |
); |
| 117 |
|
| 118 |
$this->add_control( |
| 119 |
'ma_el_card_action_text', |
| 120 |
[ |
| 121 |
'label' => esc_html__('Action Text', 'master-addons' ), |
| 122 |
'type' => Controls_Manager::TEXT, |
| 123 |
'label_block' => true, |
| 124 |
'separator' => 'before', |
| 125 |
'default' => esc_html__('Details', 'master-addons' ), |
| 126 |
] |
| 127 |
); |
| 128 |
|
| 129 |
$this->add_control( |
| 130 |
'ma_el_card_action_link', |
| 131 |
[ |
| 132 |
'label' => __('Action URL', 'master-addons' ), |
| 133 |
'type' => Controls_Manager::URL, |
| 134 |
'placeholder' => __('https://your-link.com', 'master-addons' ), |
| 135 |
'label_block' => true, |
| 136 |
'default' => [ |
| 137 |
'url' => '', |
| 138 |
'is_external' => true, |
| 139 |
], |
| 140 |
] |
| 141 |
); |
| 142 |
|
| 143 |
$this->end_controls_section(); |
| 144 |
|
| 145 |
/* |
| 146 |
* Card Styling Section |
| 147 |
*/ |
| 148 |
$this->start_controls_section( |
| 149 |
'ma_el_section_card_styles_preset', |
| 150 |
[ |
| 151 |
'label' => esc_html__('General Styles', 'master-addons' ), |
| 152 |
'tab' => Controls_Manager::TAB_STYLE |
| 153 |
] |
| 154 |
); |
| 155 |
$this->add_control( |
| 156 |
'ma_el_card_preset', |
| 157 |
[ |
| 158 |
'label' => esc_html__('Style Preset', 'master-addons' ), |
| 159 |
'type' => Controls_Manager::SELECT, |
| 160 |
'default' => 'one', |
| 161 |
'options' => [ |
| 162 |
'one' => esc_html__('Variation 1', 'master-addons' ), |
| 163 |
'two' => esc_html__('Variation 2', 'master-addons' ), |
| 164 |
'three' => esc_html__('Variation 3', 'master-addons' ), |
| 165 |
], |
| 166 |
] |
| 167 |
); |
| 168 |
|
| 169 |
$this->add_control( |
| 170 |
'ma_el_card_color_scheme', |
| 171 |
[ |
| 172 |
'label' => __('Color Scheme', 'master-addons' ), |
| 173 |
'type' => Controls_Manager::COLOR, |
| 174 |
'default' => '#5031ef', |
| 175 |
'selectors' => [ |
| 176 |
'{{WRAPPER}} .ma-el-card.two .ma-el-card-action:hover, {{WRAPPER}} .ma-el-card.two .ma-el-card-title::before, {{WRAPPER}} .ma-el-card.one .ma-el-card-action:hover, |
| 177 |
{{WRAPPER}} .ma-el-card.one .ma-el-card-title::before, {{WRAPPER}} .ma-el-card.three .ma-el-card-action:hover, {{WRAPPER}} .ma-el-card.three .ma-el-card-tag::before, {{WRAPPER}} .ma-el-card.three::before' => 'background-color: {{VALUE}};', |
| 178 |
|
| 179 |
], |
| 180 |
] |
| 181 |
); |
| 182 |
|
| 183 |
$this->add_control( |
| 184 |
'ma_el_card_background', |
| 185 |
[ |
| 186 |
'label' => esc_html__('Content Background Color', 'master-addons' ), |
| 187 |
'type' => Controls_Manager::COLOR, |
| 188 |
'default' => '', |
| 189 |
'selectors' => [ |
| 190 |
'{{WRAPPER}} .ma-el-card-body' => 'background-color: {{VALUE}};', |
| 191 |
], |
| 192 |
] |
| 193 |
); |
| 194 |
|
| 195 |
$this->end_controls_section(); |
| 196 |
|
| 197 |
/* |
| 198 |
* Card Content Styling Section |
| 199 |
*/ |
| 200 |
$this->start_controls_section( |
| 201 |
'ma_el_section_card_styles_title', |
| 202 |
[ |
| 203 |
'label' => esc_html__('Title', 'master-addons' ), |
| 204 |
'tab' => Controls_Manager::TAB_STYLE, |
| 205 |
] |
| 206 |
); |
| 207 |
$this->add_control( |
| 208 |
'ma_el_title_color', |
| 209 |
[ |
| 210 |
'label' => __('Color', 'master-addons' ), |
| 211 |
'type' => Controls_Manager::COLOR, |
| 212 |
'default' => '#132c47', |
| 213 |
'selectors' => [ |
| 214 |
'{{WRAPPER}} .ma-el-card-body .ma-el-card-title' => 'color: {{VALUE}};', |
| 215 |
], |
| 216 |
] |
| 217 |
); |
| 218 |
|
| 219 |
$this->add_group_control( |
| 220 |
Group_Control_Typography::get_type(), |
| 221 |
[ |
| 222 |
'name' => 'card_title_typography', |
| 223 |
'selector' => '{{WRAPPER}} .ma-el-card-body .ma-el-card-title', |
| 224 |
] |
| 225 |
); |
| 226 |
|
| 227 |
$this->end_controls_section(); |
| 228 |
|
| 229 |
// description style |
| 230 |
$this->start_controls_section( |
| 231 |
'ma_el_section_card_styles_description', |
| 232 |
[ |
| 233 |
'label' => esc_html__('Description', 'master-addons' ), |
| 234 |
'tab' => Controls_Manager::TAB_STYLE, |
| 235 |
] |
| 236 |
); |
| 237 |
$this->add_control( |
| 238 |
'ma_el_description_color', |
| 239 |
[ |
| 240 |
'label' => __('Color', 'master-addons' ), |
| 241 |
'type' => Controls_Manager::COLOR, |
| 242 |
'default' => '', |
| 243 |
'selectors' => [ |
| 244 |
'{{WRAPPER}} .ma-el-card-body .ma-el-card-description' => 'color: {{VALUE}};', |
| 245 |
], |
| 246 |
] |
| 247 |
); |
| 248 |
$this->add_group_control( |
| 249 |
Group_Control_Typography::get_type(), |
| 250 |
[ |
| 251 |
'name' => 'card_description_typography', |
| 252 |
'selector' => '{{WRAPPER}} .ma-el-card-body .ma-el-card-description', |
| 253 |
] |
| 254 |
); |
| 255 |
$this->end_controls_section(); |
| 256 |
|
| 257 |
$this->start_controls_section( |
| 258 |
'ma_el_section_card_styles_tag', |
| 259 |
[ |
| 260 |
'label' => esc_html__('Tag', 'master-addons' ), |
| 261 |
'tab' => Controls_Manager::TAB_STYLE, |
| 262 |
] |
| 263 |
); |
| 264 |
$this->add_control( |
| 265 |
'ma_el_tag_color', |
| 266 |
[ |
| 267 |
'label' => __('Color', 'master-addons' ), |
| 268 |
'type' => Controls_Manager::COLOR, |
| 269 |
'default' => '', |
| 270 |
'selectors' => [ |
| 271 |
'{{WRAPPER}} .ma-el-card-body .ma-el-card-tag' => 'color: {{VALUE}};', |
| 272 |
], |
| 273 |
] |
| 274 |
); |
| 275 |
$this->add_group_control( |
| 276 |
Group_Control_Typography::get_type(), |
| 277 |
[ |
| 278 |
'name' => 'card_tag_typography', |
| 279 |
'selector' => '{{WRAPPER}} .ma-el-card-body .ma-el-card-tag', |
| 280 |
] |
| 281 |
); |
| 282 |
|
| 283 |
$this->end_controls_section(); |
| 284 |
} |
| 285 |
protected function render() |
| 286 |
{ |
| 287 |
$settings = $this->get_settings_for_display(); |
| 288 |
$card_image = $this->get_settings_for_display('ma_el_card_image'); |
| 289 |
$card_image_url_src = Group_Control_Image_Size::get_attachment_image_src($card_image['id'], 'thumbnail', $settings); |
| 290 |
if (empty($card_image_url_src)) { |
| 291 |
$card_image_url = $card_image['url']; |
| 292 |
} else { |
| 293 |
$card_image_url = $card_image_url_src; |
| 294 |
} |
| 295 |
|
| 296 |
?> |
| 297 |
|
| 298 |
<div id="ma-el-card-<?php echo esc_attr($this->get_id()); ?>" class="ma-el-card <?php echo esc_attr($settings['ma_el_card_preset']); ?>"> |
| 299 |
<div class="ma-el-card-thumb"> |
| 300 |
<img src="<?php echo esc_url($card_image_url); ?>" alt="<?php echo esc_attr(get_post_meta($card_image['id'], '_wp_attachment_image_alt', true)); ?>"> |
| 301 |
</div> |
| 302 |
<div class="ma-el-card-body"> |
| 303 |
<a href="<?php echo esc_url($settings['ma_el_card_title_link']['url']); ?>" class="ma-el-card-title"> |
| 304 |
<?php echo esc_html($settings['ma_el_card_title']); ?> |
| 305 |
</a> |
| 306 |
<p class="ma-el-card-tag"> |
| 307 |
<?php echo esc_html($settings['ma_el_card_tag']); ?> |
| 308 |
</p> |
| 309 |
<p class="ma-el-card-description"> |
| 310 |
<?php echo wp_kses_post( $this->parse_text_editor($settings['ma_el_card_description']) ); ?> |
| 311 |
</p> |
| 312 |
<a href="<?php echo esc_url($settings['ma_el_card_action_link']['url']); ?>" class="ma-el-card-action"> |
| 313 |
<?php if ('two' === $settings['ma_el_card_preset']) { ?> |
| 314 |
<i class="fa fa-arrow-right" aria-hidden="true"></i> |
| 315 |
<?php } else { |
| 316 |
echo esc_html($settings['ma_el_card_action_text']); |
| 317 |
} |
| 318 |
?> |
| 319 |
</a> |
| 320 |
</div> |
| 321 |
</div> |
| 322 |
|
| 323 |
<?php |
| 324 |
} |
| 325 |
|
| 326 |
protected function content_template() |
| 327 |
{ |
| 328 |
?> |
| 329 |
<div id="ma-el-card" class="ma-el-card {{ settings.ma_el_card_preset }}"> |
| 330 |
<div class="ma-el-card-thumb"> |
| 331 |
<img src="{{ settings.ma_el_card_image.url }}"> |
| 332 |
</div> |
| 333 |
<div class="ma-el-card-body"> |
| 334 |
<a href="{{ settings.ma_el_card_title_link.url }}" class="ma-el-card-title">{{{ settings |
| 335 |
.ma_el_card_title }}}</a> |
| 336 |
<p class="ma-el-card-tag">{{{ settings.ma_el_card_tag }}}</p> |
| 337 |
<p class="ma-el-card-description">{{{ settings.ma_el_card_description }}}</p> |
| 338 |
<a href="{{ settings.ma_el_card_action_link.url ); ?>" class="ma-el-card-action"> |
| 339 |
<# if ( 'two' == settings.ma_el_card_preset ) { |
| 340 |
#><i class="fa fa-arrow-right" aria-hidden="true"></i> |
| 341 |
<# } else { #> |
| 342 |
{{{ settings.ma_el_card_action_text }}} <# |
| 343 |
} #> |
| 344 |
</a> |
| 345 |
</div> |
| 346 |
</div> |
| 347 |
<?php |
| 348 |
} |
| 349 |
} |
| 350 |
|