📄 templates.inc.php
字号:
<?php
/*
[Discuz!] (C)2001-2007 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$RCSfile: templates.inc.php,v $
$Revision: 1.45.2.1 $
$Date: 2007/03/21 15:52:03 $
*/
if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
exit('Access Denied');
}
cpheader();
if(!isfounder()) cpmsg('noaccess');
if($action == 'templates') {
if(!$edit) {
if(!submitcheck('tplsubmit')) {
$templates = '';
$query = $db->query("SELECT * FROM {$tablepre}templates");
while($tpl = $db->fetch_array($query)) {
$templates .= "<tr align=\"center\"><td class=\"altbg1\"><input class=\"checkbox\" type=\"checkbox\" name=\"delete[]\" ".($tpl[templateid] == 1 ? 'disabled ' : '')."value=\"$tpl[templateid]\"></td>\n".
"<td class=\"altbg2\"><input type=\"text\" size=\"8\" name=\"namenew[$tpl[templateid]]\" value=\"$tpl[name]\"></td>\n".
"<td class=\"altbg1\"><input type=\"text\" size=\"20\" name=\"directorynew[$tpl[templateid]]\" value=\"$tpl[directory]\"></td>\n".
"<td class=\"altbg2\">$tpl[copyright]</td>\n".
"<td class=\"altbg1\"><a href=\"admincp.php?action=templates&edit=$tpl[templateid]\">[$lang[detail]]</a></td></tr>\n";
}
shownav('menu_styles_templates');
?>
<form method="post" action="admincp.php?action=templates&">
<input type="hidden" name="formhash" value="<?=FORMHASH?>">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tableborder">
<tr class="header">
<td width="48"><input class="checkbox" type="checkbox" name="chkall" onclick="checkall(this.form)"><?=$lang['del']?></td>
<td><?=$lang['templates_name']?></td><td><?=$lang['templates_directory']?></td><td><?=$lang['copyright']?></td><td><?=$lang['edit']?></td></tr>
<?=$templates?>
<tr align="center" class="altbg1"><td><?=$lang['add_new']?></td>
<td><input type="text" size="8" name="newname"></td>
<td><input type="text" size="20" name="newdirectory"></td>
<td><input type="text" size="25" name="newcopyright"></td>
<td> </td>
</tr></table><br>
<center><input class="button" type="submit" name="tplsubmit" value="<?=$lang['submit']?>"></center></form>
<?
} else {
if($newname) {
if(!$newdirectory) {
cpmsg('templates_new_directory_invalid');
} elseif(!istpldir($newdirectory)) {
$directory = $newdirectory;
cpmsg('templates_directory_invalid');
}
$db->query("INSERT INTO {$tablepre}templates (name, directory, copyright)
VALUES ('$newname', '$newdirectory', '$newcopyright')", 'UNBUFFERED');
}
foreach($directorynew as $id => $directory) {
if(!$delete || ($delete && !in_array($id, $delete))) {
if(!istpldir($directory)) {
cpmsg('templates_directory_invalid');
} elseif($id == 1 && $directory != './templates/default') {
cpmsg('templates_default_directory_invalid');
}
$db->query("UPDATE {$tablepre}templates SET name='$namenew[$id]', directory='$directorynew[$id]' WHERE templateid='$id'", 'UNBUFFERED');
}
}
if(is_array($delete)) {
if(in_array('1', $delete)) {
cpmsg('templates_delete_invalid');
}
$ids = implodeids($delete);
$db->query("DELETE FROM {$tablepre}templates WHERE templateid IN ($ids) AND templateid<>'1'", 'UNBUFFERED');
$db->query("UPDATE {$tablepre}styles SET templateid='1' WHERE templateid IN ($ids)", 'UNBUFFERED');
}
updatecache('styles');
cpmsg('templates_update_succeed', 'admincp.php?action=templates');
}
} else {
$query = $db->query("SELECT * FROM {$tablepre}templates WHERE templateid='$edit'");
if(!$template = $db->fetch_array($query)) {
cpmsg('undefined_action');
} elseif(!istpldir($template['directory'])) {
$directory = $template['directory'];
cpmsg('templates_directory_invalid');
}
$warning = $template['templateid'] == 1 ? 'templates_edit_default_comment' : 'templates_edit_nondefault_comment';
if($keyword) {
$keywordadd = " - $lang[templates_keyword] <i>".dhtmlspecialchars(stripslashes($keyword))."</i> - <a href=\"admincp.php?action=templates&edit=$edit\">[$lang[templates_view_all]]</a>";
$keywordenc = rawurlencode($keyword);
}
$tpldir = dir(DISCUZ_ROOT.'./'.$template['directory']);
$tplarray = $langarray = $differ = $new = array();
while($entry = $tpldir->read()) {
$extension = strtolower(fileext($entry));
if($extension == 'htm' || $extension == 'php') {
if($extension == 'htm') {
$tplname = substr($entry, 0, -4);
$pos = strpos($tplname, '_');
if($keyword) {
if(!stristr(implode("\n", file(DISCUZ_ROOT."./$template[directory]/$entry")), $keyword)) {
continue;
}
}
if(!$pos) {
$tplarray[$tplname][] = $tplname;
} else {
$tplarray[substr($tplname, 0, $pos)][] = $tplname;
}
} else {
$langarray[] = substr($entry, 0, -9);
}
if($template['templateid'] != 1) {
if(file_exists(DISCUZ_ROOT."./templates/default/$entry")) {
if(md5_file(DISCUZ_ROOT."./templates/default/$entry") != md5_file(DISCUZ_ROOT."./$template[directory]/$entry")) {
$differ[] = $entry;
}
} else {
$new[] = $entry;
}
}
}
}
$tpldir->close();
ksort($tplarray);
ksort($langarray);
$templates = $languages = '';
$allowedittpls = checkpermission('tpledit', 0);
foreach($tplarray as $tpl => $subtpls) {
$templates .= "<ul><li><b>$tpl</b><ul>\n";
foreach($subtpls as $subtpl) {
$filename = "$subtpl.htm";
$resetlink = '';
if(in_array($filename, $differ)) {
$subtpl = '<font color=\'#FF0000\'>'.$subtpl.'</font>';
$resetlink = " <a href=\"admincp.php?action=tpledit&templateid=$template[templateid]&fn=$filename&reset=yes\">[$lang[templates_reset]]</a>";
}
if(in_array($filename, $new)) {
$subtpl = '<font color=\'#00FF00\'>'.$subtpl.'</font>';
}
if($allowedittpls) {
$templates .= "<li>$subtpl <a href=\"admincp.php?action=tpledit&templateid=$template[templateid]&fn=$filename&keyword=$keywordenc\">[$lang[edit]]</a> ".
"<a href=\"admincp.php?action=tpledit&templateid=$template[templateid]&fn=$filename&delete=yes\">[$lang[delete]]</a>$resetlink";
} else {
$templates .= "<li>$subtpl <a href=\"admincp.php?action=tpledit&templateid=$template[templateid]&fn=$filename&keyword=$keywordenc\">[$lang[view]]</a> ";
}
}
$templates .= "</ul></ul>\n";
}
foreach($langarray as $langpack) {
$resetlink = '';
$langpackname = $langpack;
if(is_array($differ) && in_array($langpack.'.lang.php', $differ)) {
$langpackname = '<font color=\'#FF0000\'>'.$langpackname.'</font>';
$resetlink = " <a href=\"admincp.php?action=tpledit&templateid=$template[templateid]&fn=$langpack.lang.php&reset=yes\">[$lang[templates_reset]]</a>";
}
if($allowedittpls) {
$languages .= "<ul><li>$langpackname <a href=\"admincp.php?action=tpledit&templateid=$template[templateid]&fn=$langpack.lang.php\">[$lang[edit]]</a>";
$languages .= $template['templateid'] != 1 ? " <a href=\"admincp.php?action=tpledit&templateid=$template[templateid]&fn=$langpack.lang.php&delete=yes\">[$lang[delete]]</a>" : '';
$languages .= "$resetlink</ul>\n";
} else {
$languages .= "<ul><li>$langpackname <a href=\"admincp.php?action=tpledit&templateid=$template[templateid]&fn=$langpack.lang.php\">[$lang[view]]</a>";
$languages .= "</ul>\n";
}
}
shownav('templates_maint');
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tableborder">
<tr class="header"><td colspan="3"><?=$lang['templates_maint']?> - <?=$template['name']?></td></tr>
<form method="post" action="admincp.php?action=tpladd&edit=<?=$edit?>&">
<input type="hidden" name="formhash" value="<?=FORMHASH?>">
<tr class="altbg2"><td width="25%"><?=$lang['templates_maint_new']?></td>
<td width="55%"><input type="text" name="name" size="40" maxlength="40"></td>
<td width="20%"><input class="button" type="submit" value="<?=$lang['submit']?>"></td></tr></form>
<form method="get" action="admincp.php">
<input type="hidden" name="action" value="templates">
<input type="hidden" name="edit" value="<?=$edit?>">
<tr class="altbg1"><td><?=$lang['templates_maint_search']?></td><td><input type="text" name="keyword" size="40"></td>
<td><input class="button" type="submit" value="<?=$lang['submit']?>"></td></tr></form>
</table><br>
<?
showtips($warning);
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tableborder">
<tr class="header"><td><?=$lang['templates_select']?><?=$keywordadd?></td></tr>
<tr class="altbg1"><td>
<ul><li><b>Discuz! <?=$lang['templates_language_pack']?></b><?=$languages?></ul>
<ul><li><b>Discuz! <?=$lang['templates_html']?></b><?=$templates?></ul>
</td></tr></table>
<?
}
} elseif($action == 'tplcopy') {
checkpermission('tpledit');
$query = $db->query("SELECT directory FROM {$tablepre}templates WHERE templateid='$templateid'");
if(!$srctemplate = $db->fetch_array($query)) {
cpmsg('templates_edit_nonexistence');
}
$query = $db->query("SELECT directory FROM {$tablepre}templates WHERE templateid='$copyto'");
if(!$desctemplate = $db->fetch_array($query)) {
cpmsg('templates_edit_nonexistence');
}
if(!file_exists(DISCUZ_ROOT.$desctemplate['directory'])) {
$directory = $desctemplate['directory'];
cpmsg('templates_directory_invalid');
}
$newfilename = DISCUZ_ROOT.$desctemplate['directory']."/$fn";
if(file_exists($newfilename) && !$confirmed) {
cpmsg('templates_desctpl_exists', "admincp.php?action=tplcopy&templateid=$templateid&fn=$fn©to=$copyto", 'form');
}
if(!copy(DISCUZ_ROOT."./$srctemplate[directory]/$fn", $newfilename)) {
cpmsg('templates_tplcopy_invalid');
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -