PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.19
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.19
1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk All 48 releases
fluent-cart / app / Modules / Templating / Bricks / Elements / ProductTitle.php

ProductTitle.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.19, at app/Modules/Templating/Bricks/Elements/ProductTitle.php

123 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace FluentCart\App\Modules\Templating\Bricks\Elements;
3
4 use Bricks\Element;
5
6 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
7
8 class ProductTitle extends Element {
9 public $category = 'fluent_cart_product';
10 public $name = 'fct-product-title';
11 public $icon = 'ti-text';
12 public $tag = 'h1';
13
14 public function get_label() {
15 return esc_html__( 'Product title (FluentCart)', 'fluent-cart' );
16 }
17
18 public function set_controls() {
19 $this->controls['tag'] = [
20 'tab' => 'content',
21 'label' => esc_html__( 'HTML tag', 'fluent-cart' ),
22 'type' => 'select',
23 'options' => [
24 'h1' => 'h1',
25 'h2' => 'h2',
26 'h3' => 'h3',
27 'h4' => 'h4',
28 'h5' => 'h5',
29 'h6' => 'h6',
30 ],
31 'inline' => true,
32 'placeholder' => 'h1',
33 ];
34
35 $this->controls['prefix'] = [
36 'tab' => 'content',
37 'label' => esc_html__( 'Prefix', 'fluent-cart' ),
38 'type' => 'text',
39 'inline' => true,
40 ];
41
42 $this->controls['prefixBlock'] = [
43 'tab' => 'content',
44 'label' => esc_html__( 'Prefix block', 'fluent-cart' ),
45 'type' => 'checkbox',
46 'inline' => true,
47 'required' => [ 'prefix', '!=', '' ],
48 ];
49
50 $this->controls['suffix'] = [
51 'tab' => 'content',
52 'label' => esc_html__( 'Suffix', 'fluent-cart' ),
53 'type' => 'text',
54 'inline' => true,
55 ];
56
57 $this->controls['suffixBlock'] = [
58 'tab' => 'content',
59 'label' => esc_html__( 'Suffix block', 'fluent-cart' ),
60 'type' => 'checkbox',
61 'inline' => true,
62 'required' => [ 'suffix', '!=', '' ],
63 ];
64
65 $this->controls['linkToProduct'] = [
66 'tab' => 'content',
67 'label' => esc_html__( 'Link to product', 'fluent-cart' ),
68 'type' => 'checkbox',
69 ];
70 }
71
72 public function render() {
73 $settings = $this->settings;
74
75
76 $prefix = ! empty( $settings['prefix'] ) ? $settings['prefix'] : false;
77 $suffix = ! empty( $settings['suffix'] ) ? $settings['suffix'] : false;
78 $link_to_product = isset( $settings['linkToProduct'] );
79 $output = '';
80
81 if ( $link_to_product ) {
82 $output .= '<a href="' . get_the_permalink( $this->post_id ) . '">';
83 }
84
85 if ( $prefix ) {
86 $this->set_attribute( 'prefix', 'class', [ 'post-prefix' ] );
87
88 $output .= isset( $settings['prefixBlock'] ) ? "<div {$this->render_attributes( 'prefix' )}>{$prefix}</div>" : "<span {$this->render_attributes( 'prefix' )}>{$prefix}</span>";
89 }
90
91 $post = get_post( $this->post_id );
92
93 $output .= $post->post_title;
94
95 if ( $suffix ) {
96 $this->set_attribute( 'suffix', 'class', [ 'post-suffix' ] );
97
98 $output .= isset( $settings['suffixBlock'] ) ? "<div {$this->render_attributes( 'suffix' )}>{$suffix}</div>" : "<span {$this->render_attributes( 'suffix' )}>{$suffix}</span>";
99 }
100
101 if ( $link_to_product ) {
102 $output .= '</a>';
103 }
104 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- render_attributes() handles escaping, output is escaped
105 echo "<" . esc_html($this->tag) . " {$this->render_attributes( '_root' )}>" . wp_kses_post($output) . "</" . esc_html($this->tag) . ">";
106 }
107
108 public static function render_builder() { ?>
109 <script type="text/x-template" id="tmpl-brxe-product-title">
110 <component :is="tag" class="product-title">
111 <div v-if="settings.prefix && settings.prefixBlock" class="post-prefix" v-html="settings.prefix"></div>
112 <span v-else-if="settings.prefix && !settings.prefixBlock" class="post-prefix" v-html="settings.prefix"></span>
113
114 <span v-html="bricks.wp.post.title"></span>
115
116 <div v-if="settings.suffix && settings.suffixBlock" class="post-suffix" v-html="settings.suffix"></div>
117 <span v-else-if="settings.suffix && !settings.suffixBlock" class="post-suffix" v-html="settings.suffix"></span>
118 </component>
119 </script>
120 <?php
121 }
122 }
123