| 1 |
<?php |
| 2 |
/** |
| 3 |
* Render class for Advanced Heading widget. |
| 4 |
* |
| 5 |
* @package RadiusTheme\SB |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace RadiusTheme\SB\Elementor\Widgets\General\AdvancedHeading; |
| 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 |
* Main render function for displaying content. |
| 26 |
* |
| 27 |
* @param array $data Data to be passed to the template. |
| 28 |
* @param array $settings Widget settings. |
| 29 |
* |
| 30 |
* @return string |
| 31 |
*/ |
| 32 |
public function display_content( $data, $settings ) { |
| 33 |
$this->settings = $settings; |
| 34 |
$data = wp_parse_args( $this->get_template_args(), $data ); |
| 35 |
$data = apply_filters( 'rtsb/general/advanced_heading/args/' . $data['unique_name'], $data ); |
| 36 |
$data['content'] = Fns::load_template( $data['template'], $data, true ); |
| 37 |
|
| 38 |
return $this->addon_view( $data, $settings ); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Retrieves template arguments based on widget settings. |
| 43 |
* |
| 44 |
* @return array |
| 45 |
*/ |
| 46 |
private function get_template_args() { |
| 47 |
return [ |
| 48 |
'layout' => $this->settings['layout_style'], |
| 49 |
'title_tag' => $this->settings['heading_title_html_tag'] ?? 'h2', |
| 50 |
'has_title' => ! empty( $this->settings['heading_title_text'] ), |
| 51 |
'title' => $this->settings['heading_title_text'] ?? '', |
| 52 |
'has_sub_heading' => ! empty( $this->settings['display_subheading'] ) && ! empty( $this->settings['subheading_text'] ), |
| 53 |
'sub_heading' => $this->settings['subheading_text'] ?? '', |
| 54 |
'sub_heading_tag' => $this->settings['subheading_html_tag'] ?? 'span', |
| 55 |
'sub_heading_position' => $this->settings['rtsb_subheading_position'] ?? 'top', |
| 56 |
'has_separator' => ! empty( $this->settings['display_separator'] ), |
| 57 |
'has_description' => ! empty( $this->settings['display_description'] ) && ! empty( $this->settings['description_text'] ), |
| 58 |
'description' => $this->settings['description_text'] ?? '', |
| 59 |
'separator_position' => $this->settings['rtsb_separator_position'] ?? 'bottom', |
| 60 |
'display_left_bar' => ! empty( $this->settings['display_subheading_left_bar'] ), |
| 61 |
'display_right_bar' => ! empty( $this->settings['display_subheading_right_bar'] ), |
| 62 |
]; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Function to render the subheading. |
| 67 |
* |
| 68 |
* @param string $sub_heading The subheading text. |
| 69 |
* @param string $sub_heading_tag The HTML tag for the subheading. |
| 70 |
* @param string $left_bar The HTML for the left bar. |
| 71 |
* @param string $right_bar The HTML for the right bar. |
| 72 |
* |
| 73 |
* @return string |
| 74 |
*/ |
| 75 |
public static function render_subheading( $sub_heading, $sub_heading_tag, $left_bar, $right_bar ) { |
| 76 |
ob_start(); |
| 77 |
?> |
| 78 |
<div class="rtsb-advanced-heading-sub-title-wrap"> |
| 79 |
<div class="rtsb-advanced-heading-sub-title"> |
| 80 |
<?php |
| 81 |
Fns::print_html( $left_bar ); |
| 82 |
?> |
| 83 |
<<?php Fns::print_validated_html_tag( $sub_heading_tag ); ?> class="sub-heading-text"> |
| 84 |
<?php Fns::print_html( $sub_heading ); ?> |
| 85 |
</<?php Fns::print_validated_html_tag( $sub_heading_tag ); ?>> |
| 86 |
<?php |
| 87 |
Fns::print_html( $right_bar ); |
| 88 |
?> |
| 89 |
</div> |
| 90 |
</div> |
| 91 |
<?php |
| 92 |
return ob_get_clean(); |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Function to render the separator line. |
| 97 |
* |
| 98 |
* @param string $position Separator position ('top' or 'bottom'). |
| 99 |
* @param bool $has_separator Whether the separator is enabled. |
| 100 |
* @param string $separator_position Position of the separator in settings. |
| 101 |
* |
| 102 |
* @return string |
| 103 |
*/ |
| 104 |
public static function render_separator( $position, $has_separator, $separator_position ) { |
| 105 |
$html = ''; |
| 106 |
|
| 107 |
if ( $has_separator && $position === $separator_position ) { |
| 108 |
$html .= '<div class="rtsb-separator-line"></div>'; |
| 109 |
} |
| 110 |
|
| 111 |
return $html; |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Function to render the left or right subheading bars. |
| 116 |
* |
| 117 |
* @param string $position Bar position ('left' or 'right'). |
| 118 |
* @param bool $display_left_bar Whether to display the left bar. |
| 119 |
* @param bool $display_right_bar Whether to display the right bar. |
| 120 |
* |
| 121 |
* @return string |
| 122 |
*/ |
| 123 |
public static function render_title_bar( $position, $display_left_bar, $display_right_bar ) { |
| 124 |
$html = ''; |
| 125 |
|
| 126 |
// Render the left bar. |
| 127 |
if ( $display_left_bar && 'left' === $position ) { |
| 128 |
$html .= '<span class="rtsb-sub-title-bar rtsb-sub-title-bar-left"></span>'; |
| 129 |
} |
| 130 |
|
| 131 |
// Render the right bar. |
| 132 |
if ( $display_right_bar && 'right' === $position ) { |
| 133 |
$html .= '<span class="rtsb-sub-title-bar rtsb-sub-title-bar-right"></span>'; |
| 134 |
} |
| 135 |
|
| 136 |
return $html; |
| 137 |
} |
| 138 |
} |
| 139 |
|