magic_repent.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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: magic_repent.php 29373 2012-04-09 07:55:30Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class magic_repent {
  12. var $version = '1.0';
  13. var $name = 'repent_name';
  14. var $description = 'repent_desc';
  15. var $price = '10';
  16. var $weight = '10';
  17. var $copyright = '<a href="http://www.comsenz.com" target="_blank">Comsenz Inc.</a>';
  18. var $magic = array();
  19. var $parameters = array();
  20. function getsetting(&$magic) {
  21. global $_G;
  22. $settings = array(
  23. 'fids' => array(
  24. 'title' => 'repent_forum',
  25. 'type' => 'mselect',
  26. 'value' => array(),
  27. ),
  28. );
  29. loadcache('forums');
  30. $settings['fids']['value'][] = array(0, '&nbsp;');
  31. if(empty($_G['cache']['forums'])) $_G['cache']['forums'] = array();
  32. foreach($_G['cache']['forums'] as $fid => $forum) {
  33. $settings['fids']['value'][] = array($fid, ($forum['type'] == 'forum' ? str_repeat('&nbsp;', 4) : ($forum['type'] == 'sub' ? str_repeat('&nbsp;', 8) : '')).$forum['name']);
  34. }
  35. $magic['fids'] = explode("\t", $magic['forum']);
  36. return $settings;
  37. }
  38. function setsetting(&$magicnew, &$parameters) {
  39. global $_G;
  40. $magicnew['forum'] = is_array($parameters['fids']) && !empty($parameters['fids']) ? implode("\t",$parameters['fids']) : '';
  41. }
  42. function usesubmit() {
  43. global $_G;
  44. if(empty($_GET['pid'])) {
  45. showmessage(lang('magic/repent', 'repent_info_nonexistence'));
  46. }
  47. $_G['tid'] = $_GET['ptid'];
  48. $post = getpostinfo($_GET['pid'], 'pid', array('p.first', 'p.tid', 'p.fid', 'p.authorid', 'p.replycredit', 't.status as thread_status'));
  49. $this->_check($post);
  50. require_once libfile('function/post');
  51. require_once libfile('function/delete');
  52. if($post['first']) {
  53. if($have_replycredit = C::t('forum_replycredit')->fetch($post['tid'])) {
  54. $thread = C::t('forum_thread')->fetch($post['tid']);
  55. if($thread['replycredit']) {
  56. updatemembercount($post['authorid'], array($_G['setting']['creditstransextra'][10] => $replycredit));
  57. }
  58. C::t('forum_replycredit')->delete($post['tid']);
  59. C::t('common_credit_log')->delete_by_operation_relatedid(array('RCT', 'RCA', 'RCB'), $post['tid']);
  60. }
  61. deletethread(array($post['tid']));
  62. updateforumcount($post['fid']);
  63. } else {
  64. if($post['replycredit'] > 0) {
  65. updatemembercount($post['authorid'], array($_G['setting']['creditstransextra'][10] => -$post['replycredit']));
  66. C::t('common_credit_log')->delete_by_uid_operation_relatedid($post['authorid'], 'RCA', $post['tid']);
  67. }
  68. deletepost(array($_GET['pid']));
  69. updatethreadcount($post['tid']);
  70. }
  71. usemagic($this->magic['magicid'], $this->magic['num']);
  72. updatemagiclog($this->magic['magicid'], '2', '1', '0', 0, 'tid', $_G['tid']);
  73. showmessage(lang('magic/repent', 'repent_succeed'), $post['first'] ? 'forum.php?mod=forumdisplay&fid='.$post['fid'] : dreferer(), array(), array('alert' => 'right', 'showdialog' => 1, 'locationtime' => true));
  74. }
  75. function show() {
  76. global $_G;
  77. $pid = !empty($_GET['id']) ? dhtmlspecialchars($_GET['id']) : '';
  78. list($pid, $_G['tid']) = explode(':', $pid);
  79. if($_G['tid']) {
  80. $post = getpostinfo($_GET['id'], 'pid', array('p.fid', 'p.authorid', 't.status as thread_status'));
  81. $this->_check($post);
  82. }
  83. magicshowtype('top');
  84. magicshowsetting(lang('magic/repent', 'repent_info'), 'pid', $pid, 'text');
  85. magicshowsetting('', 'ptid', $_G['tid'], 'hidden');
  86. magicshowtype('bottom');
  87. }
  88. function buy() {
  89. global $_G;
  90. if(!empty($_GET['id'])) {
  91. list($_GET['id'], $_G['tid']) = explode(':', $_GET['id']);
  92. $post = getpostinfo($_GET['id'], 'pid', array('p.fid', 'p.authorid'));
  93. $this->_check($post);
  94. }
  95. }
  96. function _check($post) {
  97. global $_G;
  98. if(!checkmagicperm($this->parameters['forum'], $post['fid'])) {
  99. showmessage(lang('magic/repent', 'repent_info_noperm'));
  100. }
  101. if($post['authorid'] != $_G['uid']) {
  102. showmessage(lang('magic/repent', 'repent_info_user_noperm'));
  103. }
  104. if(getstatus($post['thread_status'], 3)) {
  105. showmessage(lang('magic/repent', 'repent_do_not_rushreply'));
  106. }
  107. }
  108. }
  109. ?>