extend_thread_image.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: extend_thread_image.php 32709 2013-03-04 03:28:55Z zhangjie $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class extend_thread_image extends extend_thread_base {
  12. public function after_newthread() {
  13. $threadimageaid = 0;
  14. $threadimage = array();
  15. $tid = $this->tid;
  16. $pid = $this->pid;
  17. $fid = $this->forum['fid'];
  18. if($this->param['special'] == 4 && $_GET['activityaid']) {
  19. $threadimageaid = $_GET['activityaid'];
  20. convertunusedattach($_GET['activityaid'], $tid, $pid);
  21. }
  22. $this->mobile_upload();
  23. if(($this->group['allowpostattach'] || $this->group['allowpostimage']) && ($_GET['attachnew'] || $this->param['sortid'] || !empty($_GET['activityaid']))) {
  24. updateattach($this->param['displayorder'] == -4 || $this->param['modnewthreads'], $tid, $pid, $_GET['attachnew']);
  25. if(!$threadimageaid) {
  26. $threadimage = C::t('forum_attachment_n')->fetch_max_image('tid:'.$tid, 'tid', $tid);
  27. $threadimageaid = $threadimage['aid'];
  28. }
  29. }
  30. $values = array('fid' => $fid, 'tid' => $tid, 'pid' => $pid, 'coverimg' => '');
  31. $param = array();
  32. if($this->forum['picstyle']) {
  33. if(!setthreadcover($pid, 0, $threadimageaid) && !defined('IN_MOBILE')) {
  34. $imglist = array();
  35. preg_match_all("/(\[img\]|\[img=\d{1,4}[x|\,]\d{1,4}\])\s*([^\[\<\r\n]+?)\s*\[\/img\]/is", $this->param['message'], $imglist, PREG_SET_ORDER);
  36. $values['coverimg'] = "<p id=\"showsetcover\">".lang('message', 'post_newthread_set_cover')."<span id=\"setcoverwait\"></span></p><script>if($('forward_a')){\$('forward_a').style.display='none';setTimeout(\"$('forward_a').style.display=''\", 5000);};ajaxget('forum.php?mod=ajax&action=setthreadcover&tid=$tid&pid=$pid&fid=$fid&imgurl={$imglist[0][2]}&newthread=1', 'showsetcover', 'setcoverwait')</script>";
  37. $param['clean_msgforward'] = 1;
  38. $param['timeout'] = $param['refreshtime'] = 15;
  39. }
  40. }
  41. if($threadimageaid) {
  42. if(!$threadimage) {
  43. $threadimage = C::t('forum_attachment_n')->fetch('tid:'.$tid, $threadimageaid);
  44. }
  45. $threadimage = daddslashes($threadimage);
  46. C::t('forum_threadimage')->insert(array(
  47. 'tid' => $tid,
  48. 'attachment' => $threadimage['attachment'],
  49. 'remote' => $threadimage['remote'],
  50. ));
  51. }
  52. $this->param['values'] = array_merge((array)$this->param['values'], $values);
  53. $this->param['param'] = array_merge((array)$this->param['param'], $param);
  54. }
  55. private function mobile_upload() {
  56. if($_GET['mobile'] == 'yes' && !empty($_FILES['Filedata'])) {
  57. $forumattachextensions = '';
  58. if($_G['forum']) {
  59. $forum = $_G['forum'];
  60. if($forum['status'] == 3 && $forum['level']) {
  61. $levelinfo = C::t('forum_grouplevel')->fetch($forum['level']);
  62. if($postpolicy = $levelinfo['postpolicy']) {
  63. $postpolicy = dunserialize($postpolicy);
  64. $forumattachextensions = $postpolicy['attachextensions'];
  65. }
  66. } else {
  67. $forumattachextensions = $forum['attachextensions'];
  68. }
  69. if($forumattachextensions) {
  70. $_G['group']['attachextensions'] = $forumattachextensions;
  71. }
  72. }
  73. $upload = new forum_upload(1);
  74. if($upload) {
  75. $_GET['attachnew'][$upload->getaid] = array('description' => '');
  76. }
  77. }
  78. }
  79. public function after_newreply() {
  80. $this->mobile_upload();
  81. ($this->group['allowpostattach'] || $this->group['allowpostimage']) && ($_GET['attachnew'] || $this->param['special'] == 2 && $_GET['tradeaid']) && updateattach($this->thread['displayorder'] == -4 || $this->param['modnewreplies'], $this->thread['tid'], $this->pid, $_GET['attachnew']);
  82. }
  83. public function before_editpost($parameters) {
  84. global $_G;
  85. $isfirstpost = $this->post['first'] ? 1 : 0;
  86. $attachupdate = !empty($_GET['delattachop']) || ($this->group['allowpostattach'] || $this->group['allowpostimage']) && ($_GET['attachnew'] || $parameters['special'] == 2 && $_GET['tradeaid'] || $parameters['special'] == 4 && $_GET['activityaid'] || $isfirstpost && $parameters['sortid']);
  87. if($attachupdate) {
  88. updateattach($this->thread['displayorder'] == -4 || $_G['forum_auditstatuson'], $this->thread['tid'], $this->post['pid'], $_GET['attachnew'], $_GET['attachupdate'], $this->post['authorid']);
  89. }
  90. if($isfirstpost && $attachupdate) {
  91. if(!$this->param['threadimageaid']) {
  92. $this->param['threadimage'] = C::t('forum_attachment_n')->fetch_max_image('tid:'.$this->thread['tid'], 'pid', $this->post['pid']);
  93. $this->param['threadimageaid'] = $this->param['threadimage']['aid'];
  94. }
  95. if($this->forum['picstyle']) {
  96. if(empty($this->thread['cover'])) {
  97. setthreadcover($this->post['pid'], 0, $this->param['threadimageaid']);
  98. } else {
  99. setthreadcover($this->post['pid'], $this->thread['tid'], 0, 1);
  100. }
  101. }
  102. if($this->param['threadimageaid']) {
  103. if(!$this->param['threadimage']) {
  104. $this->param['threadimage'] = C::t('forum_attachment_n')->fetch_max_image('tid:'.$this->thread['tid'], 'tid', $this->thread['tid']);
  105. }
  106. C::t('forum_threadimage')->delete_by_tid($this->thread['tid']);
  107. C::t('forum_threadimage')->insert(array(
  108. 'tid' => $this->thread['tid'],
  109. 'attachment' => $this->param['threadimage']['attachment'],
  110. 'remote' => $this->param['threadimage']['remote'],
  111. ));
  112. }
  113. }
  114. }
  115. public function before_deletepost($parameters) {
  116. $thread_attachment = $post_attachment = 0;
  117. foreach(C::t('forum_attachment_n')->fetch_all_by_id('tid:'.$this->thread['tid'], 'tid', $this->thread['tid']) as $attach) {
  118. if($attach['pid'] == $this->post['pid']) {
  119. if($this->thread['displayorder'] >= 0) {
  120. $post_attachment++;
  121. }
  122. dunlink($attach);
  123. } else {
  124. $thread_attachment = 1;
  125. }
  126. }
  127. $this->param['updatefieldarr']['attachment'] = array($thread_attachment);
  128. if($post_attachment) {
  129. C::t('forum_attachment')->delete_by_id('pid', $this->post['pid']);
  130. DB::query("DELETE FROM ".DB::table(getattachtablebytid($this->thread['tid']))." WHERE pid='".$this->post['pid']."'", 'UNBUFFEREED');
  131. updatecreditbyaction('postattach', $this->post['authorid'], array(), '', -$post_attachment);
  132. }
  133. }
  134. }
  135. ?>