📄 styles.php
字号:
<?php
/*
[DISCUZ!] admin/styles.php - add, edit, export/import styles, etc
This is NOT a freeware, use is subject to license terms
Version: 1.1.0
Author: Crossday (info@discuz.net)
Copyright: Crossday Studio (www.crossday.com)
Last Modified: 2002/12/31 8:52
*/
if($action == 'styles' && $export) {
$query = $db->query("SELECT s.name, s.templateid, t.name AS tplname, t.charset, t.directory, t.copyright FROM $table_styles s LEFT JOIN $table_templates t ON t.templateid=s.templateid WHERE styleid='$export'");
if(!$stylearray = $db->fetch_array($query)) {
cpheader();
cpmsg('指定的风格不存在,无法导出。');
}
$stylearray['version'] = strip_tags($version);
$time = gmdate("$dateformat $timeformat", $timestamp + $timeoffset * 3600);
$query = $db->query("SELECT * FROM $table_stylevars WHERE styleid='$export'");
while($style = $db->fetch_array($query)) {
$stylearray['style'][$style['variable']] = $style['substitute'];
}
if($stylearray['templateid'] != 1) {
$dir = dir($discuz_root.'./'.$stylearray['directory']);
while($entry = $dir->read()) {
$filename = $discuz_root.'./'.$stylearray['directory'].'/'.$entry;
if(is_file($filename)) {
$stylearray['template'][str_replace('.', '_DOT_', $entry)] = join('', file($filename));
}
}
$dir->close();
}
$style_export = "# Discuz! Style Dump\n".
"# Version: Discuz! $version\n".
"# Time: $time\n".
"# From: $bbname ($boardurl)\n".
"#\n".
"# This file was BASE64 encoded\n".
"#\n".
"# Discuz! Community: http://www.Discuz.net\n".
"# Please visit our website for newest infomation about Discuz!\n".
"# --------------------------------------------------------\n\n\n".
wordwrap(base64_encode(serialize($stylearray)), 50, "\n", 1);
ob_end_clean();
header('Content-Encoding: none');
header('Content-Type: '.(strpos($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 'MSIE') ? 'application/octetstream' : 'application/octet-stream')); header('Content-Disposition: '.(strpos($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 'MSIE') ? 'inline; ' : 'attachment; ').'filename="dz_style_'.$stylearray['name'].'.txt"'); header('Content-Length: '.strlen($style_export));
header('Pragma: no-cache'); header('Expires: 0');
echo $style_export;
discuz_exit();
}
cpheader();
if($action == 'styles' && !$export) {
$predefinedvars = array('bgcolor', 'altbg1', 'altbg2', 'link', 'bordercolor', 'headercolor', 'headertext', 'catcolor',
'tabletext', 'text', 'borderwidth', 'tablewidth', 'tablespace', 'fontsize', 'font',
'smfontsize', 'smfont', 'nobold', 'boardimg', 'imgdir', 'smdir', 'cattext');
if(!$stylesubmit && !$importsubmit && !$edit && !$export) {
$styleselect = '';
$query = $db->query("SELECT s.styleid, s.available, s.name, t.name AS tplname, t.charset, t.copyright FROM $table_styles s LEFT JOIN $table_templates t ON t.templateid=s.templateid");
while($styleinfo = $db->fetch_array($query)) {
$styleselect .= "<tr align=\"center\"><td bgcolor=\"".ALTBG1."\"><input type=\"checkbox\" name=\"delete[]\" value=\"$styleinfo[styleid]\"></td>\n".
"<td bgcolor=\"".ALTBG2."\"><input type=\"text\" name=\"namenew[$styleinfo[styleid]]\" value=\"$styleinfo[name]\" size=\"18\"></td>\n".
"<td bgcolor=\"".ALTBG1."\"><input type=\"checkbox\" name=\"availablenew[$styleinfo[styleid]]\" value=\"1\" ".($styleinfo['available'] ? 'checked' : NULL)."></td>\n".
"<td bgcolor=\"".ALTBG2."\">$styleinfo[styleid]</td>\n".
"<td bgcolor=\"".ALTBG1."\">$styleinfo[tplname]</td>\n".
"<td bgcolor=\"".ALTBG2."\">$styleinfo[charset]</td>\n".
"<td bgcolor=\"".ALTBG1."\"><a href=\"admincp.php?action=styles&export=$styleinfo[styleid]\">[下载]</a></td>\n".
"<td bgcolor=\"".ALTBG2."\"><a href=\"admincp.php?action=styles&edit=$styleinfo[styleid]\">[详情]</a></td></tr>\n";
}
?>
<table cellspacing="0" cellpadding="0" border="0" width="90%" align="center"><tr><td bgcolor="<?=BORDERCOLOR?>"><table border="0" cellspacing="<?=BORDERWIDTH?>" cellpadding="<?=TABLESPACE?>" width="100%"><tr class="header"><td>特别提示</td></tr>
<tr bgcolor="<?=ALTBG1?>"><td>
<br>
<ul><li>您可以指导用户通过在 URL 加入 styleid 变量来轻松切换当前界面风格,如 http://your.com/discuz/index.php?styleid=2 或 http://your.com/discuz/forumdisplay.php?fid=2&styleid=3</ul>
<ul><li>界面方案的“可用”是指用户是否选择使用此风格,但无论设置可用与否,都可以将此界面设置为默认界面或某分论坛的默认界面。</ul>
</td></tr></table></td></tr></table><br><br>
<form method="post" action="admincp.php?action=styles">
<table cellspacing="0" cellpadding="0" border="0" width="90%" align="center">
<tr><td bgcolor="<?=BORDERCOLOR?>">
<table border="0" cellspacing="<?=BORDERWIDTH?>" cellpadding="<?=TABLESPACE?>" width="100%">
<tr class="header" align="center">
<td width="45"><input type="checkbox" name="chkall" class="header" onclick="checkall(this.form)">删?</td>
<td>方案名称</td><td>可用</td><td>styleID</td><td>所用模板</td><td>字符集</td><td>导出</td><td>编辑</td></tr>
<?=$styleselect?>
<tr bgcolor="<?=ALTBG2?>"><td height="1" colspan="8"></td></tr>
<tr align="center"><td bgcolor="<?=ALTBG1?>">新增:</td>
<td bgcolor="<?=ALTBG2?>"><input type='text' name="newname" size="18"></td>
<td colspan="6" bgcolor="<?=ALTBG2?>"> </td>
</tr></table></td></tr></table><br>
<center><input type="submit" name="stylesubmit" value="更新界面设置"></center></form>
<br><form method="post" action="admincp.php?action=styles">
<table cellspacing="<?=BORDERWIDTH?>" cellpadding="<?=TABLESPACE?>" width="90%" bgcolor="<?=BORDERCOLOR?>" align="center">
<tr class="header"><td>导入界面方案 - 请将导出的文件内容粘贴如下</td></tr>
<tr><td bgcolor="<?=ALTBG1?>" align="center"><textarea name="styledata" cols="80" rows="8"></textarea><br>
<input type="checkbox" name="ignoreversion" value="1"> 允许导入不同版本 Discuz! 的界面(易产生错误!!)</td></tr>
</table><br><center><input type="submit" name="importsubmit" value="将风格文件导入 Discuz!"></center></form>
<?
} elseif($stylesubmit) {
if(is_array($namenew)) {
foreach($namenew as $id => $val) {
$db->query("UPDATE $table_styles SET name='$namenew[$id]', available='$availablenew[$id]' WHERE styleid='$id'");
}
}
if(is_array($delete)) {
$ids = $comma = '';
foreach($delete as $id) {
$ids .= "$comma'$id'";
$comma = ', ';
}
$query = $db->query("SELECT COUNT(*) FROM $table_settings WHERE styleid IN ($ids)");
if($db->result($query, 0)) {
cpmsg("您不能直接删除系统默认的风格,请返回选择其他风格为默认后再进行删除。");
}
$db->query("DELETE FROM $table_styles WHERE styleid IN ($ids)");
$db->query("DELETE FROM $table_stylevars WHERE styleid IN ($ids)");
$db->query("UPDATE $table_members SET styleid='0' WHERE styleid IN ($ids)");
$db->query("UPDATE $table_forums SET styleid='0' WHERE styleid IN ($ids)");
$db->query("UPDATE $table_sessions SET styleid='$_DCACHE[settings][styleid]' WHERE styleid IN ($ids)");
}
if($newname) {
$db->query("INSERT INTO $table_styles (name, templateid) VALUES ('$newname', '1')");
$styleid = $db->insert_id();
foreach($predefinedvars as $variable) {
$db->query("INSERT INTO $table_stylevars (styleid, variable)
VALUES ('$styleid', '$variable')");
}
}
cpmsg("界面方案成功更新。");
} elseif($importsubmit) {
$styledata = preg_replace("/(#.*\s+)*/", '', $styledata);
$stylearray = daddslashes(unserialize(base64_decode($styledata)), 1);
if(!is_array($stylearray)) {
cpmsg("界面文件已损坏,无法导入,请返回。");
}
if(empty($ignoreversion) && strip_tags($stylearray['version']) != strip_tags($version)) {
cpmsg("导出界面所用 Discuz! ($stylearray[version])与当前版本($version)不一致,请返回。");
}
if($stylearray['templateid'] != 1) {
$templatedir = $discuz_root.'./'.$stylearray['directory'];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -