📄 templates.inc.php
字号:
<?php
/*
[Discuz!] (C)2001-2009 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: templates.inc.php 17148 2008-12-08 02:57:21Z monkey $
*/
if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
exit('Access Denied');
}
cpheader();
if(!isfounder()) cpmsg('noaccess_isfounder', '', 'error');
$operation = empty($operation) ? 'admin' : $operation;
if($operation == 'admin') {
if(!submitcheck('tplsubmit')) {
$templates = '';
$query = $db->query("SELECT * FROM {$tablepre}templates");
while($tpl = $db->fetch_array($query)) {
$templates .= showtablerow('', array('class="td25"', '', 'class="td29"'), array(
"<input class=\"checkbox\" type=\"checkbox\" name=\"delete[]\" ".($tpl[templateid] == 1 ? 'disabled ' : '')."value=\"$tpl[templateid]\">",
"<input type=\"text\" class=\"txt\" size=\"8\" name=\"namenew[$tpl[templateid]]\" value=\"$tpl[name]\">",
"<input type=\"text\" class=\"txt\" size=\"20\" name=\"directorynew[$tpl[templateid]]\" value=\"$tpl[directory]\">",
!empty($tpl['copyright']) ? $tpl['copyright'] : "<input type=\"text\" class=\"txt\" size=\"8\" name=\"copyrightnew[$tpl[templateid]]\" value=>",
"<a href=\"$BASESCRIPT?action=templates&operation=maint&id=$tpl[templateid]\" class=\"act\">$lang[detail]</a>"
), TRUE);
}
shownav('style', 'templates_admin');
showsubmenu('templates_admin');
showformheader('templates');
showtableheader();
showsubtitle(array('', 'templates_admin_name', 'dir', 'copyright', ''));
echo $templates;
echo '<tr><td>'.$lang['add_new'].'</td><td><input type="text" class="txt" size="8" name="newname"></td><td class="td29"><input type="text" class="txt" size="20" name="newdirectory"></td><td><input type="text" class="txt" size="25" name="newcopyright"></td><td> </td></tr>';
showsubmit('tplsubmit', 'submit', 'del');
showtablefooter();
showformfooter();
} else {
if($newname) {
if(!$newdirectory) {
cpmsg('tpl_new_directory_invalid', '', 'error');
} elseif(!istpldir($newdirectory)) {
$directory = $newdirectory;
cpmsg('tpl_directory_invalid', '', 'error');
}
$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('tpl_directory_invalid', '', 'error');
} elseif($id == 1 && $directory != './templates/default') {
cpmsg('tpl_default_directory_invalid', '', 'error');
}
$db->query("UPDATE {$tablepre}templates SET name='$namenew[$id]', directory='$directorynew[$id]' WHERE templateid='$id'", 'UNBUFFERED');
if(!empty($copyrightnew[$id])) {
$db->query("UPDATE {$tablepre}templates SET copyright='$copyrightnew[$id]' WHERE templateid='$id' AND copyright=''", 'UNBUFFERED');
}
}
}
if(is_array($delete)) {
if(in_array('1', $delete)) {
cpmsg('tpl_delete_invalid', '', 'error');
}
if($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('tpl_update_succeed', $BASESCRIPT.'?action=templates', 'succeed');
}
} elseif($operation == 'maint') {
if(empty($id)) {
$tplselect = "<select name=\"id\" style=\"width: 150px\">\n";
$query = $db->query("SELECT templateid, name FROM {$tablepre}templates");
while($tpl = $db->fetch_array($query)) {
$tplselect .= "<option value=\"$tpl[templateid]\">$tpl[name]</option>\n";
}
$tplselect .= '</select>';
cpmsg('templates_edit_select', $BASESCRIPT.'?action=templates&operation=maint'.(!empty($highlight) ? "&highlight=$highlight" : ''), 'form', $tplselect);
}
$template = $db->fetch_first("SELECT * FROM {$tablepre}templates WHERE templateid='$id'");
if(!$template) {
cpmsg('undefined_action', '', 'error');
} elseif(!istpldir($template['directory'])) {
$directory = $template['directory'];
cpmsg('tpl_directory_invalid', '', 'error');
}
$warning = $template['templateid'] == 1 ? 'templates_maint_default_comment' : 'templates_maint_nondefault_comment';
if($keyword) {
$keywordadd = " - $lang[templates_maint_keyword] <i>".dhtmlspecialchars(stripslashes($keyword))."</i> - <a href=\"$BASESCRIPT?action=templates&operation=maint&id=$id\">[$lang[templates_maint_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 .= "<li><h5>$tpl</h5><ul class=\"tpllist3\">";
foreach($subtpls as $subtpl) {
$filename = "$subtpl.htm";
$resetlink = '';
if(in_array($filename, $differ)) {
$subtpl = '<font color=\'#FF0000\'>'.$subtpl.'</font>';
$resetlink = " <a href=\"$BASESCRIPT?action=templates&operation=edit&templateid=$template[templateid]&fn=$filename&reset=yes\" class=\"act\">$lang[templates_maint_reset]</a>";
}
if(in_array($filename, $new)) {
$subtpl = '<font color=\'#00FF00\'>'.$subtpl.'</font>';
}
$templates .= '<li>';
if($allowedittpls) {
$templates .= "$subtpl <a href=\"$BASESCRIPT?action=templates&operation=edit&templateid=$template[templateid]&fn=$filename&keyword=$keywordenc\" class=\"act\">$lang[edit]</a> ".
"<a href=\"$BASESCRIPT?action=templates&operation=edit&templateid=$template[templateid]&fn=$filename&delete=yes\" class=\"act\">$lang[delete]</a>$resetlink";
} else {
$templates .= "$subtpl <a href=\"$BASESCRIPT?action=templates&operation=edit&templateid=$template[templateid]&fn=$filename&keyword=$keywordenc\" class=\"act\">$lang[view]</a> ";
}
$templates .= '</li>';
}
$templates .= "</ul></li>";
}
$languages .= '<ul class="tpllist3">';
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=\"$BASESCRIPT?action=templates&operation=edit&templateid=$template[templateid]&fn=$langpack.lang.php&reset=yes\" class=\"act\">$lang[templates_maint_reset]</a>";
}
$languages .= '<li>';
if($allowedittpls) {
$languages .= "$langpackname <a href=\"$BASESCRIPT?action=templates&operation=edit&templateid=$template[templateid]&fn=$langpack.lang.php\" class=\"act\">$lang[edit]</a>";
$languages .= $template['templateid'] != 1 ? " <a href=\"$BASESCRIPT?action=templates&operation=edit&templateid=$template[templateid]&fn=$langpack.lang.php&delete=yes\" class=\"act\">$lang[delete]</a>" : '';
$languages .= "$resetlink";
} else {
$languages .= "$langpackname <a href=\"$BASESCRIPT?action=templates&operation=edit&templateid=$template[templateid]&fn=$langpack.lang.php\" class=\"act\">$lang[view]</a>";
}
$languages .= '</li>';
}
$languages .= '</ul>';
shownav('style', 'templates_maint');
showsubmenu(lang('templates_maint').' - '.$template['name']);
showtips($warning);
showtableheader('', 'nobottom fixpadding');
showformheader("templates&operation=add&id=$id");
showtablerow('', array('class="td21"', 'class="td22"'), array(
lang('templates_maint_new'),
'<input type="text" class="txt" name="name" size="40" maxlength="40">',
'<input type="submit" class="btn" value="'.lang('submit').'">'
));
showformfooter();
showformheader("templates&operation=maint&id=$id");
showtablerow('', array('class="td21"', 'class="td22"'), array(
lang('templates_maint_search'),
'<input type="text" class="txt" name="keyword" size="40">',
'<input type="submit" class="btn" value="'.lang('submit').'">'
));
showformfooter();
showtablefooter();
showtableheader(lang('templates_maint_select').$keywordadd, 'notop fixpadding');
?>
<tr><td style="background:none;">
<ul class="tpllist">
<li>
<h4>Discuz! <?=$lang['templates_maint_language_pack']?></h4>
<ul class="tpllist2">
<?=$languages?>
</ul>
</li>
<li>
<h4>Discuz! <?=$lang['templates_maint_html']?></h4>
<ul class="tpllist2">
<?=$templates?>
</ul>
</li>
</ul>
</td></tr>
<?
showtablefooter();
} elseif($operation == 'copy') {
checkpermission('tpledit');
$srctemplate = $db->fetch_first("SELECT directory FROM {$tablepre}templates WHERE templateid='$templateid'");
if(!$srctemplate) {
cpmsg('tpl_edit_nonexistence', '', 'error');
}
$desctemplate = $db->fetch_first("SELECT directory FROM {$tablepre}templates WHERE templateid='$copyto'");
if(!$desctemplate) {
cpmsg('tpl_edit_nonexistence', '', 'error');
}
if(!file_exists(DISCUZ_ROOT.$desctemplate['directory'])) {
$directory = $desctemplate['directory'];
cpmsg('tpl_directory_invalid', '', 'error');
}
$newfilename = DISCUZ_ROOT.$desctemplate['directory']."/$fn";
if(file_exists($newfilename) && !$confirmed) {
cpmsg('tpl_desctpl_exists', "$BASESCRIPT?action=templates&operation=copy&templateid=$templateid&fn=$fn©to=$copyto", 'form');
}
if(!copy(DISCUZ_ROOT."./$srctemplate[directory]/$fn", $newfilename)) {
cpmsg('tpl_tplcopy_invalid', '', 'error');
}
cpmsg('tpl_tplcopy_succeed', "$BASESCRIPT?action=templates&operation=edit&templateid=$templateid&fn=$fn", 'succeed');
} elseif($operation == 'edit') {
$allowedittpls = checkpermission('tpledit', 0);
$template = $db->fetch_first("SELECT * FROM {$tablepre}templates WHERE templateid='$templateid'");
if(!$template) {
cpmsg('tpl_edit_nonexistence', '', 'error');
}
$directorys = '';
$query = $db->query("SELECT templateid, directory FROM {$tablepre}templates WHERE templateid!='$templateid' GROUP BY directory");
while($directory = $db->fetch_array($query)) {
$directorys .='<option value="'.$directory['templateid'].'">'.$directory['directory'].'</option>';
}
$fn = str_replace(array('..', '/', '\\'), array('', '', ''), $fn);
$filename = DISCUZ_ROOT."./$template[directory]/$fn";
if(!is_writeable($filename)) {
cpmsg('tpl_edit_invalid', '', 'error');
}
$keywordenc = rawurlencode($keyword);
if(!submitcheck('editsubmit') && $delete != 'yes' && $reset != 'yes') {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -