Forgot password?
 Create new account
View 179|Reply 0

Discuz发帖过程分析

[Copy link]

3147

Threads

8495

Posts

610K

Credits

Credits
66173
QQ

Show all posts

hbghlyj Posted at 2022-2-22 22:03:39 |Read mode
以前的发帖代码都是从网上找的,现在可以自己分析了。

发帖
由发帖按钮  
forum.php?mod=post&action=newthread&fid=45&extra=&topicsubmit=yes

转到  
source/module/forum/forum_post.php
  1. if($_GET['action'] == 'newthread' || $_GET['action'] == 'newtrade') {
  2.         loadcache('groupreadaccess');
  3.         $navtitle .= ' - '.$_G['forum']['name'];
  4.         require_once libfile('post/newthread', 'include');
  5. } elseif($_GET['action'] == 'reply') {
  6.         $navtitle .= ' - '.$thread['subject'].' - '.$_G['forum']['name'];
  7.         require_once libfile('post/newreply', 'include');
  8. } elseif($_GET['action'] == 'edit') {
  9.         loadcache('groupreadaccess');
  10.         $navtitle .= ' - '.$thread['subject'].' - '.$_G['forum']['name'];
  11.         require_once libfile('post/editpost', 'include');
  12. }
  13. 然后到
  14. source/include/post/post_newthread.php
  15.         $modthread = C::m('forum_thread');
  16.     ...
  17.         $return = $modthread->newthread($params);
  18.         $tid = $modthread->tid;
  19.         $pid = $modthread->pid;
  20. source/class/model/model_forum_thread.php
  21.                 $newthread = array(
  22.                         'fid' => $this->forum['fid'],
  23.                         'posttableid' => 0,
  24.                         'readperm' => $this->param['readperm'],
  25.                         'price' => $this->param['price'],
  26.                         'typeid' => $this->param['typeid'],
  27.                         'sortid' => $this->param['sortid'],
  28.                         'author' => $author,
  29.                         'authorid' => $this->member['uid'],
  30.                         'subject' => $this->param['subject'],
  31.                         'dateline' => $this->param['publishdate'],
  32.                         'lastpost' => $this->param['publishdate'],
  33.                         'lastposter' => $author,
  34.                         'displayorder' => $this->param['displayorder'],
  35.                         'digest' => $this->param['digest'],
  36.                         'special' => $this->param['special'],
  37.                         'attachment' => 0,
  38.                         'moderated' => $this->param['moderated'],
  39.                         'status' => $this->param['tstatus'],
  40.                         'isgroup' => $this->param['isgroup'],
  41.                         'replycredit' => $this->param['replycredit'],
  42.                         'closed' => $this->param['closed'] ? 1 : 0
  43.                 );
  44.         1,插入主题
  45.                 $this->tid = C::t('forum_thread')->insert($newthread, true);
  46.         2,更新最新主题
  47.                 C::t('forum_newthread')->insert(array(
  48.                     'tid' => $this->tid,
  49.                     'fid' => $this->forum['fid'],
  50.                     'dateline' => $this->param['publishdate'],
  51.                 ));
  52.         用户家园的最近行为记录
  53.                 if(!$this->param['isanonymous']) {
  54.                         C::t('common_member_field_home')->update($this->member['uid'], array('recentnote'=>$this->param['subject']));
  55.                 }
  56.         3,插入帖子
  57.                 $this->pid = insertpost(array(
  58.                         'fid' => $this->forum['fid'],
  59.                         'tid' => $this->tid,
  60.                         'first' => '1',
  61.                         'author' => $this->member['username'],
  62.                         'authorid' => $this->member['uid'],
  63.                         'subject' => $this->param['subject'],
  64.                         'dateline' => $this->param['publishdate'],
  65.                         'message' => $this->param['message'],
  66.                         'useip' => $this->param['clientip'] ? $this->param['clientip'] : getglobal('clientip'),
  67.                         'port' => $this->param['remoteport'] ? $this->param['remoteport'] : getglobal('remoteport'),
  68.                         'invisible' => $this->param['pinvisible'],
  69.                         'anonymous' => $this->param['isanonymous'],
  70.                         'usesig' => $this->param['usesig'],
  71.                         'htmlon' => $this->param['htmlon'],
  72.                         'bbcodeoff' => $this->param['bbcodeoff'],
  73.                         'smileyoff' => $this->param['smileyoff'],
  74.                         'parseurloff' => $this->param['parseurloff'],
  75.                         'attachment' => '0',
  76.                         'tags' => $this->param['tagstr'],
  77.                         'replycredit' => 0,
  78.                         'status' => $this->param['pstatus']
  79.                 ));
  80.         
  81.         
  82. function insertpost($data) {
  83.         if(isset($data['tid'])) {
  84.                 $thread = C::t('forum_thread')->fetch($data['tid']);
  85.                 $tableid = $thread['posttableid'];
  86.         } else {
  87.                 $tableid = $data['tid'] = 0;
  88.         }
  89.         $pid = C::t('forum_post_tableid')->insert(array('pid' => null), true);
  90.         $data = array_merge($data, array('pid' => $pid));
  91.         C::t('forum_post')->insert($tableid, $data);
  92.         if($pid % 1024 == 0) {
  93.                 C::t('forum_post_tableid')->delete_by_lesspid($pid);
  94.         }
  95.         savecache('max_post_id', $pid);
  96.         return $pid;
  97. }
  98.                 更新积分
  99.                                 updatepostcredits('+',  $this->member['uid'], 'post', $this->forum['fid']);
  100.                 ...
  101.                                 $subject = str_replace("\t", ' ', $this->param['subject']);
  102.                                 $lastpost = "$this->tid\t".$subject."\t".TIMESTAMP."\t$author";
  103.                 更新版块的最后发表
  104.                                 C::t('forum_forum')->update($this->forum['fid'], array('lastpost' => $lastpost));
  105.                 更新数量,包括 $threads , $posts , $todayposts =
  106.                                 C::t('forum_forum')->update_forum_counter($this->forum['fid'], 1, 1, 1);
  107.                                 if($this->forum['type'] == 'sub') {
  108.                                         C::t('forum_forum')->update($this->forum['fup'], array('lastpost' => $lastpost));
  109.                                 }
  110.             ...
  111.                         C::t('forum_sofa')->insert(array('tid' => $this->tid,'fid' => $this->forum['fid']));
Copy the Code
编辑帖子
  1. source/module/forum/forum_post.php
  2. source/include/post/post_editpost.php
  3.         $modpost = C::m('forum_post', $_G['tid'], $pid);
  4.                 $modpost->editpost($param);
  5. source/class/model/model_forum_post.php
  6.             更新主题
  7.                         C::t('forum_thread')->update($this->thread['tid'], $this->param['threadupdatearr'], true);
  8.         更新帖子
  9.                 C::t('forum_post')->update('tid:'.$this->thread['tid'], $this->post['pid'], $setarr);
  10.         更新最后发表
  11.                 if($this->post['dateline'] == $this->forum['lastpost'][2] && ($this->post['author'] == $this->forum['lastpost'][3] || ($this->forum['lastpost'][3] == '' && $this->post['anonymous']))) {
  12.                         $lastpost = $this->thread['tid']."\t".($isfirstpost ? $this->param['subject'] : $this->thread['subject'])."\t".$this->post['dateline']."\t".($this->param['isanonymous'] ? '' : $this->post['author']);
  13.                         C::t('forum_forum')->update($this->forum['fid'], array('lastpost' => $lastpost));
  14.                 }
Copy the Code
回帖、删帖
都在source/class/model/model_forum_post.php

手机版Mobile version|Leisure Math Forum

2025-4-21 01:15 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list