PluginProbe
YayMail – WooCommerce Email Customizer / 4.3.4
YayMail – WooCommerce Email Customizer v4.3.4
4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 3.4.2 3.4.3 All 55 releases
yaymail / src / Elements / ColumnLayout.php

ColumnLayout.php in YayMail – WooCommerce Email Customizer 4.3.4, at src/Elements/ColumnLayout.php

190 lines 9.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace YayMail\Elements;
3
4 use YayMail\Abstracts\BaseElement;
5 use YayMail\Utils\SingletonTrait;
6
7 /**
8 * Column Elements
9 */
10 class ColumnLayout extends BaseElement {
11
12 use SingletonTrait;
13
14 protected static $type = 'column_layout';
15
16 public $available_email_ids = [ YAYMAIL_ALL_EMAILS ];
17
18 public static function get_data( $amount = 1, $attributes = [] ) {
19 return [
20 'id' => uniqid(),
21 'type' => self::$type,
22 'name' => self::get_name( $amount ),
23 'icon' => self::get_icon( $amount ),
24 'group' => 'general',
25 'available' => true,
26 'position' => 150,
27 'children' => isset( $attributes['children'] ) ? $attributes['children'] : self::get_nested_columns( $amount ),
28 'data' => [
29 'amount_of_columns' => [
30 'value_path' => 'amount_of_columns',
31 'default_value' => $amount,
32 ],
33 'column_width' => [
34 'value_path' => 'column_width',
35 'component' => 1 == $amount ? '' : 'ColumnWidth',
36 'title' => __( 'Column width (%)', 'yaymail' ),
37 'default_value' => [],
38 // Trick to bypass checking value_path
39 ],
40 'column_spacing' => [
41 'value_path' => 'column_spacing',
42 'component' => 'Dimension',
43 'title' => __( 'Column spacing', 'yaymail' ),
44 'default_value' => isset( $attributes['column_spacing'] ) ? $attributes['column_spacing'] : '0',
45 'min' => 0,
46 'max' => 100,
47 'type' => 'style',
48 ],
49 'container_setting_breaker' => [
50 'component' => 'LineBreaker',
51 ],
52 'container_setting_group_definition' => [
53 'component' => 'GroupDefinition',
54 'title' => __( 'Container layout settings', 'yaymail' ),
55 'description' => __( 'Handle container layout settings', 'yaymail' ),
56 ],
57 'padding' => [
58 'value_path' => 'padding',
59 'component' => 'Spacing',
60 'title' => __( 'Padding', 'yaymail' ),
61 'default_value' => isset( $attributes['padding'] ) ? $attributes['padding'] : [
62 'top' => '15',
63 'right' => '0',
64 'bottom' => '15',
65 'left' => '0',
66 ],
67 'type' => 'style',
68 ],
69 'border_radius' => [
70 'value_path' => 'border_radius',
71 'component' => 'BorderRadius',
72 'title' => __( 'Border radius', 'yaymail' ),
73 'default_value' => [
74 'top_left' => isset( $attributes['border_radius']['top_left'] ) ? $attributes['border_radius']['top_left'] : '0',
75 'top_right' => isset( $attributes['border_radius']['top_right'] ) ? $attributes['border_radius']['top_right'] : '0',
76 'bottom_left' => isset( $attributes['border_radius']['bottom_left'] ) ? $attributes['border_radius']['bottom_left'] : '0',
77 'bottom_right' => isset( $attributes['border_radius']['bottom_right'] ) ? $attributes['border_radius']['bottom_right'] : '0',
78 ],
79 'type' => 'style',
80 ],
81 'background_color' => [
82 'value_path' => 'background_color',
83 'component' => 'Color',
84 'title' => __( 'Background color', 'yaymail' ),
85 'default_value' => isset( $attributes['background_color'] ) ? $attributes['background_color'] : '#fff',
86 'type' => 'style',
87 ],
88 'background_image' => [
89 'value_path' => 'background_image',
90 'component' => 'BackgroundImage',
91 'title' => __( 'Background image', 'yaymail' ),
92 'default_value' => isset( $attributes['background_image'] ) ? $attributes['background_image'] : [
93 'url' => '',
94 'position' => 'default',
95 'x_position' => 0,
96 'y_position' => 0,
97 'repeat' => 'default',
98 'size' => 'default',
99 ],
100 'type' => 'style',
101 ],
102 'inner_setting_breaker' => [
103 'component' => 'LineBreaker',
104 ],
105 'inner_setting_group_definition' => [
106 'component' => 'GroupDefinition',
107 'title' => __( 'Inner layout settings', 'yaymail' ),
108 'description' => __( 'Handle inner layout settings', 'yaymail' ),
109 ],
110 'inner_border_radius' => [
111 'value_path' => 'inner_border_radius',
112 'component' => 'BorderRadius',
113 'title' => __( 'Inner border radius', 'yaymail' ),
114 'default_value' => [
115 'top_left' => isset( $attributes['inner_border_radius']['top_left'] ) ? $attributes['inner_border_radius']['top_left'] : '0',
116 'top_right' => isset( $attributes['inner_border_radius']['top_right'] ) ? $attributes['inner_border_radius']['top_right'] : '0',
117 'bottom_left' => isset( $attributes['inner_border_radius']['bottom_left'] ) ? $attributes['inner_border_radius']['bottom_left'] : '0',
118 'bottom_right' => isset( $attributes['inner_border_radius']['bottom_right'] ) ? $attributes['inner_border_radius']['bottom_right'] : '0',
119 ],
120 'type' => 'style',
121 ],
122 'inner_background_color' => [
123 'value_path' => 'inner_background_color',
124 'component' => 'Color',
125 'title' => __( 'Inner background color', 'yaymail' ),
126 'default_value' => isset( $attributes['inner_background_color'] ) ? $attributes['inner_background_color'] : '#ffffff00',
127 'type' => 'style',
128 ],
129 ],
130 ];
131 }
132
133 private static function get_nested_columns( $amount ) {
134 if ( ! isset( $amount ) || $amount <= 0 ) {
135 return [];
136 }
137 $width = 100 / $amount;
138
139 $nested_columms = [];
140 for ( $i = 0; $i < $amount; $i++ ) {
141 array_push(
142 $nested_columms,
143 Column::get_data( $width )
144 );
145 }
146
147 return $nested_columms;
148 }
149
150 private static function get_name( $amount ) {
151 $column_names = [
152 1 => __( 'One Column', 'yaymail' ),
153 2 => __( 'Two Columns', 'yaymail' ),
154 3 => __( 'Three Columns', 'yaymail' ),
155 4 => __( 'Four Columns', 'yaymail' ),
156 ];
157
158 return isset( $column_names[ $amount ] ) ? $column_names[ $amount ] : 'Column';
159 }
160
161 private static function get_icon( $amount ) {
162 $icons = [
163 1 => '<svg xmlns="http://www.w3.org/2000/svg" id="Layer_1" data-name="Layer 1" viewBox="0 0 20 20">
164 <path d="M18.75,1.25v17.5H1.25V1.25h17.5M19,1H1v18h18V1h0Z"/>
165 <rect x="8.4" y="1.94" width="3.2" height="16.12"/>
166 </svg>',
167 2 => '<svg xmlns="http://www.w3.org/2000/svg" id="Layer_1" data-name="Layer 1" viewBox="0 0 20 20">
168 <path d="M18.75,1.25v17.5H1.25V1.25h17.5M19,1H1v18h18V1h0Z"/>
169 <rect x="2.12" y="1.94" width="7.2" height="16.12"/>
170 <rect x="10.66" y="1.94" width="7.2" height="16.12"/>
171 </svg>',
172 3 => '<svg xmlns="http://www.w3.org/2000/svg" id="Layer_1" data-name="Layer 1" viewBox="0 0 20 20">
173 <path d="M18.75,1.25v17.5H1.25V1.25h17.5M19,1H1v18h18V1h0Z"/>
174 <rect x="2.07" y="1.94" width="4.36" height="16.12"/>
175 <rect x="7.79" y="1.94" width="4.36" height="16.12"/>
176 <rect x="13.51" y="1.94" width="4.36" height="16.12"/>
177 </svg>',
178 4 => '<svg xmlns="http://www.w3.org/2000/svg" id="Layer_1" data-name="Layer 1" viewBox="0 0 20 20">
179 <path d="M18.75,1.25v17.5H1.25V1.25h17.5M19,1H1v18h18V1h0Z"/>
180 <rect x="2.07" y="1.94" width="3.2" height="16.12"/>
181 <rect x="6.26" y="1.94" width="3.2" height="16.12"/>
182 <rect x="10.46" y="1.94" width="3.2" height="16.12"/>
183 <rect x="14.66" y="1.94" width="3.2" height="16.12"/>
184 </svg>',
185 ];
186
187 return isset( $icons[ $amount ] ) ? $icons[ $amount ] : $icons[1];
188 }
189 }
190