[Idea] The discuz post sets the cover setthreadcover table pre_forum_threadimage, preforumforum

Source: Internet
Author: User

[Idea] The discuz post sets the cover setthreadcover table pre_forum_threadimage, preforumforum

One of Discuz is to set the cover for the POST. In many cases, it can only be set manually or by submitting the POST request; however, this is all set by calling the DISCUZ function; sometimes it is not omnipotent or useful. Let's talk about the design idea of DISCUZ in designing the cover. Once you know the idea, you can use your own code to implement it;


Good start:

After the cover is set, a data like this will be inserted in pre_forum_threadimage;

Tid is the attachment address after the ID of the post;


When you click set cover, the program will request an address, as shown in figure

He:

http://localhost/dz/forum.php?mod=ajax&action=setthreadcover&aid=1&fid=36&infloat=yes&handlekey=setcover1&inajax=1&ajaxtarget=fwin_content_setcover1

In the connection of this request, we have the mod, action, fid, and aid parameters important to us. In the request for Forum. php, we can find them.

At the end of Forum. php, we found the following code:

require DISCUZ_ROOT.'./source/module/forum/forum_'.$mod.'.php';

Based on the Code and request parameters, we found the file source/module/forum/forum_ajax.php, and found the processing code of setthreadcover as follows:

elseif($_GET['action'] == 'setthreadcover') {$aid = intval($_GET['aid']);$imgurl = $_GET['imgurl'];require_once libfile('function/post');if($_G['forum'] && ($aid || $imgurl)) {if($imgurl) {$tid = intval($_GET['tid']);$pid = intval($_GET['pid']);} else {$threadimage = C::t('forum_attachment_n')->fetch('aid:'.$aid, $aid);$tid = $threadimage['tid'];$pid = $threadimage['pid'];}if($tid && $pid) {$thread =get_thread_by_tid($tid);} else {$thread = array();}if(empty($thread) || (!$_G['forum']['ismoderator'] && $_G['uid'] != $thread['authorid'])) {if($_GET['newthread']) {showmessage('set_cover_faild', '', array(), array('msgtype' => 3));} else {showmessage('set_cover_faild', '', array(), array('closetime' => 3));}}if(setthreadcover($pid, $tid, $aid, 0, $imgurl)) {if(empty($imgurl)) {C::t('forum_threadimage')->delete_by_tid($threadimage['tid']);C::t('forum_threadimage')->insert(array('tid' => $threadimage['tid'],'attachment' => $threadimage['attachment'],'remote' => $threadimage['remote'],));}if($_GET['newthread']) {showmessage('set_cover_succeed', '', array(), array('msgtype' => 3));} else {showmessage('set_cover_succeed', '', array(), array('alert' => 'right', 'closetime' => 1));}}}if($_GET['newthread']) {showmessage('set_cover_faild', '', array(), array('msgtype' => 3));} else {showmessage('set_cover_faild', '', array(), array('closetime' => 3));}} 

The most important piece of code in this section is: if (setthreadcover ($ pid, $ tid, $ aid, 0, $ imgurl )) you don't have to look at the code below, but we can guess that after the setthreadcover function is called, the cover has been set;

Where is the setthreadcover function? I also searched for it for half a day and finally found it in the file source/function/function_post.php. The Code is as follows:

function setthreadcover($pid, $tid = 0, $aid = 0, $countimg = 0, $imgurl = '') {global $_G;$cover = 0;if(empty($_G['uid']) || !intval($_G['setting']['forumpicstyle']['thumbheight']) || !intval($_G['setting']['forumpicstyle']['thumbwidth'])) {return false;}if(($pid || $aid) && empty($countimg)) {if(empty($imgurl)) {if($aid) {$attachtable = 'aid:'.$aid;$attach = C::t('forum_attachment_n')->fetch('aid:'.$aid, $aid, array(1, -1));} else {$attachtable = 'pid:'.$pid;$attach = C::t('forum_attachment_n')->fetch_max_image('pid:'.$pid, 'pid', $pid);}if(!$attach) {return false;}if(empty($_G['forum']['ismoderator']) && $_G['uid'] != $attach['uid']) {return false;}$pid = empty($pid) ? $attach['pid'] : $pid;$tid = empty($tid) ? $attach['tid'] : $tid;$picsource = ($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']).'forum/'.$attach['attachment'];} else {$attachtable = 'pid:'.$pid;$picsource = $imgurl;}$basedir = !$_G['setting']['attachdir'] ? (DISCUZ_ROOT.'./data/attachment/') : $_G['setting']['attachdir'];$coverdir = 'threadcover/'.substr(md5($tid), 0, 2).'/'.substr(md5($tid), 2, 2).'/';dmkdir($basedir.'./forum/'.$coverdir);require_once libfile('class/image');$image = new image();if($image->Thumb($picsource, 'forum/'.$coverdir.$tid.'.jpg', $_G['setting']['forumpicstyle']['thumbwidth'], $_G['setting']['forumpicstyle']['thumbheight'], 2)) {$remote = '';if(getglobal('setting/ftp/on')) {if(ftpcmd('upload', 'forum/'.$coverdir.$tid.'.jpg')) {$remote = '-';}}$cover = C::t('forum_attachment_n')->count_image_by_id($attachtable, 'pid', $pid);if($imgurl && empty($cover)) {$cover = 1;}$cover = $remote.$cover;} else {return false;}}if($countimg) {if(empty($cover)) {$thread = C::t('forum_thread')->fetch($tid);$oldcover = $thread['cover'];$cover = C::t('forum_attachment_n')->count_image_by_id('tid:'.$tid, 'pid', $pid);if($cover) {$cover = $oldcover < 0 ? '-'.$cover : $cover;}}}if($cover) {C::t('forum_thread')->update($tid, array('cover' => $cover));return true;}}

The whole function is the processing function for processing and setting the cover. The processing process is not explained much, but only the idea is described. In this function, an important code is as follows:

if(ftpcmd('upload', 'forum/'.$coverdir.$tid.'.jpg')) {

When viewing the cover request address, you will feel that the address for storing the cover thumbnail is as follows:



C4/ca? It seems to be random. It is totally different from the cover database storage mentioned above. What exactly does it correspond;

Now let's take a look at the above-mentioned setthreadcover function. We have mentioned that if (ftpcmd ('upload', 'Forum/'.w.coverdir.w.tid.'.jpg ') {// This code is very important.


What is the function of ftpcmd? We have a reason to guess the upload code below. This Code implements an image upload operation. It can be processed in this function, you must have uploaded the thumbnail to the new path.

Where is the path? 'forum/'. $ coverdir. $ tid. '// The following is the upload path.

$ Tid Needless to say, it must be the ID of the post, that is, the name of the cover image file. As for $ coverdir, it is not difficult to find that this is the path. We can find it through this; found this Code:

$coverdir = 'threadcover/'.substr(md5($tid), 0, 2).'/'.substr(md5($tid), 2, 2).'/';


At this point, the directory is generated by intercepting the first two digits after $ tid MD5 encryption as a directory and creating a directory with the third and fourth digits. To prove our speculation, make the following comparison:



Let's look at our directory:



It's completely stable, knowing how to set DISCUZ, so we can use the program to automatically post and set the cover even when we open an interface for our own forum.

Conclusion: It is obvious that DISCUZ uses the method of creating a directory to store the cover of the post. I don't know why they are designed this way. I think it is absolutely unnecessary;







How can I set a cover for a post on the Discuz forum?

Go to xingrui-station-Changlong-there are a lot of Discuz tutorials very suitable for beginners
 

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.