magic_anonymouspost.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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_anonymouspost.php 29373 2012-04-09 07:55:30Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class magic_anonymouspost {
  12. var $version = '1.0';
  13. var $name = 'anonymouspost_name';
  14. var $description = 'anonymouspost_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' => 'anonymouspost_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. $id = intval($_GET['id']);
  45. if(empty($id)) {
  46. showmessage(lang('magic/anonymouspost', 'anonymouspost_info_nonexistence'));
  47. }
  48. $idtype = !empty($_GET['idtype']) ? dhtmlspecialchars($_GET['idtype']) : '';
  49. if(!in_array($idtype, array('pid', 'cid'))) {
  50. showmessage(lang('magic/anonymouspost', 'anonymouspost_use_error'));
  51. }
  52. if($idtype == 'pid') {
  53. $_G['tid'] = $_GET['ptid'];
  54. $post = getpostinfo($id, 'pid', array('p.first', 'p.tid', 'p.fid', 'p.authorid', 'p.author', 'p.dateline', 'p.anonymous'));
  55. $this->_check($post);
  56. if($post['authorid'] != $_G['uid']) {
  57. showmessage('magics_operation_nopermission');
  58. }
  59. $thread = getpostinfo($post['tid'], 'tid', array('tid', 'subject', 'author', 'replies', 'lastposter'));
  60. if($post['first']) {
  61. $author = '';
  62. $lastposter = $thread['replies'] > 0 ? $thread['lastposter'] : '';
  63. } else {
  64. $author = $thread['author'];
  65. $lastposter = '';
  66. }
  67. C::t('forum_post')->update('tid:'.$post['tid'], $id, array('anonymous' => 1));
  68. $query = C::t('forum_forum')->fetch($post['fid']);
  69. $forum['lastpost'] = explode("\t", $query['lastpost']);
  70. if($post['dateline'] == $forum['lastpost'][2] && ($post['author'] == $forum['lastpost'][3] || ($forum['lastpost'][3] == '' && $post['anonymous']))) {
  71. $lastpost = "$thread[tid]\t$thread[subject]\t$_G[timestamp]\t$lastposter";
  72. C::t('forum_forum')->update($post['fid'], array('lastpost' => $lastpost));
  73. }
  74. C::t('forum_thread')->update($post['tid'], array('author' => $author, 'lastposter' => $lastposter));
  75. } elseif($idtype == 'cid') {
  76. $value = C::t('home_comment')->fetch($id, intval($_G['uid']));
  77. if(empty($value)) {
  78. showmessage(lang('magic/anonymouspost', 'anonymouspost_use_error'));
  79. } elseif($value['author'] == '') {
  80. showmessage(lang('magic/anonymouspost', 'anonymouspost_once_limit'));
  81. }
  82. C::t('home_comment')->update($id, array('author'=>''), $_G['uid']);
  83. }
  84. usemagic($this->magic['magicid'], $this->magic['num']);
  85. updatemagiclog($this->magic['magicid'], '2', '1', '0', 0, $idtype, $id);
  86. showmessage(lang('magic/anonymouspost', 'anonymouspost_succeed'), dreferer(), array(), array('alert' => 'right', 'showdialog' => 1, 'locationtime' => true));
  87. }
  88. function show() {
  89. global $_G;
  90. $id = !empty($_GET['id']) ? dhtmlspecialchars($_GET['id']) : '';
  91. $idtype = !empty($_GET['idtype']) ? dhtmlspecialchars($_GET['idtype']) : '';
  92. if($idtype == 'pid') {
  93. list($id, $_G['tid']) = explode(':', $id);
  94. if($id && $_G['tid']) {
  95. $post = getpostinfo($id, 'pid', array('p.fid', 'p.authorid'));
  96. $this->_check($post);
  97. }
  98. }
  99. magicshowtype('top');
  100. magicshowtips(lang('magic/anonymouspost', 'anonymouspost_desc'));
  101. magicshowtips(lang('magic/anonymouspost', 'anonymouspost_num', array('magicnum' => $this->magic['num'])));
  102. magicshowsetting('', 'id', $id, 'hidden');
  103. magicshowsetting('', 'idtype', $idtype, 'hidden');
  104. if($idtype == 'pid') {
  105. magicshowsetting('', 'ptid', $_G['tid'], 'hidden');
  106. }
  107. magicshowtype('bottom');
  108. }
  109. function buy() {
  110. global $_G;
  111. $id = !empty($_GET['id']) ? dhtmlspecialchars($_GET['id']) : '';
  112. $idtype = !empty($_GET['idtype']) ? dhtmlspecialchars($_GET['idtype']) : '';
  113. if(!empty($id) && $idtype == 'pid') {
  114. list($id, $_G['tid']) = explode(':', $id);
  115. $post = getpostinfo(intval($id), 'pid', array('p.fid', 'p.authorid'));
  116. $this->_check($post);
  117. }
  118. }
  119. function _check($post) {
  120. global $_G;
  121. if(!checkmagicperm($this->parameters['forum'], $post['fid'])) {
  122. showmessage(lang('magic/anonymouspost', 'anonymouspost_info_noperm'));
  123. }
  124. if($post['authorid'] != $_G['uid']) {
  125. showmessage(lang('magic/anonymouspost', 'anonymouspost_info_user_noperm'));
  126. }
  127. }
  128. }
  129. ?>