magic_close.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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_close.php 29373 2012-04-09 07:55:30Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class magic_close {
  12. var $version = '1.0';
  13. var $name = 'close_name';
  14. var $description = 'close_desc';
  15. var $price = '10';
  16. var $weight = '10';
  17. var $targetgroupperm = true;
  18. var $copyright = '<a href="http://www.comsenz.com" target="_blank">Comsenz Inc.</a>';
  19. var $magic = array();
  20. var $parameters = array();
  21. function getsetting(&$magic) {
  22. global $_G;
  23. $settings = array(
  24. 'expiration' => array(
  25. 'title' => 'close_expiration',
  26. 'type' => 'text',
  27. 'value' => '',
  28. 'default' => 24,
  29. ),
  30. 'fids' => array(
  31. 'title' => 'close_forum',
  32. 'type' => 'mselect',
  33. 'value' => array(),
  34. ),
  35. );
  36. loadcache('forums');
  37. $settings['fids']['value'][] = array(0, '&nbsp;');
  38. if(empty($_G['cache']['forums'])) $_G['cache']['forums'] = array();
  39. foreach($_G['cache']['forums'] as $fid => $forum) {
  40. $settings['fids']['value'][] = array($fid, ($forum['type'] == 'forum' ? str_repeat('&nbsp;', 4) : ($forum['type'] == 'sub' ? str_repeat('&nbsp;', 8) : '')).$forum['name']);
  41. }
  42. $magic['fids'] = explode("\t", $magic['forum']);
  43. return $settings;
  44. }
  45. function setsetting(&$magicnew, &$parameters) {
  46. global $_G;
  47. $magicnew['forum'] = is_array($parameters['fids']) && !empty($parameters['fids']) ? implode("\t",$parameters['fids']) : '';
  48. $magicnew['expiration'] = intval($parameters['expiration']);
  49. }
  50. function usesubmit() {
  51. global $_G;
  52. if(empty($_GET['tid'])) {
  53. showmessage(lang('magic/close', 'close_info_nonexistence'));
  54. }
  55. $thread = getpostinfo($_GET['tid'], 'tid', array('fid', 'authorid', 'subject'));
  56. $this->_check($thread);
  57. magicthreadmod($_GET['tid']);
  58. C::t('forum_thread')->update($_GET['tid'], array('closed' => 1, 'moderated' => 1));
  59. $this->parameters['expiration'] = $this->parameters['expiration'] ? intval($this->parameters['expiration']) : 24;
  60. $expiration = TIMESTAMP + $this->parameters['expiration'] * 3600;
  61. usemagic($this->magic['magicid'], $this->magic['num']);
  62. updatemagiclog($this->magic['magicid'], '2', '1', '0', 0, 'tid', $_GET['tid']);
  63. updatemagicthreadlog($_GET['tid'], $this->magic['magicid'], $expiration > 0 ? 'ECL' : 'CLS', $expiration);
  64. if($thread['authorid'] != $_G['uid']) {
  65. notification_add($thread['authorid'], 'magic', lang('magic/close', 'close_notification'), array('tid' => $_GET['tid'], 'subject' => $thread['subject'], 'magicname' => $this->magic['name']));
  66. }
  67. showmessage(lang('magic/close', 'close_succeed'), dreferer(), array(), array('alert' => 'right', 'showdialog' => 1, 'locationtime' => true));
  68. }
  69. function show() {
  70. global $_G;
  71. $tid = !empty($_GET['id']) ? dhtmlspecialchars($_GET['id']) : '';
  72. if($tid) {
  73. $thread = getpostinfo($_GET['id'], 'tid', array('fid', 'authorid'));
  74. $this->_check($thread);
  75. }
  76. $this->parameters['expiration'] = $this->parameters['expiration'] ? intval($this->parameters['expiration']) : 24;
  77. magicshowtype('top');
  78. magicshowsetting(lang('magic/close', 'close_info', array('expiration' => $this->parameters['expiration'])), 'tid', $tid, 'text');
  79. magicshowtype('bottom');
  80. }
  81. function buy() {
  82. global $_G;
  83. if(!empty($_GET['id'])) {
  84. $thread = getpostinfo($_GET['id'], 'tid', array('fid', 'authorid'));
  85. $this->_check($thread);
  86. }
  87. }
  88. function _check($thread) {
  89. if(!checkmagicperm($this->parameters['forum'], $thread['fid'])) {
  90. showmessage(lang('magic/close', 'close_info_noperm'));
  91. }
  92. $member = getuserbyuid($thread['authorid']);
  93. if(!checkmagicperm($this->parameters['targetgroups'], $member['groupid'])) {
  94. showmessage(lang('magic/close', 'close_info_user_noperm'));
  95. }
  96. }
  97. }
  98. ?>