HEX
Server: nginx/1.22.1
System: Linux VM-16-9-centos 3.10.0-1160.99.1.el7.x86_64 #1 SMP Wed Sep 13 14:19:20 UTC 2023 x86_64
User: www (1001)
PHP: 7.3.31
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/softfox.com.cn/wp-content/themes/kratos/inc/theme-volcengine.php
<?php

/**
 * ImageX 图片服务
 * @author Seaton Jiang <hi@seatonjiang.com>
 * @license GPL-3.0 License
 * @version 2022.01.26
 */

if (!empty(kratos_option('g_imgx_fieldset')['g_imgx'])) {

    require_once 'volcengine-imagex/vendor/autoload.php';

    function imagex_get_client()
    {
        $imagex_client = Volc\Service\ImageX::getInstance($region = kratos_option('g_imgx_fieldset')['g_imgx_region']);
        $imagex_client->setAccessKey(kratos_option('g_imgx_fieldset')['g_imgx_accesskey']);
        $imagex_client->setSecretKey(kratos_option('g_imgx_fieldset')['g_imgx_secretkey']);

        return $imagex_client;
    }

    function imagex_upload($object, $file)
    {
        if (!@file_exists($file)) {
            return false;
        }
        if (@file_exists($file)) {
            $client = imagex_get_client();
            $params = array();
            $params["ServiceId"] = kratos_option('g_imgx_fieldset')['g_imgx_serviceid'];
            $params['UploadNum'] = 1;
            $params['StoreKeys'] = array($object);
            $response = $client->uploadImages($params, array($file));
        } else {
            return false;
        }
    }

    // 上传附件
    function imagex_upload_attachments($metadata)
    {
        if (get_option('upload_path') == '.') {
            $metadata['file'] = str_replace("./", '', $metadata['file']);
        }

        $object = str_replace("\\", '/', $metadata['file']);
        $object = str_replace(get_home_path(), '', $object);
        $object = str_replace("wp-content/uploads/", '', $object);
        $file = get_home_path() . "wp-content/uploads/" . $object;
        imagex_upload($object, $file);

        return $metadata;
    }

    if (substr_count($_SERVER['REQUEST_URI'], '/update.php') <= 0) {
        add_filter('wp_handle_upload', 'imagex_upload_attachments', 50);
    }

    // 上传缩略图
    function imagex_upload_thumbs($metadata)
    {
        if (isset($metadata['sizes']) && count($metadata['sizes']) > 0) {
            $wp_uploads = wp_upload_dir();
            $basedir = $wp_uploads['basedir'];
            $file_dir = $metadata['file'];
            $file_path = $basedir . '/' . dirname($file_dir) . '/';
            if (get_option('upload_path') == '.') {
                $file_path = str_replace("\\", '/', $file_path);
                $file_path = str_replace(get_home_path() . "./", '', $file_path);
            } else {
                $file_path = str_replace("\\", '/', $file_path);
            }
            $file_path = str_replace("./", '', $file_path);
            $object_path = str_replace(get_home_path(), '', $file_path);
            foreach ($metadata['sizes'] as $val) {
                $object = $object_path . $val['file'];
                $object = str_replace("wp-content/uploads/", '', $object);
                $file = $file_path . $val['file'];
                imagex_upload($object, $file);
            }
        }
        return $metadata;
    }

    if (substr_count($_SERVER['REQUEST_URI'], '/update.php') <= 0) {
        add_filter('wp_generate_attachment_metadata', 'imagex_upload_thumbs', 100);
    }

    // 删除文件
    function imagex_delete_remote_file($file)
    {
        $client = imagex_get_client();
        $file = str_replace("\\", '/', $file);
        $file = str_replace(get_home_path(), '', $file);
        $del_file_path = str_replace("wp-content/uploads/", '', $file);

        $client->deleteImages(kratos_option('g_imgx_fieldset')['g_imgx_serviceid'], array($del_file_path));

        return $file;
    }
    add_action('wp_delete_file', 'imagex_delete_remote_file', 100);

    // 修改图片地址
    function custom_upload_dir($uploads)
    {
        $upload_path = '';
        $upload_url_path = kratos_option('g_imgx_fieldset')['g_imgx_url'];

        if (empty($upload_path) || 'wp-content/uploads' == $upload_path) {
            $uploads['basedir'] = WP_CONTENT_DIR . '/uploads';
        } elseif (0 !== strpos($upload_path, ABSPATH)) {
            $uploads['basedir'] = path_join(ABSPATH, $upload_path);
        } else {
            $uploads['basedir'] = $upload_path;
        }

        $uploads['path'] = $uploads['basedir'] . $uploads['subdir'];

        if ($upload_url_path) {
            $uploads['baseurl'] = $upload_url_path;
            $uploads['url'] = $uploads['baseurl'] . $uploads['subdir'];
        }

        if (substr($upload_url_path, -1) == '/') {
            $upload_url_path = str_replace(get_home_path(), '', $upload_url_path);
        }

        return $uploads;
    }
    add_filter('upload_dir', 'custom_upload_dir');

    function imagex_setting_content_ci($content)
    {
        preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $images);
        if (!empty($images) && isset($images[1])) {
            foreach ($images[1] as $item) {
                $content = str_replace($item, $item . kratos_option('g_imgx_fieldset')['g_imgx_tmp'], $content);
            }
        }
        return $content;
    }
    add_filter('the_content', 'imagex_setting_content_ci');

    function imagex_setting_post_thumbnail_ci($html, $post_id, $post_image_id)
    {
        if (has_post_thumbnail()) {
            preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $html, $images);
            if (!empty($images) && isset($images[1])) {
                foreach ($images[1] as $item) {
                    $html = str_replace($item, $item . kratos_option('g_imgx_fieldset')['g_imgx_tmp'], $html);
                }
            }
        }
        return $html;
    }
    add_filter('post_thumbnail_html', 'imagex_setting_post_thumbnail_ci', 10, 3);
}