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

📄 upgrade7.php

📁 Discuz功能源码(开源)
💻 PHP
📖 第 1 页 / 共 2 页
字号:

	if($step == 1) {

		dir_clear('./forumdata/cache');
		dir_clear('./forumdata/templates');

		if(!dir_writeable('./forumdata/threadcaches')) {
			echo '升级检测失败,无法建立目录 /forumdata/threadcaches,请手工建立此目录,然后重新运行升级程序';
			exit;
		}

		runquery($upgrade1);

		echo "第 $step 步升级成功<br><br>";
		redirect("?action=upgrade&step=".($step+1));

	} elseif($step == 2) {

		runquery($upgrade2);

		echo "第 $step 步升级成功<br><br>";
		redirect("?action=upgrade&step=".($step+1));

	} elseif($step == 3) {

		runquery($upgrade3);

		echo "第 $step 步升级成功<br><br>";
		redirect("?action=upgrade&step=".($step+1));

	} elseif($step == 4) {

		runquery($upgrade4);

		echo "第 $step 步升级成功<br><br>";
		redirect("?action=upgrade&step=".($step+1));

	} elseif($step == 5) {

		runquery($upgrade5);

		echo "第 $step 步升级成功<br><br>";
		redirect("?action=upgrade&step=".($step+1));

	} elseif($step == 6) {

		runquery($upgrade6);

		echo "第 $step 步升级成功<br><br>";
		redirect("?action=upgrade&step=".($step+1));

	} elseif($step == 7) {

		$limit = 500; // 每次升级多少投票主题
		$start = intval($start);
		$next = FALSE;

		$query = $db->query("SELECT tid, pollopts from {$tablepre}polls_temp LIMIT $start, $limit");
		while($array = $db->fetch_array($query)) {

			$next = TRUE;

			$polltid = $array['tid'];
			$pollopts = unserialize($array['pollopts']);

			if(!empty($pollopts['options'])) {
				foreach($pollopts['options'] as $temp_options) {
					$db->query("REPLACE INTO {$tablepre}polloptions (tid, votes, polloption) VALUES ('$polltid', '$temp_options[1]', '$temp_options[0]')");
				}
			}

			if($pollopts['multiple']) {
				$maxchoices = 0;
			} else {
				$maxchoices = 1;
			}

			$closedquery = $db->query("SELECT closed FROM {$tablepre}threads WHERE tid='$polltid'");
			$closed = $db->result($closedquery, 0);
			$expiration = $closed ? $timestamp : 0;

			$db->query("REPLACE INTO {$tablepre}polls (tid, multiple, visible, maxchoices, expiration) VALUES ('$polltid', '$pollopts[multiple]', '1', '$maxchoices', '$expiration')");

		}

		if($next) {
			echo "正在进行第 $step 步升级 起始列数: $start<br><br>";
			redirect("?action=upgrade&step=$step&start=".($start+$limit));
		} else {
			$db->query("DROP TABLE IF EXISTS cdb_polls_temp");
			echo "第 $step 步升级成功<br><br>";
			redirect("?action=upgrade&step=".($step+1));
		}

	} elseif($step == 8) {

		$limit = 500; // 每次升级多少附件
		$next = FALSE;
		$start = $start ? intval($start) : 0;

		$query = $db->query("SELECT a.aid, a.filetype, p.authorid FROM {$tablepre}attachments a, {$tablepre}posts p WHERE a.pid=p.pid LIMIT $start, $limit");
		while($data = $db->fetch_array($query)) {
			$next = TRUE;
			$isimage = substr($data['filetype'], 0, 5) == 'image' ? '1' : '0';
			$db->query("UPDATE {$tablepre}attachments SET isimage='$isimage', uid='$data[authorid]' WHERE aid='$data[aid]'");
		}

		if($next) {
			redirect("?action=upgrade&step=$step&start=".($start + $limit));
		} else {
			echo "第 $step 步升级成功<br><br>";
			redirect("?action=upgrade&step=".($step+1));
		}

	} elseif($step == 9) {

		$limit = 100; // 每次升级多少栏目板块
		$next = FALSE;
		$start = $start ? intval($start) : 0;

		$query = $db->query("SELECT fid, threadtypes FROM {$tablepre}forumfields WHERE 1 LIMIT $start, $limit");
		while($forum = $db->fetch_array($query)) {
			$next = TRUE;
			$forum['threadtypes'] = unserialize($forum['threadtypes']);

			if(!empty($forum['threadtypes']['types'])) {
				$newthreadtypes = addslashes(serialize(array
					(
					'required' => (bool)$forum['threadtypes']['required'],
					'listable' => (bool)$forum['threadtypes']['listable'],
					'prefix' => (bool)$forum['threadtypes']['prefix'],
					'types' => $forum['threadtypes']['types'],
					'selectbox' => '',
					'flat' => $forum['threadtypes']['types'],
					)));
			} else {
				$newthreadtypes = '';
			}
			$db->query("UPDATE {$tablepre}forumfields SET threadtypes='$newthreadtypes' WHERE fid='$forum[fid]'");
		}

		if($next) {
			redirect("?action=upgrade&step=$step&start=".($start + $limit));
		} else {
			echo "第 $step 步升级成功<br><br>";
			redirect("?action=upgrade&step=".($step+1));
		}

	} elseif($step == 10) {

		$query = $db->query("SELECT styleid FROM {$tablepre}styles ORDER BY styleid DESC LIMIT 1");
		$styleid = intval($db->result($query, 0));
		$newstyleid = $styleid + 1;

		$db->query("REPLACE INTO {$tablepre}settings (variable, value) VALUES ('indexname', 'index.php')");
		$db->query("REPLACE INTO {$tablepre}styles (styleid, name, available, templateid) VALUES ('$newstyleid', 'Discuz! 5 Default', '1', '1')");
		$db->query("REPLACE INTO {$tablepre}stylevars (styleid, variable, substitute) VALUES
			('$newstyleid', 'boardimg', 'logo.gif'),
			('$newstyleid', 'nobold', '0'),
			('$newstyleid', 'msgfontsize', '12px'),
			('$newstyleid', 'fontsize', '12px'),
			('$newstyleid', 'font', 'Tahoma, Verdana'),
			('$newstyleid', 'tablespace', '4'),
			('$newstyleid', 'tablewidth', '98%'),
			('$newstyleid', 'borderwidth', '1'),
			('$newstyleid', 'text', '#333333'),
			('$newstyleid', 'tabletext', '#333333'),
			('$newstyleid', 'catcolor', '#FFFFD9'),
			('$newstyleid', 'headertext', '#154BA0'),
			('$newstyleid', 'headercolor', 'header_bg.gif'),
			('$newstyleid', 'bordercolor', '#86B9D6'),
			('$newstyleid', 'link', '#154BA0'),
			('$newstyleid', 'altbg2', '#FFFFFF'),
			('$newstyleid', 'altbg1', '#F5FBFF'),
			('$newstyleid', 'bgcolor', '#FFFFFF'),
			('$newstyleid', 'imgdir', 'images/default'),
			('$newstyleid', 'smdir', 'images/smilies'),
			('$newstyleid', 'cattext', '#92A05A'),
			('$newstyleid', 'smfontsize', '11px'),
			('$newstyleid', 'smfont', 'Arial, Tahoma'),
			('$newstyleid', 'maintablewidth', '98%'),
			('$newstyleid', 'maintablecolor', '#FFFFFF'),
			('$newstyleid', 'innerborderwidth', '0'),
			('$newstyleid', 'innerbordercolor', '#D6E0EF'),
			('$newstyleid', 'bgborder', '#BBE9FF'),
			('$newstyleid', 'inputborder', '#7AC4EA'),
			('$newstyleid', 'mainborder', '#154BA0'),
			('$newstyleid', 'catborder', '#DEDEB8'),
			('$newstyleid', 'lighttext', '#666666'),
			('$newstyleid', 'headermenu', 'menu_bg.gif'),
			('$newstyleid', 'postnoticebg', '#FDFFF2'),
			('$newstyleid', 'msgheader', '#F3F8D7'),
			('$newstyleid', 'msgheadertext', '#000000'),
			('$newstyleid', 'msgtext', '#FDFFF2'),
			('$newstyleid', 'headermenutext', '#154BA0'),
			('$newstyleid', 'navtext', '#154BA0'),
			('$newstyleid', 'menubg', '#D9EEF9'),
			('$newstyleid', 'menutext', '#154BA0'),
			('$newstyleid', 'menuhltext', '#FFFFFF'),
			('$newstyleid', 'menuhlbg', '#7AC4EA'),
			('$newstyleid', 'calendartext', '#000000'),
			('$newstyleid', 'calendarexpire', '#999999'),
			('$newstyleid', 'calendarchecked', '#FF0000'),
			('$newstyleid', 'calendartoday', '#00BB00');");
		$db->query("UPDATE {$tablepre}settings SET value = '$newstyleid' WHERE variable = 'styleid'");
		$db->query("UPDATE {$tablepre}members SET styleid = '0'");
		$db->query("UPDATE {$tablepre}styles SET available = '0' WHERE styleid != '$newstyleid'");

		echo "第 $step 步升级成功<br><br>";
		redirect("?action=upgrade&step=".($step+1));

	} elseif($step == 11) {

		$start = $start ? intval($start) : 1;

		if($start == 1) {
			$supe = array();
			$query = $db->query("SELECT * FROM {$tablepre}settings WHERE variable IN ('supe_maxupdateusers', 'supe_status', 'supe_siteurl', 'supe_sitename', 'supe_tablepre')");
			while($setting = $db->fetch_array($query)) {
				$supe[$setting['variable']] = $setting['value'];
			}
			$db->query("REPLACE INTO {$tablepre}settings (variable, value) VALUES ('supe_maxupdateusers', '$supe[supe_maxupdateusers]')");
			$db->query("REPLACE INTO {$tablepre}settings (variable, value) VALUES ('supe_status', '$supe[supe_status]')");
			$db->query("REPLACE INTO {$tablepre}settings (variable, value) VALUES ('supe_siteurl', '$supe[supe_siteurl]')");
			$db->query("REPLACE INTO {$tablepre}settings (variable, value) VALUES ('supe_sitename', '$supe[supe_sitename]')");
			$db->query("REPLACE INTO {$tablepre}settings (variable, value) VALUES ('supe_tablepre', '$supe[supe_tablepre]')");

			$db->query("ALTER TABLE {$tablepre}forumfields ADD supe_pushsetting TEXT NOT NULL", 'SILENT');
			$db->query("ALTER TABLE {$tablepre}admingroups ADD supe_allowpushthread tinyint(1) NOT NULL default '0'", 'SILENT');
			$db->query("UPDATE {$tablepre}admingroups SET supe_allowpushthread='1' WHERE admingid='1'", 'SILENT');

			echo "第 $step 步 步骤[ $start ] 升级成功<br><br>";
			redirect("?action=upgrade&step=$step&start=2");

		} else {

			$db->query("ALTER TABLE {$tablepre}members ADD xspacestatus tinyint(1) NOT NULL default '0'", 'SILENT');
			$db->query("ALTER TABLE {$tablepre}threads ADD itemid mediumint(8) unsigned NOT NULL default '0'", 'SILENT');
			$db->query("ALTER TABLE {$tablepre}threads ADD supe_pushstatus tinyint(1) NOT NULL default '0'", 'SILENT');

			echo "第 $step 步 步骤[ $start ] 升级成功<br><br>";
			redirect("?action=upgrade&step=".($step+1));

		}

	} else {

		echo '<br>恭喜您论坛数据升级成功,接下来请您:<ol><li><b>必删除本程序</b>'.
			'<li>使用管理员身份登录论坛,进入后台,更新缓存'.
			'<li>进行论坛注册、登录、发贴等常规测试,看看运行是否正常'.
			'<li>如果您希望启用 <b>'.$version_new.'</b> 提供的新功能,你还需要对于论坛基本设置、栏目、会员组等等进行重新设置</ol><br><br>'.
			'<b>感谢您选用我们的产品!</b>';
		exit;
	}
}

