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