PluginProbe
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code / 4.0.3
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code v4.0.3
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 4.0.3, at classes/elementor/widgets/table/widget.php

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