function dir_clear($dir) {
	$directory = dir($dir);
	while($entry = $directory->read()) {
		$filename = $dir.'/'.$entry;
		if(is_file($filename)) {
			@unlink($filename);
		}
	}
	$directory->close();
}

function dir_writeable($dir) {
	if(!is_dir($dir)) {
		@mkdir($dir, 0777);
	}
	if(is_dir($dir)) {
		if($fp = @fopen("$dir/test.test", 'w')) {
			@fclose($fp);
			@unlink("$dir/test.test");
			$writeable = 1;
		} else {
			$writeable = 0;
		}
	}
	return $writeable;
}

function daddslashes($string) {
	if(is_array($string)) {
		foreach($string as $key => $val) {
			$string[$key] = daddslashes($val, $force);
		}
	} else {
		$string = addslashes($string);
	}
	return $string;
}

function loginit($log) {
	global $lang;

	$fp = @fopen('./forumdata/'.$log.'.php');
	@fwrite($fp, "<?PHP exit(\"Access Denied\"); ?>\n");
	@fclose($fp);
}

function runquery($query) {
	global $db, $tablepre, $dbcharset;
	$expquery = explode(";", $query);
	foreach($expquery as $sql) {
		$sql = trim($sql);
		if($sql == '' || $sql[0] == '#') continue;

		$sql = str_replace(' cdb_', ' '.$tablepre, $sql);
		if(strtoupper(substr($sql, 0, 12)) == 'CREATE TABLE') {
			$db->query(createtable($sql, $dbcharset));
		} else {
			$db->query($sql);
		}
	}
}

function redirect($url) {

	echo "<script>",
		"function redirect() {window.location.replace('$url');}\n",
		"setTimeout('redirect();', 500);\n",
		"</script>",
		"<br><br><a href=\"$url\">浏览器会自动跳转页面,无需人工干预。<br>除非当您的浏览器没有自动跳转时,请点击这里</a>";
	flush();

}

function createtable($sql, $dbcharset) {
	$type = strtoupper(preg_replace("/^\s*CREATE TABLE\s+.+\s+\(.+?\).*(ENGINE|TYPE)\s*=\s*([a-z]+?).*$/isU", "\\2", $sql));
	$type = in_array($type, array('MYISAM', 'HEAP')) ? $type : 'MYISAM';
	return preg_replace("/^\s*(CREATE TABLE\s+.+\s+\(.+?\)).*$/isU", "\\1", $sql).
		(mysql_get_server_info() > '4.1' ? " ENGINE=$type default CHARSET=$dbcharset" : " TYPE=$type");
}

?>

⌨️ 快捷键说明

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