Discuz! 论坛软件系统 big5

源代码在线查看: templates.inc.php

软件大小: 2576 K
上传用户: machao844655
关键词: Discuz big5 论坛 软件系统
下载地址: 免注册下载 普通下载 VIP

相关代码

								
				/*
					[DISCUZ!] admin/templates.inc.php - add or edit templates
					This is NOT a freeware, use is subject to license terms
				
					Version: 4.0.0
					Web: http://www.comsenz.com
					Copyright: 2001-2005 Comsenz Technology Ltd.
					Last Modified: 2004/12/12 12:08
				*/
				
				if(!defined('IN_DISCUZ') || !isset($PHP_SELF) || !preg_match("/[\/\\\\]admincp\.php$/", $PHP_SELF)) {
				        exit('Access Denied');
				}
				
				cpheader();
				
				if($action == 'templates') {
				
					if(!$edit) {
				
						if(!submitcheck('tplsubmit')) {
				
							$templates = '';
							$query = $db->query("SELECT * FROM {$tablepre}templates");
							while($tpl = $db->fetch_array($query)) {
								$templates .= "\n".
									"\n".
									"\n".
									"$tpl[copyright]\n".
									"[$lang[detail]]\n";
							}
				
				?>
				
												
				
				
				
				 
				
																				
												
						} else {
				
							if($newname) {
								if(!$newdirectory) {
									cpmsg('templates_new_directory_invalid');
								} elseif(!tpldir_valid($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(!tpldir_valid($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 = $comma = '';
								foreach($delete as $id) {
									$ids .= "$comma'$id'";
									$comma = ', ';
								}
								$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(!tpldir_valid($template['directory'])) {
							$directory = $template['directory'];
							cpmsg('templates_directory_invalid');
						}
				
						$warning = $template['templateid'] == 1 ?
								$lang['templates_edit_default_comment'] :
								$lang['templates_edit_nondefault_comment'];
						if($keyword) {
							$keywordadd = " - $lang[templates_keyword] ".htmlspecialchars(stripslashes($keyword))." - [ $lang[templates_view_all] ]";
							$keywordenc = rawurlencode($keyword);
						}
				
						$tpldir = dir(DISCUZ_ROOT.'./'.$template['directory']);
						$tplarray = $langarray = array();
						while($entry = $tpldir->read()) {
							$extension = strtolower(fileext($entry));
							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;
								}
							} elseif($extension == 'php') {
								$langarray[] = substr($entry, 0, -9);
							}
						}
						$tpldir->close();
				
						ksort($tplarray);
						ksort($langarray);
						$templates = $languages = '';
				
						foreach($tplarray as $tpl => $subtpls) {
							$templates .= "$tpl\n";
							foreach($subtpls as $subtpl) {
								$filename = "$subtpl.htm";
								$templates .= "$subtpl   [$lang[edit]] ".
									"[$lang[delete]]";
							}
							$templates .= "\n";
						}
						foreach($langarray as $langpack) {
							$languages .= "$langpack   [$lang[edit]]\n";
						}
				
				?>
								
				
												
				
								
				
				
								
								
				
				
								
								Discuz! 
				Discuz! 
				
								
					}
							
				} elseif($action == 'tpledit') {
				
					$query = $db->query("SELECT * FROM {$tablepre}templates WHERE templateid='$templateid'");
					if(!$template = $db->fetch_array($query)) {
						cpmsg('templates_edit_nonexistence');
					}
				
					$fn = str_replace(array('..', '/', '\\'), array('', '', ''), $fn);
					$filename = DISCUZ_ROOT."./$template[directory]/$fn";
					if(!is_writeable($filename)) {
						cpmsg('templates_edit_invalid');
					}
				
					if(!submitcheck('editsubmit') && $delete != 'yes') {
				
						$keywordenc = rawurlencode($keyword);
				
						$fp = fopen($filename, 'rb');
						$content = fread($fp, filesize($filename));
						fclose($fp);
				
						$content = str_replace("\\'", "'", htmlspecialchars($content));
				
				?>
				
				var n = 0;
				function displayHTML(obj) {
					win = window.open(" ", 'popup', 'toolbar = no, status = no, scrollbars=yes');
					win.document.write("" + obj.value + "");
				}
				function HighlightAll(obj) {
					obj.focus();
					obj.select();
					if (document.all) {
						obj.createTextRange().execCommand("Copy");
						window.status = "";
						setTimeout("window.status=''", 1800);
					}
				}
				function findInPage(obj, str) {
					var txt, i, found;
					if (str == "") {
						return false;
					}
					if (document.layers) {
						if (!obj.find(str)) {
							while(obj.find(str, false, true)) {
								n++;
							}
						} else {
							n++;
						}
						if (n == 0) {
							alert("");
						}
					}
					if (document.all) {
						txt = obj.createTextRange();
						for (i = 0; i 							txt.moveStart('character', 1);
							txt.moveEnd('textedit');
						}
						if (found) {
							txt.moveStart('character', -1);
							txt.findText(str);
							txt.select();
							txt.scrollIntoView();
							n++;
						} else {
							if (n > 0) {
								n = 0;
								findInPage(str);
							} else {
								alert("");
							}
						}
					}
					return false;
				}
				
																				 - 
								
				
																								
				
				
								
					} elseif($delete == 'yes') {
				
						if(!$confirmed) {
							cpmsg('templates_delete_confirm', "admincp.php?action=tpledit&templateid=$templateid&fn=$fn&delete=yes", 'form');
						} else {
							if(@unlink($filename)) {
								cpmsg('templates_delete_succeed', "admincp.php?action=templates&edit=$templateid");
							} else {
								cpmsg('templates_delete_fail');
							}
						}
				
					} else {
				
						$fp = fopen($filename, 'wb');
						flock($fp, 2);
						fwrite($fp, stripslashes(str_replace("\x0d\x0a", "\x0a", $templatenew)));
						fclose($fp);
				
						cpmsg('templates_edit_succeed', "admincp.php?action=templates&edit=$templateid&keyword=$keyword");
				
					}
				
				} elseif($action == 'tpladd') {
				
					$query = $db->query("SELECT * FROM {$tablepre}templates WHERE templateid='$edit'");
					if(!$template = $db->fetch_array($query)) {
						cpmsg('templates_add_invalid');
					} elseif(!tpldir_valid($template['directory'])) {
						$directory = $template['directory'];
						cpmsg('templates_directory_invalid');
					} elseif(file_exists(DISCUZ_ROOT."./$template[directory]/$name.htm")) {
						cpmsg('templates_add_duplicate');
					} elseif(!@$fp = fopen(DISCUZ_ROOT."./$template[directory]/$name.htm", 'wb')) {
						cpmsg('templates_add_file_invalid');
					}
				
					@fclose($fp);
					cpmsg('templates_add_succeed', "admincp.php?action=tpledit&templateid=1&fn=$name.htm");
					
				}	
				
				?>			

相关资源