Discuz two times development, analysis and implementation insert your own posts into the DZ database

Source: Internet
Author: User
Tags php download tagname

Send a blog too troublesome, no wonder the less blogging, vomit, Cnblogs editor template is too ugly!

Recently the development community needs to collect some data, so that the template output has a graphic effect. Just write a simple collection script, crawl the content of the target station, (with PHP download image processing is more troublesome).
With the data will be inserted into the DZ database, the name of a test.php placed in the Discuz Web root directory.
It took a bit of work and a lot of headaches in the middle. Special Records.
Two points of attention,
One, discuz posts stored in the Post table Pre_forum_post, the Message field, where the picture and line breaks are bbcode, before inserting need to first convert
Two, Discuz itself processing the code of the post is located in \source\class\model\model_forum_thread.php, to use the method inside the first to introduce Discuz core class test.php
Require_once './source/class/class_core.php ';
C::app ()->init (); Be sure to initialize it, otherwise the method in model_forum_thread.php cannot be used

Discuz as a veteran community there are nearly 300 tables, to achieve a more complex post data insertion.
At first, Baidu a bit, find an article record, feel more reliable.
Quote:
DISCUZ publishes several tables related to the topic: (Here is a list of the main relevant tables)

1. Topic table Pre_forum_thread: One of the main data of this table is the TID theme ID

2, Post table coordination Table Pre_forum_post_tableid: here need to get a self-increasing PID

3, the post table pre_forum_post: Record the theme PID, FID, Tid, title, content and other key information

4, the section table Pre_forum_forum: Here mainly update the topic of the section, the number of posts

5, Post subject Audit data Sheet pre_forum_thread_moderate: This can be decided according to their own situation, not necessary

6, User statistics Pre_common_member_count: Mainly to update the user's topic number
Thanks to the unknown author of the fungus, just engage in the time can be consulted, after all, 300 of the table to find a few specific also cost Kung Fu.

Another http://discuzt.cr180.com/discuzcode-db.html cr180 discuz two opened the database dictionary provided with a detailed index of the data table.

Directly on the code snippet, this in my local environment is able to insert the post data successfully.
Require_once './source/class/class_core.php ';
C::app ()->init ();
$param =array (
' FID ' =>2,//category ID
' UID ' =>1,//publisher's ID
' Subject ' = ' article title 333 ',
' Author ' = ' Big Brother ',
' Message ' = ' content location, implement insert ',
' Publishdate ' =>timestamp,
' Views ' =>168,
' Tstatus ' =>32,
' Tags ' =>array (' good ', ' cool '),
' Useip ' = Getglobal (' ClientIP '),
' Port ' = Getglobal (' RemotePort ')

);

Print_r ($NEWIMGSRC);
function Dzthread ($param) {
$newthread = Array (
' FID ' = $param [' FID '],//article category section
' Author ' = $param [' Author '],
' Authorid ' = $param [' uid '],
' Subject ' = $param [' Subject '],
' Dateline ' = $param [' Publishdate '],
' Lastpost ' = $param [' Publishdate '],
' Lastposter ' = $param [' Author '],
' Attachment ' = 0,
' Views ' and $param [' views '],
' Status ' = $param [' Tstatus '],
' Closed ' = $param [' Closed ']? 1:0
);

$tid = c::t (' Forum_thread ')->insert ($newthread, true);

C::t (' Forum_newthread ')->insert (Array (
' Tid ' = $tid,
' FID ' = $param [' FID '],
' Dateline ' = $param [' Publishdate '],
));
Working with Tags

$param [' tagstr '] = Addtag ($param [' tags '], $tid, ' tid ');


$pid = Insertpost (Array (
' FID ' = $param [' FID '],
' Tid ' = $tid,
' First ' = ' 1 ',
' Author ' = $param [' Author '],
' Authorid ' = $param [' uid '],
' Subject ' = $param [' Subject '],
' Dateline ' = $param [' Publishdate '],
' Message ' = $param [' Message '],
' Useip ' = $param [' ClientIP '],
' Port ' = $param [' RemotePort '],
' Usesig ' = 1,
' Attachment ' = ' 0 ',
' Tags ' = $param [' Tagstr '],
' Replycredit ' = 0,
' Status ' = 0
));

}


function Insertpost ($data) {
if (Isset ($data [' tid ')]) {
$thread = c::t (' Forum_thread ')->fetch ($data [' tid ']);
$tableid = $thread [' Posttableid '];
} else {
$tableid = $data [' tid '] = 0;
}
echo $data [' Tid '];
$pid = c::t (' Forum_post_tableid ')->insert (Array (' pid ' = null), true);

echo ' 116 ';
$data = Array_merge ($data, Array (' pid ' = = $pid));

C::t (' Forum_post ')->insert ($tableid, $data);
if ($pid% 1024 = = 0) {
C::t (' Forum_post_tableid ')->delete_by_lesspid ($pid);
}
Savecache (' max_post_id ', $pid);
return $pid;
}
Discuz tag handling is more troublesome
function Addtag ($tagarray, $itemid, $idtype = ' tid ') {
$tagcount = 0;
$return = ";
foreach ($tagarray as $tagname) {
$tagname = Trim ($tagname);
if (Preg_match ('/^ ([\x7f-\xff_-]|\w|\s) {3,20}$/', $tagname)) {
$status = $idtype! = ' uid '? 0:3;
$result = c::t (' Common_tag ')->get_bytagname ($tagname, $idtype);
if ($result [' TagID ']) {
if ($result [' status '] = = $status) {
$tagid = $result [' TagID '];
}
} else {
$tagid = c::t (' Common_tag ')->insert ($tagname, $status);
}
if ($tagid) {
if ($itemid) {
C::t (' Common_tagitem ')->replace ($tagid, $itemid, $idtype);
}
$tagcount + +;

$return. = $tagid. ', '. $tagname. " \ t ";


}
if ($tagcount > 4) {
Unset ($tagarray);
Break
}
}
}
return $return;
}
Hehe, combined with the acquisition code to $param array data can be.

Discuz two times development, analysis and implementation insert your own posts into the DZ database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.