refactor: 深度代码规范化
- argontheme.js: 将 89 个 var 声明改为 let (保留 3 个全局变量) - functions.php: 修复 106 处箭头操作符空格问题 (-> 前后不应有空格) - functions.php: 移除多余空行
This commit is contained in:
178
argontheme.js
178
argontheme.js
@@ -409,7 +409,7 @@ $(document).on("blur" , "#navbar_search_input_container" , function(){
|
||||
});
|
||||
// 监听输入变化来切换has-text类
|
||||
$(document).on("input" , "#navbar_search_input" , function(){
|
||||
var container = $("#navbar_search_input_container");
|
||||
let container = $("#navbar_search_input_container");
|
||||
if ($(this).val().trim() !== "") {
|
||||
container.addClass("has-text");
|
||||
} else {
|
||||
@@ -602,7 +602,7 @@ function waterflowInit() {
|
||||
let heights = [0, 0, 0];
|
||||
function getMinHeightPosition(){
|
||||
let res = 0, minn = 2147483647;
|
||||
for (var i = 0; i < columns; i++) {
|
||||
for (let i = 0; i < columns; i++) {
|
||||
if (heights[i] < minn) {
|
||||
minn = heights[i];
|
||||
res = i;
|
||||
@@ -663,11 +663,11 @@ if (argonConfig.waterflow_columns !== "1") {
|
||||
|
||||
/*移动端文章列表布局切换*/
|
||||
!function(){
|
||||
var mobileLayout = argonConfig.article_list_layout_mobile || "1";
|
||||
var isMobile = window.innerWidth <= 900;
|
||||
let mobileLayout = argonConfig.article_list_layout_mobile || "1";
|
||||
let isMobile = window.innerWidth <= 900;
|
||||
|
||||
function applyMobileLayout() {
|
||||
var nowMobile = window.innerWidth <= 900;
|
||||
let nowMobile = window.innerWidth <= 900;
|
||||
if (nowMobile) {
|
||||
$("html").addClass("mobile-layout-" + mobileLayout);
|
||||
} else {
|
||||
@@ -728,10 +728,10 @@ if (argonConfig.waterflow_columns !== "1") {
|
||||
$("#fabtn_go_to_comment").addClass("fabtn-hidden");
|
||||
}
|
||||
$goToComment.on("click" , function(){
|
||||
var commentsArea = $("#comments");
|
||||
var postCommentArea = $("#post_comment");
|
||||
var wasCollapsed = commentsArea.hasClass("comments-collapsed");
|
||||
var toggleBtn = $("#comments_toggle");
|
||||
let commentsArea = $("#comments");
|
||||
let postCommentArea = $("#post_comment");
|
||||
let wasCollapsed = commentsArea.hasClass("comments-collapsed");
|
||||
let toggleBtn = $("#comments_toggle");
|
||||
|
||||
if (wasCollapsed && toggleBtn.length > 0) {
|
||||
// 折叠状态:先滚动到评论切换按钮位置,再展开
|
||||
@@ -1290,7 +1290,7 @@ if (argonConfig.waterflow_columns !== "1") {
|
||||
});
|
||||
|
||||
// 准备数据
|
||||
var ajaxData = {
|
||||
let ajaxData = {
|
||||
action: "ajax_post_comment",
|
||||
comment: commentContent,
|
||||
author: commentName,
|
||||
@@ -2279,7 +2279,7 @@ if ($("html").hasClass("banner-as-cover")){
|
||||
}
|
||||
|
||||
/*Pjax*/
|
||||
var pjaxScrollTop = 0, pjaxLoading = false;
|
||||
let pjaxScrollTop = 0, pjaxLoading = false;
|
||||
$.pjax.defaults.timeout = 10000;
|
||||
$.pjax.defaults.container = ['#primary', '#leftbar_part1_menu', '#leftbar_part2_inner', '.page-information-card-container', '#rightbar', '#wpadminbar'];
|
||||
$.pjax.defaults.fragment = ['#primary', '#leftbar_part1_menu', '#leftbar_part2_inner', '.page-information-card-container', '#rightbar', '#wpadminbar'];
|
||||
@@ -2448,7 +2448,7 @@ $(document).on("click" , "#blog_categories .tag" , function(){
|
||||
initMobileCatalog();
|
||||
// 如果有文章目录,默认展开
|
||||
setTimeout(function() {
|
||||
var catalogSection = $("#mobile_catalog_toggle").closest(".leftbar-mobile-collapse-section");
|
||||
let catalogSection = $("#mobile_catalog_toggle").closest(".leftbar-mobile-collapse-section");
|
||||
console.log('[Mobile Sidebar] Catalog section found:', catalogSection.length);
|
||||
if (catalogSection.length > 0 && !catalogSection.hasClass("expanded")) {
|
||||
catalogSection.addClass("expanded");
|
||||
@@ -2489,15 +2489,15 @@ $(document).on("click" , "#blog_categories .tag" , function(){
|
||||
|
||||
// ========== 移动端折叠面板交互 ==========
|
||||
$(document).on("click", ".leftbar-mobile-collapse-header", function(e) {
|
||||
var section = $(this).closest(".leftbar-mobile-collapse-section");
|
||||
var header = $(this);
|
||||
var isExpanded = section.hasClass("expanded");
|
||||
let section = $(this).closest(".leftbar-mobile-collapse-section");
|
||||
let header = $(this);
|
||||
let isExpanded = section.hasClass("expanded");
|
||||
|
||||
// 添加点击波纹效果
|
||||
var ripple = $('<span class="collapse-ripple"></span>');
|
||||
var rect = this.getBoundingClientRect();
|
||||
var x = e.clientX - rect.left;
|
||||
var y = e.clientY - rect.top;
|
||||
let ripple = $('<span class="collapse-ripple"></span>');
|
||||
let rect = this.getBoundingClientRect();
|
||||
let x = e.clientX - rect.left;
|
||||
let y = e.clientY - rect.top;
|
||||
ripple.css({
|
||||
left: x + 'px',
|
||||
top: y + 'px'
|
||||
@@ -2523,14 +2523,14 @@ $(document).on("click" , "#blog_categories .tag" , function(){
|
||||
function initMobileCatalog() {
|
||||
console.log('[Mobile Catalog] initMobileCatalog called, initialized:', window.mobileCatalogInitialized);
|
||||
if (window.mobileCatalogInitialized) return;
|
||||
var $mobileContainer = $("#leftbar_mobile_catalog");
|
||||
var $postContent = $("#post_content");
|
||||
let $mobileContainer = $("#leftbar_mobile_catalog");
|
||||
let $postContent = $("#post_content");
|
||||
console.log('[Mobile Catalog] Container found:', $mobileContainer.length, 'PostContent found:', $postContent.length);
|
||||
if ($mobileContainer.length === 0) return;
|
||||
if ($postContent.length === 0) return;
|
||||
|
||||
// 直接生成目录,不依赖 headIndex 插件
|
||||
var $headers = $postContent.find('h1, h2, h3, h4, h5, h6');
|
||||
let $headers = $postContent.find('h1, h2, h3, h4, h5, h6');
|
||||
console.log('[Mobile Catalog] Headers found:', $headers.length);
|
||||
if ($headers.length === 0) {
|
||||
$mobileContainer.html('<div class="no-catalog">暂无目录</div>');
|
||||
@@ -2538,14 +2538,14 @@ $(document).on("click" , "#blog_categories .tag" , function(){
|
||||
}
|
||||
|
||||
// 构建目录树
|
||||
var toc = [];
|
||||
var stack = [{ level: 0, children: toc }];
|
||||
let toc = [];
|
||||
let stack = [{ level: 0, children: toc }];
|
||||
|
||||
$headers.each(function(index) {
|
||||
var $h = $(this);
|
||||
var level = parseInt(this.tagName.charAt(1));
|
||||
var text = $h.text().trim();
|
||||
var id = $h.attr('id');
|
||||
let $h = $(this);
|
||||
let level = parseInt(this.tagName.charAt(1));
|
||||
let text = $h.text().trim();
|
||||
let id = $h.attr('id');
|
||||
|
||||
// 确保标题有 ID
|
||||
if (!id) {
|
||||
@@ -2553,7 +2553,7 @@ $(document).on("click" , "#blog_categories .tag" , function(){
|
||||
$h.attr('id', id);
|
||||
}
|
||||
|
||||
var item = { id: id, text: text, level: level, children: [] };
|
||||
let item = { id: id, text: text, level: level, children: [] };
|
||||
|
||||
// 找到合适的父级
|
||||
while (stack.length > 1 && stack[stack.length - 1].level >= level) {
|
||||
@@ -2566,9 +2566,9 @@ $(document).on("click" , "#blog_categories .tag" , function(){
|
||||
// 递归生成 HTML
|
||||
function buildHtml(items, isRoot) {
|
||||
if (!items || items.length === 0) return '';
|
||||
var html = isRoot ? '<ul>' : '<ul class="index-subItem-box">';
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var item = items[i];
|
||||
let html = isRoot ? '<ul>' : '<ul class="index-subItem-box">';
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
let item = items[i];
|
||||
html += '<li class="index-item">';
|
||||
html += '<a href="#' + item.id + '" class="index-link" data-target="' + item.id + '">' + item.text + '</a>';
|
||||
if (item.children.length > 0) {
|
||||
@@ -2587,9 +2587,9 @@ $(document).on("click" , "#blog_categories .tag" , function(){
|
||||
// 绑定点击事件
|
||||
$mobileContainer.off('click.mobileCatalog').on('click.mobileCatalog', '.index-link', function(e) {
|
||||
e.preventDefault();
|
||||
var targetId = $(this).attr('href');
|
||||
let targetId = $(this).attr('href');
|
||||
if (targetId) {
|
||||
var $target = $(targetId);
|
||||
let $target = $(targetId);
|
||||
if ($target.length) {
|
||||
$mobileContainer.find('.index-item').removeClass('current');
|
||||
$(this).closest('.index-item').addClass('current');
|
||||
@@ -2611,17 +2611,17 @@ $(document).on("click" , "#blog_categories .tag" , function(){
|
||||
|
||||
// 更新移动端目录高亮
|
||||
function updateMobileCatalogHighlight() {
|
||||
var $mobileContainer = $("#leftbar_mobile_catalog");
|
||||
var $postContent = $("#post_content");
|
||||
let $mobileContainer = $("#leftbar_mobile_catalog");
|
||||
let $postContent = $("#post_content");
|
||||
if ($mobileContainer.length === 0 || $postContent.length === 0) return;
|
||||
|
||||
var scrollTop = $(window).scrollTop();
|
||||
var $headers = $postContent.find('h1, h2, h3, h4, h5, h6');
|
||||
var currentId = null;
|
||||
let scrollTop = $(window).scrollTop();
|
||||
let $headers = $postContent.find('h1, h2, h3, h4, h5, h6');
|
||||
let currentId = null;
|
||||
|
||||
$headers.each(function() {
|
||||
var $h = $(this);
|
||||
var top = $h.offset().top - 100;
|
||||
let $h = $(this);
|
||||
let top = $h.offset().top - 100;
|
||||
if (scrollTop >= top) {
|
||||
currentId = $h.attr('id');
|
||||
}
|
||||
@@ -2641,14 +2641,14 @@ $(document).on("click" , "#blog_categories .tag" , function(){
|
||||
|
||||
// 滚动目录到当前激活项
|
||||
function scrollMobileCatalogToActive() {
|
||||
var container = $("#leftbar_mobile_catalog");
|
||||
var activeItem = container.find(".index-item.current");
|
||||
let container = $("#leftbar_mobile_catalog");
|
||||
let activeItem = container.find(".index-item.current");
|
||||
if (activeItem.length > 0 && container.length > 0) {
|
||||
var containerHeight = container.height();
|
||||
var itemTop = activeItem.position().top;
|
||||
var itemHeight = activeItem.outerHeight();
|
||||
var scrollTop = container.scrollTop();
|
||||
var targetScroll = scrollTop + itemTop - (containerHeight / 2) + (itemHeight / 2);
|
||||
let containerHeight = container.height();
|
||||
let itemTop = activeItem.position().top;
|
||||
let itemHeight = activeItem.outerHeight();
|
||||
let scrollTop = container.scrollTop();
|
||||
let targetScroll = scrollTop + itemTop - (containerHeight / 2) + (itemHeight / 2);
|
||||
container.stop().animate({
|
||||
scrollTop: Math.max(0, targetScroll)
|
||||
}, 300, 'easeOutCubic');
|
||||
@@ -2656,7 +2656,7 @@ $(document).on("click" , "#blog_categories .tag" , function(){
|
||||
}
|
||||
|
||||
// 监听页面滚动,实时更新移动端目录高亮并自动滚动
|
||||
var mobileCatalogScrollTimer = null;
|
||||
let mobileCatalogScrollTimer = null;
|
||||
$(window).on("scroll.mobileCatalog", function() {
|
||||
if (!window.mobileCatalogInitialized) return;
|
||||
// 节流处理
|
||||
@@ -2677,7 +2677,7 @@ $(document).on("click" , "#blog_categories .tag" , function(){
|
||||
|
||||
// ========== 移动端TODO交互 ==========
|
||||
function updateMobileTodoCount() {
|
||||
var count = $("#mobile-todo-list .mobile-todo-item:not(.todo-completed)").length;
|
||||
let count = $("#mobile-todo-list .mobile-todo-item:not(.todo-completed)").length;
|
||||
$("#mobile_todo_count").text(count);
|
||||
// 同步更新桌面端计数
|
||||
$(".todo-count").text(count);
|
||||
@@ -2697,11 +2697,11 @@ $(document).on("click" , "#blog_categories .tag" , function(){
|
||||
function addMobileTodo() {
|
||||
if (!window.mobileTodoConfig) return;
|
||||
|
||||
var input = $("#mobile-todo-input");
|
||||
var content = input.val().trim();
|
||||
let input = $("#mobile-todo-input");
|
||||
let content = input.val().trim();
|
||||
if (!content) return;
|
||||
|
||||
var btn = $("#mobile-todo-add-btn");
|
||||
let btn = $("#mobile-todo-add-btn");
|
||||
btn.prop("disabled", true);
|
||||
|
||||
$.ajax({
|
||||
@@ -2714,10 +2714,10 @@ $(document).on("click" , "#blog_categories .tag" , function(){
|
||||
},
|
||||
success: function(res) {
|
||||
if (res.success) {
|
||||
var list = $("#mobile-todo-list");
|
||||
let list = $("#mobile-todo-list");
|
||||
list.find(".mobile-todo-empty").remove();
|
||||
|
||||
var newItem = $('<li class="mobile-todo-item" data-id="' + res.data.id + '">' +
|
||||
let newItem = $('<li class="mobile-todo-item" data-id="' + res.data.id + '">' +
|
||||
'<span class="mobile-todo-content">' + $("<div>").text(content).html() + '</span>' +
|
||||
'<button class="mobile-todo-complete-btn" title="完成"><i class="fa fa-check"></i></button>' +
|
||||
'</li>');
|
||||
@@ -2738,16 +2738,16 @@ $(document).on("click" , "#blog_categories .tag" , function(){
|
||||
}
|
||||
|
||||
// 移动端 TODO 验证码相关变量
|
||||
var mobilePendingUrgeBtn = null;
|
||||
var mobileGeetestCaptchaObj = null;
|
||||
let mobilePendingUrgeBtn = null;
|
||||
let mobileGeetestCaptchaObj = null;
|
||||
|
||||
// 完成/删除/催促TODO
|
||||
$(document).on("click", "#mobile-todo-list .mobile-todo-complete-btn, #mobile-todo-list .mobile-todo-delete-btn, #mobile-todo-list .mobile-todo-urge-btn", function() {
|
||||
if (!window.mobileTodoConfig) return;
|
||||
|
||||
var btn = $(this);
|
||||
var item = btn.closest(".mobile-todo-item");
|
||||
var id = item.data("id");
|
||||
let btn = $(this);
|
||||
let item = btn.closest(".mobile-todo-item");
|
||||
let id = item.data("id");
|
||||
|
||||
if (btn.hasClass("mobile-todo-complete-btn")) {
|
||||
btn.prop("disabled", true);
|
||||
@@ -2797,7 +2797,7 @@ $(document).on("click" , "#blog_categories .tag" , function(){
|
||||
} else if (btn.hasClass("mobile-todo-urge-btn") && !btn.hasClass("urged")) {
|
||||
// 检查是否需要验证码
|
||||
if (window.mobileTodoConfig.needCaptcha) {
|
||||
var captchaContainer = $(".mobile-todo-captcha-container");
|
||||
let captchaContainer = $(".mobile-todo-captcha-container");
|
||||
if (captchaContainer.length > 0) {
|
||||
captchaContainer.slideDown(200);
|
||||
mobilePendingUrgeBtn = btn;
|
||||
@@ -2813,9 +2813,9 @@ $(document).on("click" , "#blog_categories .tag" , function(){
|
||||
captcha.onReady(function() {
|
||||
captcha.showCaptcha();
|
||||
}).onSuccess(function() {
|
||||
var result = captcha.getValidate();
|
||||
let result = captcha.getValidate();
|
||||
if (result && mobilePendingUrgeBtn) {
|
||||
var urgeId = mobilePendingUrgeBtn.closest(".mobile-todo-item").data("id");
|
||||
let urgeId = mobilePendingUrgeBtn.closest(".mobile-todo-item").data("id");
|
||||
doMobileUrgeGeetest(mobilePendingUrgeBtn, urgeId, result);
|
||||
}
|
||||
}).onError(function() {
|
||||
@@ -2843,15 +2843,15 @@ $(document).on("click" , "#blog_categories .tag" , function(){
|
||||
$(document).on("click", "#mobile-todo-captcha-submit", function() {
|
||||
if (!mobilePendingUrgeBtn) return;
|
||||
|
||||
var captchaInput = $("#mobile-todo-captcha-input");
|
||||
var captchaValue = captchaInput.val().trim();
|
||||
let captchaInput = $("#mobile-todo-captcha-input");
|
||||
let captchaValue = captchaInput.val().trim();
|
||||
|
||||
if (!captchaValue) {
|
||||
captchaInput.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
var id = mobilePendingUrgeBtn.closest(".mobile-todo-item").data("id");
|
||||
let id = mobilePendingUrgeBtn.closest(".mobile-todo-item").data("id");
|
||||
doMobileUrge(mobilePendingUrgeBtn, id, captchaValue);
|
||||
});
|
||||
|
||||
@@ -2912,7 +2912,7 @@ $(document).on("click" , "#blog_categories .tag" , function(){
|
||||
|
||||
// 处理移动端催促响应
|
||||
function handleMobileUrgeResponse(btn, res) {
|
||||
var captchaContainer = $(".mobile-todo-captcha-container");
|
||||
let captchaContainer = $(".mobile-todo-captcha-container");
|
||||
|
||||
if (res.success) {
|
||||
btn.addClass("urged").html('<i class="fa fa-check"></i>');
|
||||
@@ -2925,7 +2925,7 @@ $(document).on("click" , "#blog_categories .tag" , function(){
|
||||
}
|
||||
|
||||
// 同步到桌面端
|
||||
var id = btn.closest(".mobile-todo-item").data("id");
|
||||
let id = btn.closest(".mobile-todo-item").data("id");
|
||||
syncTodoToDesktop(id, "", "urge");
|
||||
|
||||
// 显示成功提示
|
||||
@@ -2960,24 +2960,24 @@ $(document).on("click" , "#blog_categories .tag" , function(){
|
||||
|
||||
// 同步TODO操作到桌面端
|
||||
function syncTodoToDesktop(id, content, action) {
|
||||
var desktopList = $("#todo-list");
|
||||
let desktopList = $("#todo-list");
|
||||
if (desktopList.length === 0) return;
|
||||
|
||||
if (action === "add") {
|
||||
desktopList.find(".todo-empty").remove();
|
||||
var newItem = $('<li class="todo-item" data-id="' + id + '">' +
|
||||
let newItem = $('<li class="todo-item" data-id="' + id + '">' +
|
||||
'<span class="todo-content">' + $("<div>").text(content).html() + '</span>' +
|
||||
'<button class="todo-complete-btn" title="完成"><i class="fa fa-check"></i></button>' +
|
||||
'</li>');
|
||||
desktopList.prepend(newItem);
|
||||
} else if (action === "complete") {
|
||||
var item = desktopList.find('.todo-item[data-id="' + id + '"]');
|
||||
let item = desktopList.find('.todo-item[data-id="' + id + '"]');
|
||||
item.addClass("todo-completed");
|
||||
item.find(".todo-complete-btn").replaceWith('<button class="todo-delete-btn" title="删除"><i class="fa fa-trash"></i></button>');
|
||||
} else if (action === "delete") {
|
||||
desktopList.find('.todo-item[data-id="' + id + '"]').remove();
|
||||
} else if (action === "urge") {
|
||||
var urgeBtn = desktopList.find('.todo-item[data-id="' + id + '"] .todo-urge-btn');
|
||||
let urgeBtn = desktopList.find('.todo-item[data-id="' + id + '"] .todo-urge-btn');
|
||||
urgeBtn.addClass("urged").prop("disabled", true).html('<i class="fa fa-check"></i>');
|
||||
}
|
||||
}
|
||||
@@ -3397,7 +3397,7 @@ function randomString(len) {
|
||||
res[0] = chars.charAt(Math.floor(Math.random() * (chars.length - 10)));
|
||||
return res;
|
||||
}
|
||||
var codeOfBlocks = {};
|
||||
let codeOfBlocks = {};
|
||||
function getCodeFromBlock(block){
|
||||
if (codeOfBlocks[block.id] !== undefined){
|
||||
return codeOfBlocks[block.id];
|
||||
@@ -3522,7 +3522,7 @@ $(document).on("click" , ".hljs-control-toggle-linenumber" , function(){
|
||||
|
||||
/*时间差计算*/
|
||||
function addPreZero(num, n) {
|
||||
var len = num.toString().length;
|
||||
let len = num.toString().length;
|
||||
while(len < n) {
|
||||
num = "0" + num;
|
||||
len++;
|
||||
@@ -3608,14 +3608,14 @@ void 0;
|
||||
// 1. 触摸涟漪效果
|
||||
function createRipple(event, element) {
|
||||
if (window.matchMedia('(hover: hover)').matches) return;
|
||||
var rect = element.getBoundingClientRect();
|
||||
var ripple = document.createElement('span');
|
||||
var size = Math.max(rect.width, rect.height);
|
||||
let rect = element.getBoundingClientRect();
|
||||
let ripple = document.createElement('span');
|
||||
let size = Math.max(rect.width, rect.height);
|
||||
ripple.style.width = ripple.style.height = size + 'px';
|
||||
ripple.style.left = ((event.clientX || event.touches[0].clientX) - rect.left - size / 2) + 'px';
|
||||
ripple.style.top = ((event.clientY || event.touches[0].clientY) - rect.top - size / 2) + 'px';
|
||||
ripple.className = 'touch-ripple';
|
||||
var oldRipple = element.querySelector('.touch-ripple');
|
||||
let oldRipple = element.querySelector('.touch-ripple');
|
||||
if (oldRipple) oldRipple.remove();
|
||||
element.style.position = 'relative';
|
||||
element.style.overflow = 'hidden';
|
||||
@@ -3624,7 +3624,7 @@ void 0;
|
||||
}
|
||||
|
||||
function initRippleEffect() {
|
||||
var rippleElements = document.querySelectorAll('.btn, .card, .nav-link, .dropdown-item, .page-link, .leftbar-mobile-menu-item > a, .leftbar-mobile-action, .fabtn, .comment-reply, .tag, .badge');
|
||||
let rippleElements = document.querySelectorAll('.btn, .card, .nav-link, .dropdown-item, .page-link, .leftbar-mobile-menu-item > a, .leftbar-mobile-action, .fabtn, .comment-reply, .tag, .badge');
|
||||
rippleElements.forEach(function(el) {
|
||||
if (el.dataset.rippleInit) return;
|
||||
el.dataset.rippleInit = 'true';
|
||||
@@ -3634,7 +3634,7 @@ void 0;
|
||||
|
||||
// 2. 图片加载动画
|
||||
function initImageLoadAnimation() {
|
||||
var images = document.querySelectorAll('article img[loading="lazy"], .post-thumbnail img');
|
||||
let images = document.querySelectorAll('article img[loading="lazy"], .post-thumbnail img');
|
||||
images.forEach(function(img) {
|
||||
if (img.dataset.loadAnimInit) return;
|
||||
img.dataset.loadAnimInit = 'true';
|
||||
@@ -3646,8 +3646,8 @@ void 0;
|
||||
// 3. 滚动入场动画
|
||||
function initScrollAnimations() {
|
||||
if (!('IntersectionObserver' in window)) return;
|
||||
var animatedElements = document.querySelectorAll('.article-list article.post, .comment-item, .timeline-item, .friend-link-item, #leftbar .card, #rightbar .card');
|
||||
var observer = new IntersectionObserver(function(entries) {
|
||||
let animatedElements = document.querySelectorAll('.article-list article.post, .comment-item, .timeline-item, .friend-link-item, #leftbar .card, #rightbar .card');
|
||||
let observer = new IntersectionObserver(function(entries) {
|
||||
entries.forEach(function(entry) {
|
||||
if (entry.isIntersecting) { entry.target.classList.add('animate-in'); observer.unobserve(entry.target); }
|
||||
});
|
||||
@@ -3661,9 +3661,9 @@ void 0;
|
||||
if (anchor.dataset.smoothScrollInit) return;
|
||||
anchor.dataset.smoothScrollInit = 'true';
|
||||
anchor.addEventListener('click', function(e) {
|
||||
var targetId = this.getAttribute('href');
|
||||
let targetId = this.getAttribute('href');
|
||||
if (targetId === '#') return;
|
||||
var target = document.querySelector(targetId);
|
||||
let target = document.querySelector(targetId);
|
||||
if (target) { e.preventDefault(); target.scrollIntoView({ behavior: 'smooth', block: 'start' }); }
|
||||
});
|
||||
});
|
||||
@@ -3672,12 +3672,12 @@ void 0;
|
||||
// 5. 页面加载进度条
|
||||
function initLoadingBar() {
|
||||
if (document.getElementById('page-loading-bar')) return;
|
||||
var bar = document.createElement('div');
|
||||
let bar = document.createElement('div');
|
||||
bar.id = 'page-loading-bar';
|
||||
bar.style.width = '0%';
|
||||
document.body.appendChild(bar);
|
||||
var progress = 0;
|
||||
var interval = setInterval(function() {
|
||||
let progress = 0;
|
||||
let interval = setInterval(function() {
|
||||
progress += Math.random() * 10;
|
||||
if (progress >= 90) { clearInterval(interval); progress = 90; }
|
||||
bar.style.width = progress + '%';
|
||||
@@ -3694,14 +3694,14 @@ void 0;
|
||||
if (typeof jQuery === 'undefined') return;
|
||||
jQuery(document).on('pjax:start', function() {
|
||||
jQuery('#primary').addClass('pjax-loading');
|
||||
var bar = document.getElementById('page-loading-bar');
|
||||
let bar = document.getElementById('page-loading-bar');
|
||||
if (!bar) { bar = document.createElement('div'); bar.id = 'page-loading-bar'; document.body.appendChild(bar); }
|
||||
bar.style.opacity = '1'; bar.style.width = '30%';
|
||||
setTimeout(function() { bar.style.width = '60%'; }, 200);
|
||||
});
|
||||
jQuery(document).on('pjax:end', function() {
|
||||
jQuery('#primary').removeClass('pjax-loading');
|
||||
var bar = document.getElementById('page-loading-bar');
|
||||
let bar = document.getElementById('page-loading-bar');
|
||||
if (bar) { bar.style.width = '100%'; setTimeout(function() { bar.style.opacity = '0'; setTimeout(function() { bar.remove(); }, 300); }, 200); }
|
||||
setTimeout(function() { initRippleEffect(); initImageLoadAnimation(); initScrollAnimations(); initSmoothScroll(); }, 100);
|
||||
});
|
||||
|
||||
195
functions.php
195
functions.php
@@ -29,7 +29,7 @@ function theme_slug_setup() {
|
||||
}
|
||||
add_action('after_setup_theme','theme_slug_setup');
|
||||
|
||||
$argon_version = !(wp_get_theme() -> Template) ? wp_get_theme() -> Version : wp_get_theme(wp_get_theme() -> Template) -> Version;
|
||||
$argon_version = !(wp_get_theme()->Template) ? wp_get_theme()->Version : wp_get_theme(wp_get_theme()->Template)->Version;
|
||||
$GLOBALS['theme_version'] = $argon_version;
|
||||
|
||||
// 强制使用本地资源,避免 CDN 加载问题
|
||||
@@ -219,7 +219,6 @@ if (version_compare($argon_last_version, $GLOBALS['theme_version'], '<' )){
|
||||
update_option("argon_last_version", $GLOBALS['theme_version']);
|
||||
}
|
||||
|
||||
|
||||
//引入邮件模板系统
|
||||
require_once(get_template_directory() . '/email-templates/base.php');
|
||||
require_once(get_template_directory() . '/email-templates/comment-notify.php');
|
||||
@@ -961,7 +960,7 @@ function argon_get_first_image_of_article(){
|
||||
if (post_password_required()){
|
||||
return false;
|
||||
}
|
||||
$post_content_full = apply_filters('the_content', preg_replace( '<!--more(.*?)-->', '', $post -> post_content));
|
||||
$post_content_full = apply_filters('the_content', preg_replace( '<!--more(.*?)-->', '', $post->post_content));
|
||||
preg_match('/<img(.*?)(src|data-original)=[\"\']((http:|https:)?\/\/(.*?))[\"\'](.*?)\/?>/', $post_content_full, $match);
|
||||
if (isset($match[3])){
|
||||
return $match[3];
|
||||
@@ -971,7 +970,7 @@ function argon_get_first_image_of_article(){
|
||||
function argon_has_post_thumbnail($postID = 0){
|
||||
if ($postID == 0){
|
||||
global $post;
|
||||
$postID = $post -> ID;
|
||||
$postID = $post->ID;
|
||||
}
|
||||
if (has_post_thumbnail()){
|
||||
return true;
|
||||
@@ -990,7 +989,7 @@ function argon_has_post_thumbnail($postID = 0){
|
||||
function argon_get_post_thumbnail($postID = 0){
|
||||
if ($postID == 0){
|
||||
global $post;
|
||||
$postID = $post -> ID;
|
||||
$postID = $post->ID;
|
||||
}
|
||||
if (has_post_thumbnail()){
|
||||
return apply_filters("argon_post_thumbnail", wp_get_attachment_image_src(get_post_thumbnail_id($postID), "full")[0]);
|
||||
@@ -1000,8 +999,8 @@ function argon_get_post_thumbnail($postID = 0){
|
||||
//文末附加内容
|
||||
function get_additional_content_after_post(){
|
||||
global $post;
|
||||
$postID = $post -> ID;
|
||||
$res = get_post_meta($post -> ID, 'argon_after_post', true);
|
||||
$postID = $post->ID;
|
||||
$res = get_post_meta($post->ID, 'argon_after_post', true);
|
||||
if ($res == "--none--"){
|
||||
return "";
|
||||
}
|
||||
@@ -1134,7 +1133,7 @@ function get_seo_description(){
|
||||
return preg_replace('/ \[…]$/', '…', get_the_excerpt());
|
||||
}
|
||||
if (!post_password_required()){
|
||||
return htmlspecialchars(mb_substr(str_replace("\n", '', strip_tags($post -> post_content)), 0, 50)) . "...";
|
||||
return htmlspecialchars(mb_substr(str_replace("\n", '', strip_tags($post->post_content)), 0, 50)) . "...";
|
||||
}else{
|
||||
return __("这是一个加密页面,需要密码来查看", 'argon');
|
||||
}
|
||||
@@ -1146,14 +1145,14 @@ function get_seo_description(){
|
||||
function get_seo_keywords(){
|
||||
if (is_single()){
|
||||
global $post;
|
||||
$tags = get_the_tags('', ',', '', $post -> ID);
|
||||
$tags = get_the_tags('', ',', '', $post->ID);
|
||||
if ($tags != null){
|
||||
$res = "";
|
||||
foreach ($tags as $tag){
|
||||
if ($res != ""){
|
||||
$res .= ",";
|
||||
}
|
||||
$res .= $tag -> name;
|
||||
$res .= $tag->name;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
@@ -1178,7 +1177,7 @@ function get_seo_keywords(){
|
||||
//页面分享预览图
|
||||
function get_og_image(){
|
||||
global $post;
|
||||
$postID = $post -> ID;
|
||||
$postID = $post->ID;
|
||||
$argon_first_image_as_thumbnail = get_post_meta($postID, 'argon_first_image_as_thumbnail', 'true');
|
||||
if (has_post_thumbnail() || $argon_first_image_as_thumbnail == 'true'){
|
||||
return argon_get_post_thumbnail($postID);
|
||||
@@ -1202,7 +1201,7 @@ function set_post_views(){
|
||||
}
|
||||
if (!isset($post_id)){
|
||||
global $post;
|
||||
$post_id = $post -> ID;
|
||||
$post_id = $post->ID;
|
||||
}
|
||||
if (post_password_required($post_id)){
|
||||
return;
|
||||
@@ -1222,10 +1221,10 @@ function set_post_views(){
|
||||
return;
|
||||
}
|
||||
global $post;
|
||||
if (!isset($post -> ID)){
|
||||
if (!isset($post->ID)){
|
||||
return;
|
||||
}
|
||||
$post_id = $post -> ID;
|
||||
$post_id = $post->ID;
|
||||
$count_key = 'views';
|
||||
$count = get_post_meta($post_id, $count_key, true);
|
||||
if (is_single() || is_page()) {
|
||||
@@ -1316,7 +1315,7 @@ function have_catalog(){
|
||||
if (is_page() && is_page_template('timeline.php')){
|
||||
return true;
|
||||
}
|
||||
$content = get_post(get_the_ID()) -> post_content;
|
||||
$content = get_post(get_the_ID())->post_content;
|
||||
// 检查 HTML 标题标签
|
||||
if (preg_match('/<h[1-6](.*?)>/i', $content)){
|
||||
return true;
|
||||
@@ -1375,7 +1374,7 @@ function get_article_meta($type){
|
||||
if ($type == 'comments'){
|
||||
return '<div class="post-meta-detail post-meta-detail-comments">
|
||||
<i class="fa fa-comments-o" aria-hidden="true"></i> ' .
|
||||
get_post(get_the_ID()) -> comment_count .
|
||||
get_post(get_the_ID())->comment_count .
|
||||
'</div>';
|
||||
}
|
||||
if ($type == 'categories'){
|
||||
@@ -1383,7 +1382,7 @@ function get_article_meta($type){
|
||||
<i class="fa fa-bookmark-o" aria-hidden="true"></i> ';
|
||||
$categories = get_the_category();
|
||||
foreach ($categories as $index => $category){
|
||||
$res .= '<a href="' . get_category_link($category -> term_id) . '" target="_blank" class="post-meta-detail-catagory-link">' . $category -> cat_name . '</a>';
|
||||
$res .= '<a href="' . get_category_link($category->term_id) . '" target="_blank" class="post-meta-detail-catagory-link">' . $category->cat_name . '</a>';
|
||||
if ($index != count($categories) - 1){
|
||||
$res .= '<span class="post-meta-detail-catagory-space">,</span>';
|
||||
}
|
||||
@@ -1395,7 +1394,7 @@ function get_article_meta($type){
|
||||
$res = '<div class="post-meta-detail post-meta-detail-author">
|
||||
<i class="fa fa-user-circle-o" aria-hidden="true"></i> ';
|
||||
global $authordata;
|
||||
$res .= '<a href="' . get_author_posts_url($authordata -> ID, $authordata -> user_nicename) . '" target="_blank">' . get_the_author() . '</a>
|
||||
$res .= '<a href="' . get_author_posts_url($authordata->ID, $authordata->user_nicename) . '" target="_blank">' . get_the_author() . '</a>
|
||||
</div>';
|
||||
return $res;
|
||||
}
|
||||
@@ -1428,7 +1427,7 @@ function is_readingtime_meta_hidden(){
|
||||
return true;
|
||||
}
|
||||
global $post;
|
||||
if (get_post_meta($post -> ID, 'argon_hide_readingtime', true) == 'true'){
|
||||
if (get_post_meta($post->ID, 'argon_hide_readingtime', true) == 'true'){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -1436,14 +1435,14 @@ function is_readingtime_meta_hidden(){
|
||||
//当前文章是否隐藏 发布时间和分类 (简洁 Meta)
|
||||
function is_meta_simple(){
|
||||
global $post;
|
||||
if (get_post_meta($post -> ID, 'argon_meta_simple', true) == 'true'){
|
||||
if (get_post_meta($post->ID, 'argon_meta_simple', true) == 'true'){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//根据文章 id 获取标题
|
||||
function get_post_title_by_id($id){
|
||||
return get_post($id) -> post_title;
|
||||
return get_post($id)->post_title;
|
||||
}
|
||||
//解析 UA 和相应图标
|
||||
require_once(get_template_directory() . '/useragent-parser.php');
|
||||
@@ -1510,14 +1509,14 @@ function check_login_user_same($userid){
|
||||
if ($userid == 0){
|
||||
return false;
|
||||
}
|
||||
if ($userid != (wp_get_current_user() -> ID)){
|
||||
if ($userid != (wp_get_current_user()->ID)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function get_comment_user_id_by_id($comment_ID){
|
||||
$comment = get_comment($comment_ID);
|
||||
return $comment -> user_id;
|
||||
return $comment->user_id;
|
||||
}
|
||||
function check_comment_userid($id){
|
||||
if (!check_login_user_same(get_comment_user_id_by_id($id))){
|
||||
@@ -1547,7 +1546,7 @@ function user_can_view_comment($id){
|
||||
//过滤 RSS 中悄悄话
|
||||
function remove_rss_private_comment_title_and_author($str){
|
||||
global $comment;
|
||||
if (isset($comment -> comment_ID) && is_comment_private_mode($comment -> comment_ID)){
|
||||
if (isset($comment->comment_ID) && is_comment_private_mode($comment->comment_ID)){
|
||||
return "***";
|
||||
}
|
||||
return $str;
|
||||
@@ -1556,9 +1555,9 @@ add_filter('the_title_rss' , 'remove_rss_private_comment_title_and_author');
|
||||
add_filter('comment_author_rss' , 'remove_rss_private_comment_title_and_author');
|
||||
function remove_rss_private_comment_content($str){
|
||||
global $comment;
|
||||
if (is_comment_private_mode($comment -> comment_ID)){
|
||||
$comment -> comment_content = __('该评论为悄悄话', 'argon');
|
||||
return $comment -> comment_content;
|
||||
if (is_comment_private_mode($comment->comment_ID)){
|
||||
$comment->comment_content = __('该评论为悄悄话', 'argon');
|
||||
return $comment->comment_content;
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
@@ -1568,11 +1567,11 @@ function get_comment_parent_info($comment){
|
||||
if (!$GLOBALS['argon_comment_options']['show_comment_parent_info']){
|
||||
return "";
|
||||
}
|
||||
if ($comment -> comment_parent == 0){
|
||||
if ($comment->comment_parent == 0){
|
||||
return "";
|
||||
}
|
||||
$parent_comment = get_comment($comment -> comment_parent);
|
||||
return '<div class="comment-parent-info" data-parent-id=' . $parent_comment -> comment_ID . '><i class="fa fa-reply" aria-hidden="true"></i> ' . get_comment_author($parent_comment -> comment_ID) . '</div>';
|
||||
$parent_comment = get_comment($comment->comment_parent);
|
||||
return '<div class="comment-parent-info" data-parent-id=' . $parent_comment->comment_ID . '><i class="fa fa-reply" aria-hidden="true"></i> ' . get_comment_author($parent_comment->comment_ID) . '</div>';
|
||||
}
|
||||
//是否可以查看评论编辑记录
|
||||
function can_visit_comment_edit_history($id){
|
||||
@@ -1618,10 +1617,10 @@ function get_comment_edit_history(){
|
||||
<div class='comment-edit-history-id'>
|
||||
#" . $position . "
|
||||
</div>
|
||||
" . ($edition -> isfirst ? "<span class='badge badge-primary badge-admin'>" . __("最初版本", 'argon') . "</span>" : "") . "
|
||||
" . ($edition->isfirst ? "<span class='badge badge-primary badge-admin'>" . __("最初版本", 'argon') . "</span>" : "") . "
|
||||
</div>
|
||||
<div class='comment-edit-history-time'>" . date('Y-m-d H:i:s', $edition -> time) . "</div>
|
||||
<div class='comment-edit-history-content'>" . str_replace("\n", "</br>", $edition -> content) . "</div>
|
||||
<div class='comment-edit-history-time'>" . date('Y-m-d H:i:s', $edition->time) . "</div>
|
||||
<div class='comment-edit-history-content'>" . str_replace("\n", "</br>", $edition->content) . "</div>
|
||||
</div>";
|
||||
}
|
||||
exit(json_encode(array(
|
||||
@@ -1633,10 +1632,10 @@ add_action('wp_ajax_get_comment_edit_history', 'get_comment_edit_history');
|
||||
add_action('wp_ajax_nopriv_get_comment_edit_history', 'get_comment_edit_history');
|
||||
//是否可以置顶/取消置顶
|
||||
function is_comment_pinable($id){
|
||||
if (get_comment($id) -> comment_approved != "1"){
|
||||
if (get_comment($id)->comment_approved != "1"){
|
||||
return false;
|
||||
}
|
||||
if (get_comment($id) -> comment_parent != 0){
|
||||
if (get_comment($id)->comment_parent != 0){
|
||||
return false;
|
||||
}
|
||||
if (is_comment_private_mode($id)){
|
||||
@@ -1660,7 +1659,7 @@ function argon_get_comment_text($comment_ID = 0, $args = array()) {
|
||||
);
|
||||
$comment_text = preg_replace(
|
||||
'/<img src="(.*?)" alt="(.*?)" \/>/',
|
||||
'<a href="$1" title="$2" data-fancybox="comment-' . $comment -> comment_ID . '-image" class="comment-image" rel="nofollow">
|
||||
'<a href="$1" title="$2" data-fancybox="comment-' . $comment->comment_ID . '-image" class="comment-image" rel="nofollow">
|
||||
<i class="fa fa-image" aria-hidden="true"></i>
|
||||
' . __('查看图片', 'argon') . '
|
||||
<img src="" alt="$2" class="comment-image-preview">
|
||||
@@ -1695,7 +1694,7 @@ function get_comment_upvotes($id) {
|
||||
if ($comment == null){
|
||||
return 0;
|
||||
}
|
||||
$upvotes = get_comment_meta($comment -> comment_ID, "upvotes", true);
|
||||
$upvotes = get_comment_meta($comment->comment_ID, "upvotes", true);
|
||||
if ($upvotes == null) {
|
||||
$upvotes = 0;
|
||||
}
|
||||
@@ -1706,12 +1705,12 @@ function set_comment_upvotes($id){
|
||||
if ($comment == null){
|
||||
return 0;
|
||||
}
|
||||
$upvotes = get_comment_meta($comment -> comment_ID, "upvotes", true);
|
||||
$upvotes = get_comment_meta($comment->comment_ID, "upvotes", true);
|
||||
if ($upvotes == null) {
|
||||
$upvotes = 0;
|
||||
}
|
||||
$upvotes++;
|
||||
update_comment_meta($comment -> comment_ID, "upvotes", $upvotes);
|
||||
update_comment_meta($comment->comment_ID, "upvotes", $upvotes);
|
||||
return $upvotes;
|
||||
}
|
||||
function is_comment_upvoted($id){
|
||||
@@ -1768,7 +1767,7 @@ $GLOBALS['argon_comment_options']['show_comment_parent_info'] = (get_option("arg
|
||||
function argon_comment_format($comment, $args, $depth){
|
||||
global $comment_enable_upvote, $comment_enable_pinning;
|
||||
$GLOBALS['comment'] = $comment;
|
||||
if (!($comment -> placeholder) && user_can_view_comment(get_comment_ID())){
|
||||
if (!($comment->placeholder) && user_can_view_comment(get_comment_ID())){
|
||||
?>
|
||||
<li class="comment-item" id="comment-<?php comment_ID(); ?>" data-id="<?php comment_ID(); ?>" data-use-markdown="<?php echo get_comment_meta(get_comment_ID(), "use_markdown", true);?>">
|
||||
<div class="comment-item-left-wrapper">
|
||||
@@ -1790,7 +1789,7 @@ function argon_comment_format($comment, $args, $depth){
|
||||
<div class="comment-item-title">
|
||||
<div class="comment-name">
|
||||
<div class="comment-author"><?php echo get_comment_author_link();?></div>
|
||||
<?php if (user_can($comment -> user_id , "update_core")){
|
||||
<?php if (user_can($comment->user_id , "update_core")){
|
||||
echo '<span class="badge badge-primary badge-admin">' . __('博主', 'argon') . '</span>';}
|
||||
?>
|
||||
<?php echo get_comment_parent_info($comment); ?>
|
||||
@@ -1800,11 +1799,11 @@ function argon_comment_format($comment, $args, $depth){
|
||||
<?php if (is_comment_private_mode(get_comment_ID()) && user_can_view_comment(get_comment_ID())){
|
||||
echo '<span class="badge badge-success badge-private-comment">' . __('悄悄话', 'argon') . '</span>';}
|
||||
?>
|
||||
<?php if ($comment -> comment_approved == 0){
|
||||
<?php if ($comment->comment_approved == 0){
|
||||
echo '<span class="badge badge-warning badge-unapproved">' . __('待审核', 'argon') . '</span>';}
|
||||
?>
|
||||
<?php
|
||||
echo parse_ua_and_icon($comment -> comment_agent);
|
||||
echo parse_ua_and_icon($comment->comment_agent);
|
||||
?>
|
||||
</div>
|
||||
<div class="comment-info">
|
||||
@@ -1832,7 +1831,7 @@ function argon_comment_format($comment, $args, $depth){
|
||||
<button class="comment-pin btn btn-sm btn-outline-primary" data-id="<?php comment_ID(); ?>" type="button" style="margin-right: 2px;"><?php _ex('置顶', 'to pin', 'argon')?></button>
|
||||
<?php }
|
||||
} ?>
|
||||
<?php if ((check_comment_token(get_comment_ID()) || check_login_user_same($comment -> user_id)) && (get_option("argon_comment_allow_editing") != "false")) { ?>
|
||||
<?php if ((check_comment_token(get_comment_ID()) || check_login_user_same($comment->user_id)) && (get_option("argon_comment_allow_editing") != "false")) { ?>
|
||||
<button class="comment-edit btn btn-sm btn-outline-primary" data-id="<?php comment_ID(); ?>" type="button" style="margin-right: 2px;"><?php _e('编辑', 'argon')?></button>
|
||||
<?php } ?>
|
||||
<button class="comment-reply btn btn-sm btn-outline-primary" data-id="<?php comment_ID(); ?>" type="button"><?php _e('回复', 'argon')?></button>
|
||||
@@ -1849,10 +1848,10 @@ function argon_comment_shuoshuo_preview_format($comment, $args, $depth){
|
||||
<div class="comment-item-inner " id="comment-inner-<?php comment_ID();?>">
|
||||
<span class="shuoshuo-comment-item-title">
|
||||
<?php echo get_comment_author_link();?>
|
||||
<?php if( user_can($comment -> user_id , "update_core") ){
|
||||
<?php if( user_can($comment->user_id , "update_core") ){
|
||||
echo '<span class="badge badge-primary badge-admin">' . __('博主', 'argon') . '</span>';}
|
||||
?>
|
||||
<?php if( $comment -> comment_approved == 0 ){
|
||||
<?php if( $comment->comment_approved == 0 ){
|
||||
echo '<span class="badge badge-warning badge-unapproved">' . __('待审核', 'argon') . '</span>';}
|
||||
?>
|
||||
:
|
||||
@@ -1886,10 +1885,10 @@ get_comment_captcha_seed();
|
||||
class captcha_calculation{ //数字验证码
|
||||
var $captchaSeed;
|
||||
function __construct($seed) {
|
||||
$this -> captchaSeed = $seed;
|
||||
$this->captchaSeed = $seed;
|
||||
}
|
||||
function getChallenge(){
|
||||
mt_srand($this -> captchaSeed + 10007);
|
||||
mt_srand($this->captchaSeed + 10007);
|
||||
$oper = mt_rand(1 , 4);
|
||||
$num1 = 0;
|
||||
$num2 = 0;
|
||||
@@ -1919,7 +1918,7 @@ class captcha_calculation{ //数字验证码
|
||||
}
|
||||
}
|
||||
function getAnswer(){
|
||||
mt_srand($this -> captchaSeed + 10007);
|
||||
mt_srand($this->captchaSeed + 10007);
|
||||
$oper = mt_rand(1 , 4);
|
||||
$num1 = 0;
|
||||
$num2 = 0;
|
||||
@@ -1967,11 +1966,11 @@ function wrong_captcha($msg = null){
|
||||
}
|
||||
function get_comment_captcha(){
|
||||
$captcha = new captcha_calculation(get_comment_captcha_seed());
|
||||
return $captcha -> getChallenge();
|
||||
return $captcha->getChallenge();
|
||||
}
|
||||
function get_comment_captcha_answer(){
|
||||
$captcha = new captcha_calculation(get_comment_captcha_seed());
|
||||
return $captcha -> getAnswer();
|
||||
return $captcha->getAnswer();
|
||||
}
|
||||
// Geetest 验证码相关函数
|
||||
function geetest_validate($lot_number, $captcha_output, $pass_token, $gen_time) {
|
||||
@@ -2323,9 +2322,9 @@ function ajax_post_comment(){
|
||||
}
|
||||
$comment = wp_handle_comment_submission(wp_unslash($_POST));
|
||||
if (is_wp_error($comment)){
|
||||
$msg = $comment -> get_error_data();
|
||||
$msg = $comment->get_error_data();
|
||||
if (!empty($msg)){
|
||||
$msg = $comment -> get_error_message();
|
||||
$msg = $comment->get_error_message();
|
||||
}
|
||||
exit(json_encode(array(
|
||||
'status' => 'failed',
|
||||
@@ -2338,7 +2337,7 @@ function ajax_post_comment(){
|
||||
if (isset($_POST['qq'])){
|
||||
if (!empty($_POST['qq']) && get_option('argon_comment_enable_qq_avatar') == 'true'){
|
||||
$_comment = $comment;
|
||||
$_comment -> comment_author_email = $_POST['qq'] . "@avatarqq.com";
|
||||
$_comment->comment_author_email = $_POST['qq'] . "@avatarqq.com";
|
||||
do_action('set_comment_cookies', $_comment, $user);
|
||||
}
|
||||
}
|
||||
@@ -2360,8 +2359,8 @@ function ajax_post_comment(){
|
||||
exit(json_encode(array(
|
||||
'status' => 'success',
|
||||
'html' => $html,
|
||||
'id' => $comment -> comment_ID,
|
||||
'parentID' => $comment -> comment_parent,
|
||||
'id' => $comment->comment_ID,
|
||||
'parentID' => $comment->comment_parent,
|
||||
'commentOrder' => (get_option("comment_order") == "" ? "desc" : get_option("comment_order")),
|
||||
'newCaptchaSeed' => $newCaptchaSeed,
|
||||
'newCaptcha' => $newCaptcha,
|
||||
@@ -2393,7 +2392,7 @@ function comment_markdown_parse($comment_content){
|
||||
|
||||
//解析 Markdown
|
||||
$parsedown = new _Parsedown();
|
||||
$res = $parsedown -> text($comment_content);
|
||||
$res = $parsedown->text($comment_content);
|
||||
/*$res = preg_replace(
|
||||
'/<code>([\s\S]*?)<\/code>/',
|
||||
'<pre>$1</pre>',
|
||||
@@ -2499,16 +2498,16 @@ function comment_mail_notify($comment){
|
||||
if ($comment == null){
|
||||
return;
|
||||
}
|
||||
$id = $comment -> comment_ID;
|
||||
$commentPostID = $comment -> comment_post_ID;
|
||||
$commentAuthor = $comment -> comment_author;
|
||||
$parentID = $comment -> comment_parent;
|
||||
$id = $comment->comment_ID;
|
||||
$commentPostID = $comment->comment_post_ID;
|
||||
$commentAuthor = $comment->comment_author;
|
||||
$parentID = $comment->comment_parent;
|
||||
if ($parentID == 0){
|
||||
return;
|
||||
}
|
||||
$parentComment = get_comment($parentID);
|
||||
$parentEmail = $parentComment -> comment_author_email;
|
||||
$parentName = $parentComment -> comment_author;
|
||||
$parentEmail = $parentComment->comment_author_email;
|
||||
$parentName = $parentComment->comment_author;
|
||||
$emailTo = "$parentName <$parentEmail>";
|
||||
if (get_comment_meta($parentID, "enable_mailnotice", true) == "true"){
|
||||
if (check_email_address($parentEmail)){
|
||||
@@ -2555,8 +2554,8 @@ add_action('argon_async_comment_mail_notify', 'argon_async_comment_mail_notify_h
|
||||
function post_comment_updatemetas($id){
|
||||
$parentID = $_POST['comment_parent'];
|
||||
$comment = get_comment($id);
|
||||
$commentPostID = $comment -> comment_post_ID;
|
||||
$commentAuthor = $comment -> comment_author;
|
||||
$commentPostID = $comment->comment_post_ID;
|
||||
$commentAuthor = $comment->comment_author;
|
||||
$mailnoticeUnsubscribeKey = get_random_token();
|
||||
//评论 Markdown 源码
|
||||
update_comment_meta($id, "comment_content_source", $_POST['comment_content_source']);
|
||||
@@ -2598,7 +2597,7 @@ function post_comment_updatemetas($id){
|
||||
update_comment_meta($id, "enable_mailnotice", "false");
|
||||
}
|
||||
//向父级评论发送邮件
|
||||
if ($comment -> comment_approved == 1){
|
||||
if ($comment->comment_approved == 1){
|
||||
wp_schedule_single_event(time() + 1, 'argon_async_comment_mail_notify', array($comment->comment_ID));
|
||||
}
|
||||
//保存 QQ 号
|
||||
@@ -2697,7 +2696,7 @@ function pin_comment(){
|
||||
'msg' => $newPinnedStat ? __('评论已经是置顶状态', 'argon') : __('评论已经是取消置顶状态', 'argon')
|
||||
)));
|
||||
}
|
||||
if (get_comment($id) -> comment_parent != 0){
|
||||
if (get_comment($id)->comment_parent != 0){
|
||||
exit(json_encode(array(
|
||||
'status' => 'failed',
|
||||
'msg' => __('不能置顶子评论', 'argon')
|
||||
@@ -2837,8 +2836,8 @@ function get_argon_comment_paginate_links_prev_url(){
|
||||
//评论重排序(置顶优先)
|
||||
$GLOBALS['comment_order'] = get_option('comment_order');
|
||||
function argon_comment_cmp($a, $b){
|
||||
$a_pinned = get_comment_meta($a -> comment_ID, 'pinned', true);
|
||||
$b_pinned = get_comment_meta($b -> comment_ID, 'pinned', true);
|
||||
$a_pinned = get_comment_meta($a->comment_ID, 'pinned', true);
|
||||
$b_pinned = get_comment_meta($b->comment_ID, 'pinned', true);
|
||||
if ($a_pinned != "true"){
|
||||
$a_pinned = "false";
|
||||
}
|
||||
@@ -2846,7 +2845,7 @@ function argon_comment_cmp($a, $b){
|
||||
$b_pinned = "false";
|
||||
}
|
||||
if ($a_pinned == $b_pinned){
|
||||
return ($a -> comment_date_gmt) > ($b -> comment_date_gmt);
|
||||
return ($a->comment_date_gmt) > ($b->comment_date_gmt);
|
||||
}else{
|
||||
if ($a_pinned == "true"){
|
||||
return ($GLOBALS['comment_order'] == 'desc');
|
||||
@@ -2858,7 +2857,7 @@ function argon_comment_cmp($a, $b){
|
||||
function argon_get_comments(){
|
||||
global $wp_query;
|
||||
/*$cpage = get_query_var('cpage') ?? 1;
|
||||
$maxiumPages = $wp_query -> max_num_pages;*/
|
||||
$maxiumPages = $wp_query->max_num_pages;*/
|
||||
$args = array(
|
||||
'post__in' => array(get_the_ID()),
|
||||
'type' => 'comment',
|
||||
@@ -2876,7 +2875,7 @@ function argon_get_comments(){
|
||||
}
|
||||
|
||||
$comment_query = new WP_Comment_Query;
|
||||
$comments = $comment_query -> query($args);
|
||||
$comments = $comment_query->query($args);
|
||||
|
||||
if (get_option("argon_enable_comment_pinning", "false") == "true"){
|
||||
usort($comments, "argon_comment_cmp");
|
||||
@@ -2894,7 +2893,7 @@ function argon_get_comments(){
|
||||
$comments_per_page = get_option('comments_per_page');
|
||||
$comments_count = 0;
|
||||
foreach ($comments as $comment){
|
||||
if ($comment -> comment_parent == 0){
|
||||
if ($comment->comment_parent == 0){
|
||||
$comments_count++;
|
||||
}
|
||||
}
|
||||
@@ -2912,10 +2911,10 @@ function argon_get_comments(){
|
||||
//QQ Avatar 获取
|
||||
function get_avatar_by_qqnumber($avatar){
|
||||
global $comment;
|
||||
if (!isset($comment) || !isset($comment -> comment_ID)){
|
||||
if (!isset($comment) || !isset($comment->comment_ID)){
|
||||
return $avatar;
|
||||
}
|
||||
$qqnumber = get_comment_meta($comment -> comment_ID, 'qq_number', true);
|
||||
$qqnumber = get_comment_meta($comment->comment_ID, 'qq_number', true);
|
||||
if (!empty($qqnumber)){
|
||||
preg_match_all('/width=\'(.*?)\'/', $avatar, $preg_res);
|
||||
$size = $preg_res[1][0];
|
||||
@@ -2977,7 +2976,7 @@ function the_content_filter($content){
|
||||
$content = argon_fancybox($content);
|
||||
}
|
||||
global $post;
|
||||
$custom_css = get_post_meta($post -> ID, 'argon_custom_css', true);
|
||||
$custom_css = get_post_meta($post->ID, 'argon_custom_css', true);
|
||||
if (!empty($custom_css)){
|
||||
$content .= "<style>" . $custom_css . "</style>";
|
||||
}
|
||||
@@ -3066,7 +3065,7 @@ function alert_footer_copyright_changed(){ ?>
|
||||
</div>
|
||||
<?php }
|
||||
function check_footer_copyright(){
|
||||
$footer = file_get_contents(get_theme_root() . "/" . wp_get_theme() -> template . "/footer.php");
|
||||
$footer = file_get_contents(get_theme_root() . "/" . wp_get_theme()->template . "/footer.php");
|
||||
if ((strpos($footer, "github.com/solstice23/argon-theme") === false) && (strpos($footer, "solstice23.top") === false)){
|
||||
add_action('admin_notices', 'alert_footer_copyright_changed');
|
||||
}
|
||||
@@ -3371,8 +3370,8 @@ add_action('wp_ajax_update_post_meta_ajax' , 'update_post_meta_ajax');
|
||||
add_action('wp_ajax_nopriv_update_post_meta_ajax' , 'update_post_meta_ajax');
|
||||
//首页显示说说
|
||||
function argon_home_add_post_type_shuoshuo($query){
|
||||
if (is_home() && $query -> is_main_query()){
|
||||
$query -> set('post_type', array('post', 'shuoshuo'));
|
||||
if (is_home() && $query->is_main_query()){
|
||||
$query->set('post_type', array('post', 'shuoshuo'));
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
@@ -3381,11 +3380,11 @@ if (get_option("argon_home_show_shuoshuo") == "true"){
|
||||
}
|
||||
//首页隐藏特定分类文章
|
||||
function argon_home_hide_categories($query){
|
||||
if (is_home() && $query -> is_main_query()){
|
||||
if (is_home() && $query->is_main_query()){
|
||||
$excludeCategories = explode(",", get_option("argon_hide_categories"));
|
||||
$excludeCategories = array_map(function($cat) { return -$cat; }, $excludeCategories);
|
||||
$query -> set('category__not_in', $excludeCategories);
|
||||
$query -> set('tag__not_in', $excludeCategories);
|
||||
$query->set('category__not_in', $excludeCategories);
|
||||
$query->set('tag__not_in', $excludeCategories);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
@@ -3395,7 +3394,7 @@ if (get_option("argon_hide_categories") != ""){
|
||||
//文章过时信息显示
|
||||
function argon_get_post_outdated_info(){
|
||||
global $post;
|
||||
$post_show_outdated_info_status = strval(get_post_meta($post -> ID, 'argon_show_post_outdated_info', true));
|
||||
$post_show_outdated_info_status = strval(get_post_meta($post->ID, 'argon_show_post_outdated_info', true));
|
||||
if (get_option("argon_outdated_info_tip_type") == "toast"){
|
||||
$before = "<div id='post_outdate_toast' style='display:none;' data-text='";
|
||||
$after = "'></div>";
|
||||
@@ -3731,25 +3730,25 @@ function shortcode_friend_link($attr,$content=""){
|
||||
foreach ($friendlinks as $friendlink){
|
||||
$out .= "
|
||||
<div class='link mb-2 col-lg-6 col-md-6'>
|
||||
<div class='card shadow-sm friend-link-container" . ($friendlink -> link_image == "" ? " no-avatar" : "") . "'>";
|
||||
if ($friendlink -> link_image != ''){
|
||||
<div class='card shadow-sm friend-link-container" . ($friendlink->link_image == "" ? " no-avatar" : "") . "'>";
|
||||
if ($friendlink->link_image != ''){
|
||||
$out .= "
|
||||
<img src='" . $friendlink -> link_image . "' class='friend-link-avatar bg-gradient-secondary'>";
|
||||
<img src='" . $friendlink->link_image . "' class='friend-link-avatar bg-gradient-secondary'>";
|
||||
}
|
||||
$out .= " <div class='friend-link-content'>
|
||||
<div class='friend-link-title title text-primary'>
|
||||
<a target='_blank' href='" . esc_url($friendlink -> link_url) . "'>" . esc_html($friendlink -> link_name) . "</a>
|
||||
<a target='_blank' href='" . esc_url($friendlink->link_url) . "'>" . esc_html($friendlink->link_name) . "</a>
|
||||
</div>
|
||||
<div class='friend-link-description'>" . esc_html($friendlink -> link_description) . "</div>";
|
||||
<div class='friend-link-description'>" . esc_html($friendlink->link_description) . "</div>";
|
||||
$out .= " <div class='friend-link-links'>";
|
||||
foreach (explode("\n", $friendlink -> link_notes) as $line){
|
||||
foreach (explode("\n", $friendlink->link_notes) as $line){
|
||||
$item = explode("|", trim($line));
|
||||
if(stripos($item[0], "fa-") !== 0){
|
||||
continue;
|
||||
}
|
||||
$out .= "<a href='" . esc_url($item[1]) . "' target='_blank'><i class='fa " . sanitize_html_class($item[0]) . "'></i></a>";
|
||||
}
|
||||
$out .= "<a href='" . esc_url($friendlink -> link_url) . "' target='_blank' style='float:right; margin-right: 10px;'><i class='fa fa-angle-right' style='font-weight: bold;'></i></a>";
|
||||
$out .= "<a href='" . esc_url($friendlink->link_url) . "' target='_blank' style='float:right; margin-right: 10px;'><i class='fa fa-angle-right' style='font-weight: bold;'></i></a>";
|
||||
$out .= "
|
||||
</div>
|
||||
</div>
|
||||
@@ -3929,12 +3928,12 @@ function shortcode_github($attr,$content=""){
|
||||
throw new Exception("");
|
||||
}
|
||||
$json = json_decode($json);
|
||||
$description = esc_html($json -> description);
|
||||
if (!empty($json -> homepage)){
|
||||
$description .= esc_html(" <a href='" . $json -> homepage . "' target='_blank' no-pjax>" . $json -> homepage . "</a>");
|
||||
$description = esc_html($json->description);
|
||||
if (!empty($json->homepage)){
|
||||
$description .= esc_html(" <a href='" . $json->homepage . "' target='_blank' no-pjax>" . $json->homepage . "</a>");
|
||||
}
|
||||
$stars = $json -> stargazers_count;
|
||||
$forks = $json -> forks_count;
|
||||
$stars = $json->stargazers_count;
|
||||
$forks = $json->forks_count;
|
||||
}catch (Exception $e){
|
||||
$getdata = "frontend";
|
||||
}
|
||||
@@ -4236,13 +4235,13 @@ function argon_get_search_post_type_array(){
|
||||
return $arr;
|
||||
}
|
||||
function search_filter($query) {
|
||||
if (!$query -> is_search || is_admin()) {
|
||||
if (!$query->is_search || is_admin()) {
|
||||
return $query;
|
||||
}
|
||||
if (get_option('argon_enable_search_filters', 'true') == 'false'){
|
||||
return $query;
|
||||
}
|
||||
$query -> set('post_type', argon_get_search_post_type_array());
|
||||
$query->set('post_type', argon_get_search_post_type_array());
|
||||
return $query;
|
||||
}
|
||||
add_filter('pre_get_posts', 'search_filter');
|
||||
@@ -4288,7 +4287,6 @@ function argon_enqueue_qrcode_script() {
|
||||
}
|
||||
add_action('wp_enqueue_scripts', 'argon_enqueue_qrcode_script');
|
||||
|
||||
|
||||
// 获取 Git 版本信息
|
||||
function argon_get_git_info() {
|
||||
$theme_dir = get_template_directory();
|
||||
@@ -4353,7 +4351,6 @@ function argon_get_git_info() {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ========== TODO 列表功能 ==========
|
||||
|
||||
// 获取 TODO 列表
|
||||
|
||||
Reference in New Issue
Block a user