1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
<?php
class SiteOrigin_Panels_Renderer_Legacy extends SiteOrigin_Panels_Renderer {
public static function single() { static $single; return empty( $single ) ? $single = new self() : $single; }
/** * Generate the CSS for the page layout. * * @param $post_id * @param $panels_data * @param $layout_data * * @return string */ public function generate_css( $post_id, $panels_data = false, $layout_data = false) { // Exit if we don't have panels data if ( empty( $panels_data ) ) { $panels_data = get_post_meta( $post_id, 'panels_data', true ); if( empty( $panels_data ) ) { return ''; } } if ( empty( $layout_data ) ) { $layout_data = $this->get_panels_layout_data( $panels_data ); $layout_data = apply_filters( 'siteorigin_panels_layout_data', $layout_data, $post_id ); }
// Get some of the default settings $settings = siteorigin_panels_setting(); $panels_tablet_width = $settings['tablet-width']; $panels_mobile_width = $settings['mobile-width']; $panels_margin_bottom = $settings['margin-bottom']; $panels_margin_bottom_last_row = $settings['margin-bottom-last-row'];
$css = new SiteOrigin_Panels_Css_Builder();
$ci = 0; foreach ( $layout_data as $ri => $row ) { if( empty( $row['cells'] ) ) continue;
// Let other themes and plugins change the gutter. $gutter = apply_filters( 'siteorigin_panels_css_row_gutter', $settings['margin-sides'] . 'px', $row, $ri, $panels_data ); preg_match( '/([0-9\.,]+)(.*)/', $gutter, $gutter_parts );
$cell_count = count( $row['cells'] );
// Add the cell sizing foreach( $row['cells'] as $ci => $cell ) { $weight = apply_filters( 'siteorigin_panels_css_cell_weight', $cell['weight'], $row, $ri, $cell, $ci - 1, $panels_data, $post_id );
// Add the width and ensure we have correct formatting for CSS. $css->add_cell_css( $post_id, $ri, $ci, '', array( 'width' => round( $weight * 100, 4 ) . '%', ) ); }
if( ! empty( $row['style']['collapse_order'] ) && $row['style']['collapse_order'] == 'right-top') { $css->add_cell_css( $post_id, $ri, false, '', array( 'float' => 'right' ) ); }
if( $ri != count( $layout_data ) - 1 || ! empty( $row[ 'style' ][ 'bottom_margin' ] ) || ! empty( $panels_margin_bottom_last_row ) ) { // Filter the bottom margin for this row with the arguments $css->add_row_css( $post_id, $ri, '', array( 'margin-bottom' => apply_filters( 'siteorigin_panels_css_row_margin_bottom', $panels_margin_bottom . 'px', $row, $ri, $panels_data, $post_id ) ) ); }
$margin_half = ( floatval( $gutter_parts[1] ) / 2 ) . $gutter_parts[2]; $css->add_row_css($post_id, $ri, '', array( 'margin-left' => '-' . $margin_half, 'margin-right' => '-' . $margin_half, ) ); $css->add_cell_css($post_id, $ri, false, '', array( 'padding-left' => $margin_half, 'padding-right' => $margin_half, ) ); }
// Add the bottom margins $css->add_widget_css( $post_id, false, false, false, '', array( 'margin-bottom' => apply_filters( 'siteorigin_panels_css_cell_margin_bottom', $panels_margin_bottom . 'px', false, false, $panels_data, $post_id ) ) ); $css->add_widget_css( $post_id, false, false, false, ':last-child', array( 'margin-bottom' => apply_filters( 'siteorigin_panels_css_cell_last_margin_bottom', '0px', false, false, $panels_data, $post_id ) ) );
if ( $settings['responsive'] ) { $css->add_cell_css($post_id, false, false, '', array( 'float' => 'none', 'width' => 'auto' ), $panels_mobile_width); $css->add_row_css($post_id, false, '', array( 'margin-left' => 0, 'margin-right' => 0, ), $panels_mobile_width); $css->add_cell_css( $post_id, false, false, '', array( 'padding' => 0, ), $panels_mobile_width );
// Hide empty cells on mobile $css->add_row_css( $post_id, false, ' .panel-grid-cell-empty', array( 'display' => 'none', ), $panels_mobile_width );
// Hide empty cells on mobile $css->add_row_css( $post_id, false, ' .panel-grid-cell-mobile-last', array( 'margin-bottom' => '0px', ), $panels_mobile_width ); foreach ( $layout_data as $ri => $row ) { $css->add_cell_css( $post_id, $ri, false, '', array( 'margin-bottom' => $panels_margin_bottom . 'px', ), $panels_mobile_width ); $css->add_cell_css( $post_id, $ri, false, ':last-child', array( 'margin-bottom' => '0px', ), $panels_mobile_width ); } }
foreach ( $panels_data['widgets'] as $widget_id => $widget ) { if ( ! empty( $widget['panels_info']['style']['link_color'] ) ) { $css->add_widget_css( $post_id, $widget['panels_info']['grid'], $widget['panels_info']['cell'], $widget['panels_info']['cell_index'], ' a', array( 'color' => $widget['panels_info']['style']['link_color'] ) ); } }
// Let other plugins and components filter the CSS object. $css = apply_filters( 'siteorigin_panels_css_object', $css, $panels_data, $post_id, $layout_data );
return $css->get_css(); }
/** * This overwrites the parent function to get the cells in reverse order when using right_on_top collapse mode. * * @param $cells The cells to modify * @param $row The row the cells belong to * * @return mixed */ protected function modify_row_cells( $cells, $row ){ if( ! empty( $row['style']['collapse_order'] ) && $row['style']['collapse_order'] == 'right-top') { $cells = array_reverse( $cells, true ); }
return $cells;
} public function front_css_url(){ return siteorigin_panels_url( 'css/front' . ( siteorigin_panels_setting( 'legacy-layout' ) ? '-legacy' : '' ) . '.css' ); } }
|