PluginProbe
YayMail – WooCommerce Email Customizer / trunk
YayMail – WooCommerce Email Customizer vtrunk
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 trunk, at src/Elements/ColumnLayout.php

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