magic_jack.php 4.0 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_jack.php 34353 2014-03-19 04:57:02Z hypowang $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class magic_jack {
  12. var $version = '1.0';
  13. var $name = 'jack_name';
  14. var $description = 'jack_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. 'expiration' => array(
  24. 'title' => 'jack_expiration',
  25. 'type' => 'text',
  26. 'value' => '',
  27. 'default' => 1,
  28. ),
  29. 'fids' => array(
  30. 'title' => 'jack_forum',
  31. 'type' => 'mselect',
  32. 'value' => array(),
  33. ),
  34. );
  35. loadcache('forums');
  36. $settings['fids']['value'][] = array(0, '&nbsp;');
  37. if(empty($_G['cache']['forums'])) $_G['cache']['forums'] = array();
  38. foreach($_G['cache']['forums'] as $fid => $forum) {
  39. $settings['fids']['value'][] = array($fid, ($forum['type'] == 'forum' ? str_repeat('&nbsp;', 4) : ($forum['type'] == 'sub' ? str_repeat('&nbsp;', 8) : '')).$forum['name']);
  40. }
  41. $magic['fids'] = explode("\t", $magic['forum']);
  42. return $settings;
  43. }
  44. function setsetting(&$magicnew, &$parameters) {
  45. global $_G;
  46. $magicnew['forum'] = is_array($parameters['fids']) && !empty($parameters['fids']) ? implode("\t",$parameters['fids']) : '';
  47. $magicnew['expiration'] = intval($parameters['expiration']);
  48. }
  49. function usesubmit() {
  50. global $_G;
  51. if(empty($_GET['tid'])) {
  52. showmessage(lang('magic/jack', 'jack_info_nonexistence'));
  53. }
  54. $thread = getpostinfo($_GET['tid'], 'tid', array('fid', 'authorid', 'subject', 'lastpost'));
  55. $this->_check($thread['fid']);
  56. magicthreadmod($_GET['tid']);
  57. $this->parameters['expiration'] = $this->parameters['expiration'] ? intval($this->parameters['expiration']) : 1;
  58. $magicnum = abs(intval($_GET['magicnum']));
  59. if(empty($magicnum) || $magicnum > $this->magic['num']) {
  60. showmessage(lang('magic/jack', 'jack_num_not_enough'));
  61. }
  62. $expiration = ($thread['lastpost'] > TIMESTAMP ? $thread['lastpost'] : TIMESTAMP) + $this->parameters['expiration'] * $magicnum * 3600;
  63. C::t('forum_thread')->update($_GET['tid'], array('lastpost' => $expiration));
  64. usemagic($this->magic['magicid'], $this->magic['num'], $magicnum);
  65. updatemagiclog($this->magic['magicid'], '2', $magicnum, '0', 0, 'tid', $_GET['tid']);
  66. if($thread['authorid'] != $_G['uid']) {
  67. notification_add($thread['authorid'], 'magic', lang('magic/jack', 'jack_notification'), array('tid' => $_GET['tid'], 'subject' => $thread['subject'], 'magicname' => $this->magic['name']));
  68. }
  69. showmessage(lang('magic/jack', 'jack_succeed'), dreferer(), array(), array('alert' => 'right', 'showdialog' => 1, 'locationtime' => true));
  70. }
  71. function show() {
  72. global $_G;
  73. $tid = !empty($_GET['id']) ? dhtmlspecialchars($_GET['id']) : '';
  74. if($tid) {
  75. $thread = getpostinfo($_GET['id'], 'tid', array('fid'));
  76. $this->_check($thread['fid']);
  77. }
  78. $this->parameters['expiration'] = $this->parameters['expiration'] ? intval($this->parameters['expiration']) : 1;
  79. magicshowtype('top');
  80. magicshowtips(lang('magic/jack', 'jack_info', array('expiration' => $this->parameters['expiration'], 'magicnum' => $this->magic['num'])));
  81. magicshowsetting(lang('magic/jack', 'jack_num'), 'magicnum', '1', 'text');
  82. magicshowsetting('', 'tid', $tid, 'hidden');
  83. magicshowtype('bottom');
  84. }
  85. function buy() {
  86. global $_G;
  87. if(!empty($_GET['id'])) {
  88. $thread = getpostinfo($_GET['id'], 'tid', array('fid'));
  89. $this->_check($thread['fid']);
  90. }
  91. $this->parameters['expiration'] = $this->parameters['expiration'] ? intval($this->parameters['expiration']) : 1;
  92. magicshowtips(lang('magic/jack', 'jack_info', array('expiration' => $this->parameters['expiration'])));
  93. }
  94. function _check($fid) {
  95. if(!checkmagicperm($this->parameters['forum'], $fid)) {
  96. showmessage(lang('magic/jack', 'jack_info_noperm'));
  97. }
  98. }
  99. }
  100. ?>