" . __("Argon 主题不支持 Wordpress 4.4 以下版本,请更新 Wordpress", 'argon') . ""; } function theme_slug_setup() { add_theme_support('title-tag'); add_theme_support('post-thumbnails'); load_theme_textdomain('argon', get_template_directory() . '/languages'); } 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; $GLOBALS['theme_version'] = $argon_version; // 强制使用本地资源,避免 CDN 加载问题 $GLOBALS['assets_path'] = get_bloginfo('template_url'); //翻译 Hook function argon_locate_filter($locate){ if (substr($locate, 0, 2) == 'zh'){ if ($locate == 'zh_TW'){ return $locate; } return 'zh_CN'; } if (substr($locate, 0, 2) == 'en'){ return 'en_US'; } if (substr($locate, 0, 2) == 'ru'){ return 'ru_RU'; } return 'en_US'; } function argon_get_locate(){ if (function_exists("determine_locale")){ return argon_locate_filter(determine_locale()); } $determined_locale = get_locale(); if (is_admin()){ $determined_locale = get_user_locale(); } } function theme_locale_hook($locate, $domain){ if ($domain == 'argon'){ return argon_locate_filter($locate); } return $locate; } add_filter('theme_locale', 'theme_locale_hook', 10, 2); //更新主题版本后的兼容 $argon_last_version = get_option("argon_last_version"); if ($argon_last_version == ""){ $argon_last_version = "0.0"; } if (version_compare($argon_last_version, $GLOBALS['theme_version'], '<' )){ if (version_compare($argon_last_version, '0.940', '<')){ if (get_option('argon_mathjax_v2_enable') == 'true' && get_option('argon_mathjax_enable') != 'true'){ update_option("argon_math_render", 'mathjax2'); } if (get_option('argon_mathjax_enable') == 'true'){ update_option("argon_math_render", 'mathjax3'); } } if (version_compare($argon_last_version, '0.970', '<')){ if (get_option('argon_show_author') == 'true'){ update_option("argon_article_meta", 'time|views|comments|categories|author'); } } if (version_compare($argon_last_version, '1.1.0', '<')){ if (get_option('argon_enable_zoomify') != 'false'){ update_option("argon_enable_fancybox", 'true'); update_option("argon_enable_zoomify", 'false'); } } if (version_compare($argon_last_version, '1.3.4', '<')){ switch (get_option('argon_search_post_filter', 'post,page')){ case 'post,page': update_option("argon_enable_search_filters", 'true'); update_option("argon_search_filters_type", '*post,*page,shuoshuo'); break; case 'post,page,shuoshuo': update_option("argon_enable_search_filters", 'true'); update_option("argon_search_filters_type", '*post,*page,*shuoshuo'); break; case 'post,page,hide_shuoshuo': update_option("argon_enable_search_filters", 'true'); update_option("argon_search_filters_type", '*post,*page'); break; case 'off': default: update_option("argon_enable_search_filters", 'false'); break; } } 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'); require_once(get_template_directory() . '/email-templates/reply-notify.php'); //检测更新 require_once(get_template_directory() . '/theme-update-checker/plugin-update-checker.php'); $argon_update_source = get_option('argon_update_source'); switch ($argon_update_source) { case "stop": break; case "fastgit": $argonThemeUpdateChecker = Puc_v4_Factory::buildUpdateChecker( 'https://api.solstice23.top/argon/info.json?source=fastgit', get_template_directory() . '/functions.php', 'argon' ); break; case "cfworker": $argonThemeUpdateChecker = Puc_v4_Factory::buildUpdateChecker( 'https://api.solstice23.top/argon/info.json?source=cfworker', get_template_directory() . '/functions.php', 'argon' ); break; case "solstice23top": $argonThemeUpdateChecker = Puc_v4_Factory::buildUpdateChecker( 'https://api.solstice23.top/argon/info.json?source=0', get_template_directory() . '/functions.php', 'argon' ); break; case "github": default: $argonThemeUpdateChecker = Puc_v4_Factory::buildUpdateChecker( 'https://raw.githubusercontent.com/solstice23/argon-theme/master/info.json', get_template_directory() . '/functions.php', 'argon' ); } //初次使用时发送安装量统计信息 (数据仅用于统计安装量) function post_analytics_info(){ if(function_exists('file_get_contents')){ $contexts = stream_context_create( array( 'http' => array( 'method'=>"GET", 'header'=>"User-Agent: ArgonTheme\r\n" ) ) ); $result = file_get_contents('http://api.solstice23.top/argon_analytics/index.php?domain=' . urlencode($_SERVER['HTTP_HOST']) . '&version='. urlencode($GLOBALS['theme_version']), false, $contexts); update_option('argon_has_inited', 'true'); return $result; }else{ update_option('argon_has_inited', 'true'); } } if (get_option('argon_has_inited') != 'true'){ post_analytics_info(); } //时区修正 if (get_option('argon_enable_timezone_fix') == 'true'){ date_default_timezone_set('UTC'); } //注册小工具 function argon_widgets_init() { register_sidebar( array( 'name' => __('左侧栏小工具', 'argon'), 'id' => 'leftbar-tools', 'description' => __( '左侧栏小工具 (如果设置会在侧栏增加一个 Tab)', 'argon'), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '
', 'after_title' => '
', ) ); register_sidebar( array( 'name' => __('右侧栏小工具', 'argon'), 'id' => 'rightbar-tools', 'description' => __( '右侧栏小工具 (在 "Argon 主题选项" 中选择 "三栏布局" 才会显示)', 'argon'), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '
', 'after_title' => '
', ) ); register_sidebar( array( 'name' => __('站点概览额外内容', 'argon'), 'id' => 'leftbar-siteinfo-extra-tools', 'description' => __( '站点概览额外内容', 'argon'), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '
', 'after_title' => '
', ) ); } add_action('widgets_init', 'argon_widgets_init'); //注册新后台主题配色方案 function argon_add_admin_color(){ wp_admin_css_color( 'argon', 'Argon', get_bloginfo('template_directory') . "/admin.css", array("#5e72e4", "#324cdc", "#e8ebfb"), array('base' => '#525f7f', 'focus' => '#5e72e4', 'current' => '#fff') ); } add_action('admin_init', 'argon_add_admin_color'); function argon_admin_themecolor_css(){ $themecolor = get_option("argon_theme_color", "#5e72e4"); $RGB = hexstr2rgb($themecolor); $HSL = rgb2hsl($RGB['R'], $RGB['G'], $RGB['B']); echo " "; if (get_option("argon_enable_immersion_color", "false") == "true"){ echo ""; } } add_filter('admin_head', 'argon_admin_themecolor_css'); function array_remove(&$arr, $item){ $pos = array_search($item, $arr); if ($pos !== false){ array_splice($arr, $pos, 1); } } //数字格式化 function format_number_in_kilos($number) { if ($number < 1000){ return $number; } if (1000 <= $number && $number < 1000000){ if (1000 <= $number && $number < 10000){ return round($number / 1000, 1) . "K"; }else{ return round($number / 1000, 0) . "K"; } } if (1000000 <= $number && $number <= 10000000){ return round($number / 1000000, 1) . "M"; }else{ return round($number / 1000000, 0) . "M"; } } //表情包 require_once(get_template_directory() . '/emotions.php'); //文章特色图片 function argon_get_first_image_of_article(){ global $post; if (post_password_required()){ return false; } $post_content_full = apply_filters('the_content', preg_replace( '', '', $post -> post_content)); preg_match('//', $post_content_full, $match); if (isset($match[3])){ return $match[3]; } return false; } function argon_has_post_thumbnail($postID = 0){ if ($postID == 0){ global $post; $postID = $post -> ID; } if (has_post_thumbnail()){ return true; } $argon_first_image_as_thumbnail = get_post_meta($postID, 'argon_first_image_as_thumbnail', true); if ($argon_first_image_as_thumbnail == ""){ $argon_first_image_as_thumbnail = "default"; } if ($argon_first_image_as_thumbnail == "true" || ($argon_first_image_as_thumbnail == "default" && get_option("argon_first_image_as_thumbnail_by_default", "false") == "true")){ if (argon_get_first_image_of_article() != false){ return true; } } return false; } function argon_get_post_thumbnail($postID = 0){ if ($postID == 0){ global $post; $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]); } return apply_filters("argon_post_thumbnail", argon_get_first_image_of_article()); } //文末附加内容 function get_additional_content_after_post(){ global $post; $postID = $post -> ID; $res = get_post_meta($post -> ID, 'argon_after_post', true); if ($res == "--none--"){ return ""; } if ($res == ""){ $res = get_option("argon_additional_content_after_post"); } $res = str_replace("\n", "
", $res); $res = str_replace("%url%", get_permalink($postID), $res); $res = str_replace("%link%", '' . get_permalink($postID) . '', $res); $res = str_replace("%title%", get_the_title(), $res); $res = str_replace("%author%", get_the_author(), $res); return $res; } //输出分页页码 function get_argon_formatted_paginate_links($maxPageNumbers, $extraClasses = ''){ $args = array( 'prev_text' => '', 'next_text' => '', 'before_page_number' => '', 'after_page_number' => '', 'show_all' => True ); $res = paginate_links($args); //单引号转双引号 & 去除上一页和下一页按钮 $res = preg_replace( '/\'/', '"', $res ); $res = preg_replace( '/
  • '; } if ($current > 1){ $html .= '
  • '; } for ($i = $from; $i <= $to; $i++){ if ($current == $i){ $html .= '
  • ' . $i . '
  • '; }else{ $html .= '
  • ' . $i . '
  • '; } } if ($current < $total){ $html .= '
  • '; } if ($to < $total){ $html .= '
  • '; } return ''; } function get_argon_formatted_paginate_links_for_all_platforms(){ return get_argon_formatted_paginate_links(7) . get_argon_formatted_paginate_links(5, " pagination-mobile"); } //访问者 Token & Session function get_random_token(){ return md5(uniqid(microtime(true), true)); } function set_user_token_cookie(){ if (!isset($_COOKIE["argon_user_token"]) || strlen($_COOKIE["argon_user_token"]) != 32){ $newToken = get_random_token(); setcookie("argon_user_token", $newToken, array( 'expires' => time() + 10 * 365 * 24 * 60 * 60, 'path' => '/', 'secure' => is_ssl(), 'httponly' => true, 'samesite' => 'Lax' )); $_COOKIE["argon_user_token"] = $newToken; } } function session_init(){ set_user_token_cookie(); if (!session_id()){ if (function_exists('session_set_cookie_params')){ session_set_cookie_params(array( 'lifetime' => 0, 'path' => '/', 'secure' => is_ssl(), 'httponly' => true, 'samesite' => 'Lax' )); } session_start(); } } session_init(); //add_action('init', 'session_init'); //页面 Description Meta function get_seo_description(){ global $post; if (is_single() || is_page()){ if (get_the_excerpt() != ""){ return preg_replace('/ \[…]$/', '…', get_the_excerpt()); } if (!post_password_required()){ return htmlspecialchars(mb_substr(str_replace("\n", '', strip_tags($post -> post_content)), 0, 50)) . "..."; }else{ return __("这是一个加密页面,需要密码来查看", 'argon'); } }else{ return get_option('argon_seo_description'); } } //页面 Keywords function get_seo_keywords(){ if (is_single()){ global $post; $tags = get_the_tags('', ',', '', $post -> ID); if ($tags != null){ $res = ""; foreach ($tags as $tag){ if ($res != ""){ $res .= ","; } $res .= $tag -> name; } return $res; } } if (is_category()){ return single_cat_title('', false); } if (is_tag()){ return single_tag_title('', false); } if (is_author()){ return get_the_author(); } if (is_post_type_archive()){ return post_type_archive_title('', false); } if (is_tax()){ return single_term_title('', false); } return get_option('argon_seo_keywords'); } //页面分享预览图 function get_og_image(){ global $post; $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); } return ''; } //页面浏览量 function get_post_views($post_id){ $count_key = 'views'; $count = get_post_meta($post_id, $count_key, true); if ($count==''){ delete_post_meta($post_id, $count_key); add_post_meta($post_id, $count_key, '0'); $count = '0'; } return number_format_i18n($count); } function set_post_views(){ if (!is_single() && !is_page()) { return; } if (!isset($post_id)){ global $post; $post_id = $post -> ID; } if (post_password_required($post_id)){ return; } if (isset($_GET['preview'])){ if ($_GET['preview'] == 'true'){ if (current_user_can('publish_posts')){ return; } } } $noPostView = 'false'; if (isset($_POST['no_post_view'])){ $noPostView = $_POST['no_post_view']; } if ($noPostView == 'true'){ return; } global $post; if (!isset($post -> ID)){ return; } $post_id = $post -> ID; $count_key = 'views'; $count = get_post_meta($post_id, $count_key, true); if (is_single() || is_page()) { if ($count==''){ delete_post_meta($post_id, $count_key); add_post_meta($post_id, $count_key, '0'); } else { update_post_meta($post_id, $count_key, $count + 1); } } } add_action('get_header', 'set_post_views'); //字数和预计阅读时间 function get_article_words($str){ preg_match_all('/[\S\s]*?([\S\s]*?)<\/code>[\S\s]*?<\/pre>/im', $str, $codeSegments, PREG_PATTERN_ORDER); $codeSegments = $codeSegments[3]; $codeTotal = 0; foreach ($codeSegments as $codeSegment){ $codeLines = preg_split('/\r\n|\n|\r/', $codeSegment); foreach ($codeLines as $line){ if (strlen(trim($str)) > 0){ $codeTotal++; } } } $str = preg_replace( '/[\S\s]*?<\/code>/im', '', $str ); $str = preg_replace( '/[\S\s]*?<\/pre>/im', '', $str ); $str = preg_replace( '/[\S\s]*?<\/style>/im', '', $str ); $str = preg_replace( '/[\S\s]*?<\/script>/im', '', $str ); $str = preg_replace('/<[^>]+?>/', ' ', $str); $str = html_entity_decode(strip_tags($str)); preg_match_all('/[\x{4e00}-\x{9fa5}]/u' , $str , $cnRes); $cnTotal = count($cnRes[0]); $enRes = preg_replace('/[\x{4e00}-\x{9fa5}]/u', '', $str); preg_match_all('/[a-zA-Z0-9_\x{0392}-\x{03c9}\x{0400}-\x{04FF}]+|[\x{4E00}-\x{9FFF}\x{3400}-\x{4dbf}\x{f900}-\x{faff}\x{3040}-\x{309f}\x{ac00}-\x{d7af}\x{0400}-\x{04FF}]+|[\x{00E4}\x{00C4}\x{00E5}\x{00C5}\x{00F6}\x{00D6}]+|\w+/u' , $str , $enRes); $enTotal = count($enRes[0]); return array( 'cn' => $cnTotal, 'en' => $enTotal, 'code' => $codeTotal, ); } function get_article_words_total($str){ $res = get_article_words($str); return $res['cn'] + $res['en'] + $res['code']; } function get_reading_time($len){ $speedcn = get_option('argon_reading_speed', 300); $speeden = get_option('argon_reading_speed_en', 160); $speedcode = get_option('argon_reading_speed_code', 20); $reading_time = $len['cn'] / $speedcn + $len['en'] / $speeden + $len['code'] / $speedcode; if ($reading_time < 0.3){ return __("几秒读完", 'argon'); } if ($reading_time < 1){ return __("1 分钟内", 'argon'); } if ($reading_time < 60){ return ceil($reading_time) . " " . __("分钟", 'argon'); } return round($reading_time / 60 , 1) . " " . __("小时", 'argon'); } //当前文章是否可以生成目录 function have_catalog(){ if (!is_single() && !is_page()){ return false; } if (post_password_required()){ return false; } if (is_page() && is_page_template('timeline.php')){ return true; } $content = get_post(get_the_ID()) -> post_content; if (preg_match('//',$content)){ return true; }else{ return false; } } //获取文章 Meta function get_article_meta($type){ if ($type == 'sticky'){ return ''; } if ($type == 'needpassword'){ return ''; } if ($type == 'time'){ return ''; } if ($type == 'edittime'){ return ''; } if ($type == 'views'){ if (function_exists('pvc_get_post_views')){ $views = pvc_get_post_views(get_the_ID()); }else{ $views = get_post_views(get_the_ID()); } return ''; } if ($type == 'comments'){ return ''; } if ($type == 'categories'){ $res = ''; return $res; } if ($type == 'author'){ $res = ''; return $res; } } //获取文章字数统计和预计阅读时间 function get_article_reading_time_meta($post_content_full){ $post_content_full = apply_filters("argon_html_before_wordcount", $post_content_full); $words = get_article_words($post_content_full); $res = '
    '; return $res; } //当前文章是否隐藏 阅读时间 Meta function is_readingtime_meta_hidden(){ if (strpos(get_the_content() , "[hide_reading_time][/hide_reading_time]") !== False){ return true; } global $post; if (get_post_meta($post -> ID, 'argon_hide_readingtime', true) == 'true'){ return true; } return false; } //当前文章是否隐藏 发布时间和分类 (简洁 Meta) function is_meta_simple(){ global $post; 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; } //解析 UA 和相应图标 require_once(get_template_directory() . '/useragent-parser.php'); $argon_comment_ua = get_option("argon_comment_ua"); $argon_comment_show_ua = Array(); if (strpos($argon_comment_ua, 'platform') !== false){ $argon_comment_show_ua['platform'] = true; } if (strpos($argon_comment_ua, 'browser') !== false){ $argon_comment_show_ua['browser'] = true; } if (strpos($argon_comment_ua, 'version') !== false){ $argon_comment_show_ua['version'] = true; } function parse_ua_and_icon($userAgent){ global $argon_comment_ua; global $argon_comment_show_ua; if ($argon_comment_ua == "" || $argon_comment_ua == "hidden"){ return ""; } $parsed = argon_parse_user_agent($userAgent); $out = "
    "; if (isset($argon_comment_show_ua['platform']) && $argon_comment_show_ua['platform'] == true){ if (isset($GLOBALS['UA_ICON'][$parsed['platform']])){ $out .= $GLOBALS['UA_ICON'][$parsed['platform']] . " "; }else{ $out .= $GLOBALS['UA_ICON']['Unknown'] . " "; } $out .= $parsed['platform']; } if (isset($argon_comment_show_ua['browser']) && $argon_comment_show_ua['browser'] == true){ if (isset($GLOBALS['UA_ICON'][$parsed['browser']])){ $out .= " " . $GLOBALS['UA_ICON'][$parsed['browser']]; }else{ $out .= " " . $GLOBALS['UA_ICON']['Unknown']; } $out .= " " . $parsed['browser']; if (isset($argon_comment_show_ua['version']) && $argon_comment_show_ua['version'] == true){ $out .= " " . $parsed['version']; } } $out .= "
    "; return apply_filters("argon_comment_ua_icon", $out); } //发送邮件 function send_mail($to, $subject, $content){ wp_mail($to, $subject, $content, array('Content-Type: text/html; charset=UTF-8')); } function check_email_address($email){ return (bool) preg_match( "/^\w+((-\w+)|(\.\w+))*@[A-Za-z0-9]+(([.\-])[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/", $email ); } //检验评论 Token 和用户 Token 是否一致 function check_comment_token($id){ if (strlen($_COOKIE['argon_user_token']) != 32){ return false; } if ($_COOKIE['argon_user_token'] != get_comment_meta($id, "user_token", true)){ return false; } return true; } //检验评论发送者 ID 和当前登录用户 ID 是否一致 function check_login_user_same($userid){ if ($userid == 0){ return false; } 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; } function check_comment_userid($id){ if (!check_login_user_same(get_comment_user_id_by_id($id))){ return false; } return true; } //悄悄话 function is_comment_private_mode($id){ if (strlen(get_comment_meta($id, "private_mode", true)) != 32){ return false; } return true; } function user_can_view_comment($id){ if (!is_comment_private_mode($id)){ return true; } if (current_user_can("manage_options")){ return true; } if ($_COOKIE['argon_user_token'] == get_comment_meta($id, "private_mode", true)){ return true; } return false; } //过滤 RSS 中悄悄话 function remove_rss_private_comment_title_and_author($str){ global $comment; if (isset($comment -> comment_ID) && is_comment_private_mode($comment -> comment_ID)){ return "***"; } return $str; } 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; } return $str; } add_filter('comment_text_rss' , 'remove_rss_private_comment_content'); //评论回复信息 function get_comment_parent_info($comment){ if (!$GLOBALS['argon_comment_options']['show_comment_parent_info']){ return ""; } if ($comment -> comment_parent == 0){ return ""; } $parent_comment = get_comment($comment -> comment_parent); return '
    ' . get_comment_author($parent_comment -> comment_ID) . '
    '; } //是否可以查看评论编辑记录 function can_visit_comment_edit_history($id){ $who_can_visit_comment_edit_history = get_option("argon_who_can_visit_comment_edit_history"); if ($who_can_visit_comment_edit_history == ""){ $who_can_visit_comment_edit_history = "admin"; } switch ($who_can_visit_comment_edit_history) { case 'everyone': return true; case 'commentsender': if (check_comment_token($id) || check_comment_userid($id)){ return true; } return false; default: if (current_user_can("moderate_comments")){ return true; } return false; } } //获取评论编辑记录 function get_comment_edit_history(){ $id = $_POST['id']; if (!can_visit_comment_edit_history($id)){ exit(json_encode(array( 'id' => $_POST['id'], 'history' => "" ))); } $editHistory = json_decode(get_comment_meta($id, "comment_edit_history", true)); $editHistory = array_reverse($editHistory); $res = ""; $position = count($editHistory) + 1; date_default_timezone_set(get_option('timezone_string')); foreach ($editHistory as $edition){ $position -= 1; $res .= "
    #" . $position . "
    " . ($edition -> isfirst ? "" . __("最初版本", 'argon') . "" : "") . "
    " . date('Y-m-d H:i:s', $edition -> time) . "
    " . str_replace("\n", "
    ", $edition -> content) . "
    "; } exit(json_encode(array( 'id' => $_POST['id'], 'history' => $res ))); } 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"){ return false; } if (get_comment($id) -> comment_parent != 0){ return false; } if (is_comment_private_mode($id)){ return false; } return true; } //评论内容格式化 function argon_get_comment_text($comment_ID = 0, $args = array()) { $comment = get_comment($comment_ID); $comment_text = get_comment_text($comment, $args); $enableMarkdown = get_comment_meta(get_comment_ID(), "use_markdown", true); /*if ($enableMarkdown == false){ return $comment_text; }*/ //图片 $comment_text = preg_replace( '/([\w\W]*)<\/a>/', '$2', $comment_text ); $comment_text = preg_replace( '/(.*?)/', ' ' . __('查看图片', 'argon') . ' $2 ', $comment_text ); //表情 if (get_option("argon_comment_emotion_keyboard", "true") != "false"){ global $emotionListDefault; $emotionList = apply_filters("argon_emotion_list", $emotionListDefault); foreach ($emotionList as $groupIndex => $group){ foreach ($group['list'] as $index => $emotion){ if ($emotion['type'] != 'sticker'){ continue; } if (!isset($emotion['code']) || mb_strlen($emotion['code']) == 0){ continue; } if (!isset($emotion['src']) || mb_strlen($emotion['src']) == 0){ continue; } $comment_text = str_replace(':' . $emotion['code'] . ':', "", $comment_text); } } } return apply_filters( 'comment_text', $comment_text, $comment, $args ); } //评论点赞 function get_comment_upvotes($id) { $comment = get_comment($id); if ($comment == null){ return 0; } $upvotes = get_comment_meta($comment -> comment_ID, "upvotes", true); if ($upvotes == null) { $upvotes = 0; } return $upvotes; } function set_comment_upvotes($id){ $comment = get_comment($id); if ($comment == null){ return 0; } $upvotes = get_comment_meta($comment -> comment_ID, "upvotes", true); if ($upvotes == null) { $upvotes = 0; } $upvotes++; update_comment_meta($comment -> comment_ID, "upvotes", $upvotes); return $upvotes; } function is_comment_upvoted($id){ $upvotedList = isset( $_COOKIE['argon_comment_upvoted'] ) ? $_COOKIE['argon_comment_upvoted'] : ''; if (in_array($id, explode(',', $upvotedList))){ return true; } return false; } function upvote_comment(){ if (get_option("argon_enable_comment_upvote", "false") != "true"){ return; } header('Content-Type:application/json; charset=utf-8'); $ID = $_POST["comment_id"]; $comment = get_comment($ID); if ($comment == null){ exit(json_encode(array( 'status' => 'failed', 'msg' => __('评论不存在', 'argon'), 'total_upvote' => 0 ))); } $upvotedList = isset( $_COOKIE['argon_comment_upvoted'] ) ? $_COOKIE['argon_comment_upvoted'] : ''; if (in_array($ID, explode(',', $upvotedList))){ exit(json_encode(array( 'status' => 'failed', 'msg' => __('该评论已被赞过', 'argon'), 'total_upvote' => get_comment_upvotes($ID) ))); } set_comment_upvotes($ID); setcookie('argon_comment_upvoted', $upvotedList . $ID . "," , array( 'expires' => time() + 3153600000, 'path' => '/', 'secure' => is_ssl(), 'httponly' => true, 'samesite' => 'Lax' )); exit(json_encode(array( 'ID' => $ID, 'status' => 'success', 'msg' => __('点赞成功', 'argon'), 'total_upvote' => format_number_in_kilos(get_comment_upvotes($ID)) ))); } add_action('wp_ajax_upvote_comment' , 'upvote_comment'); add_action('wp_ajax_nopriv_upvote_comment' , 'upvote_comment'); //评论样式格式化 $GLOBALS['argon_comment_options']['enable_upvote'] = (get_option("argon_enable_comment_upvote", "false") == "true"); $GLOBALS['argon_comment_options']['enable_pinning'] = (get_option("argon_enable_comment_pinning", "false") == "true"); $GLOBALS['argon_comment_options']['current_user_can_moderate_comments'] = current_user_can('moderate_comments'); $GLOBALS['argon_comment_options']['show_comment_parent_info'] = (get_option("argon_show_comment_parent_info", "true") == "true"); 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())){ ?>
  • ">
    user_id , "update_core")){ echo '' . __('博主', 'argon') . '';} ?> ' . _x('置顶', 'pinned', 'argon') . ''; }?> ' . __('悄悄话', 'argon') . '';} ?> comment_approved == 0){ echo '' . __('待审核', 'argon') . '';} ?> comment_agent); ?>
    user_id)) && (get_option("argon_comment_allow_editing") != "false")) { ?>
  • user_id , "update_core") ){ echo '' . __('博主', 'argon') . '';} ?> comment_approved == 0 ){ echo '' . __('待审核', 'argon') . '';} ?> :
  • captchaSeed = $seed; } function getChallenge(){ mt_srand($this -> captchaSeed + 10007); $oper = mt_rand(1 , 4); $num1 = 0; $num2 = 0; switch ($oper){ case 1: $num1 = mt_rand(1 , 20); $num2 = mt_rand(0 , 20 - $num1); return $num1 . " + " . $num2 . " = "; break; case 2: $num1 = mt_rand(10 , 20); $num2 = mt_rand(1 , $num1); return $num1 . " - " . $num2 . " = "; break; case 3: $num1 = mt_rand(3 , 9); $num2 = mt_rand(3 , 9); return $num1 . " * " . $num2 . " = "; break; case 4: $num2 = mt_rand(2 , 9); $num1 = $num2 * mt_rand(2 , 9); return $num1 . " / " . $num2 . " = "; break; default: break; } } function getAnswer(){ mt_srand($this -> captchaSeed + 10007); $oper = mt_rand(1 , 4); $num1 = 0; $num2 = 0; switch ($oper){ case 1: $num1 = mt_rand(1 , 20); $num2 = mt_rand(0 , 20 - $num1); return $num1 + $num2; break; case 2: $num1 = mt_rand(10 , 20); $num2 = mt_rand(1 , $num1); return $num1 - $num2; break; case 3: $num1 = mt_rand(3 , 9); $num2 = mt_rand(3 , 9); return $num1 * $num2; break; case 4: $num2 = mt_rand(2 , 9); $num1 = $num2 * mt_rand(2 , 9); return $num1 / $num2; break; default: break; } return ""; } function check($answer){ if ($answer == self::getAnswer()){ return true; } return false; } } function wrong_captcha($msg = null){ $message = $msg ? $msg : __('验证码错误', 'argon'); exit(json_encode(array( 'status' => 'failed', 'msg' => $message, 'isAdmin' => current_user_can('level_7') ))); //wp_die('验证码错误,评论失败'); } function get_comment_captcha(){ $captcha = new captcha_calculation(get_comment_captcha_seed()); return $captcha -> getChallenge(); } function get_comment_captcha_answer(){ $captcha = new captcha_calculation(get_comment_captcha_seed()); return $captcha -> getAnswer(); } // Geetest 验证码相关函数 function geetest_validate($lot_number, $captcha_output, $pass_token, $gen_time) { $captcha_id = get_option('argon_geetest_captcha_id', ''); $captcha_key = get_option('argon_geetest_captcha_key', ''); $api_server = get_option('argon_geetest_api_server', ''); // 如果 api_server 为空,使用默认值 if (empty($api_server)) { $api_server = 'https://gcaptcha4.geetest.com'; } if (empty($captcha_id) || empty($captcha_key)) { return false; } // 验证必需参数 if (empty($lot_number) || empty($captcha_output) || empty($pass_token) || empty($gen_time)) { return false; } // 生成签名 - 使用lot_number的字节进行HMAC-SHA256签名 $sign_token = hash_hmac('sha256', $lot_number, $captcha_key); // 构建请求参数 $query = array( "lot_number" => $lot_number, "captcha_output" => $captcha_output, "pass_token" => $pass_token, "gen_time" => $gen_time, "sign_token" => $sign_token ); // 构建完整的URL,包含captcha_id参数 $url = sprintf("%s/validate?captcha_id=%s", rtrim($api_server, '/'), $captcha_id); global $argon_geetest_last_reason; $argon_geetest_last_reason = ''; $response = geetest_post_request($url, $query); if ($response === false) { // geetest_post_request 已经设置了具体原因 if (empty($argon_geetest_last_reason)) { $argon_geetest_last_reason = 'http_request_failed'; } return false; } $result = json_decode($response, true); // 检查JSON解析是否成功 if (json_last_error() !== JSON_ERROR_NONE) { $argon_geetest_last_reason = 'json_decode_error: ' . json_last_error_msg(); return false; } // 根据官方文档,检查返回结果(GT4 返回 result 与 reason) if (isset($result['result'])) { if ($result['result'] === 'success') { return true; } // 失败时记录原因,便于排查 $argon_geetest_last_reason = isset($result['reason']) ? $result['reason'] : 'unknown'; return false; } // 非预期返回结构 $argon_geetest_last_reason = 'unexpected_response: ' . substr($response, 0, 200); return false; } function geetest_post_request($url, $postdata) { global $argon_geetest_last_reason; // 验证 URL 格式 if (empty($url) || !filter_var($url, FILTER_VALIDATE_URL)) { $argon_geetest_last_reason = 'invalid_url: ' . $url; return false; } // 使用 WordPress HTTP API,更可靠 $response = wp_remote_post($url, array( 'timeout' => 15, 'body' => $postdata, 'headers' => array( 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'WordPress/Argon Theme Geetest Client' ), 'sslverify' => true )); if (is_wp_error($response)) { global $argon_geetest_last_reason; $argon_geetest_last_reason = 'wp_error: ' . $response->get_error_message(); return false; } $response_code = wp_remote_retrieve_response_code($response); if ($response_code !== 200) { global $argon_geetest_last_reason; $argon_geetest_last_reason = 'http_' . $response_code; return false; } return wp_remote_retrieve_body($response); } /** * 检查评论验证码是否启用 * @return bool */ function argon_is_comment_captcha_enabled() { $mode = get_option('argon_comment_captcha_mode', 'global'); if ($mode === 'enabled') { return true; } elseif ($mode === 'disabled') { return false; } // global: 使用全局设置 return argon_is_captcha_enabled(); } /** * 检查 TODO 验证码是否启用 * @return bool */ function argon_is_todo_captcha_enabled() { $mode = get_option('argon_todo_captcha_mode', 'global'); if ($mode === 'enabled') { return true; } elseif ($mode === 'disabled') { return false; } // global: 使用全局设置 return argon_is_captcha_enabled(); } /** * 获取全局验证码是否启用(兼容旧选项名) * @return bool */ function argon_is_captcha_enabled() { $enabled = get_option('argon_need_captcha', get_option('argon_comment_need_captcha', 'true')); return $enabled !== 'false'; } /** * 通用验证码验证函数 * @param string $context 验证场景: 'comment', 'todo' 或 'flink' * @return array ['success' => bool, 'error' => string|null] */ function argon_verify_captcha($context = 'comment') { // 根据场景检查是否需要验证码 if ($context === 'todo') { if (!argon_is_todo_captcha_enabled()) { return array('success' => true, 'error' => null); } } elseif ($context === 'flink') { // 友链申请使用评论验证码设置 if (!argon_is_captcha_enabled()) { return array('success' => true, 'error' => null); } } else { if (!argon_is_comment_captcha_enabled()) { return array('success' => true, 'error' => null); } } // 管理员跳过验证码 if (current_user_can('level_7')) { return array('success' => true, 'error' => null); } $captcha_type = get_option('argon_captcha_type', 'math'); if ($captcha_type === 'geetest') { // 极验验证码 - 检查配置 $captcha_id = get_option('argon_geetest_captcha_id', ''); $captcha_key = get_option('argon_geetest_captcha_key', ''); if (empty($captcha_id) || empty($captcha_key)) { return array('success' => false, 'error' => __('服务端验证码配置异常,请稍后再试', 'argon')); } $lot_number = isset($_POST['lot_number']) ? trim($_POST['lot_number']) : ''; $captcha_output = isset($_POST['captcha_output']) ? trim($_POST['captcha_output']) : ''; $pass_token = isset($_POST['pass_token']) ? trim($_POST['pass_token']) : ''; $gen_time = isset($_POST['gen_time']) ? trim($_POST['gen_time']) : ''; if (empty($lot_number) || empty($captcha_output) || empty($pass_token) || empty($gen_time)) { return array('success' => false, 'error' => __('请完成验证码验证', 'argon')); } // 格式验证 if (!preg_match('/^[a-zA-Z0-9\-_]+$/', $lot_number) || strlen($lot_number) > 100) { return array('success' => false, 'error' => __('验证码参数格式错误', 'argon')); } if (!is_numeric($gen_time) || $gen_time <= 0) { return array('success' => false, 'error' => __('验证码时间参数错误', 'argon')); } if (strlen($captcha_output) == 0 || strlen($pass_token) == 0) { return array('success' => false, 'error' => __('验证码参数不完整', 'argon')); } if (strlen($captcha_output) > 1000 || strlen($pass_token) > 1000) { return array('success' => false, 'error' => __('验证码参数过长', 'argon')); } // 时间窗口校验 $gen_ts = intval($gen_time); if ($gen_ts > 9999999999) { $gen_ts = intval($gen_ts / 1000); } $now_ts = time(); if ($gen_ts <= 0 || abs($now_ts - $gen_ts) > 300) { return array('success' => false, 'error' => __('验证码已过期,请刷新后重试', 'argon')); } // 防重放检查 $used_key = 'argon_geetest_used_' . md5($lot_number); if (get_transient($used_key)) { return array('success' => false, 'error' => __('验证码已使用,请刷新后重试', 'argon')); } // 调用极验验证 if (!geetest_validate($lot_number, $captcha_output, $pass_token, $gen_time)) { global $argon_geetest_last_reason; $error_message = __('验证码验证失败', 'argon'); if (!empty($argon_geetest_last_reason)) { $error_message .= ' (' . $argon_geetest_last_reason . ')'; } return array('success' => false, 'error' => $error_message); } // 标记已使用 set_transient($used_key, 1, 15 * MINUTE_IN_SECONDS); } else { // 数学验证码 $answer = isset($_POST['comment_captcha']) ? trim($_POST['comment_captcha']) : ''; if ($answer === '') { return array('success' => false, 'error' => __('请输入验证码', 'argon')); } $seed = get_comment_captcha_seed(); $captcha = new captcha_calculation($seed); if (!$captcha->check($answer)) { return array('success' => false, 'error' => __('验证码错误', 'argon')); } } return array('success' => true, 'error' => null); } function check_comment_captcha($comment){ $result = argon_verify_captcha('comment'); if (!$result['success']) { wrong_captcha($result['error']); } return $comment; } add_filter('preprocess_comment' , 'check_comment_captcha'); function ajax_get_captcha(){ if (get_option('argon_get_captcha_by_ajax', 'false') != 'true') { return; } exit(json_encode(array( 'captcha' => get_comment_captcha(get_comment_captcha_seed()) ))); } add_action('wp_ajax_get_captcha', 'ajax_get_captcha'); add_action('wp_ajax_nopriv_get_captcha', 'ajax_get_captcha'); //Ajax 发送评论 function ajax_post_comment(){ $parentID = $_POST['comment_parent']; if (is_comment_private_mode($parentID)){ if (!user_can_view_comment($parentID)){ //如果父级评论是悄悄话模式且当前 Token 与父级不相同则返回 exit(json_encode(array( 'status' => 'failed', 'msg' => __('不能回复其他人的悄悄话评论', 'argon'), 'isAdmin' => current_user_can('level_7') ))); } } if (get_option('argon_comment_enable_qq_avatar') == 'true'){ if (check_qqnumber($_POST['email'])){ $_POST['qq'] = $_POST['email']; $_POST['email'] .= "@qq.com"; }else{ $_POST['qq'] = ""; } } // CSRF nonce 校验 if (!isset($_POST['argon_nonce']) || !wp_verify_nonce($_POST['argon_nonce'], 'argon_comment')) { exit(json_encode(array( 'status' => 'failed', 'msg' => __('请求已失效,请刷新页面后重试', 'argon'), 'isAdmin' => current_user_can('level_7') ))); } // Honeypot check if (!empty($_POST['argon_comment_honeypot'])) { exit(json_encode(array( 'status' => 'failed', 'msg' => __('Spam detected', 'argon'), 'isAdmin' => current_user_can('level_7') ))); } // 简单速率限制(按 IP 计数,可配置) $rate_enable = get_option('argon_rate_limit_enable', 'true'); if ($rate_enable === 'true') { $ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])[0] : $_SERVER['REMOTE_ADDR']; $ip = sanitize_text_field($ip); $rate_key = 'argon_rate_cmt_' . md5($ip); $state = get_transient($rate_key); $now = time(); $window = intval(get_option('argon_rate_limit_window', 300)); // 窗口秒数 $max_count = intval(get_option('argon_rate_limit_max_count', 5)); // 窗口内最大次数 $min_interval = intval(get_option('argon_rate_limit_min_interval', 10)); // 两次最小间隔 // 合理边界 $window = max(30, $window); $max_count = max(1, $max_count); $min_interval = max(0, $min_interval); if (!is_array($state)) { $state = array('count' => 0, 'start' => $now, 'last' => 0); } if ($state['last'] > 0 && ($now - intval($state['last'])) < $min_interval) { exit(json_encode(array( 'status' => 'failed', 'msg' => __('您评论过快,请稍后再试', 'argon'), 'isAdmin' => current_user_can('level_7') ))); } if (($now - intval($state['start'])) < $window && intval($state['count']) >= $max_count) { exit(json_encode(array( 'status' => 'failed', 'msg' => __('操作过于频繁,请稍后再试', 'argon'), 'isAdmin' => current_user_can('level_7') ))); } // 更新速率状态并设置有效期 if (($now - intval($state['start'])) >= $window) { $state['start'] = $now; $state['count'] = 0; } $state['count'] = intval($state['count']) + 1; $state['last'] = $now; set_transient($rate_key, $state, $window); } $comment = wp_handle_comment_submission(wp_unslash($_POST)); if (is_wp_error($comment)){ $msg = $comment -> get_error_data(); if (!empty($msg)){ $msg = $comment -> get_error_message(); } exit(json_encode(array( 'status' => 'failed', 'msg' => $msg, 'isAdmin' => current_user_can('level_7') ))); } $user = wp_get_current_user(); do_action('set_comment_cookies', $comment, $user); 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"; do_action('set_comment_cookies', $_comment, $user); } } $html = wp_list_comments( array( 'type' => 'comment', 'callback' => 'argon_comment_format', 'echo' => false ), array($comment) ); $newCaptchaSeed = get_comment_captcha_seed(true); $newCaptcha = get_comment_captcha($newCaptchaSeed); if (current_user_can('level_7')){ $newCaptchaAnswer = get_comment_captcha_answer($newCaptchaSeed); }else{ $newCaptchaAnswer = ""; } exit(json_encode(array( 'status' => 'success', 'html' => $html, 'id' => $comment -> comment_ID, 'parentID' => $comment -> comment_parent, 'commentOrder' => (get_option("comment_order") == "" ? "desc" : get_option("comment_order")), 'newCaptchaSeed' => $newCaptchaSeed, 'newCaptcha' => $newCaptcha, 'newCaptchaAnswer' => $newCaptchaAnswer, 'isAdmin' => current_user_can('level_7'), 'isLogin' => is_user_logged_in() ))); } add_action('wp_ajax_ajax_post_comment', 'ajax_post_comment'); add_action('wp_ajax_nopriv_ajax_post_comment', 'ajax_post_comment'); //评论 Markdown 解析 require_once(get_template_directory() . '/parsedown.php'); function comment_markdown_parse($comment_content){ //HTML 过滤 global $allowedtags; //$comment_content = wp_kses($comment_content, $allowedtags); //允许评论中额外的 HTML Tag $allowedtags['pre'] = array('class' => array()); $allowedtags['i'] = array('class' => array(), 'aria-hidden' => array()); $allowedtags['img'] = array('src' => array(), 'alt' => array(), 'class' => array()); $allowedtags['ol'] = array(); $allowedtags['ul'] = array(); $allowedtags['li'] = array(); $allowedtags['span'] = array('class' => array(), 'style' => array(), 'title' => array()); $allowedtags['a']['class'] = array(); $allowedtags['a']['data-src'] = array(); $allowedtags['a']['target'] = array(); $allowedtags['h1'] = $allowedtags['h2'] = $allowedtags['h3'] = $allowedtags['h4'] = $allowedtags['h5'] = $allowedtags['h6'] = array(); //解析 Markdown $parsedown = new _Parsedown(); $res = $parsedown -> text($comment_content); /*$res = preg_replace( '/([\s\S]*?)<\/code>/', '
    $1
    ', $res );*/ $res = preg_replace( '/(.*?)<\/a>/', '$2', $res ); return $res; } function argon_apply_comment_macros($text){ // 黑幕:{{黑幕|内容}} 或 {{黑幕|内容|提示}} $text = preg_replace_callback('/\{\{黑幕\|([\s\S]*?)(?:\|([\s\S]*?))?\}\}/u', function($m){ $content = trim($m[1]); $title = isset($m[2]) ? trim($m[2]) : '你知道的太多了'; return '' . htmlspecialchars($content) . ''; }, $text); // 胡话:{{胡话|内容}} 或 {{胡话|内容|提示}} $text = preg_replace_callback('/\{\{胡话\|([\s\S]*?)\}\}/u', function($m){ $parts = explode('|', $m[1]); $content = isset($parts[0]) ? trim($parts[0]) : ''; $tip = isset($parts[1]) ? trim($parts[1]) : '只为博君一笑,不必照单全收XD'; return '' . htmlspecialchars($content) . ''; }, $text); // 文字模糊:{{文字模糊|内容|提示|颜色|时间}} $text = preg_replace_callback('/\{\{文字模糊\|([\s\S]*?)\}\}/u', function($m){ $parts = explode('|', $m[1]); $content = isset($parts[0]) ? trim($parts[0]) : ''; $tip = isset($parts[1]) ? trim($parts[1]) : '你知道的太多了'; $color = isset($parts[2]) ? trim($parts[2]) : ''; $time = isset($parts[3]) ? trim($parts[3]) : '0.2'; $style = '--text-blur-transition-time: ' . preg_replace('/[^0-9\.]/', '', $time) . 's;'; if (strlen($color) > 0) { $style .= ' --text-blur-color: ' . htmlspecialchars($color, ENT_QUOTES) . ';'; } return '' . htmlspecialchars($content) . ''; }, $text); // 彩幕:{{彩幕|内容|背景色|提示|前景色}} $text = preg_replace_callback('/\{\{彩幕\|([\s\S]*?)\}\}/u', function($m){ $parts = explode('|', $m[1]); $content = isset($parts[0]) ? trim($parts[0]) : ''; $bg = isset($parts[1]) ? trim($parts[1]) : '#252525'; $tip = isset($parts[2]) ? trim($parts[2]) : '你知道的太多了'; $fg = isset($parts[3]) ? trim($parts[3]) : ''; // 确保背景色有 # 前缀 $bghex = (substr($bg, 0, 1) == '#') ? $bg : ('#' . $bg); // 如果没有指定前景色,根据背景色亮度自动计算 if (empty($fg)) { $hex = ltrim($bghex, '#'); if (strlen($hex) == 3) { $hex = $hex[0].$hex[0].$hex[1].$hex[1].$hex[2].$hex[2]; } if (strlen($hex) == 6) { $r = hexdec(substr($hex, 0, 2)); $g = hexdec(substr($hex, 2, 2)); $b = hexdec(substr($hex, 4, 2)); $luma = 0.2126 * $r + 0.7152 * $g + 0.0722 * $b; $fg = ($luma >= 180) ? '#000' : '#fff'; } else { $fg = '#fff'; } } $style = '--curtain-bg: ' . htmlspecialchars($bghex, ENT_QUOTES) . '; --curtain-fg: ' . htmlspecialchars($fg, ENT_QUOTES) . ';'; return '' . htmlspecialchars($content) . ''; }, $text); return $text; } function argon_extend_comment_allowed_tags($tags, $context){ if ($context !== 'comment') { return $tags; } $tags['span'] = array('class' => true, 'style' => true, 'title' => true); return $tags; } add_filter('wp_kses_allowed_html', 'argon_extend_comment_allowed_tags', 10, 2); function argon_comment_text_render($text){ return argon_apply_comment_macros($text); } add_filter('comment_text', 'argon_comment_text_render', 9); add_filter('the_content', 'argon_comment_text_render', 9); //评论发送处理 function post_comment_preprocessing($comment){ //保存评论未经 Markdown 解析的源码 $_POST['comment_content_source'] = $comment['comment_content']; $comment['comment_content'] = argon_apply_comment_macros($comment['comment_content']); //Markdown if ($_POST['use_markdown'] == 'true' && get_option("argon_comment_allow_markdown") != "false"){ $comment['comment_content'] = comment_markdown_parse($comment['comment_content']); } return $comment; } add_filter('preprocess_comment' , 'post_comment_preprocessing'); //发送评论通知邮件 function comment_mail_notify($comment){ if (get_option("argon_comment_allow_mailnotice") != "true"){ return; } if ($comment == null){ return; } $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; $emailTo = "$parentName <$parentEmail>"; if (get_comment_meta($parentID, "enable_mailnotice", true) == "true"){ if (check_email_address($parentEmail)){ $title = __("您在", 'argon') . " 「" . wp_trim_words(get_post_title_by_id($commentPostID), 20) . "」 " . __("的评论有了新的回复", 'argon'); $fullTitle = __("您在", 'argon') . " 「" . get_post_title_by_id($commentPostID) . "」 " . __("的评论有了新的回复", 'argon'); $content = htmlspecialchars(get_comment_meta($id, "comment_content_source", true)); $link = get_permalink($commentPostID) . "#comment-" . $id; $unsubscribeLink = site_url("unsubscribe-comment-mailnotice?comment=" . $parentID . "&token=" . get_comment_meta($parentID, "mailnotice_unsubscribe_key", true)); // 使用新的邮件模板系统 $settings = argon_get_email_settings(); $post = get_post($commentPostID); // 生成新模板内容 $email_content = argon_get_reply_notify_content(array( 'post_title' => $post->post_title, 'post_url' => get_permalink($post->ID), 'original_comment' => wp_trim_words($parentComment->comment_content, 50, '...'), 'replier_name' => $commentAuthor, 'reply_content' => $content, 'comment_url' => $link, 'theme_color' => $settings['theme_color'] )); // 添加退订链接 $email_content .= '

    ' . __('退订该评论的邮件提醒', 'argon') . '

    '; // 渲染完整邮件 $html = argon_render_email($email_content, array('subject' => $title)); $html = apply_filters("argon_comment_mail_notification_content", $html); send_mail($emailTo, $title, $html); } } } function argon_async_comment_mail_notify_handler($comment_id){ $comment = get_comment($comment_id); comment_mail_notify($comment); } add_action('argon_async_comment_mail_notify', 'argon_async_comment_mail_notify_handler'); //评论发送完成添加 Meta function post_comment_updatemetas($id){ $parentID = $_POST['comment_parent']; $comment = get_comment($id); $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']); //评论者 Token set_user_token_cookie(); update_comment_meta($id, "user_token", $_COOKIE["argon_user_token"]); //保存初次编辑记录 $editHistory = array(array( 'content' => $_POST['comment_content_source'], 'time' => time(), 'isfirst' => true )); update_comment_meta($id, "comment_edit_history", addslashes(json_encode($editHistory, JSON_UNESCAPED_UNICODE))); //是否启用 Markdown if ($_POST['use_markdown'] == 'true' && get_option("argon_comment_allow_markdown") != "false"){ update_comment_meta($id, "use_markdown", "true"); }else{ update_comment_meta($id, "use_markdown", "false"); } //是否启用悄悄话模式 if ($_POST['private_mode'] == 'true' && get_option("argon_comment_allow_privatemode") == "true"){ update_comment_meta($id, "private_mode", $_COOKIE["argon_user_token"]); }else{ update_comment_meta($id, "private_mode", "false"); } if (is_comment_private_mode($parentID)){ //如果父级评论是悄悄话模式则将当前评论可查看者的 Token 跟随父级评论者的 Token update_comment_meta($id, "private_mode", get_comment_meta($parentID, "private_mode", true)); } if ($parentID!= 0 && !is_comment_private_mode($parentID)){ //如果父级评论不是悄悄话模式则当前评论也不是悄悄话模式 update_comment_meta($id, "private_mode", "false"); } //是否启用邮件通知 if ($_POST['enable_mailnotice'] == 'true' && get_option("argon_comment_allow_mailnotice") == "true"){ update_comment_meta($id, "enable_mailnotice", "true"); update_comment_meta($id, "mailnotice_unsubscribe_key", $mailnoticeUnsubscribeKey); }else{ update_comment_meta($id, "enable_mailnotice", "false"); } //向父级评论发送邮件 if ($comment -> comment_approved == 1){ wp_schedule_single_event(time() + 1, 'argon_async_comment_mail_notify', array($comment->comment_ID)); } //保存 QQ 号 if (get_option('argon_comment_enable_qq_avatar') == 'true'){ if (!empty($_POST['qq'])){ update_comment_meta($id, "qq_number", $_POST['qq']); } } } add_action('comment_post' , 'post_comment_updatemetas'); add_action('comment_unapproved_to_approved', 'comment_mail_notify'); add_rewrite_rule('^unsubscribe-comment-mailnotice/?(.*)$', '/wp-content/themes/argon/unsubscribe-comment-mailnotice.php$1', 'top'); //编辑评论 function user_edit_comment(){ header('Content-Type:application/json; charset=utf-8'); if (get_option("argon_comment_allow_editing") == "false"){ exit(json_encode(array( 'status' => 'failed', 'msg' => __('博主关闭了编辑评论功能', 'argon') ))); } $id = $_POST["id"]; $content = $_POST["comment"]; $contentSource = $content; if (!check_comment_token($id) && !check_login_user_same(get_comment_user_id_by_id($id))){ exit(json_encode(array( 'status' => 'failed', 'msg' => __('您不是这条评论的作者或 Token 已过期', 'argon') ))); } if ($_POST["comment"] == ""){ exit(json_encode(array( 'status' => 'failed', 'msg' => __('新的评论为空', 'argon') ))); } $content = argon_apply_comment_macros($content); if (get_comment_meta($id, "use_markdown", true) == "true"){ $content = comment_markdown_parse($content); } $res = wp_update_comment(array( 'comment_ID' => $id, 'comment_content' => $content )); if ($res == 1){ update_comment_meta($id, "comment_content_source", $contentSource); update_comment_meta($id, "edited", "true"); //保存编辑历史 $editHistory = json_decode(get_comment_meta($id, "comment_edit_history", true)); if (is_null($editHistory)){ $editHistory = array(); } array_push($editHistory, array( 'content' => htmlspecialchars(stripslashes($contentSource)), 'time' => time(), 'isfirst' => false )); update_comment_meta($id, "comment_edit_history", addslashes(json_encode($editHistory, JSON_UNESCAPED_UNICODE))); exit(json_encode(array( 'status' => 'success', 'msg' => __('编辑评论成功', 'argon'), 'new_comment' => apply_filters('comment_text', argon_get_comment_text($id), $id), 'new_comment_source' => htmlspecialchars(stripslashes($contentSource)), 'can_visit_edit_history' => can_visit_comment_edit_history($id) ))); }else{ exit(json_encode(array( 'status' => 'failed', 'msg' => __('编辑评论失败,可能原因: 与原评论相同', 'argon'), ))); } } add_action('wp_ajax_user_edit_comment', 'user_edit_comment'); add_action('wp_ajax_nopriv_user_edit_comment', 'user_edit_comment'); //置顶评论 function pin_comment(){ header('Content-Type:application/json; charset=utf-8'); if (get_option("argon_enable_comment_pinning") == "false"){ exit(json_encode(array( 'status' => 'failed', 'msg' => __('博主关闭了评论置顶功能', 'argon') ))); } if (!current_user_can("moderate_comments")){ exit(json_encode(array( 'status' => 'failed', 'msg' => __('您没有权限进行此操作', 'argon') ))); } $id = $_POST["id"]; $newPinnedStat = $_POST["pinned"] == "true"; $origPinnedStat = get_comment_meta($id, "pinned", true) == "true"; if ($newPinnedStat == $origPinnedStat){ exit(json_encode(array( 'status' => 'failed', 'msg' => $newPinnedStat ? __('评论已经是置顶状态', 'argon') : __('评论已经是取消置顶状态', 'argon') ))); } if (get_comment($id) -> comment_parent != 0){ exit(json_encode(array( 'status' => 'failed', 'msg' => __('不能置顶子评论', 'argon') ))); } if (is_comment_private_mode($id)){ exit(json_encode(array( 'status' => 'failed', 'msg' => __('不能置顶悄悄话', 'argon') ))); } update_comment_meta($id, "pinned", $newPinnedStat ? "true" : "false"); exit(json_encode(array( 'status' => 'success', 'msg' => $newPinnedStat ? __('置顶评论成功', 'argon') : __('取消置顶成功', 'argon'), ))); } add_action('wp_ajax_pin_comment', 'pin_comment'); add_action('wp_ajax_nopriv_pin_comment', 'pin_comment'); //输出评论分页页码 function get_argon_formatted_comment_paginate_links($maxPageNumbers, $extraClasses = ''){ $args = array( 'prev_text' => '', 'next_text' => '', 'before_page_number' => '', 'after_page_number' => '', 'show_all' => True, 'echo' => False ); $res = paginate_comments_links($args); //单引号转双引号 & 去除上一页和下一页按钮 $res = preg_replace( '/\'/', '"', $res ); $res = preg_replace( '/
  • --none-- 则不显示。", 'argon');?>