magic_highlight.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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_highlight.php 33516 2013-06-27 08:58:10Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class magic_highlight {
  12. var $version = '1.0';
  13. var $name = 'highlight_name';
  14. var $description = 'highlight_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. var $idtypearray = array('blogid', 'tid');
  21. function getsetting(&$magic) {
  22. global $_G;
  23. $settings = array(
  24. 'expiration' => array(
  25. 'title' => 'highlight_expiration',
  26. 'type' => 'text',
  27. 'value' => '',
  28. 'default' => 24,
  29. ),
  30. 'fids' => array(
  31. 'title' => 'highlight_forum',
  32. 'type' => 'mselect',
  33. 'value' => array(),
  34. ),
  35. );
  36. loadcache('forums');
  37. $settings['fids']['value'][] = array(0, '&nbsp;');
  38. if(empty($_G['cache']['forums'])) $_G['cache']['forums'] = array();
  39. foreach($_G['cache']['forums'] as $fid => $forum) {
  40. $settings['fids']['value'][] = array($fid, ($forum['type'] == 'forum' ? str_repeat('&nbsp;', 4) : ($forum['type'] == 'sub' ? str_repeat('&nbsp;', 8) : '')).$forum['name']);
  41. }
  42. $magic['fids'] = explode("\t", $magic['forum']);
  43. return $settings;
  44. }
  45. function setsetting(&$magicnew, &$parameters) {
  46. global $_G;
  47. $magicnew['forum'] = is_array($parameters['fids']) && !empty($parameters['fids']) ? implode("\t",$parameters['fids']) : '';
  48. $magicnew['expiration'] = intval($parameters['expiration']);
  49. }
  50. function usesubmit() {
  51. global $_G;
  52. $idtype = !empty($_GET['idtype']) ? $_GET['idtype'] : '';
  53. if(!in_array($idtype, $this->idtypearray)) {
  54. showmessage(lang('magic/highlight', 'highlight_info_notype'), dreferer(), array(), array('showdialog' => 1, 'locationtime' => true));
  55. }
  56. if(empty($_GET['id'])) {
  57. showmessage(lang('magic/highlight', 'highlight_info_nonexistence_'.$idtype));
  58. }
  59. if($idtype == 'tid') {
  60. $info = getpostinfo($_GET['id'], $idtype, array('fid', 'authorid', 'subject'));
  61. $this->_check($info['fid']);
  62. magicthreadmod($_GET['id']);
  63. C::t('forum_thread')->update($_GET['id'], array('highlight' => $_GET['highlight_color'], 'moderated' => 1));
  64. $this->parameters['expiration'] = $this->parameters['expiration'] ? intval($this->parameters['expiration']) : 24;
  65. $expiration = TIMESTAMP + $this->parameters['expiration'] * 3600;
  66. updatemagicthreadlog($_GET['id'], $this->magic['magicid'], $expiration > 0 ? 'EHL' : 'HLT', $expiration);
  67. if($info['authorid'] != $_G['uid']) {
  68. notification_add($info['authorid'], 'magic', lang('magic/highlight', 'highlight_notification'), array('tid' => $_GET['id'], 'subject' => $info['subject'], 'magicname' => $this->magic['name']));
  69. }
  70. } elseif($idtype == 'blogid') {
  71. $info = getpostinfo($_GET['id'], $idtype, array('uid', 'subject'));
  72. C::t('home_blogfield')->update($_GET['id'], array('magiccolor' => $_GET['highlight_color']));
  73. if($info['uid'] != $_G['uid']) {
  74. notification_add($info['uid'], 'magic', lang('magic/highlight', 'highlight_notification_blogid'), array('blogid' => $_GET['id'], 'subject' => $info['subject'], 'magicname' => $this->magic['name']));
  75. }
  76. }
  77. usemagic($this->magic['magicid'], $this->magic['num']);
  78. updatemagiclog($this->magic['magicid'], '2', '1', '0', 0, $idtype, $_GET['id']);
  79. showmessage(lang('magic/highlight', 'highlight_succeed_'.$idtype), dreferer(), array(), array('alert' => 'right', 'showdialog' => 1, 'locationtime' => true));
  80. }
  81. function show() {
  82. global $_G;
  83. $id = !empty($_GET['id']) ? dhtmlspecialchars($_GET['id']) : '';
  84. $idtype = !empty($_GET['idtype']) ? $_GET['idtype'] : '';
  85. if(!in_array($idtype, $this->idtypearray)) {
  86. showmessage(lang('magic/highlight', 'highlight_info_notype'), dreferer(), array(), array('showdialog' => 1, 'locationtime' => true));
  87. }
  88. if($id) {
  89. $info = getpostinfo($_GET['id'], $idtype);
  90. if($idtype == 'tid') {
  91. $this->_check($info['fid']);
  92. $this->parameters['expiration'] = $this->parameters['expiration'] && $idtype == 'tid' ? intval($this->parameters['expiration']) : 24;
  93. }
  94. }
  95. magicshowtype('top');
  96. $lang = lang('magic/highlight');
  97. magicshowsetting(lang('magic/highlight', 'highlight_info_'.$idtype, array('expiration' => $this->parameters['expiration'])), 'id', $id, 'hidden');
  98. echo <<<EOF
  99. <p class="mtm mbn">$lang[highlight_color]</p>
  100. <div class="hasd mbm cl">
  101. <input type="hidden" id="highlight_color" name="highlight_color" />
  102. <input type="hidden" id="highlight_idtype" name="idtype" value="$idtype"/>
  103. <input type="text" id="highlight_color_show" class="crl readonly="readonly"" />
  104. <a href="javascript:;" id="highlight_color_ctrl" class="dpbtn" onclick="showHighLightColor('highlight_color')">^</a>
  105. </div>
  106. <script type="text/javascript" reload="1">
  107. function showHighLightColor(hlid) {
  108. var showid = hlid + '_show';
  109. if(!$(showid + '_menu')) {
  110. var str = '';
  111. var coloroptions = {'0' : '#000', '1' : '#EE1B2E', '2' : '#EE5023', '3' : '#996600', '4' : '#3C9D40', '5' : '#2897C5', '6' : '#2B65B7', '7' : '#8F2A90', '8' : '#EC1282'};
  112. var menu = document.createElement('div');
  113. menu.id = showid + '_menu';
  114. menu.className = 'cmen';
  115. menu.style.display = 'none';
  116. for(var i in coloroptions) {
  117. str += '<a href="javascript:;" onclick="$(\'' + hlid + '\').value=' + i + ';$(\'' + showid + '\').style.backgroundColor=\'' + coloroptions[i] + '\';hideMenu(\'' + menu.id + '\')" style="background:' + coloroptions[i] + ';color:' + coloroptions[i] + ';">' + coloroptions[i] + '</a>';
  118. }
  119. menu.innerHTML = str;
  120. $('append_parent').appendChild(menu);
  121. }
  122. showMenu({'ctrlid':hlid + '_ctrl','evt':'click','showid':showid});
  123. }
  124. </script>
  125. EOF;
  126. magicshowtype('bottom');
  127. }
  128. function buy() {
  129. global $_G;
  130. $idtype = !empty($_GET['idtype']) ? $_GET['idtype'] : '';
  131. if(!empty($_GET['id'])) {
  132. $info = getpostinfo($_GET['id'], $idtype);
  133. if($idtype == 'tid') {
  134. $this->_check($info['fid']);
  135. }
  136. }
  137. }
  138. function _check($fid) {
  139. if(!checkmagicperm($this->parameters['forum'], $fid)) {
  140. showmessage(lang('magic/highlight', 'highlight_info_noperm'));
  141. }
  142. }
  143. }
  144. ?>