⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 templates.inc.php

📁 论坛代码网增加免费空间业务
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php

/*
	[Discuz!] (C)2001-2007 Comsenz Inc.
	This is NOT a freeware, use is subject to license terms

	$Id: templates.inc.php 13374 2008-04-11 08:04:21Z liuqiang $
*/

if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
        exit('Access Denied');
}

cpheader();
if(!isfounder()) cpmsg('noaccess_isfounder', '', 'error');

if(!$operation) {

	if(!$edit) {

		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]\">",
					$tpl['copyright'],
					"<a href=\"admincp.php?action=templates&edit=$tpl[templateid]\" class=\"act\">$lang[detail]</a>"
				), TRUE);
			}

			shownav('forum', 'nav_templates');
			showsubmenu('nav_templates');
			showformheader('templates');
			showtableheader();
			showsubtitle(array('', 'tpl_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>&nbsp;</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(is_array($delete)) {
				if(in_array('1', $delete)) {
					cpmsg('tpl_delete_invalid', '', 'error');
				}
				$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', 'admincp.php?action=templates', 'succeed');

		}

	} else {

		$template = $db->fetch_first("SELECT * FROM {$tablepre}templates WHERE templateid='$edit'");
		if(!$template) {
			cpmsg('undefined_action', '', 'error');
		} elseif(!istpldir($template['directory'])) {
			$directory = $template['directory'];
			cpmsg('tpl_directory_invalid', '', 'error');
		}

		$warning = $template['templateid'] == 1 ? 'tpl_edit_default_comment' : 'tpl_edit_nondefault_comment';
		if($keyword) {
			$keywordadd = " - $lang[tpl_keyword] <i>".dhtmlspecialchars(stripslashes($keyword))."</i> - <a href=\"admincp.php?action=templates&edit=$edit\">[$lang[tpl_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=\"admincp.php?action=templates&operation=edit&templateid=$template[templateid]&fn=$filename&reset=yes\" class=\"act\">$lang[tpl_reset]</a>";
				}
				if(in_array($filename, $new)) {
					$subtpl = '<font color=\'#00FF00\'>'.$subtpl.'</font>';
				}
				$templates .= '<li>';
				if($allowedittpls) {
					$templates .= "$subtpl &nbsp; <a href=\"admincp.php?action=templates&operation=edit&templateid=$template[templateid]&fn=$filename&keyword=$keywordenc\" class=\"act\">$lang[edit]</a> ".
						"<a href=\"admincp.php?action=templates&operation=edit&templateid=$template[templateid]&fn=$filename&delete=yes\" class=\"act\">$lang[delete]</a>$resetlink";
				} else {
					$templates .= "$subtpl &nbsp; <a href=\"admincp.php?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=\"admincp.php?action=templates&operation=edit&templateid=$template[templateid]&fn=$langpack.lang.php&reset=yes\" class=\"act\">$lang[tpl_reset]</a>";
			}
			$languages .= '<li>';
			if($allowedittpls) {
				$languages .= "$langpackname &nbsp; <a href=\"admincp.php?action=templates&operation=edit&templateid=$template[templateid]&fn=$langpack.lang.php\" class=\"act\">$lang[edit]</a>";
				$languages .= $template['templateid'] != 1 ? " <a href=\"admincp.php?action=templates&operation=edit&templateid=$template[templateid]&fn=$langpack.lang.php&delete=yes\" class=\"act\">$lang[delete]</a>" : '';
				$languages .= "$resetlink";
			} else {
				$languages .= "$langpackname &nbsp; <a href=\"admincp.php?action=templates&operation=edit&templateid=$template[templateid]&fn=$langpack.lang.php\" class=\"act\">$lang[view]</a>";
			}
			$languages .= '</li>';
		}
		$languages .= '</ul>';

		shownav('forum', 'tpl_maint');
		showsubmenu(lang('tpl_maint').' - '.$template['name']);
		showtips($warning);
		showtableheader('', 'nobottom fixpadding');

		showformheader("templates&operation=add&edit=$edit");
		showtablerow('', array('class="td21"', 'class="td22"'), array(
			lang('tpl_maint_new'),
			'<input type="text" class="txt" name="name" size="40" maxlength="40">',
			'<input type="submit" class="btn" value="'.lang('submit').'">'
		));
		showformfooter();

		showformheader("templates&edit=$edit");
		showtablerow('', array('class="td21"', 'class="td22"'), array(
			lang('tpl_maint_search'),
			'<input type="text" class="txt" name="keyword" size="40">',
			'<input type="submit" class="btn" value="'.lang('submit').'">'
		));
		showformfooter();

		showtablefooter();

		showtableheader(lang('tpl_select').$keywordadd, 'notop fixpadding');

?>

<tr><td style="background:none;">
<ul class="tpllist">
	<li>
		<h4>Discuz! <?=$lang['tpl_language_pack']?></h4>
		<ul class="tpllist2">
			<?=$languages?>
		</ul>
	</li>
	<li>
		<h4>Discuz! <?=$lang['tpl_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', "admincp.php?action=templates&operation=copy&templateid=$templateid&fn=$fn&copyto=$copyto", 'form');
	}

	if(!copy(DISCUZ_ROOT."./$srctemplate[directory]/$fn", $newfilename)) {
		cpmsg('tpl_tplcopy_invalid', '', 'error');
	}

	cpmsg('tpl_tplcopy_succeed', "admincp.php?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') {

		$islang = FALSE;
		if(preg_match('/\.lang\.php$/i', $filename)) {
			$currentlang = $lang;
			$currentmsglang = $msglang;
			unset($lang, $msglang);
			include $filename;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -