| 1 |
<?php |
| 2 |
/** |
| 3 |
* Render class for Pricing Table widget. |
| 4 |
* |
| 5 |
* @package RadiusTheme\SB |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace RadiusTheme\SB\Elementor\Widgets\General\PricingTable; |
| 9 |
|
| 10 |
use RadiusTheme\SB\Elementor\Helper\RenderHelpers; |
| 11 |
use RadiusTheme\SB\Helpers\Fns; |
| 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/pricing_table/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 |
return [ |
| 49 |
'sb_pricing_table_title_html_tag' => $this->settings['sb_pricing_table_title_html_tag'] ?? 'h2', |
| 50 |
'sb_pricing_table_title' => $this->settings['sb_pricing_table_title'], |
| 51 |
'preset_layout' => $this->settings['layout_style'] ?? 'rtsb-pricing-table-layout1', |
| 52 |
'has_description' => ! empty( $this->settings['display_content'] ) && ! empty( $this->settings['sb_pricing_table_content'] ), |
| 53 |
'has_table_icon' => ! empty( $this->settings['sb_pricing_table_display_icon'] ), |
| 54 |
'description' => $this->settings['sb_pricing_table_content'] ?? '', |
| 55 |
'has_button' => ! empty( $this->settings['display_button'] ), |
| 56 |
'price' => $this->settings['sb_pricing_table_price'], |
| 57 |
'has_sale_price' => ! empty( $this->settings['sale_price'] ) && ! empty( $this->settings['sb_pricing_table_sale_price'] ), |
| 58 |
'sale_price' => $this->settings['sb_pricing_table_sale_price'], |
| 59 |
'price_currency' => $this->settings['sb_pricing_table_currency'] ?? '$', |
| 60 |
'currency_position' => $this->settings['sb_pricing_table_currency_position'] ?? 'left', |
| 61 |
'price_unit' => $this->settings['sb_pricing_table_unit'] ?? 'mo', |
| 62 |
'price_unit_separator' => $this->settings['sb_pricing_table_unit_separator'] ?? '/', |
| 63 |
'has_badge' => ! empty( $this->settings['sb_pricing_table_badge'] ), |
| 64 |
'badge_style' => $this->settings['sb_pricing_table_badge_style'], |
| 65 |
'badge_text' => $this->settings['sb_pricing_table_badge_text'] ?? '', |
| 66 |
'offer_text' => $this->settings['sb_pricing_table_offer_text'] ?? '', |
| 67 |
'badge_position' => $this->settings['sb_pricing_table_badge_position'] ?? 'right', |
| 68 |
'sb_button_content' => $this->settings['sb_button_content'], |
| 69 |
'sb_button_icon' => $this->settings['sb_button_icon'] ?? '', |
| 70 |
'sb_button_icon_position' => $this->settings['sb_button_icon_position'] ?? 'right', |
| 71 |
'button_attributes' => $this->render_button_attributes( 'rtsb_button_' . $id, 'sb_button_link', 'primary-btn' ) ?? '', |
| 72 |
'icon_html' => $this->render_icon_image(), |
| 73 |
'feature_item_html' => $this->render_pricing_table_feature(), |
| 74 |
'icon_type' => $this->settings['sb_pricing_table_icon_type'], |
| 75 |
'icon_bg_type' => ! empty( $this->settings['pricing_table_icon_style_gradient_bg_background'] ) ? $this->settings['pricing_table_icon_style_gradient_bg_background'] : 'classic', |
| 76 |
'badge_bg_type' => ! empty( $this->settings['pricing_table_badge_style_gradient_bg_background'] ) ? $this->settings['pricing_table_badge_style_gradient_bg_background'] : 'classic', |
| 77 |
]; |
| 78 |
} |
| 79 |
/** |
| 80 |
* Function to render button attributes. |
| 81 |
* |
| 82 |
* @param string $id Element ID. |
| 83 |
* |
| 84 |
* @return string |
| 85 |
*/ |
| 86 |
public function render_button_attributes( $id, $control_name, $class, $type = 'rtsb-btn' ) { |
| 87 |
if ( ! empty( $this->settings['hover_animation'] ) ) { |
| 88 |
$class .= ' ' . 'hover-' . $this->settings['hover_animation']; |
| 89 |
} |
| 90 |
$this->add_attribute( $id, 'class', $type . ' ' . $class ); |
| 91 |
|
| 92 |
if ( ! empty( $this->settings[ $control_name ]['url'] ) ) { |
| 93 |
$this->add_link_attributes( $id, $this->settings[ $control_name ] ); |
| 94 |
} else { |
| 95 |
$this->add_attribute( $id, 'role', 'button' ); |
| 96 |
} |
| 97 |
|
| 98 |
return $this->get_attribute_string( $id ); |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Function to render icon. |
| 103 |
* |
| 104 |
* @param string $position icon position ('left' or 'right'). |
| 105 |
* @param array $icon Position of the separator in settings. |
| 106 |
* |
| 107 |
* @return string |
| 108 |
*/ |
| 109 |
public static function render_icon( $position, $icon, $icon_position ) { |
| 110 |
$html = ''; |
| 111 |
|
| 112 |
// Render the left icon. |
| 113 |
if ( $position === $icon_position ) { |
| 114 |
$html .= '<span class="icon">' . Fns::icons_manager( $icon ) . '</span>'; |
| 115 |
} |
| 116 |
|
| 117 |
return $html; |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Function to render icon image. |
| 122 |
* |
| 123 |
* @return string |
| 124 |
*/ |
| 125 |
public function render_icon_image() { |
| 126 |
$icon_img_html = ''; |
| 127 |
|
| 128 |
$icon = $this->settings['sb_pricing_table_icon'] ?? ''; |
| 129 |
|
| 130 |
if ( 'icon' === $this->settings['sb_pricing_table_icon_type'] ) { |
| 131 |
$icon_img_html .= '<span class="icon">' . Fns::icons_manager( $icon ) . '</span>'; |
| 132 |
} else { |
| 133 |
if ( ! empty( $this->settings['sb_pricing_table_image'] ) ) { |
| 134 |
$c_image_size = RenderHelpers::get_data( $this->settings, 'sb_pricing_table_img_dimension', [] ); |
| 135 |
$c_image_size['crop'] = RenderHelpers::get_data( $this->settings, 'sb_pricing_table_img_crop', [] ); |
| 136 |
$c_image_size = ! empty( $c_image_size ) && is_array( $c_image_size ) ? $c_image_size : []; |
| 137 |
$image_id = ! empty( $this->settings['sb_pricing_table_image']['id'] ) ? $this->settings['sb_pricing_table_image']['id'] : $this->settings['sb_pricing_table_image']; |
| 138 |
$icon_img_html .= Fns::get_product_image_html( |
| 139 |
'', |
| 140 |
null, |
| 141 |
RenderHelpers::get_data( $this->settings, 'sb_pricing_table_image_size', 'full' ), |
| 142 |
$image_id, |
| 143 |
$c_image_size |
| 144 |
); |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
return $icon_img_html; |
| 149 |
} |
| 150 |
/** |
| 151 |
* Function to render feature. |
| 152 |
* |
| 153 |
* @return string |
| 154 |
*/ |
| 155 |
public function render_pricing_table_feature() { |
| 156 |
$feature_html = ''; |
| 157 |
if ( ! empty( $this->settings['sb_pricing_table_feature_items'] ) ) { |
| 158 |
|
| 159 |
$feature_html .= '<ul class="rtsb-feature-list">'; |
| 160 |
foreach ( $this->settings['sb_pricing_table_feature_items'] as $key => $item ) { |
| 161 |
$cross_text = ! empty( $item['sb_pricing_table_feature_cross_text'] ) ? 'has-cross-text' : ''; |
| 162 |
$feature_html .= '<li class="list-type-' . esc_attr( $item['sb_pricing_table_list_style'] . ' ' . $cross_text ) . '">'; |
| 163 |
if ( 'icon' === $item['sb_pricing_table_list_style'] ) { |
| 164 |
$feature_html .= '<span class="list-icon">' . Fns::icons_manager( $item['sb_pricing_table_feature_icon'] ) . '</span>'; |
| 165 |
} |
| 166 |
$feature_html .= '<span class="list-text">' . $item['sb_pricing_table_feature_text'] . '</span>'; |
| 167 |
$feature_html .= '</li>'; |
| 168 |
} |
| 169 |
$feature_html .= '</ul>'; |
| 170 |
|
| 171 |
} |
| 172 |
return $feature_html; |
| 173 |
} |
| 174 |
/** |
| 175 |
* Function to render price. |
| 176 |
* |
| 177 |
* @return string |
| 178 |
*/ |
| 179 |
public static function render_price( $has_sale_price, $currency_position, $price_currency, $price, $sale_price, $price_unit, $price_unit_separator ) { |
| 180 |
ob_start(); |
| 181 |
?> |
| 182 |
<div class="rtsb-pricing-wrap"> |
| 183 |
<div class="rtsb-price-wrap-inner"> |
| 184 |
<span class="rtsb-price-wrap"> |
| 185 |
<span class="rtsb-orginal-price <?php echo esc_attr( $has_sale_price ? 'line-through' : '' ); ?>"> |
| 186 |
<?php Fns::print_html( self::render_price_currency( 'left', $currency_position, $price_currency ) ); ?> |
| 187 |
<span class="rtsb-price"><?php Fns::print_html( $price ); ?></span> |
| 188 |
<?php Fns::print_html( self::render_price_currency( 'right', $currency_position, $price_currency ) ); ?> |
| 189 |
</span> |
| 190 |
<?php if ( $has_sale_price ) { ?> |
| 191 |
<span class="rtsb-sale-price"> |
| 192 |
<?php Fns::print_html( self::render_price_currency( 'left', $currency_position, $price_currency ) ); ?> |
| 193 |
<span class="rtsb-price"><?php Fns::print_html( $sale_price ); ?></span> |
| 194 |
<?php Fns::print_html( self::render_price_currency( 'right', $currency_position, $price_currency ) ); ?> |
| 195 |
</span> |
| 196 |
<?php } ?> |
| 197 |
</span> |
| 198 |
<?php if ( $price_unit ) { ?> |
| 199 |
<span class="rtsb-price-period"> |
| 200 |
<?php |
| 201 |
if ( $price_unit_separator ) : |
| 202 |
?> |
| 203 |
<span class="period-seperator"><?php Fns::print_html( $price_unit_separator ); ?></span><?php endif; ?> |
| 204 |
<span class="period-text"><?php Fns::print_html( $price_unit ); ?></span> |
| 205 |
</span> |
| 206 |
<?php } ?> |
| 207 |
</div> |
| 208 |
</div> |
| 209 |
<?php |
| 210 |
return ob_get_clean(); |
| 211 |
} |
| 212 |
|
| 213 |
/** |
| 214 |
* Function to render the badge. |
| 215 |
* |
| 216 |
* @param bool $has_badge Whether the badge is enabled. |
| 217 |
* @param string $badge_style Badge Presets. |
| 218 |
* @param string $badge_text Badge Text. |
| 219 |
* @param string $badge_position Separator position ('left' or 'right'). |
| 220 |
* @return string |
| 221 |
*/ |
| 222 |
public static function render_badge( $has_badge, $badge_style, $badge_text, $badge_position, $badge_bg_type ) { |
| 223 |
ob_start(); |
| 224 |
$feature_icon_svg = '<svg width="12" height="22" viewBox="0 0 12 22" fill="none" xmlns="http://www.w3.org/2000/svg"> |
| 225 |
<path d="M5 14H0L7 0V8H12L5 22V14Z" fill="white"/> |
| 226 |
</svg>'; |
| 227 |
?> |
| 228 |
<?php |
| 229 |
if ( $has_badge ) { |
| 230 |
if ( 'rtsb-pricing-table-badge-preset4' === $badge_style ) { |
| 231 |
?> |
| 232 |
<span class="rtsb-ribbon-span <?php echo esc_attr( $badge_style . ' ' . $badge_position . ' ' . 'has-' . $badge_bg_type ); ?>"> |
| 233 |
<span class="badge-icon"> |
| 234 |
<?php Fns::print_html( $feature_icon_svg ); ?> |
| 235 |
</span> |
| 236 |
</span> |
| 237 |
<?php |
| 238 |
} else { |
| 239 |
?> |
| 240 |
<span class="rtsb-ribbon-span <?php echo esc_attr( $badge_style . ' ' . $badge_position . ' ' . 'has-' . $badge_bg_type ); ?>"> |
| 241 |
<?php Fns::print_html( $badge_text ); ?> |
| 242 |
<span class="triangle-bar bar-one"> </span> |
| 243 |
<span class="triangle-bar bar-two"></span> |
| 244 |
</span> |
| 245 |
<?php |
| 246 |
} |
| 247 |
} |
| 248 |
?> |
| 249 |
<?php |
| 250 |
return ob_get_clean(); |
| 251 |
} |
| 252 |
/** |
| 253 |
* Function to render the left or right price currency. |
| 254 |
* |
| 255 |
* @param string $position currency position ('left' or 'right'). |
| 256 |
* |
| 257 |
* @return string |
| 258 |
*/ |
| 259 |
public static function render_price_currency( $position, $currency_position, $currency ) { |
| 260 |
$html = ''; |
| 261 |
// Render the left currency. |
| 262 |
if ( $position === $currency_position ) { |
| 263 |
$html .= '<span class="rtsb-currency">' . $currency . '</span>'; |
| 264 |
} |
| 265 |
return $html; |
| 266 |
} |
| 267 |
} |
| 268 |
|