discuz 帖子模块用到的表及自动发帖函数
最近在做一个discuz的插件,由于需要程序自动生成并调用discuz已经存在插件的帖子。然而这就相当于自动发帖的功能了。网上找了一下,大部分都是通过curl模拟登陆,模拟发帖的,这显然不满足我的要求。如果采用这种方式既笨重又麻烦。百度了一通,没发现好的结果。于是google了一番,最后找到一个类似的方法。经过一番整理,于是有了下面这个函数。
discuz帖子模块用到的表:
帖子表:pre_forum_post
帖子表pid最大值设置表:pre_forum_post_tableid
帖子列表表:pre_forum_thread
帖子所在板块表:pre_forum_forum
这几个表之间的关系是,帖子表pre_forum_post存放帖子的详细信息,其pid通过pre_forum_post_tableid表获得。帖子列表pre_forum_thread表决定了该条记录是否显示在列表中,如果此表中没有相应的记录帖子也就无法显示在列表中了。帖子所在板块表pre_forum_forum存放了对应板块的发帖数量,今日发帖数以及最近发帖的标题等信息。
好了,了解了这几张表之间的关系后有了下面这个函数和测试例子。
<?php
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
echo "11111111111111111111111";
require_once DISCUZ_ROOT . './source/class/class_core.php';
$discuz = C::app();
$discuz->cachelist = $cachelist;
$discuz->init(); $subject = '自行写入帖子';
$message = '自行写入帖子的消息消息消息';
$thread['fid'] = 86;
$thread['subject'] = $subject;
$thread['message'] = $message;
$thread["authorid"]= 1;
$thread["author"]=$_G['member'][username]; $tid = addThread($thread); echo "*********** $tid **************"; /*
* 添加帖子
* @data 帖子数组
* array('fid' => '板块ID',
'subject' => '标题',
'message' => '具体内容',
'authorid' => '用户ID',
'author' => '用户名');
*/
function addThread($data){
$fid = $data['fid'];
$subject = $data['subject'];
$message = $data['message'];
$authorid = $data['authorid'];
$author = $data['author'];
$proc_time = time(); $thread['fid'] = $fid;//板块ID
$thread['subject'] = $subject;//标题
$thread["authorid"]= $authorid;
$thread["author"]= $author;
$thread["dateline"]= $proc_time;
$thread["lastpost"]= $proc_time;
$thread["lastposter"]= $author;
//插件必须添加special参数,否则无法按照插件的样式进行显示
$thread["special"]= 127;//特殊主题,1:投票;2:商品;3:悬赏;4:活动;5:辩论贴;127:插件相关 $tid=C::t('forum_thread')->insert($thread, 1);//添加到帖子列表 if($tid){
$post["tid"] = $tid;
$post['fid'] = $fid;
$post["position"]= 1;
$post["smileyoff"]= "-1";
$post["bbcodeoff"]= "-1";
$post["usesig"]= 1;
$post["author"]= $author;
$post["authorid"]= $authorid;
$post["subject"]= $subject;
$post["message"]= $message . chr(0).chr(0).chr(0) . "online_alipay";//结尾一定要加chr(0).chr(0).chr(0) . "online_alipay"结尾,否则无法调用插件的模板。
$post["dateline"]= $proc_time;
$post["first"]= 1; $pid = C::t('forum_post_tableid')->insert(array('pid' => null), true);//添加pre_forum_post表的pid最大值
$post["pid"]= $pid;
$okid=C::t('forum_post')->insert("0", $post, 1);//写入帖子 $lastpost = $tid . "$subject" . $proc_time . $author;
$sql = "update " . DB::table('forum_forum') . " set threads = threads + 1, todayposts = todayposts + 1, lastpost = '$lastpost' where fid= $fid";//修改今日主题和帖子数量
DB::query($sql);
} return $tid;
}
?>
addThread参数需要提供几个必要的参数板块ID、标题、用户名、用户ID和消息内容。如果你想往哪个板块自动生成一个帖子,尽管调用addThread函数即可。
如果是插件这里有个需要特别注意的地方。
1、forum_thread表,必须将special字段的值设为127($thread["special"]= 127;)
2、forum_post表的message字段。如果你的是插件的话,最后面一定要加上
chr(0).chr(0).chr(0) . "插件名称"
否则,插件的模板将无法调用。这是为什么呢?这涉及到discuz插件模板设计的问题。
原因分析:
./source/module/forum/forum_viewthread.php,大概700行左右,有这么一段
if($_G['forum_thread']['special'] > 0 && (empty($_GET['viewpid']) || $_GET['viewpid'] == $_G['forum_firstpid'])) {
$_G['forum_thread']['starttime'] = gmdate($_G['forum_thread']['dateline']);
$_G['forum_thread']['remaintime'] = '';
switch($_G['forum_thread']['special']) {
case 1: require_once libfile('thread/poll', 'include'); break;
case 2: require_once libfile('thread/trade', 'include'); break;
case 3: require_once libfile('thread/reward', 'include'); break;
case 4: require_once libfile('thread/activity', 'include'); break;
case 5: require_once libfile('thread/debate', 'include'); break;
case 127:
if($_G['forum_firstpid']) {
$sppos = strpos($postlist[$_G['forum_firstpid']]['message'], chr(0).chr(0).chr(0));
$specialextra = substr($postlist[$_G['forum_firstpid']]['message'], $sppos + 3);
$postlist[$_G['forum_firstpid']]['message'] = substr($postlist[$_G['forum_firstpid']]['message'], 0, $sppos);
if($specialextra) {
if(array_key_exists($specialextra, $_G['setting']['threadplugins'])) {
@include_once DISCUZ_ROOT.'./source/plugin/'.$_G['setting']['threadplugins'][$specialextra]['module'].'.class.php';
$classname = 'threadplugin_'.$specialextra;
if(class_exists($classname) && method_exists($threadpluginclass = new $classname, 'viewthread')) {
$threadplughtml = $threadpluginclass->viewthread($_G['tid']);
//var_dump($post['message']);
}
}
}
}
break;
}
}
原因就出在这。
1、special为127是才执行插件的内容
2、由于插件有很多,真么知道是哪个插件呢?因此,请看这行
$sppos = strpos($postlist[$_G['forum_firstpid']]['message'], chr(0).chr(0).chr(0));
discuz采用了chr(0).chr(0).chr(0)进行分割,获取插件名。如果无法获取插件名,则无法调用相应的模板,因而也就调用默认的系统模板了。
discuz 帖子模块用到的表及自动发帖函数的更多相关文章
- JavaWeb_(SSH论坛)_五、帖子模块
基于SSH框架的小型论坛项目 一.项目入门 传送门 二.框架整合 传送门 三.用户模块 传送门 四.页面显示 传送门 五.帖子模块 传送门 六.点赞模块 传送门 七.辅助模块 传送门 回复帖子 分析回 ...
- 第三百零七节,Django框架,models.py模块,数据库操作——表类容的增删改查
Django框架,models.py模块,数据库操作——表类容的增删改查 增加数据 create()方法,增加数据 save()方法,写入数据 第一种方式 表类名称(字段=值) 需要save()方法, ...
- phalcon:整合官方多模块功能,方便多表查询
phalcon:整合官方多模块功能,方便多表查询 项目分为: namespace Multiple\Backend; namespace Multiple\Frontend; 目录结构如下: publ ...
- 五 Django框架,models.py模块,数据库操作——表类容的增删改查
Django框架,models.py模块,数据库操作——表类容的增删改查 增加数据 create()方法,增加数据 save()方法,写入数据 第一种方式 表类名称(字段=值) 需要save()方法, ...
- Python进阶----pymysql模块的使用,单表查询
Python进阶----pymysql模块的使用,单表查询 一丶使用pymysql 1.下载pymysql包: pip3 install pymysql 2.编写代码 ...
- python xlrd 模块(获取Excel表中数据)
python xlrd 模块(获取Excel表中数据) 一.安装xlrd模块 到python官网下载http://pypi.python.org/pypi/xlrd模块安装,前提是已经安装了pyt ...
- [MySQL数据库之Navicat.pymysql模块、视图、触发器、存储过程、函数、流程控制]
[MySQL数据库之Navicat.pymysql模块.视图.触发器.存储过程.函数.流程控制] Navicat Navicat是一套快速.可靠并价格相当便宜的数据库管理工具,专为简化数据库的管理及降 ...
- 你真的会玩SQL吗?表表达式,排名函数
你真的会玩SQL吗?系列目录 你真的会玩SQL吗?之逻辑查询处理阶段 你真的会玩SQL吗?和平大使 内连接.外连接 你真的会玩SQL吗?三范式.数据完整性 你真的会玩SQL吗?查询指定节点及其所有父节 ...
- MS SQL Server中数据表、视图、函数/方法、存储过程是否存在判断及创建
前言 在操作数据库的时候经常会用到判断数据表.视图.函数/方法.存储过程是否存在,若存在,则需要删除后再重新创建.以下是MS SQL Server中的示例代码. 数据表(Table) 创建数据表的时候 ...
随机推荐
- 警告: [SetContextPropertiesRule]{Context} Setting property 'source' to 'org.eclipse.jst.jee.server:CurrencyClientServe
有的说: 在Servers视图里双击创建的server,然后在其server的配置界面中选中"Publish module contexts to separate XML files&qu ...
- 你也可以当面霸-Servlet与JSP的原理及特点
既然是面试系列,就是面试官和应聘者之间的对话.本文是采用一问一答的形式呈现给读者的,这样能有一个明确的考察点,不像理论知识那么枯燥. 01.什么是Servlet技术 Servlet是和平台无关的服务器 ...
- 腾讯云CentOS7安装LNMP+wordpress
许多云主机都有学生优惠,于是我趁着现在大一买了个腾讯1元云主机+免费cn域名(高中生的话就别想了).鉴于我只知道用服务器安装博客,别的用途不了解,所以我就去安装wordpress. 而由于我看的教程有 ...
- BZOJ2121 字符串游戏
Description BX正在进行一个字符串游戏,他手上有一个字符串L,以及其 他一些字符串的集合S,然后他可以进行以下操作:对于一个在集合S中的字符串p,如果p在L中出现,BX就可以选择是否将其删 ...
- maven加载spring包
<dependencies> <dependency> <groupId>org.springframework</groupId> <artif ...
- JAVA-封装
1.什么是封装? 顾名思义,封装就是装起来,圈起来的意思,用于类与对象中来讲,就是在一个类中把对象拥有的属性和隐藏信息(条件)进行封装,不允许外部程序直接访问,而必须要通过该类提供的方法来实现对隐藏信 ...
- Spring学习3—控制反转(IOC)Spring依赖注入(DI)和控制反转(IOC)
一.思想理解 Spring 能有效地组织J2EE应用各层的对象.不管是控制层的Action对象,还是业务层的Service对象,还是持久层的DAO对象,都可在Spring的 管理下有机地协调.运行.S ...
- easyUI框架之学习1--框架
<!DOCTYPE html><html> <head > <link href="~/Scripts/easyUI/themes/default/ ...
- Idea 添加lib文件夹,并添加至项目Libary
在WEB-INF文件夹下新建lib文件夹,在lib文件夹上右键选择Add as Libary...,然后填写library名称,选择作用级别,选择作用项目,OK 注意:lib文件夹下需要有jar包后才 ...
- SSH协议及其应用
SSH协议及其应用 原文作者:阮一峰 链接: http://www.ruanyifeng.com/blog/2011/12/ssh_remote_login.html http://www.ruany ...