Skip to content

Commit

Permalink
Extracted any logic that may need to be tested from the api class (#522)
Browse files Browse the repository at this point in the history
* Extracted any logic that may need to be tested from the api class

* Refactored to facilitate testing

* Refactored zip construction to use shared code with saving logic

* Consolidated template and css parsing logic for theme exporting

* removed queryID removal from query blocks

* Fixed the image processing so that the id is removed from inner content correctly

* Added tests that evaluate encoded patterns and test patterns created from templates with media

* Added taxQuery removal tests and fixed taxQuery attribute removal logic

* Refactored image/cover processing to more cleanly handle id classes

* Add test and fixed bugs around escaping <'s and >'s

* localized quote blocks

* Added localization processing to list, verse, table and media-text blocks

---------

Co-authored-by: Vicente Canales <vicente.canales@automattic.com>
Co-authored-by: Madhu Dollu <madhusudhan.dollu@gmail.com>
  • Loading branch information
3 people committed Mar 27, 2024
1 parent 99a35c5 commit 20bcc01
Show file tree
Hide file tree
Showing 15 changed files with 996 additions and 746 deletions.
31 changes: 9 additions & 22 deletions admin/class-create-theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require_once __DIR__ . '/create-theme/theme-tags.php';
require_once __DIR__ . '/create-theme/theme-zip.php';
require_once __DIR__ . '/create-theme/theme-media.php';
require_once __DIR__ . '/create-theme/theme-blocks.php';
require_once __DIR__ . '/create-theme/theme-patterns.php';
require_once __DIR__ . '/create-theme/theme-templates.php';
require_once __DIR__ . '/create-theme/theme-styles.php';
Expand All @@ -14,7 +13,7 @@
require_once __DIR__ . '/create-theme/theme-form.php';
require_once __DIR__ . '/create-theme/form-messages.php';
require_once __DIR__ . '/create-theme/theme-fonts.php';

require_once __DIR__ . '/create-theme/theme-create.php';
/**
* The admin-specific functionality of the plugin.
*
Expand Down Expand Up @@ -158,14 +157,14 @@ function create_sibling_theme( $theme, $screenshot ) {
// Remove metadata from style.css file
$css_contents = trim( substr( $css_contents, strpos( $css_contents, '*/' ) + 2 ) );
// Add new metadata
$css_contents = Theme_Styles::build_child_style_css( $theme ) . $css_contents;
$css_contents = Theme_Styles::build_style_css( $theme ) . $css_contents;
$zip->addFromStringToTheme(
'style.css',
$css_contents
);

// Add / replace screenshot.
if ( $this->is_valid_screenshot( $screenshot ) ) {
if ( Theme_Utils::is_valid_screenshot( $screenshot ) ) {
$zip->addFileToTheme(
$screenshot['tmp_name'],
'screenshot.png'
Expand Down Expand Up @@ -227,14 +226,14 @@ function clone_theme( $theme, $screenshot ) {
// Remove metadata from style.css file
$css_contents = trim( substr( $css_contents, strpos( $css_contents, '*/' ) + 2 ) );
// Add new metadata
$css_contents = Theme_Styles::build_child_style_css( $theme ) . $css_contents;
$css_contents = Theme_Styles::build_style_css( $theme ) . $css_contents;
$zip->addFromStringToTheme(
'style.css',
$css_contents
);

// Add / replace screenshot.
if ( $this->is_valid_screenshot( $screenshot ) ) {
if ( Theme_Utils::is_valid_screenshot( $screenshot ) ) {
$zip->addFileToTheme(
$screenshot['tmp_name'],
'screenshot.png'
Expand Down Expand Up @@ -289,11 +288,11 @@ function create_child_theme( $theme, $screenshot ) {
// Add style.css.
$zip->addFromStringToTheme(
'style.css',
Theme_Styles::build_child_style_css( $theme )
Theme_Styles::build_style_css( $theme )
);

// Add / replace screenshot.
if ( $this->is_valid_screenshot( $screenshot ) ) {
if ( Theme_Utils::is_valid_screenshot( $screenshot ) ) {
$zip->addFileToTheme(
$screenshot['tmp_name'],
'screenshot.png'
Expand Down Expand Up @@ -362,7 +361,7 @@ function create_blank_theme( $theme, $screenshot ) {
);

// Add new metadata.
$css_contents = Theme_Styles::build_child_style_css( $theme );
$css_contents = Theme_Styles::build_style_css( $theme );

// Add style.css.
file_put_contents(
Expand All @@ -386,7 +385,7 @@ function create_blank_theme( $theme, $screenshot ) {
}

// Overwrite default screenshot if one is provided.
if ( $this->is_valid_screenshot( $screenshot ) ) {
if ( Theme_Utils::is_valid_screenshot( $screenshot ) ) {
file_put_contents(
$blank_theme_path . DIRECTORY_SEPARATOR . 'screenshot.png',
file_get_contents( $screenshot['tmp_name'] )
Expand Down Expand Up @@ -491,16 +490,4 @@ function blockbase_save_theme() {
}
}
}

const ALLOWED_SCREENSHOT_TYPES = array(
'png' => 'image/png',
);

function is_valid_screenshot( $file ) {
$filetype = wp_check_filetype( $file['name'], self::ALLOWED_SCREENSHOT_TYPES );
if ( is_uploaded_file( $file['tmp_name'] ) && in_array( $filetype['type'], self::ALLOWED_SCREENSHOT_TYPES, true ) && $file['size'] < 2097152 ) {
return 1;
}
return 0;
}
}
193 changes: 0 additions & 193 deletions admin/create-theme/theme-blocks.php

This file was deleted.

0 comments on commit 20bcc01

Please sign in to comment.