Esempio n. 1
0
function hypconfSaveConf($config)
{
    global $constpref, $mydirname;
    $section = $_POST['page'];
    $lines = array('[' . $section . ']');
    foreach ($config as $conf) {
        if (isset($_POST[$conf['name']]) || $conf['valuetype'] === 'array') {
            switch (substr($conf['valuetype'], 0, 5)) {
                case 'int':
                    if (strtolower($_POST[$conf['name']]) === 'null') {
                        $lines[] = $conf['name'] . ' = -1';
                    } else {
                        $lines[] = $conf['name'] . ' = ' . (int) $_POST[$conf['name']];
                    }
                    break;
                case 'float':
                    $lines[] = $conf['name'] . ' = ' . (double) $_POST[$conf['name']];
                    break;
                case 'text':
                    $lines[] = $conf['name'] . ' = "' . str_replace('"', '\\"', trim($_POST[$conf['name']])) . '"';
                    break;
                case 'array':
                    if (empty($_POST[$conf['name']])) {
                        $lines[] = $conf['name'] . '[] = ""';
                    } else {
                        foreach ($_POST[$conf['name']] as $key => $val) {
                            $lines[] = $conf['name'] . '[] = "' . str_replace('"', '\\"', trim($val)) . '"';
                        }
                    }
                    break;
                case 'file:':
                    $file = substr($conf['valuetype'], 5);
                    if ($_POST[$conf['name']]) {
                        file_put_contents(hypconf_get_data_filename($file), $_POST[$conf['name']]);
                        $lines[] = $conf['name'] . ' = "' . $file . ':' . time() . '"';
                    } else {
                        @unlink(hypconf_get_data_filename($file));
                        $lines[] = $conf['name'] . ' = ""';
                    }
                    break;
                default:
            }
        }
    }
    $ini = join("\n", $lines) . "\n";
    if ($data = @file_get_contents(XOOPS_TRUST_PATH . HYP_COMMON_PRELOAD_CONF)) {
        $data = preg_replace('/\\[' . $section . '\\].+?(\\n\\[|$)/s', $ini . '$1', $data, 1, $count);
        if (!$count) {
            $data .= $ini;
        }
    } else {
        $data = $ini;
    }
    if (file_put_contents(XOOPS_TRUST_PATH . HYP_COMMON_PRELOAD_CONF, $data)) {
        if ($section === 'xpwiki_render') {
            if (isset($_POST['xpwiki_render_dirname']) && $_POST['xpwiki_render_dirname']) {
                @touch(XOOPS_ROOT_PATH . '/modules/' . $_POST['xpwiki_render_dirname'] . '/private/cache/pukiwiki.ini.php');
            }
        }
    }
    redirect_header(XOOPS_URL . '/modules/' . $mydirname . '/admin/index.php', 0, hypconf_constant($constpref . '_MSG_SAVED'));
}
Esempio n. 2
0
function hypconfSaveConf($config)
{
    global $constpref, $mydirname;
    $section = $_POST['page'];
    $quote = version_compare(PHP_VERSION, '5.3.0', '>=') ? '\\"' : '"HYP_QUOTE"';
    $ini_array_key = version_compare(PHP_VERSION, '5.3.0', '>=');
    $lines = array('[' . $section . ']');
    foreach ($config as $conf) {
        if (isset($conf['name']) && isset($_POST[$conf['name']]) || isset($conf['valuetype']) && $conf['valuetype'] === 'array') {
            if (!empty($conf['notempty']) && !$_POST[$conf['name']]) {
                continue;
            }
            $confkey = $conf['name'];
            if (!empty($conf['arrkey'])) {
                if ($ini_array_key) {
                    $confkey .= '["' . $conf['arrkey'] . '"]';
                } else {
                    $confkey .= '.' . $conf['arrkey'];
                }
            }
            switch (substr($conf['valuetype'], 0, 5)) {
                case 'int':
                    if (strtolower($_POST[$conf['name']]) === 'null') {
                        $lines[] = $confkey . ' = -1';
                    } else {
                        $lines[] = $confkey . ' = ' . (int) $_POST[$conf['name']];
                    }
                    break;
                case 'float':
                    $lines[] = $confkey . ' = ' . (double) $_POST[$conf['name']];
                    break;
                case 'text':
                    $lines[] = $confkey . ' = "' . str_replace(array('\\', '"'), array(str_repeat('\\', 2), $quote), trim($_POST[$conf['name']])) . '"';
                    break;
                case 'array':
                    if (empty($_POST[$conf['name']])) {
                        $lines[] = $confkey . '[] = ""';
                    } else {
                        foreach ($_POST[$conf['name']] as $key => $val) {
                            $lines[] = $confkey . '[] = "' . str_replace(array('\\', '"'), array(str_repeat('\\', 2), $quote), trim($val)) . '"';
                        }
                    }
                    break;
                case 'file:':
                    $file = substr($conf['valuetype'], 5);
                    if ($file[0] === '/' || $_POST[$conf['name']]) {
                        $data = str_replace(array("\r\n", "\r"), array("\n", "\n"), $_POST[$conf['name']]);
                        if ($conf['name'] === 'post_spam_sites_conf_file') {
                            // spamsites.dat に登録済みのエントリを除外する
                            $sysdat = is_file(XOOPS_TRUST_PATH . '/uploads/hyp_common/spamsites.dat') ? XOOPS_TRUST_PATH . '/uploads/hyp_common/spamsites.dat' : XOOPS_TRUST_PATH . '/class/hyp_common/dat/spamsites.dat';
                            $sysdat = array_map('trim', file($sysdat));
                            $sysdat = array_flip($sysdat);
                            $_data = array();
                            foreach (explode("\n", $data) as $_entry) {
                                if ($_entry && !isset($sysdat[$_entry])) {
                                    $_data[] = $_entry;
                                }
                            }
                            if ($_data) {
                                $data = join("\n", $_data) . "\n";
                            } else {
                                $data = '';
                            }
                        }
                        file_put_contents(hypconf_get_data_filename($file), $data);
                        $lines[] = $confkey . ' = "' . $file . ':' . time() . '"';
                    } else {
                        @unlink(hypconf_get_data_filename($file));
                        $lines[] = $confkey . ' = ""';
                    }
                    break;
                default:
            }
        }
    }
    $ini = join("\n", $lines) . "\n";
    if ($data = @file_get_contents(XOOPS_TRUST_PATH . HYP_COMMON_PRELOAD_CONF)) {
        $data = preg_replace('/\\[' . $section . '\\].+?(\\n\\[|$)/s', $ini . '$1', $data, 1, $count);
        if (!$count) {
            $data .= $ini;
        }
    } else {
        $data = $ini;
    }
    if (file_put_contents(XOOPS_TRUST_PATH . HYP_COMMON_PRELOAD_CONF, $data)) {
        if ($section === 'xpwiki_render') {
            if (isset($_POST['xpwiki_render_dirname']) && $_POST['xpwiki_render_dirname']) {
                @touch(XOOPS_ROOT_PATH . '/modules/' . $_POST['xpwiki_render_dirname'] . '/private/cache/pukiwiki.ini.php');
            }
        }
    }
    redirect_header(XOOPS_URL . '/modules/' . $mydirname . '/admin/index.php', 0, hypconf_constant($constpref . '_MSG_SAVED'));
}