magic_stick.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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_stick.php 29373 2012-04-09 07:55:30Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class magic_stick {
  12. var $version = '1.0';
  13. var $name = 'stick_name';
  14. var $description = 'stick_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' => 'stick_expiration',
  25. 'type' => 'text',
  26. 'value' => '',
  27. 'default' => 24,
  28. ),
  29. 'fids' => array(
  30. 'title' => 'stick_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/stick', 'stick_info_nonexistence'));
  53. }
  54. $thread = getpostinfo($_GET['tid'], 'tid', array('fid', 'authorid', 'subject'));
  55. $this->_check($thread['fid']);
  56. magicthreadmod($_GET['tid']);
  57. C::t('forum_thread')->update($_GET['tid'], array('displayorder' => 1, 'moderated' => 1));
  58. $this->parameters['expiration'] = $this->parameters['expiration'] ? intval($this->parameters['expiration']) : 24;
  59. $expiration = TIMESTAMP + $this->parameters['expiration'] * 3600;
  60. usemagic($this->magic['magicid'], $this->magic['num']);
  61. updatemagiclog($this->magic['magicid'], '2', '1', '0', 0, 'tid', $_GET['tid']);
  62. updatemagicthreadlog($_GET['tid'], $this->magic['magicid'], $expiration > 0 ? 'EST' : 'STK', $expiration);
  63. if($thread['authorid'] != $_G['uid']) {
  64. notification_add($thread['authorid'], 'magic', lang('magic/stick', 'stick_notification'), array('tid' => $_GET['tid'], 'subject' => $thread['subject'], 'magicname' => $this->magic['name']));
  65. }
  66. showmessage(lang('magic/stick', 'stick_succeed'), dreferer(), array(), array('alert' => 'right', 'showdialog' => 1, 'locationtime' => true));
  67. }
  68. function show() {
  69. global $_G;
  70. $tid = !empty($_GET['id']) ? dhtmlspecialchars($_GET['id']) : '';
  71. if($tid) {
  72. $thread = getpostinfo($_GET['id'], 'tid', array('fid'));
  73. $this->_check($thread['fid']);
  74. }
  75. $this->parameters['expiration'] = $this->parameters['expiration'] ? intval($this->parameters['expiration']) : 24;
  76. magicshowtype('top');
  77. magicshowsetting(lang('magic/stick', 'stick_info', array('expiration' => $this->parameters['expiration'])), 'tid', $tid, 'text');
  78. magicshowtype('bottom');
  79. }
  80. function buy() {
  81. global $_G;
  82. if(!empty($_GET['id'])) {
  83. $thread = getpostinfo($_GET['id'], 'tid', array('fid'));
  84. $this->_check($thread['fid']);
  85. }
  86. }
  87. function _check($fid) {
  88. if(!checkmagicperm($this->parameters['forum'], $fid)) {
  89. showmessage(lang('magic/stick', 'stick_info_noperm'));
  90. }
  91. }
  92. }
  93. ?>