| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.4/wp-content/plugins/safe-svg/includes/blocks/safe-svg/ |
Upload File : |
<?php
/**
* SafeSvg Block setup
*
* @package SafeSvg\Blocks\SafeSvgBlock
*/
namespace SafeSvg\Blocks\SafeSvgBlock;
/**
* Register the block
*/
function register() {
$n = function( $function ) {
return __NAMESPACE__ . "\\$function";
};
// Register the block.
\register_block_type_from_metadata(
SAFE_SVG_PLUGIN_DIR . '/includes/blocks/safe-svg',
[
'render_callback' => $n( 'render_block_callback' ),
]
);
}
/**
* Render callback method for the block.
*
* @param array $attributes The blocks attributes
*
* @return string|\WP_Post[] The rendered block markup.
*/
function render_block_callback( $attributes ) {
// If image is not an SVG return empty string.
if ( 'image/svg+xml' !== get_post_mime_type( $attributes['imageID'] ) ) {
return '';
}
// If we couldn't get the contents of the file, empty string again.
if ( ! $contents = file_get_contents( get_attached_file( $attributes['imageID'] ) ) ) { // phpcs:ignore
return '';
}
/**
* The wrapper class name.
*
* Allows a user to adjust the inline svg wrapper class name.
*
* @param string The class name.
*
* @since 2.1.0
*/
$class_name = apply_filters( 'safe_svg_inline_class', 'safe-svg-inline' );
/**
* The wrapper markup.
*
* Allows a user to adjust the inline svg wrapper markup.
*
* @param string The current wrapper markup.
* @param string $contents The SVG contents.
* @param string $class_name The wrapper class name.
* @param int $attachment_id The ID of the attachment.
*
* @since 2.1.0
*/
return apply_filters(
'safe_svg_inline_markup',
sprintf(
'<div class="wp-block-safe-svg-svg-icon safe-svg-cover" style="text-align: %1$s;">
<div class="safe-svg-inside %2$s%3$s" style="width: %4$spx; height: %5$spx; background-color: var(--wp--preset--color--%6$s); color: var(--wp--preset--color--%7$s); padding-top: %8$s; padding-right: %9$s; padding-bottom: %10$s; padding-left: %11$s; margin-top: %12$s; margin-right: %13$s; margin-bottom: %14$s; margin-left: %15$s;">%16$s</div>
</div>',
isset( $attributes['alignment'] ) ? esc_attr( $attributes['alignment'] ) : 'left',
esc_attr( $class_name ),
isset( $attributes['className'] ) ? ' ' . esc_attr( $attributes['className'] ) : '',
isset( $attributes['dimensionWidth'] ) ? esc_attr( $attributes['dimensionWidth'] ) : '',
isset( $attributes['dimensionHeight'] ) ? esc_attr( $attributes['dimensionHeight'] ) : '',
isset( $attributes['backgroundColor'] ) ? esc_attr( $attributes['backgroundColor'] ) : '',
isset( $attributes['textColor'] ) ? esc_attr( $attributes['textColor'] ) : '',
isset( $attributes['style']['spacing']['padding']['top'] ) ? esc_attr( convert_to_css_variable( $attributes['style']['spacing']['padding']['top'] ) ) : '',
isset( $attributes['style']['spacing']['padding']['right'] ) ? esc_attr( convert_to_css_variable( $attributes['style']['spacing']['padding']['right'] ) ) : '',
isset( $attributes['style']['spacing']['padding']['bottom'] ) ? esc_attr( convert_to_css_variable( $attributes['style']['spacing']['padding']['bottom'] ) ) : '',
isset( $attributes['style']['spacing']['padding']['left'] ) ? esc_attr( convert_to_css_variable( $attributes['style']['spacing']['padding']['left'] ) ) : '',
isset( $attributes['style']['spacing']['margin']['top'] ) ? esc_attr( convert_to_css_variable( $attributes['style']['spacing']['margin']['top'] ) ) : '',
isset( $attributes['style']['spacing']['margin']['right'] ) ? esc_attr( convert_to_css_variable( $attributes['style']['spacing']['margin']['right'] ) ) : '',
isset( $attributes['style']['spacing']['margin']['bottom'] ) ? esc_attr( convert_to_css_variable( $attributes['style']['spacing']['margin']['bottom'] ) ) : '',
isset( $attributes['style']['spacing']['margin']['left'] ) ? esc_attr( convert_to_css_variable( $attributes['style']['spacing']['margin']['left'] ) ) : '',
$contents
),
$contents,
$class_name,
$attributes['imageID']
);
}
/**
* Converts a given value to a CSS variable if it starts with 'var:'.
*
* @param string $value The value to be converted.
* @return string The converted value or the original value if it doesn't start with 'var:'.
*/
function convert_to_css_variable( $value ) {
if ( strpos( $value, 'var:' ) === 0 ) {
$parts = explode( '|', $value );
if ( count( $parts ) === 3 ) {
return 'var(--wp--preset--' . $parts[1] . '--' . $parts[2] . ')';
}
}
return $value;
}