http://www.php230.com/discuz-add-a-new-page.html

 

下面就简单介绍一下discuz添加页面的方法:

1、在根目录添加photo.php文件,代码如下

1、在根目录添加photo.php文件,代码如下

<?php
/**
 * 修改【图说天下】版本帖子发布时间
 * Created by PhpStorm.
 * User: sumiaowen
 * Date: 14-1-20
 * Time: 下午3:52
 * To change this template use File | Settings | File Templates.
 */
define('CURSCRIPT', 'photo');
require_once './source/class/class_core.php';
$discuz = & discuz_core::instance();
$discuz->init();
include template("diy:photo/modify");

include './photo/class_photo.php';
$photo = new photo();
$photo->updateDateline();



2、添加模板文件,./template/default/photo/modify.htm(相对根目录)
<!DOCTYPE html>
<html>
<head>
	<title>修改【图说天下】版本帖子发布时间</title>
	<meta charset="GBK">
</head>
<body>
<h2>【图说天下】版块帖子发布时间修改</h2>

<div style="margin-left: 20px;">
	<form action="photo.php" method="post">
		帖子ID:<input type="text" name="tid" value=""/>
		<input type="submit" name="submit" value="修改" style="cursor: pointer"/>
	</form>
	<p style="font-size: 13px;">注:</p>
	<p style="font-size: 13px;">1、只能修改【图说天下】版块下的帖子</p>
	<p style="font-size: 13px;">2、帖子修改时间默认为当前时间.</p>
</div>
</body>
</html>

注意:discuz静态文件的后缀名为htm

3、添加处理类,./photo/class_photo.php(相对根目录),代码如下:

<?php
/**
 * 修改【图说天下】版本帖子发布时间
 * Created by PhpStorm.
 * User: sumiaowen
 * Date: 14-1-20
 * Time: 下午4:30
 * To change this template use File | Settings | File Templates.
 */
if(!defined('IN_DISCUZ'))
{
	exit('Access Denied');
}

class photo
{
	public function updateDateline()
	{
		global $_G;

		if(isset($_POST['submit']))
		{
			//获取帖子tid
			$tid = (int)$_G['gp_tid'];

			//获取帖子信息
			$query = DB::query("select * from " . DB::table('forum_thread') . " where tid={$tid} and fid=393");

			$result = DB::fetch($query);

			//判断帖子存在
			if($result)
			{
				//更新帖子时间
				$ctime = $_SERVER['REQUEST_TIME'];

				$sql = "update com_forum_thread as t,com_forum_post as p
						set t.dateline={$ctime},p.dateline={$ctime}
						where t.tid={$tid} and p.tid={$tid} and p.`first`=1";

				if(DB::query($sql))
				{
					echo "<span style='color:blue;'>SUCCESS:</span>Successfully modified post {$tid}. New Times is " . date('Y-m-d H:i:s', $ctime);
				}
				else
				{
					echo "<span style='color:Red;'>ERROR:Failure modified. Please try again later.</span>";
				}
			}
			else
			{
				echo "<span style='color:Red;'>ERROR:The tid of {$tid}  is not existence!</span>";
			}
		}

	}
}
提示:这里没有对操作权限进行限制。为了安全,建议还是要添加操作权限控制。

通过上面3步就可以完成新页面添加了,我们可以通过URL:http://www.test.com/photo.php进行新页面访问了。

如果新页面是静态页面,那么第三步就没有必要了。

posted on 2014-12-09 00:29  infosz.com  阅读(243)  评论(0编辑  收藏  举报