PluginProbe
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code / 5.5.4
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code v5.5.4
5.5.4 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 All 79 releases
copy-the-code / includes / elementor / widgets / table / widget.php

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

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