magic_open.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_open.php 29373 2012-04-09 07:55:30Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class magic_open {
  12. var $version = '1.0';
  13. var $name = 'open_name';
  14. var $description = 'open_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. 'fids' => array(
  25. 'title' => 'open_forum',
  26. 'type' => 'mselect',
  27. 'value' => array(),
  28. ),
  29. );
  30. loadcache('forums');
  31. $settings['fids']['value'][] = array(0, '&nbsp;');
  32. if(empty($_G['cache']['forums'])) $_G['cache']['forums'] = array();
  33. foreach($_G['cache']['forums'] as $fid => $forum) {
  34. $settings['fids']['value'][] = array($fid, ($forum['type'] == 'forum' ? str_repeat('&nbsp;', 4) : ($forum['type'] == 'sub' ? str_repeat('&nbsp;', 8) : '')).$forum['name']);
  35. }
  36. $magic['fids'] = explode("\t", $magic['forum']);
  37. return $settings;
  38. }
  39. function setsetting(&$magicnew, &$parameters) {
  40. global $_G;
  41. $magicnew['forum'] = is_array($parameters['fids']) && !empty($parameters['fids']) ? implode("\t",$parameters['fids']) : '';
  42. $magicnew['expiration'] = intval($parameters['expiration']);
  43. }
  44. function usesubmit() {
  45. global $_G;
  46. if(empty($_GET['tid'])) {
  47. showmessage(lang('magic/open', 'open_info_nonexistence'));
  48. }
  49. $thread = getpostinfo($_GET['tid'], 'tid', array('fid', 'authorid', 'subject'));
  50. $this->_check($thread);
  51. magicthreadmod($_GET['tid']);
  52. C::t('forum_thread')->update($_GET['tid'], array('closed' => 0, 'moderated' => 1));
  53. usemagic($this->magic['magicid'], $this->magic['num']);
  54. updatemagiclog($this->magic['magicid'], '2', '1', '0', 0, 'tid', $_GET['tid']);
  55. updatemagicthreadlog($_GET['tid'], $this->magic['magicid'], 'OPN');
  56. if($thread['authorid'] != $_G['uid']) {
  57. notification_add($thread['authorid'], 'magic', lang('magic/open', 'open_notification'), array('tid' => $_GET['tid'], 'subject' => $thread['subject'], 'magicname' => $this->magic['name']));
  58. }
  59. showmessage(lang('magic/open', 'open_succeed'), dreferer(), array(), array('alert' => 'right', 'showdialog' => 1, 'locationtime' => true));
  60. }
  61. function show() {
  62. global $_G;
  63. $tid = !empty($_GET['id']) ? dhtmlspecialchars($_GET['id']) : '';
  64. if($tid) {
  65. $thread = getpostinfo($_GET['id'], 'tid', array('fid', 'authorid'));
  66. $this->_check($thread);
  67. }
  68. $this->parameters['expiration'] = $this->parameters['expiration'] ? intval($this->parameters['expiration']) : 24;
  69. magicshowtype('top');
  70. magicshowsetting(lang('magic/open', 'open_info', array('expiration' => $this->parameters['expiration'])), 'tid', $tid, 'text');
  71. magicshowtype('bottom');
  72. }
  73. function buy() {
  74. global $_G;
  75. if(!empty($_GET['id'])) {
  76. $thread = getpostinfo($_GET['id'], 'tid', array('fid', 'authorid'));
  77. $this->_check($thread);
  78. }
  79. }
  80. function _check($thread) {
  81. if(!checkmagicperm($this->parameters['forum'], $thread['fid'])) {
  82. showmessage(lang('magic/open', 'open_info_noperm'));
  83. }
  84. $member = getuserbyuid($thread['authorid']);
  85. if(!checkmagicperm($this->parameters['targetgroups'], $member['groupid'])) {
  86. showmessage(lang('magic/open', 'open_info_user_noperm'));
  87. }
  88. }
  89. }
  90. ?>