<?php

$alltheme = $arr = array();
$d = dir(ABSPATH . 'themes');
while (false !== ($entry = $d->read()))
{
    if (file_exists($file = ABSPATH . 'themes/' . $entry . '/__init.php'))
    {
        $data = read_file($file);
        $str = substr($data, 0, strpos($data, '*/') + 1);
        preg_replace("/\*\s*([^*]+?)\s*:\s*(.+?)\s*\n/eis", "\$arr['$entry'][]=array('\\1','\\2')",
            $str);
    }
}
$d->close();
foreach ($arr as $k => $v)
{
    foreach ($v as $var)
    {
        $alltheme[$k][stripslashes($var[0])] = stripslashes($var[1]);
    }
}
$conf['sys_themes'] = $alltheme;
if (IS_POST)
{
    $elangs = is_array($_POST['ethemes']) ? $_POST['ethemes'] : array();
    isset($conf['sys_themes'][$_POST['theme']]) or yun_error('默认主题不存在');
    foreach ($elangs as $v)
    {
        $conf['sys_elangs'][$v] = $_POST['name'][$v];
    }
    $conf['sys_themes'] = arraysort($conf['sys_themes'], $_POST['order']);
    set_conf('sys_theme', $_POST['theme']);
    set_conf('sys_themes', $conf['sys_themes']);
    yun_succeed('提交成功', url(RPGM . 'theme/'));
}
arg($alltheme);

?>