示例#1
0
function writeConfigFile($settings, $description = null)
{
    $context = Model_Context::getInstance();
    $writer = new Utils_OutputWriter();
    $database = $context->getAllFromNamespace('database');
    $service = $context->getAllFromNamespace('service');
    $memcached = $context->getAllFromNamespace('memcached');
    $config = array();
    $contents = "<?php" . CRLF . "ini_set('display_errors', 'off');" . CRLF;
    // Database information. It is not allow to modify.
    $config['server'] = $database['server'];
    $config['database'] = $database['database'];
    $config['username'] = $database['username'];
    $config['password'] = $database['password'];
    $config['dbms'] = $database['dbms'];
    $config['prefix'] = $database['prefix'];
    foreach ($config as $item => $value) {
        $contents .= "\$database['" . $item . "'] = '" . $value . "';" . (array_key_exists($item, $description) ? "   // " . $description[$item] : "") . CRLF;
    }
    $config = array();
    $config['type'] = $service['type'];
    $config['domain'] = $service['domain'];
    $config['path'] = $service['path'];
    foreach ($config as $item => $value) {
        $contents .= "\$service['" . $item . "'] = '" . $value . "';" . (array_key_exists($item, $description) ? "   // " . $description[$item] : "") . CRLF;
    }
    if (!empty($memcached) && array_key_exists('server', $memcached)) {
        $contents .= "\$memcached['server'] = '" . $memcached['server'] . "';" . CRLF;
    }
    // Service-specific information.
    foreach ($settings as $item => $value) {
        if ($item == 'serviceURL') {
            $contents .= "\$serviceURL = '" . $value . "';" . (array_key_exists($item, $description) ? "   // " . $description[$item] : "") . CRLF;
        } else {
            if ($value === true || $value === false || is_numeric($value)) {
                if ($value === true) {
                    $value = 'true';
                } else {
                    if ($value === false) {
                        $value = 'false';
                    }
                }
                $contents .= "\$service['" . $item . "'] = " . $value . ";" . (array_key_exists($item, $description) ? "   // " . $description[$item] : "") . CRLF;
            } else {
                $contents .= "\$service['" . $item . "'] = '" . $value . "';" . (array_key_exists($item, $description) ? "   // " . $description[$item] : "") . CRLF;
            }
        }
    }
    $contents .= "?>" . CRLF;
    if (!is_writable(ROOT . "/config.php")) {
        return _f('파일 쓰기 권한이 없습니다. 웹서버가 %1 파일의 쓰기 권한을 가지고 있는지 확인하세요.', 'config.php');
    }
    $writer->openFile(ROOT . "/config.php");
    if ($writer->write($contents) === false) {
        $writer->close();
        return _t('실패했습니다.');
    }
    $writer->close();
    return true;
}
示例#2
0
    if ($writer->openFile(__TEXTCUBE_CACHE_DIR__ . "/backup/{$blogid}.xml")) {
    } else {
        exit;
    }
} else {
    if ($writer->openStdout()) {
        header('Content-Disposition: attachment; filename="Textcube-Backup-' . getBlogName($blogid) . "-" . Timestamp::getDate() . '.xml"');
        header('Content-Description: Textcube Backup Data');
        header('Content-Transfer-Encoding: binary');
        header('Content-Type: application/xml');
    } else {
        exit;
    }
}
$newlineStyle = !is_null(Setting::getServiceSettingGlobal('newlineStyle')) ? ' format="' . Setting::getServiceSettingGlobal('newlineStyle') . '"' : '';
$writer->write('<?xml version="1.0" encoding="utf-8" ?>');
$writer->write('<blog type="tattertools/1.1" extension="textcube/2.0" migrational="false">');
$setting = new BlogSetting();
if ($setting->load()) {
    $setting->escape();
    $writer->write('<setting>' . '<name>' . $setting->name . '</name>' . '<secondaryDomain>' . $setting->secondaryDomain . '</secondaryDomain>' . '<defaultDomain>' . Validator::getBit($setting->defaultDomain) . '</defaultDomain>' . '<title>' . $setting->title . '</title>' . '<description>' . Utils_Unicode::correct($setting->description) . '</description>' . '<banner><name>' . $setting->banner . '</name>');
    if ($includeFileContents && file_exists(__TEXTCUBE_ATTACH_DIR__ . "/{$blogid}/{$setting->banner}")) {
        $writer->write('<content>');
        if (!empty($setting->banner) && file_exists(__TEXTCUBE_ATTACH_DIR__ . "/{$blogid}/" . $setting->banner)) {
            Utils_Base64Stream::encode(__TEXTCUBE_ATTACH_DIR__ . "/{$blogid}/{$setting->banner}", $writer);
        }
        $writer->write('</content>');
    }
    $writer->write('</banner>' . '<useSloganOnPost>' . Validator::getBit($setting->useSloganOnPost) . '</useSloganOnPost>' . '<postsOnPage>' . $setting->postsOnPage . '</postsOnPage>' . '<postsOnList>' . $setting->postsOnList . '</postsOnList>' . '<postsOnFeed>' . $setting->postsOnFeed . '</postsOnFeed>' . '<publishWholeOnFeed>' . Validator::getBit($setting->publishWholeOnFeed) . '</publishWholeOnFeed>' . '<acceptGuestComment>' . Validator::getBit($setting->acceptGuestComment) . '</acceptGuestComment>' . '<acceptcommentOnGuestComment>' . Validator::getBit($setting->acceptcommentOnGuestComment) . '</acceptcommentOnGuestComment>' . '<language>' . $setting->language . '</language>' . '<timezone>' . $setting->timezone . '</timezone>' . '</setting>');
    $writer->write(CRLF);
}