magic_namepost.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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_namepost.php 29373 2012-04-09 07:55:30Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class magic_namepost {
  12. var $version = '1.0';
  13. var $name = 'namepost_name';
  14. var $description = 'namepost_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' => 'namepost_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. }
  43. function usesubmit() {
  44. global $_G;
  45. $id = intval($_GET['id']);
  46. if(empty($id)) {
  47. showmessage(lang('magic/namepost', 'namepost_info_nonexistence'));
  48. }
  49. $idtype = !empty($_GET['idtype']) ? dhtmlspecialchars($_GET['idtype']) : '';
  50. if(!in_array($idtype, array('pid', 'cid'))) {
  51. showmessage(lang('magic/namepost', 'namepost_use_error'));
  52. }
  53. if($idtype == 'pid') {
  54. $_G['tid'] = intval($_GET['ptid']);
  55. $post = getpostinfo($id, 'pid', array('p.first', 'p.tid', 'p.fid', 'p.authorid', 'p.dateline', 'p.anonymous'));
  56. $this->_check($post);
  57. $authorid = $post['authorid'];
  58. $author = $post['anonymous'] ? '' : 1;
  59. } elseif($idtype == 'cid') {
  60. $comment = C::t('home_comment')->fetch($id);
  61. $authorid = $comment['authorid'];
  62. $author = $comment['author'];
  63. }
  64. if($author) {
  65. showmessage('magicuse_bad_object');
  66. }
  67. $member = getuserbyuid($authorid);
  68. if(!checkmagicperm($this->parameters['targetgroups'], $member['groupid'])) {
  69. showmessage(lang('magic/namepost', 'namepost_info_user_noperm'));
  70. }
  71. $author = daddslashes($member['username']);
  72. usemagic($this->magic['magicid'], $this->magic['num']);
  73. updatemagiclog($this->magic['magicid'], '2', '1', '0', 0, $idtype, $id);
  74. showmessage(lang('magic/namepost', 'magic_namepost_succeed'),'javascript:;', array('uid' => $authorid, 'username' => $author, 'avatar' => 1), array('alert' => 'right'));
  75. }
  76. function show() {
  77. global $_G;
  78. $id = !empty($_GET['id']) ? dhtmlspecialchars($_GET['id']) : '';
  79. $idtype = !empty($_GET['idtype']) ? dhtmlspecialchars($_GET['idtype']) : '';
  80. if($idtype == 'pid') {
  81. list($id, $_G['tid']) = explode(':', $id);
  82. if($id && $_G['tid']) {
  83. $post = getpostinfo($id, 'pid', array('p.fid', 'p.authorid'));
  84. $this->_check($post);
  85. }
  86. }
  87. magicshowtype('top');
  88. magicshowtips(lang('magic/namepost', 'namepost_desc'));
  89. magicshowtips(lang('magic/namepost', 'namepost_num', array('magicnum' => $this->magic['num'])));
  90. magicshowsetting('', 'id', $id, 'hidden');
  91. magicshowsetting('', 'idtype', $idtype, 'hidden');
  92. if($idtype == 'pid') {
  93. magicshowsetting('', 'ptid', $_G['tid'], 'hidden');
  94. }
  95. magicshowtype('bottom');
  96. }
  97. function buy() {
  98. global $_G;
  99. $id = !empty($_GET['id']) ? dhtmlspecialchars($_GET['id']) : '';
  100. $idtype = !empty($_GET['idtype']) ? dhtmlspecialchars($_GET['idtype']) : '';
  101. if(!empty($id) && $_GET['idtype'] == 'pid') {
  102. list($id, $_G['tid']) = explode(':', $id);
  103. $post = getpostinfo(intval($id), 'pid', array('p.fid', 'p.authorid'));
  104. $this->_check($post);
  105. }
  106. }
  107. function _check($post) {
  108. global $_G;
  109. if(!checkmagicperm($this->parameters['forum'], $post['fid'])) {
  110. showmessage(lang('magic/namepost', 'namepost_info_noperm'));
  111. }
  112. $member = getuserbyuid($post['authorid']);
  113. if(!checkmagicperm($this->parameters['targetgroups'], $member['groupid'])) {
  114. showmessage(lang('magic/namepost', 'namepost_info_user_noperm'));
  115. }
  116. }
  117. }
  118. ?>