-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
141 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
/** | ||
* @package snow-monkey | ||
* @author inc2734 | ||
* @license GPL-2.0+ | ||
* @version 27.6.0 | ||
*/ | ||
|
||
use Framework\Controller\Manager; | ||
|
||
/** | ||
* Get remote block styles. | ||
* | ||
* @param string $url A URL of the remote styles API. | ||
* @param array $args An array of request arguments. | ||
* @return array | ||
*/ | ||
function _snow_monkey_get_remote_block_styles( $url, array $args = array() ) { | ||
global $wp_version; | ||
|
||
$response = wp_remote_get( | ||
$url, | ||
array( | ||
'user-agent' => 'WordPress/' . $wp_version, | ||
'timeout' => 30, | ||
'headers' => array_merge( | ||
$args, | ||
array( | ||
'Accept-Encoding' => '', | ||
) | ||
), | ||
) | ||
); | ||
|
||
if ( ! $response || is_wp_error( $response ) ) { | ||
return array(); | ||
} | ||
|
||
$response_code = wp_remote_retrieve_response_code( $response ); | ||
if ( 200 !== $response_code ) { | ||
return array(); | ||
} | ||
|
||
$styles = json_decode( wp_remote_retrieve_body( $response ), true ); | ||
if ( ! is_array( $styles ) ) { | ||
return array(); | ||
} | ||
|
||
foreach ( $styles as $key => $style ) { | ||
$styles[ $key ]['viewportWidth'] = 1440; | ||
} | ||
|
||
return $styles; | ||
} | ||
|
||
/** | ||
* Register remote block styles. | ||
* This requires a valid license key. | ||
*/ | ||
add_action( | ||
'init', | ||
function () { | ||
$request_uri = filter_input( INPUT_SERVER, 'REQUEST_URI' ); | ||
if ( ! $request_uri ) { | ||
$request_uri = esc_html( wp_unslash( $_SERVER['REQUEST_URI'] ?? '' ) ); // @phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | ||
} | ||
if ( $request_uri && false !== strpos( $request_uri, 'wp-json/snow-monkey-license-manager' ) ) { | ||
return; | ||
} | ||
|
||
$transient = get_transient( 'snow-monkey-remote-styles' ); | ||
|
||
if ( false !== $transient ) { | ||
$remote_block_styles = $transient; | ||
} else { | ||
$license_key = Manager::get_option( 'license-key' ); | ||
$status = Manager::get_license_status( $license_key ); | ||
|
||
$url = 'https://snow-monkey.2inc.org/wp-json/snow-monkey-license-manager/v1/styles/'; | ||
|
||
$remote_block_styles = 'true' === $status | ||
? _snow_monkey_get_remote_block_styles( | ||
$url, | ||
array( | ||
'X-Snow-Monkey-License-key' => Manager::get_option( 'license-key' ), | ||
'X-Snow-Monkey-Locale' => get_locale(), | ||
) | ||
) | ||
: false; | ||
|
||
if ( $remote_block_styles && is_array( $remote_block_styles ) ) { | ||
set_transient( 'snow-monkey-remote-styles', $remote_block_styles, DAY_IN_SECONDS ); | ||
} | ||
} | ||
|
||
if ( ! is_array( $remote_block_styles ) ) { | ||
$remote_block_styles = array(); | ||
} | ||
|
||
$registry = WP_Block_Styles_Registry::get_instance(); | ||
|
||
foreach ( $remote_block_styles as $style ) { | ||
if ( ! $style['name'] || ! $style['label'] || ! $style['blockTypes'] ) { | ||
continue; | ||
} | ||
|
||
$block_types = array_filter( | ||
array_map( | ||
function ( $block_type ) { | ||
return str_replace( array( 'core-', 'snow-monkey-blocks-' ), array( 'core/', 'snow-monkey-blocks/' ), $block_type ); | ||
}, | ||
$style['blockTypes'] | ||
) | ||
); | ||
|
||
if ( in_array( 'core/button', $block_types, true ) ) { | ||
$block_types[] = 'snow-monkey-blocks/btn'; | ||
} | ||
|
||
register_block_style( array_unique( $block_types ), (array) $style ); | ||
} | ||
}, | ||
9 | ||
); |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Snow Monkey\n" | ||
"POT-Creation-Date: 2025-01-06 23:52+0900\n" | ||
"PO-Revision-Date: 2025-01-06 23:53+0900\n" | ||
"POT-Creation-Date: 2025-01-30 10:20+0900\n" | ||
"PO-Revision-Date: 2025-01-30 10:20+0900\n" | ||
"Last-Translator: inc2734 <[email protected]>\n" | ||
"Language-Team: inc2734 <[email protected]>\n" | ||
"Language: ja_JP\n" | ||
|
@@ -134,50 +134,50 @@ msgid "Reset settings" | |
msgstr "設定をリセット" | ||
|
||
#: Framework/Controller/Manager.php:97 | ||
msgid "Retrieve patterns from the pattern library" | ||
msgstr "パターンライブラリーからパターンを再取得する" | ||
msgid "Retrieve data from the pattern / style library" | ||
msgstr "パターン / スタイルライブラリーからデータを再取得する" | ||
|
||
#: Framework/Controller/Manager.php:165 | ||
#: Framework/Controller/Manager.php:166 | ||
msgid "Settings" | ||
msgstr "設定" | ||
|
||
#: Framework/Controller/Manager.php:173 | ||
#: Framework/Controller/Manager.php:174 | ||
msgid "License key" | ||
msgstr "ライセンスキー" | ||
|
||
#: Framework/Controller/Manager.php:179 Framework/Controller/Manager.php:221 | ||
#: Framework/Controller/Manager.php:180 Framework/Controller/Manager.php:222 | ||
msgid "Enable" | ||
msgstr "有効" | ||
|
||
#: Framework/Controller/Manager.php:184 Framework/Controller/Manager.php:226 | ||
#: Framework/Controller/Manager.php:185 Framework/Controller/Manager.php:227 | ||
msgid "Disable" | ||
msgstr "無効" | ||
|
||
#: Framework/Controller/Manager.php:204 | ||
#: Framework/Controller/Manager.php:205 | ||
msgid "" | ||
"If the license key entered is valid, premium block patterns are available." | ||
msgstr "" | ||
"入力されたライセンスキーが有効な場合、プレミアムブロックパターンが利用できま" | ||
"す。" | ||
|
||
#: Framework/Controller/Manager.php:205 | ||
#: Framework/Controller/Manager.php:206 | ||
msgid "" | ||
"If the license key is entered, the XServer register key setting is not saved." | ||
msgstr "ライセンスキーを入力した場合、XServer 登録キーの設定は保存されません。" | ||
|
||
#: Framework/Controller/Manager.php:215 | ||
#: Framework/Controller/Manager.php:216 | ||
msgid "XServer register key" | ||
msgstr "XServer 登録キー" | ||
|
||
#: Framework/Controller/Manager.php:246 | ||
#: Framework/Controller/Manager.php:247 | ||
msgid "" | ||
"If the XServer register key entered is valid, premium block patterns are " | ||
"available." | ||
msgstr "" | ||
"入力されたXServer 登録キーが有効な場合、プレミアムブロックパターンが使用可能" | ||
"です。" | ||
|
||
#: Framework/Controller/Manager.php:247 | ||
#: Framework/Controller/Manager.php:248 | ||
msgid "" | ||
"If you are using XServer integration, enter the XServer register key in the " | ||
"XServer register key entry field without entering anything in the license " | ||
|