PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/source/class/extend/extend_thread_reward.php

https://github.com/jinbo51/DiscuzX
PHP | 126 lines | 101 code | 19 blank | 6 comment | 40 complexity | 3e7d746d4a30939f99256b5f9b2fee6d MD5 | raw file
Possible License(s): BSD-3-Clause
  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_reward.php 32417 2013-01-15 04:26:17Z monkey $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class extend_thread_reward extends extend_thread_base {
  12. public $rewardprice;
  13. public $realprice;
  14. public function before_newthread($parameters) {
  15. $this->rewardprice = intval($_GET['rewardprice']);
  16. $minrewardprice = $this->group['minrewardprice'];
  17. $maxrewardprice = $this->group['maxrewardprice'];
  18. if($this->rewardprice < 1) {
  19. showmessage('reward_credits_please');
  20. } elseif($this->rewardprice > 32767) {
  21. showmessage('reward_credits_overflow');
  22. } elseif($this->rewardprice < $minrewardprice || ($maxrewardprice > 0 && $this->rewardprice > $maxrewardprice)) {
  23. if($maxrewardprice > 0) {
  24. showmessage('reward_credits_between', '', array('minrewardprice' => $minrewardprice, 'maxrewardprice' => $maxrewardprice));
  25. } else {
  26. showmessage('reward_credits_lower', '', array('minrewardprice' => $minrewardprice));
  27. }
  28. } elseif(($this->realprice = $this->rewardprice + ceil($this->rewardprice * $this->setting['creditstax'])) > getuserprofile('extcredits'.$this->setting['creditstransextra'][2])) {
  29. showmessage('reward_credits_shortage');
  30. }
  31. $this->param['price'] = $this->rewardprice;
  32. }
  33. public function after_newthread() {
  34. if($this->group['allowpostreward']) {
  35. updatemembercount($this->member['uid'], array($this->setting['creditstransextra']['2'] => -$this->realprice), 1, 'RTC', $this->tid);
  36. }
  37. }
  38. public function before_feed() {
  39. $this->feed['icon'] = 'reward';
  40. $this->feed['title_template'] = 'feed_thread_reward_title';
  41. $this->feed['body_template'] = 'feed_thread_reward_message';
  42. $this->feed['body_data'] = array(
  43. 'subject'=> "<a href=\"forum.php?mod=viewthread&tid={$this->tid}\">".$this->param['subject']."</a>",
  44. 'rewardprice'=> $this->rewardprice,
  45. 'extcredits' => $this->setting['extcredits'][$this->setting['creditstransextra']['2']]['title'],
  46. );
  47. }
  48. public function before_replyfeed() {
  49. if($this->forum['allowfeed'] && !$this->param['isanonymous']) {
  50. if($this->param['special'] == 3 && $this->thread['authorid'] != $this->member['uid']) {
  51. $this->feed['icon'] = 'reward';
  52. $this->feed['title_template'] = 'feed_reply_reward_title';
  53. $this->feed['title_data'] = array(
  54. 'subject' => "<a href=\"forum.php?mod=viewthread&tid=".$this->thread['tid']."\">".$this->thread['subject']."</a>",
  55. 'author' => "<a href=\"home.php?mod=space&uid=".$this->thread['authorid']."\">".$this->thread['author']."</a>"
  56. );
  57. }
  58. }
  59. }
  60. public function before_editpost($parameters) {
  61. $isfirstpost = $this->post['first'] ? 1 : 0;
  62. $isorigauthor = $this->member['uid'] && $this->member['uid'] == $this->post['authorid'];
  63. if($isfirstpost) {
  64. if($this->thread['special'] == 3) {
  65. $this->param['price'] = $isorigauthor ? ($this->thread['price'] > 0 && $this->thread['price'] != $_GET['rewardprice'] ? $_GET['rewardprice'] : 0) : $this->thread['price'];
  66. }
  67. if($this->thread['special'] == 3 && $isorigauthor) {
  68. $rewardprice = intval($_GET['rewardprice']);
  69. if($this->thread['price'] > 0 && $this->thread['price'] != $_GET['rewardprice']) {
  70. if($rewardprice <= 0){
  71. showmessage('reward_credits_invalid');
  72. }
  73. $addprice = ceil(($rewardprice - $this->thread['price']) + ($rewardprice - $this->thread['price']) * $this->setting['creditstax']);
  74. if($rewardprice < $this->thread['price']) {
  75. showmessage('reward_credits_fall');
  76. } elseif($rewardprice < $this->group['minrewardprice'] || ($this->group['maxrewardprice'] > 0 && $rewardprice > $this->group['maxrewardprice'])) {
  77. showmessage('reward_credits_between', '', array('minrewardprice' => $this->group['minrewardprice'], 'maxrewardprice' => $this->group['maxrewardprice']));
  78. } elseif($addprice > getuserprofile('extcredits'.$_G['setting']['creditstransextra'][2])) {
  79. showmessage('reward_credits_shortage');
  80. }
  81. $realprice = ceil($this->thread['price'] + $this->thread['price'] * $this->setting['creditstax']);
  82. updatemembercount($this->thread['authorid'], array($this->setting['creditstransextra'][2] => -$addprice));
  83. C::t('common_credit_log')->update_by_uid_operation_relatedid($this->thread['authorid'], 'RTC', $this->thread['tid'], array('extcredits'.$this->setting['creditstransextra'][2] => $realprice));
  84. }
  85. if(!$this->forum['ismoderator']) {
  86. if($this->thread['replies'] > 1) {
  87. $this->param['subject'] = addslashes($this->thread['subject']);
  88. }
  89. }
  90. $this->param['price'] = $rewardprice;
  91. }
  92. }
  93. }
  94. public function before_deletepost($parameters) {
  95. $isfirstpost = $this->post['first'] ? 1 : 0;
  96. if($this->thread['special'] == 3) {
  97. if($this->thread['price'] < 0 && ($this->thread['dateline'] + 1 == $this->post['dateline'])) {
  98. showmessage('post_edit_reward_nopermission', NULL);
  99. }
  100. }
  101. if($this->thread['special'] == 3 && $isfirstpost) {
  102. updatemembercount($this->post['authorid'], array($this->setting['creditstransextra'][2] => $this->thread['price']));
  103. C::t('common_credit_log')->delete_by_uid_operation_relatedid($this->thread['authorid'], 'RTC', $this->thread['tid']);
  104. }
  105. }
  106. }
  107. ?>