Close identity 1:1 gaps after p1: user-center weixin/alipay tip QR upload+save, AKSRT_User_Metrics counters for medal get_type and level XP bridges, forum/revenue/signin hooks, comment moderate via user_caps, and clearer free-task deep links/status CTAs.
146 lines
5.7 KiB
Python
146 lines
5.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
from pathlib import Path
|
|
|
|
# save profile rewards
|
|
p = Path('inc/helpers/aksrt-user-center.php')
|
|
t = p.read_text(encoding='utf-8')
|
|
if 'rewards_weixin' not in t:
|
|
needle = "update_user_meta($user_id, 'aksrt_user_contacts', aksrt_normalize_user_contacts($input['contacts'] ?? []));\n\t\t\treturn true;"
|
|
insert = """update_user_meta($user_id, 'aksrt_user_contacts', aksrt_normalize_user_contacts($input['contacts'] ?? []));
|
|
|
|
// Tip QR images (attachment id or URL). Empty clears.
|
|
if (array_key_exists('rewards_weixin', $input) || array_key_exists('rewards_alipay', $input)) {
|
|
foreach (['rewards_weixin' => 'aksrt_rewards_weixin', 'rewards_alipay' => 'aksrt_rewards_alipay'] as $field => $meta) {
|
|
if (!array_key_exists($field, $input)) {
|
|
continue;
|
|
}
|
|
$raw = is_string($input[$field]) ? trim(wp_unslash($input[$field])) : '';
|
|
if ($raw === '' || $raw === '0') {
|
|
delete_user_meta($user_id, $meta);
|
|
continue;
|
|
}
|
|
if (ctype_digit($raw)) {
|
|
$att = (int) $raw;
|
|
if ($att > 0 && wp_attachment_is_image($att)) {
|
|
update_user_meta($user_id, $meta, $att);
|
|
}
|
|
continue;
|
|
}
|
|
$url = esc_url_raw($raw);
|
|
if ($url !== '') {
|
|
update_user_meta($user_id, $meta, $url);
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;"""
|
|
if needle not in t:
|
|
raise SystemExit('save needle missing')
|
|
p.write_text(t.replace(needle, insert, 1), encoding='utf-8')
|
|
print('save rewards ok')
|
|
else:
|
|
print('save rewards already')
|
|
|
|
# tasks deep links + done CTA
|
|
p = Path('inc/helpers/user-center-renderers/credits-points-tasks.php')
|
|
t = p.read_text(encoding='utf-8')
|
|
start = t.find("case 'comment_new':")
|
|
end = t.find("case 'bbs_posts_new':", start)
|
|
if start < 0 or end < 0:
|
|
raise SystemExit('task cases missing')
|
|
new_block = """case 'comment_new':
|
|
$posts = get_posts(['numberposts' => 1, 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC']);
|
|
$href = $home;
|
|
if (!empty($posts[0]) && $posts[0] instanceof WP_Post) {
|
|
$link = get_permalink($posts[0]);
|
|
if (is_string($link) && $link !== '') {
|
|
$href = $link . '#comments';
|
|
}
|
|
}
|
|
return [
|
|
'type' => 'link',
|
|
'label' => __('去完成', 'aksrt'),
|
|
'href' => $href,
|
|
];
|
|
case 'login':
|
|
return [
|
|
'type' => 'none',
|
|
'label' => __('登录即可领取', 'aksrt'),
|
|
];
|
|
case 'post_like':
|
|
case 'post_favorite':
|
|
case 'comment_like':
|
|
$posts = get_posts(['numberposts' => 1, 'post_status' => 'publish', 'orderby' => 'comment_count', 'order' => 'DESC']);
|
|
$href = $home;
|
|
if (!empty($posts[0]) && $posts[0] instanceof WP_Post) {
|
|
$link = get_permalink($posts[0]);
|
|
if (is_string($link) && $link !== '') {
|
|
$href = $link;
|
|
}
|
|
}
|
|
return [
|
|
'type' => 'link',
|
|
'label' => __('去看看', 'aksrt'),
|
|
'href' => $href,
|
|
];
|
|
case 'followed':
|
|
$center = function_exists('aksrt_get_user_center_url') ? (string) aksrt_get_user_center_url() : $home;
|
|
return [
|
|
'type' => 'link',
|
|
'label' => __('去主页', 'aksrt'),
|
|
'href' => $center !== '' ? $center : $home,
|
|
];
|
|
"""
|
|
# preserve indent of original case
|
|
indent = ''
|
|
line = t[t.rfind('\n', 0, start)+1:start]
|
|
# new_block assumes tabs matching file
|
|
t = t[:start] + new_block + t[end:]
|
|
|
|
# CTA block
|
|
old_cta = """<?php if (($action['type'] ?? 'none') === 'signin') : ?>
|
|
<button type=\"button\" class=\"uc-points-tasks__action muted-color em09 mt6\" data-aksrt-signin-goto>
|
|
<?php echo esc_html((string) $action['label']); ?><i class=\"fa fa-angle-right em12 ml3\" aria-hidden=\"true\"></i>
|
|
</button>
|
|
<?php elseif (($action['type'] ?? 'none') === 'link' && !empty($action['href'])) : ?>
|
|
<a class=\"uc-points-tasks__action muted-color em09 mt6\" href=\"<?php echo esc_url((string) $action['href']); ?>\">
|
|
<?php echo esc_html((string) $action['label']); ?><i class=\"fa fa-angle-right em12 ml3\" aria-hidden=\"true\"></i>
|
|
</a>
|
|
<?php endif; ?>"""
|
|
new_cta = """<?php if ($done) : ?>
|
|
<span class=\"uc-points-tasks__action muted-color em09 mt6\"><?php esc_html_e('今日已完成', 'aksrt'); ?></span>
|
|
<?php elseif (($action['type'] ?? 'none') === 'signin') : ?>
|
|
<button type=\"button\" class=\"uc-points-tasks__action muted-color em09 mt6\" data-aksrt-signin-goto>
|
|
<?php echo esc_html((string) $action['label']); ?><i class=\"fa fa-angle-right em12 ml3\" aria-hidden=\"true\"></i>
|
|
</button>
|
|
<?php elseif (($action['type'] ?? 'none') === 'link' && !empty($action['href'])) : ?>
|
|
<a class=\"uc-points-tasks__action muted-color em09 mt6\" href=\"<?php echo esc_url((string) $action['href']); ?>\">
|
|
<?php echo esc_html((string) $action['label']); ?><i class=\"fa fa-angle-right em12 ml3\" aria-hidden=\"true\"></i>
|
|
</a>
|
|
<?php elseif (($action['type'] ?? 'none') === 'none' && !empty($action['label'])) : ?>
|
|
<span class=\"uc-points-tasks__action muted-color em09 mt6\"><?php echo esc_html((string) $action['label']); ?></span>
|
|
<?php endif; ?>"""
|
|
# try without escaped quotes
|
|
old_cta2 = old_cta.replace('\\"', '"')
|
|
new_cta2 = new_cta.replace('\\"', '"')
|
|
if old_cta2 in t:
|
|
t = t.replace(old_cta2, new_cta2, 1)
|
|
print('cta updated')
|
|
else:
|
|
# fuzzy find
|
|
i = t.find("data-aksrt-signin-goto")
|
|
print('signin btn at', i)
|
|
print(repr(t[i-120:i+220]))
|
|
# replace using unique start
|
|
s = t.find("<?php if (($action['type'] ?? 'none') === 'signin') : ?>")
|
|
e = t.find("<?php endif; ?>", s)
|
|
e = t.find("\n", e)
|
|
if s > 0 and e > s:
|
|
t = t[:s] + new_cta2 + t[e+1:]
|
|
print('cta fuzzy updated')
|
|
else:
|
|
print('cta not found')
|
|
|
|
p.write_text(t, encoding='utf-8')
|
|
print('tasks updated')
|