<?php

use Twig\Environment;

class ACMS_GET_Admin_Dashboard_PhpStatus extends ACMS_GET
{
    public function get()
    {
        if (!sessionWithAdministration()) {
            return '';
        }

        $Tpl = new Template($this->tpl, new ACMS_Corrector());

        // ディレクティブ
        // `.` を含むキー (例: session.gc_maxlifetime) はテンプレート変数名と合わないため、
        // 格納時に `_` 区切りへ変換する
        $directive = [
            'memory_limit',
            'upload_max_filesize',
            'post_max_size',
            'max_file_uploads',
            'safe_mode',
            'max_input_vars',
            'session.gc_maxlifetime',
        ];

        foreach ($directive as $key) {
            $val = ini_get($key);
            if (empty($val)) {
                continue;
            }
            $ini[str_replace('.', '_', $key)] = $val;
        }

        $ini['ImageRotate'] = function_exists('imagerotate') ? '使用可' : '不可';
        $ini['php_version'] = PHP_VERSION;
        $ini['mysql_version'] = DB::getVersion();
        $ini['twig_version'] = Environment::VERSION;
        $ini['html_purifier_version'] = HTMLPurifier::VERSION;
        $ini['php_datetime'] = date('Y-m-d H:i:s');
        $ini['php_gettext'] = (
            function_exists('gettext') &&
            function_exists('bindtextdomain') &&
            function_exists('textdomain')
        ) ? 'enable' : 'disable';
        $ini['php_imagick'] = class_exists('Imagick') ? 'enable' : 'disable';

        if (strpos(PHP_SAPI, 'apache') !== false) {
            $ini['php_sapi'] = 'モジュール版';
        } elseif (strpos(PHP_SAPI, 'cgi') !== false) {
            $ini['php_sapi'] = 'CGI版';
        } else {
            $ini['php_sapi'] = '不明';
        }

        $Tpl->add(null, $ini);

        return $Tpl->get();
    }
}
