模拟discuz发帖的类实现
一直想弄个discuz的数据采集程序,这2天研究了下discuz发帖涉及的几个数据库表,这里分享一下自己的处理方法。
discuz发表主题设计的几个表:(这里列出了主要的几个相关的表)
1、主题表 pre_forum_thread:这个表一个主要数据就是 tid 主题ID
2、post 分表协调表 pre_forum_post_tableid:这里需要获取一个自增的 pid
3、帖子表 pre_forum_post :记录主题pid、fid、tid、title、content等主要信息
4、版块表 pre_forum_forum:这里主要更新版块的主题、帖子数量
5、帖子主题审核数据表 pre_forum_thread_moderate:这个可以根据自己状况决定,并不是必须的
6、用户统计表 pre_common_member_count:主要是更新用户的主题数量
自己处理发帖主要涉及到了上面6个数据库表,其中第5个不是必须的。想了解discuz 数据库相关信息可以查看:http://faq.comsenz.com/library/database/x25/x25_index.htm
大致流程是这样的:
第一步:向 主题表 pre_forum_thread 中插入版块ID、用户ID、用户名、帖子标题、发帖时间等信息。
第二步:获取第一步插入表 pre_forum_thread 的数据ID,作为主题ID,即 tid
第三步:向 post 分表协调表 pre_forum_post_tableid 插入一条数据,这张表中只有一个自增字段 pid
第四步:获取 第三步 插入表 pre_forum_post_tableid 的数据ID,作为 pid
第五部:向帖子表 pre_forum_post 中插入帖子相关信息,这里需要注意的是: pid为第四部的pid值,tid为第二步的tid值
第六部:更新版块 pre_forum_forum 相关主题、帖子数量信息
第七步:更新用户 pre_common_member_count 帖子数量信息
discuz发帖过程主要就是以上7个步骤,通过这几个步骤就可以完成对实现discuz的发帖流程,其中设计到一些积分等其他信息的可以自己加上。
<?php
date_default_timezone_set('PRC');
include 'db.class.php'; class post
{
private $host = 'localhost';
private $username = 'root';
private $password = '123456';
private $database_name = 'ultrax';
private $_db = null; private $fid = null;
private $title = null;
private $content = null;
private $author = null;
private $author_id = null;
private $current_time = null;
private $displayorder = null; //0:正常,-2:待审核 public function __construct($fid, $title, $content, $author, $author_id, $displayorder = -2)
{
$this->_db = db::get_instance($this->host, $this->username, $this->password, $this->database_name); $this->fid = $fid;
$this->title = $title;
$this->content = $content;
$this->author = $author;
$this->author_id = $author_id;
$this->current_time = time();
$this->displayorder = $displayorder;
} public function post_posts()
{
$tid = $this->do_pre_forum_thread(); if(!$tid)
{
return '更新表 pre_forum_thread 失败<br />';
} $pid = $this->do_pre_forum_post_tableid(); if(!$this->do_pre_forum_post($pid, $tid))
{
return '更新表 pre_forum_post 失败<br />';
} if(!$this->do_pre_forum_forum())
{
return '更新表 pre_forum_forum 失败<br />';
} if($this->displayorder == -2)
{
if(!($this->do_pre_forum_thread_moderate($tid)))
{
return '更新表 pre_forum_thread_moderate 失败<br />';
}
} return ($this->do_pre_common_member_count()) ? '发帖成功<br />' : '更新表 pre_pre_common_member_count 失败<br />';
} private function do_pre_forum_thread()
{
$data = array();
$data['fid'] = $this->fid;
$data['author'] = $this->author;
$data['authorid'] = $this->author_id;
$data['subject'] = $this->title;
$data['dateline'] = $this->current_time;
$data['lastpost'] = $this->current_time;
$data['lastposter'] = $this->author;
$data['displayorder'] = $this->displayorder; $result = $this->_db->insert($data, 'pre_forum_thread'); if($result == 1)
{
$tid = $this->get_last_id();
} return $tid;
} private function do_pre_forum_post_tableid()
{
$sql = "INSERT INTO `pre_forum_post_tableid`(`pid`) VALUES(NULL)";
$result = $this->_db->query($sql);
if($result == 1)
{
$pid = $this->get_last_id();
} return $pid;
} private function do_pre_forum_post($pid, $tid)
{
$data = array();
$data['pid'] = $pid;
$data['fid'] = $this->fid;
$data['tid'] = $tid;
$data['first'] = 1;
$data['author'] = $this->author;
$data['authorid'] = $this->author_id;
$data['subject'] = $this->title;
$data['dateline'] = $this->current_time;
$data['message'] = $this->content; $result = $this->_db->insert($data, 'pre_forum_post'); return ($result == 1) ? true : false;
} private function do_pre_forum_forum()
{
$sql = "UPDATE `pre_forum_forum` SET `threads`=threads+1,`posts`=posts+1,`todayposts`=todayposts+1 WHERE `fid`={$this->fid}"; $result = $this->_db->query($sql); return ($result == 1) ? true : false;
} private function do_pre_forum_thread_moderate($tid)
{
$data = array();
$data['tid'] = $tid;
$data['status'] = 0;
$data['dateline'] = $this->current_time; $result = $this->_db->insert($data, 'pre_forum_thread_moderate'); return ($result == 1) ? true : false;
} private function do_pre_common_member_count()
{
$sql = "UPDATE `pre_common_member_count` SET `threads`=threads+1 WHERE `uid`={$this->author_id}"; $result = $this->_db->query($sql); return ($result == 1) ? true : false;
} private function get_last_id()
{
$sql = "SELECT LAST_INSERT_ID()";
$result = mysql_query($sql); while($row = mysql_fetch_assoc($result))
{ $id = $row['LAST_INSERT_ID()'];
} return $id;
}
}
转自:http://blog.csdn.net/laiqun_ai/article/details/49586917
模拟discuz发帖的类实现的更多相关文章
- [PHP自动化-进阶]004.Snoopy VS CURL 模拟Discuz.net登陆
引言:采集论坛第一步就是要模拟登陆,由于各个站点登录表单各不相同,验证方式又是多种多样,所以直接提交用户名密码到登录页面就比较繁琐. 所以我们采用cookie来模拟登陆无疑是最佳捷径. 今天我们要处理 ...
- 04 http协议模拟登陆发帖
<?php require('./http.class.php'); $http = new Http('http://home.verycd.com/cp.php?ac=pm&op=s ...
- C# Socket 模拟http服务器帮助类
0x01 写在前面 0x02 Http协议 0x03 TCP/IP 0x04 看代码 0x05 总结 0x01 写在前面 由于工作中,经常需要在服务器之间,或者进程之间进行通信,分配任务等.用Sock ...
- 如何让c语言使用结构体近似模拟c++中的类
如今统治市场的主流编程语言,如c++,java,大都是面向对象类型的编程语言. 而众所周知,c语言是面向过程的编程语言,但是它拥有一个类似于类的结构,叫做结构体,主要的区别在于结构体无法定义函数. 因 ...
- 从零到有模拟实现一个Set类
前言 es6新增了Set数据结构,它允许你存储任何类型的唯一值,无论是原始值还是对象引用.这篇文章希望通过模拟实现一个Set来增加对它的理解. 原文链接 用在前面 实际工作和学习过程中,你可能也经常用 ...
- Qt模拟C#的File类对文件进行操作
其实只是QT菜鸟为了练习而搞出来的 文件头: #include <QFile> #include <QString> #include <iostream> #in ...
- C#模拟登录的htmlHelper类
public class HTMLHelper { /// <summary> /// 获取CooKie /// /// </summary> /// /// <para ...
- Discuz模拟批量上传附件发帖
简介 对于很多用discuz做资源下载站来说,一个个上传附件,发帖是很繁琐的过程.如果需要批量上传附件发帖,就需要去模拟discuz 上传附件的流程. 模拟上传 discuz 附件逻辑 dz附件储存在 ...
- discuz 模拟批量上传附件发帖
discuz 模拟批量上传附件发帖 简介 对于很多用discuz做资源下载站来说,一个个上传附件,发帖是很繁琐的过程.如果需要批量上传附件发帖,就需要去模拟discuz 上传附件的流程. 插件地址 h ...
随机推荐
- input标签name与value区别
id是唯一标识符,不允许有重复值(类似数据表的主键)可以通过它的值来获得对应的html标签对象.(如果在同一页面代码中,出现重复的id,会导致不可预料的错误) name:单独地在一个网页里面,一个控件 ...
- iOS系统tabbar图标出现重影问题
大家在自定义tabbar的时候会将系统的tabbar干掉,然后放上自已自定义的tabbar(含有想要的Button)对不对,具体代码如下: /** * 添加自定义的tabBar */ -(void)a ...
- 古典问题rabbit
/**古典问题: * 有一对兔子,从出生后第三个月起每个月都生一对兔子, * 小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死, * 问每个月的兔子总数为多少? * 程序分析:兔子的规律为数列: ...
- JUnit4参数的使用
用JUnit4进行参数化测试 参数化测试是一个JUnit 3不具备的功能. 基本使用方法 @RunWith 当类被@RunWith注解修饰,或者类继承了一个被该注解修饰的类,JUnit将会使用这个注解 ...
- Exchange 基本命令累计
Get-ExchangeServer | fl name,edition,admindisplayversion //查看exchange服务器版本
- MFC如何隐藏RibbonBar的QAT QuickAccessToolBar(快速访问工具栏)
在CMainFrame的中的OnCreate函数中找到 m_wndRibbonBar.LoadFromResource(IDR_RIBBON); 在这一行的下面添加 CMFCRibbonQuickAc ...
- linux和windows共享文件
开发板的文档上说可以使用nfs共享文件夹,提供的命令如下: mount –t nfs –o nolock 192.168.1.244:/usr/ /mnt/ 因此我在我的win10上设了共享文件夹,然 ...
- maven不打包子模块资源文件
在maven多模块项目中,对子模块中的测试文件不需要打包到目标项目中,以免产生影响.实现方法: 1. 将测试资源放在java/test/resources 目录下,mvn package默认不会将te ...
- Emgu学习手册
作为opencv的c#封装库.emgu可以满足基本的图像处理功能,经过测试,效果还可以,主要用于windows窗体应用程序的开发,或者wpf,你可以用来做ocr,也可以用来做人脸识别或者可以用来做定位 ...
- asd
弹出输入提示框 :window.prompt(); 24. 指定当前显示链接的位置 :window.location.href="URL" 25. 取出窗体中的所有表单的数量 :d ...