Compare commits

...

No commits in common. "main" and "v1.0.16" have entirely different histories.

9 changed files with 41 additions and 408 deletions

View file

@ -1,7 +1,6 @@
# 文派统一插件发布 CI Workflow
# 触发push tag v*
# 运行环境forgejo-ci-php:latest (Alpine + php-cli + git + rsync + zip + node)
# 基于 ci-workflows/wp-release.yml 2026-02-18 版本
name: Release Plugin

on:
@ -18,18 +17,17 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Verify tools
shell: bash
run: |
php -v | head -1 || true
set -euo pipefail
php -v | head -1
git --version
rsync --version | head -1 || true
zip --version | head -2 || true
rsync --version | head -1
zip --version | head -2
jq --version
curl --version | head -1 || true
curl --version | head -1

- name: Extract version from tag
id: version
@ -76,58 +74,6 @@ jobs:
fi
echo "Version consistency check passed: $VERSION"

- name: Generate Changelog
shell: bash
run: |
set -euo pipefail
TAG="${GITHUB_REF#refs/tags/}"

PREV_TAG=$(git tag --sort=-version:refname | grep -E '^v' | grep -v "^${TAG}$" | head -1)

if [ -n "$PREV_TAG" ]; then
echo "Changelog: ${PREV_TAG}..${TAG}"
COMMITS=$(git log "${PREV_TAG}..${TAG}" --no-merges --pretty=format:"%s (%h)" 2>/dev/null || true)
else
echo "Changelog: first release, using all commits"
COMMITS=$(git log --no-merges --pretty=format:"%s (%h)" 2>/dev/null || true)
fi

if [ -z "$COMMITS" ]; then
: > /tmp/changelog.md
echo "No commits found for changelog"
exit 0
fi

FEAT="" FIX="" OTHER=""
while IFS= read -r line; do
case "$line" in
feat:*|feat\(*) FEAT="${FEAT}\n- ${line}" ;;
fix:*|fix\(*) FIX="${FIX}\n- ${line}" ;;
*) OTHER="${OTHER}\n- ${line}" ;;
esac
done <<< "$COMMITS"

CHANGELOG=""
HAS_CATEGORIES=false
if [ -n "$FEAT" ]; then
CHANGELOG="${CHANGELOG}#### New Features${FEAT}\n\n"
HAS_CATEGORIES=true
fi
if [ -n "$FIX" ]; then
CHANGELOG="${CHANGELOG}#### Bug Fixes${FIX}\n\n"
HAS_CATEGORIES=true
fi
if [ -n "$OTHER" ]; then
if [ "$HAS_CATEGORIES" = true ]; then
CHANGELOG="${CHANGELOG}#### Other Changes${OTHER}\n\n"
else
CHANGELOG="${OTHER#\\n}\n\n"
fi
fi

printf '%b' "$CHANGELOG" > /tmp/changelog.md
echo "Changelog generated ($(echo "$COMMITS" | wc -l) commits)"

- name: PHP Lint
shell: bash
run: |
@ -167,13 +113,8 @@ jobs:
--exclude=".gitattributes" \
--exclude=".editorconfig" \
--exclude=".env*" \
--exclude=".agent" \
--exclude=".vscode" \
--exclude="node_modules" \
--exclude="vendor" \
--exclude="tests" \
--exclude="docs" \
--exclude="lib" \
--exclude="phpunit.xml*" \
--exclude="phpcs.xml*" \
--exclude="phpstan.neon*" \
@ -232,23 +173,7 @@ jobs:
SHA256="${{ steps.checksum.outputs.sha256 }}"
API_URL="${GITHUB_SERVER_URL%/}/api/v1/repos/${GITHUB_REPOSITORY}"
AUTH_HEADER="Authorization: token ${AUTH_TOKEN}"

{
echo "## ${SLUG} ${TAG}"
echo ""
CHANGELOG_FILE="/tmp/changelog.md"
if [ -f "$CHANGELOG_FILE" ] && [ -s "$CHANGELOG_FILE" ]; then
echo "### What's Changed"
echo ""
cat "$CHANGELOG_FILE"
fi
echo "### Checksums"
echo ""
echo "| File | SHA-256 |"
echo "|------|---------|"
echo "| ${ZIP_NAME} | ${SHA256} |"
} > /tmp/release-notes.md
RELEASE_NOTES=$(cat /tmp/release-notes.md)
printf -v RELEASE_NOTES '## %s %s\n\n### Checksums\n\n| File | SHA-256 |\n|------|---------|\n| %s | %s |\n' "$SLUG" "$TAG" "$ZIP_NAME" "$SHA256"

