-
-
Notifications
You must be signed in to change notification settings - Fork 411
修复古腾堡块的一些问题 #1376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: preview
Are you sure you want to change the base?
修复古腾堡块的一些问题 #1376
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2702,28 +2702,51 @@ function send_theme_version() | |||||
|
|
||||||
| //解析短代码 | ||||||
| function register_shortcodes() { | ||||||
| add_shortcode('task', function($attr, $content = '') { | ||||||
| return '<div class="task shortcodestyle"><i class="fa-solid fa-clipboard-list"></i>' . $content . '</div>'; | ||||||
| }); | ||||||
| // 提示块 | ||||||
| function iro_render_notice($type, $content = '') { | ||||||
|
|
||||||
| $map = [ | ||||||
| 'task' => ['fa-solid fa-clipboard-list', 'task'], | ||||||
| 'warning' => ['fa-solid fa-triangle-exclamation', 'warning'], | ||||||
| 'noway' => ['fa-solid fa-square-xmark', 'noway'], | ||||||
| 'buy' => ['fa-solid fa-square-check', 'buy'], | ||||||
| ]; | ||||||
|
|
||||||
| add_shortcode('warning', function($attr, $content = '') { | ||||||
| return '<div class="warning shortcodestyle"><i class="fa-solid fa-triangle-exclamation"></i>' . $content . '</div>'; | ||||||
| }); | ||||||
| if (!isset($map[$type])) { | ||||||
| return ''; | ||||||
| } | ||||||
|
|
||||||
| add_shortcode('noway', function($attr, $content = '') { | ||||||
| return '<div class="noway shortcodestyle"><i class="fa-solid fa-square-xmark"></i>' . $content . '</div>'; | ||||||
| }); | ||||||
| [$icon, $class] = $map[$type]; | ||||||
|
|
||||||
| add_shortcode('buy', function($attr, $content = '') { | ||||||
| return '<div class="buy shortcodestyle"><i class="fa-solid fa-square-check"></i>' . $content . '</div>'; | ||||||
| }); | ||||||
| return sprintf( | ||||||
| '<div class="shortcodestyle %s"> | ||||||
| <i class="%s"></i> | ||||||
| <span>%s</span> | ||||||
| </div>', | ||||||
| esc_attr($class), | ||||||
| esc_attr($icon), | ||||||
| wp_kses_post($content) | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| add_shortcode('ghcard', function($attr, $content = '') { | ||||||
| //获取内容 | ||||||
| $atts = shortcode_atts(array("path" => "mirai-mamori/Sakurairo"), $attr); | ||||||
| add_shortcode('task', fn($a,$c='') => iro_render_notice('task',$c)); | ||||||
| add_shortcode('warning', fn($a,$c='') => iro_render_notice('warning',$c)); | ||||||
| add_shortcode('noway', fn($a,$c='') => iro_render_notice('noway',$c)); | ||||||
| add_shortcode('buy', fn($a,$c='') => iro_render_notice('buy',$c)); | ||||||
|
|
||||||
| $path = trim($atts['path']); | ||||||
| register_block_type('sakurairo/notice', [ | ||||||
| 'render_callback' => 'iro_render_notice_block', | ||||||
| ]); | ||||||
| function iro_render_notice_block($attributes, $content) { | ||||||
|
|
||||||
|
Comment on lines
2704
to
+2741
|
||||||
| $type = $attributes['type'] ?? 'task'; | ||||||
| $text = $attributes['content'] ?? ''; | ||||||
|
|
||||||
| return iro_render_notice($type, $text); | ||||||
| } | ||||||
|
|
||||||
| // gh卡片 | ||||||
| function iro_render_ghcard($path){ | ||||||
| if (strpos($path, 'https://github.com/') === 0) { | ||||||
| $path = str_replace('https://github.com/', '', $path); | ||||||
| } | ||||||
|
|
@@ -2823,50 +2846,135 @@ function register_shortcodes() { | |||||
| $language, | ||||||
| intval($stars) | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| add_shortcode('ghcard', function($attr, $content = '') { | ||||||
| //获取内容 | ||||||
| $atts = shortcode_atts(array("path" => "mirai-mamori/Sakurairo"), $attr); | ||||||
|
|
||||||
| $path = trim($atts['path']); | ||||||
|
|
||||||
| return iro_render_ghcard($path); | ||||||
| }); | ||||||
|
|
||||||
| add_shortcode('showcard', function($attr, $content = '') { | ||||||
| $atts = shortcode_atts(array("icon" => "", "title" => "", "img" => "", "color" => ""), $attr); | ||||||
| register_block_type('sakurairo/ghcard', [ | ||||||
| 'render_callback' => 'iro_render_ghcard_block', | ||||||
| ]); | ||||||
| function iro_render_ghcard_block($attributes, $content) { | ||||||
|
|
||||||
| $path = $attributes['path'] ?? ''; | ||||||
|
|
||||||
| return iro_render_ghcard($path); | ||||||
| } | ||||||
|
|
||||||
| // 展示卡片 | ||||||
| function iro_render_showcard($atts,$content) { | ||||||
|
|
||||||
| return sprintf( | ||||||
| '<div class="showcard"> | ||||||
| <div class="img" alt="Show-Card" style="background:url(%s);background-size:cover;background-position: center;"> | ||||||
| <a href="%s"><button class="showcard-button" style="color:%s !important;"><i class="fa-solid fa-angle-right"></i></button></a> | ||||||
| <div class="img" style="background:url(%s);background-size:cover;background-position:center;"> | ||||||
| <a href="%s" target="_blank" rel="noopener noreferrer"> | ||||||
| <button class="showcard-button" style="color:%s;"> | ||||||
| <i class="fa-solid fa-angle-right"></i> | ||||||
| </button> | ||||||
| </a> | ||||||
| </div> | ||||||
| <div class="icon-title"> | ||||||
| <i class="%s" style="color:%s !important;"></i> | ||||||
| <i class="%s" style="color:%s;"></i> | ||||||
| <span class="title">%s</span> | ||||||
| </div> | ||||||
| </div>', | ||||||
| $atts['img'], | ||||||
| $content, | ||||||
| esc_attr($atts['color']), | ||||||
| esc_attr($atts['icon']), | ||||||
| esc_attr($atts['color']), | ||||||
| $atts['title'], | ||||||
| esc_url($atts['img'] ?? ''), | ||||||
| esc_url($atts['link'] ?? $content ?? ''), | ||||||
| esc_attr($atts['color'] ?? ''), | ||||||
| esc_attr($atts['icon'] ?? ''), | ||||||
| esc_attr($atts['color'] ?? ''), | ||||||
| wp_kses_post($atts['title'] ?? '') | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| add_shortcode('showcard', function($attr, $content = '') { | ||||||
| $atts = shortcode_atts(array("icon" => "", "title" => "", "img" => "", "color" => ""), $attr); | ||||||
|
||||||
| $atts = shortcode_atts(array("icon" => "", "title" => "", "img" => "", "color" => ""), $attr); | |
| $atts = shortcode_atts(array("icon" => "", "title" => "", "img" => "", "color" => "", "link" => ""), $attr); |
Copilot
AI
Feb 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conversations markup outputs an <img> without an alt attribute, which is an accessibility issue for screen readers. Add an appropriate alt (e.g., the speaker name) or at least alt="" if it's decorative.
Copilot
AI
Feb 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function iro_render_conversations outputs $content directly into the HTML div without any sanitization or escaping, while both the conversations shortcode and the new sakurairo/conversation block pass user-controlled text into this parameter. An attacker with the ability to create or edit posts can craft shortcode or block content (for example via the block editor code view) that includes <script> or malicious HTML in the conversation text, leading to stored XSS when the post is viewed. You should sanitize or escape $content (for example by passing it through wp_kses_post or similar) before including it in the conversations-code-text markup for both the shortcode and block rendering.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| <?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-dom-ready', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-primitives'), 'version' => '7c81915308f122223650'); | ||
| <?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-dom-ready', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-primitives'), 'version' => '130bee0fec91c3da0739'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR changes block names from the previous
sakurairo/*-blockidentifiers to new names likesakurairo/notice/sakurairo/showcard/sakurairo/conversation. Existing posts using the old block names will become "unsupported" unless the old block types remain registered (withdeprecated/transforms or a server-side alias). Please add backward-compat registration/migration for the old block names.