PluginProbe
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code / 3.4.2
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code v3.4.2
5.5.3 3.1.0 3.2.0 3.2.1 3.3.0 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.6.0 3.7.0 3.8.0 3.8.1 3.8.2 3.8.3 4.0.0 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 4.1.1 All 78 releases
copy-the-code / classes / elementor / widgets / table / widget.php

widget.php in Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code 3.4.2, at classes/elementor/widgets/table/widget.php

219 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Elementor Table Block
5 *
6 * @package Copy the Code
7 * @since 3.4.0
8 */
9 namespace CopyTheCode\Elementor\Block;
10
11 use CopyTheCode\Helpers ;
12 use Elementor\Widget_Base ;
13 use Elementor\Controls_Manager ;
14 /**
15 * Table Block
16 *
17 * @since 3.4.0
18 */
19 class Table extends Widget_Base
20 {
21 /**
22 * Constructor
23 *
24 * @param array $data
25 * @param array $args
26 *
27 * @since 3.4.0
28 */
29 public function __construct( $data = array(), $args = null )
30 {
31 parent::__construct( $data, $args );
32 // Block.
33 wp_enqueue_style(
34 'ctc-el-table',
35 COPY_THE_CODE_URI . 'classes/elementor/widgets/table/style.css',
36 [ 'ctc-blocks-core' ],
37 COPY_THE_CODE_VER,
38 'all'
39 );
40 }
41
42 /**
43 * Get style dependencies
44 */
45 public function get_style_depends()
46 {
47 return [ 'ctc-el-table' ];
48 }
49
50 /**
51 * Get name
52 */
53 public function get_name()
54 {
55 return 'ctc_table';
56 }
57
58 /**
59 * Get title
60 */
61 public function get_title()
62 {
63 return esc_html__( 'Table', 'copy-the-code' );
64 }
65
66 /**
67 * Get icon
68 */
69 public function get_icon()
70 {
71 return 'eicon-table';
72 }
73
74 /**
75 * Get categories
76 */
77 public function get_categories()
78 {
79 return Helpers::get_categories();
80 }
81
82 /**
83 * Get keywords
84 */
85 public function get_keywords()
86 {
87 return Helpers::get_keywords( [
88 'table',
89 'copy',
90 'code',
91 'copy the code',
92 'vertical',
93 'horizontal',
94 'compare',
95 'comparison',
96 'pricing',
97 'pricing table'
98 ] );
99 }
100
101 /**
102 * Render
103 */
104 public function render()
105 {
106 $is_horizontal = $this->get_settings_for_display( 'is_horizontal' );
107 $content = $this->get_settings_for_display( 'copy_content' );
108 if ( !$content ) {
109 return;
110 }
111 // Convert the content which is the csv comma seperated values to array.
112 $content = explode( "\n", $content );
113 // Remove the first element from the array which is the header.
114 $header = array_shift( $content );
115 // Convert the header to array.
116 $header = explode( ',', $header );
117 // Convert the content to array.
118 $content = array_map( function ( $item ) {
119 return explode( ',', $item );
120 }, $content );
121 ?>
122 <div class="ctc-block ctc-table">
123 <div class="ctc-table-wrap">
124 <?php
125
126 if ( $is_horizontal === 'yes' ) {
127 $this->render_horizontal( $header, $content );
128 } else {
129 $this->render_vertical( $header, $content );
130 }
131
132 ?>
133 </div>
134 <div class="ctc-block-actions">
135 <?php
136 Helpers::render_copy_button( $this );
137 ?>
138 </div>
139 <?php
140 Helpers::render_copy_content( $this );
141 ?>
142 </div>
143 <?php
144 }
145
146 /**
147 * Render horizontal
148 */
149 function render_horizontal( $header, $content )
150 {
151 echo '<table class="ctc-table--horizontal">' ;
152 foreach ( $header as $heading_index => $heading ) {
153 echo '<tr>' ;
154 echo '<td class="ctc-table__key">' . esc_html( $heading ) . '</td>' ;
155 foreach ( $content as $row ) {
156 echo '<td class="ctc-table__value">' . do_shortcode( '[copy_inline text="' . esc_html( $row[$heading_index] ) . '"]' ) . '</td>' ;
157 }
158 echo '</tr>' ;
159 }
160 echo '</table>' ;
161 }
162
163 /**
164 * Render vertical
165 */
166 function render_vertical( $header, $content )
167 {
168 echo '<table class="ctc-table--vertical">' ;
169 echo '<tr>' ;
170 // Output table headers
171 foreach ( $header as $heading ) {
172 echo '<th class="ctc-table__key">' . esc_html( $heading ) . '</th>' ;
173 }
174 echo '</tr>' ;
175 // Output table content
176 foreach ( $content as $row ) {
177 echo '<tr>' ;
178 foreach ( $row as $value ) {
179 echo '<td class="ctc-table__value">' . do_shortcode( '[copy_inline text="' . esc_html( $value ) . '"]' ) . '</td>' ;
180 }
181 echo '</tr>' ;
182 }
183 echo '</table>' ;
184 }
185
186 /**
187 * Register controls
188 */
189 protected function _register_controls()
190 {
191 Helpers::register_copy_content_section( $this, [
192 'label' => esc_html__( 'Table Content (Comma Separated Values)', 'copy-the-code' ),
193 'default' => 'Processor number, Graphics, Cores/Threads, Graphics (EUs), Cache, Memory, Operating range, Base Freq (GHz), Max Single Core Turbo (GHz; up to), Max All Core Turbo (GHz; up to), Graphics Max Freq (GHz; up to), Intel DL Bost/Intel GMA 2.0
194 Intel Core i7-1160G7, Intel Iris X, 4/8, 96, 12MB, LPDDR4x-4266, 7-15W, 1.2, 4.4, 3.6, 1.1, Yes
195 Intel Core i5-1130G7, Intel Iris X, 4/8, 80, 8MB, LPDDR4x-4266, 7-15W, 1.1, 4.0, 3.4, 1.1, Yes
196 Intel Core i3-1120G4, Intel UHD Graphics, 4/8, 48, 8MB, LPDDR4x-4266, 7-15W, 1.1, 3.5, 3.0, 1.1, Yes
197 Intel Core i3-1110G4, Intel UHD Graphics, 2/4, 48, 6MB, LPDDR4x-4266, 7-15W, 1.8, 3.9, 3.9, 1.1, Yes',
198 'before_controls' => [
199 'is_horizontal' => [
200 'label' => esc_html__( 'Is Horizontal', 'copy-the-code' ),
201 'type' => Controls_Manager::SWITCHER,
202 'label_on' => esc_html__( 'Yes', 'copy-the-code' ),
203 'label_off' => esc_html__( 'No', 'copy-the-code' ),
204 'return_value' => 'yes',
205 'default' => 'yes',
206 ],
207 ],
208 ] );
209 Helpers::register_copy_button_section( $this );
210 Helpers::register_pro_sections( $this, [
211 'Table',
212 'Headings',
213 'Odd Rows',
214 'Even Rows'
215 ] );
216 Helpers::register_copy_button_style_section( $this );
217 }
218
219 }