echo ">>> Resolving release ${TAG}"
STATUS=$(curl -sS -o /tmp/release.json -w "%{http_code}" \
@ -352,8 +277,9 @@ jobs:
KEY_PATH="$HOME/.ssh/deploy_key"
printf '%s\n' "$DEPLOY_SSH_KEY" > "$KEY_PATH"
chmod 600 "$KEY_PATH"
ssh-keyscan -t rsa,ecdsa,ed25519 -p "$DEPLOY_PORT" -H "$DEPLOY_HOST" >> "$HOME/.ssh/known_hosts" 2>/dev/null || true
ssh-keyscan -p "$DEPLOY_PORT" -H "$DEPLOY_HOST" >> "$HOME/.ssh/known_hosts" 2>/dev/null || true

# Run only for this plugin to reduce release-time impact.
if [[ "$DEPLOY_COMMAND_MODE" == "runner" ]]; then
DEPLOY_COMPOSER_SCRIPT="${DEPLOY_COMPOSER_SCRIPT:-/usr/local/sbin/wp-post-release-composer-runner}"
ssh -i "$KEY_PATH" -p "$DEPLOY_PORT" -o BatchMode=yes -o StrictHostKeyChecking=yes "${DEPLOY_USER}@${DEPLOY_HOST}" \

5
.gitignore vendored
View file

@ -1,5 +0,0 @@
vendor/
node_modules/
.env
*.log
.DS_Store

View file

@ -31,7 +31,7 @@ class WenPai_Updater {
*
* @var string
*/
const VERSION = '1.1.0';
const VERSION = '1.0.0';

/**
* 云桥 API 地址。
@ -168,50 +168,24 @@ class WenPai_Updater {

$response = $this->api_request( "plugins/{$this->slug}/info" );

if ( ! is_wp_error( $response ) && ! isset( $response['error'] ) && ! empty( $response['name'] ) ) {
$info = new stdClass();
$info->name = $response['name'];
$info->slug = $response['slug'] ?? $this->slug;
$info->version = $response['version'] ?? '';
$info->author = $response['author'] ?? '';
$info->homepage = $response['homepage'] ?? '';
$info->download_link = $response['download_link'] ?? '';
$info->requires = $response['requires'] ?? '';
$info->tested = $response['tested'] ?? '';
$info->requires_php = $response['requires_php'] ?? '';
$info->last_updated = $response['last_updated'] ?? '';
$info->icons = $response['icons'] ?? [];
$info->banners = $response['banners'] ?? [];
$info->sections = $response['sections'] ?? [];
$info->external = true;

return $info;
}

// API 不可用或插件未注册时,用本地插件头信息兜底
$plugin_path = WP_PLUGIN_DIR . '/' . $this->plugin_file;
if ( ! file_exists( $plugin_path ) ) {
if ( is_wp_error( $response ) ) {
return $result;
}

if ( ! function_exists( 'get_plugin_data' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}

$plugin_data = get_plugin_data( $plugin_path );

$info = new stdClass();
$info->name = $plugin_data['Name'] ?? $this->slug;
$info->slug = $this->slug;
$info->version = $this->version;
$info->author = $plugin_data['AuthorName'] ?? '';
$info->homepage = $plugin_data['PluginURI'] ?? '';
$info->requires = $plugin_data['RequiresWP'] ?? '';
$info->requires_php = $plugin_data['RequiresPHP'] ?? '';
$info->sections = [
'description' => $plugin_data['Description'] ?? '',
];
$info->external = true;
$info = new stdClass();
$info->name = $response['name'] ?? '';
$info->slug = $response['slug'] ?? $this->slug;
$info->version = $response['version'] ?? '';
$info->author = $response['author'] ?? '';
$info->homepage = $response['homepage'] ?? '';
$info->download_link = $response['download_link'] ?? '';
$info->requires = $response['requires'] ?? '';
$info->tested = $response['tested'] ?? '';
$info->requires_php = $response['requires_php'] ?? '';
$info->last_updated = $response['last_updated'] ?? '';
$info->icons = $response['icons'] ?? [];
$info->banners = $response['banners'] ?? [];
$info->sections = $response['sections'] ?? [];

return $info;
}

View file

@ -127,10 +127,10 @@ class WPSlug_Admin
<span style="font-size: 13px; padding-left: 10px;">
<?php printf( esc_html__( 'Version: %s', 'wpslug' ), esc_html( WPSLUG_VERSION ) ); ?>
</span>
<a href="https://wpcy.com/slug/" target="_blank" class="button button-secondary" style="margin-left: 10px;">
<a href="https://wpslug.com/document" target="_blank" class="button button-secondary" style="margin-left: 10px;">
<?php esc_html_e( 'Documentation', 'wpslug' ); ?>
</a>
<a href="https://wpcy.com/c/wpslug/" target="_blank" class="button button-secondary">
<a href="https://sharecms.com/forums/" target="_blank" class="button button-secondary">
<?php esc_html_e( 'Support', 'wpslug' ); ?>
</a>
</h1>
@ -740,35 +740,6 @@ class WPSlug_Admin
</tr>
</table>
</div>

<div class="wpslug-api-section" data-service="wpmind">
<h4><?php _e("WPMind AI Translation", "wpslug"); ?></h4>
<div class="wpslug-wpmind-status">
<?php if (function_exists('wpmind_is_available') && wpmind_is_available()): ?>
<p class="description" style="color: #2e7d32;">
<span class="dashicons dashicons-yes-alt"></span>
<?php _e("WPMind is active and configured. No additional settings required.", "wpslug"); ?>
</p>
<p class="description">
<?php _e("WPMind uses AI to translate titles to SEO-friendly slugs. It provides more accurate and context-aware translations compared to traditional translation services.", "wpslug"); ?>
</p>
<p class="description">
<a href="<?php echo admin_url('options-general.php?page=wpmind'); ?>">
<?php _e("Configure WPMind Settings", "wpslug"); ?> →
</a>
</p>
<?php else: ?>
<p class="description" style="color: #d32f2f;">
<span class="dashicons dashicons-warning"></span>
<?php _e("WPMind plugin is not active or not configured.", "wpslug"); ?>
</p>
<p class="description">
<?php _e("Please install and activate the WPMind plugin to use AI-powered translation.", "wpslug"); ?>
<a href="https://wpcy.com/mind/" target="_blank"><?php _e("Learn more", "wpslug"); ?></a>
</p>
<?php endif; ?>
</div>
</div>
</div>
<?php
}

View file

@ -30,9 +30,6 @@ class WPSlug_Converter {
case 'pinyin':
$result = $this->convertPinyin($text, $options);
break;
case 'semantic_pinyin':
$result = $this->convertSemanticPinyin($text, $options);
break;
case 'transliteration':
$result = $this->convertTransliteration($text, $options);
break;
@ -74,89 +71,6 @@ class WPSlug_Converter {
}
}

/**
* 语义化拼音转换(使用 WPMind AI
*
* 与普通拼音不同,这个方法会按词语分隔而非按字分隔
* 例如 "你好世界" → "nihao-shijie" 而非 "ni-hao-shi-jie"
*/
private function convertSemanticPinyin($text, $options) {
$debug_mode = isset($options['debug_mode']) && $options['debug_mode'];
try {
// 1. 检查是否是中文
if ($this->detectLanguage($text) !== 'zh') {
return $this->cleanBasicSlug($text, $options);
}

// 2. 检查 WPMind 是否可用
if (!function_exists('wpmind_pinyin') || !function_exists('wpmind_is_available') || !wpmind_is_available()) {
if ($debug_mode) {
error_log('[WPSlug] WPMind not available for semantic pinyin, falling back to regular pinyin');
}
return $this->convertPinyin($text, $options);
}

// 3. 文本长度限制(避免超时)
if (mb_strlen($text) > 200) {
if ($debug_mode) {
error_log('[WPSlug] Text too long for semantic pinyin, using regular pinyin');
}
return $this->convertPinyin($text, $options);
}

// 4. 调用 WPMind AI 进行语义化拼音转换
$result = wpmind_pinyin($text, [
'context' => 'wpslug_semantic_pinyin',
'cache_ttl' => 604800, // 7天
]);

// 5. 处理结果
if (is_wp_error($result)) {
if ($debug_mode) {
error_log('[WPSlug] WPMind pinyin error: ' . $result->get_error_message());
}
return $this->convertPinyin($text, $options);
}

// 6. 清理结果
$slug = $this->cleanSemanticPinyinResult($result, $options);

if (empty($slug)) {
if ($debug_mode) {
error_log('[WPSlug] WPMind returned empty pinyin, using regular pinyin');
}
return $this->convertPinyin($text, $options);
}

if ($debug_mode) {
error_log('[WPSlug] Semantic pinyin: "' . $text . '" → "' . $slug . '"');
}

return $slug;

} catch (Exception $e) {
$this->settings->logError('Semantic pinyin error: ' . $e->getMessage());
return $this->convertPinyin($text, $options);
}
}

/**
* 清理语义化拼音结果
*/
private function cleanSemanticPinyinResult($text, $options) {
// 移除可能的引号和空格
$text = trim($text, " \t\n\r\0\x0B\"'");
// 确保只有小写字母、数字和连字符
$text = preg_replace('/[^a-zA-Z0-9\-]/', '-', $text);
$text = strtolower($text);
$text = preg_replace('/-+/', '-', $text);
$text = trim($text, '-');
return $text;
}

private function convertTransliteration($text, $options) {
try {
$detected_lang = $this->detectLanguage($text);
@ -249,7 +163,7 @@ class WPSlug_Converter {
}

public function getSupportedModes() {
return array('pinyin', 'semantic_pinyin', 'transliteration', 'translation');
return array('pinyin', 'transliteration', 'translation');
}

public function isModeSupported($mode) {

View file

@ -237,24 +237,14 @@ class WPSlug_Settings

public function getConversionModes()
{
$modes = [
return [
"pinyin" => __("Chinese Pinyin Conversion", "wpslug"),
"transliteration" => __(
"Foreign Language Transliteration",
"wpslug"
),
"translation" => __("Multi-language Translation", "wpslug"),
];
// 如果 WPMind 可用,添加语义化拼音选项
if (function_exists('wpmind_is_available') && wpmind_is_available()) {
$modes["semantic_pinyin"] = __("Semantic Pinyin (WPMind AI)", "wpslug");
} elseif (class_exists('\\WPMind\\WPMind')) {
$modes["semantic_pinyin"] = __("Semantic Pinyin (Requires WPMind)", "wpslug");
}
$modes["transliteration"] = __(
"Foreign Language Transliteration",
"wpslug"
);
$modes["translation"] = __("Multi-language Translation", "wpslug");
return $modes;
}

public function getTransliterationMethods()
@ -276,25 +266,11 @@ class WPSlug_Settings

public function getTranslationServices()
{
$services = [
return [
"none" => __("None", "wpslug"),
"google" => __("Google Translate", "wpslug"),
"baidu" => __("Baidu Translate", "wpslug"),
];
// 动态检测 WPMind 是否可用
if (function_exists('wpmind_is_available') && wpmind_is_available()) {
// WPMind 可用,添加到服务列表顶部(推荐)
$services = array_merge(
["wpmind" => __("WPMind AI (Recommended)", "wpslug")],
$services
);
} elseif (class_exists('\\WPMind\\WPMind')) {
// WPMind 已安装但未配置
$services["wpmind"] = __("WPMind AI (Not Configured)", "wpslug");
}
return $services;
}

public function getLanguages()

View file

@ -7,15 +7,6 @@ if (!defined('ABSPATH')) {
class WPSlug_Translator {
private $converter;

/**
* 防止循环调用的静态标志
* 当使用 WPMind 翻译时WPMind 内部可能触发 sanitize_title filter
* 如果没有保护,会导致无限递归
*
* @var bool
*/
private static $is_translating = false;

public function __construct() {
$this->converter = null;
}
@ -25,23 +16,9 @@ class WPSlug_Translator {
return '';
}

// 防止循环调用:如果正在翻译中,直接回退到拼音
if (self::$is_translating) {
return $this->fallbackTranslate($text, $options);
}

$service = isset($options['translation_service']) ? $options['translation_service'] : 'none';
switch ($service) {
case 'wpmind':
// WPMind 服务需要循环保护
self::$is_translating = true;
try {
$result = $this->translateWPMind($text, $options);
} finally {
self::$is_translating = false;
}
return $result;
case 'google':
return $this->translateGoogle($text, $options);
case 'baidu':
@ -189,96 +166,6 @@ class WPSlug_Translator {
}
}

/**
* 使用 WPMind AI 翻译
*
* @param string $text 要翻译的文本
* @param array $options 选项
* @return string 翻译后的文本slug 格式)
*/
private function translateWPMind($text, $options) {
$debug_mode = isset($options['debug_mode']) && $options['debug_mode'];
// 获取语言设置(提前获取以便用于缓存键)
$source_lang = isset($options['translation_source_lang']) ? $options['translation_source_lang'] : 'zh';
$target_lang = isset($options['translation_target_lang']) ? $options['translation_target_lang'] : 'en';
// 1. 先检查本地缓存(缓存键包含语言设置)
$cache_key = 'wpslug_wpmind_' . md5($text . '_' . $source_lang . '_' . $target_lang);
$cached = get_transient($cache_key);
if ($cached !== false) {
if ($debug_mode) {
error_log('[WPSlug] WPMind cache hit for: ' . $text . ' (' . $source_lang . ' -> ' . $target_lang . ')');
}
return $cached;
}

// 2. 检查 WPMind 是否可用
if (!function_exists('wpmind_is_available') || !wpmind_is_available()) {
if ($debug_mode) {
error_log('[WPSlug] WPMind not available, falling back to pinyin');
}
return $this->fallbackTranslate($text, $options);
}

// 3. 文本长度限制(避免超时)
if (mb_strlen($text) > 200) {
if ($debug_mode) {
error_log('[WPSlug] Text too long (' . mb_strlen($text) . ' chars), using pinyin');
}
return $this->fallbackTranslate($text, $options);
}

// 4. 中文字符数限制
$chinese_count = preg_match_all('/[\x{4e00}-\x{9fff}]/u', $text);
if ($chinese_count > 50) {
if ($debug_mode) {
error_log('[WPSlug] Too many Chinese characters (' . $chinese_count . '), using pinyin');
}
return $this->fallbackTranslate($text, $options);
}

// 5. 调用 WPMind API语言设置已在前面获取
$start_time = microtime(true);
$result = wpmind_translate($text, $source_lang, $target_lang, [
'context' => 'wpslug_translation',
'format' => 'slug',
'cache_ttl' => 86400, // WPMind 内部缓存 1 天
'max_tokens' => 100,
'temperature' => 0.3,
]);

$elapsed_time = round((microtime(true) - $start_time) * 1000);

// 7. 处理结果
if (is_wp_error($result)) {
if ($debug_mode) {
error_log('[WPSlug] WPMind error: ' . $result->get_error_message() . ' (took ' . $elapsed_time . 'ms)');
}
return $this->fallbackTranslate($text, $options);
}

$slug = $this->cleanTranslatedText($result);

// 8. 验证结果有效性
if (empty($slug)) {
if ($debug_mode) {
error_log('[WPSlug] WPMind returned empty result, using pinyin');
}
return $this->fallbackTranslate($text, $options);
}

// 9. 缓存结果7 天)
set_transient($cache_key, $slug, 7 * DAY_IN_SECONDS);

if ($debug_mode) {
error_log('[WPSlug] WPMind translated "' . $text . '" to "' . $slug . '" in ' . $elapsed_time . 'ms');
}

return $slug;
}

private function fallbackTranslate($text, $options) {
if ($this->converter === null) {
$this->converter = new WPSlug_Converter();

View file

@ -130,13 +130,12 @@ class WPSlug_Validator {
}
public static function validateConversionMode($mode) {
$valid_modes = array('pinyin', 'semantic_pinyin', 'transliteration', 'translation');
$valid_modes = array('pinyin', 'transliteration', 'translation');
return self::validateSelect($mode, $valid_modes, 'pinyin');
}
public static function validateTranslationService($service) {
// 注意wpmind 服务需要在此列表中才能保存
$valid_services = array('none', 'google', 'baidu', 'wpmind');
$valid_services = array('none', 'google', 'baidu');
return self::validateSelect($service, $valid_services, 'none');
}
@ -158,15 +157,6 @@ class WPSlug_Validator {
if ($service === 'baidu' && (empty($options['baidu_app_id']) || empty($options['baidu_secret_key']))) {
$errors[] = __('Baidu App ID and Secret Key are required for Baidu Translate service.', 'wpslug');
}
// WPMind 需要已配置
if ($service === 'wpmind') {
if (!function_exists('wpmind_is_available')) {
$errors[] = __('WPMind plugin is not installed.', 'wpslug');
} elseif (!wpmind_is_available()) {
$errors[] = __('WPMind is not configured. Please configure it in WPMind settings.', 'wpslug');
}
}
}
return empty($errors) ? true : $errors;

View file

@ -2,11 +2,11 @@

/*
Plugin Name: WPSlug
Plugin URI: https://wpcy.com/slug
Plugin URI: https://wpslug.com
Description: Advanced slug management plugin with Chinese Pinyin support and SEO optimization.
Version: 1.1.0
Author: WPSlug
Author URI: https://wpcy.com/slug
Version: 1.0.16
Author: WPSlug.com
Author URI: https://wpslug.com
License: GPL2
Text Domain: wpslug
Domain Path: /languages
@ -19,7 +19,7 @@ if (!defined("ABSPATH")) {
exit();
}

define("WPSLUG_VERSION", "1.1.0");
define("WPSLUG_VERSION", "1.0.16");
define("WPSLUG_PLUGIN_DIR", plugin_dir_path(__FILE__));
define("WPSLUG_PLUGIN_URL", plugin_dir_url(__FILE__));
define("WPSLUG_PLUGIN_BASENAME", plugin_basename(__FILE__));