/source/class/magic/magic_namepost.php

https://github.com/sichen/hrmmdiscuz · PHP · 133 lines · 112 code · 15 blank · 6 comment · 23 complexity · d0a2feb254945bc3f8e85f0aa4446a03 MD5 · raw file

  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 18832 2010-12-07 04:01:53Z liulanbo $
  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($_G['gp_id']);
  46. if(empty($id)) {
  47. showmessage(lang('magic/namepost', 'namepost_info_nonexistence'));
  48. }
  49. $idtype = !empty($_G['gp_idtype']) ? htmlspecialchars($_G['gp_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($_G['gp_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 = DB::fetch_first("SELECT * FROM ".DB::table('home_comment')." WHERE cid='$id'");
  61. $authorid = $comment['authorid'];
  62. $author = $comment['author'];
  63. }
  64. if($author) {
  65. showmessage('magicuse_bad_object');
  66. }
  67. $member = DB::fetch_first("SELECT username, groupid FROM ".DB::table('common_member')." WHERE uid='$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));
  75. }
  76. function show() {
  77. global $_G;
  78. $id = !empty($_G['gp_id']) ? htmlspecialchars($_G['gp_id']) : '';
  79. $idtype = !empty($_G['gp_idtype']) ? htmlspecialchars($_G['gp_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($_G['gp_id']) ? htmlspecialchars($_G['gp_id']) : '';
  100. $idtype = !empty($_G['gp_idtype']) ? htmlspecialchars($_G['gp_idtype']) : '';
  101. if(!empty($id) && $_G['gp_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. ?>