| 1 |
<?php |
| 2 |
/** |
| 3 |
* Render class for Info Box widget. |
| 4 |
* |
| 5 |
* @package RadiusTheme\SB |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace RadiusTheme\SB\Elementor\Widgets\General\InfoBox; |
| 9 |
|
| 10 |
use RadiusTheme\SB\Helpers\Fns; |
| 11 |
use RadiusTheme\SB\Elementor\Helper\RenderHelpers; |
| 12 |
use RadiusTheme\SB\Elementor\Render\GeneralAddons; |
| 13 |
|
| 14 |
// Do not allow directly accessing this file. |
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit( 'This script cannot be accessed directly.' ); |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Render class. |
| 21 |
* |
| 22 |
* @package RadiusTheme\SB |
| 23 |
*/ |
| 24 |
class Render extends GeneralAddons { |
| 25 |
/** |
| 26 |
* Main render function for displaying content. |
| 27 |
* |
| 28 |
* @param array $data Data to be passed to the template. |
| 29 |
* @param array $settings Widget settings. |
| 30 |
* |
| 31 |
* @return string |
| 32 |
*/ |
| 33 |
public function display_content( $data, $settings ) { |
| 34 |
$this->settings = $settings; |
| 35 |
$data = wp_parse_args( $this->get_template_args( $data['id'] ), $data ); |
| 36 |
$data = apply_filters( 'rtsb/general/info_box/args/' . $data['unique_name'], $data ); |
| 37 |
$data['content'] = Fns::load_template( $data['template'], $data, true ); |
| 38 |
|
| 39 |
return $this->addon_view( $data, $settings ); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Retrieves template arguments based on widget settings. |
| 44 |
* |
| 45 |
* @param int $id Widget ID. |
| 46 |
* |
| 47 |
* @return array |
| 48 |
*/ |
| 49 |
private function get_template_args( $id ) { |
| 50 |
return [ |
| 51 |
'info_box_title_html_tag' => $this->settings['info_box_title_html_tag'] ?? 'h2', |
| 52 |
'info_box_title' => $this->settings['info_box_title'], |
| 53 |
'has_description' => ! empty( $this->settings['display_content'] ) && ! empty( $this->settings['info_box_content'] ), |
| 54 |
'description' => $this->settings['info_box_content'] ?? '', |
| 55 |
'has_button' => ! empty( $this->settings['display_button'] ), |
| 56 |
'has_count' => ! empty( $this->settings['display_count'] ), |
| 57 |
'count' => $this->settings['info_box_count'] ?? '01', |
| 58 |
'sb_button_content' => $this->settings['sb_button_content'], |
| 59 |
'sb_button_icon' => $this->settings['sb_button_icon'] ?? '', |
| 60 |
'icon_border_layer' => $this->settings['info_box_icon_border_layer'] ?? '', |
| 61 |
'sb_button_icon_position' => $this->settings['sb_button_icon_position'] ?? 'right', |
| 62 |
'button_attributes' => $this->render_button_attributes( 'rtsb_button_' . $id, 'sb_button_link', 'primary-btn' ) ?? '', |
| 63 |
'icon_html' => $this->render_icon_image(), |
| 64 |
'icon_type' => $this->settings['info_box_icon_type'] ?? 'icon', |
| 65 |
'icon_bg_type' => ! empty( $this->settings['info_box_icon_style_gradient_bg_background'] ) ? $this->settings['info_box_icon_style_gradient_bg_background'] : 'classic', |
| 66 |
'icon_hover_bg_type' => ! empty( $this->settings['info_box_icon_style_hover_gradient_bg_background'] ) ? $this->settings['info_box_icon_style_hover_gradient_bg_background'] : 'classic', |
| 67 |
]; |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Function to render button attributes. |
| 72 |
* |
| 73 |
* @param string $id Element ID. |
| 74 |
* @param string $control_name Control name. |
| 75 |
* @param string $class Class. |
| 76 |
* @param string $type Button type. |
| 77 |
* |
| 78 |
* @return string |
| 79 |
*/ |
| 80 |
public function render_button_attributes( $id, $control_name, $class, $type = 'rtsb-btn' ) { |
| 81 |
if ( ! empty( $this->settings['hover_animation'] ) ) { |
| 82 |
$class .= ' ' . 'hover-' . $this->settings['hover_animation']; |
| 83 |
} |
| 84 |
$this->add_attribute( $id, 'class', $type . ' ' . $class ); |
| 85 |
|
| 86 |
if ( ! empty( $this->settings[ $control_name ]['url'] ) ) { |
| 87 |
$this->add_link_attributes( $id, $this->settings[ $control_name ] ); |
| 88 |
} else { |
| 89 |
$this->add_attribute( $id, 'role', 'button' ); |
| 90 |
} |
| 91 |
|
| 92 |
return $this->get_attribute_string( $id ); |
| 93 |
} |
| 94 |
/** |
| 95 |
* Function to render icon image. |
| 96 |
* |
| 97 |
* @return string |
| 98 |
*/ |
| 99 |
public function render_icon_image() { |
| 100 |
$icon_img_html = ''; |
| 101 |
|
| 102 |
$icon = $this->settings['info_box_icon'] ?? ''; |
| 103 |
|
| 104 |
if ( 'icon' === $this->settings['info_box_icon_type'] ) { |
| 105 |
$icon_img_html .= '<span class="icon">' . Fns::icons_manager( $icon ) . '</span>'; |
| 106 |
} else { |
| 107 |
if ( ! empty( $this->settings['info_box_image'] ) ) { |
| 108 |
$c_image_size = RenderHelpers::get_data( $this->settings, 'info_box_img_dimension', [] ); |
| 109 |
$c_image_size['crop'] = RenderHelpers::get_data( $this->settings, 'info_box_img_crop', [] ); |
| 110 |
$c_image_size = ! empty( $c_image_size ) && is_array( $c_image_size ) ? $c_image_size : []; |
| 111 |
$image_id = ! empty( $this->settings['info_box_image']['id'] ) ? $this->settings['info_box_image']['id'] : $this->settings['info_box_image']; |
| 112 |
$icon_img_html .= Fns::get_product_image_html( |
| 113 |
'', |
| 114 |
null, |
| 115 |
RenderHelpers::get_data( $this->settings, 'info_box_image_size', 'full' ), |
| 116 |
$image_id, |
| 117 |
$c_image_size |
| 118 |
); |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
return $icon_img_html; |
| 123 |
} |
| 124 |
} |
| 125 |
|