discuz发帖流程_discuz直接向数据库插入文章步骤

本文提供了一段PHP代码示例,详细解释了如何在Discuz! 系统中通过API直接向数据库插入文章,包括创建主题(thread)、帖子(post)以及附件(attachment)的数据。首先定义常量并初始化Discuz!,然后解析JSON输入,将UTF-8编码转换为GBK,接着处理并插入到相应的数据库表中,最后返回新主题的URL。
摘要由CSDN通过智能技术生成

[PHP] 纯文本查看 复制代码<?php

define('APPTYPEID', 100);

define('CURSCRIPT', 'appapi');

require './source/class/class_core.php';

$discuz = & discuz_core::instance();

//$discuz->init_mobile = false;

$discuz->init();

$ac = $_G['gp_ac'];

if(empty($_GET['ac']) || !in_array($_GET['ac'], array('pushthread'))) $_GET['ac'] = 'index';

define('CURMODULE', $_GET['ac']);

runhooks();

$discuz_url = "https://www.baidu.com";

$json = file_get_contents("php://input");

$json = json_decode($json, true);

$json = api_utf8_to_gbk($json);

if($ac == 'pushthread' && $json['key'] == 'jfjoff979868sjcoidscio'){

// $_POST = array(

// 'thread' => $thread,

// 'thread_forum_attachment' => $thread_forum_attachment,

// 'thread_forum_attachment_subs' => $thread_forum_attachment_subs,

// 'thread_posts' => $thread_posts,

// );

$thread = arrayaddslashes($json['thread']);

unset($thread['isposttoline']);

$thread_forum_attachment = arrayaddslashes($json['thread_forum_attachment']);

$thread_forum_attachment_subs = arrayaddslashes($json['thread_forum_attachment_subs']);

$thread_posts = arrayaddslashes($json['thread_posts']);

$posttableid = $thread['posttableid'] > 0 ? '_'.$thread['posttableid'] : '';

// echo "

";

// print_r($json);

// echo "

";

// exit;

//记录到图书表 tid=''

if(empty($thread['tid']) || empty($thread['subject']) ){

exit('参数不完整');

}

//thread表

if($thread){

DB::insert('forum_thread', $thread);

//useractionlog($thread['authorid'], 'tid');

DB::update('common_member_field_home', array('recentnote'=>$thread['subject']), array('uid'=>$thread['authorid']));

//updatepostcredits('+', $thread['authorid'], 'post', $thread['fid']);

$newlastpost = "$thread[tid]\t$thread[subject]\t$_G[timestamp]\t$thread[author]";

DB::query("UPDATE ".DB::table('forum_forum')." SET lastpost='$newlastpost', threads=threads+1, posts=posts+1, todayposts=todayposts+1 WHERE fid='$thread[fid]'", 'UNBUFFERED');

}

//post或分表

if($thread_posts){

for ($i=0;$i

DB::insert('forum_post'.$posttableid, $thread_posts[$i]);

}

DB::query("UPDATE ".DB::table('common_member_count')." SET posts=posts+1 WHERE uid='".$thread['authorid']."'", 'UNBUFFERED');

DB::query("UPDATE ".DB::table('common_member_status')." SET lastip='$_G[clientip]',lastvisit='$_G[timestamp]',lastactivity='$_G[timestamp]',lastpost='$_G[timestamp]' WHERE uid='".$thread['authorid']."'", 'UNBUFFERED');

}

//attachment主表

if($thread_forum_attachment){

DB::insert('forum_attachment', $thread_forum_attachment);

}

//attachment分表

if($thread_forum_attachment_subs){

for ($i=0; $i

DB::insert('forum_attachment_'.$thread_forum_attachment['tableid'], $thread_forum_attachment_subs[$i]);

}

}

$url = $discuz_url."/thread-".$thread['tid']."-1-1.html";

echo $url;

exit;

}else{

exit('nothing');

}

function arrayaddslashes($string) {

if(is_array($string)) {

foreach($string as $key => $value) {

$string[$key] = arrayaddslashes($value);

}

} else {

$string = addslashes($string);

}

return $string;

}

function api_utf8_to_gbk($string) {

if(is_array($string)) {

foreach($string as $key => $value) {

$string[$key] = api_utf8_to_gbk($value);

}

} else {

//$string = diconv($string,'utf-8', CHARSET);

if(mb_detect_encoding($string, 'UTF-8',true) === 'UTF-8'){

$string = iconv('UTF-8','gbk',$string);

}

}

return $string;

}

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值