| 1 |
<?php |
| 2 |
/** |
| 3 |
* Render class for Advanced Heading widget. |
| 4 |
* |
| 5 |
* @package RadiusTheme\SB |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace RadiusTheme\SB\Elementor\Widgets\General\ShopBuilderButton; |
| 9 |
|
| 10 |
use RadiusTheme\SB\Helpers\Fns; |
| 11 |
use RadiusTheme\SB\Elementor\Render\GeneralAddons; |
| 12 |
|
| 13 |
// Do not allow directly accessing this file. |
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit( 'This script cannot be accessed directly.' ); |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Render class. |
| 20 |
* |
| 21 |
* @package RadiusTheme\SB |
| 22 |
*/ |
| 23 |
class Render extends GeneralAddons { |
| 24 |
|
| 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/shopbuilder_button/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 |
* @return array |
| 46 |
*/ |
| 47 |
private function get_template_args( $id ) { |
| 48 |
|
| 49 |
return [ |
| 50 |
'sb_button__content' => $this->settings['sb_button__content'], |
| 51 |
'sb_button2__content' => $this->settings['sb_button2__content'], |
| 52 |
'sb_button_link' => ! empty( $this->settings['sb_button_link']['url'] ) ? $this->settings['sb_button_link']['url'] : '#', |
| 53 |
'sb_button2_link' => ! empty( $this->settings['sb_button2_link']['url'] ) ? $this->settings['sb_button2_link']['url'] : '#', |
| 54 |
'sb_button_target' => ! empty( $this->settings['sb_button_link']['is_external'] ) ? '_blank' : '_self', |
| 55 |
'sb_button2_target' => ! empty( $this->settings['sb_button2_link']['is_external'] ) ? '_blank' : '_self', |
| 56 |
'sb_button1_icon' => $this->settings['sb_button1_icon'] ?? '', |
| 57 |
'sb_button1_icon_position' => $this->settings['sb_button1_icon_position'] ?? 'right', |
| 58 |
'sb_button2_icon' => $this->settings['sb_button2_icon'] ?? '', |
| 59 |
'sb_button2_icon_position' => $this->settings['sb_button2_icon_position'] ?? 'right', |
| 60 |
'has_connector' => ! empty( $this->settings['display_connector'] ), |
| 61 |
'connector_type' => $this->settings['connector_type'] ?? 'text', |
| 62 |
'sb_button_connect_text' => $this->settings['sb_button_connect_text'] ?? '', |
| 63 |
'sb_button_connect_icon' => $this->settings['sb_button_connect_icon'] ?? '', |
| 64 |
'button1_attributes' => $this->render_button_attributes( 'rtsb_button_' . $id, 'sb_button_link', 'rtsb-btn rtsb-primary-btn' ) ?? '', |
| 65 |
'button2_attributes' => $this->render_button_attributes( 'rtsb_button2_' . $id, 'sb_button2_link', 'rtsb-btn rtsb-secondary-btn' ) ?? '', |
| 66 |
]; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Function to render icon. |
| 71 |
* |
| 72 |
* @param string $position icon position ('left' or 'right'). |
| 73 |
* @param string $icon Position of the separator in settings. |
| 74 |
* |
| 75 |
* @return string |
| 76 |
*/ |
| 77 |
public static function render_icon( $position, $icon, $icon_position ) { |
| 78 |
$html = ''; |
| 79 |
|
| 80 |
// Render the left icon. |
| 81 |
if ( $position === $icon_position ) { |
| 82 |
$html .= '<span class="icon">' . Fns::icons_manager( $icon ) . '</span>'; |
| 83 |
} |
| 84 |
|
| 85 |
return $html; |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Function to render button attributes. |
| 90 |
* |
| 91 |
* @param string $id Element ID. |
| 92 |
* |
| 93 |
* @return string |
| 94 |
*/ |
| 95 |
public function render_button_attributes( $id, $control_name, $class = 'rtsb-btn' ) { |
| 96 |
if ( ! empty( $this->settings['hover_animation'] ) ) { |
| 97 |
$class .= ' ' . 'hover-' . $this->settings['hover_animation']; |
| 98 |
} |
| 99 |
$this->add_attribute( $id, 'class', $class ); |
| 100 |
|
| 101 |
if ( ! empty( $this->settings[ $control_name ]['url'] ) ) { |
| 102 |
$this->add_link_attributes( $id, $this->settings[ $control_name ] ); |
| 103 |
} else { |
| 104 |
$this->add_attribute( $id, 'role', 'button' ); |
| 105 |
} |
| 106 |
|
| 107 |
return $this->get_attribute_string( $id ); |
| 108 |
} |
| 109 |
/** |
| 110 |
* Function to render connector. |
| 111 |
* |
| 112 |
* @param string $connector_type ('text' or 'icon'). |
| 113 |
* @param string $sb_button_connect_text . |
| 114 |
* @param string $sb_button_connect_icon . |
| 115 |
* |
| 116 |
* @return string |
| 117 |
*/ |
| 118 |
public static function render_connector( $connector_type, $sb_button_connect_text, $sb_button_connect_icon ) { |
| 119 |
ob_start(); |
| 120 |
?> |
| 121 |
<div class="rtsb-dual-btn-connector"> |
| 122 |
<div class="connector-inner"> |
| 123 |
<?php |
| 124 |
if ( 'text' === $connector_type ) { |
| 125 |
Fns::print_html( $sb_button_connect_text ); |
| 126 |
} |
| 127 |
if ( 'icon' === $connector_type ) { |
| 128 |
Fns::print_html( Fns::icons_manager( $sb_button_connect_icon ) ); |
| 129 |
} |
| 130 |
?> |
| 131 |
</div> |
| 132 |
</div> |
| 133 |
<?php |
| 134 |
return ob_get_clean(); |
| 135 |
} |
| 136 |
} |
| 137 |
|