Skip to content

Commit

Permalink
Merge pull request #807 from siteorigin/release/2.11.3
Browse files Browse the repository at this point in the history
Release/2.11.3
  • Loading branch information
Misplon authored Sep 14, 2020
2 parents 77ced4c + 788c0d2 commit 065d4b9
Show file tree
Hide file tree
Showing 18 changed files with 327 additions and 119 deletions.
71 changes: 59 additions & 12 deletions compat/js/siteorigin-panels-layout-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,46 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _createSuper(Derived) {
function isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;

try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}

return function () {
var Super = _getPrototypeOf(Derived),
result;

if (isNativeReflectConstruct()) {
var NewTarget = _getPrototypeOf(this).constructor;

result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}

return _possibleConstructorReturn(this, result);
};
}

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

var _lodash = lodash,
isEqual = _lodash.isEqual,
debounce = _lodash.debounce,
Expand All @@ -34,7 +64,6 @@ var _wp$components = wp.components,
Toolbar = _wp$components.Toolbar,
IconButton = _wp$components.IconButton,
Spinner = _wp$components.Spinner;
var __ = wp.i18n.__;
var _window = window,
soPanelsBlockEditorAdmin = _window.soPanelsBlockEditorAdmin;

Expand All @@ -43,12 +72,14 @@ var SiteOriginPanelsLayoutBlock =
function (_Component) {
_inherits(SiteOriginPanelsLayoutBlock, _Component);

var _super = _createSuper(SiteOriginPanelsLayoutBlock);

function SiteOriginPanelsLayoutBlock(props) {
var _this;

_classCallCheck(this, SiteOriginPanelsLayoutBlock);

_this = _possibleConstructorReturn(this, _getPrototypeOf(SiteOriginPanelsLayoutBlock).call(this, props));
_this = _super.call(this, props);
var editMode = soPanelsBlockEditorAdmin.defaultMode === 'edit' || isEmpty(props.panelsData);
_this.state = {
editing: editMode,
Expand Down Expand Up @@ -167,6 +198,12 @@ function (_Component) {
}
});
jQuery(document).trigger('panels_setup', this.builderView);

if ( typeof window.soPanelsBuilderView == 'undefined' ) {
window.soPanelsBuilderView = [];
}
window.soPanelsBuilderView.push( this.builderView );

this.panelsInitialized = true;
}
}, {
Expand Down Expand Up @@ -222,7 +259,7 @@ function (_Component) {
return React.createElement(Fragment, null, React.createElement(BlockControls, null, React.createElement(Toolbar, null, React.createElement(IconButton, {
icon: "visibility",
className: "components-icon-button components-toolbar__control",
label: __('Preview layout.', 'siteorigin-panels'),
label: wp.i18n.__('Preview layout.', 'siteorigin-panels'),
onClick: switchToPreview
}))), React.createElement("div", {
key: "layout-block",
Expand All @@ -234,7 +271,7 @@ function (_Component) {
return React.createElement(Fragment, null, React.createElement(BlockControls, null, React.createElement(Toolbar, null, React.createElement(IconButton, {
icon: "edit",
className: "components-icon-button components-toolbar__control",
label: __('Edit layout.', 'siteorigin-panels'),
label: wp.i18n.__('Edit layout.', 'siteorigin-panels'),
onClick: switchToEditing
}))), React.createElement("div", {
key: "preview",
Expand All @@ -252,15 +289,18 @@ function (_Component) {
return SiteOriginPanelsLayoutBlock;
}(Component);

var hasLayoutCategory = wp.blocks.getCategories().some(function (category) {
return category.slug === 'layout';
});
registerBlockType('siteorigin-panels/layout-block', {
title: __('SiteOrigin Layout', 'siteorigin-panels'),
description: __("Build a layout using SiteOrigin's Page Builder.", 'siteorigin-panels'),
title: wp.i18n.__('SiteOrigin Layout', 'siteorigin-panels'),
description: wp.i18n.__("Build a layout using SiteOrigin's Page Builder.", 'siteorigin-panels'),
icon: function icon() {
return React.createElement("span", {
className: "siteorigin-panels-block-icon"
});
},
category: 'layout',
category: hasLayoutCategory ? 'layout' : 'design',
keywords: ['page builder', 'column,grid', 'panel'],
supports: {
html: false
Expand Down Expand Up @@ -364,4 +404,11 @@ registerBlockType('siteorigin-panels/layout-block', {
}, 100);
});
}
})(jQuery);
})(jQuery);

// Detect preview mode changes, and trigger resize.
jQuery(document).on('click', '.block-editor-post-preview__button-resize', function (e) {
if (!jQuery(this).hasClass('has-icon')) {
jQuery(window).trigger('resize');
}
});
28 changes: 22 additions & 6 deletions compat/js/siteorigin-panels-layout-block.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const { registerBlockType } = wp.blocks;
const { Component, Fragment, RawHTML, createRef } = wp.element;
const { BlockControls } = wp.editor;
const { Toolbar, IconButton, Spinner } = wp.components;
const { __ } = wp.i18n;
const { soPanelsBlockEditorAdmin } = window;

class SiteOriginPanelsLayoutBlock extends Component {
Expand Down Expand Up @@ -118,6 +117,12 @@ class SiteOriginPanelsLayoutBlock extends Component {
} );

jQuery( document ).trigger( 'panels_setup', this.builderView );

if ( typeof window.soPanelsBuilderView == 'undefined' ) {
window.soPanelsBuilderView = [];
}
window.soPanelsBuilderView.push( this.builderView );
}

this.panelsInitialized = true;
}
Expand Down Expand Up @@ -169,7 +174,7 @@ class SiteOriginPanelsLayoutBlock extends Component {
<IconButton
icon="visibility"
className="components-icon-button components-toolbar__control"
label={ __( 'Preview layout.', 'siteorigin-panels' ) }
label={ wp.i18n.__( 'Preview layout.', 'siteorigin-panels' ) }
onClick={ switchToPreview }
/>
</Toolbar>
Expand All @@ -190,7 +195,7 @@ class SiteOriginPanelsLayoutBlock extends Component {
<IconButton
icon="edit"
className="components-icon-button components-toolbar__control"
label={ __( 'Edit layout.', 'siteorigin-panels' ) }
label={ wp.i18n.__( 'Edit layout.', 'siteorigin-panels' ) }
onClick={ switchToEditing }
/>
</Toolbar>
Expand All @@ -212,16 +217,20 @@ class SiteOriginPanelsLayoutBlock extends Component {
}
}

var hasLayoutCategory = wp.blocks.getCategories().some( function( category ) {
return category.slug === 'layout';
} );

registerBlockType( 'siteorigin-panels/layout-block', {
title: __( 'SiteOrigin Layout', 'siteorigin-panels' ),
title: wp.i18n.__( 'SiteOrigin Layout', 'siteorigin-panels' ),

description: __( "Build a layout using SiteOrigin's Page Builder.", 'siteorigin-panels' ),
description: wp.i18n.__( "Build a layout using SiteOrigin's Page Builder.", 'siteorigin-panels' ),

icon () {
return <span className="siteorigin-panels-block-icon"/>;
},

category: 'layout',
category: hasLayoutCategory ? 'layout' : 'design',

keywords: [ 'page builder', 'column,grid', 'panel' ],

Expand Down Expand Up @@ -330,3 +339,10 @@ registerBlockType( 'siteorigin-panels/layout-block', {
}

} )( jQuery );

// Detect preview mode changes, and trigger resize.
jQuery( document ).on( 'click', '.block-editor-post-preview__button-resize', function( e ) {
if ( ! jQuery( this ).hasClass('has-icon') ) {
jQuery( window ).trigger( 'resize' );
}
} );
7 changes: 7 additions & 0 deletions compat/layout-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public function __construct() {
// This action is slightly later than `enqueue_block_editor_assets`,
// which we need to use to ensure our templates are loaded at the right time.
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_layout_block_editor_assets' ) );

// We need to override the container when using the Block Editor to allow for resizing.
add_filter( 'siteorigin_panels_full_width_container', array( $this, 'override_container' ) );
}

public function register_layout_block() {
Expand Down Expand Up @@ -113,4 +116,8 @@ private function sanitize_panels_data( $panels_data ) {
$panels_data = SiteOrigin_Panels_Styles_Admin::single()->sanitize_all( $panels_data );
return $panels_data;
}

function override_container( $container ) {
return SiteOrigin_Panels_Admin::is_block_editor() ? '.editor-styles-wrapper' : $container;
}
}
40 changes: 40 additions & 0 deletions compat/yoast-sitemap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* Returns a list of all images added using Page Builder.
*
* @param $images an array of all detected images used in the current post.
* @param $post_id the current post id.
*
* @return array
*/
function siteorigin_yoast_sitemap_images_compat( $images, $post_id ) {
if (
get_post_meta( $post_id, 'panels_data', true ) &&
extension_loaded( 'xml' ) &&
class_exists( 'DOMDocument' )
) {
$content = SiteOrigin_Panels::renderer()->render(
$post_id,
false
);

libxml_use_internal_errors( true );
$dom = new DOMDocument();
$dom->loadHTML( '<?xml encoding="UTF-8">' . $content );
libxml_clear_errors();

foreach ( $dom->getElementsByTagName( 'img' ) as $img ) {
$src = $img->getAttribute( 'src' );

if ( ! empty( $src ) && $src == esc_url( $src ) ) {
$images[] = array(
'src' => $src,
);
}
}
}

return $images;
}
add_filter( 'wpseo_sitemap_urlimages', 'siteorigin_yoast_sitemap_images_compat', 10, 2 );
13 changes: 11 additions & 2 deletions inc/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,17 @@ function enqueue_admin_scripts( $prefix = '', $force = false ) {

public function enqueue_seo_compat(){
if ( self::is_admin() ) {
if ( defined( 'WPSEO_FILE' ) && wp_script_is( 'yoast-seo-metabox' ) ) {
if (
defined( 'WPSEO_FILE' ) &&
(
wp_script_is( 'yoast-seo-admin-global-script' ) || // => 14.6
wp_script_is( 'yoast-seo-metabox' ) // <= 14.5
)
) {
wp_enqueue_script(
'so-panels-seo-compat',
siteorigin_panels_url( 'js/seo-compat' . SITEORIGIN_PANELS_JS_SUFFIX . '.js' ),
array('jquery', 'yoast-seo-metabox' ),
array( 'jquery' ),
SITEORIGIN_PANELS_VERSION,
true
);
Expand Down Expand Up @@ -1124,6 +1130,9 @@ function action_builder_content_json() {

$GLOBALS[ 'SITEORIGIN_PANELS_PREVIEW_RENDER' ] = true;
$return['preview'] = SiteOrigin_Panels::renderer()->render( intval( $_POST['post_id'] ), false, $panels_data );
if ( function_exists( 'wp_targeted_link_rel' ) ) {
$return['preview'] = wp_targeted_link_rel( $return['preview'] );
}
unset( $GLOBALS[ 'SITEORIGIN_PANELS_PREVIEW_RENDER' ] );

echo json_encode( $return );
Expand Down
2 changes: 1 addition & 1 deletion inc/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function generate_css( $post_id, $panels_data = false, $layout_data = fal

// Filter the bottom margin for this row with the arguments
$panels_margin_bottom = apply_filters( 'siteorigin_panels_css_row_margin_bottom', $settings['margin-bottom'] . 'px', $row, $ri, $panels_data, $post_id );
$panels_mobile_margin_bottom = apply_filters( 'siteorigin_panels_css_row_mobile_margin_bottom', '', $row, $ri, $panels_data, $post_id );
$panels_mobile_margin_bottom = apply_filters( 'siteorigin_panels_css_row_mobile_margin_bottom', $settings['row-mobile-margin-bottom'] . 'px', $row, $ri, $panels_data, $post_id );

if ( empty( $row['cells'] ) ) {
continue;
Expand Down
28 changes: 18 additions & 10 deletions inc/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,16 @@ function settings_defaults( $defaults ) {
$defaults['instant-open-widgets'] = false;

// The layout fields
$defaults['responsive'] = true;
$defaults['tablet-layout'] = false;
$defaults['legacy-layout'] = 'auto';
$defaults['tablet-width'] = 1024;
$defaults['mobile-width'] = 780;
$defaults['margin-bottom'] = 30;
$defaults['margin-bottom-last-row'] = false;
$defaults['margin-sides'] = 30;
$defaults['full-width-container'] = 'body';
$defaults['responsive'] = true;
$defaults['tablet-layout'] = false;
$defaults['legacy-layout'] = 'auto';
$defaults['tablet-width'] = 1024;
$defaults['mobile-width'] = 780;
$defaults['margin-bottom'] = 30;
$defaults['row-mobile-margin-bottom'] = '';
$defaults['margin-bottom-last-row'] = false;
$defaults['margin-sides'] = 30;
$defaults['full-width-container'] = 'body';

// Content fields
$defaults['copy-content'] = true;
Expand Down Expand Up @@ -253,7 +254,7 @@ function settings_fields( $fields ) {

$fields['general']['fields']['use-classic'] = array(
'type' => 'checkbox',
'label' => __( 'Use Classic Editor for new posts', 'siteorigin-panels' ),
'label' => __( 'Use Classic Editor for New Posts', 'siteorigin-panels' ),
'description' => __( 'New posts of the above Post Types will be created using the Classic Editor.', 'siteorigin-panels' )
);

Expand Down Expand Up @@ -417,6 +418,13 @@ function settings_fields( $fields ) {
'description' => __( 'Default margin below rows and widgets.', 'siteorigin-panels' ),
);

$fields['layout']['fields']['row-mobile-margin-bottom'] = array(
'type' => 'number',
'unit' => 'px',
'label' => __( 'Row Mobile Bottom Margin', 'siteorigin-panels' ),
'description' => __( 'The default margin below rows on mobile.', 'siteorigin-panels' ),
);

$fields['layout']['fields']['margin-bottom-last-row'] = array(
'type' => 'checkbox',
'label' => __( 'Last Row With Margin', 'siteorigin-panels' ),
Expand Down
Loading

0 comments on commit 065d4b9

Please sign in to comment.