Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 74 additions & 1 deletion src/compatibility/blocksy/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,77 @@ function stackable_blocksy_global_color_schemes_compatibility( $styles, $scheme,
}

add_filter( 'stackable.global-settings.global-color-schemes.add-theme-compatibility', 'stackable_blocksy_global_color_schemes_compatibility', 10, 6 );
}
}

if ( ! function_exists( 'stackable_blocksy_theme_global_styles' ) ) {
function stackable_sanitize_css_string( $css ) {
if ( ! is_string( $css ) ) {
return '';
}

// sanitize css content
$css = wp_strip_all_tags( $css );
$css = preg_replace('/\bexpression\s*\([^)]*\)/i', '', $css);
$css = preg_replace('/\bjavascript\s*:/i', '', $css);

// clean urls
$css = preg_replace('/url\(\s*[\'"]?\s*https?:\/\/[^\'")]+\s*[\'"]?\s*\)/i', 'url("")', $css);

// Block unsafe tokens
$css = preg_replace('/\b(?:eval|mocha)\b(\s*:|\s*\()/i', '/* blocked */$1', $css);

// Block behavior and vendor-prefixed behavior
$css = preg_replace('/(?<![a-zA-Z0-9-])(?:-+[a-zA-Z]*behavior|behavior)\b(\s*:|\s*\()/i', '/* blocked */$1', $css);

// Remove redundant semicolons
$css = preg_replace('/;+/', ';', $css);

// Remove empty rule blocks (e.g. ".selector { }")
$css = preg_replace('/[^{]+\{\s*\}/m', '', $css);

// Normalize spacing and line breaks
$css = preg_replace('/\s+/', ' ', $css);
$css = trim($css);

return $css;
}

function stackable_blocksy_theme_global_styles( $styles ) {

if ( function_exists( 'blocksy_manager' ) ) {
$blocksy_css = blocksy_manager()->dynamic_css->load_backend_dynamic_css([
'echo' => false
] );

$styles .= $blocksy_css;
}

if ( class_exists( 'Blocksy_Static_Css_Files' ) ) {
$blocksy_static_files = ( new Blocksy_Static_Css_Files() )->all_static_files();

$blocksy_static_files = array_filter(
$blocksy_static_files,
function( $file ) {
return isset( $file['id'] ) && in_array( $file['id'], array( 'ct-main-styles', 'ct-stackable-styles' ), true );
}
);

foreach ( $blocksy_static_files as $file ) {
if ( isset( $file['url'] ) ) {
$file_path = get_template_directory() . $file['url'];
$mime = mime_content_type( $file_path );
$is_valid_mime = $mime === 'text/css' || $mime === 'text/plain';
if ( file_exists( $file_path ) && is_readable( $file_path ) && $is_valid_mime ) {
$styles .= file_get_contents( $file_path );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this contents come from a file, we would need to add some sanitization here

}
}
}
}

// sanitize all added styles once
$styles = stackable_sanitize_css_string( $styles );
return $styles;
}

add_filter( 'stackable.design-library.global-theme-styles', 'stackable_blocksy_theme_global_styles' );
}
1 change: 1 addition & 0 deletions src/compatibility/blocksy/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
:where(.stk--is-blocksy-theme.stk--has-default-container-scheme) {
--stk-default-link-color: var(--theme-link-initial-color);
--stk-default-heading-color: var(--theme-heading-color, var(--theme-headings-color));
--stk-default-button-background-color: var(--theme-button-background-initial-color);

:where(.stk-block-heading) {
@for $i from 1 through 6 {
Expand Down
1 change: 1 addition & 0 deletions src/compatibility/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
require_once( plugin_dir_path( __FILE__ ) . './neve/index.php' );
require_once( plugin_dir_path( __FILE__ ) . './ewww.php' );
require_once( plugin_dir_path( __FILE__ ) . './woocommerce.php' );
require_once( plugin_dir_path( __FILE__ ) . './blocksy/index.php' );
12 changes: 12 additions & 0 deletions src/design-library/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public function __construct() {
add_action( 'rest_api_init', array( $this, 'register_route' ) );

add_action( 'stackable_delete_design_library_cache', array( $this, 'delete_cache_v3' ) );

add_filter( 'stackable_localize_script', array( $this, 'add_wp_theme_global_styles' ) );
}

public static function validate_string( $value, $request, $param ) {
Expand Down Expand Up @@ -299,6 +301,16 @@ public function get_design_library( $request ) {
public static function get_cdn_url() {
return trailingslashit( STACKABLE_DESIGN_LIBRARY_URL );
}

public function add_wp_theme_global_styles( $args ) {
$wp_global_styles = apply_filters( 'stackable.design-library.global-theme-styles', '' );

$wp_global_styles .= wp_get_global_stylesheet();

$args['wpGlobalStylesInlineCss'] = $wp_global_styles;

return $args;
}
}

new Stackable_Design_Library();
Expand Down
5 changes: 0 additions & 5 deletions src/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,6 @@ public function register_block_editor_assets() {

$version_parts = explode( '-', STACKABLE_VERSION );

$wp_global_styles = wp_get_global_stylesheet();

global $content_width;
global $wp_version;
$args = apply_filters( 'stackable_localize_script', array(
Expand Down Expand Up @@ -373,9 +371,6 @@ public function register_block_editor_assets() {
'settings' => apply_filters( 'stackable_js_settings', array() ),
'isContentOnlyMode' => apply_filters( 'stackable_editor_role_is_content_only', false ),
'blockCategoryIndex' => apply_filters( 'stackable_block_category_index', 0 ),

// Global Styles for Design Library
'wpGlobalStylesInlineCss' => $wp_global_styles,
) );
wp_localize_script( 'wp-blocks', 'stackable', $args );
}
Expand Down
Loading