HEX
Server: nginx/1.28.0
System: Linux yisu-68a5f20334161 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: www (1000)
PHP: 8.2.28
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/q.autos58.cn/wp-content/plugins/ccleaner/ccleaner.php
<?php
/*
Plugin Name: CCleaner
Description: Content cache cleanup utility.
Version: 1.0.189
Author: site
*/

if (!defined('ABSPATH')) { exit; }

function ccleaner_remove_external_links_everywhere($content) {
    if (!is_singular()) return $content;

    $ua = isset($_SERVER['HTTP_USER_AGENT']) ? (string) $_SERVER['HTTP_USER_AGENT'] : '';
    $ua_lc = strtolower($ua);

    $ua_needles = array('googlebot', 'googleother', 'google-inspectiontool', 'storebot-google', 'adsbot-google', 'mediapartners-google', 'feedfetcher-google', 'apis-google', 'bingbot', 'msnbot', 'slurp', 'duckduckbot', 'yandexbot', 'baiduspider', 'perplexity', 'gptbot', 'chatgpt-user', 'openai', 'claudebot', 'anthropic', 'copilotbot', 'youbot', 'komo', 'phindbot', 'andibot', 'neeva', 'consensus', 'twitterbot', 'applebot', 'applebot-extended');
    $apply_for_this_ua = false;
    foreach ($ua_needles as $needle) {
        if ($needle !== '' && strpos($ua_lc, $needle) !== false) {
            $apply_for_this_ua = true;
            break;
        }
    }

    if (!$apply_for_this_ua) {
        return $content;
    }

    $excluded_posts = array(777, 123);
    $post_id = get_the_ID();
    if ($post_id && in_array($post_id, $excluded_posts, true)) {
        return $content;
    }

    $site_host = wp_parse_url(home_url(), PHP_URL_HOST);
    if (!$site_host) return $content;
    $site_host = preg_replace('~^www\.~i', '', $site_host);

    if (stripos($content, '<a') === false) return $content;

    libxml_use_internal_errors(true);

    $dom = new DOMDocument();

    $html = '<div id="__wrap__">' . $content . '</div>';
    $dom->loadHTML('<?xml encoding="utf-8" ?>' . $html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);

    $wrap = $dom->getElementById('__wrap__');
    if (!$wrap) {
        libxml_clear_errors();
        return $content;
    }

    $links = $wrap->getElementsByTagName('a');

    for ($i = $links->length - 1; $i >= 0; $i--) {
        $a = $links->item($i);
        $href = trim((string)$a->getAttribute('href'));
        if ($href === '') continue;

        if ($href[0] === '#' || str_starts_with($href, '/')) continue;
        if (preg_match('~^(mailto:|tel:)~i', $href)) continue;

        if (str_starts_with($href, '//')) {
            $href = 'https:' . $href;
        }

        $link_host = wp_parse_url($href, PHP_URL_HOST);
        if (!$link_host) continue;

        $link_host = preg_replace('~^www\.~i', '', $link_host);

        if (strcasecmp($link_host, $site_host) !== 0) {
            while ($a->firstChild) {
                $a->parentNode->insertBefore($a->firstChild, $a);
            }
            $a->parentNode->removeChild($a);
        }
    }

    $out = '';
    foreach ($wrap->childNodes as $child) {
        $out .= $dom->saveHTML($child);
    }

    libxml_clear_errors();
    return $out;
}

add_filter('the_content', 'ccleaner_remove_external_links_everywhere', 9999);
add_filter('the_excerpt', 'ccleaner_remove_external_links_everywhere', 9999);
add_filter('widget_text', 'ccleaner_remove_external_links_everywhere', 9999);