extend_thread_sort.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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_sort.php 34201 2013-11-04 06:21:04Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class extend_thread_sort extends extend_thread_base {
  12. public function before_newthread() {
  13. if($_GET['typeoption']) {
  14. $this->param['extramessage'] = "\t".implode("\t", $_GET['typeoption']);
  15. }
  16. }
  17. public function after_newthread() {
  18. global $_G;
  19. $sortid = $this->param['sortid'];
  20. $pid = $this->pid;
  21. $_G['forum_optiondata'] = array();
  22. if($this->forum['threadsorts']['types'][$sortid] && !$this->forum['allowspecialonly']) {
  23. $_G['forum_optiondata'] = threadsort_validator($_GET['typeoption'], $pid);
  24. }
  25. if($this->forum['threadsorts']['types'][$sortid] && !empty($_G['forum_optiondata']) && is_array($_G['forum_optiondata'])) {
  26. $sortaids = array();
  27. $filedname = $valuelist = $separator = '';
  28. $fid = $this->forum['fid'];
  29. $tid = $this->tid;
  30. foreach($_G['forum_optiondata'] as $optionid => $value) {
  31. if($value) {
  32. $filedname .= $separator.$_G['forum_optionlist'][$optionid]['identifier'];
  33. $valuelist .= $separator."'".daddslashes($value)."'";
  34. $separator = ' ,';
  35. }
  36. if($_G['forum_optionlist'][$optionid]['type'] == 'image') {
  37. $identifier = $_G['forum_optionlist'][$optionid]['identifier'];
  38. $sortaids[] = intval($_GET['typeoption'][$identifier]['aid']);
  39. }
  40. C::t('forum_typeoptionvar')->insert(array(
  41. 'sortid' => $sortid,
  42. 'tid' => $tid,
  43. 'fid' => $fid,
  44. 'optionid' => $optionid,
  45. 'value' => censor($value),
  46. 'expiration' => ($typeexpiration ? $publishdate + $typeexpiration : 0),
  47. ));
  48. }
  49. if($filedname && $valuelist) {
  50. C::t('forum_optionvalue')->insert($sortid, "($filedname, tid, fid) VALUES ($valuelist, '{$tid}', '$fid')");
  51. }
  52. if($sortaids) {
  53. foreach($sortaids as $sortaid) {
  54. convertunusedattach($sortaid, $tid, $pid);
  55. }
  56. }
  57. }
  58. }
  59. public function before_editpost($parameters) {
  60. global $_G;
  61. $sortid = $parameters['sortid'];
  62. $isfirstpost = $this->post['first'] ? 1 : 0;
  63. if($isfirstpost) {
  64. $parameters['typeid'] = isset($this->forum['threadtypes']['types'][$parameters['typeid']]) ? $parameters['typeid'] : 0;
  65. if(!$this->forum['ismoderator'] && !empty($this->forum['threadtypes']['moderators'][$this->thread['typeid']])) {
  66. $parameters['typeid'] = $this->thread['typeid'];
  67. }
  68. $parameters['sortid'] = isset($this->forum['threadsorts']['types'][$parameters['sortid']]) ? $parameters['sortid'] : 0;
  69. $typeexpiration = intval($_GET['typeexpiration']);
  70. if(!$parameters['typeid'] && $this->forum['threadtypes']['required'] && !$this->thread['special']) {
  71. showmessage('post_type_isnull');
  72. }
  73. if($this->forum['threadsorts']['types'][$sortid] && $_G['forum_checkoption']) {
  74. $_G['forum_optiondata'] = threadsort_validator($_GET['typeoption'], $this->post['pid']);
  75. }
  76. $this->param['threadimageaid'] = 0;
  77. $this->param['threadimage'] = array();
  78. if($this->forum['threadsorts']['types'][$parameters['sortid']] && $_G['forum_optiondata'] && is_array($_G['forum_optiondata'])) {
  79. $sql = $separator = $filedname = $valuelist = '';
  80. foreach($_G['forum_optiondata'] as $optionid => $value) {
  81. $value = censor(daddslashes($value));
  82. if($_G['forum_optionlist'][$optionid]['type'] == 'image') {
  83. $identifier = $_G['forum_optionlist'][$optionid]['identifier'];
  84. $newsortaid = intval($_GET['typeoption'][$identifier]['aid']);
  85. if($newsortaid && $_GET['oldsortaid'][$identifier] && $newsortaid != $_GET['oldsortaid'][$identifier]) {
  86. $attach = C::t('forum_attachment_n')->fetch('tid:'.$this->thread['tid'], $_GET['oldsortaid'][$identifier]);
  87. C::t('forum_attachment')->delete($_GET['oldsortaid'][$identifier]);
  88. C::t('forum_attachment_n')->delete('tid:'.$this->thread['tid'], $_GET['oldsortaid'][$identifier]);
  89. dunlink($attach);
  90. $this->param['threadimageaid'] = $newsortaid;
  91. convertunusedattach($newsortaid, $this->thread['tid'], $this->post['pid']);
  92. }
  93. }
  94. if($_G['forum_optionlist'][$optionid]['unchangeable']) {
  95. continue;
  96. }
  97. if(($_G['forum_optionlist'][$optionid]['search'] || in_array($_G['forum_optionlist'][$optionid]['type'], array('radio', 'select', 'number'))) && $value) {
  98. $filedname .= $separator.$_G['forum_optionlist'][$optionid]['identifier'];
  99. $valuelist .= $separator."'$value'";
  100. $sql .= $separator.$_G['forum_optionlist'][$optionid]['identifier']."='$value'";
  101. $separator = ' ,';
  102. }
  103. C::t('forum_typeoptionvar')->update_by_tid($this->thread['tid'], array('value' => $value, 'sortid' => $parameters['sortid']), false, false, $optionid);
  104. }
  105. if($typeexpiration) {
  106. C::t('forum_typeoptionvar')->update_by_tid($this->thread['tid'], array('expiration' => (TIMESTAMP + $typeexpiration)), false, false, null, $parameters['sortid']);
  107. }
  108. if($sql || ($filedname && $valuelist)) {
  109. if(C::t('forum_optionvalue')->fetch_all_tid($parameters['sortid'], "WHERE tid='".$this->thread['tid']."'")) {
  110. if($sql) {
  111. C::t('forum_optionvalue')->update($parameters['sortid'], $this->thread['tid'], $this->forum['fid'], $sql);
  112. }
  113. } elseif($filedname && $valuelist) {
  114. C::t('forum_optionvalue')->insert($parameters['sortid'], "($filedname, tid, fid) VALUES ($valuelist, '".$this->thread['tid']."', '".$this->forum['fid']."')");
  115. }
  116. }
  117. }
  118. }
  119. }
  120. public function after_deletepost() {
  121. $isfirstpost = $this->post['first'] ? 1 : 0;
  122. if($isfirstpost) {
  123. C::t('forum_typeoptionvar')->delete_by_tid($this->thread['tid']);
  124. }
  125. }
  126. }
  127. ?>