Skip to content
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

修复ajax提交评论不显示UA、IP的bug #408

Merged
merged 3 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions inc/fun/comment-ajax.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use function donatj\UserAgent\parse_user_agent;
function pk_comment_err($msg, $refresh_code = true)
{
$protocol = $_SERVER['SERVER_PROTOCOL'];
Expand Down Expand Up @@ -185,15 +186,34 @@ function pk_comment_ajax()
<div class="ml-3 two-info">
<div class="puock-text ta3b">
<span class="t-md puock-links">' . get_comment_author_link($comment_id) . '</span>
' . pk_the_author_class(false, $comment) . '
' . (pk_is_checked('comment_level') ? pk_the_author_class(false, $comment) : '') . '
</div>
<div class="t-sm c-sub">' . get_comment_date('Y-m-d H:i:s', $comment_id) . '</div>
</div>
</div>
<div class="content t-sm mt10 puock-text">
<div class="content-text">
' . get_comment_text($comment_id) . '
<div class="content">
<div class="content-text t-md mt10 puock-text">
<p>' . get_comment_text($comment_id) . '</p>
' . $comment_approved_str . '
<div class="comment-os c-sub">';

if (pk_is_checked('comment_show_ua', true)):
$commentUserAgent = parse_user_agent($comment->comment_agent);
$commentOsIcon = pk_get_comment_ua_os_icon($commentUserAgent['platform']);
$commentBrowserIcon = pk_get_comment_ua_os_icon($commentUserAgent['browser']);
echo "<span class='mt10' title='{$commentUserAgent['platform']}'><i class='$commentOsIcon'></i>&nbsp;<span>{$commentUserAgent['platform']}&nbsp;</span></span>";
echo "<span class='mt10' title='{$commentUserAgent['browser']} {$commentUserAgent['version']}'><i class='$commentBrowserIcon'></i>&nbsp;<span>{$commentUserAgent['browser']}</span></span>";
endif;
?>
<?php
if (pk_is_checked('comment_show_ip', true)) {
if (!pk_is_checked('comment_dont_show_owner_ip') || (pk_is_checked('comment_dont_show_owner_ip') && $comment->user_id != 1)) {
$ip = pk_get_ip_region_str($comment->comment_author_IP);
echo "<span class='mt10' title='IP'><i class='fa-solid fa-location-dot'></i>&nbsp;$ip</span>";
}
}

echo ' </div>
</div>
</div>
</div>';
Expand Down
4 changes: 2 additions & 2 deletions inc/fun/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -909,13 +909,13 @@ function pk_get_ip_region_str($ip)
} catch (Exception $e) {
return '未知';
}
if (str_contains($s['region'], '内网IP')) {
if (strpos($s['region'], '内网IP') !== false) {
return '内网IP';
}
$region = explode('|', $s['region']);
$res = '';
foreach ($region as $item) {
if (str_starts_with($item, '0')) {
if (strpos($item, '0') === 0) {
continue;
}
$res .= $item;
Expand Down
4 changes: 2 additions & 2 deletions inc/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ function pk_init_register_assets()
add_filter('style_loader_tag', 'pk_assets_href_handle', 10, 3);
function pk_assets_scr_handle($tag, $handle, $source)
{
if (str_starts_with($handle, 'puock') && strpos($source,'instant=true')===false)
if (strpos($handle, 'puock') === 0 && strpos($source,'instant=true')===false)
{
$tag = str_replace(' src', ' data-no-instant src', $tag);
}
Expand All @@ -233,7 +233,7 @@ function pk_assets_scr_handle($tag, $handle, $source)

function pk_assets_href_handle($tag, $handle, $source)
{
if (str_starts_with($handle, 'puock') && strpos($source,'instant=true')===false) {
if (strpos($handle, 'puock') === 0 && strpos($source,'instant=true')===false) {
$tag = str_replace(' href', ' data-no-instant href', $tag);
}
return $tag;
Expand Down