/** * Render the panels * * @param int|string|bool $post_id The Post ID or 'home'. * @param bool $enqueue_css Should we also enqueue the layout CSS. * @param array|bool $panels_data Existing panels data. By default load from settings or post meta. * @return string */ function siteorigin_panels_render($post_id = false, $enqueue_css = true, $panels_data = false) { if (empty($post_id)) { $post_id = get_the_ID(); } global $siteorigin_panels_current_post; $old_current_post = $siteorigin_panels_current_post; $siteorigin_panels_current_post = $post_id; // Try get the cached panel from in memory cache. //global $siteorigin_panels_cache; //if ( !empty( $siteorigin_panels_cache ) && !empty( $siteorigin_panels_cache[$post_id] ) ) // return $siteorigin_panels_cache[$post_id]; if (empty($panels_data)) { if ($post_id == 'home') { $panels_data = get_option('siteorigin_panels_home_page', get_theme_mod('panels_home_page', null)); if (is_null($panels_data)) { // Load the default layout $layouts = apply_filters('siteorigin_panels_prebuilt_layouts', array()); $panels_data = !empty($layouts['home']) ? $layouts['home'] : current($layouts); } } else { //Allowing rendering for password protected Tab( wc_product_tab ) post types if (post_password_required($post_id) && get_post_type($post_id) != 'wc_product_tab') { return false; } $panels_data = get_post_meta($post_id, 'panels_data', true); } } $panels_data = apply_filters('siteorigin_panels_data', $panels_data, $post_id); if (empty($panels_data) || empty($panels_data['grids'])) { return ''; } //Removing filters for proper functionality remove_filter('the_content', 'wptexturize'); //wptexturize : Replaces each & with & unless it already looks like an entity remove_filter('the_content', 'convert_chars'); //convert_chars : Converts lone & characters into & ( a.k.a. & ) remove_filter('the_content', 'wpautop'); //wpautop : Adds the Stupid Paragraphs for two line breaks // Create the skeleton of the grids $grids = array(); if (!empty($panels_data['grids']) && !empty($panels_data['grids'])) { foreach ($panels_data['grids'] as $gi => $grid) { $gi = intval($gi); $grids[$gi] = array(); for ($i = 0; $i < $grid['cells']; $i++) { $grids[$gi][$i] = array(); } } } if (!empty($panels_data['widgets']) && is_array($panels_data['widgets'])) { foreach ($panels_data['widgets'] as $widget) { $grids[intval($widget['info']['grid'])][intval($widget['info']['cell'])][] = $widget; } } ob_start(); global $siteorigin_panels_inline_css; if (empty($siteorigin_panels_inline_css)) { $siteorigin_panels_inline_css = ''; } if ($enqueue_css) { if (siteorigin_panels_setting('inline-css')) { wp_enqueue_style('siteorigin-panels-front'); $siteorigin_panels_inline_css .= siteorigin_panels_generate_css($post_id, $panels_data); } else { // This is the CSS for the page layout. wp_enqueue_style('siteorigin-panels-post-css-' . $post_id, add_query_arg(array('action' => 'siteorigin_panels_post_css', 'post' => $post_id, 'layout' => substr(md5(serialize($panels_data)), 0, 8)), admin_url('admin-ajax.php')), array('siteorigin-panels-front'), POOTLEPAGE_VERSION); } } foreach ($grids as $gi => $cells) { // This allows other themes and plugins to add html before the row echo apply_filters('siteorigin_panels_before_row', '', $panels_data['grids'][$gi]); $grid_classes = apply_filters('siteorigin_panels_row_classes', array('panel-grid'), $panels_data['grids'][$gi]); $grid_attributes = apply_filters('siteorigin_panels_row_attributes', array('class' => implode(' ', $grid_classes), 'id' => 'pg-' . $post_id . '-' . $gi), $panels_data['grids'][$gi]); echo '<div '; foreach ($grid_attributes as $name => $value) { echo $name . '="' . esc_attr($value) . '" '; } echo '>'; $style_attributes = array(); if (!empty($panels_data['grids'][$gi]['style']['class'])) { $style_attributes['class'] = array('panel-row-style-' . $panels_data['grids'][$gi]['style']['class']); } // Themes can add their own attributes to the style wrapper $styleArray = !empty($panels_data['grids'][$gi]['style']) ? $panels_data['grids'][$gi]['style'] : array(); $style_attributes = apply_filters('siteorigin_panels_row_style_attributes', $style_attributes, $styleArray); if (!empty($style_attributes)) { if (empty($style_attributes['class'])) { $style_attributes['class'] = array(); } $style_attributes['class'][] = 'panel-row-style'; $style_attributes['class'] = array_unique($style_attributes['class']); echo '<div '; foreach ($style_attributes as $name => $value) { if (is_array($value)) { echo $name . '="' . esc_attr(implode(" ", array_unique($value))) . '" '; } else { echo $name . '="' . esc_attr($value) . '" '; } } echo '>'; } if (isset($styleArray['background']) && isset($styleArray['background_color_over_image']) && $styleArray['background_color_over_image'] == true) { $rowID = '#pg-' . $post_id . '-' . $gi; ?> <style> /* make this sit under .panel-row-style:before, so background color will be on top on background image */ <?php echo esc_attr($rowID); ?> > .panel-row-style:before { background-color: <?php echo $styleArray['background']; ?> ; } <?php echo esc_attr($rowID); ?> > .panel-row-style { position: relative; z-index: 10; } <?php echo esc_attr($rowID); ?> > .panel-row-style:before { position: absolute; width: 100%; height: 100%; content: ""; top: 0; left: 0; z-index: 20; } .panel-grid-cell-container { position: relative; z-index: 30; /* row content needs to be on top of row background color */ } </style> <?php } echo "<div class='panel-grid-cell-container'>"; foreach ($cells as $ci => $widgets) { // Themes can add their own styles to cells $cellId = 'pgc-' . $post_id . '-' . $gi . '-' . $ci; $cell_classes = apply_filters('siteorigin_panels_row_cell_classes', array('panel-grid-cell'), $panels_data); $cell_attributes = apply_filters('siteorigin_panels_row_cell_attributes', array('class' => implode(' ', $cell_classes), 'id' => $cellId), $panels_data); echo '<div '; foreach ($cell_attributes as $name => $value) { echo $name . '="' . esc_attr($value) . '" '; } echo '>'; foreach ($widgets as $pi => $widget_info) { $data = $widget_info; $widgetStyle = isset($data['info']['style']) ? json_decode($data['info']['style'], true) : pp_get_default_widget_style(); unset($data['info']); // don't do shortcode or it will mess up shortcodes when WP do shortcode at the end if ($widget_info['info']['class'] == 'Pootle_Text_Widget') { remove_filter('widget_text', 'do_shortcode'); if (isset($widget_info['hide-title']) && $widget_info['hide-title'] == '1') { $widgetStyle['hide-title'] = 'none'; } } siteorigin_panels_the_widget($widget_info['info']['class'], $data, $widgetStyle, $gi, $ci, $pi, $pi == 0, $pi == count($widgets) - 1, $post_id); if ($widget_info['info']['class'] == 'Pootle_Text_Widget') { add_filter('widget_text', 'do_shortcode'); } // post loop css for multiple columns if ($widget_info['info']['class'] == "SiteOrigin_Panels_Widgets_PostLoop") { $css = ''; if (isset($widget_info['column_count'])) { $count = (int) $widget_info['column_count']; // fix division by zero if ($count < 1) { $count = 1; } $width = 100 / $count . "%"; $cssId = 'panel-' . $post_id . '-' . $gi . '-' . $ci . '-' . $pi; $css .= "#{$cssId} {\n"; $css .= "\t" . "font-size: 0; \n"; $css .= "}\n"; $css .= "#{$cssId} > article {\n"; $css .= "\t" . "width: " . $width . ";\n"; $css .= "\t" . 'display: inline-block;' . "\n"; $css .= "\t" . 'box-sizing: border-box;' . "\n"; $css .= "\t" . 'padding-right: 10px;' . "\n"; $css .= "\t" . 'vertical-align: top;' . "\n"; $css .= "}\n"; } if (isset($widget_info['post_meta_enable'])) { if ($widget_info['post_meta_enable'] != '1') { $cssId = 'panel-' . $post_id . '-' . $gi . '-' . $ci . '-' . $pi; $css .= "#{$cssId} > article > .post-meta {\n"; $css .= "\t" . "display: none;\n"; $css .= "}\n"; } } echo "<style>\n" . $css . "</style>\n"; } if ($widget_info['info']['class'] == "Woo_Widget_Component") { wp_reset_query(); } } if (empty($widgets)) { echo ' '; } echo '</div>'; } echo "</div>"; echo '</div>'; if (!empty($style_attributes)) { echo '</div>'; } // This allows other themes and plugins to add html after the row echo apply_filters('siteorigin_panels_after_row', '', $panels_data['grids'][$gi]); } $html = ob_get_clean(); // Reset the current post $siteorigin_panels_current_post = $old_current_post; return apply_filters('siteorigin_panels_render', $html, $post_id, !empty($post) ? $post : null); }
/** * Convert form post data into more efficient panels data. * * @param $form_post * @return array */ function siteorigin_panels_get_panels_data_from_post($form_post) { $panels_data = array(); $panels_data['widgets'] = array_values(stripslashes_deep(isset($form_post['widgets']) ? $form_post['widgets'] : array())); // save data ( e.g. row styling ) even if no widget is in row // if ( empty( $panels_data['widgets'] ) ) return array(); foreach ($panels_data['widgets'] as $i => $widget) { $info = $widget['info']; if (!class_exists($info['class'])) { continue; } $the_widget = new $info['class'](); $widget = json_decode($widget['data'], true); if (method_exists($the_widget, 'update') && !empty($info['raw'])) { $widget = $the_widget->update($widget, $widget); } unset($info['raw']); $widget['info'] = $info; // if widget style is not present in $_POST, set a default if (!isset($info['style'])) { $widgetStyle = pp_get_default_widget_style(); $info['style'] = $widgetStyle; } $panels_data['widgets'][$i] = $widget; } $panels_data['grids'] = array_values(stripslashes_deep(isset($form_post['grids']) ? $form_post['grids'] : array())); $panels_data['grid_cells'] = array_values(stripslashes_deep(isset($form_post['grid_cells']) ? $form_post['grid_cells'] : array())); return apply_filters('siteorigin_panels_panels_data_from_post', $panels_data); }