Skip to content

Commit

Permalink
v1.2.2 hotfix for page builder background and border options. They we…
Browse files Browse the repository at this point in the history
…re broken in previous release
  • Loading branch information
aprokopenko committed May 15, 2017
1 parent f6fb64e commit 4406b1c
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 30 deletions.
81 changes: 81 additions & 0 deletions framework/PageBuilder/v25/Layouts/Layout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace JustCoded\ThemeFramework\PageBuilder\v25\Layouts;

/**
* Class Layout
* Starting from Page Builder v2.5 all inline css were moved into separate inline css block.
* Since we remove all inline css from PageBuilder - we need to enable back this feature.
*
* For image attachment we can use rwd plugin for better support.
*/
class Layout {
/**
* Image size for background image in case of RWD plugin enabled.
*
* @var string
*/
public $background_image_size = 'large';

/**
* Generate inline styles, from Design Page Builder options
*
* @param array $style_data Style options array.
* @param string $unique_selector Unique block selector (for rwd function).
*
* @return array
*/
protected function generate_inline_styles( $style_data, $unique_selector = '' ) {
$styles = array();

// generate bg color.
if ( ! empty( $style_data['background'] ) ) {
$styles['bg_color'] = 'background-color: ' . $style_data['background'];
}

// generate border color.
if ( ! empty( $style_data['border_color'] ) ) {
$styles['border'] = 'border: 1px solid ' . $style_data['border_color'];
}

// print background and bg position.
if ( ! empty( $style_data['background_image_attachment'] ) ) {
// in case we have rwd plugin - print bg in responsive manner.
if ( is_plugin_active( 'just-responsive-images/just-responsive-images.php' ) ) {
rwd_attachment_background( ".$unique_selector", $style_data['background_image_attachment'], $this->background_image_size );
} elseif ( $url = wp_get_attachment_image_url( $style_data['background_image_attachment'], 'full' ) ) {
// otherwise just use full image as bg.
$styles['bg_image'] = 'background-image: url(' . $url . ')';
}

switch ( $style_data['background_display'] ) {
case 'parallax':
case 'parallax-original':
$styles['bg_pos'] = 'background-position:center center';
$styles['bg_repeat'] = 'background-repeat:no-repeat';
break;
case 'tile':
$styles['bg_repeat'] = 'background-repeat:repeat';
break;
case 'cover':
$styles['bg_pos'] = 'background-position:center center';
$styles['bg_size'] = 'background-size:cover';
break;
case 'center':
$styles['bg_pos'] = 'background-position:center center';
$styles['bg_repeat'] = 'background-repeat:no-repeat';
break;
case 'fixed':
$styles['bg_attach'] = 'background-attachment:fixed';
$styles['bg_pos'] = 'background-position:center center';
$styles['bg_size'] = 'background-size:cover';
break;
}
} // End if().

$styles = implode( ';', $styles );

return $styles;
}

}
7 changes: 6 additions & 1 deletion framework/PageBuilder/v25/Layouts/RowLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @package JustCoded\ThemeFramework\SOPanels
*/
class RowLayout {
class RowLayout extends Layout {
/**
* Row Layout identifier
* should be overwritten in child class
Expand Down Expand Up @@ -98,6 +98,11 @@ public function row( $attributes, $panel_data ) {
* @return array update attributes
*/
public function row_inner( $attributes, $style_data ) {
$style_class = "pb-style-r{$this->row_index}";
if ( ! empty( $style_data['background_image_attachment'] ) ) {
$attributes['class'][] = $style_class;
}
$attributes['style'] = $this->generate_inline_styles( $style_data, $style_class );
return $attributes;
}

Expand Down
26 changes: 26 additions & 0 deletions framework/PageBuilder/v25/Layouts/RwdWidgetLayout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
namespace JustCoded\ThemeFramework\PageBuilder\v25\Layouts;

/**
* Class WidgetLayout
*
* @package JustCoded\ThemeFramework\SOPanels
*/
class RwdWidgetLayout extends WidgetLayout {
/**
* Widget Layout identifier
* should be overwritten in child class
*
* @var string
*/
public static $ID = 'default';

/**
* Widget Layout display name
* should be overwritten in child class
*
* @var string
*/
public static $TITLE = 'Default';

}
14 changes: 13 additions & 1 deletion framework/PageBuilder/v25/Layouts/WidgetLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @package JustCoded\ThemeFramework\SOPanels
*/
class WidgetLayout {
class WidgetLayout extends Layout {
/**
* Widget Layout identifier
* should be overwritten in child class
Expand All @@ -30,6 +30,13 @@ class WidgetLayout {
*/
public $widget_index;

/**
* Unique widget index.
*
* @var integer
*/
public static $unique_index;

/**
* WidgetLayout constructor.
*
Expand Down Expand Up @@ -72,6 +79,11 @@ public function options() {
* @return array update attributes
*/
public function widget( $attributes, $style_data ) {
$style_class = 'pb-style-w' . ( (int) self::$unique_index ++ );
if ( ! empty( $style_data['background_image_attachment'] ) ) {
$attributes['class'][] = $style_class;
}
$attributes['style'] = $this->generate_inline_styles( $style_data, $style_class );
return $attributes;
}

Expand Down
25 changes: 9 additions & 16 deletions framework/PageBuilder/v25/Traits/RowLayoutsLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ trait RowLayoutsLoader {
*/
protected $layouts = array();

/**
* Default RowLayout to be loaded if it's not specified by Row settings manually
*
* @var string
*/
public $default_row_layout = '\JustCoded\ThemeFramework\PageBuilder\v25\RwdRowLayout';

/**
* Define is layout currently in use for specific row.
*
Expand All @@ -42,11 +35,6 @@ public function row_layouts_loader() {

add_filter( 'siteorigin_panels_before_row', array( $this, 'set_row_before' ), 10, 3 );
add_filter( 'siteorigin_panels_after_row', array( $this, 'set_row_after' ), 10, 3 );

// registers default layout.
if ( ! empty( $this->default_row_layout ) ) {
$this->register_row_layout( $this->default_row_layout, 'Default' );
}
}

/**
Expand All @@ -58,6 +46,14 @@ public function row_layouts_loader() {
*/
public function add_row_options( $fields ) {
$layouts = $this->get_list_layouts();
if ( empty( $layouts ) ) {
unset( $fields['background'] );
unset( $fields['background_image_attachment'] );
unset( $fields['background_display'] );
unset( $fields['border_color'] );
return $fields;
}

$fields['row_template'] = array(
'name' => 'Row layout',
'type' => 'select',
Expand Down Expand Up @@ -103,9 +99,6 @@ public function register_row_layout( $class_name, $title = '' ) {
protected function get_list_layouts() {
$list = array();

if ( empty( $this->default_row_layout ) ) {
$list[''] = 'Default';
}
foreach ( $this->layouts as $key => $lt ) {
$list[ $key ] = $lt::$TITLE;
}
Expand All @@ -127,7 +120,7 @@ protected function check_layout_in_use( $style_data ) {
if ( isset( $this->layouts[ $layout_key ] ) ) {
return $this->layouts[ $layout_key ];
}
} elseif ( ! empty( $this->default_row_layout ) ) {
} elseif ( ! empty( $this->layouts ) ) {
return reset( $this->layouts );
}

Expand Down
28 changes: 17 additions & 11 deletions framework/PageBuilder/v25/Traits/WidgetLayoutsLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,22 @@ public function widget_layouts_loader() {
*/
public function add_widget_options( $fields ) {
$layouts = $this->get_list_widgets();
if ( ! empty( $layouts ) ) {
$fields['widget_template'] = array(
'name' => 'Widget layout',
'type' => 'select',
'group' => 'layout',
'options' => $layouts,
'priority' => 10,
);
if ( empty( $layouts ) ) {
unset( $fields['background'] );
unset( $fields['background_image_attachment'] );
unset( $fields['background_display'] );
unset( $fields['border_color'] );
return $fields;
}

$fields['widget_template'] = array(
'name' => 'Widget layout',
'type' => 'select',
'group' => 'layout',
'options' => $layouts,
'priority' => 10,
);

// add additional options from layouts.
foreach ( $this->widgets as $layout ) {
if ( $options = $layout->options() ) {
Expand Down Expand Up @@ -86,9 +92,7 @@ public function register_widget_layout( $class_name ) {
* @return array (id, title) pairs
*/
protected function get_list_widgets() {
$list = array(
'' => 'Default',
);

foreach ( $this->widgets as $key => $lt ) {
$list[ $key ] = $lt::$TITLE;
}
Expand All @@ -110,6 +114,8 @@ protected function check_widget_layout_in_use( $style_data ) {
if ( isset( $this->widgets[ $layout_key ] ) ) {
return $this->widgets[ $layout_key ];
}
} elseif ( ! empty( $this->widgets ) ) {
return reset( $this->widgets );
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion just-theme-framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin Name: Just Theme Framework
Description: Lightweight MVC theming framework for developers who want to better organize their own custom themes with an MVC approach.
Tags: mvc theme, theme boilerplate, oop theme, mini framework
Version: 1.2.1
Version: 1.2.2
Author: JustCoded / Alex Prokopenko
Author URI: http://justcoded.com/
License: GPL3
Expand Down
2 changes: 2 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ To upgrade remove the old plugin folder. After than follow the installation step

== Changelog ==

= Version 1.2.2 - 12 May 2017 =
* Hotfix: Page Builder design options (background, borders) were missing in new version. Fixed.
= Version 1.2.1 - 12 May 2017 =
* Improvement: Change wp hook to widgets_init for register_widget method
= Version 1.2 - 12 May 2017 =
Expand Down

0 comments on commit 4406b1c

Please sign in to comment.